Constructing all Wikidata triples in SPARQL that have to do with a certain identifier

狂风中的少年 提交于 2019-12-11 16:16:21

问题


I am trying to return a list of triples by using a construct query in the Wikidata SPARQL query service. I want all triples of people who have a GTAA_ID identifier. In addition to this, of all people who have a GTAA_ID, I want all triples containing the person with a GTAA_ID as the subject + all combinations of predicates and objects.

Take the following example: Tom Hanks has a GTAA_ID (identifier). Tom Hanks also has a lot of other statements and identifiers in Wikidata. I want to retrieve everything that has to do with Tom Hanks (as he has a GTAA_ID).

So for example:

Tom Hanks | GTAA_ID    | 106942
Tom Hanks | residence  | Los Angeles
Tom Hanks | residence  | Oakland
Tom Hanks | occupation | film actor
Tom Hanks | occupation | film director

and so on..

The example query Wikidata give (for all triples to do with Asthma) is:

#CONSTRUCT query to get the RDF graph for a Wikidata item (e.g. asthma)
CONSTRUCT {
  wd:Q35869 ?p ?o .
  ?o ?qualifier ?f .
  ?o prov:wasDerivedFrom ?u .
  ?u ?a ?b .
}
WHERE {
  wd:Q35869 ?p ?o .
  OPTIONAL {?o ?qualifier ?f .}
  OPTIONAL {?o prov:wasDerivedFrom ?u .
  ?u ?a ?b .}
}

This returns a list of triples that has to do with the item 'Asthma'. However, what I want to do is return a list of triples where the item is a person with a GTAA_ID.

This is the code which returns all subjects with the corresponding GTAA_ID:

CONSTRUCT {
  ?s ps:1741 ?o .
  }
WHERE {
  ?s ps:P1741 ?o.
  }

and the link to the Wikidata SPARQL Query Service

Many thanks in advance!

来源:https://stackoverflow.com/questions/49259737/constructing-all-wikidata-triples-in-sparql-that-have-to-do-with-a-certain-ident

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!