예제 #1
0
 private static void GetSource(Answer SourceObject, BasePage basePage)
 {
     List<Answer> localAnswers = SourceObject.GetAnswer(basePage);
     if (localAnswers != null && localAnswers.Count > 0)
     {
         lock (locker)
         {
             basePage.FinalAnswers.InsertRange(0, localAnswers);
         }
     }
 }
예제 #2
0
        public void GetFeatures(Answer answer)
        {
            try
            {
                if (answer == null)
                    return;
                answer.features = new Features();
                answer.features.titleDifference = Util.CosineDistance(answer.question.ToLower().Split(' '), this.query.ToLower().Split(' '));
                answer.features.titleLengthDifference = Math.Abs(answer.question.Length - this.query.Length);
                answer.features.queryInTitle = answer.question.Contains(this.query) ? 1 : 0;
                answer.features.queryInResponse = answer.TopAnswer.Contains(this.query) ? 1 : 0;
                int questionLength = answer.question.Split(' ').Length;
                int queryLength = this.query.Split(' ').Length;
                answer.features.questionLengthRatio = (double)Math.Min(questionLength, queryLength) / Math.Max(questionLength, queryLength);
                answer.features.responseLength = answer.topAnswer.Split(' ').Length;

                if (answer.questionFileTime != 0)
                    answer.features.creationTimeDifference = (DateTime.Now - DateTime.FromFileTimeUtc(answer.questionFileTime)).Days;
                else
                    answer.features.creationTimeDifference = 500;// a average number to obtain final score for this as 0.5
                if (answer.updatedFileTime != 0)
                    answer.features.lastResponseTimeDifference = (DateTime.Now - DateTime.FromFileTimeUtc(answer.updatedFileTime)).Days;
                else
                    answer.features.lastResponseTimeDifference = 500;// a average number to obtain final score for this as 0.5
                answer.features.responseVotes = answer.answerVotes;
                answer.features.totalVotes = answer.totalVotes;
                answer.features.voteRatio = (answer.answerVotes + 1) / (answer.totalVotes + 1);
                answer.features.sourceWeight = (sourceWeights.Keys.Contains(answer.source)) ? sourceWeights[answer.source] : 0;
                answer.features.containsSteps = (answer.topAnswer.Contains("<li>")) ? 1 : 0;
                Regex r = new Regex("<li>", RegexOptions.IgnoreCase);
                answer.features.noSteps = r.Matches(answer.TopAnswer).Count;

                r = new Regex(spechialCharPattern, RegexOptions.IgnoreCase);
                string[] questionwords = r.Replace(answer.question.ToLower(), "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                List<string> questionTags = tagger.Tag(questionwords).ToList<string>();
                // Relevant Question words are words with stop words removed
                List<string> relevantQuestionWords = questionwords.Where((s, i) => !Ranker.irrelevantTags.Contains(questionTags[i])).ToList<string>();
                // feature to see how many words are relevant
                answer.features.relevantWordsRatio = (double)questionwords.Where(s => this.relevantQueryTerms.Contains(s)).Count() / questionwords.Count();
                // check if the question words contain the query words
                answer.features.relevantStringPresent = string.Join(" ", relevantQuestionWords).Contains(String.Join(" ", this.relevantQueryTerms)) ? 1 : 0;
                answer.features.relevantStringPresent = string.Join(" ", this.relevantQueryTerms).Contains(String.Join(" ", relevantQuestionWords)) ? 1 : 0;
                answer.features.relevantStringPresent = Math.Max(answer.features.relevantStringPresent, 1);

                answer.features.questionWordsMatchCount = questionwords.Where((s, i) => WHTags.Contains(questionTags[i])).Intersect(this.queryWords.Where((s, i) => WHTags.Contains(queryTags[i]))).Count();

                // Check if the Noun Words present in the query are present in the question
                List<string> NounQuestionWords = questionwords.Where((s, i) => Ranker.NNTags.Contains(questionTags[i])).ToList<string>();
                List<string> NounQueryWords = this.queryWords.Where((s, i) => WHTags.Contains(this.queryTags[i])).ToList<string>();
                answer.features.nounWordsPresent = string.Join(" ", NounQuestionWords).Contains(String.Join(" ", NounQueryWords)) ? 1 : 0;

                // Check if the verb Words present in the query are present in the question
                List<string> VerbQuestionWords = questionwords.Where((s, i) => Ranker.VBTags.Contains(questionTags[i])).ToList<string>();
                List<string> VerbQueryWords = this.queryWords.Where((s, i) => Ranker.VBTags.Contains(this.queryTags[i])).ToList<string>();
                // computing common verb counts; if either question or query doesnt have a verb then we give it a score of 1
                if (VerbQuestionWords.Count() == 0 || VerbQueryWords.Count() == 0)
                    answer.features.verbWordsPresent = 1;
                else
                    answer.features.verbWordsPresent = VerbQueryWords.Intersect(VerbQuestionWords).Count() / (VerbQueryWords.Count() + VerbQuestionWords.Count() + 0.0);

                answer.features.staticScore = answer.staticScore;

                answer.score = GetScore(answer.features);
            }
            catch (Exception)
            {
                answer.score = 0;
            }
        }