Skip to content

Feature 85 alchemy language config #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ Change Log

_2016-06-24_

* New: Added Alchemy Language v1 abstraction
* New: Added Personality Insights v2 abstraction
* Fix: Added Tone Analyzer to the Configuration Editor
* Fix: Added Tradeoff Analytics to the Configuration Editor
* Fix: Added Conversation to the Configuration Editor
* Fix: Added Personality Insights to the Configuration Editor
* New: Added `Alchemy Language` abstraction
* New: Added `Personality Insights` abstraction
* Fix: Added `Tone Analyzer` to the Configuration Editor
* Fix: Added `Tradeoff Analytics` to the Configuration Editor
* Fix: Added `Conversation` to the Configuration Editor
* Fix: Added `Personality Insights` to the Configuration Editor
* Fix: Added `Alchemy Language` to the Configuration Editor
* Fix: Added `Visual Recognition` to the Configuration Editor

## Version 0.4.0

_2016-06-09_

* New: Added Tone Analyzer v3 abstraction
* New: Added Tradeoff Analytics abstraction
* New: Added Conversation abstraction
* New: Added Visual Recognition v3 abstraction
* New: Added `Tone Analyzer v3` abstraction
* New: Added `Tradeoff Analytics` abstraction
* New: Added `Conversation` abstraction
* New: Added `Visual Recognition v3` abstraction
* Fix: Creating test project dynamically for Travis CL integration
* Fix: Refactored Language Translation to Language Translator
* Fix: Widget examples sprite references were disconnected
Expand Down
Binary file modified Config.json.enc
Binary file not shown.
16 changes: 8 additions & 8 deletions Examples/ServiceExamples/Scripts/ExampleVisualRecognition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class ExampleVisualRecognition : MonoBehaviour {
private VisualRecognition m_VisualRecognition = new VisualRecognition();
private string m_classifierName = "Apples_OptionalParams";
private string m_classifierID = "Apples_OptionalParams_1213405640";
private string m_classifierID = "ApplesClassifierNameWithSpaces_73100404";
private string m_classifierToDelete = "unitytestclassifier2b_37849361";
private string m_imageURL = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Official_portrait_of_Barack_Obama.jpg";
private string m_imageTextURL = "http://i.stack.imgur.com/ZS6nH.png";
Expand All @@ -36,7 +36,7 @@ void Start ()
// Get all classifiers
if(!m_VisualRecognition.GetClassifiers(OnGetClassifiers))
Log.Debug("ExampleVisualRecognition", "Getting classifiers failed!");

//
// Find classifier by name
m_VisualRecognition.FindClassifier(m_classifierName, OnFindClassifier);

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

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

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

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

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

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

// Recognize text post image
string m_textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/from_platos_apology.png";
string m_textExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/from_platos_apology.png";
if(!m_VisualRecognition.RecognizeText(OnRecognizeText, m_textExamplePath))
Log.Debug("ExampleVisualRecognition", "Recognize text failed!");
}
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,7 @@ void OnMessage (DataModels.MessageResponse resp)


### Visual Recognition
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.

