Skip to content

ac_bioc

autocorpus.ac_bioc ¤

BioCTable Package.

This package provides classes for handling modified BioC table structures, including cells, collections, documents, JSON encoding, and passages.

Classes¤

BioCAnnotation(id=str(), text=str(), offset=int(), length=int(), infons=dict(), locations=list()) dataclass ¤

Represents an annotation in a BioC document.

Functions¤
from_dict(data) classmethod ¤

Create a BioCAnnotation instance from a dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

A dictionary containing annotation data.

required

Returns:

Name Type Description
BioCAnnotation BioCAnnotation

An instance of BioCAnnotation created from the dictionary.

Source code in autocorpus/ac_bioc/annotation.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@classmethod
def from_dict(cls, data: dict[str, Any]) -> BioCAnnotation:
    """Create a BioCAnnotation instance from a dictionary.

    Args:
        data (dict[str, Any]): A dictionary containing annotation data.

    Returns:
        BioCAnnotation: An instance of BioCAnnotation created from the dictionary.
    """
    from .location import BioCLocation  # Prevent circular imports

    locations = [BioCLocation.from_dict(loc) for loc in data.get("locations", [])]

    return cls(
        id=data["id"],
        text=data.get("text", ""),
        offset=data.get("offset", 0),
        length=data.get("length", 0),
        infons=data.get("infons", {}),
        locations=locations,
    )
from_xml(elem) classmethod ¤

Create a BioCAnnotation instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element representing the annotation.

required

Returns:

Name Type Description
BioCAnnotation BioCAnnotation

An instance of BioCAnnotation created from the XML element.

Source code in autocorpus/ac_bioc/annotation.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCAnnotation:
    """Create a BioCAnnotation instance from an XML element.

    Args:
        elem (ET.Element): An XML element representing the annotation.

    Returns:
        BioCAnnotation: An instance of BioCAnnotation created from the XML element.
    """
    from .location import BioCLocation  # Again, avoid circular imports

    id_ = elem.attrib.get("id", "")
    text = elem.findtext("text", default="")

    infons = {
        e.attrib["key"]: e.text for e in elem.findall("infon") if e.text is not None
    }

    locations = [
        BioCLocation.from_xml(loc_elem) for loc_elem in elem.findall("location")
    ]

    # Offset and length can be derived if needed from locations
    offset = int(locations[0].offset) if locations else 0
    length = int(locations[0].length) if locations else 0

    return cls(
        id=id_,
        text=text,
        offset=offset,
        length=length,
        infons=infons,
        locations=locations,
    )
to_json() ¤

Convert the annotation to a JSON-serializable dictionary.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: A dictionary containing the annotation's id, text, offset, length, infons, and locations.

Source code in autocorpus/ac_bioc/annotation.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def to_json(self) -> dict[str, Any]:
    """Convert the annotation to a JSON-serializable dictionary.

    Returns:
        dict[str, Any]: A dictionary containing the annotation's id, text, offset, length, infons, and locations.
    """
    return {
        "id": self.id,
        "text": self.text,
        "offset": self.offset,
        "length": self.length,
        "infons": self.infons,
        "locations": [loc.to_dict() for loc in self.locations],
    }
to_xml() ¤

Convert the annotation to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representing the annotation.

Source code in autocorpus/ac_bioc/annotation.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def to_xml(self) -> ET.Element:
    """Convert the annotation to an XML element.

    Returns:
        ET.Element: An XML element representing the annotation.
    """
    annotation_elem = ET.Element("annotation")
    annotation_elem.set("id", self.id)

    for k, v in self.infons.items():
        infon = ET.SubElement(annotation_elem, "infon", {"key": k})
        infon.text = v

    for loc in self.locations:
        annotation_elem.append(loc.to_xml())

    text_elem = ET.SubElement(annotation_elem, "text")
    text_elem.text = self.text

    return annotation_elem

BioCCollection(source=str(), date=str(), key=str(), documents=list(), infons=dict()) dataclass ¤

Bases: DataClassJsonMixin

A class representing a BioC collection.

Functions¤
from_xml(elem) classmethod ¤

Create a BioCCollection instance from an XML element.

Parameters:

