Skip to content

node

autocorpus.ac_bioc.node ¤

This module defines the BioCNode class.

Classes¤

BioCNode(refid=str(), role=str()) dataclass ¤

Represents a node in a BioC graph with a reference ID and a role.

Functions¤
from_dict(data) classmethod ¤

Create a BioCNode instance from a dictionary.

Parameters:

Name Type Description Default
data dict[str, str]

A dictionary containing 'refid' and 'role' keys.

required

Returns:

Name Type Description
BioCNode BioCNode

An instance of BioCNode initialized with the provided data.

Source code in autocorpus/ac_bioc/node.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@classmethod
def from_dict(cls, data: dict[str, str]) -> BioCNode:
    """Create a BioCNode instance from a dictionary.

    Args:
        data (dict[str, str]): A dictionary containing 'refid' and 'role' keys.

    Returns:
        BioCNode: An instance of BioCNode initialized with the provided data.
    """
    return cls(
        refid=data.get("refid", ""),
        role=data.get("role", ""),
    )
from_xml(elem) classmethod ¤

Create a BioCNode instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element containing 'refid' and 'role' attributes.

required

Returns:

Name Type Description
BioCNode BioCNode

An instance of BioCNode initialized with the provided XML data.

Source code in autocorpus/ac_bioc/node.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCNode:
    """Create a BioCNode instance from an XML element.

    Args:
        elem (ET.Element): An XML element containing 'refid' and 'role' attributes.

    Returns:
        BioCNode: An instance of BioCNode initialized with the provided XML data.
    """
    return cls(
        refid=elem.attrib.get("refid", ""),
        role=elem.attrib.get("role", ""),
    )
to_xml() ¤

Convert the BioCNode instance to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representing the BioCNode instance.

Source code in autocorpus/ac_bioc/node.py
36
37
38
39
40
41
42
43
44
45
def to_xml(self) -> ET.Element:
    """Convert the BioCNode instance to an XML element.

    Returns:
        ET.Element: An XML element representing the BioCNode instance.
    """
    elem = ET.Element("node")
    elem.set("refid", self.refid)
    elem.set("role", self.role)
    return elem