SemanticMediaWiki / SemanticScribunto

Provides service functions to support the Scribunto extension
Other
23 stars 14 forks source link

Error using language filter with renamed column #85

Closed octfx closed 2 years ago

octfx commented 2 years ago

Setup and configuration

Issue

Using a language filter on a renamed column results in the language filter being appended to the renamed name.

Examples:

mw.smw.ask( { '[[-Has subobject::Example]][[Typ::+]]', '?Column|+lang=de' } )

Produces correct results, a table of tables containing only the german text for Column.

mw.smw.ask( { '[[-Has subobject::Example]][[Typ::+]]', '?Example=renamed_de|+lang=de'} )

Produces incorrect results:

  table#2 {
    "<span class=\"smw-subobject-entity\">[[...]]</span>",
    ["renamed_de|+lang=de"] = table#3 {
      "Entry (de)",
      "Entry (en)",
    },
  },

Am I calling mw.smw.ask wrong?

oetterer commented 2 years ago

@octfx thanks for the question

Have you tried, using the +lang selector as a separate parameter? Disclaimer: Unfortunately, I have never used the cool language filter feature. However, referencing my basic knowlege of the code and the ask-syntax, I would deduct since "|" in wiki code is used to separate operators in the ask query, you should/could add the +lang as separate item in the query table.

In other words, could you please try the following and return with the result:

mw.smw.ask( { '[[-Has subobject::Example]][[Typ::+]]', '?Example=renamed_de', '+lang=de' }  )
octfx commented 2 years ago

Oh interesting!
This does indeed seem to fix the problem. Many thanks 😊

Alternatively I've found that table.concat( { ... } ,'|' ) works for this aswell (but it breaks some other queries)

oetterer commented 2 years ago

splendid. :)

However I am a little flabbergasted that table.concat( { ... } ,'|' ) works. Please don't ask my why. I would not recomment using it.

Another thing: some people (me included) sometimes like to use lua tables in the same way as an associative array, especially whan adding query parameters. An example can be found in the documentation and would look like this:

query.mainlabel = 'origin'
query.limit = 10

BUT! Please dont try using this method for the language paramter. Something like the following will most probably not work and possible leed to unexpected behaviour:

query['+lang'] = 'de'

the reason is that lua does not maintain the order of elements in tables indexed by non-numerical values. and since the +lang parameter needs to be positional as it references the selector preceeding it, this will leed to unexpected (and inconsistent) behaviour.

octfx commented 2 years ago

Yeah I've learned not using table.concat( { ... } ,'|' ) the hard way.

Right now I'm building my query as follows:

    local smwData = mw.smw.ask( {
        '[[-Has subobject::' .. page .. ']][[Typ::+]]',
        '?Aus Spieldaten#-=from_gamedata',
        '[...]'
        '?Komponentenklasse=class', '+lang=' .. common.getLocaleForPage(),
        '?Komponentenklasse=class_de',
        '+lang=de',
        '?Typ=type', '+lang=' .. common.getLocaleForPage(),
        '?Typ=type_de', '+lang=de',
        '?UUID#-=uuid',
        '[...]'
        'sort=Komponentenklasse,Typ,Maximalgröße,Anzahl',
        'order=asc,asc,asc,asc',
    } )

As this works, I'm guessing that the order is preserved.

Thanks again!