Name Type Description Default
elem Element

The XML element representing a BioCCollection.

required

Returns:

Name Type Description
BioCCollection BioCCollection

An instance of BioCCollection created from the XML element.

Source code in autocorpus/ac_bioc/collection.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCCollection:
    """Create a BioCCollection instance from an XML element.

    Args:
        elem (ET.Element): The XML element representing a BioCCollection.

    Returns:
        BioCCollection: An instance of BioCCollection created from the XML element.
    """
    source = elem.findtext("source", default="")
    date = elem.findtext("date", default="")
    key = elem.findtext("key", default="")

    infons = {
        e.attrib["key"]: e.text for e in elem.findall("infon") if e.text is not None
    }

    documents = [
        BioCDocument.from_xml(doc_elem) for doc_elem in elem.findall("document")
    ]

    return cls(
        source=source, date=date, key=key, infons=infons, documents=documents
    )
to_xml() ¤

Convert the BioCCollection instance to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representation of the BioCCollection instance.

Source code in autocorpus/ac_bioc/collection.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def to_xml(self) -> ET.Element:
    """Convert the BioCCollection instance to an XML element.

    Returns:
        ET.Element: An XML element representation of the BioCCollection instance.
    """
    collection_elem = ET.Element("collection")

    if self.source:
        source_elem = ET.SubElement(collection_elem, "source")
        source_elem.text = self.source

    if self.date:
        date_elem = ET.SubElement(collection_elem, "date")
        date_elem.text = self.date

    if self.key:
        key_elem = ET.SubElement(collection_elem, "key")
        key_elem.text = self.key

    if self.infons:
        for k, v in self.infons.items():
            infon = ET.SubElement(collection_elem, "infon", {"key": k})
            infon.text = v

    for doc in self.documents:
        collection_elem.append(doc.to_xml())

    return collection_elem

BioCDocument(id=str(), inputfile=str(), infons=dict(), passages=list(), relations=list(), annotations=list()) dataclass ¤

Bases: DataClassJsonMixin

Represents a BioC document containing passages, annotations, and relations.

Functions¤
from_xml(elem) classmethod ¤

Create a BioCDocument instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element representing the document.

required

Returns:

Name Type Description
BioCDocument BioCDocument

An instance of BioCDocument created from the XML element.

Source code in autocorpus/ac_bioc/document.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCDocument:
    """Create a BioCDocument instance from an XML element.

    Args:
        elem (ET.Element): An XML element representing the document.

    Returns:
        BioCDocument: An instance of BioCDocument created from the XML element.
    """
    id_text = elem.findtext("id", default="")

    infons = {
        e.attrib["key"]: e.text for e in elem.findall("infon") if e.text is not None
    }

    passages = [BioCPassage.from_xml(p_elem) for p_elem in elem.findall("passage")]

    return cls(
        id=id_text,
        infons=infons,
        passages=passages,
    )
to_xml() ¤

Convert the BioCDocument instance to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representing the document.

Source code in autocorpus/ac_bioc/document.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def to_xml(self) -> ET.Element:
    """Convert the BioCDocument instance to an XML element.

    Returns:
        ET.Element: An XML element representing the document.
    """
    doc_elem = ET.Element("document")

    id_elem = ET.SubElement(doc_elem, "id")
    id_elem.text = self.id

    for k, v in self.infons.items():
        infon = ET.SubElement(doc_elem, "infon", {"key": k})
        infon.text = v

    for passage in self.passages:
        doc_elem.append(passage.to_xml())

    for rel in self.relations:
        doc_elem.append(rel.to_xml())

    return doc_elem

BioCJSON ¤

JSON serialization for BioC objects.

Functions¤
dump(obj, fp, **kwargs) staticmethod ¤

Serialize a BioCCollection object to a JSON file-like object.

Source code in autocorpus/ac_bioc/json.py
30
31
32
33
@staticmethod
def dump(obj: BioCCollection, fp, **kwargs) -> None:
    """Serialize a BioCCollection object to a JSON file-like object."""
    return json.dump(obj, fp, cls=BioCJSONEncoder, **kwargs)
dumps(obj, **kwargs) staticmethod ¤

