A French-English text realizer
Project description
pyRealB - A Python Bilingual Text Realizer
Version 2.3 - February 2023
pyRealB is a Python adaptation of the JavaScript jsRealB text realizer with the same constituent and dependency syntax notation. It facilitates its integration within Python applications by simply adding
from pyrealb import *
Installing the distribution package from PyPI
pip install pyrealb
Upgrading the version
pip install pyrealb --upgrade
Building and installing the package from the sources
cd
into this directory (withpyproject.toml
file)- Build the distribution package
python3 -m build
- Install with
python3 -m pip install .
First realization tests at the Python 3 prompt
from pyrealb import *
loadEn()
print(S(Pro("I").g("f"),VP(V("say"),"hello",PP(P("to"),NP(D("the"),N("world"))))))
- this should print
She says hello to the world.
print(root(V("say").t("ps"),subj(Pro("him").c("nom")),comp(N("goodbye"))).typ({"neg":True}))
- this should print
He did not say goodbye.
Use pyrealb in a Jupyter notebook thru Binder
- in a browser, load one of these links:
Directories
src
__init__.py
: empty program that imports subpackages and exports relevant symbols.Constituent.py
: Constituent is the top class for methods shared between Phrases and TerminalsLexicon.py
: class to access lexicon entries and syntactic rulesNumber.py
: utility functions for dealing with number formattingPhrase.py
: subclass of Constituent for creating complex phrasesDependent.py
: subclass of Constituent for creating complex phrases using dependenciesTerminal.py
: subclass of Constituent for creating a single unit (most often a single word)util.py
: some useful functionsWarning.py
: function to generate warnings in case of erroneous specifications using pyRealB itselfdata
:lexicon-en.json
: English lexicon (33,932 entries) in json formatrule-en.js
: English conjugation and declension tableslexicon-fr.json
: French lexicon (52,547 entries) in json formatrule-fr.js
: French conjugation and declension tables
In most of the following directories, a context.py
file is used to set the appropriate search path for pyRealB functions. Thus, many example programs start with the following lines:
from context import pyrealb
from pyrealb import *
Some directories include markup.py
which should be loaded using pip
. Unfortunately I never managed to make this "piped" version work, it does not import the name oneliner
although it should. It works once the file is in the local directory.
-
docs
: in both English and French.documentation.html
: generated documentation (used for consultation) DO NOT EDIT directlydocumentation.py
: Python program for generatingdocumentation.html
usingmarkup.py
style.css
: style sheet for the documentationuserinfos.py
: definitions of variables containing the examplesuser.js
: Python helper script.
-
IDE
: Integrated Development Environmentide.py
: built on the Python read-eval-print loop, it imports pyRealB to get the realization of an expression, to consult the lexicon, the conjugation and declension tables. It is also possible to get a lemmatization: i.e. the pyRealB expression corresponding to a form.README.html
: documentation and examples
-
tests
: unit tests of special features of pyRealB in both French and English. Files have the pattern*_{en|fr}.py
test.py
: simplistic function to check if a function returns the expected answer and display appropriate messagetestAll.html
: run this file to run all tests
Demos
99bottlesofbeer/99bottlesofbeer.py
: simple generation of a classic repetitive text in English.evenementsDemo/evenements.py
: Description (in French) of a list of events, it creates HTML.flight_infos/README.md
: development of a RASA NLG server giving information about flights, aircrafts, etc...gophypi/amr2text.py
: generate a literal reading of an AMR (Abstract Meaning Representation);
paper describing the approachinflectionDemo/inflection.py
: French or English conjugation and declension of a form.kilometresapied/kilometresapied.py
: simple generation of a classic repetitive text in French.methodius/methodius.py
: generation of English sentences from a logical form expressed in XML.randomgen/randomgen.py
: Generation of random English sentencesRDFpyrealb/WebGenerate.py
: Generation from RDF triplesreport/report.py
: Single sentence parameterized by language, tense and subjectsimple_example/simple_example.py
: a few examples of English and French expressions to be realizedvariantes/variantes.py
: French or English sentences realized with all possible sentence modifiers; some challenging examples are inexamples.py
.weather/Bulletin.py
: French and English weather bulletins generated from information in a json-line file. (weather-data.jsonl
). It uses the packages in theRealization
directory.
Contact
Acknowledgement
Thanks to Fabrizio Gotti for helping to organize the Python package.
Updating package version on PyPI (for the maintainer only)
see this tutorial
These steps take for granted that the password for PyPI has already been given...
- update version number in
setup.cfg
cd
into the directory with thepyproject.toml
file- Build the distribution package
python3 -m build
- Upload to PyPi
twine upload dist/*
- Install new version from PyPI
python3 -m pip install pyrealb --upgrade
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.