// Use this for initialization void Start() { LogSystem.InstallDefaultReactors(); Credentials credentials = new Credentials("dedf1de0-34f0-4de5-a8c3-e0006f89d577", "2G364oc4pTYU", "https://gateway.watsonplatform.net/natural-language-understanding/api"); _understand = new NaturalLanguageUnderstanding(credentials); }
private IEnumerator CreateService() { if (string.IsNullOrEmpty(_iamApikey)) { throw new WatsonException("Plesae provide IAM ApiKey for the service."); } // Create credential and instantiate service Credentials credentials = null; // Authenticate using iamApikey TokenOptions tokenOptions = new TokenOptions() { IamApiKey = _iamApikey }; credentials = new Credentials(tokenOptions, _serviceUrl); // Wait for tokendata while (!credentials.HasIamTokenData()) { yield return(null); } _service = new NaturalLanguageUnderstanding(credentials); _service.VersionDate = _versionDate; Runnable.Run(Examples()); }
void Start() { // Initialize the current emotions currentEmotions = new EmotionStruct(); LogSystem.InstallDefaultReactors(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); _speechToText = new SpeechToText(credentials); Credentials naturalLanguageUnderstandingCredentials = new Credentials() { // Original Watson NLP credentials // Username = "******", // Password = "******", Username = "******", Password = "******", Url = "https://gateway.watsonplatform.net/natural-language-understanding/api" }; _nlu = new NaturalLanguageUnderstanding(naturalLanguageUnderstandingCredentials); Active = true; StartCoroutine(coroutineA()); StartRecording(); }
void Start() { if (!Utility.GetToken(OnGetToken, _nluURL, _nluUserName, _nluPassword)) { Log.Debug("ExampleGetToken.Start()", "Failed to get token."); } LogSystem.InstallDefaultReactors(); //Speech to Text Credentials sttCredentials = new Credentials(_sttUsername, _sttPassword, _sttURL); _speechToText = new SpeechToText(sttCredentials); Active = true; //StartRecording(); //NLU Credentials nluCredentials = new Credentials(_nluUserName, _nluPassword, _nluURL) { AuthenticationToken = _nluAuthenticationToken }; _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(nluCredentials); //NLUAnalyze("I hate you so much! Analyze"); }
void Start() { LogSystem.InstallDefaultReactors(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(credentials); Runnable.Run(Examples()); }
void Start() { customFoundWords = new List <string>(); storyData = GetComponent <StoryData> (); Credentials analyze_cred = new Credentials("dfb6ed8f-ca63-4c3f-8723-95c92aebaa83", "bbNFyUD1LMDg", "https://gateway.watsonplatform.net/natural-language-understanding/api"); _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(analyze_cred); Credentials textSpeech_cred = new Credentials("4f7ef3c9-414a-463e-bd94-200da766011b", "QVPX0Zz66Dbb", "https://stream.watsonplatform.net/text-to-speech/api"); _textToSpeech = new TextToSpeech(textSpeech_cred); }
void Start() { LogSystem.InstallDefaultReactors(); if (!Utility.GetToken(OnGetTokenSST, sttUrl, sttUsername, sttPassword)) { Log.Debug("ExampleGetToken.Start()", "Failed to get token."); } if (!Utility.GetToken(OnGetTokenTTS, ttsUrl, ttsUsername, ttsPassword)) { Log.Debug("ExampleGetToken.Start()", "Failed to get token."); } if (!Utility.GetToken(OnGetTokenNLU, nluUrl, nluUsername, nluPassword)) { Log.Debug("ExampleGetToken.Start()", "Failed to get token."); } //STT Credentials credentials = new Credentials(sttUsername, sttPassword, sttUrl) { AuthenticationToken = _authenticationTokenSST }; _speechToText = new SpeechToText(credentials); Active = true; StartRecording(); //TTS Credentials ttscredentials = new Credentials(ttsUsername, ttsPassword, ttsUrl) { AuthenticationToken = _authenticationTokenTTS }; _textToSpeech = new TextToSpeech(ttscredentials); //NLU Credentials nlucredentials = new Credentials(nluUsername, nluPassword, nluUrl) { AuthenticationToken = _authenticationTokenNLU }; _naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(nlucredentials); //Canvas menu.SetActive(false); }
private IEnumerator CreateService() { // Create credential and instantiate service Credentials credentials = null; if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password)) { // Authenticate using username and password credentials = new Credentials(_username, _password, _serviceUrl); } else if (!string.IsNullOrEmpty(_iamApikey)) { // Authenticate using iamApikey TokenOptions tokenOptions = new TokenOptions() { IamApiKey = _iamApikey, IamUrl = _iamUrl }; credentials = new Credentials(tokenOptions, _serviceUrl); // Wait for tokendata while (!credentials.HasIamTokenData()) { yield return(null); } } else { throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service."); } _service = new NaturalLanguageUnderstanding(credentials); _service.VersionDate = _versionDate; readyToWork = true; }
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; }