> I tried breaking the query down to smaller bits right down to doing a
> simple select on vehicles:
>
> String query1=
> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
> "PREFIX cv:<
> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>"+
>
> "Select ?v"+
> "where {"+
> "?v cv:vehicleSpeed ?speed."+
> "}";
>
> Query query = QueryFactory.create(query1);
> QueryExecution qexec= QueryExecutionFactory.create(query, ontologyModel);
> try{
> ResultSet results=qexec.execSelect();
> while(results.hasNext()){
> QuerySolution soln=results.nextSolution();
> org.apache.jena.rdf.model.Literal name = soln.getLiteral("x");
Do never copy and paste without understand what's done in the code:
Your query selects resources and bind them to a variable ?v. So why you
then try to extract a literal for the variable ?x ?
It has to be

Resource res = soln.getResource("v");
> System.out.println(name);
> }
> }finally{
> qexec.close();
> }
> But everything I have tried yields in the result "null".
>
> Can you give me pointers on how I should go about trying to figure out the
> problem with the insert function?
> Sorry if my questions are too naive, but I am trying to grasp the concepts
> as much as possible.
>
> Best Regards,
> Aya
>
>
>
>
> On Mon, Jun 5, 2017 at 8:32 PM, Andy Seaborne <[email protected]> wrote:
>
>> Then find the sensor of interest, and all cars on that given road.
>>
>> GROUP BY the speed sensor, and the AVG is that of calls on that given road.
>>
>> The way to develop complex queris is to write simple parts, then combine
>> them.
>>
>>         Andy
>>
>>
>> On 05/06/17 16:46, Aya Hamdy wrote:
>>
>>> The goal is not to calculate the avg speed of a car. It is rather to
>>> compute the avg speed of all the cars on a given road and assign that
>>> computed average as the reading of the average speed sensot attached to
>>> that road.
>>>
>>> Sorry if my wording is causing confusion.
>>>
>>> On Jun 5, 2017 5:12 PM, "Lorenz Buehmann" <
>>> [email protected]> wrote:
>>>
>>> No, why do you think so? ?v is the variable that gets assigned a vehicle
>>>> for which you compute the avg speed.
>>>>
>>>> <Instance> should be ?v, i.e. you have to group by it and select it
>>>>
>>>> INSERT {
>>>>
>>>> ?v :avgSpeed ?avg
>>>>
>>>> } WHERE {
>>>>
>>>> SELECT ?v (AVG(?speed) AS ?avg) {
>>>>
>>>> ....
>>>>
>>>> } GROUP BY ?v
>>>>
>>>> }
>>>>
>>>>
>>>> On 05.06.2017 17:03, Aya Hamdy wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I will try to explain with examples. I have generated my ontology from
>>>>> Protege and converted it to turtle syntax via an online tool.
>>>>>
>>>>> *I have a class for average speed sensors:*
>>>>>
>>>>>   ###
>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>
>>>> untitled-ontology-6#Avg_Speed_Sensor
>>>>
>>>>> untitled-ontology-6:Avg_Speed_Sensor rdf:type owl:Class ;
>>>>>
>>>>>                                       rdfs:subClassOf
>>>>> untitled-ontology-6:Sensor ,
>>>>>
>>>>>   untitled-ontology-6:Speed_Sensor .
>>>>>
>>>>> *and a class for vehicles:*
>>>>> ###
>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>
>>>> untitled-ontology-6#Vehicle
>>>>
>>>>> untitled-ontology-6:Vehicle rdf:type owl:Class .
>>>>>
>>>>> *The vehicle class has a property called vehicleSpeed:*
>>>>> ###
>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>
>>>> untitled-ontology-6#vehicleSpeed
>>>>
>>>>> untitled-ontology-6:vehicleSpeed rdf:type owl:DatatypeProperty ;
>>>>>
>>>>>                                   rdfs:domain
>>>>> untitled-ontology-6:Vehicle
>>>>>
>>>> ;
>>>>
>>>>>                                   rdfs:range xsd:integer .
>>>>>
>>>>> *The avg speed sensor class has  a property called recorded_speed:*
>>>>>
>>>>> ###
>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>
>>>> untitled-ontology-6#recorded_speed
>>>>
>>>>> untitled-ontology-6:recorded_speed rdf:type owl:DatatypeProperty ;
>>>>>
>>>>>                                     rdfs:domain
>>>>>
>>>> untitled-ontology-6:Sensor ,
>>>>
>>>>>   untitled-ontology-6:Speed_Sensor ;
>>>>>
>>>>>                                     rdfs:range xsd:integer .
>>>>>
>>>>> The recorded speed by the avg speed sensor allocated to a specific road
>>>>>
>>>> is
>>>>
>>>>> the average of the vehicleSpeeds of the vehicles on that specific road,
>>>>> where the avg speed sensor class has a property called
>>>>> avgSpeedSensor_Infrastructure and the vehicle has a property called
>>>>> Vehicle_Road.
>>>>>
>>>>> I have two vehicle instances: Vehicle1 and Vehicle2; and two sensor
>>>>> instances: SpeedSensor1 and SpeedSensor2.
>>>>>
>>>>> Is it clearer now or just confusing?
>>>>>
>>>>> so I am guessing following your guide it would be something like:
>>>>>
>>>>> INSERT {
>>>>>       <instance> :avgSpeed ?avg
>>>>>     }
>>>>> WHERE {
>>>>>     SELECT (AVG(?speed) AS ?avg) {
>>>>>         ?v rdf:type :Vehicle ;
>>>>>            :vehicleSpeed ?speed;
>>>>>            : Vehicle_Road ?r;
>>>>>         ?avs rdf:type :Avg_Speed_Sensor;
>>>>>                :avgSpeedSensor_Infrastructure ?r
>>>>>
>>>>>     }
>>>>> }
>>>>>
>>>>> But  the value of the  <instance> should come from reading the file,
>>>>>
>>>> right?
>>>>
>>>>>
>>>>> On Sun, Jun 4, 2017 at 9:04 PM, Andy Seaborne <[email protected]> wrote:
>>>>>
>>>>>
>>>>>> On 04/06/17 18:47, Aya Hamdy wrote:
>>>>>>
>>>>>> Hello,
>>>>>>> I wanted to add a property called avgSpeed to an instance of a class
>>>>>>> called
>>>>>>> FlowSensor. This property should be the average of the values of the
>>>>>>> property vehicleSpeed attached to instances of the class Vehicle.
>>>>>>>
>>>>>>> I read that SPARQL update allows doing this. However, I cannot reach
>>>>>>>
>>>>>> the
>>>>> syntax for doing the* averaging of values* or for building the *SPARQL
>>>>>>> Update *query using jena with eclipse on the jena website.
>>>>>>>
>>>>>>> If Jena indeed supports doing what I intend to do then can someone
>>>>>>>
>>>>>> point
>>>>> out some sources to guide me in my attempt?
>>>>>>> Best Regards,
>>>>>>> Aya
>>>>>>>
>>>>>>>
>>>>>>> Calculate the average in a nested select so somethign like (you'll
>>>>>> have
>>>>>>
>>>>> to
>>>>> fix this up):
>>>>>> INSERT {
>>>>>>       <instance> :avgSpeed ?avg
>>>>>>     }
>>>>>> WHERE {
>>>>>>     SELECT (AVG(?speed) AS ?avg) {
>>>>>>         ?v rdf:type :Vehicle ;
>>>>>>            :vehicleSpeed ?speed
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> By the way - it is better to more concrete in your description - actual
>>>>>> data for example.
>>>>>>
>>>>>>
>>>>

Reply via email to