Skip to content

Commit 42f270c

Browse files
fix: issue with split_long_span
1 parent 8d9c680 commit 42f270c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

deep_reference_parser/prodigy/reference_to_token_annotations.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,24 @@ def split_long_span(self, tokens, span, start_label, end_label, inside_label):
189189
"""
190190
Split a multi-token span into `n` spans of lengh `1`, where `n=len(tokens)`
191191
"""
192-
193192
spans = []
194-
spans.append(self.create_span(tokens, span["token_start"], start_label))
195-
spans.append(self.create_span(tokens, span["token_end"], end_label))
193+
start = span["token_start"]
194+
end = span["token_end"]
195+
196+
span_size = end - start
197+
198+
# Case when there is only one token in the span
199+
if span_size == 0:
200+
spans.append(self.create_span(tokens, start, start_label))
201+
# Case when there are two or more tokens in the span
202+
else:
203+
spans.append(self.create_span(tokens, start, start_label))
204+
spans.append(self.create_span(tokens, end, end_label))
205+
206+
if span_size > 1:
196207

197-
for index in range(span["token_start"] + 1, span["token_end"]):
198-
spans.append(self.create_span(tokens, index, inside_label))
208+
for index in range(start + 1, end):
209+
spans.append(self.create_span(tokens, index, inside_label))
199210

200211
spans = sorted(spans, key=lambda k: k["token_start"])
201212

0 commit comments

Comments
 (0)