Skip to content

Commit 5b51969

Browse files
committed
bundle.add_tree(t) should set/update t.sent_id according to bundle.bundle_id
also use f-strings and internally faster self._bundle_id
1 parent 985b327 commit 5b51969

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

udapi/block/udpipe/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def process_document(self, doc):
153153
orig_bundle_id = bundle.bundle_id
154154
bundle.bundle_id = orig_bundle_id + '-1'
155155
for i, new_tree in enumerate(new_trees[1:], 2):
156-
new_bundle = Bundle(document=doc, bundle_id=orig_bundle_id + '-' + str(i))
156+
new_bundle = Bundle(document=doc, bundle_id=f"{orig_bundle_id}-{i}")
157157
new_tree.zone = tree.zone
158158
new_bundle.add_tree(new_tree)
159159
new_bundles.append(new_bundle)
@@ -166,7 +166,7 @@ def process_document(self, doc):
166166
bundle.bundle_id = orig_bundle_id + '-1'
167167
tree.text = sentences[0]
168168
for i, sentence in enumerate(sentences[1:], 2):
169-
new_bundle = Bundle(document=doc, bundle_id=orig_bundle_id + '-' + str(i))
169+
new_bundle = Bundle(document=doc, bundle_id=f"{orig_bundle_id}-{i}")
170170
new_tree = new_bundle.create_tree(zone=tree.zone)
171171
new_tree.text = sentence
172172
new_bundles.append(new_bundle)

udapi/core/bundle.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def bundle_id(self, bundle_id):
3939
tree._sent_id = bundle_id + '/' + tree.zone # pylint: disable=protected-access
4040

4141
def __str__(self):
42-
if self.bundle_id is None:
42+
if self._bundle_id is None:
4343
return 'bundle without id'
44-
return "bundle id='%s'" % self.bundle_id
44+
return f"bundle id='{self._bundle_id}'"
4545

4646
def __iter__(self):
4747
return iter(self.trees)
@@ -91,6 +91,10 @@ def add_tree(self, root):
9191
if root.zone is None:
9292
root._zone = ''
9393
self.check_zone(root.zone)
94+
if self._bundle_id:
95+
root._sent_id = self._bundle_id
96+
if root.zone:
97+
root._sent_id += '/' + root.zone
9498
root.bundle = self
9599
self.trees.append(root)
96100
doc_json = root.json.get('__doc__')
@@ -107,7 +111,7 @@ def remove(self):
107111

108112
def address(self):
109113
"""Return bundle_id or '?' if missing."""
110-
return self.bundle_id if self.bundle_id is not None else '?'
114+
return self._bundle_id if self._bundle_id is not None else '?'
111115

112116
def draw(self, **kwargs):
113117
"""Pretty print the trees using TextModeTrees."""

0 commit comments

Comments
 (0)