-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindHeadVerbDistribution.py
80 lines (78 loc) · 2.55 KB
/
findHeadVerbDistribution.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from corenlp import StanfordCoreNLP
directory = 'ayush_dataset/'
with open(directory+'newCfile.txt','r') as checkedSentences:
checkedSentences = checkedSentences.readlines()
with open(directory+'newNCfile.txt','r') as unCheckedSentences:
unCheckedSentences = unCheckedSentences.readlines()
nlp = StanfordCoreNLP('http://10.5.18.109:11111')
dictionaryOfCheckedVerbs = {}
for sentence in checkedSentences:
# print(sentence)
text = ( sentence )
output = nlp.annotate(
text, properties={
'annotators': 'tokenize,ssplit,pos,depparse,parse',
'outputFormat': 'json'
})
for token in output['sentences'][0]['tokens']:
if token['pos'][:2] == 'VB':
try:
dictionaryOfCheckedVerbs[token['word']]+=1
except:
dictionaryOfCheckedVerbs[token['word']]=1
print('Checked Verbs :--')
for w in sorted(dictionaryOfCheckedVerbs, key=dictionaryOfCheckedVerbs.get, reverse=True):
print(w, dictionaryOfCheckedVerbs[w])
# print(dictionaryOfCheckedVerbs)
# print(token['word'], token['pos'])
# for gloss in output['sentences'][0]['collapsed-dependencies']:
# print(gloss)
# break
# for gloss in output['sentences'][0]['collapsed-dependencies']:
# print(gloss['dep'][:2])
# print
# if gloss['dep'] == 'ROOT' or gloss['dep'][:2].upper() == 'VB':
# print(gloss['dependentGloss'], gloss['dep']),
# print
# print (gloss['dependentGloss'], gloss['dep'])
# print(output['sentences'][0])
# break
dictionaryOfUnCheckedVerbs = {}
for sentence in unCheckedSentences:
# print(sentence)
text = ( sentence )
output = nlp.annotate(
text, properties={
'annotators': 'tokenize,ssplit,pos,depparse,parse',
'outputFormat': 'json'
})
# print(sentence)
# print(output['sentences'][0])
try:
for token in output['sentences'][0]['tokens']:
if token['pos'][:2] == 'VB':
try:
dictionaryOfUnCheckedVerbs[token['word']]+=1
except:
dictionaryOfUnCheckedVerbs[token['word']]=1
except:
print(sentence)
print(output)
print()
print('Unchecked Verbs :--')
for w in sorted(dictionaryOfUnCheckedVerbs, key=dictionaryOfUnCheckedVerbs.get, reverse=True):
print(w, dictionaryOfUnCheckedVerbs[w])
# print(dictionaryOfUnCheckedVerbs)
# print(token['word'], token['pos'])
# for gloss in output['sentences'][0]['collapsed-dependencies']:
# print(gloss)
# break
# for gloss in output['sentences'][0]['collapsed-dependencies']:
# print(gloss['dep'][:2])
# print
# if gloss['dep'] == 'ROOT' or gloss['dep'][:2].upper() == 'VB':
# print(gloss['dependentGloss'], gloss['dep']),
# print
# print (gloss['dependentGloss'], gloss['dep'])
# print(output['sentences'][0])
# break