11import json
2+ from multiprocessing import reduction
23import shutil
34from pathlib import Path
45from typing import Dict , List , Optional
56
67from stam import AnnotationStore , Offset , Selector
8+ from openpecha .pecha .annotations import span
79
810from openpecha .exceptions import StamAddAnnotationError , FileNotFoundError , MetaDataValidationError
911from openpecha .ids import (
@@ -27,6 +29,7 @@ def __init__(self, pecha_id: str, pecha_path: Path) -> None:
2729 self .bases = self .load_bases ()
2830 self .annotations = []
2931
32+
3033 @classmethod
3134 def from_path (cls , pecha_path : Path ) -> "Pecha" :
3235 # Validate that the path exists
@@ -252,6 +255,20 @@ def update_annotation(self, annotation_id: str, annotation:List[BaseAnnotation],
252255 self .add (annotation_id , annotation )
253256 return self
254257
258+ def get_base_text (self ) -> str :
259+ base_dir = self .pecha_path / "base"
260+ for base_file in base_dir .glob ("*.txt" ):
261+ base_text = base_file .read_text (encoding = "utf-8" )
262+ return base_text
263+
264+ def get_span_text (self , span : Optional [span ] = None ) -> str :
265+ base_text = self .get_base_text ()
266+ if span is None :
267+ return base_text
268+ else :
269+ return base_text [span .start :span .end ]
270+
271+
255272
256273def get_anns (ann_store : AnnotationStore , include_span : bool = False ):
257274 anns = []
0 commit comments