DexFlex is a Python package for Romanian language processing.
It leverages dexonline to extract dictionary data, applies rule-based methods, and integrates spaCy with the Romanian model ro_core_news_lg.
The library provides functionality such as inflection handling, synonym suggestions, and transformations between tenses and voices.
DexFlex is available on PyPI:
pip install dexflex
- On the first run, a setup script will be executed to fetch and prepare the dictionary data required by DexFlex. This process may take a few minutes depending on your internet connection.
For a given target word, extract all inflectional forms.
Automated switching between past perfect and past simple.
Context-aware synonym generation.
Convert active → passive voice and passive → active voice.
Synonym generation is performed in four steps:
- Identify the current contextual meaning of the word
- Select synonyms that match the sentence’s meaning
- Inflect synonyms to match the contextual grammatical form
- Heuristically sort and return synonyms
- Length of the word
- Dictionary ordering
- Approximate syllable count
- Similarity with context embeddings
- Frequency
pip install dexflexfrom dexflex.prototype import *
import spacy
nlp = spacy.load("ro_core_news_lg")data_aif = [
("ocol", 0),
("Rece, crudă, geloasă pe frumusețea și șarmul Cenușăresei,", 2),
("Ea era hotărâtă să susțină interesele propriilor sale fiice.", 0),
("Castelul a ajuns o ruină.", 0),
]
for sample in data_aif:
doc = nlp(sample[0])
all_forms_for_word = get_all_forms(doc[sample[1]])
print(f"For target-word: {doc[sample[1]]} there are all the inflected forms:")
for form in all_forms_for_word:
print(form)
print("\n\n")samples = [
("Am observat eroarea la timp.", 2),
("Ea a învățat să cânte la pian.", 4),
("Am observat eroarea la timp.", 1),
("Ei au reparat mașina stricată.", -2),
("Tu ai scris o poezie frumoasă.", -2),
("Ea s-a gătit pentru o cină delicioasă.", 3),
("El a uitat să aducă documentele.", -2),
("Ea a primit un cadou de ziua ei.", 4),
("Tu ai vorbit cu profesorul?", -2),
("Ei au construit un parc nou.", 2),
("El a plecat la camera lui.", -3)
]
for sample in samples:
doc = nlp(sample[0])
syn_list = [syn[0] for syn in doc[sample[1]]._.get_syns()]
print(f"Synonyms for: {doc[sample[1]]} are {syn_list}")- DexFlex uses dexonline data, transformed into JSON files for efficient lookups.
- Example contexts are stored as embeddings in
.featherformat for better memory handling. - A working demo is provided in
demo.ipynb.
- 📚 DexOnline reference: github.com/dexonline/dexonline
- 📦 PyPI package: pypi.org/project/dexflex
- 🔎 SpaCy Romanian model:
ro_core_news_lg