So lyre is designed to not include any linguistic assumptions in itself, but it still has to generate synthetic text, more so than something like Ink but not quite as much as something like Inform. The reason is that it needs built in phrasing for things like quality change messages and branch requirement tooltips, ie messages like…
Wounds is increasing..
This is unlocked by having more than 100 doubloons.
And so on. My solution to this is that lyre’s API can take a language provider, a module with a specific interface that encapsulates all of those text generation tasks. This is useful for localization but also for games to change how they want to phrase things, so the specific tone of these kinds of messages isn’t enforced either, and it allows more flexibility than just exposing loc strings (which wouldn’t really work anyway for localizing a text gen system this complex).
Of course, lyre also ships with an English language provider as a default and as a reference implementation for making your own. Which means that I run into the difficulty of inflecting English nouns and articles, for generating phrases like “you now have a walnut” or “this requires seven wine corks” and so on.
This really is what I’m asking here: is there any relevant prior art on this that I should know about that’s more recent than the approaches used in the Inform 7 standard library?
A/an article inflection is relatively simple, and I have cribbed the grammar that Inform uses for this problem (but I just wrote a simple tree search algorithm to use them, since every grammar rule is just “either this produces the given article or it doesn’t “.
English pluralization, however, is a nightmare and I somewhat question to what extent it’s worth including sophisticated pluralization in the lyre English provider. The main reason is that the thing getting pluralized is typically lyre quality names, which are very likely to take forms that require semantic understanding to pluralize; phrases like “tin of preserved fish” or “evidence against the ambassador”. The current approach is to look for a user defined plural form and, failing that, try a small naive pluralization algorithm. But maybe there’s a reasonable way to address complex noun phrases?
There are definitely computational linguists who work on this. That is outside my area of expertise, but I’m aware of a little bit of it. Damien Conway has done some work on this and published papers; here is what purports to be a Java implementation of his algorithm. (I haven’t examined it or verified it myself.)
ClarityNLP does some natural language processing, including pluralization and verb forms, for English; it’s targeted at medical text, though. In general, it seems that the larger languages with robust library ecosystems usually have one or more projects trying to provide basic language-inflection type services for English as usable modules. C# has inflector.net; Python has inflect, pyinflect, and inflex; Common Lisp has cl-inflector; etc.
So there definitely is prior art and the general consensus seems to be that this is one of the places where it’s best to leverage it instead of trying to reinvent the wheel.
I can’t find that Conway has published anything on this subject since the 1998 paper that everybody knows about. And that’s mostly for single words?
I think Bruno’s on the right track: a naive pluralization algorithm (e.g. go down through the clauses of Conway’s algorithm until you get to the point where you go “this is ridiculous, I should just use a table for the rest”) and then an easily editable table of custom plurals is probably the way to go these days (unless you want to just pull in a library; do they handle complex noun phrases well?).
I have sometimes included a dictionary of prepositions so I could chop off prepositional phrases and pluralize just the noun: that’s not too hard and works fairly well IIRC. (“evidences against the ambassador”? hmm). Maybe adjectives too. But it’s all just a big tradeoff: how much work do you want to put into the code/dictionary, vs. how much do authors mind having to go “oh yeah, that pluralizes to ‘tins of preserved fish’” sometimes? And you can always go back and add more cases later: the code tends to be very straightforward.
Might also be worth talking to the Caves of Qud devs, if you’re friends with them? Or maybe even if you’re not: they sounded like they wouldn’t mind chatting about it when they gave a talk on localizing Qud (to Turkish!?) at Roguelike Celebration last weekend (timestamp in the YouTube livestream – individual videos aren’t up yet). They might have a bunch of practical experience with pluralizing complex noun phrases…
I’m not a big QBN guy, but my impression is that qualities are relatively few but significant, compared to other things in the story, so it’s fine to ask the user to do the work of deciding how it should be displayed. (And it might be preferable to have fine-grained control.)
A compromise would be adding syntax so you could declare your quality as doubloon(s) or tin(s) of preserved fish or champ(s) élysee(s) or octop(us|i) or whatever and let the computer figure it out from there…
In other words, a phrasebook entry accepts a parameter (the word that goes in the blank), and returns a value based on that parameter. In the case of Chinese, this operation is simple; in the case of Russian, it’s quite complex.
This talk of parameters and complexity is just another way to say that an entry in a phrasebook is what we programmers call a “function.” Just so you don’t miss it, this is the crux of the article: A phrase is a function; a phrasebook is a bunch of functions.
The reason that gettext runs into walls is that it tries to use strings to do something that requires a function, which is futile.
NetHack has a system for adding articles and making nouns plural (in English). It works for built-in game objects, of course: “1 zorkmid” / “10 zorkmids”; “a food ration” / “2 food rations”; “a scroll of blank paper” / “2 scrolls of blank paper”; “an incubus” / “2 incubi”. But it also copes, to some degree, with the user-customizable “fruit” setting, which is an arbitrary string: “a pomelo” / “2 pomelos”; “an apple pie” / “2 apple pies”; “a plate of shrimp” / “2 plates of shrimp”. See the functions makeplural, makesingular, an, the.