示例#1
0
        private Dictionary <string, double> _generateKeywordsFromParagraph(IEnumerable <string> paragraphs)
        {
            if (paragraphs != null)
            {
                string joinedParagraph = string.Join(" ", paragraphs);
                return(KeywordExtractor.Invoke(joinedParagraph));
            }

            return(new Dictionary <string, double>());
        }
示例#2
0
        private Dictionary <string, double> _synonymize(Dictionary <string, double> scoredStatements)
        {
            var updatedScoredStatements = new Dictionary <string, double>();

            var keywords = KeywordExtractor.Invoke(string.Join(" ", scoredStatements.Select(x => x.Key)));

            foreach (var sentence in scoredStatements)
            {
                var tokens = NLPExtractor.Words(sentence.Key);
                var pos    = NLPExtractor.Pos(tokens);

                string recontructedStatement = "";
                double score = sentence.Value;

                for (int idx = 0; idx < tokens.Count; idx++)
                {
                    string word = tokens[idx];

                    if (keywords.Keys.Contains(word))
                    {
                        var wordEntries = Api.Invoke(tokens[idx]);
                        wordEntries.Wait();

                        if (wordEntries != null)
                        {
                            List <DictionaryEntity> results = wordEntries.Result;
                            if (results != null && results.Count > 0)
                            {
                                string currentFunctionalLabel = MapPosToFunctionalLabel(pos[idx].ToPos());

                                if (currentFunctionalLabel != null)
                                {
                                    DictionaryEntity correctDataset = results
                                                                      .Find(x => x.Fl == currentFunctionalLabel);

                                    if (correctDataset != null)
                                    {
                                        word   = SelectRandomSynonym(correctDataset.Meta.Syns);
                                        score += 0.1;
                                    }
                                }
                            }
                        }
                    }

                    recontructedStatement += string.Format("{0} ", word);
                }

                updatedScoredStatements.Add(recontructedStatement, score);
            }

            return(scoredStatements);
        }