Skip to content

Commit 0974ca1

Browse files
authored
Merge pull request #92 from watson-developer-cloud/feature-85-alchemyLanguageConfig
Feature 85 alchemy language config
2 parents cc11136 + 344e74e commit 0974ca1

File tree

8 files changed

+99
-47
lines changed

8 files changed

+99
-47
lines changed

CHANGELOG.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ Change Log
44

55
_2016-06-24_
66

7-
* New: Added Alchemy Language v1 abstraction
8-
* New: Added Personality Insights v2 abstraction
9-
* Fix: Added Tone Analyzer to the Configuration Editor
10-
* Fix: Added Tradeoff Analytics to the Configuration Editor
11-
* Fix: Added Conversation to the Configuration Editor
12-
* Fix: Added Personality Insights to the Configuration Editor
7+
* New: Added `Alchemy Language` abstraction
8+
* New: Added `Personality Insights` abstraction
9+
* Fix: Added `Tone Analyzer` to the Configuration Editor
10+
* Fix: Added `Tradeoff Analytics` to the Configuration Editor
11+
* Fix: Added `Conversation` to the Configuration Editor
12+
* Fix: Added `Personality Insights` to the Configuration Editor
13+
* Fix: Added `Alchemy Language` to the Configuration Editor
14+
* Fix: Added `Visual Recognition` to the Configuration Editor
1315

1416
## Version 0.4.0
1517

1618
_2016-06-09_
1719

18-
* New: Added Tone Analyzer v3 abstraction
19-
* New: Added Tradeoff Analytics abstraction
20-
* New: Added Conversation abstraction
21-
* New: Added Visual Recognition v3 abstraction
20+
* New: Added `Tone Analyzer v3` abstraction
21+
* New: Added `Tradeoff Analytics` abstraction
22+
* New: Added `Conversation` abstraction
23+
* New: Added `Visual Recognition v3` abstraction
2224
* Fix: Creating test project dynamically for Travis CL integration
2325
* Fix: Refactored Language Translation to Language Translator
2426
* Fix: Widget examples sprite references were disconnected

Config.json.enc

512 Bytes
Binary file not shown.

Examples/ServiceExamples/Scripts/ExampleVisualRecognition.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class ExampleVisualRecognition : MonoBehaviour {
2525
private VisualRecognition m_VisualRecognition = new VisualRecognition();
2626
private string m_classifierName = "Apples_OptionalParams";
27-
private string m_classifierID = "Apples_OptionalParams_1213405640";
27+
private string m_classifierID = "ApplesClassifierNameWithSpaces_73100404";
2828
private string m_classifierToDelete = "unitytestclassifier2b_37849361";
2929
private string m_imageURL = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Official_portrait_of_Barack_Obama.jpg";
3030
private string m_imageTextURL = "http://i.stack.imgur.com/ZS6nH.png";
@@ -36,7 +36,7 @@ void Start ()
3636
// Get all classifiers
3737
if(!m_VisualRecognition.GetClassifiers(OnGetClassifiers))
3838
Log.Debug("ExampleVisualRecognition", "Getting classifiers failed!");
39-
39+
//
4040
// Find classifier by name
4141
m_VisualRecognition.FindClassifier(m_classifierName, OnFindClassifier);
4242

@@ -49,17 +49,17 @@ void Start ()
4949
Log.Debug("ExampleVisualRecognition", "Deleting classifier failed!");
5050

5151
// Train classifier
52-
string m_positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/taj_positive_examples.zip";
53-
string m_negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/negative_examples.zip";
54-
if(!m_VisualRecognition.TrainClassifier("unity-test-classifier5", "taj", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier))
52+
string m_positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip";
53+
string m_negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip";
54+
if(!m_VisualRecognition.TrainClassifier("unity-test-classifier5", "giraffe", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier))
5555
Log.Debug("ExampleVisualRecognition", "Train classifier failed!");
5656

5757
// Classify get
5858
if(!m_VisualRecognition.Classify(m_imageURL, OnClassify))
5959
Log.Debug("ExampleVisualRecognition", "Classify image failed!");
6060

6161
// Classify post image
62-
string m_imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/obama.jpg";
62+
string m_imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg";
6363
string[] m_owners = {"IBM", "me"};
6464
string[] m_classifierIDs = {"default"};
6565
if(!m_VisualRecognition.Classify(OnClassify, m_imagesPath, m_owners, m_classifierIDs, 0.5f))
@@ -71,7 +71,7 @@ void Start ()
7171
Log.Debug("ExampleVisualRecogntiion", "Detect faces failed!");
7272

7373
// Detect faces post image
74-
string m_faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/obama.jpg";
74+
string m_faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg";
7575
if(!m_VisualRecognition.DetectFaces(OnDetectFaces, m_faceExamplePath))
7676
Log.Debug("ExampleVisualRecognition", "Detect faces failed!");
7777

@@ -82,7 +82,7 @@ void Start ()
8282
Log.Debug("ExampleVisualRecognition", "Recognize text failed!");
8383

8484
// Recognize text post image
85-
string m_textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/from_platos_apology.png";
85+
string m_textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png";
8686
if(!m_VisualRecognition.RecognizeText(OnRecognizeText, m_textExamplePath))
8787
Log.Debug("ExampleVisualRecognition", "Recognize text failed!");
8888
}

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,7 @@ void OnMessage (DataModels.MessageResponse resp)
354354

