Example #1
0
def whyMainRule(q,sent_list):
    score = []
    best = []
    temp_list = []
    for k,s in enumerate(sent_list):
        score.append(WordMatch(q,helper.remove_puncts(s)))
        best.append((s, score[k]))  # best is all the sentences with their scores
    best_list = sorted(best, key=lambda  x: (-x[1],x[0]))
    sent_best = []
    for j in range(10):
        sent_best.append(best_list[j][0])
    for i,s in enumerate(sent_list):
        if i == 0:
            score = whyRule(q,helper.remove_puncts(s),sent_best,None,sent_list[i+1])
        elif  i == len(sent_list) - 1:
            score = whyRule(q,helper.remove_puncts(s),sent_best,sent_list[i-1],None)
        else:
            score = whyRule(q,helper.remove_puncts(s),sent_best,sent_list[i-1],sent_list[i+1])
        temp_list.append((s,score))
    return temp_list
Example #2
0
     if x.lower() == "why":
         question_type="why"
         break
     if x.lower() == "how":
         for e,q_word in enumerate(q_li):
             if q_word.lower() == "how" and "how " + q_li[e+1] not in constants.ans_type:
                 question_type="how"
                 break
             if q_word.lower() == "how" and "how " + q_li[e+1] in constants.ans_type:
                 question_type="hownum"
                 break
 list1 = []
 dateline_score = 0
 if question_type=="who":
     for s in sent_list:
         score = Rules.whoRule(q,helper.remove_puncts(s))
         list1.append((s,score))
 elif question_type=="what":
     for s in sent_list:
         score = Rules.whatRule(q,helper.remove_puncts(s))
         list1.append((s,score))
 elif question_type=="when":
     dateline_score = Rules.datelineRule(q)
     for s in sent_list:
         score = Rules.whenRule(q,helper.remove_puncts(s))
         list1.append((s,score))
 elif question_type=="where":
     dateline_score = Rules.datelineRule(q)
     for s in sent_list:
         score = Rules.whereRule(q,helper.remove_puncts(s))
         list1.append((s,score))