Skip to main content

asymgram

asymgram is a small Python toolkit for working with CoNLL-U dependency treebanks. It wraps parsed CoNLL-U tokens and sentences with convenient object references, provides tree manipulation helpers, evaluates dependency parses, and includes diagnostics for common annotation and format errors.

The package is designed for corpus linguistics, dependency grammar research, Universal Dependencies style treebank work, and quick inspection of parser output.

Features

  • Enhanced CoNLL-U objects: Token, TokenList, SentenceList, and SentenceLists.
  • Context-aware token navigation, including head lookup, dependent lookup, subtree span extraction, and node depth.
  • Sentence and token manipulation helpers for merging tokens, splitting tokens, removing leaf nodes, merging sentences, and splitting sentences at marginal subtrees.
  • Basic dependency evaluation metrics: UAS and LAS.
  • CoNLL-U readers, writers, text reconstruction, and simple conversion helpers.
  • Error checking for common CoNLL-U and dependency treebank issues, including invalid IDs, malformed HEAD values, self-loops, cycles, missing roots, multiple roots, invalid UPOS/DEPREL labels, malformed FEATS/DEPS, punctuation mismatches, and suspicious UPOS-DEPREL combinations.

Installation

pip install asymgram

For local development:

git clone https://github.com/Yihtsy/asymgram.git
cd asymgram
pip install -e .

Optional NLP-related dependencies can be installed with:

pip install "asymgram[nlp]"

Quick Start

import asymgram as ag

text = """
# sent_id = demo-1
# text = I saw her.
1	I	_	PRON	_	_	2	nsubj	2:nsubj	_
2	saw	_	VERB	_	_	0	root	0:root	_
3	her	_	PRON	_	_	2	obj	2:obj	SpaceAfter=No
4	.	_	PUNCT	_	_	2	punct	2:punct	_
"""

sentences = ag.parse(text)
sentence = sentences[0]
root = sentence.get_roottoken()

print(root.form)
print([tok.form for tok in root.get_deptokens(include_punct=True)])
print(sentences.to_tokenized_text())

Error Checking

asymgram.error_checker can inspect raw CoNLL-U text, files, parsed sentences, or sentence lists.

from asymgram.error_checker import check_conllu_text, check_file

diagnostics = check_conllu_text(text)

for diagnostic in diagnostics:
    print(diagnostic.level, diagnostic.code, diagnostic.sent_id, diagnostic.token_id, diagnostic.message)

file_diagnostics = check_file("treebank.conllu")

Each diagnostic is represented by a Diagnostic object:

Diagnostic(
    code="SELF_LOOP",
    level="ERROR",
    message="token cannot take itself as HEAD",
    sent_id="demo-1",
    token_id=3,
)

Diagnostic levels are:

  • ERROR: structural or format problems that are usually automatically decidable.
  • WARNING: strong annotation warnings that should be manually checked.
  • INFO: low-frequency or linguistically atypical patterns that may still be valid.

Common APIs

import asymgram as ag

sentences = ag.read_conllu("sample.conllu")
sentences.to_conllu("copy.conllu")

root = sentences[0].get_roottoken()
children = root.get_deptokens()
span = root.get_subtree_span()

uas = ag.uas(gold_sentences, predicted_sentences)
las = ag.las(gold_sentences, predicted_sentences)

Notes

asymgram follows the CoNLL-U conventions used by Universal Dependencies, but it is not limited to official UD treebanks. Some diagnostics intentionally return warnings or info-level messages because many unusual UPOS-DEPREL combinations can be valid in ellipsis, multiword expressions, headless constructions, dates, measurements, names, and language-specific analyses.

License

License information has not yet been specified.

Metadata

Release files for asymgram 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asymgram 0.1.0
File Size Uploaded
asymgram-0.1.0.tar.gz 32.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asymgram 0.1.0
File Interpreter ABI Platform
asymgram-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 63.6 kB

Release files / asymgram-0.1.0.tar.gz

Download URL asymgram-0.1.0.tar.gz
Size 32.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8230c9aad3736d58ca986ed0b3cf0142743efdffb38bfcfb479e5fc265cbecfb
BLAKE2b-256 checksum
How to use checksums
282fcead4477b4e7c8f70bdba285d0bab5c341ea4e2ad02bda339b5e9cdc5939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / asymgram-0.1.0-py3-none-any.whl

Download URL asymgram-0.1.0-py3-none-any.whl
Size 31.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f8ecf5723f7a47a0cad89a1c2e240cef0322059099eed73feaa338d92824b43
BLAKE2b-256 checksum
How to use checksums
cd77a2950690ea4400913414aadccdf061a3263990c929094d9276ea539f5742
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page