dep2con
dep2con converts Universal Dependencies (UD) parses into constituency
representations. It accepts either a CoNLL-U format or text for the
Stanza dependency parser.
Requirements
- Python 3.14 or newer
pyconll4.0 or newer for CoNLL-U inputstanzawhen parsing raw text
Installation
Install the published package:
python -m pip install dep2con
Usage
from dep2con import make_const
Simple usage (for string parsing):
t_s = make_const("I saw a UFO in the backyard.", lang = 'en', use_parser = True)
for dep2con in t_s:
print(dep2con.sent_parse)
for i in dep2con.x_phrases:
print(i)
[VP [NP I] saw [NP a UFO] [PP in [NP the backyard]]] .
...
NPs:
I
a UFO
the backyard
VPs:
I saw a UFO in the backyard
PPs:
in the backyard
More on usage (for a CoNLL-U format):
t_s = make_const("conllu")
for dep2con in t_s:
print(dep2con.sent_parse)
print(dep2con.x_phrases)
print(dep2con.sentence_index)
...
Output attributes:
make_const() returns a list with one Dep2Con object per input sentence.
Each result has these attributes:
sent_parse- a constituency tree for the sentencex_phrases- constituents for the specified phrasessent_dict- a dictionary format for a sentence UD{1: {'idw': 1, 'wf': 'I', 'nf': 'I', 'pos': 'PRON', 'xpos': '_', 'tags': 'Case=Nom|Number=Sing|Person=1|PronType=Prs', 'head_id': 2, 'rel': 'nsubj', 'deps': '_', 'misc': '_'},...sent_text- sentence textsent_len- sentence lengthsentence_index- an index of a sentence in a textsource- sentence source if mentioned in a CoNLL-U file
Input arguments:
input: str, obligatory. Is string ifuse_parser = True, otherwise input in conllu formatlang: str, the language parameter ('en',...) in case of text parsinguse_parser: bool, True - the Stanza parser is at work; False - input in the conllu format,default = Falsedelete_orth: bool, delete orthography from the final tree,default = Falsexps: bool, return specific phrases separately,default = Trueemb: bool, returns subconstituents, not only maximal projection, if True,default = Trueh_terminals: List[str], terminals to be put in brackets w/out dependents,default = ['NOUN', 'PRON', 'PROPN', 'ADV']selected_cons: List[str], when we want some specific constituents only,default = ['NP', 'VP', 'PP', 'AP', 'AdvP', 'NumP', 'PartP', 'CCONJP', 'INTJP', 'Particle', 'SCONJP', 'SYMP', 'XP']
Metadata
Release files for dep2con 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dep2con-0.2.1.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dep2con-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / dep2con-0.2.1.tar.gz
| Download URL | dep2con-0.2.1.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6295dbc762fe6fc27d060a4884e01ca2f58ebf202a76ec2e48856279735b553
|
|
BLAKE2b-256 checksum How to use checksums |
95e15cf5bbc7a5653c5a1a4e990cb8ae43007112d5e512e092b7589dc885ca4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / dep2con-0.2.1-py3-none-any.whl
| Download URL | dep2con-0.2.1-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae8417c4023ee9a4e30f37b3aff969848599b2cbdf13f7b39d07edb9d8ad9cdb
|
|
BLAKE2b-256 checksum How to use checksums |
899b2c6f5714022ec1d95977aef525585c7030665eb1d4a1452f1f0ad2bb37dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|