Could you please translate this query into English?
I am trying to write a naive implementation in code.
PREFIX om-owl: <http://knoesis.wright.edu/ssw/ont/sensor-observation.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX weather: <http://knoesis.wright.edu/ssw/ont/weather.owl#>
SELECT DISTINCT ?sensor ?value ?uom
FROM NAMED STREAM <http://www.cwi.nl/SRBench/observations> [NOW - 1 HOURS]
WHERE {
?observation om-owl:procedure ?sensor ;
rdf:type/rdfs:subClassOf* weather:PrecipitationObservation ;
om-owl:result ?result .
?result ?p1 ?value .
OPTIONAL {
?result ?p2 ?uom .
}
}
Any help will be appreciated
As I understand it:
SELECT DISTINCT ?sensor ?value ?uom
Give me all the distinct sensors name, their value and the uom (I am not familiar with sensors) that correspond to the following conditions :
?observation om-owl:procedure ?sensor ;
First, give me the observations related by a procedure to a sensor.
rdf:type/rdfs:subClassOf* weather:PrecipitationObservation ;
From these observations, take all those are subclasses of Precipitations.
om-owl:result ?result .
And extract me their result.
?result ?p1 ?value .
Take all their value.
OPTIONAL { ?result ?p2 ?uom . }
And if it exist, all their uom (?).
So in the end, it seems to get all the value of rainfall aggregated by hour for each sensor.
Related
Im a using Virtuoso and DBpedia as an endpoint.
My purpose is to retrieve all movies which have a greater amount of actor than the mean number of actors for all movies.
I thought the following query would work:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT
DISTINCT ?film
COUNT(?actor) AS ?numActors
WHERE{
?film rdf:type dbp:Film .
?film dbp:starring ?actor .
{
SELECT
AVG(?numActors) AS ?avgNumActors
WHERE{
SELECT
?Sfilm
COUNT(?Sactor) AS ?numActors
WHERE{
?Sfilm rdf:type dbp:Film .
?Sfilm dbp:starring ?Sactor
}
}
}
}
GROUP BY ?film
HAVING (COUNT(?actor) > ?avgNumActors)
LIMIT 20
but I receveice the following error
Variable ?avgNumActors is used in the result set outside aggregate and not mentioned in GROUP BY clause
What am I doing wrong?
I am working from this example, and I want to archieve the same, however with a different topic - Climate change
All i need to output is the abstract from this page: http://dbpedia.org/page/Climate_change
PREFIX dbp-res: <http://dbpedia.org/resource/>
PREFIX dbp-ont: <http://dbpedia.org/ontology/>
PREFIX dbp-prop: <http://dbpedia.org/property/>
SELECT *
WHERE
{
?Resource a dbp-ont:Agent .
?Resource dbp-ont:abstract ?Description .
?Resource rdfs:label ?Label .
FILTER( STR(?Label) = 'Climate_change' )
FILTER (langMatches(lang(?Description),'en'))
FILTER (langMatches(lang(?Label),'en'))
}
The problem seems to be the Agent, but I have no clue, as to what to replace it with.
My query
I need to calculate distance between two points like this:
Prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Prefix ogc: <http://www.opengis.net/ont/geosparql#>
Prefix geom: <http://geovocab.org/geometry#>
Prefix lgdo: <http://linkedgeodata.org/ontology/>
Select distinct ?label ?uri ?geo
{
?uri rdf:type <http://linkedgeodata.org/ontology/Hotel>;
geom:geometry [ ogc:asWKT ?geo ] .
?uri rdfs:label ?label
Filter (
bif:st_intersect (?geo, bif:st_point (13.3517,38.12407), 0.25)
) .
} LIMIT 1000
The problem is that it seems to give wrong results:
take for example this point (13.3517,38.12407) and one of the result is "Kafara Hotel". If you check its geometry, you can see that the distance is far away to 250m.
How can i get near places between that point and points around 250 meters?
this is my actual problem:
?var0 is a group variable and ?var1 is not. But whenever I try to validate the syntax, there comes the following error message:
Non-group key variable in SELECT: ?var1 in expression ( sum(?var0) / ?var1 )
The complete Query:
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 cz: <http://www.vs.cs.hs-rm.de/ontostor/SVC#Cluster>
PREFIX n: <http://www.vs.cs.hs-rm.de/ontostor/SVC#Node>
SELECT ( (SUM(?var0) / ?var1) AS ?result)
WHERE{
?chain0 rdf:type rdfs:Property .
?chain0 rdfs:domain <http://www.vs.cs.hs-rm.de/ontostor/SVC#Cluster> .
?chain0 rdfs:range <http://www.vs.cs.hs-rm.de/ontostor/SVC#Node> .
?this ?chain0 ?arg0 .
?arg0 n:node_realtime_cpu ?var0 .
?this cz:node_count ?var1 .
}
My question is how to correct that calculation to fit the SPARQL syntax?
The immediate problem is that ?var1 is not grouped on, so a fix would be to simply append
GROUP BY ?var1
at the end of your query.
However, whether that gives you the calculation you actually want is another matter.
It's not quite clear what you're trying to calculate, but it looks as if you're attempting to determine the average node_realtime_cpu for a cluster. If that is the case, you can probably do your calculation by just using SPARQL's AVG function instead:
SELECT ( AVG(?var0) AS ?result)
WHERE{
?chain0 rdf:type rdfs:Property .
?chain0 rdfs:domain <http://www.vs.cs.hs-rm.de/ontostor/SVC#Cluster> .
?chain0 rdfs:range <http://www.vs.cs.hs-rm.de/ontostor/SVC#Node> .
?this ?chain0 ?arg0 .
?arg0 n:node_realtime_cpu ?var0 .
}
GROUP BY ?this // grouping on the cluster identifier so we get an average _per cluster_
Yet another alternative would be to keep your query as-is, but group on two variables:
GROUP BY ?this ?var1
Which is best depends on what your data looks like and what, exactly, you're trying to calculate.
Ok so i have this query
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT (COUNT(?instance) AS ?count) WHERE {
?instance a <http://dbpedia.org/ontology/Ambassador> .
}
and the result is 286. Cool. Now I want to get the number of ambassadors that have http://dbpedia.org/property/name property. But
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT (COUNT(?instance) AS ?count) WHERE {
?instance a <http://dbpedia.org/ontology/Ambassador> .
?instance <http://dbpedia.org/property/name> ?name
}
results in 533 :(. So it is counting more because there are people which have this property one or more times. But how do I get the number of ambassadors that have this property regardless of how many times they have it. Can you do this in a single query?
Thanks.
You might want to try this:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (COUNT(DISTINCT ?instance) AS ?count) WHERE {
?instance a <http://dbpedia.org/ontology/Ambassador>;
<http://dbpedia.org/property/name> ?name
}
It's giving me a result of 283, which might or might not be right :).