简体   繁体   中英

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

'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 , ie 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 , ie 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

ie 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM