How to use the forte.data.ontology.top.Link 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 / base_ontology.py View on Github external
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

github asyml / forte / tests / forte / data / ontology / test_outputs / ft / onto / base_ontology.py View on Github external
"""

    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
github asyml / forte / tests / forte / data / ontology / test_outputs / ft / onto / example_ontology.py View on Github external
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] = []
github asyml / forte / tests / forte / data / ontology / test_outputs / ft / onto / example_complex_ontology.py View on Github external
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
github asyml / forte / ft / onto / base_ontology.py View on Github external
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

github asyml / forte / ft / onto / base_ontology.py View on Github external
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


@dataclass
class RelationLink(Link):
    """
    A `Link` type entry which represent a relation between two entity mentions
    Attributes:
        rel_type (Optional[str])	The type of the relation.
    """

    rel_type: Optional[str]

    ParentType = EntityMention
    ChildType = EntityMention

    def __init__(self, pack: DataPack, parent: Optional[Entry] = None, child: Optional[Entry] = None):
        super().__init__(pack, parent, child)
        self.rel_type: Optional[str] = None

github asyml / forte / forte / data / data_pack.py View on Github external
a_args: Union[Dict, Iterable],
            data: Dict,
            cont: Optional[Annotation]) -> Dict:

        components, unit, fields = self._parse_request_args(a_type, a_args)

        if unit is not None:
            raise ValueError(f"Link entries cannot be indexed by {unit}.")

        a_dict: Dict[str, Any] = dict()
        for field in fields:
            a_dict[field] = []
        a_dict["parent"] = []
        a_dict["child"] = []

        link: Link
        for link in self.get(a_type, cont, components):
            parent_type = link.ParentType.__name__
            child_type = link.ChildType.__name__

            if parent_type not in data.keys():
                raise KeyError(f"The Parent entry of {a_type} is not requested."
                               f" You should also request {parent_type} with "
                               f"{a_type}")
            if child_type not in data.keys():
                raise KeyError(f"The child entry of {a_type} is not requested."
                               f" You should also request {child_type} with "
                               f"{a_type}")

            a_dict["parent"].append(
                np.where(data[parent_type]["tid"] == link.parent)[0][0])
            a_dict["child"].append(
github asyml / forte / forte / data / ontology / wiki_ontology.py View on Github external
class WikiBody(Annotation):
    def __init__(self, pack: DataPack, begin: int, end: int):
        super().__init__(pack, begin, end)
        self.introduction: WikiSection
        self.sections: List[WikiSection]


class WikiSection(Annotation):
    pass


class WikiAnchor(Annotation):
    pass


class WikiAnchorLink(Link):
    ParentType = WikiAnchor
    ChildType = WikiPage

    def __init__(self, pack: DataPack, anchor: WikiAnchor, page: WikiPage):
        super().__init__(pack, anchor, page)


class WikiInfoBox(Entry):
    def __init__(self, pack: DataPack):
        super().__init__(pack)
        self.text_entries: Dict[str, str] = {}
        self.entity_entries: Dict[str, WikiPage] = {}


class WikiCategories(Entry):
    def __init__(self, pack: DataPack):
github asyml / forte / ft / onto / base_ontology.py View on Github external
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


@dataclass
class Dependency(Link):
    """
    A `Link` type entry which represent a syntactic dependency.
    Attributes:
        dep_label (Optional[str])	The dependency label.
        rel_type (Optional[str])
    """

    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