Skip to content

Commit

Permalink
Fix #98; correctly read var-properties in MRS-JSON
Browse files Browse the repository at this point in the history
This was eluding the unit tests because:
  - Xmrs.__eq__() didn't check variable properties (now fixed)
  - The unit test didn't include variable properties (also fixed)
  • Loading branch information
goodmami committed Mar 28, 2017
1 parent b982257 commit a9084d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* `delphin.interfaces.ace` joins content lines in tsdb mode---fixes #95
* Write empty tables for `delphin mkprof` command unless `--skeleton` is
used (fixes #96)
* `delphin.mrs.xmrs.Xmrs` equality test now checks variable properties
* `delphin.mrs.xmrs.Mrs.from_dict()` correctly reads variable properties (#98)

### Deprecated

Expand Down
5 changes: 4 additions & 1 deletion delphin/mrs/xmrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def __eq__(self, other):
a, b = sorted(self.icons()), sorted(other.icons())
if len(a) != len(b) or any(ic1 != ic2 for ic1, ic2 in zip(a, b)):
return False
for v in self.variables():
if self.properties(v) != other.properties(v):
return False
return True

@property
Expand Down Expand Up @@ -832,7 +835,7 @@ def _ep(ep):
for c in d.get('constraints', []) if 'high' in c]
icons = [(c['high'], c['relation'], c['low'])
for c in d.get('constraints', []) if 'left' in c]
variables = {var: {k:v for k, v in data.items() if k != 'type'}
variables = {var: list(data.get('properties', {}).items())
for var, data in d.get('variables', {}).items()}
return cls(
top=d.get('top'),
Expand Down
9 changes: 7 additions & 2 deletions tests/mrs_Mrs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ def test_from_dict(self):
'arguments': {'ARG0': 'e2'}}
],
'constraints': [],
'variables': {'h1': {'type': 'h'}, 'e2': {'type': 'e'}}
'variables': {
'h1': {'type': 'h'},
'e2': {'type': 'e',
'properties': {'SF': 'prop', 'TENSE': 'pres'}}
}
})
m2 = Mrs(
rels=[
EP(FIRST_NODEID, sp('"_rain_v_1_rel"'), 'h1', {'ARG0': 'e2'})
]
],
vars={'e2': {'SF': 'prop', 'TENSE': 'pres'}}
)
assert m1 == m2

0 comments on commit a9084d6

Please sign in to comment.