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 .
}
Related
I am trying to get children of persons. Some persons have children listed in "dbo:child", others have them listed as "is dbo:parent of"
Here are examples of the two types
https://dbpedia.org/page/Elizabeth_II
https://dbpedia.org/page/George_V
For the first one I can pull child records off as follows:
SELECT * WHERE {
<http://dbpedia.org/resource/Elizabeth_II>
dbo:child?child
}
For the second it's a bit harder as I think I have to find other records which point to George_V. I'm struggling to find anything that works, this is the best I can come up with
SELECT *
WHERE
{
?person a dbo:Person ;
dbo:parent [dbo:Person dbr:George_V]
}
limit 10
What's the best way to do this? Is there a way I can combine the two approaches?
Here's an example that solves the problem. Note, you have to look at the data for familial properties (relationship types) and then explore regarding data quality.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT DISTINCT ?royal ?ancestor
WHERE {
{
<http://dbpedia.org/resource/Charles,_Prince_of_Wales>
<http://dbpedia.org/property/father>+ ?ancestor .
}
UNION
{
<http://dbpedia.org/resource/Charles,_Prince_of_Wales>
<http://dbpedia.org/property/mother>+ ?ancestor .
}
BIND ( <http://dbpedia.org/resource/Charles,_Prince_of_Wales> as ?royal )
}
Live DBpedia Query Solution Link.
Alternatively, which is closer to your original property preference (i.e., dbo:parent), here is another property-paths based example.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT DISTINCT ?royal ?ancestor ?ancestorName
WHERE {
<http://dbpedia.org/resource/Elizabeth_II>
dbo:parent* ?ancestor .
?ancestor
foaf:name ?ancestorName .
FILTER (LANG(?ancestorName) = "en")
BIND ( <http://dbpedia.org/resource/Elizabeth_II> as ?royal )
}
Live Query Results Link.
We are working on a new DBpedia release that should have increased quality regarding this kind of information.
Finally, a tweak to some earlier suggestions (posted as comments).
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT DISTINCT ?royal ?child
WHERE {
dbr:George_V dbo:child+|^dbo:parent+ ?child .
BIND ( dbr:George_V AS ?royal )
}
Live DBpedia Query Link.
How to List the laureate awards (given by their label) for which the description of the contribution (given by nobel:motivation) contains the word "human" together with the word "peace" (i.e., both words must be there).
I have use the bds:search namespace from the the full-text search feature of Blazegraph.
After visiting this link i have composed this query
Free text search in sparql when you have multiword and scaping character
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bds: <http://www.bigdata.com/rdf/search#>
PREFIX nobel: <http://data.nobelprize.org/terms/>
SELECT ?awards ?description
WHERE {
?entity rdfs:label ?awards .
?entity nobel:motivation ?description .
FILTER ( bds:search ( ?description, '"human" AND "peace"' ) )
}
This query is returning me the following error on execution shown in image.
Error Image
How to correct this query and get the desired result?
You may take a look at the specification of this dataset or download an RDF dump of the dataset
Use bds:search to search for "human" category.Then apply filter and contain function to "peace".
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bds: <http://www.bigdata.com/rdf/search#>
PREFIX nobel: <http://data.nobelprize.org/terms/>
PREFIX bif: <http://www.openlinksw.com/schemas/bif#>
SELECT ?awards ?description
WHERE {
?entity rdfs:label ?awards .
?entity nobel:motivation ?description .
?description bds:search "human" .
FILTER (CONTAINS(?description, "peace"))
}
I'm trying to calculate the distance between two points using geosparql. I have objects like the following image (same properties, different values):
And I'm executing that query in sparql:
PREFIX geos: <http://www.opengis.net/ont/geosparql#>
PREFIX geosf: <http://www.opengis.net/def/function/geosparql/>
PREFIX : <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#>
SELECT ?distance
WHERE {
?wifipoint1 :hasGeometry ?geo1 .
?geo1 geos:asWKT ?wpoint1 .
FILTER sameterm(?wifipoint1, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree103>)
?wifipoint2 :hasGeometry ?geo2 .
?geo2 geos:asWKT ?wpoint2 .
FILTER sameterm(?wifipoint2, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree105>) .
?distance geosf:distance(?wpoint1 ?wpoint2 <http://qudt.org/vocab/unit#Kilometer>)
}
Without adding the distance, I'm able to get the following result:
But at the moment I add the distance I get empty rows. Any idea?
Notes:
I need to calculate the distance between two wifipoints (NYWifiFree103 and NYWifiFree105) which have each one a point.
I'm executing that queries in stardog.
** EDIT **
I simplified the query:
PREFIX geos: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX : <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#>
SELECT (geof:distance(?wpoint1, ?wpoint2, <http://qudt.org/vocab/unit#Kilometer>) as ?distance)
WHERE {
?wifipoint1 :hasGeometry ?geo1 .
?geo1 geos:asWKT ?wpoint1 .
FILTER sameterm(?wifipoint1, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree103>) .
?wifipoint2 :hasGeometry ?geo2 .
?geo2 geos:asWKT ?wpoint2 .
FILTER sameterm(?wifipoint2, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree105>)
}
When I set in geof:distance two harcoded wktLiteral returns me correct distance, but using Points does not return nothing.
The geof:distance function accepts Geometries as its first two parameters. So with your simplified query, using geof:distance(?geo1, ?geo2, unit:Kilometer) should give you the result you desire. The Stardog Blog has a geospatial primer post that you may find useful.
AKSW is correct, you should use the built in geof:distance function for the calculation.
I have the same problem with GraphDB. instead of distance it returns 2 fields empty and I have already enabled geosparql
Here is my code:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix unit: <http://qudt.org/vocab/unit#>
prefix sf: <http://www.opengis.net/ont/sf#>
prefix test24: <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
prefix omgeo: <http://www.ontotext.com/owlim/geo#>
SELECT (geof:distance(?point, ?point2, <http://qudt.org/vocab/unit#Kilometer>) as ?distance)
WHERE
{
:MouseioMetaksisSoufliou :hasGPSCoordinates ?geom2.
?geom2 geo:asWKT ?point.
?geom3 geo:asWKT ?point2.
FILTER (?geom2 != ?geom3)
}
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)
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