bfritz
bfritz

Reputation: 2422

Wikidata SPARQL Query Qualifier Value

This should be fairly easy for anyone familiar with SPARQL (which I am not). I'm trying to return a qualifier/property value for "score_by" in this query and it's showing up blank:

SELECT ?item ?itemLabel ?IMDb_ID ?_review_score ?_score_by WHERE {
    ?item wdt:P345 "tt3315342".
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    OPTIONAL { ?item wdt:P345 ?IMDb_ID. }
    OPTIONAL { ?item wdt:P444 ?_review_score. }
    OPTIONAL { ?item ps:P447 ?_score_by. }
}

Here is a link to this query

Upvotes: 2

Views: 1132

Answers (1)

user205512
user205512

Reputation: 8888

'Score by' is a tricky thing, because it qualifies a score.

Scores are complex things: they aren't just a value, but are qualified by the scorer (Rotten Tomatoes, IMDB, etc). If your query worked the answers would be misleading, since it wouldn't be clear whether ?_review_score corresponded to ?_score_by, i.e. whether the review score corresponded to the review.

(You might ask why P444 - score - is there, since without a reviewer the information isn't complete. It's a fair question. The actual property is wdt:P444, a wikidata direct property. What that means is that the property was created as a shortcut for convenience, at the expense of losing some context. They're like database views.)

The way they actually work is by 'reifying' the complex review score as a thing, an object 'the review', then hanging the information - score, reviewer etc - off that.

For example:

select * where {
    wd:Q24053263 p:P444 ?review . # Get reviews for wolverine
    ?review ?p ?o                 # Get all info from the review
}

Link

You can see here that the score is there under p:statement/P444, and there's a 'qualifier' p:qualifier/P447, i.e. the reviewer.

Essentially properties in wikidata can appear in a number of guises, encoded in the prefix.

To answer your question:

OPTIONAL { ?item wdt:P444 ?_review_score. }
OPTIONAL { ?item ps:P447 ?_score_by. }

should be

OPTIONAL { 
    ?item p:P444 ?review . 
    ?review pq:P447 ?_score_by ; ps:P444 ?_review_score
}

Link

i.e. Treat the review as a single thing, then get the score and corresponding reviewer from that.

(If you worry that there might be scores without reviewers you could add another optional within that)

Upvotes: 5

Related Questions