Ejemplo n.º 1
0
    public void analyse(string inputText)
    {
        if (inputText.Trim() == "")
        {
            return;
        }
        Parameters parameters = new Parameters()
        {
            //text = "In the rugged Colorado Desert of California, there lies buried a treasure ship sailed there hundreds of years ago by either Viking or Spanish explorers. Some say this is legend; others insist it is fact. A few have even claimed to have seen the ship, its wooden remains poking through the sand like the skeleton of a prehistoric beast. Among those who say they�ve come close to the ship is small-town librarian Myrtle Botts. In 1933, she was hiking with her husband in the Anza-Borrego Desert, not far from the border with Mexico. It was early March, so the desert would have been in bloom, its washed-out yellows and grays beaten back by the riotous invasion of wildflowers. Those wildflowers were what brought the Bottses to the desert, and they ended up near a tiny settlement called Agua Caliente. Surrounding place names reflected the strangeness and severity of the land: Moonlight Canyon, Hellhole Canyon, Indian Gorge. Try Newsweek for only $1.25 per week To enter the desert is to succumb to the unknowable. One morning, a prospector appeared in the couple�s camp with news far more astonishing than a new species of desert flora: He�d found a ship lodged in the rocky face of Canebrake Canyon. The vessel was made of wood, and there was a serpentine figure carved into its prow. There were also impressions on its flanks where shields had been attached�all the hallmarks of a Viking craft. Recounting the episode later, Botts said she and her husband saw the ship but couldn�t reach it, so they vowed to return the following day, better prepared for a rugged hike. That wasn�t to be, because, several hours later, there was a 6.4 magnitude earthquake in the waters off Huntington Beach, in Southern California. Botts claimed it dislodged rocks that buried her Viking ship, which she never saw again.There are reasons to doubt her story, yet it is only one of many about sightings of the desert ship. By the time Myrtle and her husband had set out to explore, amid the blooming poppies and evening primrose, the story of the lost desert ship was already about 60 years old. By the time I heard it, while working on a story about desert conservation, it had been nearly a century and a half since explorer Albert S. Evans had published the first account. Traveling to San Bernardino, Evans came into a valley that was �the grim and silent ghost of a dead sea,� presumably Lake Cahuilla. �The moon threw a track of shimmering light,� he wrote, directly upon �the wreck of a gallant ship, which may have gone down there centuries ago.� The route Evans took came nowhere near Canebrake Canyon, and the ship Evans claimed to see was Spanish, not Norse. Others have also seen this vessel, but much farther south, in Baja California, Mexico. Like all great legends, the desert ship is immune to its contradictions: It is fake news for the romantic soul, offering passage into some ancient American dreamtime when blood and gold were the main currencies of civic life.The legend does seem, prima facie, bonkers: a craft loaded with untold riches, sailed by early-European explorers into a vast lake that once stretched over much of inland Southern California, then run aground, abandoned by its crew and covered over by centuries of sand and rock and creosote bush as that lake dried out�and now it lies a few feet below the surface, in sight of the chicken-wire fence at the back of the Desert Dunes motel, $58 a night and HBO in most rooms.Totally insane, right? Let us slink back to our cubicles and never speak of the desert ship again. Let us only believe that which is shared with us on Facebook. Let us banish forever all traces of wonder from our lives. Yet there are believers who insist that, using recent advances in archaeology, the ship can be found. They point, for example, to a wooden sloop from the 1770s unearthed during excavations at the World Trade Center site in lower Manhattan, or the more than 40 ships, dating back perhaps 800 years, discovered in the Black Sea earlier this year.",
            //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.",
            // text = "I am Happy, I am going to a beach party. ",
            text = inputText,

            return_analyzed_text = true,
            language             = "en",
            features             = new Features()
            {
                // entities = new EntitiesOptions()
                // {
                //     limit = 100,
                //     sentiment = true,
                //     emotion = true,
                // },
                keywords = new KeywordsOptions()
                {
                    limit = 1,
                    //relevance = true,
                    sentiment = true,
                    emotion   = true
                }
            }
        };

        _nlu.Analyze(OnAnalyseResponse, OnFail, parameters);
    }
