-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookup.py
44 lines (36 loc) · 1.46 KB
/
lookup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import googleSearcher2
import search
#import nltk
from nltk import pos_tag
from nltk.tokenize import word_tokenize
def run(redQuestion,answers):
"""first run - searches the question and finds the answer"""
result = googleSearcher2.searching(redQuestion)
countRes = [-1,-1,-1]
for i in range(0,3):
countRes[i] = search.count_occurrences(answers[i].lower(),result.lower())
"""second run - searches each of the answers and finds key words in the question"""
if countRes == [0,0,0]:
keywords = word_tokenize(redQuestion)
proper_nouns = []
nouns = []
keywords = pos_tag(keywords)
for word in keywords:
if word[1] == 'NN' or word[1] == 'NNS':
nouns.append(word[0])
if word[1] == 'NNP' or word[1] == 'NNPS':
proper_nouns.append(word[0])
print(countRes,"\n\n\n\n")
print(nouns)
print(proper_nouns)
#now search answers
for i in range(0,3):
ansRes = googleSearcher2.searching(answers[i])
for j in nouns:
countRes[i] += search.count_occurrences(j.lower(),ansRes.lower())
print(countRes)
for j in proper_nouns:
countRes[i] += search.count_occurrences(j.lower(),ansRes.lower())
print(countRes)
return countRes
#print(run("PBS icon named honorary captain National Hockey League team?",["Mister Rogers","Bob Ross","William F. Buckley Jr."]))