0

I use the following query:

SELECT DISTINCT  (SAMPLE(?image)as ?image) ?item ?itemLabel ?itemDescription (SAMPLE(?DR) AS ?DRSample) (SAMPLE(?article) AS ?articleSample)
WHERE{ ?article  schema:about       ?item ; schema:inLanguage  "en" ; schema:isPartOf    <https://en.wikipedia.org/>
    FILTER ( ?item = <//www.wikidata.org/entity/Q303> )
    OPTIONAL { ?item  wdt:P569  ?DR }
    OPTIONAL { ?item  wdt:P570  ?RIP }
    OPTIONAL { ?item  wdt:P18  ?image }
    SERVICE wikibase:label { bd:serviceParam wikibase:language  "en"}}
GROUP BY ?item ?itemLabel ?itemDescription

enter image description here

If I copy image url from result, I get:
https://commons.wikimedia.org/wiki/File:Elvis%20Presley%20promoting%20Jailhouse%20Rock.jpg

but if I look at query response (in Dev Tools), I get:
http://commons.wikimedia.org/wiki/Special:FilePath/Elvis%20Presley%20promoting%20Jailhouse%20Rock.jpg

Why different urls?

Why second http, not https?

Running query in my application I get second result too, but I want first.

And why I get second image from Elvis Presley profile, not first?

Query link

logi-kal
  • 7,107
  • 6
  • 31
  • 43
Alexan
  • 8,165
  • 14
  • 74
  • 101
  • what do you mean with "why"? you're using `sample` - it returns a **random** item from the group, in your case image. – UninformedUser Feb 06 '20 at 04:39
  • @UninformedUser, if I remove sample, I get error: Query is malformed: Bad aggregate. How I can select first image? – Alexan Feb 06 '20 at 04:45
  • sure, you need an aggregate function if you just want one image per item. That said, you should read about ranking of statements: https://www.wikidata.org/wiki/Help:Ranking - if you're talking about the first in your example, this would be the normal rank statement. The prefered rank statement would the second image. You can see the ranking from the small icons close to the top left corner of each image. Hover via mouse and it will show the tooltip. – UninformedUser Feb 06 '20 at 07:20
  • That said, if you really want the normal rank picture, do `OPTIONAL { ?item p:P18 [ps:P18 ?image; wikibase:rank wikibase:NormalRank] }` - but, this is just for this single item now - what happens if there are multiple images fpr other entities. Why not using the preferred rank, i.e. `OPTIONAL { ?item p:P18 [ps:P18 ?image; wikibase:rank wikibase:PreferredRank] }` - even then, you just get a random one unless you do `(iri(min(str(?image))) as ?image)` to have some kind of determinism – UninformedUser Feb 06 '20 at 07:23
  • `SELECT ?item ?itemLabel (iri(min(str(?image))) as ?image) ?itemDescription (SAMPLE(?DR) AS ?DRSample) (SAMPLE(?article) AS ?articleSample) WHERE{ VALUES ?item { wd:Q303 } ?article schema:about ?item ; schema:inLanguage "en" ; schema:isPartOf OPTIONAL { ?item wdt:P569 ?DR } OPTIONAL { ?item wdt:P570 ?RIP } OPTIONAL { ?item p:P18 [ps:P18 ?image; wikibase:rank wikibase:PreferredRank] } SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}} GROUP BY ?item ?itemLabel ?itemDescription` – UninformedUser Feb 06 '20 at 07:25
  • @UninformedUser, I get the same image from this query – Alexan Feb 06 '20 at 18:53

0 Answers0