Skip to content

Commit 057d483

Browse files
committed
add root.prev_tree and root.next_tree
1 parent 4b0c5cd commit 057d483

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

udapi/core/root.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,25 @@ def flatten(self, deprel='root'):
314314
for node in self._children:
315315
node._parent = self
316316
node._children.clear()
317+
318+
@property
319+
def prev_tree(self):
320+
"""Return the previous tree (root) in the document (from the same zone)."""
321+
doc = self._bundle._document
322+
num = self._bundle.number
323+
if len(doc.bundles) <= num - 1 or doc.bundles[num - 1] is not self._bundle:
324+
num = doc.bundles.index(self._bundle) + 1
325+
if num == 1:
326+
return None
327+
return doc.bundles[num - 2].get_tree(zone=self._zone)
328+
329+
@property
330+
def next_tree(self):
331+
"""Return the next tree (root) in the document (from the same zone)."""
332+
doc = self._bundle._document
333+
num = self._bundle.number
334+
if len(doc.bundles) <= num - 1 or doc.bundles[num - 1] is not self._bundle:
335+
num = doc.bundles.index(self._bundle) + 1
336+
if len(doc.bundles) <= num:
337+
return None
338+
return doc.bundles[num].get_tree(zone=self._zone)

0 commit comments

Comments
 (0)