示例#1
0
def containsNER(q,category):
    q_str = ""
    for words in q.split():
        word = helper.removepunc(words)
        q_str = q_str + word + " "
    q_tokens  = nltk.word_tokenize(q_str)
    q_tag = nltk.pos_tag(q_tokens)
    ne_tag = nltk.ne_chunk(q_tag)
    for tree in ne_tag.subtrees():
        if tree.label() == category:
            return True
    return False
示例#2
0
     if question_type == "what":
         new_ans = FinalizeSent.matchFinalAnsWhat(q,sorted_top_ans)
     if question_type == "when" or question_type == "hownum":
         new_ans = FinalizeSent.matchFinalAnsWhenHow(q,sorted_top_ans)
     if question_type == "why":
         new_ans = FinalizeSent.matchFinalWhy(q,sorted_top_ans)
 else:
     new_ans = FinalizeSent.formatFinalSent(Whword, s2, q)
     #new_ans = FinalizeSent.trimFinalAns(matched_ans,s2.split(),1)
 value = ""
 if len(new_ans) > 0:
     value_str = ""
     for ans in new_ans:
         #ans = " ".join("".join([" " if ch in string.punctuation else ch for ch in ans]).split())
         ans = ans.strip()
         ans = helper.removepunc(ans)
         value_str = value_str + ans + " "
     value = ""
     value_str_list1 = value_str.split()
     value_str = ""
     value_str_list = sorted(set(value_str_list1),key=value_str_list1.index)
     for val in value_str_list:
         if not helper.remqueswords(q,val):
             value_str = value_str + str(val) + " "
     if value_str == "":
         match_ans = sorted_top_ans[0][0]
         match_ans1 = match_ans.strip()
         match_ans2 = match_ans1.replace("\n"," ")
         for val in match_ans2.split():
             if not helper.remqueswords(q,val):
                 val = helper.removepunc(val)