Serialize a BioCCollection object to a JSON-formatted string.

Source code in autocorpus/ac_bioc/json.py
35
36
37
38
@staticmethod
def dumps(obj: BioCCollection, **kwargs) -> str:
    """Serialize a BioCCollection object to a JSON-formatted string."""
    return json.dumps(obj, cls=BioCJSONEncoder, **kwargs)
loads(json_str) staticmethod ¤

Deserialize a JSON-formatted string to a BioCCollection object.

Source code in autocorpus/ac_bioc/json.py
40
41
42
43
44
@staticmethod
def loads(json_str: str) -> BioCCollection:
    """Deserialize a JSON-formatted string to a BioCCollection object."""
    data = json.loads(json_str)
    return BioCCollection.from_json(data)

BioCLocation(offset=int(), length=int()) dataclass ¤

Represents a location in BioC format.

Functions¤
from_dict(data) classmethod ¤

Create a BioCLocation instance from a dictionary.

Parameters:

Name Type Description Default
cls type

The class to instantiate.

required
data dict[str, int]

A dictionary containing the 'offset' and 'length' keys. If the keys are not present, default values of 0 will be used.

required

Returns:

Name Type Description
BioCLocation BioCLocation

An instance of BioCLocation created from the dictionary.

Source code in autocorpus/ac_bioc/location.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@classmethod
def from_dict(cls, data: dict[str, int]) -> BioCLocation:
    """Create a BioCLocation instance from a dictionary.

    Args:
        cls (type): The class to instantiate.
        data (dict[str, int]): A dictionary containing the 'offset' and 'length' keys.
            If the keys are not present, default values of 0 will be used.

    Returns:
        BioCLocation: An instance of BioCLocation created from the dictionary.
    """
    return cls(
        offset=data.get("offset", 0),
        length=data.get("length", 0),
    )
from_xml(elem) classmethod ¤

Create a BioCLocation instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element with 'offset' and 'length' attributes. The attributes will be converted to integers.

required

Returns:

Type Description
BioCLocation

BioCLocation An instance of BioCLocation created from the XML element. If the attributes are not present, default values of 0 will be used.

Source code in autocorpus/ac_bioc/location.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCLocation:
    """Create a BioCLocation instance from an XML element.

    Args:
        elem (ET.Element): An XML element with 'offset' and 'length' attributes.
            The attributes will be converted to integers.

    Returns:
        BioCLocation
            An instance of BioCLocation created from the XML element.
            If the attributes are not present, default values of 0 will be used.
    """
    offset = int(elem.attrib.get("offset", 0))
    length = int(elem.attrib.get("length", 0))
    return cls(offset=offset, length=length)
to_xml() ¤

Convert the BioCLocation instance to an XML element.

Returns:

Type Description
Element

ET.Element An XML element representation of the BioCLocation instance. The element will have 'offset' and 'length' attributes.

Source code in autocorpus/ac_bioc/location.py
44
45
46
47
48
49
50
51
52
53
54
55
def to_xml(self) -> ET.Element:
    """Convert the BioCLocation instance to an XML element.

    Returns:
        ET.Element
            An XML element representation of the BioCLocation instance.
            The element will have 'offset' and 'length' attributes.
    """
    elem = ET.Element("location")
    elem.set("offset", str(self.offset))
    elem.set("length", str(self.length))
    return elem

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

BioCPassage(text=str(), offset=int(), infons=dict(), sentences=list(), annotations=list(), relations=list()) dataclass ¤

Bases: DataClassJsonMixin

Represents a passage in a BioC document.

Functions¤
from_ac_dict(passage) classmethod ¤

Create a BioCPassage from a passage dict and an offset.

Parameters:

Name Type Description Default
passage dict[str, Any]

dict containing info about passage

required

Returns:

Type Description
BioCPassage

BioCPassage object

