Exemplo n.º 1
0
        public static async Task <List <AzureSentiment> > VaderSentimentAnalytics(Docs json, string score_type, bool stopword)
        {
            SentimentIntensityAnalyzer analyzer = new SentimentIntensityAnalyzer();



            List <AzureSentiment> azureSentiments = new List <AzureSentiment> {
            };


            foreach (var item in json.documents)
            {
                string text = item.text;

                if (stopword)
                {
                    //if stops words, clean the text.
                    text = Stopword.cleaner(item.text);
                }

                var score = analyzer.PolarityScores(text);
                var type  = new Hashtable {
                    { "compound", score.Compound },
                    { "neutral", score.Neutral },
                    { "positive", score.Positive },
                    { "negative", score.Negative }
                };

                azureSentiments.Add(new AzureSentiment {
                    id = item.id, score = (double)type[score_type]
                });
            }

            return(azureSentiments.ToList());
        }
Exemplo n.º 2
0
        public ActionResult <IList> PostActualizerKeyPrhases([FromBody] DocsWithTime json, int wordthreshold = 1, bool stopword = false)
        {
            Docs jsonDoc = JsonSerializer.Deserialize <Docs>(JsonSerializer.Serialize(json));

            IList <string> keywordsList;



            if (stopword)
            {
                keywordsList = jsonDoc.documents.Select(s => Stopword.cleaner(s.text)).ToList();
            }
            else
            {
                keywordsList = jsonDoc.documents.Select(s => s.text).ToList();
            }


            List <string> keywordsLake = new List <string> {
            };

            var keywordArray = String.Join(",", keywordsList).ToLowerInvariant().Split(' ');

            foreach (var sentence in keywordArray)
            {
                var splitSentence = sentence.Split(",").ToArray();
                keywordsLake.AddRange(splitSentence);
            }


            var keywords = keywordsLake.GroupBy(x => x)
                           .Where(g => g.Count() >= wordthreshold)
                           .Select(y => new { word = y.Key, count = y.Count() }).OrderBy(o => o.count).Where(w => !string.IsNullOrWhiteSpace(w.word)).ToList();

            var srm = _db.SearchResultsMetadata.First();

            srm.keywordsExtracted = srm.keywordsExtracted + keywords.Count;
            _db.SaveChangesAsync();

            return(keywords);
        }