Пример #1
0
        /// <summary>
        /// Command function to execute the linguistic analysis, based on the given analyzers and input query
        /// Results is displayed in the UI
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecuteOperation(object obj)
        {
            var queryString = HttpUtility.ParseQueryString("analyze");

            LinguisticRequest request = new LinguisticRequest
            {
                language    = "en",
                analyzerIds = SelectedAnalyzers.Select(x => x.id).ToArray(),
                text        = InputQuery
            };

            AnalyzerResults[] results = await _webRequest.MakeRequest <LinguisticRequest, AnalyzerResults[]>(HttpMethod.Post, queryString.ToString(), request);

            if (results == null || results.Length == 0)
            {
                Result = "Could not analyze text.";
                return;
            }

            StringBuilder sb = new StringBuilder();

            foreach (AnalyzerResults analyzedResult in results)
            {
                sb.AppendFormat("{0}\n", analyzedResult.result.ToString());
            }

            Result = sb.ToString();
        }
Пример #2
0
        private async Task AnalyzeSpeechParts(IDialogContext context, string sentence)
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(String.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "643750b150eb47f79c7ef20fac882676");

            var uri = "https://westus.api.cognitive.microsoft.com/linguistics/v1.0/analyze?" + queryString;

            HttpResponseMessage response;
            var body = new LinguisticRequest {
                Language = "en", Text = sentence, AnalyzerIds = new List <string>()
            };

            //body.AnalyzerIds.Add("4fa79af1-f22c-408d-98bb-b7d7aeef7f04");
            //body.AnalyzerIds.Add("08EA174B-BFDB-4E64-987E-602F85DA7F72");
            body.AnalyzerIds.Add("22a6b758-420f-4745-8a3c-46835a67c0d2");
            var jsonBody = JsonConvert.SerializeObject(body);

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes(jsonBody);
            List <LinquisticResponse> linguisticResponse;

            try
            {
                using (var content = new ByteArrayContent(byteData))
                {
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    response = await client.PostAsync(uri, content);

                    var json = await response.Content.ReadAsStringAsync();

                    Debug.WriteLine(json);
                    linguisticResponse = JsonConvert.DeserializeObject <List <LinquisticResponse> >(json);
                }
                if (linguisticResponse != null)
                {
                    GrammarStatistics.ParseParts(linguisticResponse[0]);
                    string result  = GrammarStatistics.AnalysisResult;
                    var    message = context.MakeMessage();
                    message.Text = result.Replace("\r\n", "\n\n");
                    await context.PostAsync(message);
                }
            }
            catch (Exception ex)
            {
                // Place exception handling here.
            }
            context.Wait(this.MessageReceived);
        }
Пример #3
0
        public ActionResult Login([FromBody] LinguisticRequest linguisticRequest)
        {
            var directory = Directory.GetCurrentDirectory();

            directory = Path.Combine(directory, "Artifacts");

            var wordNet = new WordNetEngine();
            var words   = new List <String>();

            try
            {
                wordNet.AddDataSource(new StreamReader(Path.Combine(directory, "data.adj")), PartOfSpeech.Adjective);
                wordNet.AddDataSource(new StreamReader(Path.Combine(directory, "data.adv")), PartOfSpeech.Adverb);
                wordNet.AddDataSource(new StreamReader(Path.Combine(directory, "data.noun")), PartOfSpeech.Noun);
                wordNet.AddDataSource(new StreamReader(Path.Combine(directory, "data.verb")), PartOfSpeech.Verb);

                wordNet.AddIndexSource(new StreamReader(Path.Combine(directory, "index.adj")), PartOfSpeech.Adjective);
                wordNet.AddIndexSource(new StreamReader(Path.Combine(directory, "index.adv")), PartOfSpeech.Adverb);
                wordNet.AddIndexSource(new StreamReader(Path.Combine(directory, "index.noun")), PartOfSpeech.Noun);
                wordNet.AddIndexSource(new StreamReader(Path.Combine(directory, "index.verb")), PartOfSpeech.Verb);

                wordNet.Load();

                var synSetList = wordNet.GetSynSets(linguisticRequest.Word);

                if (synSetList.Count == 0)
                {
                    return(BadRequest(new { message = "No Words Found." }));
                }

                foreach (var synSet in synSetList)
                {
                    foreach (string word in synSet.Words)
                    {
                        words.Add(word);
                    }
                }


                return(Ok(words));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }