Exemplo n.º 1
0
 public FoundedTerm(SenteneType senteneType, TermType termType, string term, int amount, double exactHit, double similiarHit, double synonymHit)
 {
     this.SenteneType = senteneType;
     this.Term        = term;
     this.TermType    = termType;
     this.Amount      = amount;
     this.ExactHit    = exactHit;
     this.SimiliarHit = similiarHit;
     this.SynonymHit  = synonymHit;
 }
        private void AddHitsToFoundedTerms(List <string> foundedWords, SenteneType sentenceType, TermType termType)
        {
            if (foundedWords.Count > 0)
            {
                var numberGroups = foundedWords.GroupBy(w => w.ToLower());
                foreach (var grp in numberGroups)
                {
                    var foundedTerm = grp.Key;
                    var total       = grp.Count();

                    this.FoundedTerms.Add(new FoundedTerm(sentenceType, termType, foundedTerm, total, 3, 2, 1));
                }
            }
        }
        private void GetSentenceResult(Sentence sentence, List <SearchWord> searchWords, SenteneType sentenceType, bool alsoSynonyms)
        {
            List <string> foundedWords = new List <string>();
            List <string> words        = sentence.SplitSentenceIntoWords();

            foreach (SearchWord searchWord in searchWords)
            {
                int count = 0;

                // Search for exact match in sentence.
                count = words.Where(w => w.ToLower() == searchWord.Term.ToLower()).Count();
                if (count > 0)
                {
                    this.FoundedTerms.Add(new FoundedTerm(sentenceType, TermType.Exact, searchWord.Term, count, 3, 2, 1));
                }

                // Search for similiar word in sentence.
                foundedWords = words.Where(w => Fastenshtein.Levenshtein.Distance(w.ToLower(), searchWord.Term.ToLower()) == 1).ToList();
                this.AddHitsToFoundedTerms(foundedWords, sentenceType, TermType.Similar);

                // Search for synonyms in sentence.
                if (alsoSynonyms)
                {
                    foundedWords = new List <string>();
                    foundedWords = words.Where(w => BackgroundTasks.CheckIfWordISynonyms(w, searchWord)).ToList();
                    this.AddHitsToFoundedTerms(foundedWords, sentenceType, TermType.Synonym);
                }
            }
        }