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); }
protected override Dictionary <string, double> ExtractKeywords(string statement) { return(NLPExtractor.KeywordsByFrequency(statement, OmittedTokens, 50)); }
public Dictionary <string, double> Invoke(Dictionary <string, double> scoredStatements) { string statement = string.Join(",", scoredStatements.Select(x => x.Key).Select(x => x.ToString()).ToArray()); return(NLPExtractor.KeywordsByFrequency(statement, OmittedTokens, 50, scoredStatements)); }