Protege Equivalent to query - sparql

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

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

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

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