How do get data from example owl data using sparql query - sparql

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

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

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

rdf:type in Jena API for SPARQL not working?

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!

How to query dbpedia.org with sparql

I'm very new in OpenData and try to write a query in SPARQL.
My goal is to get data for following set of criteria:
- Category: Home_automation
- select all items from type "Thing"
- with at least one entry in "is Product of"
- that have a picture-url with a German description
I tried the following:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
cat:Home_automation skos:broader ?x
}
But now I don't know how to add the other filters to the where clause.
I tried to user broader:... to get the items, but I think that was the wrong direction.
I tested the queries with: https://dbpedia.org/sparql
The result should be:
| (label) | (url)
|--------------------------|-----------------------------------
|"Kurzzeitwecker"#de | urls to the picture of the device
|"Staubsauger"#de | -||-
|"Waschmaschine"#de | -||-
|"Geschirrspülmaschine"#de | -||-
Does anyone have some tips please?
UPDATE: new query:
PREFIX cat: <http://dbpedia.org/resource/Category:>
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#>
SELECT ?s ?label WHERE {
?s ?p cat:Home_automation .
?s rdf:type owl:Thing .
?s rdfs:label ?label
FILTER (LANG(?label)='de')
}
order by ?p
It is not clear what you want. You must first know what exact related information dbpedia contains and how they are structured.
However, you can try discovering what types of relationships cat:Home_automation is involved in, thus, you may know better what you want.
I suggest starting by generic queries, to specify how cat:Home_automation occurs in dbpedia, then, you might be able to go more specific, and pose further queries.
A query to list triples where cat:Home_automation is an subject:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?p ?o WHERE {
cat:Home_automation ?p ?o
}
order by ?p
A query to list triples where cat:Home_automation is an object:
PREFIX cat: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?s ?p WHERE {
?s ?p cat:Home_automation
}
order by ?p
check the results, see what is interesting for you, and then continue with further queries.

Protege Equivalent to query

Please help to list all Mealcourse from the wine Ontology or happy to receive useful links like this one :Sparql query on restriction list (Equivalent To) in protégé
MealCourse
and (hasFood value Pizza)
and(hasDrink value Wine)
Thank you
This is a bit complicated, but if you look into the ontology everything that is defined as a :MealCourse is an owl:equivalentClass, so you need to first find all owl:equivalentClass and then if you look into the result you will see that they are made of owl:intersectionOf parts. Then you need to break this intersection and filter so that you will only get objects that have :MealCourse as part of the intersection.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
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 : <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#>
SELECT distinct *
WHERE { ?subject owl:equivalentClass ?object.
?object (owl:intersectionOf | owl:unionOf) ?node.
?node rdf:rest*/rdf:first ?eq.
Filter ( ?eq in (:MealCourse ) )
}
orderBy ?subject