I just started writing SPARQL queries. I created an ontology of countries, cities, counties and towns. I wanted to run a query that returns the name of a town and the town's population, but instead my query returns blank entries in the tables for town and population.
This is the query I wrote:
PREFIX countries-and-cities: <http://www.semanticweb.org/xxxxxxx/ontologies/2022/11/countries-and-cities#>
SELECT ?Town ?Population
WHERE { ?Town countries-and-cities:Population ?Population. }
Related
Here is my query:
prefix dbc: <http://dbpedia.org/resource/Category:>
SELECT COUNT (?x) AS ?numberIn_Horror, COUNT (?y) AS ?numberIn_Action
WHERE { ?x dct:subject dbc:Horror_film .
?y dct:subject dbc:Action_film .}
I get a numeric output for this query however, it does not match the actual value for the number of movies present in these genres.
Is there a way to change the query so it returns the number of movies accurately.
Additionally, I am unsure as to what value it is currently returning.
Added Picture
Game look-up
I am trying to retrieve the titles of movies on http://id.dbpedia.org/page/Daftar_film_Indonesia but there is nothing on the list
I tried this queries, it runs but with no results.
SELECT DISTINCT * WHERE{
?p dbpedia-owl:Movies <http://id.dbpedia.org/resource/Daftar_film_Indonesia>.
}
what queries i can use to retrive all title of the movies ?
I've a dbpedia resource and I'd like to obtain all the dbpedia categories associated. For this purpose I wrote this SPARQL query
SELECT ?p ?o WHERE
{
<http://dbpedia.org/resource/Rihanna> ?p ?o .
}
focusing only on http://purl.org/dc/terms/subject property.
The results I've is a set of categories. Which could be a good manner to select the most relevant category which describes Rihanna singer?
This query orders Rihanna's categories by the total number of members in each category:
SELECT ?category (COUNT(?member) as ?memberCount) WHERE {
?member dct:subject ?category.
{ SELECT ?category WHERE { dbr:Rihanna dct:subject ?category. } }
}
ORDER BY ?memberCount
The assumption here is that, the fewer members a category has, the higher the relevance of that category for any particular member.
The results for this query list the following categories as most relevant to Rihanna:
Barbadian fashion designers
Barbadian people of Irish descent
Barbadian Christians
Barbadian people of Guyanese descent
Barbadian female singers
I'd like to query DBPedia with SPARQL to select car manufacturers (of France to start), but I have no idea how to do this.
I started with this query:
select distinct * where {
?carManufacturer dbpedia-owl:product <http://dbpedia.org/page/Automobile> .
?carManufacturer dbpprop:locationCountry "France"#en
} LIMIT 100
However, it returns an empty result set. What am I doing wrong?
You’re using the wrong URI to identify DBPedia resources. On DBPedia, http://dbpedia.org/resource/Automobile refers to the noun ‘automobile’, while http://dbpedia.org/page/Automobile refers to a page describing the noun ‘automobile’. Thus,
SELECT DISTINCT * WHERE {
?carManufacturer dbpedia-owl:product <http://dbpedia.org/resource/Automobile>.
?carManufacturer dbpprop:locationCountry "France"#en.
} LIMIT 100
works just fine.
However, if you want to be a bit more idiomatic, you can use a bit of syntactic sugar to eliminate the subject repetition in your query. DBPedia also loads http://dbpedia.org/resource/ as prefix dbpedia, so you can actually eliminate all URIs from your query entirely:
SELECT DISTINCT * WHERE {
?carManufacturer dbpedia-owl:product dbpedia:Automobile;
dbpprop:locationCountry "France"#en.
} LIMIT 100
My question is a followup with my first question about SPARQL here.
My SPARQL query results for Mountain objects are here.
From those results I picked a certain object resource.
Now I want to get values of "is dbpedia-owl:highestPlace of" records for this chosen Mountain object.
That is, names of mountain ranges for which this mountain is highest place of.
This is, as I figure, complex. Not only because I do not know the required syntax, but also I get two objects here.
One of them is Mont Blank Massif which is of type "place".
Another one is Western Alps which is of type "mountain range" - my desired record.
I need record # 2 above but not 1. I know 1 is also relevant but sometimes it doesn't follow same pattern. Sometimes the records appear to be of YAGO type, which can be totally misleading. To be safe, I simply want to discard those records whenever there is type mismatch.
How can I form my SPARQL query to get these "is dbpedia-owl:highestPlace of" records and also have the type filtering?
you can use this query, note however that Mont_Blanc_massif in your example is both a dbpedia-owl:Place and a dbpedia-owl:MountainRange
select * where {
?place dbpedia-owl:highestPlace :Mont_Blanc.
?place rdf:type dbpedia-owl:MountainRange.
}
run query
edit after comment: filter
It is not really clear what you want to filter (yago?), technically you can filter for example like this:
select * where {
?place dbpedia-owl:highestPlace :Mont_Blanc.
?place rdf:type dbpedia-owl:MountainRange.
FILTER NOT EXISTS {
?place ?pred ?obj
Filter (regex(?obj, "yago"))
}
}
this filters out results that have any object with 'yago' in its URL.
Extending the result from the previous answer, the appropriate query would be
select * where {
?mountain a dbpedia-owl:Mountain ;
dbpedia-owl:abstract ?abstract ;
foaf:depiction ?depiction .
?range a dbpedia-owl:MountainRange ;
dbpedia-owl:highestPlace ?mountain .
FILTER(langMatches(lang(?abstract),"EN"))
}
LIMIT 10
SPARQL Results
This selects mountains with English abstracts that have at least one depiction (or else the pattern wouldn't match) and for which there is some mountain range of which the mountain is the highest place. Without the parts from the earlier question, if you just want to retrieve mountains that are the highest place of a range, you can use a query like this:
select * where {
?mountain a dbpedia-owl:Mountain .
?range a dbpedia-owl:MountainRange ;
dbpedia-owl:highestPlace ?mountain .
}
LIMIT 10
SPARQL results