-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.py
46 lines (36 loc) · 1.63 KB
/
misc.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
'''
Attaches miscellaneous remaining edges from the dependency parse: currently
nn -> :mod-NN
prep_X -> :prep-X
@author: Nathan Schneider (nschneid)
@since: 2012-08-09
'''
from __future__ import print_function
import os, sys, re, codecs, fileinput
import pipeline
from pipeline import new_concept, new_amr_from_old, get_or_create_concept_from_token as amrget
def main(sentenceId, jsonFile, tokens, ww, wTags, depParse, inAMR, alignment, completed):
amr = inAMR
for deps in depParse:
if deps is None: continue
for dep in deps:
i, r, h = dep["dep_idx"], dep["rel"], dep["gov_idx"]
if completed[1][(h,i)]: continue
if r in ['nn','poss'] or r.startswith('prep_'):
x = amrget(amr, alignment, h, depParse, wTags, completed)
y = amrget(amr, alignment, i, depParse, wTags, completed) # modifier variable
if r=='nn': # attach as :mod-NN
newtriple = (str(x), 'mod-NN', str(y))
elif r=='poss':
newtriple = (str(x), 'poss', str(y))
else: # attach with :prep-X relation
assert r.startswith('prep_')
newtriple = (str(x), r.replace('_','-'), str(y))
amr = new_amr_from_old(amr, new_triples=[newtriple])
completed[1][(h,i)] = True
'''
# simplify adverbs to adjectives based on lexicon
for v in amr.node_to_concepts.keys():
amr.node_to_concepts[v] = simplify_adv(amr.node_to_concepts[v])
'''
return depParse, amr, alignment, completed