Ejemplo n.º 2
0
    public void StartUnderstand()
    {
        Parameters parameters = new Parameters()
        {
            text = _questiontext.text,
            // text = "what is the weather in san jose",
            return_analyzed_text = true,
            language             = "en",
            features             = new Features()
            {
                entities = new EntitiesOptions()
                {
                    limit     = 50,
                    sentiment = false,
                    emotion   = false,
                },
                keywords = new KeywordsOptions()
                {
                    limit     = 50,
                    sentiment = false,
                    emotion   = false
                }
            }
        };

        if (!_understand.Analyze(OnAnalyze, OnFail, parameters))
        {
            Log.Debug("ExampleNaturalLanguageUnderstanding.Analyze()", "Failed to get models.");
        }
    }
        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;
        }
Ejemplo n.º 4
0
    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 Work()
    {
        _service.Analyze(OnAnalyze, OnFail, parameters);

        while (!readyToWork)
        {
            yield return(null);
        }
    }
Ejemplo n.º 6
0
    private void NLUAnalyze(string message)
    {
        Parameters parameters = CreatingParametersNLU(message);

        if (!_naturalLanguageUnderstanding.Analyze(OnAnalyze, OnFail, parameters))
        {
            Log.Debug("ExampleNaturalLanguageUnderstanding.Analyze()", "Failed to get models.");
        }
        Log.Debug("ExampleNaturalLanguageUnderstanding.Examples()", "Natural language understanding examples complete.");
    }
Ejemplo n.º 7
0
 void Update()
 {
     //When the user makes a new Request, this method is called
     if (newMessage)
     {
         newMessage = false;
         //Setting the user message as part of the parameters, needed for NLU
         parameters.text = userMessage;
         //Creating the Canvas in front of the user
         menu.gameObject.transform.position = Camera.main.transform.position + Camera.main.transform.forward;
         menu.gameObject.transform.rotation = Camera.main.transform.rotation;
         //Setting the canvas true to make it visible to the user
         menu.SetActive(true);
         //Setting assetsAppeared false, due to user not choosing an asset yet
         singleAssestDisplay.assetAppeared = false;
         //Calling NLU
         _naturalLanguageUnderstanding.Analyze(OnAnalyze, OnFail, parameters);
     }
     //When the user has choosen an asset this method is called
     if (singleAssestDisplay.assetAppeared)
     {
         //Each child is destory on the canvas panel, the reason is that if left, the childern will still appear in the next user request
         MulitAssets.destoryChildern();
         //Removing the canvas after the user choosen their asset
         menu.SetActive(false);
     }
     //When the user request came in, this method is called
     if (MulitAssets.creatingAssestsMessageFlag)
     {
         //Setting the flag to false
         MulitAssets.creatingAssestsMessageFlag = false;
         //Invoking TTS
         string ttsString = "I have found " + MulitAssets.numberOfAssetsFoundFromPoly + " objects that match your request";
         Synthesize(ttsString);
     }
     //When the user has choosen an asset this method is called
     if (singleAssestDisplay.assetGenerate)
     {
         string ttsString = singleAssestDisplay.assetName.ToString() + " ... Is there anything else you want to create?";
         Synthesize(ttsString);
         singleAssestDisplay.assetGenerate = false;
     }
 }
Ejemplo n.º 8
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.");
    }
Ejemplo n.º 9
0
    IEnumerator Analyze()
    {
        Debug.Log("analyzing story");
        List <string> apiChunks = GetChunksFromStory();

        loadingChunk = true;

        foreach (string chunk in apiChunks)
        {
            //Analyze chunk
            Parameters p = GetAnalyzeParams(chunk);
            customAnalyze(chunk);
            _naturalLanguageUnderstanding.Analyze(OnAnalyze, OnFail, p);
            yield return(new WaitWhile(() => loadingChunk));

            loadingChunk = true;
        }
        Debug.Log("Story analyzed!");
        Debug.Log("Adding debug text");
        GetDebugText();
        startNarration();
    }
Ejemplo n.º 10
0
    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;
        }