Skip to content

Export

Span-based corpus export for training datasets. Converts pipeline Document objects without changing the parser or Document API.

from burmesenlp import process, CorpusExporter

doc = process("ကျွန်တော်ကျောင်းသို့သွားသည်။")
exporter = CorpusExporter()

exporter.to_json(doc)       # {"sentences": [...]}
exporter.to_jsonl(doc)      # one JSON object per sentence
exporter.to_conll(doc)
exporter.to_brat(doc)       # {"txt": ..., "ann": ...}
exporter.to_labelstudio(doc)

burmesenlp.export.CorpusExporter

Convert Document analysis objects into training-friendly formats.

The NLP pipeline and Document model are left unchanged; this layer only remaps existing annotations into non-redundant span records.

to_records

to_records(doc: Document) -> List[SentenceRecord]

Return sentence records for doc.

Source code in src/burmesenlp/export/exporter.py
def to_records(self, doc: Document) -> List[SentenceRecord]:
    """Return sentence records for ``doc``."""
    return document_to_sentences(doc)

to_json

to_json(doc: Document) -> Dict[str, Any]

Return {"sentences": [...]} without writing to disk.

Source code in src/burmesenlp/export/exporter.py
def to_json(self, doc: Document) -> Dict[str, Any]:
    """Return ``{"sentences": [...]}`` without writing to disk."""
    return jsonl_mod.document_to_dict(self.to_records(doc))

to_jsonl

to_jsonl(doc: Document) -> str

Return newline-delimited JSON (one sentence object per line).

Source code in src/burmesenlp/export/exporter.py
def to_jsonl(self, doc: Document) -> str:
    """Return newline-delimited JSON (one sentence object per line)."""
    return jsonl_mod.dumps_jsonl(self.to_records(doc))

to_conll

to_conll(doc: Document) -> str

Return CoNLL-style token rows for all sentences in doc.

Source code in src/burmesenlp/export/exporter.py
def to_conll(self, doc: Document) -> str:
    """Return CoNLL-style token rows for all sentences in ``doc``."""
    return conll_mod.dumps_conll(self.to_records(doc))

to_brat

to_brat(doc: Document, *, basename: str = 'document') -> Dict[str, str]

Return {"txt": ..., "ann": ...} (basename reserved for writers).

Source code in src/burmesenlp/export/exporter.py
def to_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 symmetry
    return brat_mod.dumps_brat(self.to_records(doc))

to_labelstudio

to_labelstudio(doc: Document) -> List[Dict[str, Any]]

Return Label Studio task dicts (one per sentence).

Source code in src/burmesenlp/export/exporter.py
def to_labelstudio(self, doc: Document) -> List[Dict[str, Any]]:
    """Return Label Studio task dicts (one per sentence)."""
    return ls_mod.to_labelstudio_tasks(self.to_records(doc))

export_jsonl

export_jsonl(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.

Source code in src/burmesenlp/export/exporter.py
def export_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)

export_brat

export_brat(doc: Document, out_dir: PathLike, *, basename: str = 'document') -> None

Write basename.txt and basename.ann under out_dir.

Source code in src/burmesenlp/export/exporter.py
def export_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)

burmesenlp.export.CorpusImporter

Load span-based sentence records from serialized corpora.

Does not reconstruct pipeline Document objects — only the export schema.

from_json staticmethod

from_json(data: Union[str, Dict[str, Any], Path]) -> List[SentenceRecord]

Load from a document dict, JSON string, or .json path.

Source code in src/burmesenlp/export/importer.py
@staticmethod
def from_json(data: Union[str, Dict[str, Any], Path]) -> List[SentenceRecord]:
    """Load from a document dict, JSON string, or ``.json`` path."""
    return jsonl_mod.load_json(data)

from_jsonl staticmethod

from_jsonl(source: Union[str, Path]) -> List[SentenceRecord]

Load from a .jsonl path or a JSONL string.

Source code in src/burmesenlp/export/importer.py
@staticmethod
def from_jsonl(source: Union[str, Path]) -> List[SentenceRecord]:
    """Load from a ``.jsonl`` path or a JSONL string."""
    return jsonl_mod.load_jsonl(source)

from_conll staticmethod

from_conll(source: Union[str, Path]) -> List[SentenceRecord]

Reserved for future CoNLL import.

Source code in src/burmesenlp/export/importer.py
@staticmethod
def from_conll(source: Union[str, Path]) -> List[SentenceRecord]:
    """Reserved for future CoNLL import."""
    raise NotImplementedError(
        "CorpusImporter.from_conll is not implemented yet; "
        "use from_json / from_jsonl for round-trips"
    )

burmesenlp.export.SentenceRecord dataclass

SentenceRecord(id: int, text: str, tokens: List[TokenRecord] = list(), chunks: List[ChunkRecord] = list(), clauses: List[ClauseRecord] = list(), entities: List[EntityRecord] = list(), mwe: List[MWERecord] = list())

One training-friendly sentence with span-based annotations.

burmesenlp.export.TokenRecord dataclass

TokenRecord(id: int, text: str, pos: str, lemma: Optional[str] = None, norm: Optional[str] = None, syllables: Optional[List[str]] = None, features: Optional[Mapping[str, str]] = None, head: Optional[int] = None, deprel: Optional[str] = None)

One token in a sentence.

burmesenlp.export.ChunkRecord dataclass

ChunkRecord(id: int, type: str, start: int, end: int, function: Optional[str] = None, semantic_role: Optional[str] = None)

Phrase chunk as a token span (no nested tokens).

burmesenlp.export.ClauseRecord dataclass

ClauseRecord(id: int, type: str, start: int, end: int, relation: Optional[str] = None, marker: Optional[str] = None)

Clause as a token span (no nested chunks/tokens).

burmesenlp.export.EntityRecord dataclass

EntityRecord(id: int, label: str, start: int, end: int)

Named entity as a token span.

burmesenlp.export.MWERecord dataclass

MWERecord(id: int, type: str, start: int, end: int)

Multi-word expression as a token span.