How to use the forte.data.ontology.top.Annotation function in forte

To help you get started, we’ve selected a few forte examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asyml / forte / tests / forte / data / ontology / test_outputs / ft / onto / race_qa_ontology.py View on Github external
@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]
github asyml / forte / tests / forte / data / ontology / test_outputs / ft / onto / example_import_ontology.py View on Github external
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

github asyml / forte / tests / forte / data / ontology / test_outputs / ft / onto / example_complex_ontology.py View on Github external
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
github asyml / forte / forte / processors / pretrained_encoder_processors.py View on Github external
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.")
github asyml / forte / ft / onto / base_ontology.py View on Github external
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):
    """
github asyml / forte / forte / data / data_pack.py View on Github external
entry: EntryType = self.get_entry(entry_id)  # type: ignore
                yield entry
            return

        # valid span
        if range_annotation is not None:
            coverage_index = self.index.coverage_index(type(range_annotation),
                                                       entry_type)
            if coverage_index is not None:
                valid_id &= coverage_index[range_annotation.tid]

        range_begin = range_annotation.span.begin if range_annotation else 0
        range_end = (range_annotation.span.end if range_annotation else
                     self.annotations[-1].span.end)

        if issubclass(entry_type, Annotation):
            temp_begin = Annotation(self, range_begin, range_begin)
            begin_index = self.annotations.bisect(temp_begin)

            temp_end = Annotation(self, range_end, range_end)
            end_index = self.annotations.bisect(temp_end)

            # Make sure these temporary annotations are not part of the
            # actual data.
            temp_begin.regret_creation()
            temp_end.regret_creation()

            for annotation in self.annotations[begin_index: end_index]:
                if annotation.tid not in valid_id:
                    continue
                if (range_annotation is None or
                        self.index.in_span(annotation, range_annotation.span)):
github asyml / forte / ft / onto / base_ontology.py View on Github external
self.ud_features: Dict[str, str] = dict()
        self.ud_misc: Dict[str, str] = dict()


@dataclass
class Document(Annotation):
    """
    A span based annotation `Document`, normally used to represent a document.
    """

    def __init__(self, pack: DataPack, begin: int, end: int):
        super().__init__(pack, begin, end)


@dataclass
class Sentence(Annotation):
    """
    A span based annotation `Sentence`, normally used to represent a sentence.
    Attributes:
        speaker (Optional[str])
        part_id (Optional[int])
        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
github asyml / forte / ft / onto / base_ontology.py View on Github external
class Utterance(Annotation):
    """
    A span based annotation `Utterance`, normally used to represent an utterance in dialogue.
    Attributes:
        speaker (Optional[str])
    """

    speaker: Optional[str]

    def __init__(self, pack: DataPack, begin: int, end: int):
        super().__init__(pack, begin, end)
        self.speaker: Optional[str] = None


@dataclass
class PredicateArgument(Annotation):
    """
    A span based annotation `PredicateArgument`, normally used to represent an argument of a predicate, can be linked to the predicate via the predicate link.
    Attributes:
        ner_type (Optional[str])
        predicate_lemma (Optional[str])
        is_verb (Optional[bool])
    """

    ner_type: Optional[str]
    predicate_lemma: Optional[str]
    is_verb: Optional[bool]

    def __init__(self, pack: DataPack, begin: int, end: int):
        super().__init__(pack, begin, end)
        self.ner_type: Optional[str] = None
        self.predicate_lemma: Optional[str] = None
github asyml / forte / ft / onto / base_ontology.py View on Github external
super().__init__(pack, begin, end)
        self.phrase_type: Optional[str] = None


@dataclass
class UtteranceContext(Annotation):
    """
    `UtteranceContext` represents the context part in dialogue.
    """

    def __init__(self, pack: DataPack, begin: int, end: int):
        super().__init__(pack, begin, end)


@dataclass
class Utterance(Annotation):
    """
    A span based annotation `Utterance`, normally used to represent an utterance in dialogue.
    Attributes:
        speaker (Optional[str])
    """

    speaker: Optional[str]

    def __init__(self, pack: DataPack, begin: int, end: int):
        super().__init__(pack, begin, end)
        self.speaker: Optional[str] = None


@dataclass
class PredicateArgument(Annotation):
    """
github asyml / forte / ft / onto / race_multi_choice_qa_ontology.py View on Github external
@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]