Search, match, and batch-edit Universal Dependencies treebanks
Project description
udsearch
Search, match, and batch-edit Universal Dependencies treebanks from the command line or as a Python library.
Pure Python, no external dependencies.
Install
pip install udsearch
CLI
# Search for tokens
udsearch "UPOS=NOUN & Case=Dat" -t Turkish-BOUN
udsearch "UPOS=NOUN|PROPN & deprel=nsubj" -f corpus.conllu
# Structural patterns (multi-node)
udsearch $'v: [UPOS=VERB]\ns: [UPOS=NOUN] -nsubj-> v' -f corpus.conllu
udsearch --pattern-file query.txt -f corpus.conllu
# Clustering (Grew-match style)
udsearch "UPOS=NOUN" -t Turkish-BOUN --cluster
udsearch "deprel=obl" -t Turkish-BOUN --cluster Case Number
# Batch rewrite (dry-run by default)
udsearch "UPOS=NOUN & lemma=yok" --set "UPOS=ADJ" --set "Polarity=Neg" -f tb.conllu
udsearch "UPOS=NOUN & lemma=yok" --set "UPOS=ADJ" -f tb.conllu --apply
# Structural rewrite (target specific nodes)
udsearch $'v: [UPOS=VERB]\ns: [] -nsubj-> v' --set "s.Case=Nom" -f tb.conllu --apply
# Treebank management
udsearch --list tr # list Turkish treebanks on GitHub
udsearch --list-cached # show downloaded treebanks
Pattern syntax
Single-node
UPOS=NOUN exact match
UPOS=NOUN|PROPN alternatives
lemma=/^yap/ regex
!PronType=Prs negation
PronType feature exists
UPOS=NOUN & Case=Dat conjunction
Structural (multi-node)
v: [UPOS=VERB] named node
s: [UPOS=PRON & Case=Nom] -nsubj-> v dependency relation
!a: [UPOS=AUX] -aux-> v negated (must NOT exist)
d: [] -nsubj|obj-> v deprel alternatives
d: [] -/^nsubj/-> v deprel regex
d: [] -> v any relation
s << v linear precedence
Rewrite operations
Polarity=Neg add/set feature
UPOS=ADJ change column field
-Case remove feature
MISC.Lang=en set MISC field
s.Case=Nom target node in structural pattern
Library usage
from udsearch import parse_conllu, parse_pattern, search_treebank
from udsearch import parse_structural, match_structural
# Parse CoNLL-U
sentences = parse_conllu(open("corpus.conllu").read())
# Single-node search
pattern = parse_pattern("UPOS=VERB & Tense=Past")
for sent, tokens in search_treebank(sentences, pattern):
print(sent.sent_id, [t.form for t in tokens])
# Structural search
sp = parse_structural("v: [UPOS=VERB]\ns: [UPOS=NOUN] -nsubj-> v")
for sent, bindings in search_structural(sentences, sp):
for b in bindings:
print(f"{b['v'].form} <- {b['s'].form}")
# Batch rewrite
from udsearch import apply_operations, parse_set_operations
ops = parse_set_operations(["Polarity=Neg"])
for sent, tokens in search_treebank(sentences, pattern):
for token in tokens:
changes = apply_operations(token, ops)
Dict-based API (for web apps)
from udsearch import match_structural_dicts, apply_operations_to_dicts
# Works with dict-based wordlines (e.g., from a database)
wordlines = [{"id_f": "1", "form": "cat", "upos": "NOUN", ...}, ...]
matches = match_structural_dicts("UPOS=NOUN", wordlines)
modified, changes = apply_operations_to_dicts(wordlines, "UPOS=NOUN", ["Case=Acc"])
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
udsearch-0.1.0.tar.gz
(27.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
udsearch-0.1.0-py3-none-any.whl
(22.6 kB
view details)
File details
Details for the file udsearch-0.1.0.tar.gz.
File metadata
- Download URL: udsearch-0.1.0.tar.gz
- Upload date:
- Size: 27.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5f3d10b21eb7516c3ff4ea0c666c9637574221e7db5178e8fb3062e28e1b50
|
|
| MD5 |
87511aacac6420bf976a169753b90f48
|
|
| BLAKE2b-256 |
345e2715bbb6cc7851c2e38fe2970f7bcb2eafb51ffe3b1aa9e343b251d0d21b
|
File details
Details for the file udsearch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: udsearch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b44ff513db6f7e1659667676586224369b1184a1f4f87149e1407020cc66b09
|
|
| MD5 |
05784e758f189a1de97dad9eff04689c
|
|
| BLAKE2b-256 |
b5bf3c5dc3c0b522a6098117051f68095b52bbc5d26f8765ceca06b9631cf3fe
|