aste-v2 / src /types.py
Matthew Franglen
Split up some of the code
8e12b39
raw
history blame
672 Bytes
from __future__ import annotations
import re
from dataclasses import dataclass
word_pattern = re.compile(r"\S+")
@dataclass(frozen=True)
class WordSpan:
start_index: int
end_index: int # this is the letter after the end
@staticmethod
def to_spans(text: str) -> list[WordSpan]:
return [
WordSpan(start_index=match.start(), end_index=match.end())
for match in word_pattern.finditer(text)
]
@dataclass(frozen=True)
class CharacterIndices:
aspect_start_index: int
aspect_end_index: int
aspect_term: str
opinion_start_index: int
opinion_end_index: int
opinion_term: str
sentiment: str