I have this SPARQL query to select all resources beloning to the Wikipedia category National_parks_in_California
:
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT * WHERE {
?park dcterms:subject dbc:National_parks_in_California .
}
which returns
park
http://dbpedia.org/resource/Death_Valley_National_Park
http://dbpedia.org/resource/Yosemite_National_Park
http://dbpedia.org/resource/Channel_Islands_National_Park
http://dbpedia.org/resource/Kings_Canyon_National_Park
http://dbpedia.org/resource/Lassen_Volcanic_National_Park
http://dbpedia.org/resource/Redwood_National_and_State_Parks
http://dbpedia.org/resource/Joshua_Tree_National_Park
http://dbpedia.org/resource/Pinnacles_National_Park
http://dbpedia.org/resource/Sequoia_National_Park
Is it possible to build a query to return along with the dbpedia resource page also the foaf:homepage
of each resource?
I wrote
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT * WHERE {
?park dcterms:subject dbc:National_parks_in_California .
?webpage foaf:homepage ?park .
}
but it returns zero results.
If you open on of the results, you will see that each resource MIGHT have a foaf:homepage
. Therefore, the direction of your query is wrong
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT * WHERE {
?park dcterms:subject dbc:National_parks_in_California .
optional{
?park foaf:homepage ?homepage.
}
}
The reason I have used optional
is that some resources do not have foaf:homepage
.