Jump to content

Wikifunctions:Type proposals/Configuration of ZIDs for given languages

From Wikifunctions

Summary

This Type is to provide an alternative (usually more performant) to Configuration of functions for given languages (Z14294).

Uses

  • Configs per language are extremely important for AW NLG. We need to optimise the data type for performance.
  • We now have an opportunity to do this better, because the Wikifunctions object reference (Z96) type was recently made available. Handling Z96 references is much more efficient than handling entire functions key-value pairs.
  • We will know whether a default function is appropriate for the languages which use it.

Structure

My first suggestion (feel free to suggest alternatives which may supersede it) is:

ZZZK1: (configured languages) a Typed list (Z881) (Typed pair (Z882) (Typed list (Z881)(Natural language (Z60)), Wikifunctions object reference (Z96)))
ZZZK2: (default) a single Typed pair (Z882) (Typed list (Z881)(Natural language (Z60)), Wikifunctions object reference (Z96))

(feel free to improve the notation)

Note that unlike Configuration of functions for given languages (Z14294), I'm proposing that the default also has an associated list of languages. These are the languages for which we are asserting that the default is the desired function choice. This default will be returned for otherwise unlisted languages either way, but this will help us audit (e.g. in the Abstract data tool) whether a language is properly represented in a configuration, or whether it still needs a local variant to be written.

As for Configuration of functions for given languages (Z14294), the first occurrence of a language in a key list is considered to supersede any later occurrence. These are ordered lists.

The structure of the first key is broadly similar (but matches languages rather than QIDs) to that of [qids of classes] and infobox function refs (Z42277) which is used in our most efficient implementations of choose infobox function for item in class (Z40002).

Example values

…

{
  "type": "…",
  "value": "…"
}
{
  "Z1K1": "Zxyz",
  "ZxyzK1": "…"
}

Identity

Every element

Converting to code

Python

Not essential, just a list.

JavaScript

Not essential, just a list.

Display function

none

Read function

none

Alternatives

  • Should the first element in the typed pairs be a list of language Z96s instead of language Z60s? That would be messier and slower to select as an editor, but might make for an even more streamlined data type. (Or are we already passing around and comparing Z60s as references, in which case it wouldn't make much of a speed difference?)
  • Do we need to find a way to allow for functions without permanent ZIDs? Or perhaps in those situations they should use the old config type.
  • Do we need a more general configuration type which does configuration by things other than language? Should all configurations be rolled up into the same data type, or separate?

Comments

For general comments, please reply to the proposer.

Neutral Neutral I suspect that the more performant approach is simply a string-keyed map. There is more work for maintaining such a mapping, since each pairing must be stored separately. The overall size of the mapping may also be larger, but that depends on how the list and pairs are represented. I believe that the resources required to resolve generic types would be a material proportion of the total required to perform any lookup.
Making the “pair” simply a two-string object (tuple) and the “map” simply a list of such “pairs” would seem to be optimal for access, and it would convert naturally to a JavaScript Map or Python dict. Maintaining the mapping would be painful, but this is where it is useful to keep the concerns separated. If we have a solution where the mapping is updated/replaced each time its specification is changed, we can optimize the specification structure for usability without sacrificing the improved performance of accessing a straightforward mapping. Conceptually, this is what happens for the searchable text within objects, where editing objects also updates database tables. But I’m not suggesting the mapping here should use the same technical implementation. GrounderUK (talk) 10:50, 19 September 2026 (UTC)reply
Thanks for your consideration. I did consider a map, but thought that those same negatives you identified were disqualifying. Can you explain this further: "If we have a solution where the mapping is updated/replaced each time its specification is changed, we can optimize the specification structure for usability without sacrificing the improved performance of accessing a straightforward mapping. " --99of9 (talk) 11:05, 19 September 2026 (UTC)reply
Oh, maybe I now understand what you mean. So we could make a type something like this where we *specify* the structure, then we have a function which translates it to a more efficient map. Then we could (manually??) copy the output of that function into a map object, which is the object actually used when we need to efficiently pick functions for languages? --99of9 (talk) 02:01, 11 October 2026 (UTC)reply
Sorry I failed to reply earlier… I wasn’t thinking of a function, specifically, because that would tend to just move the processing around with not much prospect of net gains, unless the intermediate call result is cached. As far as I know, it’s not currently possible to copy and persist the result of a function call as a Wikifunctions object, although it should be feasible using the APIs. Ensuring that both objects are subsequently kept in step would be a concern.
I think it would be sensible to consider solution options here alongside phab:T440039. Although Option F there is pretty much dismissed, I think the reasoning is flawed, because a “specification” object would have its own edit-history and the database table would/should always be a faithful representation of the underlying specification object. That’s not to suggest that Option F is the right (or wrong) sort of solution in either context, but it relates most directly to my previous comment, where updates to a persistent object’s label or aliases are reflected in the tables that support the predictive completion search. As I said before, I’m not suggesting that particular implementation; the secondary representation might also be a Wikifunctions object, as with persisting the result via the APIs. GrounderUK (talk) 08:40, 11 October 2026 (UTC)reply
Thanks for the phab link. I agree it is relevant. Whatever we build should seek to solve those issues too. --99of9 (talk) 09:13, 11 October 2026 (UTC)reply
  • Support Support YoshiRulz (talk) 22:13, 10 October 2026 (UTC)reply
    • I'm not sure whether it's necessary to include the languages for the default branch in this structure. NLG functions should be returning a Monolingual text (Z11) (or now Monolingual html (Z91)), which can then be checked against the requested language with language is acceptable substitute? (Z29750).
      Should the first element in the typed pairs be a list of language Z96s instead of language [Z9]s? They're about the same size in JSON, so it wouldn't make much difference either way. YoshiRulz (talk) 22:13, 10 October 2026 (UTC)reply
      My guess is that since it doesn't actually call any functions DSantamaria-WMF's tool would find it easier to have default-applicable languages explicitly listed. An example might be something like sentence separator (Z35672) with config config of sentence separators (string) (Z35676). The default is ideal for English (and many other languages), but there's no way to tell whether another arbitrary (Asian?) language has been missed from languages without spaces between sentences (Z33984). So it would be good to explicitly list the languages that do work with the default. --99of9 (talk) 01:57, 11 October 2026 (UTC)reply
      That's two related but separate concerns: 1) we want external tools like toolforge:abstract-data to be able to know the supported languages statically, just by fetching the Configuration object, and 2) we want to indicate that the default function is correct for some languages. The latter could be done by adding an explicit branch which has the same function as the default. But I think it wouldn't be sufficient for the former, since some of the default functions are like Z36197: they conditionally call another function if it's configured, else they return some incomprehensible sigils. YoshiRulz (talk) 05:26, 11 October 2026 (UTC)reply
Note Note: Please note phab:T440032 in general and phab:T440039 in particular. GrounderUK (talk) 08:45, 11 October 2026 (UTC)reply
As requested, I've filed an (edited) copy of the write-up for T440032 in Wikifunctions:Status updates/2026-11-04 at Wikifunctions:Type proposals/NLG Function. Discussion welcome! Jdforrester (WMF) (talk) 14:48, 5 November 2026 (UTC)reply