Source code in autocorpus/ac_bioc/passage.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@classmethod
def from_ac_dict(cls, passage: dict[str, Any]) -> BioCPassage:
    """Create a BioCPassage from a passage dict and an offset.

    Args:
        passage: dict containing info about passage

    Returns:
        BioCPassage object
    """
    infons = {k: v for k, v in passage.items() if k not in _DEFAULT_KEYS}
    # TODO: Doesn't account for subsubsection headings which might exist
    if heading := passage.get("section_heading", None):
        infons["section_title_1"] = heading
    if subheading := passage.get("subsection_heading", None):
        infons["section_title_2"] = subheading
    for i, section_type in enumerate(passage["section_type"]):
        infons[f"iao_name_{i + 1}"] = section_type["iao_name"]
        infons[f"iao_id_{i + 1}"] = section_type["iao_id"]

    return cls(offset=passage.get("offset", 0), infons=infons, text=passage["body"])
from_title(title, offset) classmethod ¤

Create a BioCPassage from a title and offset.

Parameters:

Name Type Description Default
title str

Passage title

required
offset int

Passage offset

required

Returns:

Type Description
BioCPassage

BioCPassage object

Source code in autocorpus/ac_bioc/passage.py
58
59
60
61
62
63
64
65
66
67
68
69
70
@classmethod
def from_title(cls, title: str, offset: int) -> BioCPassage:
    """Create a BioCPassage from a title and offset.

    Args:
        title: Passage title
        offset: Passage offset

    Returns:
        BioCPassage object
    """
    infons = {"iao_name_1": "document title", "iao_id_1": "IAO:0000305"}
    return cls(offset=offset, infons=infons, text=title)
from_xml(elem) classmethod ¤

Create a BioCPassage instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element representing a passage.

required

Returns:

Name Type Description
BioCPassage BioCPassage

An instance of BioCPassage populated with the provided XML data.

Source code in autocorpus/ac_bioc/passage.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCPassage:
    """Create a BioCPassage instance from an XML element.

    Args:
        elem (ET.Element): An XML element representing a passage.

    Returns:
        BioCPassage: An instance of BioCPassage populated with the provided XML data.
    """
    offset = int(elem.findtext("offset", default="0"))
    text = elem.findtext("text", default="")

    infons = {
        e.attrib["key"]: e.text for e in elem.findall("infon") if e.text is not None
    }

    sentences = [
        BioCSentence.from_xml(s_elem) for s_elem in elem.findall("sentence")
    ]

    return cls(
        text=text,
        offset=offset,
        infons=infons,
        sentences=sentences,
    )
to_xml() ¤

Convert the BioCPassage instance to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representation of the BioCPassage instance.

Source code in autocorpus/ac_bioc/passage.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def to_xml(self) -> ET.Element:
    """Convert the BioCPassage instance to an XML element.

    Returns:
        ET.Element: An XML element representation of the BioCPassage instance.
    """
    passage_elem = ET.Element("passage")

    for k, v in self.infons.items():
        infon = ET.SubElement(passage_elem, "infon", {"key": k})
        infon.text = v

    offset_elem = ET.SubElement(passage_elem, "offset")
    offset_elem.text = str(self.offset)

    text_elem = ET.SubElement(passage_elem, "text")
    text_elem.text = self.text

    for sentence in self.sentences:
        passage_elem.append(sentence.to_xml())

    return passage_elem

BioCRelation(id=str(), infons=dict(), nodes=list()) dataclass ¤

Bases: DataClassJsonMixin

A class representing a BioC relation.

Functions¤
from_xml(elem) classmethod ¤

Create a BioCRelation instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element containing the relation data.

required

Returns:

Name Type Description
BioCRelation BioCRelation

An instance of BioCRelation created from the XML element.

Source code in autocorpus/ac_bioc/relation.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCRelation:
    """Create a BioCRelation instance from an XML element.

    Args:
        elem (ET.Element): An XML element containing the relation data.

    Returns:
        BioCRelation: An instance of BioCRelation created from the XML element.
    """
    from .node import BioCNode

    infons = {e.attrib["key"]: e.text for e in elem.findall("infon")}
    nodes = [BioCNode.from_xml(n) for n in elem.findall("node")]
    return cls(
        id=elem.attrib.get("id", ""),
        infons={k: v for k, v in infons.items() if v is not None},
        nodes=nodes,
    )
to_xml() ¤

Convert the BioCRelation instance to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representation of the BioCRelation instance.

