SPARQL query against DBPedia to get all property-value of the item - sparql

I am a novice in Semantic Web and I would like to retrieve all property-value pairs of "apple" from DBPedia using SPARQL query. Below I have written the query in http://dbpedia.org/sparql editor, but it returns no any results.Could you tell me where I make a mistake, please?
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dbo: <http://dbpedia.org/ontology/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix prov: <http://www.w3.org/ns/prov#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbp: <http://dbpedia.org/property/>
prefix dct: <http://purl.org/dc/terms/>
select * where {<http://http://dbpedia.org/page/Apple> ?property ?value}

You wrote http:// twice. Also, the correct URI for the query is /resource/, not /page/.
Working query:
select * where {<http://dbpedia.org/resource/Apple> ?property ?value}
Keep in mind this will give you information about the fruit, not the company.

I am giving you the query which will give you information about Apple Company rather than apple Fruit.
PREFIX dbprop: <http://dbpedia.org/property/>
PREFIX db: <http://dbpedia.org/resource/>
SELECT ?property, ?value WHERE {db:Apple_Inc ?property ?value}

Related

SPARQL query: show result for individuals without some attributes, and sum two of the attributes

I have to make this SPARQL query on protege:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sw:<http://www.semanticweb.org/lorep/ontologies/2022/0/untitled-ontology-16#>
SELECT ?Name ?Surname ?test ?written ?oral ?Course
WHERE {
?Candidates sw:take_parts ?Course;
sw:Name ?Name;
sw:Surname ?Surname;
sw:test ?test;
sw:written ?written;
sw:oral ?oral;
}
Now I have some candidates that took only the test without taking written and oral so when I execute the query they does not show. How can I make everyone visible?
And then how could i sum the values from written and oral? I tried with BIND(?written+?oral AS ?total) but it doesn't seem to work

Querying dbpedia, not getting expected result not sure what's the mistake

My query is
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT ?craft where
{
?craft <http://dbpedia.org/property/title> ?v.
}
Now this returning lot of results,
but nothing related to Steve Jobs or Tim Cook, even though in their page there is a property named title.
dbp:title dbr:List_of_Apple_Computer_CEOs
http://dbpedia.org/page/Steve_Jobs
The query:
PREFIX dbp: <http://dbpedia.org/property/>
SELECT (COUNT(*) AS ?nb_result)
WHERE {
?craft dbp:title ?v .
}
returns:
nb_result
---------
1566113
The public query endpoint for DBpedia limits the number of results to 10,000, among other restrictions. So your chances of retrieving any specific statement there are very small. If you worry that the data at the query endpoint is different than at the front end, you can check that the data is there with the query:
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?prop ?value
WHERE {
dbr:Steve_Jobs ?prop ?value .
}
and compare with what's displayed at http://dbpedia.org/page/Steve_Jobs.

Different order of results in DBpedia through SNORQL vs. SERVICE query

I am trying to retrieve some data about movies from DBpedia. This is my query:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX onto: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT *
{{SELECT *
WHERE {
SERVICE<http://dbpedia.org/sparql>{
?movie dcterms:subject <http://dbpedia.org/resource/Category:American_films> ;
a onto:Film ;
rdfs:label ?title ;
dbpedia2:gross ?revenue .
?movie onto:starring ?actorUri .
?actorUri rdfs:label ?actor .
OPTIONAL {
?movie onto:imdbId ?imdbId .
}
BIND(xsd:integer(?revenue) as ?intRevenue) .
FILTER ((datatype(?revenue) = 'http://dbpedia.org/datatype/usDollar') && (LANGMATCHES(LANG(?title), 'en')) && (LANGMATCHES(LANG(?actor), 'en'))) .
}
}
}}
ORDER BY DESC (?intRevenue)
LIMIT 40000
OFFSET 0
Running this query on http://dbpedia.org/snorql/ (without the SERVICE keyword) returns the correct result. However, doing so from a third party triplestore doesn't yield the same order (ex: Hobbit and Lord of the Rings are missing).
What do I need to change in the query to get identical results?
The best way to overcome this specific limitation is to have your own DBpedia mirror, on which you can set your own limits (including none), and which you can then use as either your primary or remote data store and/or query engine.
(ObDisclaimer: OpenLink Software provides the public DBpedia SPARQL endpoint, produces Virtuoso and the DBpedia Mirror AMI, and employs me.)

SPARQL query for finding current manager

I currently have the following SPARQL query:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://dbpedia.org/property/>
PREFIX o: <http://dbpedia.org/ontology/>
SELECT * WHERE{
?manager p:managerclubs <http://dbpedia.org/resource/Manchester_City_F.C.>.
OPTIONAL {?manager p:cityofbirth ?city}.
OPTIONAL {?manager p:dateOfBirth ?dob}.
OPTIONAL {?manager p:image ?image}.
}
This currently returns all the managers but I want to only return the current manager, is this done via a filter or is there an alternate way of writing the query.
I also have a second question which is on the page for MCFC: http://dbpedia.org/page/Manchester_City_F.C.
How can I access the DBO data types? I assumed that simply using o: instead of p: and then calling the name of the datatype would work but this doesn't seem to be the case.
EDIT:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://dbpedia.org/property/>
PREFIX o: <http://dbpedia.org/ontology/>
SELECT * WHERE{
?ground p:ground <http://dbpedia.org/resource/Manchester_City_F.C.>.
OPTIONAL {?ground p:seatingCapacity ?capacity}.
OPTIONAL {?ground p:image ?image}.
}
I don't understand why the above query returns nothing in: http://dbpedia.org/sparql, from the page ground is of type dbp and there is an image and seatinCapacity for the ground.
You don't need to add filter in this case. You can just use the property o:manager:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://dbpedia.org/property/>
PREFIX o: <http://dbpedia.org/ontology/>
SELECT * WHERE{
<http://dbpedia.org/resource/Manchester_City_F.C.> o:manager ?manager
OPTIONAL {?manager p:cityofbirth ?city}.
OPTIONAL {?manager p:dateOfBirth ?dob}.
OPTIONAL {?manager foaf:depiction ?image}.
}
You may also use p:currentclub but I wouldn't recommended as its object is literal.
Regarding the second question, the capacity seams to be object of p:capacity but I don't see an p:image property, only foaf:depiction, which I also used on the query above for the managers.
As your first question is duly answered by Ivo, here's how your second can be improved. If you are looking for the stadium of Manchester City F.C, that fact is represented as bellow.
dbr:Manchester_City_F.C. p:ground dbr:City_of_Manchester_Stadium
You are using the relation with opposite direction. Your query should be
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://dbpedia.org/property/>
PREFIX o: <http://dbpedia.org/ontology/>
SELECT * WHERE{
<http://dbpedia.org/resource/Manchester_City_F.C.> p:ground ?ground .
OPTIONAL {?ground p:seatingCapacity ?capacity}.
OPTIONAL {?ground p:image ?image}.
}

DBPedia SPARQL query should return results but is empty

I want to get all pages which have a specified category and a specified key. My query:
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://dublincore.org/2010/10/11/dcterms.rdf#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX grs: <http://www.georss.org/georss/point>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?page ?cat ?key ?value (lang(?value) as ?language) WHERE {
?page dcterms:subject ?cat .
?page ?key ?value .
FILTER(
regex(?cat, "category:Amusement_parks_in_the_Netherlands") &&
?key = foaf:depiction
)
}
But it return zero results. See here: SNORQL query
It should at least return this page: http://dbpedia.org/page/Duinrell (because it matches the criteria).
Any ideas?
There's a couple of things wrong with your query. First of all, don't use a regex when comparing URIs. Instead of:
regex(?cat, "category:Amusement_parks_in_the_Netherlands")
use:
?cat = <http://dbpedia.org/resource/category:Amusement_parks_in_the_Netherlands>
Second: your namespace prefix for dublin core seems wrong. You are querying the property dcterms:subject, and in your query, the prefix dcterms is mapped to the namespace http://dublincore.org/2010/10/11/dcterms.rdf#. However, the actual property in DBPedia is http://purl.org/dc/terms/subject, so your namespace prefix should map to http://purl.org/dc/terms/ instead.