SPARQL: Exclude datatype uri from query result [duplicate] - sparql

This question already has an answer here:
SPARQL Query: How I get only a literal or string as result?
(1 answer)
Closed 5 years ago.
I am trying to learn SPARQL queries on Protege and I have added some individuals to query on the Movie ontology found at :
Movie Ontology
I have following simple sparql query:
Query 1: Get all movies and actors having rating more than 7.0
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 dbo: <http://dbpedia.org/ontology/>
PREFIX mov: <http://www.movieontology.org/2009/10/01/movieontology.owl#>
SELECT ?subject ?actors ?rating
WHERE {
?subject a mov:Movie;
mov:hasActor ?actors;
mov:imdbrating ?rating.
Filter(?rating > "7.0"^^xsd:double)
}
And I am getting the result as expected:
The problem is that I dont need the ^^xsd:double uri in the rating column !!
How do I get rid of the uri " ^^http://www.w3.org/2001/XMLSchema#double ".
Thanks in advance !

Use str to get the lexical part
SELECT ?subject ?actors (str(?rating) AS ?r)

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

Display by ObjectProperty in SPARQL

I have a problem in displaying the result using SPARQL in protege.
I have two classes Panne and Solution and an ObjectProperty hasSolution .
I want to display the Panne that has A Solution ex: GODEX hasSolution SOLGODEX.
I tried
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 panne:<http://www.semanticweb.org/rahma/ontologies/2020/pannesOnto.owl#>
SELECT ?Panne ?Solution
WHERE {
?Panne panne:hasSolution ?Solution}
Without knowing your specific ontology structure, the following will likely need some adaptations.
Currently your query selects all subjects and objects involved in a tuple using panne:hasSolution.
If you want to filter down to only those of a specific solution, you have to include that in the query:
SELECT ?Panne
WHERE {
?Panne panne:hasSolution ex:SOLGODEX .
}
If you want all pairs of panne:Panne and panne:Solution, add the respective patterns to select only members ot those classes:
SELECT ?Panne ?Solution
WHERE {
?Panne a panne:Panne .
?Solution a panne:Solution .
?Panne panne:hasSolution ?Solution .
}

How to get specific type of individuals in SPARQL?

I am new to SPARQL. I am creating a movie ontology in which actors and actress names are given as individuals with the object property Acted_In. When I write a query to get the names of actress, i get all actors and actress names. How can i specify the type to actress to see only actress names. Here is my query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX Film: <http://www.semanticweb.org/nayye/ontologies/2019/10/untitled-ontology-4#>
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 ?Actress ?Movie WHERE
{
?Actress Film:Acted_In ?Movie.
}
Also how can i see the datatype properties, e.g., year for these movies?
The result is as follows:

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

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}

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