Source code in autocorpus/ac_bioc/relation.py
21
22
23
24
25
26
27
28
29
30
31
32
33
def to_xml(self) -> ET.Element:
    """Convert the BioCRelation instance to an XML element.

    Returns:
        ET.Element: An XML element representation of the BioCRelation instance.
    """
    elem = ET.Element("relation", {"id": self.id})
    for k, v in self.infons.items():
        infon = ET.SubElement(elem, "infon", {"key": k})
        infon.text = v
    for node in self.nodes:
        elem.append(node.to_xml())
    return elem

BioCSentence(text, offset, infons=dict(), annotations=list(), relations=list()) dataclass ¤

Bases: DataClassJsonMixin

Represents a sentence in the BioC format.

Functions¤
from_xml(elem) classmethod ¤

Create a BioCSentence instance from an XML element.

Parameters:

Name Type Description Default
elem Element

An XML element representing a sentence.

required

Returns:

Name Type Description
BioCSentence BioCSentence

An instance of BioCSentence created from the XML element.

Source code in autocorpus/ac_bioc/sentence.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@classmethod
def from_xml(cls, elem: ET.Element) -> BioCSentence:
    """Create a BioCSentence instance from an XML element.

    Args:
        elem (ET.Element): An XML element representing a sentence.

    Returns:
        BioCSentence: An instance of BioCSentence created from the XML element.
    """
    offset = int(elem.findtext("offset", default="0"))
    text = elem.findtext("text", default="")

    infons = {
        e.attrib["key"]: e.text for e in elem.findall("infon") if e.text is not None
    }

    annotations = [
        BioCAnnotation.from_xml(a_elem) for a_elem in elem.findall("annotation")
    ]

    return cls(
        text=text,
        offset=offset,
        infons=infons,
        annotations=annotations,
    )
to_xml() ¤

Convert the BioCSentence instance to an XML element.

Returns:

Type Description
Element

ET.Element: An XML element representing the sentence.

Source code in autocorpus/ac_bioc/sentence.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def to_xml(self) -> ET.Element:
    """Convert the BioCSentence instance to an XML element.

    Returns:
        ET.Element: An XML element representing the sentence.
    """
    sentence_elem = ET.Element("sentence")

    for k, v in self.infons.items():
        infon = ET.SubElement(sentence_elem, "infon", {"key": k})
        infon.text = v

    offset_elem = ET.SubElement(sentence_elem, "offset")
    offset_elem.text = str(self.offset)

    text_elem = ET.SubElement(sentence_elem, "text")
    text_elem.text = self.text

    for ann in self.annotations:
        sentence_elem.append(ann.to_xml())

    return sentence_elem

BioCXML ¤

XML serialization for BioC objects.

Functions¤
dumps(collection) staticmethod ¤

Serialize a BioCCollection object to an XML string.

Parameters:

Name Type Description Default
collection BioCCollection

The BioCCollection object to serialize.

required

Returns:

Name Type Description
str str

The XML string representation of the collection.

Source code in autocorpus/ac_bioc/xml.py
11
12
13
14
15
16
17
18
19
20
21
22
@staticmethod
def dumps(collection: BioCCollection) -> str:
    """Serialize a BioCCollection object to an XML string.

    Args:
        collection (BioCCollection): The BioCCollection object to serialize.

    Returns:
        str: The XML string representation of the collection.
    """
    root = collection.to_xml()
    return ET.tostring(root, encoding="unicode")
loads(xml_str) staticmethod ¤

Deserialize an XML string into a BioCCollection object.

Parameters:

Name Type Description Default
xml_str str

The XML string to deserialize.

required

Returns:

Name Type Description
BioCCollection BioCCollection

The deserialized BioCCollection object.

Source code in autocorpus/ac_bioc/xml.py
24
25
26
27
28
29
30
31
32
33
34
35
@staticmethod
def loads(xml_str: str) -> BioCCollection:
    """Deserialize an XML string into a BioCCollection object.

    Args:
        xml_str (str): The XML string to deserialize.

    Returns:
        BioCCollection: The deserialized BioCCollection object.
    """
    root = ET.fromstring(xml_str)
    return BioCCollection.from_xml(root)