rdf:type in Jena API for SPARQL not working? - sparql

Why Jena API (Java) for SPARQL does not provide any result for queries with rdf:type? Other SPARQL queries work just fine. For example, this query is not working:
SELECT DISTINCT ?p{
?p rdf:type :AAA
}
Full code:
String queryString=listOfPrefixesOntNormXML+" \n"
+"SELECT DISTINCT ?p{ ?p rdf:type :AAA }";
System.out.println(queryString);
Query query = QueryFactory.create(queryString);
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", query );
ResultSet results = qExe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;
Full queryString:
PREFIX : <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl11: <http://www.w3.org/2006/12/owl11#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
PREFIX owl11xml: <http://www.w3.org/2006/12/owl11-xml#>
SELECT DISTINCT ?p{ ?p rdf:type :AAA }

Because you are posing a query to DBpedia endpoint looking for an rdf:type of :AAA which doesn't exist.
If you change it to dbo:Book, it should work, because rdf:type exists in DBpedia!

Related

SPARQL Query filter values from another resource

I have a query made like this:
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/2021/7/untitled-ontology-3#>
SELECT ?Name ?Surname ?Birth ?y
WHERE {
?x sw:is_in ?y ;
sw:Name ?Name;
sw:Surname ?Cognome;
sw:Birth ?Birth;
}
Is there any way to filter from a specific value of the resource y?
I'm quite new to query so any help would be appreciated

SPARQL query all persons who lived through the 20th century in DBPedia

I want to query all persons who lived through the entire 20th century in DBPedia.
Im using https://dbpedia.org/sparql/ to process my query. I have limited the output to 20.
The query I've tried is the following:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?personName ?birthDate ?deathDate
WHERE {
FILTER (?birthDate < "1900-01-01"^^xsd:date AND ?deathDate > "1999-12-31"^^xsd:date).
?p rdf:type dbo:Person.
?p dbp:name ?personName.
?p dbp:birthDate ?birthDate.
?p dbp:deathDate ?deathDate.
}
LIMIT 20.
In the output all person died after 1999-12-31 but they weren't born before 1900-01-01.
Why is my query wrong? How can I fix it?
Thanks in advance for you time.
This issue is due to integer values being included in the query results, and can be resolved using the DATATYPE() function in the same or a new FILTER() section.
For example:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?personName ?birthDate ?deathDate
WHERE
{
?person rdf:type dbo:Person;
dbp:name ?personName;
dbp:birthDate ?birthDate;
dbp:deathDate ?deathDate.
#This FILTER ensures that only xsd:date values are returned
FILTER(DATATYPE(?birthDate) = xsd:date && DATATYPE(?deathDate) = xsd:date).
FILTER (?birthDate < "1900-01-01"^^xsd:date && ?deathDate > "1999-12-31"^^xsd:date).
}
LIMIT 20
Live Query Definition
Live Query Result
DATATYPE() Documentation

How do get data from example owl data using sparql query

This is my example owl :
<rdf:type rdf:resource="http://www.w3.org/2000/10/swap/pim/contact#Person"/>
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</foaf:age>
<foaf:birthday rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10.10</foaf:birthday>
<foaf:firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Liis</foaf:firstName>
</owl:NamedIndividual>
And because im rookie with sparql, i want to know how do make a query to get all instances with this rdf a
<rdf:type rdf:resource="http://www.w3.org/2000/10/swap/pim/contact#Person"/>
nd then get the data from it example like get age and the get age=10 or get name and name="someName"
<foaf:age rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</foaf:age> i mean get data from this row.
My answares to this question are:
This query help you to find all instances, s is the object name, p is the type how do accsess to this data and o is the value of the row.
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX resource: <http://purl.org/vocab/resourcelist/schema#>
select distinct ?s ?p ?o ?k where {
?s ?p ?o ;
a <http://www.w3.org/2000/10/swap/pim/contact#Person> .
?k foaf:age ?x .}
and the second part ?k foaf:age ?x . is how do accsess to instance data by the type name.
and the result is <http://example.register.nl/nationaalhandelsregister#person1>,10

Retrieve all individuals based on Data Property Assertions

I am trying to retrieve information based on Data Property Assertions in Protege (SPARQL Query), however, my code is not working. I am trying to get all individuals that were born after 1960.
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#>
SELECT ?person ?birthYear
WHERE {
?a rdfs:label ?person .
?person xsd:hasBirthYear ?birthYear .
FILTER(?birthYear>=1960)
}

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.)