wikidata示例:
# 查询父亲或者母亲是作家的中国作家
SELECT ?child ?childLabel ?fatherLabel ?motherLabel WHERE {
?child wdt:P31 wd:Q5.
?child wdt:P27 wd:Q148.
?child wdt:P106 wd:Q36180.
{?child wdt:P22 ?father.
?father wdt:P106 wd:Q36180.}
UNION
{?child wdt:P25 ?mother.
?mother wdt:P106 wd:Q36180.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "zh". }
}
wikidata的SPARQL查询界面及结果:
yago示例:
### 父母也是作家的中国作家
PREFIX schema: <http://schema.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX yago: <http://yago-knowledge.org/resource/>
SELECT ?person ?label ?parent_label WHERE {
?person rdf:type yago:Human.
?person schema:nationality yago:China.
?person schema:hasOccupation yago:Writer.
?person schema:parent ?parent.
?parent schema:hasOccupation yago:Writer.
?parent rdfs:label ?parent_label.
?person rdfs:label ?label.
FILTER (langMatches(lang(?label),"ZH") && langMatches(lang(?parent_label),"ZH")).
}
dbpedia示例:
查询中国作家
注意:如果不清楚property、value、relation、namespace等等这些,可以直接在浏览器(Chrome)搜索一个实体,
如:
wikidata 莫言
yago 莫言
dbpedia 莫言