Skip to content

Commit

Permalink
Increase robustness for predicates missing a POS
Browse files Browse the repository at this point in the history
Resolves #129
  • Loading branch information
goodmami committed Apr 17, 2018
1 parent 504512a commit 1780151
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion delphin/mrs/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ def string_or_grammar_pred(predstr):
@classmethod
def realpred(cls, lemma, pos, sense=None):
"""Return a Pred from its components."""
string_tokens = [lemma, pos]
string_tokens = [lemma]
if pos is not None:
string_tokens.append(pos)
if sense is not None:
sense = str(sense)
string_tokens.append(sense)
Expand Down
17 changes: 17 additions & 0 deletions tests/mrs_components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def testSpred(self):
assert p.pos == 'n'
assert p.sense == '1'
assert p.short_form() == '_dog_n_1'
# see https://github.com/delph-in/pydelphin/issues/129
p = spred('_te_adjunct_rel')
assert p.type == Pred.STRINGPRED
assert p.string == '_te_adjunct_rel'
assert p.lemma == 'te'
assert p.pos == None
assert p.sense == 'adjunct'
assert p.short_form() == '_te_adjunct'
#TODO: the following shouldn't throw warnings.. the code should
# be more robust, but there should be some Warning or logging
#with pytest.raises(ValueError): spred('_dog_rel')
Expand Down Expand Up @@ -433,6 +441,15 @@ def testRealPred(self):
assert p.pos == 'n'
assert p.sense == '1'
assert p.short_form() == '_dog_n_1'
# see https://github.com/delph-in/pydelphin/issues/129
p = Pred.realpred('te', None, 'adjunct')
assert p.type == Pred.REALPRED
assert p.string == '_te_adjunct_rel'
assert p.lemma == 'te'
assert p.pos == None
assert p.sense == 'adjunct'
assert p.short_form() == '_te_adjunct'

with pytest.raises(TypeError): Pred.realpred(lemma='dog')
with pytest.raises(TypeError): Pred.realpred(pos='n')
repr(p) # no error
Expand Down
23 changes: 23 additions & 0 deletions tests/mrs_dmrx_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ convenient:

```

See https://github.com/delph-in/pydelphin/issues/129

```python
>>> m3 = next(dmrx.loads('''<dmrs-list>
... <dmrs cfrom="-1" cto="-1">
... <node nodeid="10000"><realpred lemma="te" sense="adjunct" /><sortinfo /></node>
... </dmrs></dmrs-list>'''))
>>> nodes(m3)[0].pred # doctest: +ELLIPSIS
<Pred object _te_adjunct_rel ...>
>>> nodes(m3)[0].pred.pos is None
True

```


## Serialization

The default prints everything on one line.
Expand Down Expand Up @@ -126,3 +141,11 @@ Using the `pretty_print` parameter adds newlines.
</dmrs-list>

```

See https://github.com/delph-in/pydelphin/issues/129

```python
>>> print(dmrx.dumps([m3]))
<dmrs-list><dmrs cfrom="-1" cto="-1"><node cfrom="-1" cto="-1" nodeid="10000"><realpred lemma="te" sense="adjunct" /><sortinfo cvarsort="u" /></node></dmrs></dmrs-list>

```

0 comments on commit 1780151

Please sign in to comment.