Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
APDPlat - Application Product Development Platform Copyright (c) 2013, 杨尚川, yang-shangchuan@qq.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 
 package org.apdplat.qa.score.answer;
 
 import java.util.List;
 
对候选答案进行评分 【最小词距评分组件】 分值=原分值*(1/词距) 候选答案的距离=候选答案和每一个问题词的最小距离之和

Author(s):
杨尚川
 
 
     private static final Logger LOG = LoggerFactory.getLogger(TermDistanceMiniCandidateAnswerScore.class);
     private ScoreWeight scoreWeight = new ScoreWeight();
 
     @Override
     public void setScoreWeight(ScoreWeight scoreWeight) {
         this. = scoreWeight;
     }
 
     @Override
     public void score(Question questionEvidence evidenceCandidateAnswerCollection candidateAnswerCollection) {
         .debug("*************************");
         .debug("最小词距评分开始");
         //1、对问题进行分词
         List<StringquestionTerms = question.getTerms();
         //2、对证据进行分词
         List<Termterms = Tools.getTerms(evidence.getTitle() + "," + evidence.getSnippet());
         for (CandidateAnswer candidateAnswer : candidateAnswerCollection.getAllCandidateAnswer()) {
             //3、计算候选答案的词距
             int distance = 0;
             .debug("计算候选答案 " + candidateAnswer.getAnswer() + " 的最小词距");
             //3.1 计算candidateAnswer的分布
             List<IntegercandidateAnswerOffes = new ArrayList<>();
             for (Term term : terms) {
                 if (term.getName().equals(candidateAnswer.getAnswer())) {
                     candidateAnswerOffes.add(term.getOffe());
                 }
             }
             for (String questionTerm : questionTerms) {
                 //3.2 计算questionTerm的分布
                 List<IntegerquestionTermOffes = new ArrayList<>();
                 for (Term term : terms) {
                     if (term.getName().equals(questionTerm)) {
                         questionTermOffes.add(term.getOffe());
                     }
                 }
                 //3.3 计算candidateAnswer和questionTerm的最小词距
                 int miniDistance = .;
                 for (int candidateAnswerOffe : candidateAnswerOffes) {
                     for (int questionTermOffe : questionTermOffes) {
                         int abs = Math.abs(candidateAnswerOffe - questionTermOffe);
                         if (miniDistance > abs) {
                             miniDistance = abs;
                         }
                     }
                 }
                 if (miniDistance != .) {
                     distance += miniDistance;
                 }
             }
             double score = candidateAnswer.getScore() / distance;
             score *= .getTermDistanceMiniCandidateAnswerScoreWeight();
             .debug("最小词距:" + distance + " ,分值:" + score);
             candidateAnswer.addScore(score);
         }
         .debug("最小词距评分结束");
        .debug("*************************");
    }
New to GrepCode? Check out our FAQ X