SNCT.JudgeOfRelevancy.get_direct_relevance C# (CSharp) Method

get_direct_relevance() public method

public get_direct_relevance ( String text, String query, HashSet query_content_words ) : double
text String
query String
query_content_words HashSet
return double
        public double get_direct_relevance(String text, String query, HashSet<String> query_content_words)
        {
            String[] query_category_words = get_category_words_of(query);
            String[] text_words = text.Split();
            double score = 0.0;
            foreach(String word in text_words)
            {
                double category_score = 0.0, content_score = 0.0;
                foreach (String category_word in query_category_words) { category_score += get_word_similarity(word, category_word); }
                foreach (String content_word in query_content_words) { content_score += get_word_similarity(word, content_word); }
                score += category_score / Math.Pow(query_category_words.Count(), 0.5) + // 0.5 because length doesn't really matter
                         content_score / Math.Pow(query_content_words.Count(), 1.0);    // 1.0 as standard scaling power
            }
            return score / Math.Pow(text_words.Count(), 1.5);                           // 1.5 to penalize long sentences
        }
    }

Usage Example

Example #1
0
 public Phrase ensure_phrase(String text)
 {
     if (!phrases.ContainsKey(text))
     {
         double rel = JoR.get_direct_relevance(text, query, query_content_words);
         phrases.Add(text, new Phrase(text, rel));
     }
     return(phrases[text]);
 }