Skip to main content

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
  • pyconll 4.0 or newer for CoNLL-U input
  • stanza when 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 sentence
  • x_phrases - constituents for the specified phrases
  • sent_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 text
  • sent_len - sentence length
  • sentence_index - an index of a sentence in a text
  • source - sentence source if mentioned in a CoNLL-U file

Input arguments:

  • input: str, obligatory. Is string if use_parser = True, otherwise input in conllu format
  • lang: str, the language parameter ('en',...) in case of text parsing
  • use_parser: bool, True - the Stanza parser is at work; False - input in the conllu format, default = False
  • delete_orth: bool, delete orthography from the final tree, default = False
  • xps: bool, return specific phrases separately, default = True
  • emb: bool, returns subconstituents, not only maximal projection, if True, default = True
  • h_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)

Source distribution for dep2con 0.2.1
File Size Uploaded
dep2con-0.2.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dep2con 0.2.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

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