Skip to content

Commit

Permalink
Add public accessor to UDF/UDX node parents
Browse files Browse the repository at this point in the history
Resolves #245
  • Loading branch information
goodmami committed Dec 19, 2019
1 parent 24a3906 commit 74c880f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ these changes are prefixed with "**BREAKING**"
### Added

* `requirements.txt` mainly to try and help GitHub detect dependencies
* `delphin.derivation.UDFNode.parent` ([#245][])
* `delphin.derivation.UDFTerminal.parent` ([#245][])

### Changed

Expand Down Expand Up @@ -1196,6 +1198,7 @@ information about changes, except for
[#200]: https://github.com/delph-in/pydelphin/issues/200
[#203]: https://github.com/delph-in/pydelphin/issues/203
[#213]: https://github.com/delph-in/pydelphin/issues/213
[#245]: https://github.com/delph-in/pydelphin/issues/245
[#247]: https://github.com/delph-in/pydelphin/issues/247
[#248]: https://github.com/delph-in/pydelphin/issues/248
[#249]: https://github.com/delph-in/pydelphin/issues/249
Expand Down
4 changes: 4 additions & 0 deletions delphin/derivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def __ne__(self, other):
return NotImplemented
return not (self == other)

@property
def parent(self):
return self._parent

# serialization

def to_udf(self, indent=1):
Expand Down
12 changes: 12 additions & 0 deletions docs/api/delphin.derivation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ delphin.derivation
The lexical type (available on preterminal UDX nodes).

.. py:attribute:: parent
The parent node in the tree, or ``None`` for the root. Note
that this is not a regular UDF/UDX attribute but is added for
convenience in traversing the tree.

.. automethod:: is_root
.. automethod:: to_udf
.. automethod:: to_udx
Expand All @@ -158,6 +164,12 @@ delphin.derivation
The list of tokens.

.. py:attribute:: parent
The parent node in the tree. Note that this is not a regular
UDF/UDX attribute but is added for convenience in traversing
the tree.

.. automethod:: is_root
.. automethod:: to_udf
.. automethod:: to_udx
Expand Down
6 changes: 6 additions & 0 deletions tests/derivation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_init(self):
assert n.is_head()
assert n.type == 'type'

def test_parent(self):
n1 = N(None, 'entity')
assert n1.parent is None
n2 = N(1, 'entity', 0.5, 1, 2, [], head=True, type='type', parent=n1)
assert n2.parent is n1


class TestDerivation():
def test_init(self):
Expand Down

0 comments on commit 74c880f

Please sign in to comment.