![visual-recognition0](http://g.recordit.co/Qke2gKfaKJ.gif)
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.

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


### Alchemy Language
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.

![alchemy-language0](http://g.recordit.co/xkGArdMVbC.gif)
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.

#### Getting Authors
You can extract Authors from a URL or HTML source.
Expand Down
40 changes: 32 additions & 8 deletions Scripts/Editor/ConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ private class ServiceSetup
new ServiceSetup() { ServiceName = "Personality Insights", ServiceAPI = "personality-insights/api",
URL ="https://console.ng.bluemix.net/catalog/services/personality-insights/", ServiceID="PersonalityInsightsV2" },
new ServiceSetup() { ServiceName = "Conversation", ServiceAPI = "conversation-experimental/api",
URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationV1" }
URL ="https://console.ng.bluemix.net/catalog/services/conversation/", ServiceID="ConversationV1" },
new ServiceSetup() { ServiceName = "Alchemy Language", ServiceAPI = "gateway-a.watsonplatform.net/calls",
URL ="https://console.ng.bluemix.net/catalog/services/alchemyapi/", ServiceID="AlchemyLanguageV1" },
new ServiceSetup() { ServiceName = "Visual Recognition", ServiceAPI = "visual-recognition/api",
URL ="https://console.ng.bluemix.net/catalog/services/visual-recognition/", ServiceID="VisualRecognitionV3" }
};

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

private bool GetIsValid(ServiceSetup setup)
{
bool isValid = false;
Config cfg = Config.Instance;
Config.CredentialInfo info = cfg.FindCredentials( setup.ServiceID );
if(info != null)
{
if((!string.IsNullOrEmpty(info.m_URL) && !string.IsNullOrEmpty(info.m_Password)) || !string.IsNullOrEmpty(info.m_Apikey))
isValid = true;
}

return isValid;
}

private void OnGUI()
{
Config cfg = Config.Instance;
Expand All @@ -205,17 +223,14 @@ private void OnGUI()
//GUILayout.Label( "Use this dialog to generate your configuration file for the Watson Unity SDK." );
//GUILayout.Label( "If you have never registered for Watson BlueMix services, click on the button below to begin registration." );

if ( GUILayout.Button( "Register for Watson Services" ) )
if(GUILayout.Button("Register for Watson Services"))
Application.OpenURL( BLUEMIX_REGISTRATION );

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

bool bValid = info != null
&& !string.IsNullOrEmpty( info.m_URL )
&& !string.IsNullOrEmpty( info.m_User )
&& !string.IsNullOrEmpty( info.m_Password );
bool bValid = GetIsValid(setup);

GUILayout.BeginHorizontal();

Expand Down Expand Up @@ -333,8 +348,17 @@ private void OnGUI()
GUILayout.EndHorizontal();

info.m_URL = EditorGUILayout.TextField("URL", info.m_URL);
info.m_User = EditorGUILayout.TextField("User", info.m_User);
info.m_Password = EditorGUILayout.TextField("Password", info.m_Password);

if(!string.IsNullOrEmpty(info.m_URL))
{
if(info.m_URL.StartsWith("https://gateway-a"))
info.m_Apikey = EditorGUILayout.TextField("API Key", info.m_Apikey);
else
{
info.m_User = EditorGUILayout.TextField("User", info.m_User);
info.m_Password = EditorGUILayout.TextField("Password", info.m_Password);
}
}

if (GUILayout.Button("Delete"))
cfg.Credentials.RemoveAt(i--);
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Services/AlchemyAPI/AlchemyLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AlchemyLanguage : IWatsonService
#region SetCredentials
private void SetCredentials()
{
mp_ApiKey = Config.Instance.GetVariableValue("ALCHEMY_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);

if (string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("ALCHEMY_API_KEY needs to be defined in config.json");
Expand Down
24 changes: 12 additions & 12 deletions Scripts/Services/VisualRecognition/VisualRecognition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class VisualRecognition : IWatsonService
public bool Classify(string url, OnClassify callback, string[] owners = default(string[]), string[] classifierIDs = default(string[]), float threshold = default(float), string acceptLanguage = "en")
{
if(string.IsNullOrEmpty(mp_ApiKey))
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
if(string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
if(string.IsNullOrEmpty(url))
Expand Down Expand Up @@ -151,7 +151,7 @@ public class VisualRecognition : IWatsonService
public bool Classify(OnClassify callback, string imagePath, string[] owners = default(string[]), string[] classifierIDs = default(string[]), float threshold = default(float), string acceptLanguage = "en")
{
if(string.IsNullOrEmpty(mp_ApiKey))
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
if(string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
if(callback == null)
Expand Down Expand Up @@ -259,7 +259,7 @@ public bool DetectFaces(string url, OnDetectFaces callback)
if(callback == null)
throw new ArgumentNullException("callback");
if(string.IsNullOrEmpty(mp_ApiKey))
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
if(string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");

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

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

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

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

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

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

Expand Down Expand Up @@ -728,7 +728,7 @@ private void OnGetClassifierResp(RESTConnector.Request req, RESTConnector.Respon
public bool TrainClassifier(string classifierName, string className, string positiveExamplesPath, string negativeExamplesPath, OnTrainClassifier callback)
{
if(string.IsNullOrEmpty(mp_ApiKey))
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
if(string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
if(string.IsNullOrEmpty(classifierName))
Expand Down Expand Up @@ -764,7 +764,7 @@ public bool TrainClassifier(string classifierName, string className, string posi
private bool UploadClassifier(string classifierName, string className, byte[] positiveExamplesData, byte[] negativeExamplesData, OnTrainClassifier callback)
{
if(string.IsNullOrEmpty(mp_ApiKey))
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
if(string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");
if(string.IsNullOrEmpty(classifierName))
Expand Down Expand Up @@ -842,7 +842,7 @@ public bool DeleteClassifier(string classifierId, OnDeleteClassifier callback)
if(callback == null)
throw new ArgumentNullException("callback");
if(string.IsNullOrEmpty(mp_ApiKey))
mp_ApiKey = Config.Instance.GetVariableValue("VISUAL_RECOGNITION_API_KEY");
mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
if(string.IsNullOrEmpty(mp_ApiKey))
throw new WatsonException("GetClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json");

Expand Down
Loading