Exemplo n.º 1
0
        private List <string> DetectKeyPhrases(string text)
        {
            List <string> keyPhrases = new List <string>();

            if (text.Length > 2500)
            {
                text = text.Substring(0, 2499);
            }

            AmazonComprehendClient comprehendClient = new AmazonComprehendClient(AWS_KEY, AWS_SECRET, Amazon.RegionEndpoint.USWest2);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectKeyPhrases");
            DetectKeyPhrasesRequest detectKeyPhrasesRequest = new DetectKeyPhrasesRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };

            DetectKeyPhrasesResponse detectKeyPhrasesResponse = comprehendClient.DetectKeyPhrasesAsync(detectKeyPhrasesRequest).Result;

            if (detectKeyPhrasesResponse.HttpStatusCode == System.Net.HttpStatusCode.OK && detectKeyPhrasesResponse.KeyPhrases != null)
            {
                keyPhrases = (from kp in detectKeyPhrasesResponse.KeyPhrases
                              where kp.Score >= MINIMUM_THRESHOLD_SCORE
                              select kp.Text).ToList();
            }

            return(keyPhrases);
        }
        public async Task <List <KeyPhrase> > DetermineTopic(string text)
        {
            DetectKeyPhrasesRequest request = new DetectKeyPhrasesRequest()
            {
                LanguageCode = "en",
                Text         = text
            };
            DetectKeyPhrasesResponse response = await config.AzComprehendClient.DetectKeyPhrasesAsync(request);

            var result = new List <KeyPhrase>();

            // Filter using a score of .9 as the threshold
            if (response != null && response.KeyPhrases.Count > 0)
            {
                foreach (var phrase in response.KeyPhrases)
                {
                    if (phrase.Score > -.7 && phrase.Text.Length > 4)
                    {
                        Console.WriteLine($"=== Phrase [{phrase.Text}] score: {phrase.Score}");
                        var str = phrase.Text;
                        phrase.Text = str.Remove(1).ToUpper() + str.Remove(0, 1).ToLower();
                        result.Add(phrase);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        internal virtual DetectKeyPhrasesResponse DetectKeyPhrases(DetectKeyPhrasesRequest request)
        {
            var marshaller   = new DetectKeyPhrasesRequestMarshaller();
            var unmarshaller = DetectKeyPhrasesResponseUnmarshaller.Instance;

            return(Invoke <DetectKeyPhrasesRequest, DetectKeyPhrasesResponse>(request, marshaller, unmarshaller));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            // Log into client with credentials
            AmazonComprehendClient client = new AmazonComprehendClient(Amazon.RegionEndpoint.USEast1);

            // Load XML doc
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load("phrases.xml");
            XmlElement  rootElement   = xmlDoc.DocumentElement;
            XmlNodeList rootsChildren = rootElement.ChildNodes;

            foreach (XmlNode node in rootsChildren)
            {
                DetectKeyPhrasesRequest request = new DetectKeyPhrasesRequest
                {
                    Text         = node.InnerText,
                    LanguageCode = "en"
                };

                DetectKeyPhrasesResponse response = client.DetectKeyPhrases(request);
                Console.WriteLine(node.InnerText);
                foreach (KeyPhrase kp in response.KeyPhrases)
                {
                    Console.Write("\t" + kp.Text + " (" + kp.Score + ") \n");
                }
                Console.WriteLine();
            }

            Console.ReadLine();
        }
Exemplo n.º 5
0
        private static string DetectKeyPhrases(string text, AmazonComprehendClient comprehendClient)
        {
            var stringBuilder = new StringBuilder();

            var detectKeyPhrasesRequest = new DetectKeyPhrasesRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };

            var detectKeyPhrasesResponse = comprehendClient.DetectKeyPhrases(detectKeyPhrasesRequest);

            stringBuilder.AppendLine("Detect Key Phrases:");
            stringBuilder.AppendLine("==========================");

            foreach (var keyPhrase in detectKeyPhrasesResponse.KeyPhrases)
            {
                stringBuilder.AppendLine(string.Format("Text: {0}, Score: {1}, BeginOffset: {2}, EndOffset: {3}",
                                                       keyPhrase.Text, keyPhrase.Score, keyPhrase.BeginOffset, keyPhrase.EndOffset));
            }

            Console.WriteLine("DetectKeyPhrases => Done\n");

            return(stringBuilder.ToString());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initiates the asynchronous execution of the DetectKeyPhrases operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the DetectKeyPhrases operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/comprehend-2017-11-27/DetectKeyPhrases">REST API Reference for DetectKeyPhrases Operation</seealso>
        public virtual Task <DetectKeyPhrasesResponse> DetectKeyPhrasesAsync(DetectKeyPhrasesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new DetectKeyPhrasesRequestMarshaller();
            var unmarshaller = DetectKeyPhrasesResponseUnmarshaller.Instance;

            return(InvokeAsync <DetectKeyPhrasesRequest, DetectKeyPhrasesResponse>(request, marshaller,
                                                                                   unmarshaller, cancellationToken));
        }
Exemplo n.º 7
0
        public async Task <DetectKeyPhrasesResponse> GetKeyPhrase(string text, DominantLanguage language)
        {
            var request = new DetectKeyPhrasesRequest()
            {
                Text         = text,
                LanguageCode = language.LanguageCode
            };
            var response = await _Client.DetectKeyPhrasesAsync(request);

            return(response);
        }
Exemplo n.º 8
0
        public DataTable KeyPhrases(string Text, string Encoding = "en")
        {
            DataTable DT = null;
            DetectKeyPhrasesRequest request = new DetectKeyPhrasesRequest();

            request.LanguageCode = Encoding;
            request.Text         = Text;
            AmazonComprehendClient client = new AmazonComprehendClient(AccessKeyId, SecretAccessKey, Amazon.RegionEndpoint.USWest2);
            var RES = client.DetectKeyPhrases(request);

            DT           = FromEntity(RES.KeyPhrases);
            DT.TableName = "KeyPhrases";
            return(DT);
        }
Exemplo n.º 9
0
        private void getKeyPhrases(string mailbody)
        {
            const string collectionUri = "https://dev.azure.com/codeletehackathon";
            const string projectName   = "secondproject";
            const string repoName      = "secondproject";
            const string pat           = "4rm4d2q2wq452n7ce2mqgfj4yyqajoipmez63nvxoveijuphckxq";

            var creds = new VssBasicCredential(string.Empty, pat);

            // Connect to Azure DevOps Services
            var connection = new VssConnection(new Uri(collectionUri), creds);

            // Get a GitHttpClient to talk to the Git endpoints
            var gitClient = connection.GetClient <GitHttpClient>();

            // Get data about a specific repository
            var    repo           = gitClient.GetRepositoryAsync(projectName, repoName).Result;
            var    repoid         = repo.Id;
            string collectionuris = "https://dev.azure.com/codeletehackathon/secondproject/_apis/git/repositories/506f6d44-0a42-4a10-9f75-c89c450c3740/commits?api-version=6.0";

            //String text = "Thank you for helping your project manager, Angela Parmar, on the latest project. Your work reflects your dedication to the project and the organisation.";

            AmazonComprehendClient comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectKeyPhrases");
            DetectKeyPhrasesRequest detectKeyPhrasesRequest = new DetectKeyPhrasesRequest()
            {
                Text         = mailbody,
                LanguageCode = "en"
            };
            DetectKeyPhrasesResponse detectKeyPhrasesResponse = comprehendClient.DetectKeyPhrases(detectKeyPhrasesRequest);
            DetectSyntaxRequest      dsr;
            DetectSyntaxResponse     dsresp;
            List <string>            lkeyPhrases = new List <string>();
            string strKeyPhrases = string.Empty;

            foreach (KeyPhrase kp in detectKeyPhrasesResponse.KeyPhrases)
            {
                lkeyPhrases.Add(kp.Text);
                strKeyPhrases = strKeyPhrases + ',' + kp.Text;
            }
            var values = new object[2];

            values[0] = "Key Phrases";
            values[1] = strKeyPhrases.Substring(1);
            dtTextAnalytic.Rows.Add(values);
            Console.WriteLine("Done");
        }
Exemplo n.º 10
0
        private async Task <string> GetComprehendData(string transcriptText, string key)
        {
            JObject transcriptJSON        = JObject.Parse(transcriptText);
            string  test                  = (string)transcriptJSON["Text"];
            AmazonComprehendClient client = new AmazonComprehendClient();


            DetectEntitiesRequest entitiesRequest = new DetectEntitiesRequest();

            entitiesRequest.LanguageCode = LanguageCode.En;
            entitiesRequest.Text         = test;



            DetectSentimentRequest sentimentRequest = new DetectSentimentRequest();

            sentimentRequest.LanguageCode = LanguageCode.En;
            sentimentRequest.Text         = test;

            DetectKeyPhrasesRequest keyPhrasesRequest = new DetectKeyPhrasesRequest();

            keyPhrasesRequest.LanguageCode = LanguageCode.En;
            keyPhrasesRequest.Text         = test;

            DetectEntitiesResponse entitiesResponse = await client.DetectEntitiesAsync(entitiesRequest);

            DetectSentimentResponse setimentResponse = await client.DetectSentimentAsync(sentimentRequest);

            DetectKeyPhrasesResponse keyPhrasesResponse = await client.DetectKeyPhrasesAsync(keyPhrasesRequest);


            CreateKeyPhraseCSV(key, keyPhrasesResponse);
            CreateSetimentJSON(key, setimentResponse);



            //now send the file to s3

            //we need to write two different files, one for setiment and one for Key Phrases.

            return(string.Empty);
        }
Exemplo n.º 11
0
        public static void Sample()
        {
            String text = "It is raining today in Seattle";

            var comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectKeyPhrases");
            var detectKeyPhrasesRequest = new DetectKeyPhrasesRequest()
            {
                Text         = text,
                LanguageCode = "en"
            };
            var detectKeyPhrasesResponse = comprehendClient.DetectKeyPhrases(detectKeyPhrasesRequest);

            foreach (var kp in detectKeyPhrasesResponse.KeyPhrases)
            {
                Console.WriteLine("Text: {1}, Type: {1}, BeginOffset: {2}, EndOffset: {3}",
                                  kp.Text, kp.Text, kp.BeginOffset, kp.EndOffset);
            }
            Console.WriteLine("Done");
        }
Exemplo n.º 12
0
        /// <summary>
        /// This method calls the Amazon Comprehend method DetectKeyPhrasesAsync
        /// to detect any key phrases in the sample text.
        /// </summary>
        public static async Task Main()
        {
            string text = "It is raining today in Seattle";

            var comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2);

            // Call DetectKeyPhrases API
            Console.WriteLine("Calling DetectKeyPhrases");
            var detectKeyPhrasesRequest = new DetectKeyPhrasesRequest()
            {
                Text         = text,
                LanguageCode = "en",
            };
            var detectKeyPhrasesResponse = await comprehendClient.DetectKeyPhrasesAsync(detectKeyPhrasesRequest);

            foreach (var kp in detectKeyPhrasesResponse.KeyPhrases)
            {
                Console.WriteLine($"Text: {kp.Text}, Score: {kp.Score}, BeginOffset: {kp.BeginOffset}, EndOffset: {kp.EndOffset}");
            }

            Console.WriteLine("Done");
        }