我正在开发一个Java应用程序,它使用ARQ通过TDB上的Fuseki端点执行SPARQL查询.
该应用程序需要一个查询,返回每个人和出生在同一个地方的其他人的出生地.
首先,我写了这个SPARQL查询,它返回person_ids和每个人的出生地.
prefix fb: <http://rdf.freebase.com/ns/>
prefix fn: <http://www.w3.org/2005/xpath-functions#>
select ?person_id ?place_of_birth
where {
?person_id fb:type.object.type fb:people.person .
?person_id fb:people.person.place_of_birth ?place_of_birth_id .
?place_of_birth_id fb:type.object.name ?place_of_birth .
FILTER (langMatches(lang(?place_of_birth),"en"))
}
LIMIT 10
----------------------------------
| person_id | place_of_birth |
==================================
| fb:m.01vtj38 | "El Centro"@en |
| fb:m.01vsy7t | "Brixton"@en |
| fb:m.09prqv | "Pittsburgh"@en |
----------------------------------
Run Code Online (Sandbox Code Playgroud)
之后,我添加了一个子查询(https://jena.apache.org/documentation/query/sub-select.html),添加了出生在那里的其他人,但我得到的不止一个人相关,我只需要一个.
prefix fb: <http://rdf.freebase.com/ns/>
prefix fn: <http://www.w3.org/2005/xpath-functions#>
select ?person_id ?place_of_birth ?other_person_id
where {
?person_id fb:type.object.type fb:people.person .
?person_id fb:people.person.place_of_birth ?place_of_birth_id .
?place_of_birth_id fb:type.object.name …Run Code Online (Sandbox Code Playgroud)