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.2

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.2
File Size Uploaded
dep2con-0.2.2.tar.gz 8.5 kB Details

Built distribution (wheel)

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

Total release size: 16.8 kB

Release files / dep2con-0.2.2.tar.gz

Download URL dep2con-0.2.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5617dd68844a7092237fbf0b9241fc65cb52d611dcf73289bd9370e0029ceab8
BLAKE2b-256 checksum
How to use checksums
71fab6eb323d1bb204834e553f548bbc44094aeb4ca481a3d8153a014a80b6be
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.2-py3-none-any.whl

Download URL dep2con-0.2.2-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c73c20aa7784253e96b3d031ae542eadc116e3b28f9e27de22440473ac2c5bc0
BLAKE2b-256 checksum
How to use checksums
a7f4088a52aead52a1453ca8d8a244af8e295e9e65323bce210cb617d999d88a
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

This release

0.2.2 This release

2 release files

0.2.1

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