Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@dataclass
class Passage(Document):
"""
Attributes:
passage_id (Optional[str])
"""
passage_id: Optional[str]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.passage_id: Optional[str] = None
@dataclass
class Option(Annotation):
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
@dataclass
class Question(Annotation):
"""
Attributes:
options (FList[Option])
answers (List[int])
"""
options: FList[Option]
answers: List[int]
Automatically generated ontology example_import_ontology. Do not change manually.
"""
from dataclasses import dataclass
from forte.data.data_pack import DataPack
from forte.data.ontology.top import Annotation
from typing import Optional
__all__ = [
"Token",
"EntityMention",
]
@dataclass
class Token(Annotation):
"""
Base parent token entry
Attributes:
pos (Optional[str])
lemma (Optional[str])
"""
pos: Optional[str]
lemma: Optional[str]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.pos: Optional[str] = None
self.lemma: Optional[str] = None
from forte.data.ontology.core import Entry
from forte.data.ontology.core import FList
from forte.data.ontology.top import Annotation
from forte.data.ontology.top import Link
from typing import Optional
__all__ = [
"Token",
"Sentence",
"Document",
"Dependency",
]
@dataclass
class Token(Annotation):
"""
Attributes:
lemma (Optional[str])
is_verb (Optional[bool])
num_chars (Optional[int])
score (Optional[float])
"""
lemma: Optional[str]
is_verb: Optional[bool]
num_chars: Optional[int]
score: Optional[float]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.lemma: Optional[str] = None
is_verb (Optional[bool])
"""
predicate_lemma: Optional[str]
framenet_id: Optional[str]
is_verb: Optional[bool]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.predicate_lemma: Optional[str] = None
self.framenet_id: Optional[str] = None
self.is_verb: Optional[bool] = None
@dataclass
class PredicateLink(Link):
"""
A `Link` type entry which represent a semantic role link between a predicate and its argument.
Attributes:
arg_type (Optional[str]) The predicate link type.
"""
arg_type: Optional[str]
ParentType = PredicateMention
ChildType = PredicateArgument
def __init__(self, pack: DataPack, parent: Optional[Entry] = None, child: Optional[Entry] = None):
super().__init__(pack, parent, child)
self.arg_type: Optional[str] = None
"""
dep_label: Optional[str]
rel_type: Optional[str]
ParentType = Token
ChildType = Token
def __init__(self, pack: DataPack, parent: Optional[Entry] = None, child: Optional[Entry] = None):
super().__init__(pack, parent, child)
self.dep_label: Optional[str] = None
self.rel_type: Optional[str] = None
@dataclass
class EnhancedDependency(Link):
"""
A `Link` type entry which represent a enhanced dependency:
https://universaldependencies.org/u/overview/enhanced-syntax.html
Attributes:
dep_label (Optional[str]) The enhanced dependency label in Universal Dependency.
"""
dep_label: Optional[str]
ParentType = Token
ChildType = Token
def __init__(self, pack: DataPack, parent: Optional[Entry] = None, child: Optional[Entry] = None):
super().__init__(pack, parent, child)
self.dep_label: Optional[str] = None
token_ranks (FDict[int, "Word"]) To demonstrate that an attribute can be a Dict, and the values can be other entries.
"""
string_features: List[str]
word_forms: FList[Word]
token_ranks: FDict[int, "Word"]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.string_features: List[str] = []
self.word_forms: FList[Word] = FList(self)
self.token_ranks: FDict[int, "Word"] = FDict(self)
@dataclass
class WordLink(Link):
"""
Attributes:
string_features (List[str]) To demonstrate the composite type, List.
"""
string_features: List[str]
ParentType = Word
ChildType = Word
def __init__(self, pack: DataPack, parent: Optional[Entry] = None, child: Optional[Entry] = None):
super().__init__(pack, parent, child)
self.string_features: List[str] = []
key_tokens: FList[Token]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.key_tokens: FList[Token] = FList(self)
@dataclass
class Document(Annotation):
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
@dataclass
class Dependency(Link):
"""
Attributes:
rel_type (Optional[str])
"""
rel_type: Optional[str]
def __init__(self, pack: DataPack, parent: Optional[Entry] = None, child: Optional[Entry] = None):
super().__init__(pack, parent, child)
self.rel_type: Optional[str] = None
from forte.data.io_utils import dataset_path_iterator
from forte.data.readers.base_reader import PackReader, MultiPackReader
from forte.data.data_pack import DataPack
from forte.data.multi_pack import MultiPack
from forte.data.base_pack import PackType
logger = logging.getLogger(__name__)
__all__ = [
"MonoFileReader",
"PackReader"
]
class MonoFileReader(PackReader, ABC):
"""Data reader that reads one data pack from each single text files.
To be inherited by all mono file data readers.
"""
# pylint: disable=no-self-use
def _cache_key_function(self, file_directory: str):
return file_directory.split('/')[-1]
# pylint: disable=no-self-use
def _collect(self, file_directory: str) -> Iterator[str]: # type: ignore
"""
:param file_directory: the path to a single directory containing the
files.
:return: Iterator[Any] collections to iterate over
"""
return dataset_path_iterator(file_directory, "")
def initialize(self, resources: Resources, configs: Config):
if configs.pretrained_model_name in self.name2tokenizer:
self.tokenizer = \
self.name2tokenizer[configs.pretrained_model_name](
pretrained_model_name=configs.pretrained_model_name)
self.encoder = self.name2encoder[configs.pretrained_model_name](
pretrained_model_name=configs.pretrained_model_name)
else:
raise ValueError("Unrecognized pre-trained model name.")
self.entry_type = get_class(configs.entry_type)
if not isinstance(self.entry_type, Annotation) and \
not issubclass(self.entry_type, Annotation):
raise ValueError("entry_type must be annotation type.")
sentiment (Dict[str, float])
"""
speaker: Optional[str]
part_id: Optional[int]
sentiment: Dict[str, float]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.speaker: Optional[str] = None
self.part_id: Optional[int] = None
self.sentiment: Dict[str, float] = dict()
@dataclass
class Phrase(Annotation):
"""
A span based annotation `Phrase`.
Attributes:
phrase_type (Optional[str])
"""
phrase_type: Optional[str]
def __init__(self, pack: DataPack, begin: int, end: int):
super().__init__(pack, begin, end)
self.phrase_type: Optional[str] = None
@dataclass
class UtteranceContext(Annotation):
"""