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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|