Skip to content

Layer

Create new Layer

use LayerEnum to create types of layer.

from openpecha.core.layer import Layer, LayerEnum

layer = Layer(annotation_type=LayerEnum.citation)

assert layer.annotation_type == LayerEnum.citation

Add Annotation to Layer

Refer Annotations docs about OpenPecha annotations.

from openpecha.core.annotations import Citation, Span
from openpecha.core.layer import Layer, LayerEnum

layer = Layer(annotation_type=LayerEnum.citation)
ann = Citation(span=Span(start=10, end=20))

layer.set_annotation(ann)

Get Annotation from layer

from openpecha.core.annotations import Citation, Span
from openpecha.core.layer import Layer, LayerEnum

layer = Layer(annotation_type=LayerEnum.citation)
ann = Citation(span=Span(start=10, end=20))
ann_id = layer.set_annotation(ann)

new_ann = layer.get_annotation(ann_id)

Remove annotation from layer

from openpecha.core.annotations import Citation, Span
from openpecha.core.layer import Layer, LayerEnum

layer = Layer(annotation_type=LayerEnum.citation)
ann = Citation(span=Span(start=10, end=20))
layer.add_annotation(ann)

assert ann.id in layer.annotations

layer.remove_annotation(ann.id)  # new

assert ann.id not in layer.annotations

Bump layer revision number

from openpecha.core.layer import Layer, LayerEnum

layer = Layer(annotation_type=LayerEnum.citation)

assert layer.revision == "00001"

layer.bump_revision()

assert layer.revision == "00002"