Module talk:WikidataIB/Archive 7: Difference between revisions

Content deleted Content added
m Archiving 1 discussion(s) from Module talk:WikidataIB) (bot
m Archiving 1 discussion(s) from Module talk:WikidataIB) (bot
Line 425:
: {{re|MSGJ}} I added the class "autoconfirmed-show" to the pen icon in the sandbox and tested it by checking against an unconfirmed alt account and when not logged in. It looked fine, so I've made the edit live. It works for [[Tower Bridge]], so I guess we just have to wait to see if there are objections from elsewhere. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 17:46, 15 December 2020 (UTC)
::Thanks. It's seems a reasonable precaution, and readers don't want to see all those icons anyway. &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 19:23, 15 December 2020 (UTC)
 
== Returning a qualifier only for values where a second qualifier matches a given qval? ==
 
Currently if a statement has multiple values, getQualifierValue will return the requested qualifier for each of those values. Could a variant be made that only returns a the qualifier for one the values where a second qualifier matches a given qval. For example,
{{Q|Q38382414}} is an {{Q|Q1607826 }} for multiple journals. I would like to retrieve only the {{Property|P580}} for the journal {{Q|Q24657325}}.
 
{{collapse|text=
<code><nowiki>{{#invoke:WikidataIB |getQualifierValue |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |fetchwikidata=ALL |onlysourced=no |noicon=true}}</nowiki></code>
*'''returns:''' {{#invoke:WikidataIB |getQualifierValue |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |fetchwikidata=ALL |onlysourced=no |noicon=true}}
 
 
Ideally, would like:<br>
<code><nowiki>{{#invoke:WikidataIB |getQualifierValue |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 </nowiki>'''{{!}}qualtocheck=P642 {{!}}qualtocheckval=Q24657325'''<nowiki> |fetchwikidata=ALL |onlysourced=no |noicon=true}}</nowiki></code>
*'''returns:''' 24 July 2016
|example syntax}}
Would that be possible to implement? [[User:Evolution and evolvability|T.Shafee(Evo<small>&#38;</small>Evo)]]<sup>[[User talk:Evolution and evolvability|talk]]</sup> 07:24, 3 December 2020 (UTC)
:
: {{re|Evolution and evolvability}} it would be possible, I think, but I'll need an uninterrupted session to work up the code. I try to find a slot in the next week or so. --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:46, 8 December 2020 (UTC)
::{{re|RexxS}} Thank you so much in advance! Appreciated as always. [[User:Evolution and evolvability|T.Shafee(Evo<small>&#38;</small>Evo)]]<sup>[[User talk:Evolution and evolvability|talk]]</sup> 22:56, 8 December 2020 (UTC)
{{od}}
{{re|Evolution and evolvability}} I'm loathe to implement two more parameters, so I've implemented a filter parameter that looks like this: <code>|filter = P642==Q22674854</code>. It seems to work, but I'd prefer to see if it fits your needs and doesn't have bugs before I incorporate it into the main module.
 
In {{q|Q38382414}}: property {{q|P39}} equal to {{q|Q1607826}} has multiple {{q|P580}} qualifiers. A filter can pick one of them.
 
Examples 2 and 3 filter on: (2) {{q|Q1607826}} {{q|P642}} {{q|Q22674854}}, and (3) {{q|Q1607826}} {{q|P642}} {{q|Q939416}}, returning the {{q|P580}} where the filter matches.
 
{| class="wikitable"
|+ Demo of filter
|-
! scope="col" | Code
! scope="col" | Result
|-
| <code><nowiki>{{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580}}</nowiki></code> || {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580}}
|-
| <code><nowiki>{{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q22674854}}}</nowiki></code> || {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q22674854}}
|-
| {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q939416}}}</nowiki></code> || {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642==Q939416}}
|}
 
If you get a chance, please test it out. I know you can provoke errors if you give nonsensical values for the filter, and I've tried to catch them, but I can't guarantee I've found them all. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 20:42, 15 December 2020 (UTC)
::Excellent! I can completely understand the want to avoid additional parameters where possible. For the uses I've tried, it out for it seems to work well. The only case it couldn't handle have been:
::* using a filter to try to find missing fields via their empty string return (could be very useful for omitting things with end dates to include only current items):
:::<code><nowiki>{{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P582==}}</nowiki></code>
::*using a date as the filter and a 'greater than' <code><=</code> or 'less than' <code>>=</code> comparator (useful for uncluding things that were the start and end dates are outside a given period:
:::<code><nowiki> {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P642 |filter=P580>=2016-01-01}}</nowiki></code>
::*Could be useful to have an antifilter implemented <code>!=</code>
:::<code><nowiki> {{#invoke:WikidataIB/sandbox |getQualifierValue |fwd=ALL |osd=n |qid=Q38382414 |P39 |pval=Q1607826 |qual=P580 |filter=P642!=Q22674854}}</nowiki></code>
::However, already very useful for the sort of filtering I'm lookng to start with. [[User:Evolution and evolvability|T.Shafee(Evo<small>&#38;</small>Evo)]]<sup>[[User talk:Evolution and evolvability|talk]]</sup> 06:03, 16 December 2020 (UTC)
:::
::: {{re|Evolution and evolvability}} There comes a point where I end up writing a query language instead of a module to return data for use in infoboxes. The first use you suggest really is best solved by a query using the WDQS. We don't put missing fields in infoboxes.
::: I considered the possibility of using operators other than equality and I deliberately coded the filter parsing to allow easy expansion in the future. However, dates are a much less structured datatype because we may have to accept inputs of dmy, mdy, ymd, and others, and Wikidata stores a timestamp, so there's a fair bit of processing to get a comparison. I have most of the code already elsewhere in the module, so it's not too bad, but it won't be high on my to-do list. Cheers --[[User:RexxS|RexxS]] ([[User talk:RexxS|talk]]) 22:25, 16 December 2020 (UTC)