public void Analyze()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var features = new Features()
            {
                Keywords = new KeywordsOptions()
                {
                    Limit     = 2,
                    Sentiment = true,
                    Emotion   = true
                },
                Entities = new EntitiesOptions()
                {
                    Sentiment = true,
                    Limit     = 2
                }
            };

            var result = service.Analyze(
                features: features,
                text: "IBM is an American multinational technology company headquartered in Armonk, New York, United States, with operations in over 170 countries."
                );

            Console.WriteLine(result.Response);
        }
        public void AnalyzeWithSentiment()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                url: "www.wsj.com/news/markets",
                features: new Features()
            {
                Sentiment = new SentimentOptions()
                {
                    Targets = new List <string>()
                    {
                        "stocks"
                    }
                }
            }
                );

            Console.WriteLine(result.Response);
        }
        public void AnalyzeWithSyntax()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                text: "With great power comes great responsibility",
                features: new Features()
            {
                Syntax = new SyntaxOptions()
                {
                    Sentences = true,
                    Tokens    = new SyntaxOptionsTokens()
                    {
                        Lemma        = true,
                        PartOfSpeech = true
                    }
                }
            }
                );

            Console.WriteLine(result.Response);
        }
        public void AnalyzeWithKeywords()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                url: "www.ibm.com",
                features: new Features()
            {
                Keywords = new KeywordsOptions()
                {
                    Sentiment = true,
                    Emotion   = true,
                    Limit     = 2
                }
            }
                );

            Console.WriteLine(result.Response);
        }
        public void AnalyzeWithEmotion()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                html: "<html><head><title>Fruits</title></head><body><h1>Apples and Oranges</h1><p>I love apples! I don't like oranges.</p></body></html>",
                features: new Features()
            {
                Emotion = new EmotionOptions()
                {
                    Targets = new List <string> {
                        "apples", "oranges"
                    }
                }
            }
                );

            Console.WriteLine(result.Response);
        }
        public void ListModels()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.ListModels();

            Console.WriteLine(result.Response);
        }
        //[TestMethod]
        public void TestIcp4d_Success()
        {
            var url         = "";
            var username    = "";
            var password    = "";
            var versionDate = "";
            CloudPakForDataAuthenticator        cloudPakForDataAuthenticator = new CloudPakForDataAuthenticator(url: url, username: username, password: password, disableSslVerification: true);
            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService(versionDate: versionDate, authenticator: cloudPakForDataAuthenticator);

            service.SetServiceUrl("");
            var listWorkspaceResult = service.ListModels();

            Assert.IsNotNull(listWorkspaceResult);
            Assert.IsNotNull(listWorkspaceResult.Result);
            Assert.IsNotNull(listWorkspaceResult.Result.Models);
        }
        public DetailedResponse <AnalysisResults> GetAnalysis(string text)
        {
            string apiKey      = _appConfiguration["WatsonAPIs:NLU:Key"];
            string version     = _appConfiguration["WatsonAPIs:NLU:Version"];
            string instanceURL = _appConfiguration["WatsonAPIs:NLU:InstanceURL"];
            string modelId     = _appConfiguration["WatsonAPIs:NLU:ModelId"];

            //Check settings are OK
            if (String.IsNullOrEmpty(apiKey) || String.IsNullOrEmpty(version) || String.IsNullOrEmpty(instanceURL))
            {
                throw new Exception("Invalid NLU API configuration. Please check appsettings.json.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: apiKey);
            NaturalLanguageUnderstandingService naturalLanguageUnderstanding = new NaturalLanguageUnderstandingService(version, authenticator);

            naturalLanguageUnderstanding.SetServiceUrl(instanceURL);

            //Specify the features we want to receive
            var features = new Features()
            {
                Keywords = new KeywordsOptions()
                {
                    Limit = 20,
                },
                Entities = new EntitiesOptions()
                {
                    Limit = 60
                },
                Categories = new CategoriesOptions()
                {
                    Limit = 20
                }
            };

            //Use our custom model for identifying entities
            if (!String.IsNullOrEmpty(modelId))
            {
                features.Entities.Model = modelId;
            }

            return(naturalLanguageUnderstanding.Analyze(
                       features: features,
                       text: text
                       ));
        }
        public void AnalyzeWithSemanticRoles()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                text: "IBM has one of the largest workforces in the world",
                features: new Features()
            {
                SemanticRoles = new SemanticRolesOptions()
            }
                );

            Console.WriteLine(result.Response);
        }
        public void AnalyzeWithRelations()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                text: "Leonardo DiCaprio won Best Actor in a Leading Role for his performance.",
                features: new Features()
            {
                Relations = new RelationsOptions()
            }
                );

            Console.WriteLine(result.Response);
        }
        public void AnalyzeWithMetadata()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}"
                );

            NaturalLanguageUnderstandingService service = new NaturalLanguageUnderstandingService("2019-07-12", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            var result = service.Analyze(
                url: "www.ibm.com",
                features: new Features()
            {
                Metadata = new FeaturesResultsMetadata()
            }
                );

            Console.WriteLine(result.Response);
        }
示例#12
0
        private IEnumerator CreateService()
        {
            if (string.IsNullOrEmpty(iamApikey))
            {
                throw new IBMException("Please add IAM ApiKey to the Iam Apikey field in the inspector.");
            }

            IamAuthenticator authenticator = new IamAuthenticator(apikey: iamApikey);

            while (!authenticator.CanAuthenticate())
            {
                yield return(null);
            }

            service = new NaturalLanguageUnderstandingService(versionDate, authenticator);
            if (!string.IsNullOrEmpty(serviceUrl))
            {
                service.SetServiceUrl(serviceUrl);
            }
        }
            public async Task <Result <List <AnalysisResults> > > Handle(Contract request, CancellationToken cancellationToken)
            {
                if (request.texts.Count == 0)
                {
                    return(Result.Fail <List <AnalysisResults> >("Não foi possivél encontrar uma lista de palavras"));
                }

                IamAuthenticator authenticator = new IamAuthenticator(
                    apikey: _configuration[$"Watson:apikey"]
                    );

                NaturalLanguageUnderstandingService naturalLanguageUnderstanding = new NaturalLanguageUnderstandingService("2021-03-25", authenticator);

                naturalLanguageUnderstanding.SetServiceUrl(_configuration[$"Watson:url"]);

                var features = new Features()
                {
                    Syntax = new SyntaxOptions()
                    {
                        Sentences = true,
                        Tokens    = new SyntaxOptionsTokens()
                        {
                            Lemma        = true,
                            PartOfSpeech = true
                        }
                    },
                    Categories = new CategoriesOptions()
                    {
                        Limit = 3
                    },
                    Keywords = new KeywordsOptions()
                    {
                        Sentiment = true,
                        Emotion   = true,
                        Limit     = 2
                    },
                    Sentiment = new SentimentOptions()
                    {
                        Document = true
                    },
                    Emotion = new EmotionOptions()
                    {
                        Document = true
                    }
                };
                var listResult = new List <AnalysisResults>();

                foreach (var text in request.texts)
                {
                    var result = naturalLanguageUnderstanding.Analyze(
                        features: features,
                        returnAnalyzedText: true,
                        language: "pt",
                        text: text
                        );

                    listResult.Add(result.Result);
                }



                return(Result.Ok(listResult));
            }