Topic on User talk:TomT0m

Jump to navigation Jump to search
Xaris333 (talkcontribs)

Hello. I am using modules for fetch from Wikidata some informations to Wikipedia templates. I like your solution in Project chat but I need help to change the Module.

For example, I am using w:el:Module:Τρέχονπρωτάθλημα to find the current season. For example, in Cypriot First Division (Q155965), the module find the current season by checking has as part (P527). The current season is the item with the largest edition number (P393).

Can you change this by the way you said it the Project chat? May the current season is the one with not have followed by (P156) or has no value for followed by (P156). Pls tell me if that is possible because that way if much easier to fetch that kind of data from wikidata.

TomT0m (talkcontribs)

Hi, just implemented Module:Event_sequence_number. It implements the same idea that was used in the query. The potential problem is that it requires as many item loading that there is previous events so it's not usable in too long sequences as the number of item loads is expensive - I'm thinking of other ideas.

For the problem of finding the latest season, I think it's enough to use ranks, exactly as we use ranks for the most recent datas for population.

Xaris333 (talkcontribs)

How to use ranks?

TomT0m (talkcontribs)

Pardon me, this is not possible in that case using "instance of" as it has no inverse properties. But your use of "edition of" suggest another thing : can't you use the "edition of" relationship ? To know how to use ranks please see Help:Rank. Only the best rank statements are by default used in queries and lua.

But I also implemented something with your suggestion to follow the "followed by" property in the (renamed) Module:Event_sequence.

Xaris333 (talkcontribs)
TomT0m (talkcontribs)

As said in the previous comment, I'd prefer another property. "Has part" in this case is definitely not used in the usual sense of Help:BMP. Maybe edition(s) (P747) would fit better.

Another remark from your item, the victories as qualifiers are redundant. There is already the list of victories in the club item isn't it ? You definitely can do this with a query : The following query uses these:

select ?team ?teamLabel (count(?championship) as ?num_vict) (group_concat(coalesce(year(?date),""); separator=", ") as ?years) where {
  {
    select ?championship ?team ?date {
    	?championship wdt:P31 wd:Q155965 ;
       	              wdt:P1346 ?team .
        ?championship wdt:P582 ?date .
    } order by asc(?date)
  }
  
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en, el" .
  }
} group by ?team ?teamLabel order by desc(?num_vict)

Try it! and that without having to repeat the data everywhere.

Xaris333 (talkcontribs)

Οκ, οκ. If I find easy way to fetch data from wikidata to Wikipedia templates for: 1) latest season 2) first season 3) previous season 4) last champions

I wouldn't need to repeat that data. I have modules for all these but I need modules that are using different properties. Can you help?

W:el:Module:Τρέχονπρωτάθλημα current season

W:el:Module:Προηγούμενοςπρωταθλητής last champions

W:el:Module:Προηγούμενοπρωτάθλημα previous season

W:el:Module:Πρώτηπερίοδος first season

They all are in English language. May I should ask to project chat for ideas.

TomT0m (talkcontribs)

I don't understand what you mean by "I need modules that are using different properties" - followed/preceded by ? . Do you understand a little the stuffs I wrote in Module:Event_sequence ?

It seems you don't use any other module in yours. Usually we use existing modules to help us writing codes like Module:Wikidata who does a few thing to avoid writing over and over again the same code patterns. In "Event sequence", I used Module:PropertyPath which is powerful and can easily be used for your problems here, but it needs you to copy a few modules itself into elwiki to be usable there - For example the template {{Show path items}} uses PropertyPath it shows how easily it becomes to get the previous season of say 1949–50 Cypriot First Division (Q629654)   with {{Show Path Items|Q629654|preceded by}} :

(here I write the property label in english but in elwiki you would be able to use the greek label if you want to) But you'll have to copy a few modules from here to elwiki to get there :

I'm writing a script to automatically import the modules to elwiki, I'll get you in touch when that's done.

You also use the query I wrote with {{Wikidata list}} in your wikipedia to get an automatically updated table.

Xaris333 (talkcontribs)

"different properties" from those I am using now. I preferred followed/preceded by.

I have copied all modules. But I have stopped when I get a message

Script error: The function "main" does not exist.

Don't know what to do about that.

TomT0m (talkcontribs)

Can you point me to the place you get this error ?

Xaris333 (talkcontribs)
TomT0m (talkcontribs)

OK, I get it. There is several problems indeed. You need to get familiar with programming with modules. There is indeed no "main" function in that module, so the error message is correct.

To call a module within a template, you must provide a function with a single parameter usually called "frame". It's not necessarily called "main" but the name of function must be the the same as used in the #invoke call. You can access the other parameters {{#invoke:youmodule|main|arg1|arg2|plop=bidou}} - here arg1, arg2 and plop thanks through "frame.args". frame.args[1] will have the value "arg1", 2 "arg2" and frame.args["plop"] will have the values "bidou".

The function I wrote don't work like that, so we need to write new one that call my functions.

Such a function would look like

function p.main(frame)
    local arg1 = frame.args[1]
    local arg2 = frame.args[2]
    local plop = frame.args["plop"]
   
    -- The useful code here
end

We kind write several of such functions in a module, for example we could write a second function "show_last_event"

function p.show_last_event(frame)
    local start_item = frame.args[1]
    local event_type_item = frame.args[2]
   
    local item = p.last_in_sequence(start_item, event_type_item)

    -- write here the code to generate a link from an item

    return link
end

Now the parameters of my functions needs a start_item and an event type. The start_item could be the Qid of the current season, as time won't turn back, and the event type is the item of the page, probably, as it seem to be the item of the competition class. So we can replace the line local event_type_item = frame.args[2] with local event_type_item = frame.args[2] or mw.wikibase.getEntityObject() to set this value by default to the item of the current page.

Xaris333 (talkcontribs)

Thanks for your time and help. My knowledge about programming are not good. I guess we are talking about different things. If you find an easy way to find the first season, the current season, the previous season and the previous winner please tell me. Thanks for all.

TomT0m (talkcontribs)

Oh, I see you replaced with another module. I was working on tighting everything together, this would have definitely worked, as long as the infobox has a parameter for a sample season in the sequence, but it's as you like. If you want my opinion with the complexity of the code you write you definitely could be able to make the rest work.

Xaris333 (talkcontribs)

Please continue what you were doing. I thought you was done, but the templates continue to show the message Script error: The function "main" does not exist so I restore the module. I am not the written of the Module. A Wikipedia friend helps me. Do what you think is correct and I will see the final result.

Reply to "Lua"