Skip to content

Commit 1807b5d

Browse files
authored
Merge pull request #3150 from mauryaland/patch-2
Modify Sentence.to_original_text() to take into account Sentence.start_position for whitespace calculation
2 parents 754bd7c + 7fe1666 commit 1807b5d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

flair/data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,9 @@ def to_original_text(self) -> str:
917917
if len(self) == 0:
918918
return ""
919919
# otherwise, return concatenation of tokens with the correct offsets
920-
return self[0].start_position * " " + "".join([t.text + t.whitespace_after * " " for t in self.tokens]).strip()
920+
return (self[0].start_position - self.start_position) * " " + "".join(
921+
[t.text + t.whitespace_after * " " for t in self.tokens]
922+
).strip()
921923

922924
def to_dict(self, tag_type: str = None):
923925
labels = []

0 commit comments

Comments
 (0)