Package: pyrealb
pyrealb- A Python Bilingual Text RealizerVersion 3.0.0 - December 2023pyrealbis a Python adaptation of the JavaScriptjsRealBtext realizer with the same constituent and dependency syntax notation.
It facilitates its integration within Python applications by simply addingfrom pyrealb import *Online documentationVersion 3.0.0 is a major code reorganization, but without any new feature, to clearly separate language dependent parts from the language independent ones. This organization is describedhere.The use of pyrealb forBilingual Data-to-text generation is described in this document.Installing the distribution package from PyPIpip install pyrealbCaution: do not forget thebat the end ofpyrealb. OnPyPI, there is an unrelated packagepyrealfor evaluating and deploying human readable machine learning explanations.Upgrading the versionpip install pyrealb --upgradeBuilding and installing the package from the sourcescdinto this directory (withpyproject.tomlfile)Build the distribution packagepython3 -m buildInstall withpython3 -m pip install .First realization tests at the Python 3 promptfrom pyrealb import *loadEn()print(S(Pro("I").g("f"),VP(V("say"),"hello",PP(P("to"),NP(D("the"),N("world"))))))this should printShe says hello to the world.print(root(V("say").t("ps"),subj(Pro("him").c("nom")),comp(N("goodbye"))).typ({"neg":True}))this should printHe did not say goodbye.Use pyrealb in aJupyter notebookthruBinderin a browser, load one of these links:English.French.Directoriessrc__init__.py: empty program that imports subpackages and exports relevant symbols.Constituent.py:Constituentis the top class for methods shared betweenPhrases andTerminalsConstituentEn.py,ConstituentFr.py: English and French specific processing ofConstituentDependent.py: subclass ofConstituentfor creating complex phrases using dependenciesDependentEn.py,DependentFr.py: English and French specific processing ofDependentLexicon.py: class to access lexicon entries and syntactic rulesNumber.py: utility functions for dealing with number formattingNonTerminalEn.py,NonTerminalFr.py: language dependent processing common toPhraseandDependentPhrase.py: subclass ofConstituentfor creating complex phrasesPhraseEn.py,PhraseFr.py: English and French specific processing ofPhraseTerminal.py: subclass ofConstituentfor creating a single unit (most often a single word)TerminalEn.py,TerminalFr.py: English and French specific processing ofTerminalutil.py: some useful functionsdata: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 tablesNota bene:In the following directories, the__init__.pyfile is used to set the appropriate search path forpyrealbfunctions; this ensures that the current Python source files are used for execution.Some directories includemarkup.pywhich should be loaded usingpip. Unfortunately I never managed to make this "piped" version work, it does not import the nameonelineralthough 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 directlyOnline versiondocumentation.py: Python program for generatingdocumentation.htmlusingmarkup.pyonce this is rundocumentation.htmlshould be copied athttp://www.iro.umontreal.ca/~lapalme/pyrealb/documentation.htmlwhich is used for consultationstyle.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 Pythonread-eval-print loop, it importspyrealbto get the realization of an expression, to consult the lexicon, the conjugation and declension tables. It is also possible to get alemmatization: i.e. thepyrealbexpression corresponding to a form.README.html: documentation and examplestests: unit tests of special features ofpyrealbin both French and English. Files have the pattern*_{en|fr}.pytest.py: simplistic function to check if a function returns the expected answer and display appropriate messagetestAll.html: run this file to run all testsDemos99bottlesofbeer/99bottlesofbeer.py: simple generation of a classic repetitive text in English.basketball/sportsettsum.py: generation of French and English basketball summariespaper describing the approachBilinguo/bilinguo.py: generation of translation drill exercisesdev_example/dev_example.py: examples of English and French expressions to be realized and checked against expected output,useful for debugging when adding a new expression and enabling tracingevenementsDemo/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 subject using two different program organizationvariantes/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 ajson-linefile. (weather-data.jsonl). It uses the packages in theRealizationdirectory.Licensespyrealbsource code is licensed underApache-2.0and the linguistic resources in the./datadirectory is
licensed underCC-BY-SA-4.0ContactGuy LapalmeAcknowledgementThanks to Fabrizio Gotti, François Lareau and Ludan Stoeckle for interesting suggestions.For the maintainer mainlyUpdating package version on PyPIseethis tutorialThese steps take for granted that the password for PyPI has already been given...Update version number insetup.cfg(it should be the same aspython_versioninsrc/pyrealb/utils.pyand at
the beginning of this document).Rundocs/documentation.pyto update the version number indocs/documentation.htmlcdinto the directory with thepyproject.tomlfile (the same as thisREADME.md)Build the distribution packagepython3 -m buildUpload to PyPi the last version I.J.Ktwine upload dist/*-I.J.K.*Install new version from PyPIpython3 -m pip install pyrealb --upgradeUseful trick for debugging with breaking point and tracing in PyCharmaddpyrealbexpression to debug at the end ofdemo/dev_example/dev_example.pycomment the line callingtestPreviousExamples()debugdemo/dev_example/dev_example.py