public List <Stopword> UpdateStopword(Guid id, Stopword stopword)
        {
            var stopwords = new List <Stopword>();
            var owners    = System.IO.File.ReadAllLines(_stopwordsFile);

            if (!owners.Any())
            {
                return(stopwords);
            }

            stopwords = JsonConvert.DeserializeObject <List <Stopword> >(owners.First());
            var existedStopword = stopwords.FirstOrDefault(p => p.Id == id);

            if (existedStopword == null)
            {
                throw new EntryPointNotFoundException("لیست توقف یافت نشد.");
            }

            existedStopword.Content = stopword.Content;
            existedStopword.Title   = stopword.Title;

            var fileWriter = new System.IO.StreamWriter(_stopwordsFile);

            fileWriter.WriteLine(JsonConvert.SerializeObject(stopwords));
            fileWriter.Dispose();
            return(stopwords);
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        private Dictionary <string, int> CalculateOccurrence(string text, string option = null)
        {
            Dictionary <string, int> occurrence = new Dictionary <string, int>();

            if (!string.IsNullOrEmpty(option) && option.Equals("link", StringComparison.OrdinalIgnoreCase))
            {
                char[]   delimiters = { '|' };
                string[] words      = text.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                Uri uriResult;
                foreach (var word in words)
                {
                    bool isValidLink = Uri.TryCreate(word, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

                    if (isValidLink)
                    {
                        if (!occurrence.ContainsKey(word))
                        {
                            occurrence.Add(word, 1);
                        }
                        else
                        {
                            occurrence[word] += 1;
                        }
                    }
                }
            }
            else
            {
                Regex wordMatcher = new Regex(@"\p{L}+");
                var   words       = wordMatcher.Matches(text).Select(c => c.Value);

                var stopwords = new Stopword().Stopwords;

                foreach (string word in words)
                {
                    string w = word.ToLower().Trim();

                    if (!stopwords.ContainsKey(w))
                    {
                        if (!occurrence.ContainsKey(w))
                        {
                            occurrence.Add(w, 1);
                        }
                        else
                        {
                            occurrence[w] += 1;
                        }
                    }
                }
            }

            return(occurrence);
        }
        public IActionResult Post(Guid id, [FromBody] StopwordCreateViewModel model)
        {
            var stopword = new Stopword()
            {
                Id      = id,
                Title   = model.Title,
                Content = model.Content
            };
            var stopwords = _stopwordService.UpdateStopword(id, stopword);

            return(Ok(stopwords));
        }
        public IActionResult Post([FromBody] StopwordCreateViewModel model)
        {
            var stopword = new Stopword()
            {
                Id      = Guid.NewGuid(),
                Title   = model.Title,
                Content = model.Content
            };
            var stopwords = _stopwordService.CreateStopword(stopword);

            return(Ok(stopwords));
        }
        public List <Stopword> CreateStopword(Stopword stopword)
        {
            var stopwords = new List <Stopword>();
            var owners    = System.IO.File.ReadAllLines(_stopwordsFile);

            if (owners.Any())
            {
                stopwords = JsonConvert.DeserializeObject <List <Stopword> >(owners.First());
            }

            stopwords.Add(stopword);
            var fileWriter = new System.IO.StreamWriter(_stopwordsFile);

            fileWriter.WriteLine(JsonConvert.SerializeObject(stopwords));
            fileWriter.Dispose();
            return(stopwords);
        }
Ejemplo n.º 7
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);
        }