355355

356356
### Visual Recognition
357-
Use the [Visual Recognition][visual_recognition] service to classify an image against a default or custom trained classifier. In addition, the service can detect faces and text in an image. Instead of credentials, the Visual Recognition key `VISUAL_RECOGNITION_API_KEY` must be set as a variable in the Advanced Mode of the Config Editor (**Watson -> Configuration Editor**). The ServiceID `VisualRecognitionV3` and endpoint URL `https://gateway-a.watsonplatform.net/visual-recognition/api` must also be added manually.
358-
359-
![visual-recognition0](http://g.recordit.co/Qke2gKfaKJ.gif)
357+
Use the [Visual Recognition][visual_recognition] service to classify an image against a default or custom trained classifier. In addition, the service can detect faces and text in an image.
360358

361359
#### Managing Classifiers
362360
You can train and delete classifiers by directly accessing low level Visual Recognition methods.
@@ -780,9 +778,7 @@ private void LogTraitTree(DataModels.TraitTreeNode traitTreeNode)
780778

781779

782780
### Alchemy Language
783-
Use the [Alchemy Language][alchemy_language] service to extract semantic meta-data from content such as information on people, places, companies, topics, facts, relationships, authors and languages. Instead of credentials, the Alchemy API Key `ALCHEMY_API_KEY` must be set as a variable in the Advanced Mode of the Config Editor (**Watson -> Configuration Editor**). The ServiceID `AlchemyLanguageV1` and endpoint URL `https://gateway-a.watsonplatform.net` must also be added manually.
784-
785-
![alchemy-language0](http://g.recordit.co/xkGArdMVbC.gif)
781+
Use the [Alchemy Language][alchemy_language] service to extract semantic meta-data from content such as information on people, places, companies, topics, facts, relationships, authors and languages.
786782

787783
#### Getting Authors
788784
You can extract Authors from a URL or HTML source.

Scripts/Editor/ConfigEditor.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ private class ServiceSetup
6565
new ServiceSetup() { ServiceName = "Personality Insights", ServiceAPI = "personality-insights/api",
6666
URL ="https://console.ng.bluemix.net/catalog/services/personality-insights/", ServiceID="PersonalityInsightsV2" },
6767
new ServiceSetup() { ServiceName = "Conversation", ServiceAPI = "conversation-experimental/api",
68-
URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationV1" }
68+
URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationV1" },
69+
new ServiceSetup() { ServiceName = "Alchemy Language", ServiceAPI = "gateway-a.watsonplatform.net/calls",
70+
URL ="https://console.ng.bluemix.net/catalog/services/alchemyapi/", ServiceID="AlchemyLanguageV1" },
71+
new ServiceSetup() { ServiceName = "Visual Recognition", ServiceAPI = "visual-recognition/api",
72+
URL ="https://console.ng.bluemix.net/catalog/services/visual-recognition/", ServiceID="VisualRecognitionV3" }
6973
};
7074

7175
private const string TITLE = "Watson Unity SDK";
@@ -193,6 +197,20 @@ private static void EditConfig()
193197
private Vector2 m_ScrollPos = Vector2.zero;
194198
private string m_PastedCredentials = "\n\n\n\n\n\n\n";
195199

200+
private bool GetIsValid(ServiceSetup setup)
201+
{
202+
bool isValid = false;
203+
Config cfg = Config.Instance;
204+
Config.CredentialInfo info = cfg.FindCredentials( setup.ServiceID );
205+
if(info != null)
206+
{
207+
if((!string.IsNullOrEmpty(info.m_URL) && !string.IsNullOrEmpty(info.m_Password)) || !string.IsNullOrEmpty(info.m_Apikey))
208+
isValid = true;
209+
}
210+
211+
return isValid;
212+
}
213+
196214
private void OnGUI()
197215
{
198216
Config cfg = Config.Instance;
@@ -205,17 +223,14 @@ private void OnGUI()
205223
//GUILayout.Label( "Use this dialog to generate your configuration file for the Watson Unity SDK." );
206224
//GUILayout.Label( "If you have never registered for Watson BlueMix services, click on the button below to begin registration." );
207225

208-
if ( GUILayout.Button( "Register for Watson Services" ) )
226+
if(GUILayout.Button("Register for Watson Services"))
209227
Application.OpenURL( BLUEMIX_REGISTRATION );
210228

211229
foreach( var setup in SERVICE_SETUP )
212230
{
213231
Config.CredentialInfo info = cfg.FindCredentials( setup.ServiceID );
214232

215-
bool bValid = info != null
216-
&& !string.IsNullOrEmpty( info.m_URL )
217-
&& !string.IsNullOrEmpty( info.m_User )
218-
&& !string.IsNullOrEmpty( info.m_Password );
233+
bool bValid = GetIsValid(setup);
219234

220235
GUILayout.BeginHorizontal();
221236

@@ -333,8 +348,17 @@ private void OnGUI()
333348
GUILayout.EndHorizontal();
334349

335350
info.m_URL = EditorGUILayout.TextField("URL", info.m_URL);
336-
info.m_User = EditorGUILayout.TextField("User", info.m_User);
337-
info.m_Password = EditorGUILayout.TextField("Password", info.m_Password);
351+
352+
if(!string.IsNullOrEmpty(info.m_URL))
353+
{
354+
if(info.m_URL.StartsWith("https://gateway-a"))
355+
info.m_Apikey = EditorGUILayout.TextField("API Key", info.m_Apikey);
356+
else
357+
{
358+
info.m_User = EditorGUILayout.TextField("User", info.m_User);
359+
info.m_Password = EditorGUILayout.TextField("Password", info.m_Password);
360+
}
361+
}
338362

339363
if (GUILayout.Button("Delete"))
340364
cfg.Credentials.RemoveAt(i--);

Scripts/Services/AlchemyAPI/AlchemyLanguage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class AlchemyLanguage : IWatsonService
4545
#region SetCredentials
4646
private void SetCredentials()
4747
{
48-
mp_ApiKey = Config.Instance.GetVariableValue("ALCHEMY_API_KEY");
48+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
4949

5050
if (string.IsNullOrEmpty(mp_ApiKey))
5151
throw new WatsonException("ALCHEMY_API_KEY needs to be defined in config.json");

Scripts/Services/VisualRecognition/VisualRecognition.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class VisualRecognition : IWatsonService
109109
public bool Classify(string url, OnClassify callback, string[] owners = default(string[]), string[] classifierIDs = default(string[]), float threshold = default(float), string acceptLanguage = "en")
110110
{
111111
if(string.IsNullOrEmpty(mp_ApiKey))
112-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
112+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
113113
if(string.IsNullOrEmpty(mp_ApiKey))
114114
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
115115
if(string.IsNullOrEmpty(url))
@@ -151,7 +151,7 @@ public class VisualRecognition : IWatsonService
151151
public bool Classify(OnClassify callback, string imagePath, string[] owners = default(string[]), string[] classifierIDs = default(string[]), float threshold = default(float), string acceptLanguage = "en")
152152
{
153153
if(string.IsNullOrEmpty(mp_ApiKey))
154-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
154+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
155155
if(string.IsNullOrEmpty(mp_ApiKey))
156156
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
157157
if(callback == null)
@@ -259,7 +259,7 @@ public bool DetectFaces(string url, OnDetectFaces callback)
259259
if(callback == null)
260260
throw new ArgumentNullException("callback");
261261
if(string.IsNullOrEmpty(mp_ApiKey))
262-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
262+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
263263
if(string.IsNullOrEmpty(mp_ApiKey))
264264
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
265265

@@ -288,7 +288,7 @@ public bool DetectFaces(OnDetectFaces callback, string imagePath)
288288
if(string.IsNullOrEmpty(imagePath))
289289
throw new ArgumentNullException("Define an image path to classify!");
290290
if(string.IsNullOrEmpty(mp_ApiKey))
291-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
291+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
292292
if(string.IsNullOrEmpty(mp_ApiKey))
293293
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
294294

@@ -392,7 +392,7 @@ public bool RecognizeText(string url, OnRecognizeText callback)
392392
if(callback == null)
393393
throw new ArgumentNullException("callback");
394394
if(string.IsNullOrEmpty(mp_ApiKey))
395-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
395+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
396396
if(string.IsNullOrEmpty(mp_ApiKey))
397397
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
398398

@@ -421,7 +421,7 @@ public bool RecognizeText(OnRecognizeText callback, string imagePath)
421421
if(string.IsNullOrEmpty(imagePath))
422422
throw new ArgumentNullException("Define an image path to classify!");
423423
if(string.IsNullOrEmpty(mp_ApiKey))
424-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
424+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
425425
if(string.IsNullOrEmpty(mp_ApiKey))
426426
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
427427

@@ -545,7 +545,7 @@ public FindClassifierReq(VisualRecognition service, string classifierName, OnFin
545545
if(string.IsNullOrEmpty(classifierName))
546546
throw new WatsonException("classifierName required");
547547
if(string.IsNullOrEmpty(mp_ApiKey))
548-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
548+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
549549
if(string.IsNullOrEmpty(mp_ApiKey))
550550
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
551551

@@ -598,7 +598,7 @@ public bool GetClassifiers(OnGetClassifiers callback)
598598
if(callback == null)
599599
throw new ArgumentNullException("callback");
600600
if(string.IsNullOrEmpty(mp_ApiKey))
601-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
601+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
602602
if(string.IsNullOrEmpty(mp_ApiKey))
603603
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
604604

@@ -662,7 +662,7 @@ public bool GetClassifier(string classifierId, OnGetClassifier callback)
662662
if (callback == null)
663663
throw new ArgumentNullException("callback");
664664
if(string.IsNullOrEmpty(mp_ApiKey))
665-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
665+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
666666
if(string.IsNullOrEmpty(mp_ApiKey))
667667
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
668668

@@ -728,7 +728,7 @@ private void OnGetClassifierResp(RESTConnector.Request req, RESTConnector.Respon
728728
public bool TrainClassifier(string classifierName, string className, string positiveExamplesPath, string negativeExamplesPath, OnTrainClassifier callback)
729729
{
730730
if(string.IsNullOrEmpty(mp_ApiKey))
731-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
731+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
732732
if(string.IsNullOrEmpty(mp_ApiKey))
733733
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
734734
if(string.IsNullOrEmpty(classifierName))
@@ -764,7 +764,7 @@ public bool TrainClassifier(string classifierName, string className, string posi
764764
private bool UploadClassifier(string classifierName, string className, byte[] positiveExamplesData, byte[] negativeExamplesData, OnTrainClassifier callback)
765765
{
766766
if(string.IsNullOrEmpty(mp_ApiKey))
767-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
767+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
768768
if(string.IsNullOrEmpty(mp_ApiKey))
769769
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
770770
if(string.IsNullOrEmpty(classifierName))
@@ -842,7 +842,7 @@ public bool DeleteClassifier(string classifierId, OnDeleteClassifier callback)
842842
if(callback == null)
843843
throw new ArgumentNullException("callback");
844844
if(string.IsNullOrEmpty(mp_ApiKey))
845-
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
845+
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
846846
if(string.IsNullOrEmpty(mp_ApiKey))
847847
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
848848

0 commit comments

Comments
 (0)