defto_json(self,doc:Document)->Dict[str,Any]:"""Return ``{"sentences": [...]}`` without writing to disk."""returnjsonl_mod.document_to_dict(self.to_records(doc))
defto_brat(self,doc:Document,*,basename:str="document")->Dict[str,str]:"""Return ``{"txt": ..., "ann": ...}`` (``basename`` reserved for writers)."""_=basename# used by ``export_brat``; kept for API symmetryreturnbrat_mod.dumps_brat(self.to_records(doc))
defto_labelstudio(self,doc:Document)->List[Dict[str,Any]]:"""Return Label Studio task dicts (one per sentence)."""returnls_mod.to_labelstudio_tasks(self.to_records(doc))
defexport_jsonl(self,documents:Iterable[Document],path:PathLike,*,renumber:bool=True,)->None:"""Write sentences from many documents to a ``.jsonl`` file. When ``renumber`` is true (default), sentence ``id`` values are reassigned globally ``0..N-1`` across the file for ML convenience. """sentences=self._iter_export_sentences(documents,renumber=renumber)jsonl_mod.dump_jsonl(sentences,path)
defexport_brat(self,doc:Document,out_dir:PathLike,*,basename:str="document",)->None:"""Write ``basename.txt`` and ``basename.ann`` under ``out_dir``."""brat_mod.write_brat(self.to_records(doc),out_dir,basename=basename)
@staticmethoddeffrom_json(data:Union[str,Dict[str,Any],Path])->List[SentenceRecord]:"""Load from a document dict, JSON string, or ``.json`` path."""returnjsonl_mod.load_json(data)
@staticmethoddeffrom_jsonl(source:Union[str,Path])->List[SentenceRecord]:"""Load from a ``.jsonl`` path or a JSONL string."""returnjsonl_mod.load_jsonl(source)
@staticmethoddeffrom_conll(source:Union[str,Path])->List[SentenceRecord]:"""Reserved for future CoNLL import."""raiseNotImplementedError("CorpusImporter.from_conll is not implemented yet; ""use from_json / from_jsonl for round-trips")