Skip to content

Commit

Permalink
Address #84; more consistently find quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmami committed Nov 4, 2016
1 parent b5ce8f5 commit 2888d1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions delphin/mrs/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def links(xmrs):
_eps = xmrs._eps
_hcons = xmrs._hcons
_vars = xmrs._vars
_pred = xmrs.pred

lsh = xmrs.labelset_heads
lblheads = {v: lsh(v) for v, vd in _vars.items() if 'LBL' in vd['refs']}
Expand All @@ -272,7 +271,7 @@ def links(xmrs):
for src, srclbl, role, val, vd in prelinks:
if IVARG_ROLE in vd['refs']:
tgtnids = [n for n in vd['refs'][IVARG_ROLE]
if not _pred(n).is_quantifier()]
if not _eps[n].is_quantifier()]
if len(tgtnids) == 0:
continue # maybe some bad MRS with a lonely quantifier
tgt = tgtnids[0] # what do we do if len > 1?
Expand Down
11 changes: 7 additions & 4 deletions delphin/mrs/xmrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,9 @@ def __init__(
qeq = HandleConstraint.qeq
vgen = _VarGenerator()
labels = _make_labels(nodes, links, vgen)
ivs = _make_ivs(nodes, vgen)
qs = set(l.start for l in links
if (l.rargname or '').upper() == RSTR_ROLE)
ivs = _make_ivs(nodes, vgen, qs)
top = index = xarg = None # for now; maybe get them from kwargs?
# initialize args with ARG0 for intrinsic variables
args = {nid: {IVARG_ROLE: iv} for nid, iv in ivs.items()}
Expand Down Expand Up @@ -988,13 +990,14 @@ def to_dict(self, short_pred=True, properties=True):
"""
Encode the Dmrs as a dictionary suitable for JSON serialization.
"""
qs = set(self.nodeids(quantifier=True))
def _lnk(obj): return {'from': obj.cfrom, 'to': obj.cto}
def _node(node, short_pred=True):
p = node.pred.short_form() if short_pred else node.pred.string
d = dict(nodeid=node.nodeid, predicate=p)
if node.lnk is not None: d['lnk'] = _lnk(node)
if properties and node.sortinfo:
if not node.is_quantifier():
if node.nodeid not in qs:
d['sortinfo'] = node.sortinfo
if node.surface is not None: d['surface'] = node.surface
if node.base is not None: d['base'] = node.base
Expand Down Expand Up @@ -1062,12 +1065,12 @@ def _make_labels(nodes, links, vgen):
seen.add(conj_nid)
return labels

def _make_ivs(nodes, vgen):
def _make_ivs(nodes, vgen, qs):
ivs = {}
for node in nodes:
# quantifiers share their IV with the quantifiee. It will be
# selected later during argument construction
if not node.is_quantifier():
if node.nodeid not in qs:
props = dict((key, val) for key, val in node.sortinfo.items()
if key != CVARSORT)
ivs[node.nodeid] = vgen.new(node.cvarsort, props)[0]
Expand Down

0 comments on commit 2888d1d

Please sign in to comment.