-
Notifications
You must be signed in to change notification settings - Fork 1
/
conjunctions.py
33 lines (26 loc) · 1.24 KB
/
conjunctions.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
'''
Attaches conjunction dependents in the AMR based on the dependency parse.
@see: pipeline.loadDepParse() for special handling of conjunctions
@author: Nathan Schneider (nschneid)
@since: 2012-08-08
'''
from __future__ import print_function
import os, sys, re, codecs, fileinput
import pipeline
from pipeline import 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
nConjOps = {} # maps conjunction concept variable to its current number of :opX relations
for deps in depParse:
if deps is None: continue
for dep in deps:
if completed[1][(dep["gov_idx"],dep["dep_idx"])]: continue
i, r, c = dep['dep_idx'], dep["rel"], dep["gov_idx"]
if r=='conj':
x = amrget(amr, alignment, c, depParse, wTags, completed)
y = amrget(amr, alignment, i, depParse, wTags, completed)
newtriple = (str(x), 'op'+str(nConjOps.setdefault(x,0)+1), str(y))
nConjOps[x] += 1
amr = new_amr_from_old(amr, new_triples=[newtriple])
completed[1][(c,i)] = True
return depParse, amr, alignment, completed