1

The first part of my question is, is there a SPARQL equivalent of the "What links here" link? E.g. as described at https://opendata.stackexchange.com/a/5271/20321

I tried:

WHERE {  ?item wdt:?property wd:Q1174 . }

which gave a syntax error, and:

WHERE {  ?item wdt:* wd:Q1174 . }

which doesn't give an error, but only returns one row: the item in the query!

The second part of my question is how can I get a list of all unique properties that are used to link to the item of interest? This is the bit I'm interested in, as I suspect there will typically just be 1 or 2 properties used for 99% of the links, and that any others are probably mistakes, that are good candidates for fixing to improve data quality.

1 Answer 1

2

The first part of my question is, is there a SPARQL equivalent of the "What links here" link?

The second part of my question is how can I get a list of all unique properties that are used to link?

Assuming you are interested in truthy statements only:

select distinct ?subject ?subjectLabel {
  values (?item) {(wd:Q42)}
  ?subject ?predicate ?item .
  ?property wikibase:directClaim ?predicate
  service wikibase:label { bd:serviceParam wikibase:language "en" }
}

(try it)

and

select distinct ?property ?propertyLabel {
  values (?item) {(wd:Q42)}
  ?subject ?predicate ?item .
  ?property wikibase:directClaim ?predicate
  service wikibase:label { bd:serviceParam wikibase:language "en" }
}

(try it)

respectively.

Update

If you want to use the label service with items that have large number of incoming links, you should place it outside of the inner query.

select ?property ?propertyLabel ?count {
  {
  select ?property (count(*) as ?count) {
    values (?item) {(wd:Q30)}
    ?subject ?predicate ?item .
    ?property wikibase:directClaim ?predicate
  } group by ?property  having (?count > 0) 
  }
  service  wikibase:label { bd:serviceParam wikibase:language "en" }
} order by desc(?count) 

Try it!

4
  • 1
    Thanks! A variation on your 2nd query, I changed first line to select ?property ?propertyLabel (COUNT(?propertyLabel) as ?cnt) then added GROUP BY ?property ?propertyLabel, and optionally ORDER BY DESC(?cnt), to the end. Commented Dec 3, 2018 at 21:05
  • 1
    If I drop the wikibase:directClaim I get over double the entries: 20 --> 43. Every wdt:NN has a ps:NN equivalent, each with identical count. But also "schema:about" (110), and then pq:P50 and pq:P5869 (1 each). I can't work out if the "pq" are typos for "ps" (and if fixed, then another "wdt" would magically appear?) Commented Dec 3, 2018 at 21:10
  • @DarrenCook, about ps: and pq:, see Data model. My query lists only wdt: properties and subjects connected via them. Commented Dec 3, 2018 at 21:13
  • pinging you again for this meta thread opendata.meta.stackexchange.com/q/413/1511
    – philshem
    Commented Dec 13, 2018 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.