public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); Log.Debug("TestNaturalLanguageUnderstanding", "Attempting to list environments"); if (!m_NaturalLanguageUnderstanding.GetModels((ListModelsResults resp, string data) => { Test(resp != null); m_ListModelsTested = true; })) { Log.Debug("TestNaturalLanguageUnderstanding", "Failed to list models"); } while (!m_ListModelsTested) { yield return(null); } Log.Debug("TestNaturalLanguageUnderstanding", "Attempting to analyze"); Parameters parameters = new Parameters() { text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.", return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 50, sentiment = true, emotion = true, }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true } } }; if (!m_NaturalLanguageUnderstanding.Analyze((AnalysisResults resp, string data) => { Test(resp != null); m_AnalyzeTested = true; }, parameters)) { Log.Debug("TestNaturalLanguageUnderstanding", "Failed to analyze"); } while (!m_AnalyzeTested) { yield return(null); } yield break; }
public static void nluSpeech() { LogSystem.InstallDefaultReactors(); Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to get models..."); if (!m_NaturalLanguageUnderstanding.GetModels(OnGetModels)) { Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models."); } Parameters parameters = new Parameters() { //text = "I am so mad right now, this demon is devouring me with the utmost perseverence. I am bound as a man of honor and valor to respect and commend his fastidiousness but in reality, I am not amused at all. Frankly, this whole ordeal has made me realize how power is a mere illusion.", text = RecordSpeech.speechText, return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 100, sentiment = true, emotion = true }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true }, concepts = new ConceptsOptions() { limit = 50, } } }; AnalysisResults analysisResults = new AnalysisResults() { analyzed_text = parameters.text, language = "en", sentiment = new SentimentResult() { document = new DocumentSentimentResults() { } } }; Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to analyze..."); if (!m_NaturalLanguageUnderstanding.Analyze(OnAnalyze, parameters)) { Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models."); } //else //Log.Debug ("NLU", "Nicole: " + analysisResults.sentiment.document.score); // Log.Debug ("NLU", "NicoleFuck: " + analysisResults.keywords [0]); }
private IEnumerator Examples() { Log.Debug("ExampleNaturalLanguageUnderstanding.Examples()", "attempting to get models..."); if (!_service.GetModels(OnGetModels, OnFail)) { Log.Debug("ExampleNaturalLanguageUnderstanding.GetModels()", "Failed to get models."); } while (!_getModelsTested) { yield return(null); } Parameters parameters = new Parameters() { text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.", return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 50, sentiment = true, emotion = true, }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true } } }; Log.Debug("ExampleNaturalLanguageUnderstanding.Examples()", "attempting to analyze..."); if (!_service.Analyze(OnAnalyze, OnFail, parameters)) { Log.Debug("ExampleNaturalLanguageUnderstanding.Analyze()", "Failed to get models."); } while (!_analyzeTested) { yield return(null); } Log.Debug("ExampleNaturalLanguageUnderstanding.Examples()", "Natural language understanding examples complete."); }
void Start() { LogSystem.InstallDefaultReactors(); Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to get models..."); if (!m_NaturalLanguageUnderstanding.GetModels(OnGetModels)) { Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models."); } Parameters parameters = new Parameters() { text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.", return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 50, sentiment = true, emotion = true, }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true } } }; Log.Debug("ExampleNaturalLanguageUnderstandingV1", "attempting to analyze..."); if (!m_NaturalLanguageUnderstanding.Analyze(OnAnalyze, parameters)) { Log.Debug("ExampleNaturalLanguageUnderstandingV1", "Failed to get models."); } }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL"); var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME"); var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD"); using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword)) { while (!simpleGet.IsComplete) { yield return(null); } result = simpleGet.Result; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["natural_language_understanding"]; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); // Or authenticate using token //Credentials credentials = new Credentials(_url) //{ // AuthenticationToken = _token //}; _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(credentials); Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "attempting to get models..."); if (!_naturalLanguageUnderstanding.GetModels(OnGetModels, OnFail)) { Log.Debug("TestNaturalLanguageUnderstanding.GetModels()", "Failed to get models."); } while (!_getModelsTested) { yield return(null); } Parameters parameters = new Parameters() { text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.", return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 50, sentiment = true, emotion = true, }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true } } }; Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "attempting to analyze..."); if (!_naturalLanguageUnderstanding.Analyze(OnAnalyze, OnFail, parameters)) { Log.Debug("TestNaturalLanguageUnderstanding.Analyze()", "Failed to get models."); } while (!_analyzeTested) { yield return(null); } Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "Natural language understanding examples complete."); yield break; }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; string credentialsFilepath = "../sdk-credentials/credentials.json"; // Load credentials file if it exists. If it doesn't exist, don't run the tests. if (File.Exists(credentialsFilepath)) { result = File.ReadAllText(credentialsFilepath); } else { yield break; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.GetCredentialByname("natural-language-understanding-sdk")[0].Credentials; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); // Or authenticate using token //Credentials credentials = new Credentials(_url) //{ // AuthenticationToken = _token //}; _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(credentials); _naturalLanguageUnderstanding.VersionDate = _versionDate; Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "attempting to get models..."); if (!_naturalLanguageUnderstanding.GetModels(OnGetModels, OnFail)) { Log.Debug("TestNaturalLanguageUnderstanding.GetModels()", "Failed to get models."); } while (!_getModelsTested) { yield return(null); } Parameters parameters = new Parameters() { text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.", return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 50, sentiment = true, emotion = true, }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true } } }; Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "attempting to analyze..."); if (!_naturalLanguageUnderstanding.Analyze(OnAnalyze, OnFail, parameters)) { Log.Debug("TestNaturalLanguageUnderstanding.Analyze()", "Failed to get models."); } while (!_analyzeTested) { yield return(null); } Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "Natural language understanding examples complete."); yield break; }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); try { VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; // Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format. // See https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html. var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES"); var fileContent = File.ReadAllText(environmentalVariable); // Add in a parent object because Unity does not like to deserialize root level collection types. fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(fileContent, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["natural_language_understanding"][TestCredentialIndex].Credentials; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); } catch { Log.Debug("TestNaturalLanguageUnderstanding.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication"); } // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); // Or authenticate using token //Credentials credentials = new Credentials(_url) //{ // AuthenticationToken = _token //}; _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(credentials); Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "attempting to get models..."); if (!_naturalLanguageUnderstanding.GetModels(OnGetModels, OnFail)) { Log.Debug("TestNaturalLanguageUnderstanding.GetModels()", "Failed to get models."); } while (!_getModelsTested) { yield return(null); } Parameters parameters = new Parameters() { text = "Analyze various features of text content at scale. Provide text, raw HTML, or a public URL, and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.", return_analyzed_text = true, language = "en", features = new Features() { entities = new EntitiesOptions() { limit = 50, sentiment = true, emotion = true, }, keywords = new KeywordsOptions() { limit = 50, sentiment = true, emotion = true } } }; Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "attempting to analyze..."); if (!_naturalLanguageUnderstanding.Analyze(OnAnalyze, OnFail, parameters)) { Log.Debug("TestNaturalLanguageUnderstanding.Analyze()", "Failed to get models."); } while (!_analyzeTested) { yield return(null); } Log.Debug("TestNaturalLanguageUnderstanding.RunTests()", "Natural language understanding examples complete."); yield break; }