-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsimilarity_check.py
59 lines (39 loc) · 1.26 KB
/
similarity_check.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import os
import nltk
from collections import Counter
from stanfordcorenlp import StanfordCoreNLP
import logging
import json
from parse import Parse
from binary import Binary
from nltk.parse import stanford
from nltk.tree import Tree
reload(sys)
sys.setdefaultencoding('utf8')
class Similarity:
def main(self, original, question):
# question = raw_input("Please enter your question: ")
question = question[0].upper() + question[1:]
q_parsed = P.parse(question)
q_tree = Tree.fromstring(str(q_parsed))
print "q_tree\n", q_tree
o = B.main(original)
o = o[0].upper() + o[1:]
o_parsed = P.parse(o)
o_tree = Tree.fromstring(o_parsed)
print "o_tree\n", o_tree
o_tree_body = o_tree[0]
for i in range(len(o_tree_body)):
node = o_tree_body[i]
level_leaves = node.leaves()
if i < len(q_tree[0]) and q_tree[0][i].label() == node.label():
print level_leaves
print q_tree[0][i].leaves()
print '\n\n\n\n\n'
question = "is life like an onion?"
test = "life is not like a vegetable."
P = Parse()
B = Binary()
S = Similarity()
S.main(test, question)