Skip to content

Commit 733744b

Browse files
author
Richard Lyle
committed
* Code cleanup.
1 parent 8aa3540 commit 733744b

File tree

3 files changed

+61
-60
lines changed

3 files changed

+61
-60
lines changed

Widgets/EventWidget.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/**
1+

2+
/**
23
* Copyright 2015 IBM Corp. All Rights Reserved.
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");

Widgets/MicrophoneWidget.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public void OnToggleActive()
8383
}
8484
#endregion
8585

86-
#region Public Function - For UI interaction
87-
86+
#region Public Functions
8887
/// <summary>
8988
/// Activates the microphone.
9089
/// </summary>
@@ -101,6 +100,7 @@ public void DeactivateMicrophone(){
101100
}
102101

103102
#endregion
103+
104104
#region Widget interface
105105
/// <exclude />
106106
protected override string GetName()

Widgets/NaturalLanguageClassifierWidget.cs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ namespace IBM.Watson.DeveloperCloud.Widgets
3333
/// Natural Language Classifier Widget.
3434
/// </summary>
3535
public class NaturalLanguageClassifierWidget : Widget
36-
{
37-
#region Private Data
38-
private NaturalLanguageClassifier m_NLC = new NaturalLanguageClassifier();
36+
{
37+
#region Private Data
38+
private NaturalLanguageClassifier m_NLC = new NaturalLanguageClassifier();
3939
private Classifier m_Selected = null;
4040

4141
[SerializeField]
42-
private Input m_RecognizeInput = new Input( "Recognize", typeof(SpeechToTextData), "OnRecognize" );
42+
private Input m_RecognizeInput = new Input("Recognize", typeof(SpeechToTextData), "OnRecognize");
4343
[SerializeField]
44-
private Output m_ClassifyOutput = new Output( typeof(ClassifyResultData) );
44+
private Output m_ClassifyOutput = new Output(typeof(ClassifyResultData));
4545
[SerializeField]
4646
private string m_ClassifierName = string.Empty;
4747
[SerializeField]
@@ -63,7 +63,7 @@ private class ClassEventMapping
6363
};
6464
[SerializeField]
6565
private List<ClassEventMapping> m_ClassEventList = new List<ClassEventMapping>();
66-
private Dictionary<string,Constants.Event> m_ClassEventMap = new Dictionary<string,Constants.Event>();
66+
private Dictionary<string, Constants.Event> m_ClassEventMap = new Dictionary<string, Constants.Event>();
6767

6868
[SerializeField]
6969
private Text m_TopClassText = null;
@@ -76,39 +76,39 @@ private class ClassEventMapping
7676
public NaturalLanguageClassifier NLC { get { return m_NLC; } }
7777
#endregion
7878

79-
#region MonoBehaviour interface
79+
#region MonoBehaviour interface
8080
/// <exclude />
8181
protected override void Start()
82-
{
82+
{
8383
base.Start();
8484

8585
// resolve configuration variables
86-
m_ClassifierName = Config.Instance.ResolveVariables( m_ClassifierName );
87-
m_ClassifierId = Config.Instance.ResolveVariables( m_ClassifierId );
86+
m_ClassifierName = Config.Instance.ResolveVariables(m_ClassifierName);
87+
m_ClassifierId = Config.Instance.ResolveVariables(m_ClassifierId);
8888

8989
// start the default log reactors if needed..
90-
LogSystem.InstallDefaultReactors();
90+
LogSystem.InstallDefaultReactors();
9191

9292
if (string.IsNullOrEmpty(m_ClassifierId))
9393
{
94-
Log.Status( "NlcWidget", "Auto selecting a classifier." );
95-
if (! m_NLC.GetClassifiers( OnGetClassifiers ) )
96-
Log.Error( "NlcWidget", "Failed to request all classifiers." );
94+
Log.Status("NlcWidget", "Auto selecting a classifier.");
95+
if (!m_NLC.GetClassifiers(OnGetClassifiers))
96+
Log.Error("NlcWidget", "Failed to request all classifiers.");
9797
}
9898
else
9999
{
100-
if (! m_NLC.GetClassifier( m_ClassifierId, OnGetClassifier ) )
101-
Log.Equals( "NlcWidget", "Failed to request classifier." );
100+
if (!m_NLC.GetClassifier(m_ClassifierId, OnGetClassifier))
101+
Log.Equals("NlcWidget", "Failed to request classifier.");
102102
}
103103
}
104104

105105
private void OnEnable()
106106
{
107-
EventManager.Instance.RegisterEventReceiver( Constants.Event.ON_DEBUG_COMMAND, OnDebugCommand );
108-
}
107+
EventManager.Instance.RegisterEventReceiver(Constants.Event.ON_DEBUG_COMMAND, OnDebugCommand);
108+
}
109109
private void OnDisable()
110110
{
111-
EventManager.Instance.UnregisterEventReceiver( Constants.Event.ON_DEBUG_COMMAND, OnDebugCommand );
111+
EventManager.Instance.UnregisterEventReceiver(Constants.Event.ON_DEBUG_COMMAND, OnDebugCommand);
112112
}
113113
#endregion
114114

@@ -120,33 +120,33 @@ protected override string GetName()
120120
}
121121
#endregion
122122

123-
private void OnGetClassifiers( Classifiers classifiers )
123+
private void OnGetClassifiers(Classifiers classifiers)
124124
{
125-
if ( classifiers != null )
125+
if (classifiers != null)
126126
{
127-
foreach( var classifier in classifiers.classifiers )
127+
foreach (var classifier in classifiers.classifiers)
128128
{
129-
if (! string.IsNullOrEmpty( m_ClassifierName ) && !classifier.name.StartsWith( m_ClassifierName ) )
129+
if (!string.IsNullOrEmpty(m_ClassifierName) && !classifier.name.StartsWith(m_ClassifierName))
130130
continue;
131-
if ( classifier.language != m_Language )
131+
if (classifier.language != m_Language)
132132
continue;
133133

134-
m_NLC.GetClassifier( classifier.classifier_id, OnGetClassifier );
134+
m_NLC.GetClassifier(classifier.classifier_id, OnGetClassifier);
135135
}
136136
}
137137
}
138138

139-
private void OnGetClassifier( Classifier classifier )
139+
private void OnGetClassifier(Classifier classifier)
140140
{
141-
if ( classifier != null && classifier.status == "Available" )
141+
if (classifier != null && classifier.status == "Available")
142142
{
143-
if ( m_Selected == null || m_Selected.created.CompareTo( classifier.created ) < 0 )
143+
if (m_Selected == null || m_Selected.created.CompareTo(classifier.created) < 0)
144144
{
145145
m_Selected = classifier;
146146
m_ClassifierId = m_Selected.classifier_id;
147147

148-
Log.Status( "NlcWidget", "Selected classifier {0}, Created: {1}, Name: {2}",
149-
m_Selected.classifier_id, m_Selected.created, m_Selected.name );
148+
Log.Status("NlcWidget", "Selected classifier {0}, Created: {1}, Name: {2}",
149+
m_Selected.classifier_id, m_Selected.created, m_Selected.name);
150150
}
151151
}
152152
}
@@ -164,70 +164,70 @@ private void OnRecognize(Data data)
164164

165165
if (textConfidence > m_MinWordConfidence)
166166
{
167-
if (! string.IsNullOrEmpty( m_ClassifierId ) )
167+
if (!string.IsNullOrEmpty(m_ClassifierId))
168168
{
169169
if (!m_NLC.Classify(m_ClassifierId, text, OnClassified))
170170
Log.Error("NlcWidget", "Failed to send {0} to NLC.", text);
171171
}
172172
else
173-
Log.Equals( "NlcWidget", "No valid classifier set." );
173+
Log.Equals("NlcWidget", "No valid classifier set.");
174174
}
175175
else
176176
{
177-
if (textConfidence > m_IgnoreWordConfidence )
178-
EventManager.Instance.SendEvent( Constants.Event.ON_CLASSIFY_FAILURE, result );
177+
if (textConfidence > m_IgnoreWordConfidence)
178+
EventManager.Instance.SendEvent(Constants.Event.ON_CLASSIFY_FAILURE, result);
179179
}
180180
}
181181
}
182182

183-
private void OnClassified(ClassifyResult result)
184-
{
185-
EventManager.Instance.SendEvent( Constants.Event.ON_CLASSIFY_RESULT, result );
183+
private void OnClassified(ClassifyResult result)
184+
{
185+
EventManager.Instance.SendEvent(Constants.Event.ON_CLASSIFY_RESULT, result);
186186

187-
if ( m_ClassifyOutput.IsConnected )
188-
m_ClassifyOutput.SendData( new ClassifyResultData( result ) );
187+
if (m_ClassifyOutput.IsConnected)
188+
m_ClassifyOutput.SendData(new ClassifyResultData(result));
189189

190-
if ( result != null )
190+
if (result != null)
191191
{
192-
Log.Debug( "NlcWidget", "OnClassified: {0} ({1:0.00})", result.top_class, result.topConfidence );
192+
Log.Debug("NlcWidget", "OnClassified: {0} ({1:0.00})", result.top_class, result.topConfidence);
193193

194-
if ( m_TopClassText != null )
195-
m_TopClassText.text = result.top_class;
194+
if (m_TopClassText != null)
195+
m_TopClassText.text = result.top_class;
196196

197-
if ( !string.IsNullOrEmpty( result.top_class) )
197+
if (!string.IsNullOrEmpty(result.top_class))
198198
{
199-
if ( result.topConfidence >= m_MinClassEventConfidence )
199+
if (result.topConfidence >= m_MinClassEventConfidence)
200200
{
201-
if ( m_ClassEventList.Count > 0 && m_ClassEventMap.Count == 0 )
201+
if (m_ClassEventList.Count > 0 && m_ClassEventMap.Count == 0)
202202
{
203203
// initialize the map
204-
foreach( var ev in m_ClassEventList )
205-
m_ClassEventMap[ ev.m_Class ] = ev.m_Event;
204+
foreach (var ev in m_ClassEventList)
205+
m_ClassEventMap[ev.m_Class] = ev.m_Event;
206206
}
207207

208208
Constants.Event sendEvent;
209-
if (! m_ClassEventMap.TryGetValue( result.top_class, out sendEvent ) )
209+
if (!m_ClassEventMap.TryGetValue(result.top_class, out sendEvent))
210210
{
211-
Log.Warning( "NlcWidget", "No class mapping found for {0}", result.top_class );
212-
EventManager.Instance.SendEvent( result.top_class, result );
211+
Log.Warning("NlcWidget", "No class mapping found for {0}", result.top_class);
212+
EventManager.Instance.SendEvent(result.top_class, result);
213213
}
214214
else
215-
EventManager.Instance.SendEvent( sendEvent, result );
215+
EventManager.Instance.SendEvent(sendEvent, result);
216216
}
217217
else
218218
{
219-
if ( result.topConfidence > m_IgnoreWordConfidence )
220-
EventManager.Instance.SendEvent( Constants.Event.ON_CLASSIFY_FAILURE, result );
219+
if (result.topConfidence > m_IgnoreWordConfidence)
220+
EventManager.Instance.SendEvent(Constants.Event.ON_CLASSIFY_FAILURE, result);
221221
}
222222
}
223223
}
224-
}
224+
}
225225

226226
#region Event Handlers
227-
private void OnDebugCommand( object [] args )
227+
private void OnDebugCommand(object[] args)
228228
{
229229
string text = args != null && args.Length > 0 ? args[0] as string : string.Empty;
230-
if (! string.IsNullOrEmpty( text ) && !string.IsNullOrEmpty(m_ClassifierId) )
230+
if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(m_ClassifierId))
231231
{
232232
if (!m_NLC.Classify(m_ClassifierId, text, OnClassified))
233233
Log.Error("NlcWidget", "Failed to send {0} to NLC.", (string)args[0]);

0 commit comments

Comments
 (0)