1

I'm having trouble getting the Label to pull through when using a DISTINCT and SAMPLE query.

My query pulls companies and a sample of some basic attributes / properties. I would like to get the raw text label for ?state but no matter which way I try it does not seem to work.

I have tried adding "

?state rdfs:label ?stateLabel"

in SERVICE as outlined here but this seems to mess up the wikibase:label behavior .

Kind thanks for any suggestions,

BenP
  • 825
  • 1
  • 10
  • 30
  • 1
    what's wrong with doing what was suggested in the answer you referred to? either `SERVICE wikibase:label {bd:serviceParam wikibase:language "en". ?item rdfs:label ?itemLabel . ?state rdfs:label ?stateLabel . }` or just the way with `OPTIONAL`? works for me as expected – UninformedUser Jul 03 '19 at 09:39
  • 1
    and what is the reason for having braces around each triple pattern inside your last `OPTIONAL` clause? – UninformedUser Jul 03 '19 at 09:40
  • When I try the solution in the answer and your first suggestion it seems to not pass through itemLabel,web and isin etc. But yes it does work for stateLabel. https://w.wiki/5da Please could you provide the of the working query if you have one. – BenP Jul 03 '19 at 09:54
  • I think I cannot follow you. I did post a working variant. Do exactly what I posted in my previous comment: `SERVICE wikibase:label {bd:serviceParam wikibase:language "en". ?item rdfs:label ?itemLabel . ?state rdfs:label ?stateLabel . }` - and yes, if you use this you have to bind all labels explicitly in the SERVICE clause as I also did for the `?itemLabel` var. At least, I can see `?itemLabel` values. What might happen is that you got some results that don't have a label for `rdfs:label` though I doubt those exist in Wikidata – UninformedUser Jul 03 '19 at 11:34
  • Thank you, but this causes the query to timeout: https://w.wiki/5dd. – BenP Jul 03 '19 at 12:01
  • I know, but this is just because your query is slow resp. complex in general. Even without my suggestion it takes "ages" to return a result. – UninformedUser Jul 03 '19 at 12:14
  • My initial query works and returns 100K results in some 30 seconds. It seems strange / unbelievable that simply extracting the English label of an returned object would add that much overhead. I think there is a simple trick missing. – BenP Jul 03 '19 at 12:26
  • it has something to do with how labels are handled for SAMPLE / OPTIONAL queries. – BenP Jul 03 '19 at 12:45
  • There is no "trick" or something. In the end, any OPTIONAL is a left-outer join. Alternative suggestion, remove the label SERVICE and do `?item rdfs:label ?itemLabel. filter(lang(?itemLabel) = "en")` - and indeed analogous for the stateLabel inside the OPTIONAL – UninformedUser Jul 03 '19 at 18:08

0 Answers0