JSrealB: A bilingual text realizer for web programming [scientific short paper]
More information on JSrealB, including demos >>
Recherche appliquée en linguistique informatique
Université de Montréal
Natural language generation can automate a significant part of textual production, only requiring a human to supply some important aspects and thus saving considerable time for producing consistent grammatically correct output. In recent years, tools such as SimpleNLG (Gatt and Reiter, 2009) facilitated text realization by a programmer provided they program their application in Java. This system was then extended with SimpleNLG-EnFr (Vaudry and Lapalme, 2013), a English-French version of SimpleNLG.
The principles underlying JSrealB are similar to those of SimpleNLG: programming language instructions create data structures corresponding to the constituents of the sentence to be produced. Once the data structure (a tree) is built in memory, it is traversed to produce the list of tokens of the sentence. This data structure is built by function calls whose names are the same as the symbols usually used for classical syntax trees: for example, N to create a noun structure, NP for a Noun Phrase, V for a Verb, D for a determiner, S for a Sentence and so on. Features added to the structures using the dot notation can modify the values according to what is intended.
Theoretically, JSrealB requires no knowledge in computer science, its syntactic representation being patterned after classical constituent grammar notations. For example,
is the JSrealB specification for The women ate. Plural is indicated with feature n("p") where n indicates number and p plural. The verb is conjugated to past tense indicated by the feature tense t and value ps. Agreement between NP and VP is performed automatically.
French and English are languages whose structures are similar. Both languages use the same alphabet, they are both fusional languages sharing a similar conjugation system and their word order follows the same basic Subject-Verb-Object paradigm (Shoebottom, 1996).
Structural differences do exist: in English, the adjective normally goes before the noun it qualifies, while in French it can appear before or after depending on the meaning (e.g. in French, we say un grand homme for a great man and un homme grand for a big man). In French, nouns agree in gender and number (e.g. un ami in masculine singular, des amies with final es in feminine plural), in English they agree only in numbers (e.g. friend become friends in plural). French determiners are based on the gender and number of the noun they are associated with, and adjectives agree with the nouns they qualify but not in English.
These differences must be taken into account at many levels. First, syntactic differences and agreements (i.e. features propagation), must be handled at the phrase or sentence level by algorithms. For French complex rules, we followed "Le bon usage, grammaire française" (Grevisse, 1980). For English, we relied on various sources from the web.
JSrealB lexicons are based on the ones found in SimpleNLG-EnFr (Vaudry and Lapalme, 2013) These lexicons can be completed by the user to add domain-specific vocabularies. In lexicons, words have grammatical properties (e.g. category, gender, etc.). and a link to an inflection table. Tables are defined for nouns, adjective, verbs and pronouns in both English and French. These inflection rules are language specific and correspond to the information found in (Bescherelle, 2012) and (Delaunay and Laurent, 2013). These conjugation, declension or transformation tables are included with the lexicon in JSrealB, they are defined declaratively for each language and interpreted by a rule engine common to both languages.
Our goal is to develop an English and French text realizer with minimal specific adaptations to each language. We have promoted the systematic application of rules hoping it is possible to support other languages at limited cost.
JSreal organization was closely bound to French, so we recognized that it was very hard to adapt JSreal for bilingualism by refactorisation.
We then completely revised its architecture and particularly the rules implementation. So we decided to code transformation rules in tables so that it works for most fusional languages. We aimed at developping a modular program to allow evolution towards to other languages, all modules being hidden behind a specific facade.
A JSrealB user can create a syntactic representation by using a facade which analyzes syntax and propagates features between phrases and from phrases to terminal elements. With an inheritance system, we can use the same propagation scenario or define a special scenario for each language. We can do the same for grammatical function identification and word ordering.
This facade handles the JSrealB core, which is divided into modules to provide better scalability. Basic operations like conjugation, declension, and punctuation are common to fusional languages. We can then define modules to be used by all languages with input parameters that differ such as lexicon and tables.
Text realization uses a syntactic hierarchical tree representation that creates a sentence by combining phrases and terminals. The relations between these lexical units determine the propagation of features between words for determining proper agreements. For example, in
grammatical categories of words are already specified in the syntactic representation. Word order usually follows the left to right order of the terminals in the tree except in some coordinated sentences where position of coordinate must be determined.
The relations between non-terminals specified in the input determine the grammatical functions of each element, which are roughly similar between French and English.
NP( AP( A("fort") ),
NP( N("orage") ),
NP( N("minuit") ) ) )
NP( AP( A("heavy") ),
NP( N("thunderstorm") ),
NP( N("midnight") ) ) )
Fortes averses ou orages cessant vers minuit.
Heavy showers or thunderstorms ending near midnight.
Figure 1 - Similar syntactic representation for both French and English, only the vocabulary differs.
We can then compute the agreement between elements of the sentence in order to propagate appropriate features to the words according to the rules of the language. These rules are similar between French and English in the case of a verb phrase where the verb agrees with the subject, but they can also differ, such as for a noun phrase where the adjective agrees with the noun that it qualifies and the possessive pronoun agrees with the noun in French. In English though, the adjective does not vary and the possessive agrees with the gender of the possessor. For example, ma belle fleur vs his/her beautiful flower in English.
Orthographic realization in JSrealB is performed during morphological realization. Sentence relays features, especially HTML tags, capitalization and full stop, to its elements (i.e. children elements), default and user features go down from sentence to lexical unit with the aim of formatting each phrase with proper elision.
The main difference between English and French lies in the rules applied to terminal elements: conjugation is specific to each language; agreements do not apply to the same categories (e.g. adjectives agree in French, but not in English). Therefore, it is necessary to define those rules outside the program and apply them systematically through transformation tables.
A realisation example
In sentences of Figure 1, S relays features to its elements (e.g. tense is relayed to the verbal phrase) and causes phrase realization. Sentence also propagates features for orthographic realization (e.g. capitalize first letter of sentence). Each phrase realization determines the grammatical function of each element before its realization. The first step is the coordinated phrase realization that relays grammatical number property to each element, except for the coordinate. Noun phrases propagate plural to the head noun which is declined in number. Dependents (i.e. adjective) must agree in number and gender with the noun. Noun realization allows passing the gender and number properties of noun averse/shower on adjective fort/heavy. The gender property is determined by a lexicon search. In English, as the adjective does not vary, there is no propagation from head to dependent in noun phrases.
We can notice that syntactic representations are similar, modifiers too, the only difference being the vocabulary. In our application, we can thus use the same sentence specification linking each concept to an appropriate word in each language.
JSrealB implements French and English grammatical categories: noun, pronoun, determiner, adjective, preposition, conjunction, and complement; the implemented phrases are: noun, verbal, adjectival, adverbial, prepositional, subordinate, and coordinate. The sentence combines all these phrases.
Supported inflections are conjugation for simple tenses, and declension in gender and number for every grammatical category. Noun phrase agrees in gender and number, while verbal phrase agrees with every type of subject (i.e. common or proper noun, or pronoun).
JSrealB is used in a weather information display application (MeteoVis) in which text is generated on the fly (either in French or English) by the browser from the numerical information and syntactic specification sent by the server at the time of web page creation.
JSrealB currently realize sentences structured in the Subject-Verb-Object paradigm (e.g. It will rain tomorrow.), or noun phrases (e.g. Heavy snowfalls this night!). This coverage is sufficient for the sentences in our current application.
But there is still much work in order to obtain a more complete coverage. For example negation is not yet handled: in French, negation is realized with two adverbs ne and pas (e.g. il ne parle pas), while in English there is only one: not (e.g. he does not speak). Moreover, the proper placement of the adverb is quite intricate.
There are also contractions (e.g. can not sometimes contracts in cannot in English) and elision (e.g. it is become it's). These rules require information that should be inserted in the lexicon and algorithmic mechanisms to be implemented at the phrase level. Finally, some properties are not yet considered (e.g. if word is countable or uncountable), which can cause non colloquial realization (e.g. NP(D("a"),N("milk")) produce a milk instead of the milk).
We will proceed to add new rules and types of sentences. Nevertheless, the core of the program is well developed and tested and various extension mechanisms have been designed so that we can quickly achieve a better coverage.
Once we have a stable prototype, we intend to make the code of our realizer, the lexicon and tables available to the NLG community, so that it can be developed for other languages with which we are less knowledgeable.
This paper has described JSrealB, a Web text realizer that use algorithmic propagation rules to propagate properties from high level elements (i.e. sentence or phrases) to terminal elements for agreements and an engine for element transformations that use systemic rules expressed as tables for inflection. This approach makes it possible to do text realization in English and French while limiting specific developments. In principle, it would be possible to support other languages to obtain a multilingual realizer.
Examples of the use of JSrealB, and a web-based development environment are available at:
Bescherelle, Bescherelle La conjugaison pour tous, Hatier, 2012.
N. Daoust and G. Lapalme, "JSreal: A Text Realizer for Web Programming", Language Production, Cognition, and the Lexicon, Springer, 2014, pp. 363-378.
B. Delaunay and N. Laurent, Bescherelle La grammaire pour tous, Hatier, France, 2013.
B. Garner, Garner's Modern American Usage, Oxford University Press, 2009.
A. Gatt and E. Reiter, "SimpleNLG: A realisation engine for practical applications", in 12th European Workshop on Natural Language Generation, Athens, Greece, 2009, pp. 90-93.
M. Grevisse, Le bon usage, grammaire française, 11e édition, Duculot, Louvain-la-Neuve, Belgique, 1980.
P.-L. Vaudry and G. Lapalme, Adapting SimpleNLG for bilingual English - French realisation, 14th European Workshop on Natural Language Generation, Sofia, Bulgaria, 2013, pp. 183-187.