You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Aya Hamdy <ay...@gmail.com> on 2017/06/04 17:47:47 UTC
Sparql Update: Insert a property whose value is a calculated average
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
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Yes, I see. I don't get why it does not add them when I run it...
Do you see the new tuples when you print or when you open the file ontology
file? Cause with me, when I used your syntax, the new triples show in the
print but when I open the ontology file on Eclipse which I am running the
query on, I find that the triples are not added.
And I have noticed that what you are showing me is in turtle format. The
ontology file is in XML format...Isn't the result of the insertion
function written to the ontology file? Note that I have previously added
lines to my code to try and rewrite the ontology after the query, but the
file is still not affected. I have tried:
FileOutputStream output = null;
try {
output = new FileOutputStream( "yarab.owl ");
} catch(Exception e) {}
ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
and I have tried:
PrintStream p= new PrintStream("yarab.owl");
ontologyModel.writeAll(p, "RDF/XML", null);
p.close();
On Sat, Jun 10, 2017 at 12:37 PM, Aya Hamdy <ay...@gmail.com> wrote:
> Yes, I see. I don't get why it does not add them when I run it...
>
> Do you see the new tuples when you print or when you open the file
> ontology file? Cause with me, when I used your syntax, the new triples show
> in the print but when I open the ontology file on Eclipse which I am
> running the query on, I find that the triples are not added.
>
> And I have noticed that what you are showing me is in turtle format. The
> ontology file is in XML format...Isn't the result of the insertion
> function written to the ontology file? Note that I have previously added
> lines to my code to try and rewrite the ontology after the query, but the
> file is still not affected:
>
> FileOutputStream output = null;
>
> try {
> output = new FileOutputStream( "yarab.owl ");
> } catch(Exception e) {}
>
> ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
>
>
> PrintStream p= new PrintStream("yarab.owl");
> ontologyModel.writeAll(p, "RDF/XML", null);
> p.close();
>
>
>
>
>
> On Sat, Jun 10, 2017 at 8:32 AM, Lorenz B. <buehmann@informatik.uni-
> leipzig.de> wrote:
>
>> That can't be. I tried your example b.java with my query
>>
>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>> PREFIX cv:
>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>> ed-ontology-6#>
>>
>> INSERT {
>> ?ass cv:recorded_speed ?avg .
>> }
>> WHERE
>> { SELECT ?ass (AVG(?speed) AS ?avg)
>> WHERE
>> { ?v cv:vehicleSpeed ?speed ;
>> cv:Vehicle_Road ?r .
>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>> }
>> GROUP BY ?ass
>> }
>>
>> Before execution the model contains 67 triples, afterwards 69. And the
>> added triples are as follows:
>>
>>
>> For SpeedSensor2:
>>
>> untitled-ontology-6:SpeedSensor2
>> a untitled-ontology-6:Speed_Sensor ,
>> untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
>> owl:NamedIndividual ;
>> untitled-ontology-6:avgSpeedSensor_Infrastructue
>> untitled-ontology-6:Road2 ;
>> untitled-ontology-6:recorded_speed
>> 50.0 ;
>> untitled-ontology-6:sensorLocatedInInfrastructure
>> true ;
>> untitled-ontology-6:sensorLocatedInVehicle
>> false .
>>
>> for SpeedSensor1:
>>
>> untitled-ontology-6:SpeedSensor1
>> a untitled-ontology-6:Speed_Sensor
>> , untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
>> owl:NamedIndividual ;
>> untitled-ontology-6:avgSpeedSensor_Infrastructue
>> untitled-ontology-6:Road1 ;
>> untitled-ontology-6:recorded_speed
>> 0.0 ;
>> untitled-ontology-6:sensorLocatedInInfrastructure
>> true ;
>> untitled-ontology-6:sensorLocatedInVehicle
>> false ;
>> untitled-ontology-6:sensor_id 11 .
>>
>> You can, see both now have the recorded_speed value.
>>
>>
>> > And I explained that using Lorenz's example syntax is something that I
>> have
>> > already tried before asking on the list and still the update to the owl
>> > file does not take place. I mentioned that in my previous email.
>> > I think the 2000+ lines u r mentioning are the full ontology file. I
>> > mentioned that the file called ont.owl is the full one in case needed,
>> but
>> > I have already provided a short version called Yarab.owl .. Doubt that
>> > Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles,
>> two
>> > roads instances and a couple of properties ..and it has lots of white
>> lines
>> > to separate the code to blocks for readability purposes. Which file did
>> u
>> > look at? I think u looked at the one I had described to be the full
>> > ontology.
>> >
>> > On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
>> >
>> >> " cv:Vehicle_Road ?r ;"+
>> >> Bad syntax. Replace ";" by "."
>> >>
>> >> Lorenz showed you the correct syntax.
>> >>
>> >> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>> >> Print the query out and see what it looks like. Hence the earlier
>> >> suggestion you put newlines in the query.
>> >>
>> >> Andy
>> >>
>> >> ~2800 lines is not a minimal example.
>> >>
>> >> On 09/06/17 15:53, Aya Hamdy wrote:
>> >>
>> >>> When I do not use the subselect and write the query this way:
>> >>>
>> >>> String queryString1 =
>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
>> >>> "PREFIX cv:<
>> >>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitle
>> d-ontology-6#
>> >>>> "+
>> >>> "INSERT {"+
>> >>> " ?ass cv:recorded_speed ?avg"+
>> >>> "}"+
>> >>> "WHERE {"+
>> >>> "SELECT (AVG(?speed) AS ?avg) {"+
>> >>> "?v cv:vehicleSpeed ?speed;"+
>> >>> " cv:Vehicle_Road ?r ;"+
>> >>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>> >>>
>> >>>
>> >>>
>> >>> "}"+ "GROUP BY ?r ?ass"+
>> >>> "}";
>> >>>
>> >>> The code generates the error below when it tries to execute the update
>> >>> action:
>> >>> Exception in thread "main" org.apache.jena.query.QueryParseException:
>> >>> Encountered " <VAR1> "?r "" at line 1, column 299.
>> >>> Was expecting one of:
>> >>> "values" ...
>> >>> "graph" ...
>> >>> "optional" ...
>> >>> "minus" ...
>> >>> "bind" ...
>> >>> "service" ...
>> >>> "filter" ...
>> >>> "{" ...
>> >>> "}" ...
>> >>> ";" ...
>> >>> "," ...
>> >>> "." ...
>> >>>
>> >>> When I researched these options under "Was expecting one of:", I did
>> not
>> >>> find one of those options that would fit my query.
>> >>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to
>> ensure
>> >>> that the sensor is attached to the road on which the car is on.
>> >>>
>> >>> I group by ?r to try to ensure that the grouping is per road as well.
>> But
>> >>> I
>> >>> think you have a point, and I should group by the sensor as well.
>> >>>
>> >>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full
>> stop
>> >>> instead of a full stop the error goes away, but still, nothing
>> happens in
>> >>> the owl file. Meaning, the new tuple is not added either. (I am a bit
>> >>> confused as to when to put a ";" and when to put a "." I believe, as
>> far
>> >>> as
>> >>> my understanding goes, when I put a "." in the end of the
>> >>> " cv:Vehicle_Road ?r " the error goes away because the last line
>> "?ass
>> >>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
>> >>> could
>> >>> you confirm or negate that?)
>> >>>
>> >>> Your help is truly much appreciated.
>> >>>
>> >>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
>> >>> buehmann@informatik.uni-leipzig.de> wrote:
>> >>>
>> >>> There was some formatting issue in my previous mail.
>> >>>> What I was wondering the need for grouping by ?r instead of ?ass.
>> >>>>
>> >>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>> >>>> PREFIX cv:
>> >>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>> >>>> ed-ontology-6#
>> >>>>
>> >>>>>
>> >>>> INSERT {
>> >>>> ?ass cv:recorded_speed ?avg .
>> >>>> }
>> >>>> WHERE
>> >>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>> >>>> WHERE
>> >>>> { ?v cv:vehicleSpeed ?speed ;
>> >>>> cv:Vehicle_Road ?r .
>> >>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>> >>>> }
>> >>>> GROUP BY ?r ?ass
>> >>>> }
>> >>>>
>> >>>>
>> >>>>
>> >>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
>> >>>>
>> >>>>> That is your query:
>> >>>>>
>> >>>>> 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#>
>> >>>>
>> >>>>> INSERT {
>> >>>>> ?ass cv:recorded_speed ?avg .
>> >>>>> }
>> >>>>> WHERE
>> >>>>> { SELECT (AVG(?speed) AS ?avg)
>> >>>>> WHERE
>> >>>>> { ?v cv:vehicleSpeed ?speed ;
>> >>>>> cv:Vehicle_Road ?r
>> >>>>> { SELECT ?r
>> >>>>> WHERE
>> >>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
>> >>>>> }
>> >>>>> }
>> >>>>> GROUP BY ?r
>> >>>>> }
>> >>>>>
>> >>>>> The problem is that you use for what ever reason a sub-SELECT to
>> get the
>> >>>>> ?ass value. But this value is not propagated to the outer query,
>> thus,
>> >>>>> it's not bound to the INSERT part.
>> >>>>>
>> >>>>> Why not do it like here (note, I dPREFIX rdf:
>> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>> >>>>> PREFIX cv:
>> >>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>> >>>>>
>> >>>> untitled-ontology-6#>
>> >>>>
>> >>>>> INSERT {
>> >>>>> ?ass cv:recorded_speed ?avg .
>> >>>>> }
>> >>>>> WHERE
>> >>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>> >>>>> WHERE
>> >>>>> { ?v cv:vehicleSpeed ?speed ;
>> >>>>> cv:Vehicle_Road ?r .
>> >>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>> >>>>> }
>> >>>>> GROUP BY ?r ?ass
>> >>>>> }on't know why you group by ?r instead of ?ass, thus, added
>> both):
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
>> >>>>>
>> >>>>>> Didn't know attachments are not allowed.
>> >>>>>> This is a gist of the three files.
>> >>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808
>> dbf85d9
>> >>>>>>
>> >>>>>> The code files are minimalist as you can see on the gist. Only the
>> >>>>>>
>> >>>>> query is
>> >>>>> included and everything else is removed. I wanted to attach them as
>> >>>>> files
>> >>>>> to avoid clutter in the email. I believe things are more organized
>> this
>> >>>>> way.
>> >>>>>> The problem is in b.java file. The c.java file is just to prove
>> that
>> >>>>>> the
>> >>>>>> individual parts of the query work together. And the OWL file is
>> the
>> >>>>>> one
>> >>>>>> generated by Protege. It has no problems, but I have removed
>> anything
>> >>>>>>
>> >>>>> that
>> >>>>> is not needed for this specific query.
>> >>>>>> I have also attached a file called "ont.owl (full)" which has the
>> full
>> >>>>>> ontology in case it is needed (which I think it is not needed, but
>> just
>> >>>>>>
>> >>>>> in
>> >>>>> case I misunderstand).
>> >>>>>> Regards,
>> >>>>>>
>> >>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org>
>> wrote:
>> >>>>>>
>> >>>>>> Attachments don't get through to this list.
>> >>>>>>> Put them in a pastebin or guithub gist.
>> >>>>>>>
>> >>>>>>> However, if they are so large that inlining email in plain text is
>> >>>>>>> impractical, than it suggests they are not minimal.
>> >>>>>>>
>> >>>>>>> Andy
>> >>>>>>>
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>> >>>>>>>
>> >>>>>>> You forgot the attachments...
>> >>>>>>>>
>> >>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>> >>>>>>>>
>> >>>>>>>> Attached is a file of my code and my ontology which I have
>> imported
>> >>>>>>>> on
>> >>>>> Eclipse.
>> >>>>>>>>> I have finally fixed the null values issue. I am not sure if I
>> >>>>>>>>> understood the cause of the nulls correctly. However, it got
>> fixed
>> >>>>>>>>> when I used a different way of making the ResultSet as shown
>> below:
>> >>>>>>>>>
>> >>>>>>>>> Query query = QueryFactory.create(queryString1);
>> >>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>> >>>>>>>>> ontologyModel);
>> >>>>>>>>> ResultSet results=qexec.execSelect();
>> >>>>>>>>> ResultSetFormatter.out(System.out, results, query);
>> >>>>>>>>> qexec.close();
>> >>>>>>>>> I am including this bit of code here in case this helps someone
>> else
>> >>>>>>>>> in the future cause I could not find it easily. It can be found
>> in
>> >>>>>>>>> context in the attached c.java file.
>> >>>>>>>>>
>> >>>>>>>>> However, the original bigger problem still persists. The insert
>> >>>>>>>>>
>> >>>>>>>> SPARQL
>> >>>>> query still does not result in inserting the new desired subject
>> >>>>>>>>> predicate object triple. No errors are generated which is I
>> suppose
>> >>>>>>>>> a
>> >>>>>>>>> good thing, but when I print the ontology after running the
>> query, I
>> >>>>>>>>> can see that the new triples are not added.
>> >>>>>>>>>
>> >>>>>>>>> Attached is the owl file and the java file (b.java). I have
>> added
>> >>>>>>>>> explanatory comments in the java file hoping to clarify what I
>> am
>> >>>>>>>>> trying to do here.
>> >>>>>>>>>
>> >>>>>>>>> Also, hoping to clarify matters a bit more, I have two average
>> speed
>> >>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>> >>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>> >>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1
>> >>>>>>>>> with
>> >>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
>> >>>>>>>>> vehicleSpeed
>> >>>>>>>>> of 50. Only one vehicle is modeled to be located on each road
>> in an
>> >>>>>>>>> attempt to simplify things for now.
>> >>>>>>>>>
>> >>>>>>>>> The goal is to calculate the average of speeds of all vehicles
>> on
>> >>>>>>>>> road1 and assign it as the value of the object property called
>> >>>>>>>>> recorded_speed of the speed sensor attached to the road which
>> the
>> >>>>>>>>> vehicles are on. Consequently, based on my modeling, after
>> running
>> >>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since
>> only
>> >>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and
>> vehicle1
>> >>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of
>> 50
>> >>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is
>> attached
>> >>>>>>>>>
>> >>>>>>>> and
>> >>>>> vehicle2 has speed of 50).
>> >>>>>>>>> Also, attached is another java file (c.java) that has the
>> results of
>> >>>>>>>>> me breaking down the big query in b.java.
>> >>>>>>>>> My suspicion is that the part where I am trying to invoke the
>> insert
>> >>>>>>>>> query is not working, but the way I built is based on
>> StackOverflow
>> >>>>>>>>> and it was supposedly working fine, so I am not sure what I am
>> >>>>>>>>>
>> >>>>>>>> missing.
>> >>>>>>>>> Hope this gives you a picture of what is going on and hope you
>> can
>> >>>>>>>>> help me understand why I cannot get the query to update the
>> >>>>>>>>> ontology.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>> >>>>>>>>> <buehmann@informatik.uni-leipzig.de
>> >>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>> >>>>>>>>>
>> >>>>>>>>> If results are bound it can't be a null value. Please show
>> >>>>>>>>> your
>> >>>>>>>>> updated
>> >>>>>>>>> code.
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>> >>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is
>> nit
>> >>>>>>>>> the
>> >>>>>>>>> cause of the
>> >>>>>>>>> > null. When I fixed it, the results of even the simplest
>> >>>>>>>>>
>> >>>>>>>> queries
>> >>>>> are still
>> >>>>>>>>> > nulls.
>> >>>>>>>>> >
>> >>>>>>>>> > The code is not generating errors though, it is not
>> >>>>>>>>> generating
>> >>>>>>>>> the proper
>> >>>>>>>>> > results ...
>> >>>>>>>>> >
>> >>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
>> >>>>>>>>>
>> >>>>>>>> andy@apache.org
>> >>>>> <ma...@apache.org>> wrote:
>> >>>>>>>>> >
>> >>>>>>>>> >>
>> >>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>> >>>>>>>>> >>
>> >>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking
>> down
>> >>>>>>>>>
>> >>>>>>>> my
>> >>>>> chain of
>> >>>>>>>>> >>> thought into smaller pieces. Thank you so much.
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> I saw an example online where the query syntax is
>> written
>> >>>>>>>>>
>> >>>>>>>> as a
>> >>>>> string on
>> >>>>>>>>> >>> Jena. so my query now looks like this:
>> >>>>>>>>> >>>
>> >>>>>>>>> >> Use
>> >>>>>>>>> >>
>> >>>>>>>>> >> String.join("\n"
>> >>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>> >>>>>>>>>
>> >>>>>>>> 02/22-rdf-syntax-ns#
>> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>> >>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>> >>>>>>>>>
>> >>>>>>>> 02/22-rdf-syntax-ns#
>> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>> >>>>>>>>> >> , "INSERT {",
>> >>>>>>>>> >> ...
>> >>>>>>>>> >> , "}"
>> >>>>>>>>> >> );
>> >>>>>>>>> >>
>> >>>>>>>>> >> then you will have newlines in the string and parser
>> errors
>> >>>>>>>>> will have
>> >>>>>>>>> >> line+column numbers that are useful.
>> >>>>>>>>> >>
>> >>>>>>>>> >> Andy
>> >>>>>>>>> >>
>> >>>>>>>>> >>
>> >>>>>>>>> >>
>> >>>>>>>>> >>> String queryString=
>> >>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02
>> /22-rdf-syntax-ns#
>> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>> >>>>>>>>> >>> "PREFIX cv:<
>> >>>>>>>>> >>>
>> >>>>>>>>> http://www.semanticweb.org/to
>> shiba/ontologies/2017/3/untitl
>> >>>>>>>>> ed-ontology-6#
>> >>>>>>>>> <http://www.semanticweb.org/t
>> oshiba/ontologies/2017/3/untit
>> >>>>>>>>> led-ontology-6#>
>> >>>>>>>>> >>>> "+
>> >>>>>>>>> >>> "insert {"+
>> >>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>> >>>>>>>>> >>> "}"+
>> >>>>>>>>> >>> "WHERE {"+
>> >>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>> >>>>>>>>> >>> "where{"+
>> >>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>> >>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
>> >>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
>> >>>>>>>>> >>> "{"+
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> "SELECT ?r"+
>> >>>>>>>>> >>> "where{"+
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>> >>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>> >>>>>>>>> >>> "}"+
>> >>>>>>>>> >>> "}"+
>> >>>>>>>>> >>>
>> >>>>>>>>> >>>
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>> >>>>>>>>> >>> "}";
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> Then, also based on my research, I feed the query
>> string
>> >>>>>>>>>
>> >>>>>>>> into
>> >>>>> the parser
>> >>>>>>>>> >>> and output the model.
>> >>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel
>> );
>> >>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
>> >>>>>>>>> >>> I encountered many errors but managed to get rid of
>> them
>> >>>>>>>>>
>> >>>>>>>> all.
>> >>>>> However,
>> >>>>>>>>> >>> based on the output, nothing has changed.
>> speedSensor1
>> >>>>>>>>> and
>> >>>>>>>>> speedSensor2
>> >>>>>>>>> >>> do
>> >>>>>>>>> >>> not have the recorded_speed property added.
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> Of course, I tried debugging, but I could not get any
>> >>>>>>>>> understanding of the
>> >>>>>>>>> >>> problem.
>> >>>>>>>>> >>>
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> 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#
>> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>> >>>>>>>>> >>> "PREFIX cv:<
>> >>>>>>>>> >>>
>> >>>>>>>>> http://www.semanticweb.org/to
>> shiba/ontologies/2017/3/untitl
>> >>>>>>>>> ed-ontology-6#
>> >>>>>>>>> <http://www.semanticweb.org/t
>> oshiba/ontologies/2017/3/untit
>> >>>>>>>>> led-ontology-6#>
>> >>>>>>>>> >>>> "+
>> >>>>>>>>> >>> "Select ?v"+
>> >>>>>>>>> >>> "where {"+
>> >>>>>>>>> >>> "?v cv:vehicleSpeed ?speed."+
>> >>>>>>>>> >>> "}";
>> >>>>>>>>> >>>
>> >>>>>>>>> >>> Query query = QueryFactory.create(query1);
>> >>>>>>>>> >>> QueryExecution qexec= QueryExecutionFactory.create(q
>> uery,
>> >>>>>>>>> ontologyModel);
>> >>>>>>>>> >>> try{
>> >>>>>>>>> >>> ResultSet results=qexec.execSelect();
>> >>>>>>>>> >>> while(results.hasNext()){
>> >>>>>>>>> >>> QuerySolution soln=results.nextSolution();
>> >>>>>>>>> >>> org.apache.jena.rdf.model.Literal name =
>> >>>>>>>>>
>> >>>>>>>> soln.getLiteral("x");
>> >>>>> >>> 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 <
>> >>>>>>>>>
>> >>>>>>>> andy@apache.org
>> >>>>> <ma...@apache.org>> 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" <
>> >>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>> >>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/tos
>> hiba/ontologies/2017/3/
>> >>>>>>>>> <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/tos
>> hiba/ontologies/2017/3/
>> >>>>>>>>> <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/tos
>> hiba/ontologies/2017/3/
>> >>>>>>>>> <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/tos
>> hiba/ontologies/2017/3/
>> >>>>>>>>> <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
>> >>>>>>>>> <andy@apache.org <ma...@apache.org>>
>> >>>>>>>>> >>>>>>> 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.
>> >>>>>>>>> >>>>>>>>
>> >>>>>>>>> >>>>>>>>
>> >>>>>>>>> >>>>>>>>
>> >>>>>>>>> >>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>>>>>>
>> >>>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Thanks! I wrote the file to a different path and imported it to eclipse and
finally, it has the new attributes.
Thank you, Lorenz for your help and patience for the past days, much
appreciated.
On Sun, Jun 11, 2017 at 12:01 PM, Lorenz B. <
buehmann@informatik.uni-leipzig.de> wrote:
> Please upload your update code for b.java
>
> And then try to write to another path instead of the same file, just to
> make sure that you really write to disk.
>
> > - I had included the writing to the file in b.java, but I must have
> dropped
> > it by mistake when putting the files as a gist, apologies.
> >
> > - I am not surprised with the output. Don't know why you got that
> > impression. You are right, it is my code so I know what I have written
> and
> > I have made the output TTL for a reason for sure. It is neater to read in
> > the console as a personal preference.
> >
> > -I used the system.write with the query you provided, I am using your
> > query for my trials with the file now. Note that your query is different
> > from the syntax I had tried before the sub-select by removing one of the
> > where clauses. I was treating the query too much like SQL syntax it
> seems,
> > so thx again for that.
> >
> > - I used writeall because in the original file, not the summarized
> > b.java one there are other inferences made, so it would have its uses.
> > Thanks for the update on the write syntax, I removed the xmlbase
> argument,
> > but still nothing.
> >
> > Finally, the file is not affected by the write although you tried it and
> it
> > worked with you, and we are working on the same files with the same
> > contents. so that is a whole other level of hopelessness. If it worked
> for
> > you then it should have worked with me.
> >
> > Anyway thanks for your efforts, it was much appreciated.
> >
> >
> >
> >
> >
> > On Jun 11, 2017 10:26 AM, "Lorenz B." <buehmann@informatik.uni-
> leipzig.de>
> > wrote:
> >
> >>
> >>> Yes, I see. I don't get why it does not add them when I run it...
> >>>
> >>> Do you see the new tuples when you print or when you open the file
> >> ontology
> >>> file? Cause with me, when I used your syntax, the new triples show in
> the
> >>> print but when I open the ontology file on Eclipse which I am running
> the
> >>> query on, I find that the triples are not added.
> >> As I said, I just used your code in b.java, thus, it's just printed to
> >> System.out .
> >>> And I have noticed that what you are showing me is in turtle format.
> The
> >>> ontology file is in XML format...
> >> The same, your code prints to System.out as "TTL" which is Turtle - I'm
> >> wondering why you're surprised, it's your code.
> >>> Isn't the result of the insertion
> >>> function written to the ontology file?
> >> No, the triples in the ontology are loaded into memory. That means you
> >> have to write the model back to disk
> >>> Note that I have previously added
> >>> lines to my code to try and rewrite the ontology after the query, but
> the
> >>> file is still not affected:
> >> But you did this without the query that I provided?
> >>> FileOutputStream output = null;
> >>>
> >>> try {
> >>> output = new FileOutputStream( "yarab.owl ");
> >>> } catch(Exception e) {}
> >>>
> >>> ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
> >> Do you really want to use writeAll()? This also writes inferred and
> >> imported triples to disk. Otherwise, use write()
> >> And the argument "xmlbase" is for sure wrong. It expects the base URI of
> >> the XML (or Turtle) document if exist - you can also use NULL or simply
> >> use write(output, "RDF/XML-ABBREV")
> >>
> >>
> >>
> >> To sum up, writing to disk works for me as well. I don't see why this
> >> should not work if the INSERT already modified the model.
> >>
> >>>
> >>> PrintStream p= new PrintStream("yarab.owl");
> >>> ontologyModel.writeAll(p, "RDF/XML", null);
> >>> p.close();
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On Sat, Jun 10, 2017 at 8:32 AM, Lorenz B. <
> >>> buehmann@informatik.uni-leipzig.de> wrote:
> >>>
> >>>> That can't be. I tried your example b.java with my query
> >>>>
> >>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>> PREFIX cv:
> >>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> >> ed-ontology-6#
> >>>> INSERT {
> >>>> ?ass cv:recorded_speed ?avg .
> >>>> }
> >>>> WHERE
> >>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>> WHERE
> >>>> { ?v cv:vehicleSpeed ?speed ;
> >>>> cv:Vehicle_Road ?r .
> >>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>> }
> >>>> GROUP BY ?ass
> >>>> }
> >>>>
> >>>> Before execution the model contains 67 triples, afterwards 69. And the
> >>>> added triples are as follows:
> >>>>
> >>>>
> >>>> For SpeedSensor2:
> >>>>
> >>>> untitled-ontology-6:SpeedSensor2
> >>>> a untitled-ontology-6:Speed_Sensor ,
> >>>> untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
> >>>> owl:NamedIndividual ;
> >>>> untitled-ontology-6:avgSpeedSensor_Infrastructue
> >>>> untitled-ontology-6:Road2 ;
> >>>> untitled-ontology-6:recorded_speed
> >>>> 50.0 ;
> >>>> untitled-ontology-6:sensorLocatedInInfrastructure
> >>>> true ;
> >>>> untitled-ontology-6:sensorLocatedInVehicle
> >>>> false .
> >>>>
> >>>> for SpeedSensor1:
> >>>>
> >>>> untitled-ontology-6:SpeedSensor1
> >>>> a untitled-ontology-6:Speed_
> Sensor
> >>>> , untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
> >>>> owl:NamedIndividual ;
> >>>> untitled-ontology-6:avgSpeedSensor_Infrastructue
> >>>> untitled-ontology-6:Road1 ;
> >>>> untitled-ontology-6:recorded_speed
> >>>> 0.0 ;
> >>>> untitled-ontology-6:sensorLocatedInInfrastructure
> >>>> true ;
> >>>> untitled-ontology-6:sensorLocatedInVehicle
> >>>> false ;
> >>>> untitled-ontology-6:sensor_id 11 .
> >>>>
> >>>> You can, see both now have the recorded_speed value.
> >>>>
> >>>>
> >>>>> And I explained that using Lorenz's example syntax is something that
> I
> >>>> have
> >>>>> already tried before asking on the list and still the update to the
> owl
> >>>>> file does not take place. I mentioned that in my previous email.
> >>>>> I think the 2000+ lines u r mentioning are the full ontology file. I
> >>>>> mentioned that the file called ont.owl is the full one in case
> needed,
> >>>> but
> >>>>> I have already provided a short version called Yarab.owl .. Doubt
> that
> >>>>> Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles,
> >> two
> >>>>> roads instances and a couple of properties ..and it has lots of white
> >>>> lines
> >>>>> to separate the code to blocks for readability purposes. Which file
> >> did u
> >>>>> look at? I think u looked at the one I had described to be the full
> >>>>> ontology.
> >>>>>
> >>>>> On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
> >>>>>
> >>>>>> " cv:Vehicle_Road ?r ;"+
> >>>>>> Bad syntax. Replace ";" by "."
> >>>>>>
> >>>>>> Lorenz showed you the correct syntax.
> >>>>>>
> >>>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
> >>>>>> Print the query out and see what it looks like. Hence the earlier
> >>>>>> suggestion you put newlines in the query.
> >>>>>>
> >>>>>> Andy
> >>>>>>
> >>>>>> ~2800 lines is not a minimal example.
> >>>>>>
> >>>>>> On 09/06/17 15:53, Aya Hamdy wrote:
> >>>>>>
> >>>>>>> When I do not use the subselect and write the query this way:
> >>>>>>>
> >>>>>>> String queryString1 =
> >>>>>>> "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#
> >>>>>>>> "+
> >>>>>>> "INSERT {"+
> >>>>>>> " ?ass cv:recorded_speed ?avg"+
> >>>>>>> "}"+
> >>>>>>> "WHERE {"+
> >>>>>>> "SELECT (AVG(?speed) AS ?avg) {"+
> >>>>>>> "?v cv:vehicleSpeed ?speed;"+
> >>>>>>> " cv:Vehicle_Road ?r ;"+
> >>>>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> "}"+ "GROUP BY ?r ?ass"+
> >>>>>>> "}";
> >>>>>>>
> >>>>>>> The code generates the error below when it tries to execute the
> >> update
> >>>>>>> action:
> >>>>>>> Exception in thread "main" org.apache.jena.query.QueryPar
> >> seException:
> >>>>>>> Encountered " <VAR1> "?r "" at line 1, column 299.
> >>>>>>> Was expecting one of:
> >>>>>>> "values" ...
> >>>>>>> "graph" ...
> >>>>>>> "optional" ...
> >>>>>>> "minus" ...
> >>>>>>> "bind" ...
> >>>>>>> "service" ...
> >>>>>>> "filter" ...
> >>>>>>> "{" ...
> >>>>>>> "}" ...
> >>>>>>> ";" ...
> >>>>>>> "," ...
> >>>>>>> "." ...
> >>>>>>>
> >>>>>>> When I researched these options under "Was expecting one of:", I
> did
> >>>> not
> >>>>>>> find one of those options that would fit my query.
> >>>>>>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to
> >>>> ensure
> >>>>>>> that the sensor is attached to the road on which the car is on.
> >>>>>>>
> >>>>>>> I group by ?r to try to ensure that the grouping is per road as
> well.
> >>>> But
> >>>>>>> I
> >>>>>>> think you have a point, and I should group by the sensor as well.
> >>>>>>>
> >>>>>>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a
> full
> >>>> stop
> >>>>>>> instead of a full stop the error goes away, but still, nothing
> >> happens
> >>>> in
> >>>>>>> the owl file. Meaning, the new tuple is not added either. (I am a
> bit
> >>>>>>> confused as to when to put a ";" and when to put a "." I believe,
> as
> >>>> far
> >>>>>>> as
> >>>>>>> my understanding goes, when I put a "." in the end of the
> >>>>>>> " cv:Vehicle_Road ?r " the error goes away because the last line
> >>>> "?ass
> >>>>>>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first
> place.
> >>>>>>> could
> >>>>>>> you confirm or negate that?)
> >>>>>>>
> >>>>>>> Your help is truly much appreciated.
> >>>>>>>
> >>>>>>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
> >>>>>>> buehmann@informatik.uni-leipzig.de> wrote:
> >>>>>>>
> >>>>>>> There was some formatting issue in my previous mail.
> >>>>>>>> What I was wondering the need for grouping by ?r instead of ?ass.
> >>>>>>>>
> >>>>>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>>>>>> PREFIX cv:
> >>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> >>>>>>>> ed-ontology-6#
> >>>>>>>>
> >>>>>>>> INSERT {
> >>>>>>>> ?ass cv:recorded_speed ?avg .
> >>>>>>>> }
> >>>>>>>> WHERE
> >>>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>>>>>> WHERE
> >>>>>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>>>>> cv:Vehicle_Road ?r .
> >>>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>>>>>> }
> >>>>>>>> GROUP BY ?r ?ass
> >>>>>>>> }
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
> >>>>>>>>
> >>>>>>>>> That is your query:
> >>>>>>>>>
> >>>>>>>>> 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#>
> >>>>>>>>
> >>>>>>>>> INSERT {
> >>>>>>>>> ?ass cv:recorded_speed ?avg .
> >>>>>>>>> }
> >>>>>>>>> WHERE
> >>>>>>>>> { SELECT (AVG(?speed) AS ?avg)
> >>>>>>>>> WHERE
> >>>>>>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>>>>>> cv:Vehicle_Road ?r
> >>>>>>>>> { SELECT ?r
> >>>>>>>>> WHERE
> >>>>>>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
> >>>>>>>>> }
> >>>>>>>>> }
> >>>>>>>>> GROUP BY ?r
> >>>>>>>>> }
> >>>>>>>>>
> >>>>>>>>> The problem is that you use for what ever reason a sub-SELECT to
> >> get
> >>>> the
> >>>>>>>>> ?ass value. But this value is not propagated to the outer query,
> >>>> thus,
> >>>>>>>>> it's not bound to the INSERT part.
> >>>>>>>>>
> >>>>>>>>> Why not do it like here (note, I dPREFIX rdf:
> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>>>>>>> PREFIX cv:
> >>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>>>>>>>
> >>>>>>>> untitled-ontology-6#>
> >>>>>>>>
> >>>>>>>>> INSERT {
> >>>>>>>>> ?ass cv:recorded_speed ?avg .
> >>>>>>>>> }
> >>>>>>>>> WHERE
> >>>>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>>>>>>> WHERE
> >>>>>>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>>>>>> cv:Vehicle_Road ?r .
> >>>>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>>>>>>> }
> >>>>>>>>> GROUP BY ?r ?ass
> >>>>>>>>> }on't know why you group by ?r instead of ?ass, thus, added
> >> both):
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
> >>>>>>>>>
> >>>>>>>>>> Didn't know attachments are not allowed.
> >>>>>>>>>> This is a gist of the three files.
> >>>>>>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808
> >> dbf85d9
> >>>>>>>>>> The code files are minimalist as you can see on the gist. Only
> the
> >>>>>>>>>>
> >>>>>>>>> query is
> >>>>>>>>> included and everything else is removed. I wanted to attach them
> as
> >>>>>>>>> files
> >>>>>>>>> to avoid clutter in the email. I believe things are more
> organized
> >>>> this
> >>>>>>>>> way.
> >>>>>>>>>> The problem is in b.java file. The c.java file is just to prove
> >> that
> >>>>>>>>>> the
> >>>>>>>>>> individual parts of the query work together. And the OWL file is
> >> the
> >>>>>>>>>> one
> >>>>>>>>>> generated by Protege. It has no problems, but I have removed
> >>>> anything
> >>>>>>>>> that
> >>>>>>>>> is not needed for this specific query.
> >>>>>>>>>> I have also attached a file called "ont.owl (full)" which has
> the
> >>>> full
> >>>>>>>>>> ontology in case it is needed (which I think it is not needed,
> but
> >>>> just
> >>>>>>>>> in
> >>>>>>>>> case I misunderstand).
> >>>>>>>>>> Regards,
> >>>>>>>>>>
> >>>>>>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org>
> >>>> wrote:
> >>>>>>>>>> Attachments don't get through to this list.
> >>>>>>>>>>> Put them in a pastebin or guithub gist.
> >>>>>>>>>>>
> >>>>>>>>>>> However, if they are so large that inlining email in plain text
> >> is
> >>>>>>>>>>> impractical, than it suggests they are not minimal.
> >>>>>>>>>>>
> >>>>>>>>>>> Andy
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> You forgot the attachments...
> >>>>>>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
> >>>>>>>>>>>>
> >>>>>>>>>>>> Attached is a file of my code and my ontology which I have
> >>>> imported
> >>>>>>>>>>>> on
> >>>>>>>>> Eclipse.
> >>>>>>>>>>>>> I have finally fixed the null values issue. I am not sure if
> I
> >>>>>>>>>>>>> understood the cause of the nulls correctly. However, it got
> >>>> fixed
> >>>>>>>>>>>>> when I used a different way of making the ResultSet as shown
> >>>> below:
> >>>>>>>>>>>>> Query query = QueryFactory.create(queryString1);
> >>>>>>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
> >>>>>>>>>>>>> ontologyModel);
> >>>>>>>>>>>>> ResultSet results=qexec.execSelect();
> >>>>>>>>>>>>> ResultSetFormatter.out(System.out, results, query);
> >>>>>>>>>>>>> qexec.close();
> >>>>>>>>>>>>> I am including this bit of code here in case this helps
> someone
> >>>> else
> >>>>>>>>>>>>> in the future cause I could not find it easily. It can be
> found
> >>>> in
> >>>>>>>>>>>>> context in the attached c.java file.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> However, the original bigger problem still persists. The
> insert
> >>>>>>>>>>>>>
> >>>>>>>>>>>> SPARQL
> >>>>>>>>> query still does not result in inserting the new desired subject
> >>>>>>>>>>>>> predicate object triple. No errors are generated which is I
> >>>> suppose
> >>>>>>>>>>>>> a
> >>>>>>>>>>>>> good thing, but when I print the ontology after running the
> >>>> query, I
> >>>>>>>>>>>>> can see that the new triples are not added.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Attached is the owl file and the java file (b.java). I have
> >> added
> >>>>>>>>>>>>> explanatory comments in the java file hoping to clarify what
> I
> >> am
> >>>>>>>>>>>>> trying to do here.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> Also, hoping to clarify matters a bit more, I have two
> average
> >>>> speed
> >>>>>>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two
> vehicles
> >>>>>>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1
> and
> >>>>>>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on
> >> Road1
> >>>>>>>>>>>>> with
> >>>>>>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
> >>>>>>>>>>>>> vehicleSpeed
> >>>>>>>>>>>>> of 50. Only one vehicle is modeled to be located on each road
> >> in
> >>>> an
> >>>>>>>>>>>>> attempt to simplify things for now.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> The goal is to calculate the average of speeds of all
> vehicles
> >> on
> >>>>>>>>>>>>> road1 and assign it as the value of the object property
> called
> >>>>>>>>>>>>> recorded_speed of the speed sensor attached to the road which
> >> the
> >>>>>>>>>>>>> vehicles are on. Consequently, based on my modeling, after
> >>>> running
> >>>>>>>>>>>>> the query, speedSensor1 should have recorded_speed of 0
> (since
> >>>> only
> >>>>>>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and
> >>>> vehicle1
> >>>>>>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed
> of
> >> 50
> >>>>>>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is
> >>>> attached
> >>>>>>>>>>>> and
> >>>>>>>>> vehicle2 has speed of 50).
> >>>>>>>>>>>>> Also, attached is another java file (c.java) that has the
> >>>> results of
> >>>>>>>>>>>>> me breaking down the big query in b.java.
> >>>>>>>>>>>>> My suspicion is that the part where I am trying to invoke the
> >>>> insert
> >>>>>>>>>>>>> query is not working, but the way I built is based on
> >>>> StackOverflow
> >>>>>>>>>>>>> and it was supposedly working fine, so I am not sure what I
> am
> >>>>>>>>>>>>>
> >>>>>>>>>>>> missing.
> >>>>>>>>>>>>> Hope this gives you a picture of what is going on and hope
> you
> >>>> can
> >>>>>>>>>>>>> help me understand why I cannot get the query to update the
> >>>>>>>>>>>>> ontology.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
> >>>>>>>>>>>>> <buehmann@informatik.uni-leipzig.de
> >>>>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> If results are bound it can't be a null value. Please
> >> show
> >>>>>>>>>>>>> your
> >>>>>>>>>>>>> updated
> >>>>>>>>>>>>> code.
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
> >>>>>>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is
> >> nit
> >>>>>>>>>>>>> the
> >>>>>>>>>>>>> cause of the
> >>>>>>>>>>>>> > null. When I fixed it, the results of even the
> simplest
> >>>>>>>>>>>>>
> >>>>>>>>>>>> queries
> >>>>>>>>> are still
> >>>>>>>>>>>>> > nulls.
> >>>>>>>>>>>>> >
> >>>>>>>>>>>>> > The code is not generating errors though, it is not
> >>>>>>>>>>>>> generating
> >>>>>>>>>>>>> the proper
> >>>>>>>>>>>>> > results ...
> >>>>>>>>>>>>> >
> >>>>>>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
> >>>>>>>>>>>>>
> >>>>>>>>>>>> andy@apache.org
> >>>>>>>>> <ma...@apache.org>> wrote:
> >>>>>>>>>>>>> >
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >>> Ok. That sounds reasonable so I will work on
> breaking
> >>>> down
> >>>>>>>>>>>> my
> >>>>>>>>> chain of
> >>>>>>>>>>>>> >>> thought into smaller pieces. Thank you so much.
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> I saw an example online where the query syntax is
> >>>> written
> >>>>>>>>>>>> as a
> >>>>>>>>> string on
> >>>>>>>>>>>>> >>> Jena. so my query now looks like this:
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >> Use
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >> String.join("\n"
> >>>>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> >>>>>>>>>>>>>
> >>>>>>>>>>>> 02/22-rdf-syntax-ns#
> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> >>>>>>>>>>>>>
> >>>>>>>>>>>> 02/22-rdf-syntax-ns#
> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>>>>>>>>>> >> , "INSERT {",
> >>>>>>>>>>>>> >> ...
> >>>>>>>>>>>>> >> , "}"
> >>>>>>>>>>>>> >> );
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >> then you will have newlines in the string and parser
> >>>> errors
> >>>>>>>>>>>>> will have
> >>>>>>>>>>>>> >> line+column numbers that are useful.
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >> Andy
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >>
> >>>>>>>>>>>>> >>> String queryString=
> >>>>>>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/
> >>>> 02/22-rdf-syntax-ns#
> >>>>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>>>>>>>>>> >>> "PREFIX cv:<
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>> untitl
> >>>>>>>>>>>>> ed-ontology-6#
> >>>>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>> untit
> >>>>>>>>>>>>> led-ontology-6#>
> >>>>>>>>>>>>> >>>> "+
> >>>>>>>>>>>>> >>> "insert {"+
> >>>>>>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
> >>>>>>>>>>>>> >>> "}"+
> >>>>>>>>>>>>> >>> "WHERE {"+
> >>>>>>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
> >>>>>>>>>>>>> >>> "where{"+
> >>>>>>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
> >>>>>>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
> >>>>>>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
> >>>>>>>>>>>>> >>> "{"+
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> "SELECT ?r"+
> >>>>>>>>>>>>> >>> "where{"+
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> >>>>>>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
> >>>>>>>>>>>>> >>> "}"+
> >>>>>>>>>>>>> >>> "}"+
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
> >>>>>>>>>>>>> >>> "}";
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> Then, also based on my research, I feed the query
> >>>> string
> >>>>>>>>>>>> into
> >>>>>>>>> the parser
> >>>>>>>>>>>>> >>> and output the model.
> >>>>>>>>>>>>> >>> UpdateAction.parseExecute( queryString,
> ontologyModel
> >>>> );
> >>>>>>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
> >>>>>>>>>>>>> >>> I encountered many errors but managed to get rid of
> >>>> them
> >>>>>>>>>>>> all.
> >>>>>>>>> However,
> >>>>>>>>>>>>> >>> based on the output, nothing has changed.
> >>>> speedSensor1
> >>>>>>>>>>>>> and
> >>>>>>>>>>>>> speedSensor2
> >>>>>>>>>>>>> >>> do
> >>>>>>>>>>>>> >>> not have the recorded_speed property added.
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> Of course, I tried debugging, but I could not get
> any
> >>>>>>>>>>>>> understanding of the
> >>>>>>>>>>>>> >>> problem.
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> >>> 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#
> >>>>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>>>>>>>>>> >>> "PREFIX cv:<
> >>>>>>>>>>>>> >>>
> >>>>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>> untitl
> >>>>>>>>>>>>> ed-ontology-6#
> >>>>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>> untit
> >>>>>>>>>>>>> led-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");
> >>>>>>>>> >>> 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 <
> >>>>>>>>>>>>>
> >>>>>>>>>>>> andy@apache.org
> >>>>>>>>> <ma...@apache.org>> 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" <
> >>>>>>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
> >>>>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
> >>>>>>>>>>>>> <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/
> >>>>>>>>>>>>> <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/
> >>>>>>>>>>>>> <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/
> >>>>>>>>>>>>> <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
> >>>>>>>>>>>>> <andy@apache.org <ma...@apache.org>>
> >>>>>>>>>>>>> >>>>>>> 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.
> >>>>>>>>>>>>> >>>>>>>>
> >>>>>>>>>>>>> >>>>>>>>
> >>>>>>>>>>>>> >>>>>>>>
> >>>>>>>>>>>>> >>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>>>>>>>>>>>
> >>>> --
> >>>> Lorenz Bühmann
> >>>> AKSW group, University of Leipzig
> >>>> Group: http://aksw.org - semantic web research center
> >>>>
> >>>>
> >> --
> >> Lorenz Bühmann
> >> AKSW group, University of Leipzig
> >> Group: http://aksw.org - semantic web research center
> >>
> >>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
Please upload your update code for b.java
And then try to write to another path instead of the same file, just to
make sure that you really write to disk.
> - I had included the writing to the file in b.java, but I must have dropped
> it by mistake when putting the files as a gist, apologies.
>
> - I am not surprised with the output. Don't know why you got that
> impression. You are right, it is my code so I know what I have written and
> I have made the output TTL for a reason for sure. It is neater to read in
> the console as a personal preference.
>
> -I used the system.write with the query you provided, I am using your
> query for my trials with the file now. Note that your query is different
> from the syntax I had tried before the sub-select by removing one of the
> where clauses. I was treating the query too much like SQL syntax it seems,
> so thx again for that.
>
> - I used writeall because in the original file, not the summarized
> b.java one there are other inferences made, so it would have its uses.
> Thanks for the update on the write syntax, I removed the xmlbase argument,
> but still nothing.
>
> Finally, the file is not affected by the write although you tried it and it
> worked with you, and we are working on the same files with the same
> contents. so that is a whole other level of hopelessness. If it worked for
> you then it should have worked with me.
>
> Anyway thanks for your efforts, it was much appreciated.
>
>
>
>
>
> On Jun 11, 2017 10:26 AM, "Lorenz B." <bu...@informatik.uni-leipzig.de>
> wrote:
>
>>
>>> Yes, I see. I don't get why it does not add them when I run it...
>>>
>>> Do you see the new tuples when you print or when you open the file
>> ontology
>>> file? Cause with me, when I used your syntax, the new triples show in the
>>> print but when I open the ontology file on Eclipse which I am running the
>>> query on, I find that the triples are not added.
>> As I said, I just used your code in b.java, thus, it's just printed to
>> System.out .
>>> And I have noticed that what you are showing me is in turtle format. The
>>> ontology file is in XML format...
>> The same, your code prints to System.out as "TTL" which is Turtle - I'm
>> wondering why you're surprised, it's your code.
>>> Isn't the result of the insertion
>>> function written to the ontology file?
>> No, the triples in the ontology are loaded into memory. That means you
>> have to write the model back to disk
>>> Note that I have previously added
>>> lines to my code to try and rewrite the ontology after the query, but the
>>> file is still not affected:
>> But you did this without the query that I provided?
>>> FileOutputStream output = null;
>>>
>>> try {
>>> output = new FileOutputStream( "yarab.owl ");
>>> } catch(Exception e) {}
>>>
>>> ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
>> Do you really want to use writeAll()? This also writes inferred and
>> imported triples to disk. Otherwise, use write()
>> And the argument "xmlbase" is for sure wrong. It expects the base URI of
>> the XML (or Turtle) document if exist - you can also use NULL or simply
>> use write(output, "RDF/XML-ABBREV")
>>
>>
>>
>> To sum up, writing to disk works for me as well. I don't see why this
>> should not work if the INSERT already modified the model.
>>
>>>
>>> PrintStream p= new PrintStream("yarab.owl");
>>> ontologyModel.writeAll(p, "RDF/XML", null);
>>> p.close();
>>>
>>>
>>>
>>>
>>>
>>> On Sat, Jun 10, 2017 at 8:32 AM, Lorenz B. <
>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>
>>>> That can't be. I tried your example b.java with my query
>>>>
>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>> PREFIX cv:
>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>> ed-ontology-6#
>>>> INSERT {
>>>> ?ass cv:recorded_speed ?avg .
>>>> }
>>>> WHERE
>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>> WHERE
>>>> { ?v cv:vehicleSpeed ?speed ;
>>>> cv:Vehicle_Road ?r .
>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>> }
>>>> GROUP BY ?ass
>>>> }
>>>>
>>>> Before execution the model contains 67 triples, afterwards 69. And the
>>>> added triples are as follows:
>>>>
>>>>
>>>> For SpeedSensor2:
>>>>
>>>> untitled-ontology-6:SpeedSensor2
>>>> a untitled-ontology-6:Speed_Sensor ,
>>>> untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
>>>> owl:NamedIndividual ;
>>>> untitled-ontology-6:avgSpeedSensor_Infrastructue
>>>> untitled-ontology-6:Road2 ;
>>>> untitled-ontology-6:recorded_speed
>>>> 50.0 ;
>>>> untitled-ontology-6:sensorLocatedInInfrastructure
>>>> true ;
>>>> untitled-ontology-6:sensorLocatedInVehicle
>>>> false .
>>>>
>>>> for SpeedSensor1:
>>>>
>>>> untitled-ontology-6:SpeedSensor1
>>>> a untitled-ontology-6:Speed_Sensor
>>>> , untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
>>>> owl:NamedIndividual ;
>>>> untitled-ontology-6:avgSpeedSensor_Infrastructue
>>>> untitled-ontology-6:Road1 ;
>>>> untitled-ontology-6:recorded_speed
>>>> 0.0 ;
>>>> untitled-ontology-6:sensorLocatedInInfrastructure
>>>> true ;
>>>> untitled-ontology-6:sensorLocatedInVehicle
>>>> false ;
>>>> untitled-ontology-6:sensor_id 11 .
>>>>
>>>> You can, see both now have the recorded_speed value.
>>>>
>>>>
>>>>> And I explained that using Lorenz's example syntax is something that I
>>>> have
>>>>> already tried before asking on the list and still the update to the owl
>>>>> file does not take place. I mentioned that in my previous email.
>>>>> I think the 2000+ lines u r mentioning are the full ontology file. I
>>>>> mentioned that the file called ont.owl is the full one in case needed,
>>>> but
>>>>> I have already provided a short version called Yarab.owl .. Doubt that
>>>>> Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles,
>> two
>>>>> roads instances and a couple of properties ..and it has lots of white
>>>> lines
>>>>> to separate the code to blocks for readability purposes. Which file
>> did u
>>>>> look at? I think u looked at the one I had described to be the full
>>>>> ontology.
>>>>>
>>>>> On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
>>>>>
>>>>>> " cv:Vehicle_Road ?r ;"+
>>>>>> Bad syntax. Replace ";" by "."
>>>>>>
>>>>>> Lorenz showed you the correct syntax.
>>>>>>
>>>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>>>>> Print the query out and see what it looks like. Hence the earlier
>>>>>> suggestion you put newlines in the query.
>>>>>>
>>>>>> Andy
>>>>>>
>>>>>> ~2800 lines is not a minimal example.
>>>>>>
>>>>>> On 09/06/17 15:53, Aya Hamdy wrote:
>>>>>>
>>>>>>> When I do not use the subselect and write the query this way:
>>>>>>>
>>>>>>> String queryString1 =
>>>>>>> "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#
>>>>>>>> "+
>>>>>>> "INSERT {"+
>>>>>>> " ?ass cv:recorded_speed ?avg"+
>>>>>>> "}"+
>>>>>>> "WHERE {"+
>>>>>>> "SELECT (AVG(?speed) AS ?avg) {"+
>>>>>>> "?v cv:vehicleSpeed ?speed;"+
>>>>>>> " cv:Vehicle_Road ?r ;"+
>>>>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> "}"+ "GROUP BY ?r ?ass"+
>>>>>>> "}";
>>>>>>>
>>>>>>> The code generates the error below when it tries to execute the
>> update
>>>>>>> action:
>>>>>>> Exception in thread "main" org.apache.jena.query.QueryPar
>> seException:
>>>>>>> Encountered " <VAR1> "?r "" at line 1, column 299.
>>>>>>> Was expecting one of:
>>>>>>> "values" ...
>>>>>>> "graph" ...
>>>>>>> "optional" ...
>>>>>>> "minus" ...
>>>>>>> "bind" ...
>>>>>>> "service" ...
>>>>>>> "filter" ...
>>>>>>> "{" ...
>>>>>>> "}" ...
>>>>>>> ";" ...
>>>>>>> "," ...
>>>>>>> "." ...
>>>>>>>
>>>>>>> When I researched these options under "Was expecting one of:", I did
>>>> not
>>>>>>> find one of those options that would fit my query.
>>>>>>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to
>>>> ensure
>>>>>>> that the sensor is attached to the road on which the car is on.
>>>>>>>
>>>>>>> I group by ?r to try to ensure that the grouping is per road as well.
>>>> But
>>>>>>> I
>>>>>>> think you have a point, and I should group by the sensor as well.
>>>>>>>
>>>>>>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full
>>>> stop
>>>>>>> instead of a full stop the error goes away, but still, nothing
>> happens
>>>> in
>>>>>>> the owl file. Meaning, the new tuple is not added either. (I am a bit
>>>>>>> confused as to when to put a ";" and when to put a "." I believe, as
>>>> far
>>>>>>> as
>>>>>>> my understanding goes, when I put a "." in the end of the
>>>>>>> " cv:Vehicle_Road ?r " the error goes away because the last line
>>>> "?ass
>>>>>>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
>>>>>>> could
>>>>>>> you confirm or negate that?)
>>>>>>>
>>>>>>> Your help is truly much appreciated.
>>>>>>>
>>>>>>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
>>>>>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>>>>>
>>>>>>> There was some formatting issue in my previous mail.
>>>>>>>> What I was wondering the need for grouping by ?r instead of ?ass.
>>>>>>>>
>>>>>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>>>>>> PREFIX cv:
>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>>> ed-ontology-6#
>>>>>>>>
>>>>>>>> INSERT {
>>>>>>>> ?ass cv:recorded_speed ?avg .
>>>>>>>> }
>>>>>>>> WHERE
>>>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>>>>>> WHERE
>>>>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>>>>> cv:Vehicle_Road ?r .
>>>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>>>>>> }
>>>>>>>> GROUP BY ?r ?ass
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
>>>>>>>>
>>>>>>>>> That is your query:
>>>>>>>>>
>>>>>>>>> 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#>
>>>>>>>>
>>>>>>>>> INSERT {
>>>>>>>>> ?ass cv:recorded_speed ?avg .
>>>>>>>>> }
>>>>>>>>> WHERE
>>>>>>>>> { SELECT (AVG(?speed) AS ?avg)
>>>>>>>>> WHERE
>>>>>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>>>>>> cv:Vehicle_Road ?r
>>>>>>>>> { SELECT ?r
>>>>>>>>> WHERE
>>>>>>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>> GROUP BY ?r
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> The problem is that you use for what ever reason a sub-SELECT to
>> get
>>>> the
>>>>>>>>> ?ass value. But this value is not propagated to the outer query,
>>>> thus,
>>>>>>>>> it's not bound to the INSERT part.
>>>>>>>>>
>>>>>>>>> Why not do it like here (note, I dPREFIX rdf:
>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>>>>>>> PREFIX cv:
>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>>>>>
>>>>>>>> untitled-ontology-6#>
>>>>>>>>
>>>>>>>>> INSERT {
>>>>>>>>> ?ass cv:recorded_speed ?avg .
>>>>>>>>> }
>>>>>>>>> WHERE
>>>>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>>>>>>> WHERE
>>>>>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>>>>>> cv:Vehicle_Road ?r .
>>>>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>>>>>>> }
>>>>>>>>> GROUP BY ?r ?ass
>>>>>>>>> }on't know why you group by ?r instead of ?ass, thus, added
>> both):
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
>>>>>>>>>
>>>>>>>>>> Didn't know attachments are not allowed.
>>>>>>>>>> This is a gist of the three files.
>>>>>>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808
>> dbf85d9
>>>>>>>>>> The code files are minimalist as you can see on the gist. Only the
>>>>>>>>>>
>>>>>>>>> query is
>>>>>>>>> included and everything else is removed. I wanted to attach them as
>>>>>>>>> files
>>>>>>>>> to avoid clutter in the email. I believe things are more organized
>>>> this
>>>>>>>>> way.
>>>>>>>>>> The problem is in b.java file. The c.java file is just to prove
>> that
>>>>>>>>>> the
>>>>>>>>>> individual parts of the query work together. And the OWL file is
>> the
>>>>>>>>>> one
>>>>>>>>>> generated by Protege. It has no problems, but I have removed
>>>> anything
>>>>>>>>> that
>>>>>>>>> is not needed for this specific query.
>>>>>>>>>> I have also attached a file called "ont.owl (full)" which has the
>>>> full
>>>>>>>>>> ontology in case it is needed (which I think it is not needed, but
>>>> just
>>>>>>>>> in
>>>>>>>>> case I misunderstand).
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org>
>>>> wrote:
>>>>>>>>>> Attachments don't get through to this list.
>>>>>>>>>>> Put them in a pastebin or guithub gist.
>>>>>>>>>>>
>>>>>>>>>>> However, if they are so large that inlining email in plain text
>> is
>>>>>>>>>>> impractical, than it suggests they are not minimal.
>>>>>>>>>>>
>>>>>>>>>>> Andy
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>>>>>>>>>>
>>>>>>>>>>> You forgot the attachments...
>>>>>>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Attached is a file of my code and my ontology which I have
>>>> imported
>>>>>>>>>>>> on
>>>>>>>>> Eclipse.
>>>>>>>>>>>>> I have finally fixed the null values issue. I am not sure if I
>>>>>>>>>>>>> understood the cause of the nulls correctly. However, it got
>>>> fixed
>>>>>>>>>>>>> when I used a different way of making the ResultSet as shown
>>>> below:
>>>>>>>>>>>>> Query query = QueryFactory.create(queryString1);
>>>>>>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>>>>>>>>>>> ontologyModel);
>>>>>>>>>>>>> ResultSet results=qexec.execSelect();
>>>>>>>>>>>>> ResultSetFormatter.out(System.out, results, query);
>>>>>>>>>>>>> qexec.close();
>>>>>>>>>>>>> I am including this bit of code here in case this helps someone
>>>> else
>>>>>>>>>>>>> in the future cause I could not find it easily. It can be found
>>>> in
>>>>>>>>>>>>> context in the attached c.java file.
>>>>>>>>>>>>>
>>>>>>>>>>>>> However, the original bigger problem still persists. The insert
>>>>>>>>>>>>>
>>>>>>>>>>>> SPARQL
>>>>>>>>> query still does not result in inserting the new desired subject
>>>>>>>>>>>>> predicate object triple. No errors are generated which is I
>>>> suppose
>>>>>>>>>>>>> a
>>>>>>>>>>>>> good thing, but when I print the ontology after running the
>>>> query, I
>>>>>>>>>>>>> can see that the new triples are not added.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Attached is the owl file and the java file (b.java). I have
>> added
>>>>>>>>>>>>> explanatory comments in the java file hoping to clarify what I
>> am
>>>>>>>>>>>>> trying to do here.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Also, hoping to clarify matters a bit more, I have two average
>>>> speed
>>>>>>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>>>>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>>>>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on
>> Road1
>>>>>>>>>>>>> with
>>>>>>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
>>>>>>>>>>>>> vehicleSpeed
>>>>>>>>>>>>> of 50. Only one vehicle is modeled to be located on each road
>> in
>>>> an
>>>>>>>>>>>>> attempt to simplify things for now.
>>>>>>>>>>>>>
>>>>>>>>>>>>> The goal is to calculate the average of speeds of all vehicles
>> on
>>>>>>>>>>>>> road1 and assign it as the value of the object property called
>>>>>>>>>>>>> recorded_speed of the speed sensor attached to the road which
>> the
>>>>>>>>>>>>> vehicles are on. Consequently, based on my modeling, after
>>>> running
>>>>>>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since
>>>> only
>>>>>>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and
>>>> vehicle1
>>>>>>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of
>> 50
>>>>>>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is
>>>> attached
>>>>>>>>>>>> and
>>>>>>>>> vehicle2 has speed of 50).
>>>>>>>>>>>>> Also, attached is another java file (c.java) that has the
>>>> results of
>>>>>>>>>>>>> me breaking down the big query in b.java.
>>>>>>>>>>>>> My suspicion is that the part where I am trying to invoke the
>>>> insert
>>>>>>>>>>>>> query is not working, but the way I built is based on
>>>> StackOverflow
>>>>>>>>>>>>> and it was supposedly working fine, so I am not sure what I am
>>>>>>>>>>>>>
>>>>>>>>>>>> missing.
>>>>>>>>>>>>> Hope this gives you a picture of what is going on and hope you
>>>> can
>>>>>>>>>>>>> help me understand why I cannot get the query to update the
>>>>>>>>>>>>> ontology.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>>>>>>>>>>> <buehmann@informatik.uni-leipzig.de
>>>>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> If results are bound it can't be a null value. Please
>> show
>>>>>>>>>>>>> your
>>>>>>>>>>>>> updated
>>>>>>>>>>>>> code.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>>>>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is
>> nit
>>>>>>>>>>>>> the
>>>>>>>>>>>>> cause of the
>>>>>>>>>>>>> > null. When I fixed it, the results of even the simplest
>>>>>>>>>>>>>
>>>>>>>>>>>> queries
>>>>>>>>> are still
>>>>>>>>>>>>> > nulls.
>>>>>>>>>>>>> >
>>>>>>>>>>>>> > The code is not generating errors though, it is not
>>>>>>>>>>>>> generating
>>>>>>>>>>>>> the proper
>>>>>>>>>>>>> > results ...
>>>>>>>>>>>>> >
>>>>>>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
>>>>>>>>>>>>>
>>>>>>>>>>>> andy@apache.org
>>>>>>>>> <ma...@apache.org>> wrote:
>>>>>>>>>>>>> >
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking
>>>> down
>>>>>>>>>>>> my
>>>>>>>>> chain of
>>>>>>>>>>>>> >>> thought into smaller pieces. Thank you so much.
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> I saw an example online where the query syntax is
>>>> written
>>>>>>>>>>>> as a
>>>>>>>>> string on
>>>>>>>>>>>>> >>> Jena. so my query now looks like this:
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >> Use
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >> String.join("\n"
>>>>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>>>>>>
>>>>>>>>>>>> 02/22-rdf-syntax-ns#
>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>>>>>>
>>>>>>>>>>>> 02/22-rdf-syntax-ns#
>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>>>>>>> >> , "INSERT {",
>>>>>>>>>>>>> >> ...
>>>>>>>>>>>>> >> , "}"
>>>>>>>>>>>>> >> );
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >> then you will have newlines in the string and parser
>>>> errors
>>>>>>>>>>>>> will have
>>>>>>>>>>>>> >> line+column numbers that are useful.
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >> Andy
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >>
>>>>>>>>>>>>> >>> String queryString=
>>>>>>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/
>>>> 02/22-rdf-syntax-ns#
>>>>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>>>>>>> >>> "PREFIX cv:<
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>> untitl
>>>>>>>>>>>>> ed-ontology-6#
>>>>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>> untit
>>>>>>>>>>>>> led-ontology-6#>
>>>>>>>>>>>>> >>>> "+
>>>>>>>>>>>>> >>> "insert {"+
>>>>>>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>>>>>>>>>>> >>> "}"+
>>>>>>>>>>>>> >>> "WHERE {"+
>>>>>>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>>>>>>>>>>> >>> "where{"+
>>>>>>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>>>>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>>>>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
>>>>>>>>>>>>> >>> "{"+
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> "SELECT ?r"+
>>>>>>>>>>>>> >>> "where{"+
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>>>>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>>>>>>>>>>> >>> "}"+
>>>>>>>>>>>>> >>> "}"+
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>>>>>>>>>>> >>> "}";
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> Then, also based on my research, I feed the query
>>>> string
>>>>>>>>>>>> into
>>>>>>>>> the parser
>>>>>>>>>>>>> >>> and output the model.
>>>>>>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel
>>>> );
>>>>>>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>>>>>>>>>>> >>> I encountered many errors but managed to get rid of
>>>> them
>>>>>>>>>>>> all.
>>>>>>>>> However,
>>>>>>>>>>>>> >>> based on the output, nothing has changed.
>>>> speedSensor1
>>>>>>>>>>>>> and
>>>>>>>>>>>>> speedSensor2
>>>>>>>>>>>>> >>> do
>>>>>>>>>>>>> >>> not have the recorded_speed property added.
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> Of course, I tried debugging, but I could not get any
>>>>>>>>>>>>> understanding of the
>>>>>>>>>>>>> >>> problem.
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> >>> 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#
>>>>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>>>>>>> >>> "PREFIX cv:<
>>>>>>>>>>>>> >>>
>>>>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>> untitl
>>>>>>>>>>>>> ed-ontology-6#
>>>>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>> untit
>>>>>>>>>>>>> led-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");
>>>>>>>>> >>> 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 <
>>>>>>>>>>>>>
>>>>>>>>>>>> andy@apache.org
>>>>>>>>> <ma...@apache.org>> 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" <
>>>>>>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>>>>>>>>>>> <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/
>>>>>>>>>>>>> <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/
>>>>>>>>>>>>> <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/
>>>>>>>>>>>>> <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
>>>>>>>>>>>>> <andy@apache.org <ma...@apache.org>>
>>>>>>>>>>>>> >>>>>>> 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.
>>>>>>>>>>>>> >>>>>>>>
>>>>>>>>>>>>> >>>>>>>>
>>>>>>>>>>>>> >>>>>>>>
>>>>>>>>>>>>> >>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>> --
>>>> Lorenz Bühmann
>>>> AKSW group, University of Leipzig
>>>> Group: http://aksw.org - semantic web research center
>>>>
>>>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
- I had included the writing to the file in b.java, but I must have dropped
it by mistake when putting the files as a gist, apologies.
- I am not surprised with the output. Don't know why you got that
impression. You are right, it is my code so I know what I have written and
I have made the output TTL for a reason for sure. It is neater to read in
the console as a personal preference.
-I used the system.write with the query you provided, I am using your
query for my trials with the file now. Note that your query is different
from the syntax I had tried before the sub-select by removing one of the
where clauses. I was treating the query too much like SQL syntax it seems,
so thx again for that.
- I used writeall because in the original file, not the summarized
b.java one there are other inferences made, so it would have its uses.
Thanks for the update on the write syntax, I removed the xmlbase argument,
but still nothing.
Finally, the file is not affected by the write although you tried it and it
worked with you, and we are working on the same files with the same
contents. so that is a whole other level of hopelessness. If it worked for
you then it should have worked with me.
Anyway thanks for your efforts, it was much appreciated.
On Jun 11, 2017 10:26 AM, "Lorenz B." <bu...@informatik.uni-leipzig.de>
wrote:
>
>
> > Yes, I see. I don't get why it does not add them when I run it...
> >
> > Do you see the new tuples when you print or when you open the file
> ontology
> > file? Cause with me, when I used your syntax, the new triples show in the
> > print but when I open the ontology file on Eclipse which I am running the
> > query on, I find that the triples are not added.
> As I said, I just used your code in b.java, thus, it's just printed to
> System.out .
> >
> > And I have noticed that what you are showing me is in turtle format. The
> > ontology file is in XML format...
> The same, your code prints to System.out as "TTL" which is Turtle - I'm
> wondering why you're surprised, it's your code.
> > Isn't the result of the insertion
> > function written to the ontology file?
> No, the triples in the ontology are loaded into memory. That means you
> have to write the model back to disk
> > Note that I have previously added
> > lines to my code to try and rewrite the ontology after the query, but the
> > file is still not affected:
> But you did this without the query that I provided?
> >
> > FileOutputStream output = null;
> >
> > try {
> > output = new FileOutputStream( "yarab.owl ");
> > } catch(Exception e) {}
> >
> > ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
> Do you really want to use writeAll()? This also writes inferred and
> imported triples to disk. Otherwise, use write()
> And the argument "xmlbase" is for sure wrong. It expects the base URI of
> the XML (or Turtle) document if exist - you can also use NULL or simply
> use write(output, "RDF/XML-ABBREV")
>
>
>
> To sum up, writing to disk works for me as well. I don't see why this
> should not work if the INSERT already modified the model.
>
> >
> >
> > PrintStream p= new PrintStream("yarab.owl");
> > ontologyModel.writeAll(p, "RDF/XML", null);
> > p.close();
> >
> >
> >
> >
> >
> > On Sat, Jun 10, 2017 at 8:32 AM, Lorenz B. <
> > buehmann@informatik.uni-leipzig.de> wrote:
> >
> >> That can't be. I tried your example b.java with my query
> >>
> >> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >> PREFIX cv:
> >> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> ed-ontology-6#
> >> INSERT {
> >> ?ass cv:recorded_speed ?avg .
> >> }
> >> WHERE
> >> { SELECT ?ass (AVG(?speed) AS ?avg)
> >> WHERE
> >> { ?v cv:vehicleSpeed ?speed ;
> >> cv:Vehicle_Road ?r .
> >> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >> }
> >> GROUP BY ?ass
> >> }
> >>
> >> Before execution the model contains 67 triples, afterwards 69. And the
> >> added triples are as follows:
> >>
> >>
> >> For SpeedSensor2:
> >>
> >> untitled-ontology-6:SpeedSensor2
> >> a untitled-ontology-6:Speed_Sensor ,
> >> untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
> >> owl:NamedIndividual ;
> >> untitled-ontology-6:avgSpeedSensor_Infrastructue
> >> untitled-ontology-6:Road2 ;
> >> untitled-ontology-6:recorded_speed
> >> 50.0 ;
> >> untitled-ontology-6:sensorLocatedInInfrastructure
> >> true ;
> >> untitled-ontology-6:sensorLocatedInVehicle
> >> false .
> >>
> >> for SpeedSensor1:
> >>
> >> untitled-ontology-6:SpeedSensor1
> >> a untitled-ontology-6:Speed_Sensor
> >> , untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
> >> owl:NamedIndividual ;
> >> untitled-ontology-6:avgSpeedSensor_Infrastructue
> >> untitled-ontology-6:Road1 ;
> >> untitled-ontology-6:recorded_speed
> >> 0.0 ;
> >> untitled-ontology-6:sensorLocatedInInfrastructure
> >> true ;
> >> untitled-ontology-6:sensorLocatedInVehicle
> >> false ;
> >> untitled-ontology-6:sensor_id 11 .
> >>
> >> You can, see both now have the recorded_speed value.
> >>
> >>
> >>> And I explained that using Lorenz's example syntax is something that I
> >> have
> >>> already tried before asking on the list and still the update to the owl
> >>> file does not take place. I mentioned that in my previous email.
> >>> I think the 2000+ lines u r mentioning are the full ontology file. I
> >>> mentioned that the file called ont.owl is the full one in case needed,
> >> but
> >>> I have already provided a short version called Yarab.owl .. Doubt that
> >>> Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles,
> two
> >>> roads instances and a couple of properties ..and it has lots of white
> >> lines
> >>> to separate the code to blocks for readability purposes. Which file
> did u
> >>> look at? I think u looked at the one I had described to be the full
> >>> ontology.
> >>>
> >>> On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
> >>>
> >>>> " cv:Vehicle_Road ?r ;"+
> >>>> Bad syntax. Replace ";" by "."
> >>>>
> >>>> Lorenz showed you the correct syntax.
> >>>>
> >>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
> >>>> Print the query out and see what it looks like. Hence the earlier
> >>>> suggestion you put newlines in the query.
> >>>>
> >>>> Andy
> >>>>
> >>>> ~2800 lines is not a minimal example.
> >>>>
> >>>> On 09/06/17 15:53, Aya Hamdy wrote:
> >>>>
> >>>>> When I do not use the subselect and write the query this way:
> >>>>>
> >>>>> String queryString1 =
> >>>>> "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#
> >>>>>> "+
> >>>>> "INSERT {"+
> >>>>> " ?ass cv:recorded_speed ?avg"+
> >>>>> "}"+
> >>>>> "WHERE {"+
> >>>>> "SELECT (AVG(?speed) AS ?avg) {"+
> >>>>> "?v cv:vehicleSpeed ?speed;"+
> >>>>> " cv:Vehicle_Road ?r ;"+
> >>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
> >>>>>
> >>>>>
> >>>>>
> >>>>> "}"+ "GROUP BY ?r ?ass"+
> >>>>> "}";
> >>>>>
> >>>>> The code generates the error below when it tries to execute the
> update
> >>>>> action:
> >>>>> Exception in thread "main" org.apache.jena.query.QueryPar
> seException:
> >>>>> Encountered " <VAR1> "?r "" at line 1, column 299.
> >>>>> Was expecting one of:
> >>>>> "values" ...
> >>>>> "graph" ...
> >>>>> "optional" ...
> >>>>> "minus" ...
> >>>>> "bind" ...
> >>>>> "service" ...
> >>>>> "filter" ...
> >>>>> "{" ...
> >>>>> "}" ...
> >>>>> ";" ...
> >>>>> "," ...
> >>>>> "." ...
> >>>>>
> >>>>> When I researched these options under "Was expecting one of:", I did
> >> not
> >>>>> find one of those options that would fit my query.
> >>>>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to
> >> ensure
> >>>>> that the sensor is attached to the road on which the car is on.
> >>>>>
> >>>>> I group by ?r to try to ensure that the grouping is per road as well.
> >> But
> >>>>> I
> >>>>> think you have a point, and I should group by the sensor as well.
> >>>>>
> >>>>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full
> >> stop
> >>>>> instead of a full stop the error goes away, but still, nothing
> happens
> >> in
> >>>>> the owl file. Meaning, the new tuple is not added either. (I am a bit
> >>>>> confused as to when to put a ";" and when to put a "." I believe, as
> >> far
> >>>>> as
> >>>>> my understanding goes, when I put a "." in the end of the
> >>>>> " cv:Vehicle_Road ?r " the error goes away because the last line
> >> "?ass
> >>>>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
> >>>>> could
> >>>>> you confirm or negate that?)
> >>>>>
> >>>>> Your help is truly much appreciated.
> >>>>>
> >>>>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
> >>>>> buehmann@informatik.uni-leipzig.de> wrote:
> >>>>>
> >>>>> There was some formatting issue in my previous mail.
> >>>>>> What I was wondering the need for grouping by ?r instead of ?ass.
> >>>>>>
> >>>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>>>> PREFIX cv:
> >>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> >>>>>> ed-ontology-6#
> >>>>>>
> >>>>>> INSERT {
> >>>>>> ?ass cv:recorded_speed ?avg .
> >>>>>> }
> >>>>>> WHERE
> >>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>>>> WHERE
> >>>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>>> cv:Vehicle_Road ?r .
> >>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>>>> }
> >>>>>> GROUP BY ?r ?ass
> >>>>>> }
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
> >>>>>>
> >>>>>>> That is your query:
> >>>>>>>
> >>>>>>> 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#>
> >>>>>>
> >>>>>>> INSERT {
> >>>>>>> ?ass cv:recorded_speed ?avg .
> >>>>>>> }
> >>>>>>> WHERE
> >>>>>>> { SELECT (AVG(?speed) AS ?avg)
> >>>>>>> WHERE
> >>>>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>>>> cv:Vehicle_Road ?r
> >>>>>>> { SELECT ?r
> >>>>>>> WHERE
> >>>>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
> >>>>>>> }
> >>>>>>> }
> >>>>>>> GROUP BY ?r
> >>>>>>> }
> >>>>>>>
> >>>>>>> The problem is that you use for what ever reason a sub-SELECT to
> get
> >> the
> >>>>>>> ?ass value. But this value is not propagated to the outer query,
> >> thus,
> >>>>>>> it's not bound to the INSERT part.
> >>>>>>>
> >>>>>>> Why not do it like here (note, I dPREFIX rdf:
> >>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>>>>> PREFIX cv:
> >>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>>>>>
> >>>>>> untitled-ontology-6#>
> >>>>>>
> >>>>>>> INSERT {
> >>>>>>> ?ass cv:recorded_speed ?avg .
> >>>>>>> }
> >>>>>>> WHERE
> >>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>>>>> WHERE
> >>>>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>>>> cv:Vehicle_Road ?r .
> >>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>>>>> }
> >>>>>>> GROUP BY ?r ?ass
> >>>>>>> }on't know why you group by ?r instead of ?ass, thus, added
> both):
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
> >>>>>>>
> >>>>>>>> Didn't know attachments are not allowed.
> >>>>>>>> This is a gist of the three files.
> >>>>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808
> dbf85d9
> >>>>>>>>
> >>>>>>>> The code files are minimalist as you can see on the gist. Only the
> >>>>>>>>
> >>>>>>> query is
> >>>>>>> included and everything else is removed. I wanted to attach them as
> >>>>>>> files
> >>>>>>> to avoid clutter in the email. I believe things are more organized
> >> this
> >>>>>>> way.
> >>>>>>>> The problem is in b.java file. The c.java file is just to prove
> that
> >>>>>>>> the
> >>>>>>>> individual parts of the query work together. And the OWL file is
> the
> >>>>>>>> one
> >>>>>>>> generated by Protege. It has no problems, but I have removed
> >> anything
> >>>>>>> that
> >>>>>>> is not needed for this specific query.
> >>>>>>>> I have also attached a file called "ont.owl (full)" which has the
> >> full
> >>>>>>>> ontology in case it is needed (which I think it is not needed, but
> >> just
> >>>>>>> in
> >>>>>>> case I misunderstand).
> >>>>>>>> Regards,
> >>>>>>>>
> >>>>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org>
> >> wrote:
> >>>>>>>> Attachments don't get through to this list.
> >>>>>>>>> Put them in a pastebin or guithub gist.
> >>>>>>>>>
> >>>>>>>>> However, if they are so large that inlining email in plain text
> is
> >>>>>>>>> impractical, than it suggests they are not minimal.
> >>>>>>>>>
> >>>>>>>>> Andy
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
> >>>>>>>>>
> >>>>>>>>> You forgot the attachments...
> >>>>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
> >>>>>>>>>>
> >>>>>>>>>> Attached is a file of my code and my ontology which I have
> >> imported
> >>>>>>>>>> on
> >>>>>>> Eclipse.
> >>>>>>>>>>> I have finally fixed the null values issue. I am not sure if I
> >>>>>>>>>>> understood the cause of the nulls correctly. However, it got
> >> fixed
> >>>>>>>>>>> when I used a different way of making the ResultSet as shown
> >> below:
> >>>>>>>>>>> Query query = QueryFactory.create(queryString1);
> >>>>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
> >>>>>>>>>>> ontologyModel);
> >>>>>>>>>>> ResultSet results=qexec.execSelect();
> >>>>>>>>>>> ResultSetFormatter.out(System.out, results, query);
> >>>>>>>>>>> qexec.close();
> >>>>>>>>>>> I am including this bit of code here in case this helps someone
> >> else
> >>>>>>>>>>> in the future cause I could not find it easily. It can be found
> >> in
> >>>>>>>>>>> context in the attached c.java file.
> >>>>>>>>>>>
> >>>>>>>>>>> However, the original bigger problem still persists. The insert
> >>>>>>>>>>>
> >>>>>>>>>> SPARQL
> >>>>>>> query still does not result in inserting the new desired subject
> >>>>>>>>>>> predicate object triple. No errors are generated which is I
> >> suppose
> >>>>>>>>>>> a
> >>>>>>>>>>> good thing, but when I print the ontology after running the
> >> query, I
> >>>>>>>>>>> can see that the new triples are not added.
> >>>>>>>>>>>
> >>>>>>>>>>> Attached is the owl file and the java file (b.java). I have
> added
> >>>>>>>>>>> explanatory comments in the java file hoping to clarify what I
> am
> >>>>>>>>>>> trying to do here.
> >>>>>>>>>>>
> >>>>>>>>>>> Also, hoping to clarify matters a bit more, I have two average
> >> speed
> >>>>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
> >>>>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
> >>>>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on
> Road1
> >>>>>>>>>>> with
> >>>>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
> >>>>>>>>>>> vehicleSpeed
> >>>>>>>>>>> of 50. Only one vehicle is modeled to be located on each road
> in
> >> an
> >>>>>>>>>>> attempt to simplify things for now.
> >>>>>>>>>>>
> >>>>>>>>>>> The goal is to calculate the average of speeds of all vehicles
> on
> >>>>>>>>>>> road1 and assign it as the value of the object property called
> >>>>>>>>>>> recorded_speed of the speed sensor attached to the road which
> the
> >>>>>>>>>>> vehicles are on. Consequently, based on my modeling, after
> >> running
> >>>>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since
> >> only
> >>>>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and
> >> vehicle1
> >>>>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of
> 50
> >>>>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is
> >> attached
> >>>>>>>>>> and
> >>>>>>> vehicle2 has speed of 50).
> >>>>>>>>>>> Also, attached is another java file (c.java) that has the
> >> results of
> >>>>>>>>>>> me breaking down the big query in b.java.
> >>>>>>>>>>> My suspicion is that the part where I am trying to invoke the
> >> insert
> >>>>>>>>>>> query is not working, but the way I built is based on
> >> StackOverflow
> >>>>>>>>>>> and it was supposedly working fine, so I am not sure what I am
> >>>>>>>>>>>
> >>>>>>>>>> missing.
> >>>>>>>>>>> Hope this gives you a picture of what is going on and hope you
> >> can
> >>>>>>>>>>> help me understand why I cannot get the query to update the
> >>>>>>>>>>> ontology.
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
> >>>>>>>>>>> <buehmann@informatik.uni-leipzig.de
> >>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>> If results are bound it can't be a null value. Please
> show
> >>>>>>>>>>> your
> >>>>>>>>>>> updated
> >>>>>>>>>>> code.
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
> >>>>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is
> nit
> >>>>>>>>>>> the
> >>>>>>>>>>> cause of the
> >>>>>>>>>>> > null. When I fixed it, the results of even the simplest
> >>>>>>>>>>>
> >>>>>>>>>> queries
> >>>>>>> are still
> >>>>>>>>>>> > nulls.
> >>>>>>>>>>> >
> >>>>>>>>>>> > The code is not generating errors though, it is not
> >>>>>>>>>>> generating
> >>>>>>>>>>> the proper
> >>>>>>>>>>> > results ...
> >>>>>>>>>>> >
> >>>>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
> >>>>>>>>>>>
> >>>>>>>>>> andy@apache.org
> >>>>>>> <ma...@apache.org>> wrote:
> >>>>>>>>>>> >
> >>>>>>>>>>> >>
> >>>>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
> >>>>>>>>>>> >>
> >>>>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking
> >> down
> >>>>>>>>>> my
> >>>>>>> chain of
> >>>>>>>>>>> >>> thought into smaller pieces. Thank you so much.
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> I saw an example online where the query syntax is
> >> written
> >>>>>>>>>> as a
> >>>>>>> string on
> >>>>>>>>>>> >>> Jena. so my query now looks like this:
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >> Use
> >>>>>>>>>>> >>
> >>>>>>>>>>> >> String.join("\n"
> >>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> >>>>>>>>>>>
> >>>>>>>>>> 02/22-rdf-syntax-ns#
> >>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> >>>>>>>>>>>
> >>>>>>>>>> 02/22-rdf-syntax-ns#
> >>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>>>>>>>> >> , "INSERT {",
> >>>>>>>>>>> >> ...
> >>>>>>>>>>> >> , "}"
> >>>>>>>>>>> >> );
> >>>>>>>>>>> >>
> >>>>>>>>>>> >> then you will have newlines in the string and parser
> >> errors
> >>>>>>>>>>> will have
> >>>>>>>>>>> >> line+column numbers that are useful.
> >>>>>>>>>>> >>
> >>>>>>>>>>> >> Andy
> >>>>>>>>>>> >>
> >>>>>>>>>>> >>
> >>>>>>>>>>> >>
> >>>>>>>>>>> >>> String queryString=
> >>>>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/
> >> 02/22-rdf-syntax-ns#
> >>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>>>>>>>> >>> "PREFIX cv:<
> >>>>>>>>>>> >>>
> >>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >> untitl
> >>>>>>>>>>> ed-ontology-6#
> >>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >> untit
> >>>>>>>>>>> led-ontology-6#>
> >>>>>>>>>>> >>>> "+
> >>>>>>>>>>> >>> "insert {"+
> >>>>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
> >>>>>>>>>>> >>> "}"+
> >>>>>>>>>>> >>> "WHERE {"+
> >>>>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
> >>>>>>>>>>> >>> "where{"+
> >>>>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
> >>>>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
> >>>>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
> >>>>>>>>>>> >>> "{"+
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> "SELECT ?r"+
> >>>>>>>>>>> >>> "where{"+
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> >>>>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
> >>>>>>>>>>> >>> "}"+
> >>>>>>>>>>> >>> "}"+
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
> >>>>>>>>>>> >>> "}";
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> Then, also based on my research, I feed the query
> >> string
> >>>>>>>>>> into
> >>>>>>> the parser
> >>>>>>>>>>> >>> and output the model.
> >>>>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel
> >> );
> >>>>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
> >>>>>>>>>>> >>> I encountered many errors but managed to get rid of
> >> them
> >>>>>>>>>> all.
> >>>>>>> However,
> >>>>>>>>>>> >>> based on the output, nothing has changed.
> >> speedSensor1
> >>>>>>>>>>> and
> >>>>>>>>>>> speedSensor2
> >>>>>>>>>>> >>> do
> >>>>>>>>>>> >>> not have the recorded_speed property added.
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> Of course, I tried debugging, but I could not get any
> >>>>>>>>>>> understanding of the
> >>>>>>>>>>> >>> problem.
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>>
> >>>>>>>>>>> >>> 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#
> >>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>>>>>>>> >>> "PREFIX cv:<
> >>>>>>>>>>> >>>
> >>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >> untitl
> >>>>>>>>>>> ed-ontology-6#
> >>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >> untit
> >>>>>>>>>>> led-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");
> >>>>>>> >>> 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 <
> >>>>>>>>>>>
> >>>>>>>>>> andy@apache.org
> >>>>>>> <ma...@apache.org>> 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" <
> >>>>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
> >>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
> >>>>>>>>>>> <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/
> >>>>>>>>>>> <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/
> >>>>>>>>>>> <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/
> >>>>>>>>>>> <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
> >>>>>>>>>>> <andy@apache.org <ma...@apache.org>>
> >>>>>>>>>>> >>>>>>> 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.
> >>>>>>>>>>> >>>>>>>>
> >>>>>>>>>>> >>>>>>>>
> >>>>>>>>>>> >>>>>>>>
> >>>>>>>>>>> >>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >> --
> >> Lorenz Bühmann
> >> AKSW group, University of Leipzig
> >> Group: http://aksw.org - semantic web research center
> >>
> >>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
> Yes, I see. I don't get why it does not add them when I run it...
>
> Do you see the new tuples when you print or when you open the file ontology
> file? Cause with me, when I used your syntax, the new triples show in the
> print but when I open the ontology file on Eclipse which I am running the
> query on, I find that the triples are not added.
As I said, I just used your code in b.java, thus, it's just printed to
System.out .
>
> And I have noticed that what you are showing me is in turtle format. The
> ontology file is in XML format...
The same, your code prints to System.out as "TTL" which is Turtle - I'm
wondering why you're surprised, it's your code.
> Isn't the result of the insertion
> function written to the ontology file?
No, the triples in the ontology are loaded into memory. That means you
have to write the model back to disk
> Note that I have previously added
> lines to my code to try and rewrite the ontology after the query, but the
> file is still not affected:
But you did this without the query that I provided?
>
> FileOutputStream output = null;
>
> try {
> output = new FileOutputStream( "yarab.owl ");
> } catch(Exception e) {}
>
> ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
Do you really want to use writeAll()? This also writes inferred and
imported triples to disk. Otherwise, use write()
And the argument "xmlbase" is for sure wrong. It expects the base URI of
the XML (or Turtle) document if exist - you can also use NULL or simply
use write(output, "RDF/XML-ABBREV")
To sum up, writing to disk works for me as well. I don't see why this
should not work if the INSERT already modified the model.
>
>
> PrintStream p= new PrintStream("yarab.owl");
> ontologyModel.writeAll(p, "RDF/XML", null);
> p.close();
>
>
>
>
>
> On Sat, Jun 10, 2017 at 8:32 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de> wrote:
>
>> That can't be. I tried your example b.java with my query
>>
>> 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#
>> INSERT {
>> ?ass cv:recorded_speed ?avg .
>> }
>> WHERE
>> { SELECT ?ass (AVG(?speed) AS ?avg)
>> WHERE
>> { ?v cv:vehicleSpeed ?speed ;
>> cv:Vehicle_Road ?r .
>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>> }
>> GROUP BY ?ass
>> }
>>
>> Before execution the model contains 67 triples, afterwards 69. And the
>> added triples are as follows:
>>
>>
>> For SpeedSensor2:
>>
>> untitled-ontology-6:SpeedSensor2
>> a untitled-ontology-6:Speed_Sensor ,
>> untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
>> owl:NamedIndividual ;
>> untitled-ontology-6:avgSpeedSensor_Infrastructue
>> untitled-ontology-6:Road2 ;
>> untitled-ontology-6:recorded_speed
>> 50.0 ;
>> untitled-ontology-6:sensorLocatedInInfrastructure
>> true ;
>> untitled-ontology-6:sensorLocatedInVehicle
>> false .
>>
>> for SpeedSensor1:
>>
>> untitled-ontology-6:SpeedSensor1
>> a untitled-ontology-6:Speed_Sensor
>> , untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
>> owl:NamedIndividual ;
>> untitled-ontology-6:avgSpeedSensor_Infrastructue
>> untitled-ontology-6:Road1 ;
>> untitled-ontology-6:recorded_speed
>> 0.0 ;
>> untitled-ontology-6:sensorLocatedInInfrastructure
>> true ;
>> untitled-ontology-6:sensorLocatedInVehicle
>> false ;
>> untitled-ontology-6:sensor_id 11 .
>>
>> You can, see both now have the recorded_speed value.
>>
>>
>>> And I explained that using Lorenz's example syntax is something that I
>> have
>>> already tried before asking on the list and still the update to the owl
>>> file does not take place. I mentioned that in my previous email.
>>> I think the 2000+ lines u r mentioning are the full ontology file. I
>>> mentioned that the file called ont.owl is the full one in case needed,
>> but
>>> I have already provided a short version called Yarab.owl .. Doubt that
>>> Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles, two
>>> roads instances and a couple of properties ..and it has lots of white
>> lines
>>> to separate the code to blocks for readability purposes. Which file did u
>>> look at? I think u looked at the one I had described to be the full
>>> ontology.
>>>
>>> On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
>>>
>>>> " cv:Vehicle_Road ?r ;"+
>>>> Bad syntax. Replace ";" by "."
>>>>
>>>> Lorenz showed you the correct syntax.
>>>>
>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>>> Print the query out and see what it looks like. Hence the earlier
>>>> suggestion you put newlines in the query.
>>>>
>>>> Andy
>>>>
>>>> ~2800 lines is not a minimal example.
>>>>
>>>> On 09/06/17 15:53, Aya Hamdy wrote:
>>>>
>>>>> When I do not use the subselect and write the query this way:
>>>>>
>>>>> String queryString1 =
>>>>> "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#
>>>>>> "+
>>>>> "INSERT {"+
>>>>> " ?ass cv:recorded_speed ?avg"+
>>>>> "}"+
>>>>> "WHERE {"+
>>>>> "SELECT (AVG(?speed) AS ?avg) {"+
>>>>> "?v cv:vehicleSpeed ?speed;"+
>>>>> " cv:Vehicle_Road ?r ;"+
>>>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>>>>
>>>>>
>>>>>
>>>>> "}"+ "GROUP BY ?r ?ass"+
>>>>> "}";
>>>>>
>>>>> The code generates the error below when it tries to execute the update
>>>>> action:
>>>>> Exception in thread "main" org.apache.jena.query.QueryParseException:
>>>>> Encountered " <VAR1> "?r "" at line 1, column 299.
>>>>> Was expecting one of:
>>>>> "values" ...
>>>>> "graph" ...
>>>>> "optional" ...
>>>>> "minus" ...
>>>>> "bind" ...
>>>>> "service" ...
>>>>> "filter" ...
>>>>> "{" ...
>>>>> "}" ...
>>>>> ";" ...
>>>>> "," ...
>>>>> "." ...
>>>>>
>>>>> When I researched these options under "Was expecting one of:", I did
>> not
>>>>> find one of those options that would fit my query.
>>>>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to
>> ensure
>>>>> that the sensor is attached to the road on which the car is on.
>>>>>
>>>>> I group by ?r to try to ensure that the grouping is per road as well.
>> But
>>>>> I
>>>>> think you have a point, and I should group by the sensor as well.
>>>>>
>>>>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full
>> stop
>>>>> instead of a full stop the error goes away, but still, nothing happens
>> in
>>>>> the owl file. Meaning, the new tuple is not added either. (I am a bit
>>>>> confused as to when to put a ";" and when to put a "." I believe, as
>> far
>>>>> as
>>>>> my understanding goes, when I put a "." in the end of the
>>>>> " cv:Vehicle_Road ?r " the error goes away because the last line
>> "?ass
>>>>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
>>>>> could
>>>>> you confirm or negate that?)
>>>>>
>>>>> Your help is truly much appreciated.
>>>>>
>>>>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
>>>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>>>
>>>>> There was some formatting issue in my previous mail.
>>>>>> What I was wondering the need for grouping by ?r instead of ?ass.
>>>>>>
>>>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>>>> PREFIX cv:
>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>> ed-ontology-6#
>>>>>>
>>>>>> INSERT {
>>>>>> ?ass cv:recorded_speed ?avg .
>>>>>> }
>>>>>> WHERE
>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>>>> WHERE
>>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>>> cv:Vehicle_Road ?r .
>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>>>> }
>>>>>> GROUP BY ?r ?ass
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
>>>>>>
>>>>>>> That is your query:
>>>>>>>
>>>>>>> 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#>
>>>>>>
>>>>>>> INSERT {
>>>>>>> ?ass cv:recorded_speed ?avg .
>>>>>>> }
>>>>>>> WHERE
>>>>>>> { SELECT (AVG(?speed) AS ?avg)
>>>>>>> WHERE
>>>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>>>> cv:Vehicle_Road ?r
>>>>>>> { SELECT ?r
>>>>>>> WHERE
>>>>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
>>>>>>> }
>>>>>>> }
>>>>>>> GROUP BY ?r
>>>>>>> }
>>>>>>>
>>>>>>> The problem is that you use for what ever reason a sub-SELECT to get
>> the
>>>>>>> ?ass value. But this value is not propagated to the outer query,
>> thus,
>>>>>>> it's not bound to the INSERT part.
>>>>>>>
>>>>>>> Why not do it like here (note, I dPREFIX rdf:
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>>>>> PREFIX cv:
>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>>>
>>>>>> untitled-ontology-6#>
>>>>>>
>>>>>>> INSERT {
>>>>>>> ?ass cv:recorded_speed ?avg .
>>>>>>> }
>>>>>>> WHERE
>>>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>>>>> WHERE
>>>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>>>> cv:Vehicle_Road ?r .
>>>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>>>>> }
>>>>>>> GROUP BY ?r ?ass
>>>>>>> }on't know why you group by ?r instead of ?ass, thus, added both):
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
>>>>>>>
>>>>>>>> Didn't know attachments are not allowed.
>>>>>>>> This is a gist of the three files.
>>>>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
>>>>>>>>
>>>>>>>> The code files are minimalist as you can see on the gist. Only the
>>>>>>>>
>>>>>>> query is
>>>>>>> included and everything else is removed. I wanted to attach them as
>>>>>>> files
>>>>>>> to avoid clutter in the email. I believe things are more organized
>> this
>>>>>>> way.
>>>>>>>> The problem is in b.java file. The c.java file is just to prove that
>>>>>>>> the
>>>>>>>> individual parts of the query work together. And the OWL file is the
>>>>>>>> one
>>>>>>>> generated by Protege. It has no problems, but I have removed
>> anything
>>>>>>> that
>>>>>>> is not needed for this specific query.
>>>>>>>> I have also attached a file called "ont.owl (full)" which has the
>> full
>>>>>>>> ontology in case it is needed (which I think it is not needed, but
>> just
>>>>>>> in
>>>>>>> case I misunderstand).
>>>>>>>> Regards,
>>>>>>>>
>>>>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org>
>> wrote:
>>>>>>>> Attachments don't get through to this list.
>>>>>>>>> Put them in a pastebin or guithub gist.
>>>>>>>>>
>>>>>>>>> However, if they are so large that inlining email in plain text is
>>>>>>>>> impractical, than it suggests they are not minimal.
>>>>>>>>>
>>>>>>>>> Andy
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>>>>>>>>
>>>>>>>>> You forgot the attachments...
>>>>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>>>>>>>>
>>>>>>>>>> Attached is a file of my code and my ontology which I have
>> imported
>>>>>>>>>> on
>>>>>>> Eclipse.
>>>>>>>>>>> I have finally fixed the null values issue. I am not sure if I
>>>>>>>>>>> understood the cause of the nulls correctly. However, it got
>> fixed
>>>>>>>>>>> when I used a different way of making the ResultSet as shown
>> below:
>>>>>>>>>>> Query query = QueryFactory.create(queryString1);
>>>>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>>>>>>>>> ontologyModel);
>>>>>>>>>>> ResultSet results=qexec.execSelect();
>>>>>>>>>>> ResultSetFormatter.out(System.out, results, query);
>>>>>>>>>>> qexec.close();
>>>>>>>>>>> I am including this bit of code here in case this helps someone
>> else
>>>>>>>>>>> in the future cause I could not find it easily. It can be found
>> in
>>>>>>>>>>> context in the attached c.java file.
>>>>>>>>>>>
>>>>>>>>>>> However, the original bigger problem still persists. The insert
>>>>>>>>>>>
>>>>>>>>>> SPARQL
>>>>>>> query still does not result in inserting the new desired subject
>>>>>>>>>>> predicate object triple. No errors are generated which is I
>> suppose
>>>>>>>>>>> a
>>>>>>>>>>> good thing, but when I print the ontology after running the
>> query, I
>>>>>>>>>>> can see that the new triples are not added.
>>>>>>>>>>>
>>>>>>>>>>> Attached is the owl file and the java file (b.java). I have added
>>>>>>>>>>> explanatory comments in the java file hoping to clarify what I am
>>>>>>>>>>> trying to do here.
>>>>>>>>>>>
>>>>>>>>>>> Also, hoping to clarify matters a bit more, I have two average
>> speed
>>>>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1
>>>>>>>>>>> with
>>>>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
>>>>>>>>>>> vehicleSpeed
>>>>>>>>>>> of 50. Only one vehicle is modeled to be located on each road in
>> an
>>>>>>>>>>> attempt to simplify things for now.
>>>>>>>>>>>
>>>>>>>>>>> The goal is to calculate the average of speeds of all vehicles on
>>>>>>>>>>> road1 and assign it as the value of the object property called
>>>>>>>>>>> recorded_speed of the speed sensor attached to the road which the
>>>>>>>>>>> vehicles are on. Consequently, based on my modeling, after
>> running
>>>>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since
>> only
>>>>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and
>> vehicle1
>>>>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>>>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is
>> attached
>>>>>>>>>> and
>>>>>>> vehicle2 has speed of 50).
>>>>>>>>>>> Also, attached is another java file (c.java) that has the
>> results of
>>>>>>>>>>> me breaking down the big query in b.java.
>>>>>>>>>>> My suspicion is that the part where I am trying to invoke the
>> insert
>>>>>>>>>>> query is not working, but the way I built is based on
>> StackOverflow
>>>>>>>>>>> and it was supposedly working fine, so I am not sure what I am
>>>>>>>>>>>
>>>>>>>>>> missing.
>>>>>>>>>>> Hope this gives you a picture of what is going on and hope you
>> can
>>>>>>>>>>> help me understand why I cannot get the query to update the
>>>>>>>>>>> ontology.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>>>>>>>>> <buehmann@informatik.uni-leipzig.de
>>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> If results are bound it can't be a null value. Please show
>>>>>>>>>>> your
>>>>>>>>>>> updated
>>>>>>>>>>> code.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is nit
>>>>>>>>>>> the
>>>>>>>>>>> cause of the
>>>>>>>>>>> > null. When I fixed it, the results of even the simplest
>>>>>>>>>>>
>>>>>>>>>> queries
>>>>>>> are still
>>>>>>>>>>> > nulls.
>>>>>>>>>>> >
>>>>>>>>>>> > The code is not generating errors though, it is not
>>>>>>>>>>> generating
>>>>>>>>>>> the proper
>>>>>>>>>>> > results ...
>>>>>>>>>>> >
>>>>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
>>>>>>>>>>>
>>>>>>>>>> andy@apache.org
>>>>>>> <ma...@apache.org>> wrote:
>>>>>>>>>>> >
>>>>>>>>>>> >>
>>>>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>>>>>>>>> >>
>>>>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking
>> down
>>>>>>>>>> my
>>>>>>> chain of
>>>>>>>>>>> >>> thought into smaller pieces. Thank you so much.
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> I saw an example online where the query syntax is
>> written
>>>>>>>>>> as a
>>>>>>> string on
>>>>>>>>>>> >>> Jena. so my query now looks like this:
>>>>>>>>>>> >>>
>>>>>>>>>>> >> Use
>>>>>>>>>>> >>
>>>>>>>>>>> >> String.join("\n"
>>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>>>>
>>>>>>>>>> 02/22-rdf-syntax-ns#
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>>>>
>>>>>>>>>> 02/22-rdf-syntax-ns#
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>>>>> >> , "INSERT {",
>>>>>>>>>>> >> ...
>>>>>>>>>>> >> , "}"
>>>>>>>>>>> >> );
>>>>>>>>>>> >>
>>>>>>>>>>> >> then you will have newlines in the string and parser
>> errors
>>>>>>>>>>> will have
>>>>>>>>>>> >> line+column numbers that are useful.
>>>>>>>>>>> >>
>>>>>>>>>>> >> Andy
>>>>>>>>>>> >>
>>>>>>>>>>> >>
>>>>>>>>>>> >>
>>>>>>>>>>> >>> String queryString=
>>>>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/
>> 02/22-rdf-syntax-ns#
>>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>>>>> >>> "PREFIX cv:<
>>>>>>>>>>> >>>
>>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>> untitl
>>>>>>>>>>> ed-ontology-6#
>>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>> untit
>>>>>>>>>>> led-ontology-6#>
>>>>>>>>>>> >>>> "+
>>>>>>>>>>> >>> "insert {"+
>>>>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>>>>>>>>> >>> "}"+
>>>>>>>>>>> >>> "WHERE {"+
>>>>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>>>>>>>>> >>> "where{"+
>>>>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
>>>>>>>>>>> >>> "{"+
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> "SELECT ?r"+
>>>>>>>>>>> >>> "where{"+
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>>>>>>>>> >>> "}"+
>>>>>>>>>>> >>> "}"+
>>>>>>>>>>> >>>
>>>>>>>>>>> >>>
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>>>>>>>>> >>> "}";
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> Then, also based on my research, I feed the query
>> string
>>>>>>>>>> into
>>>>>>> the parser
>>>>>>>>>>> >>> and output the model.
>>>>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel
>> );
>>>>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>>>>>>>>> >>> I encountered many errors but managed to get rid of
>> them
>>>>>>>>>> all.
>>>>>>> However,
>>>>>>>>>>> >>> based on the output, nothing has changed.
>> speedSensor1
>>>>>>>>>>> and
>>>>>>>>>>> speedSensor2
>>>>>>>>>>> >>> do
>>>>>>>>>>> >>> not have the recorded_speed property added.
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> Of course, I tried debugging, but I could not get any
>>>>>>>>>>> understanding of the
>>>>>>>>>>> >>> problem.
>>>>>>>>>>> >>>
>>>>>>>>>>> >>>
>>>>>>>>>>> >>> 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#
>>>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>>>>> >>> "PREFIX cv:<
>>>>>>>>>>> >>>
>>>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
>> untitl
>>>>>>>>>>> ed-ontology-6#
>>>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>> untit
>>>>>>>>>>> led-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");
>>>>>>> >>> 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 <
>>>>>>>>>>>
>>>>>>>>>> andy@apache.org
>>>>>>> <ma...@apache.org>> 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" <
>>>>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>>>>>>>>> <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/
>>>>>>>>>>> <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/
>>>>>>>>>>> <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/
>>>>>>>>>>> <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
>>>>>>>>>>> <andy@apache.org <ma...@apache.org>>
>>>>>>>>>>> >>>>>>> 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.
>>>>>>>>>>> >>>>>>>>
>>>>>>>>>>> >>>>>>>>
>>>>>>>>>>> >>>>>>>>
>>>>>>>>>>> >>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Yes, I see. I don't get why it does not add them when I run it...
Do you see the new tuples when you print or when you open the file ontology
file? Cause with me, when I used your syntax, the new triples show in the
print but when I open the ontology file on Eclipse which I am running the
query on, I find that the triples are not added.
And I have noticed that what you are showing me is in turtle format. The
ontology file is in XML format...Isn't the result of the insertion
function written to the ontology file? Note that I have previously added
lines to my code to try and rewrite the ontology after the query, but the
file is still not affected:
FileOutputStream output = null;
try {
output = new FileOutputStream( "yarab.owl ");
} catch(Exception e) {}
ontologyModel.writeAll(output, "RDF/XML-ABBREV","xmlbase");
PrintStream p= new PrintStream("yarab.owl");
ontologyModel.writeAll(p, "RDF/XML", null);
p.close();
On Sat, Jun 10, 2017 at 8:32 AM, Lorenz B. <
buehmann@informatik.uni-leipzig.de> wrote:
> That can't be. I tried your example b.java with my query
>
> 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#
> >
>
> INSERT {
> ?ass cv:recorded_speed ?avg .
> }
> WHERE
> { SELECT ?ass (AVG(?speed) AS ?avg)
> WHERE
> { ?v cv:vehicleSpeed ?speed ;
> cv:Vehicle_Road ?r .
> ?ass cv:avgSpeedSensor_Infrastructue ?r
> }
> GROUP BY ?ass
> }
>
> Before execution the model contains 67 triples, afterwards 69. And the
> added triples are as follows:
>
>
> For SpeedSensor2:
>
> untitled-ontology-6:SpeedSensor2
> a untitled-ontology-6:Speed_Sensor ,
> untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
> owl:NamedIndividual ;
> untitled-ontology-6:avgSpeedSensor_Infrastructue
> untitled-ontology-6:Road2 ;
> untitled-ontology-6:recorded_speed
> 50.0 ;
> untitled-ontology-6:sensorLocatedInInfrastructure
> true ;
> untitled-ontology-6:sensorLocatedInVehicle
> false .
>
> for SpeedSensor1:
>
> untitled-ontology-6:SpeedSensor1
> a untitled-ontology-6:Speed_Sensor
> , untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
> owl:NamedIndividual ;
> untitled-ontology-6:avgSpeedSensor_Infrastructue
> untitled-ontology-6:Road1 ;
> untitled-ontology-6:recorded_speed
> 0.0 ;
> untitled-ontology-6:sensorLocatedInInfrastructure
> true ;
> untitled-ontology-6:sensorLocatedInVehicle
> false ;
> untitled-ontology-6:sensor_id 11 .
>
> You can, see both now have the recorded_speed value.
>
>
> > And I explained that using Lorenz's example syntax is something that I
> have
> > already tried before asking on the list and still the update to the owl
> > file does not take place. I mentioned that in my previous email.
> > I think the 2000+ lines u r mentioning are the full ontology file. I
> > mentioned that the file called ont.owl is the full one in case needed,
> but
> > I have already provided a short version called Yarab.owl .. Doubt that
> > Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles, two
> > roads instances and a couple of properties ..and it has lots of white
> lines
> > to separate the code to blocks for readability purposes. Which file did u
> > look at? I think u looked at the one I had described to be the full
> > ontology.
> >
> > On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
> >
> >> " cv:Vehicle_Road ?r ;"+
> >> Bad syntax. Replace ";" by "."
> >>
> >> Lorenz showed you the correct syntax.
> >>
> >> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
> >> Print the query out and see what it looks like. Hence the earlier
> >> suggestion you put newlines in the query.
> >>
> >> Andy
> >>
> >> ~2800 lines is not a minimal example.
> >>
> >> On 09/06/17 15:53, Aya Hamdy wrote:
> >>
> >>> When I do not use the subselect and write the query this way:
> >>>
> >>> String queryString1 =
> >>> "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#
> >>>> "+
> >>> "INSERT {"+
> >>> " ?ass cv:recorded_speed ?avg"+
> >>> "}"+
> >>> "WHERE {"+
> >>> "SELECT (AVG(?speed) AS ?avg) {"+
> >>> "?v cv:vehicleSpeed ?speed;"+
> >>> " cv:Vehicle_Road ?r ;"+
> >>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
> >>>
> >>>
> >>>
> >>> "}"+ "GROUP BY ?r ?ass"+
> >>> "}";
> >>>
> >>> The code generates the error below when it tries to execute the update
> >>> action:
> >>> Exception in thread "main" org.apache.jena.query.QueryParseException:
> >>> Encountered " <VAR1> "?r "" at line 1, column 299.
> >>> Was expecting one of:
> >>> "values" ...
> >>> "graph" ...
> >>> "optional" ...
> >>> "minus" ...
> >>> "bind" ...
> >>> "service" ...
> >>> "filter" ...
> >>> "{" ...
> >>> "}" ...
> >>> ";" ...
> >>> "," ...
> >>> "." ...
> >>>
> >>> When I researched these options under "Was expecting one of:", I did
> not
> >>> find one of those options that would fit my query.
> >>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to
> ensure
> >>> that the sensor is attached to the road on which the car is on.
> >>>
> >>> I group by ?r to try to ensure that the grouping is per road as well.
> But
> >>> I
> >>> think you have a point, and I should group by the sensor as well.
> >>>
> >>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full
> stop
> >>> instead of a full stop the error goes away, but still, nothing happens
> in
> >>> the owl file. Meaning, the new tuple is not added either. (I am a bit
> >>> confused as to when to put a ";" and when to put a "." I believe, as
> far
> >>> as
> >>> my understanding goes, when I put a "." in the end of the
> >>> " cv:Vehicle_Road ?r " the error goes away because the last line
> "?ass
> >>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
> >>> could
> >>> you confirm or negate that?)
> >>>
> >>> Your help is truly much appreciated.
> >>>
> >>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
> >>> buehmann@informatik.uni-leipzig.de> wrote:
> >>>
> >>> There was some formatting issue in my previous mail.
> >>>> What I was wondering the need for grouping by ?r instead of ?ass.
> >>>>
> >>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>> PREFIX cv:
> >>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> >>>> ed-ontology-6#
> >>>>
> >>>>>
> >>>> INSERT {
> >>>> ?ass cv:recorded_speed ?avg .
> >>>> }
> >>>> WHERE
> >>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>> WHERE
> >>>> { ?v cv:vehicleSpeed ?speed ;
> >>>> cv:Vehicle_Road ?r .
> >>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>> }
> >>>> GROUP BY ?r ?ass
> >>>> }
> >>>>
> >>>>
> >>>>
> >>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
> >>>>
> >>>>> That is your query:
> >>>>>
> >>>>> 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#>
> >>>>
> >>>>> INSERT {
> >>>>> ?ass cv:recorded_speed ?avg .
> >>>>> }
> >>>>> WHERE
> >>>>> { SELECT (AVG(?speed) AS ?avg)
> >>>>> WHERE
> >>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>> cv:Vehicle_Road ?r
> >>>>> { SELECT ?r
> >>>>> WHERE
> >>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
> >>>>> }
> >>>>> }
> >>>>> GROUP BY ?r
> >>>>> }
> >>>>>
> >>>>> The problem is that you use for what ever reason a sub-SELECT to get
> the
> >>>>> ?ass value. But this value is not propagated to the outer query,
> thus,
> >>>>> it's not bound to the INSERT part.
> >>>>>
> >>>>> Why not do it like here (note, I dPREFIX rdf:
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> >>>>> PREFIX cv:
> >>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> >>>>>
> >>>> untitled-ontology-6#>
> >>>>
> >>>>> INSERT {
> >>>>> ?ass cv:recorded_speed ?avg .
> >>>>> }
> >>>>> WHERE
> >>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
> >>>>> WHERE
> >>>>> { ?v cv:vehicleSpeed ?speed ;
> >>>>> cv:Vehicle_Road ?r .
> >>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
> >>>>> }
> >>>>> GROUP BY ?r ?ass
> >>>>> }on't know why you group by ?r instead of ?ass, thus, added both):
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
> >>>>>
> >>>>>> Didn't know attachments are not allowed.
> >>>>>> This is a gist of the three files.
> >>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
> >>>>>>
> >>>>>> The code files are minimalist as you can see on the gist. Only the
> >>>>>>
> >>>>> query is
> >>>>> included and everything else is removed. I wanted to attach them as
> >>>>> files
> >>>>> to avoid clutter in the email. I believe things are more organized
> this
> >>>>> way.
> >>>>>> The problem is in b.java file. The c.java file is just to prove that
> >>>>>> the
> >>>>>> individual parts of the query work together. And the OWL file is the
> >>>>>> one
> >>>>>> generated by Protege. It has no problems, but I have removed
> anything
> >>>>>>
> >>>>> that
> >>>>> is not needed for this specific query.
> >>>>>> I have also attached a file called "ont.owl (full)" which has the
> full
> >>>>>> ontology in case it is needed (which I think it is not needed, but
> just
> >>>>>>
> >>>>> in
> >>>>> case I misunderstand).
> >>>>>> Regards,
> >>>>>>
> >>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org>
> wrote:
> >>>>>>
> >>>>>> Attachments don't get through to this list.
> >>>>>>> Put them in a pastebin or guithub gist.
> >>>>>>>
> >>>>>>> However, if they are so large that inlining email in plain text is
> >>>>>>> impractical, than it suggests they are not minimal.
> >>>>>>>
> >>>>>>> Andy
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
> >>>>>>>
> >>>>>>> You forgot the attachments...
> >>>>>>>>
> >>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
> >>>>>>>>
> >>>>>>>> Attached is a file of my code and my ontology which I have
> imported
> >>>>>>>> on
> >>>>> Eclipse.
> >>>>>>>>> I have finally fixed the null values issue. I am not sure if I
> >>>>>>>>> understood the cause of the nulls correctly. However, it got
> fixed
> >>>>>>>>> when I used a different way of making the ResultSet as shown
> below:
> >>>>>>>>>
> >>>>>>>>> Query query = QueryFactory.create(queryString1);
> >>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
> >>>>>>>>> ontologyModel);
> >>>>>>>>> ResultSet results=qexec.execSelect();
> >>>>>>>>> ResultSetFormatter.out(System.out, results, query);
> >>>>>>>>> qexec.close();
> >>>>>>>>> I am including this bit of code here in case this helps someone
> else
> >>>>>>>>> in the future cause I could not find it easily. It can be found
> in
> >>>>>>>>> context in the attached c.java file.
> >>>>>>>>>
> >>>>>>>>> However, the original bigger problem still persists. The insert
> >>>>>>>>>
> >>>>>>>> SPARQL
> >>>>> query still does not result in inserting the new desired subject
> >>>>>>>>> predicate object triple. No errors are generated which is I
> suppose
> >>>>>>>>> a
> >>>>>>>>> good thing, but when I print the ontology after running the
> query, I
> >>>>>>>>> can see that the new triples are not added.
> >>>>>>>>>
> >>>>>>>>> Attached is the owl file and the java file (b.java). I have added
> >>>>>>>>> explanatory comments in the java file hoping to clarify what I am
> >>>>>>>>> trying to do here.
> >>>>>>>>>
> >>>>>>>>> Also, hoping to clarify matters a bit more, I have two average
> speed
> >>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
> >>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
> >>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1
> >>>>>>>>> with
> >>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
> >>>>>>>>> vehicleSpeed
> >>>>>>>>> of 50. Only one vehicle is modeled to be located on each road in
> an
> >>>>>>>>> attempt to simplify things for now.
> >>>>>>>>>
> >>>>>>>>> The goal is to calculate the average of speeds of all vehicles on
> >>>>>>>>> road1 and assign it as the value of the object property called
> >>>>>>>>> recorded_speed of the speed sensor attached to the road which the
> >>>>>>>>> vehicles are on. Consequently, based on my modeling, after
> running
> >>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since
> only
> >>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and
> vehicle1
> >>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
> >>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is
> attached
> >>>>>>>>>
> >>>>>>>> and
> >>>>> vehicle2 has speed of 50).
> >>>>>>>>> Also, attached is another java file (c.java) that has the
> results of
> >>>>>>>>> me breaking down the big query in b.java.
> >>>>>>>>> My suspicion is that the part where I am trying to invoke the
> insert
> >>>>>>>>> query is not working, but the way I built is based on
> StackOverflow
> >>>>>>>>> and it was supposedly working fine, so I am not sure what I am
> >>>>>>>>>
> >>>>>>>> missing.
> >>>>>>>>> Hope this gives you a picture of what is going on and hope you
> can
> >>>>>>>>> help me understand why I cannot get the query to update the
> >>>>>>>>> ontology.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
> >>>>>>>>> <buehmann@informatik.uni-leipzig.de
> >>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
> >>>>>>>>>
> >>>>>>>>> If results are bound it can't be a null value. Please show
> >>>>>>>>> your
> >>>>>>>>> updated
> >>>>>>>>> code.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
> >>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is nit
> >>>>>>>>> the
> >>>>>>>>> cause of the
> >>>>>>>>> > null. When I fixed it, the results of even the simplest
> >>>>>>>>>
> >>>>>>>> queries
> >>>>> are still
> >>>>>>>>> > nulls.
> >>>>>>>>> >
> >>>>>>>>> > The code is not generating errors though, it is not
> >>>>>>>>> generating
> >>>>>>>>> the proper
> >>>>>>>>> > results ...
> >>>>>>>>> >
> >>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
> >>>>>>>>>
> >>>>>>>> andy@apache.org
> >>>>> <ma...@apache.org>> wrote:
> >>>>>>>>> >
> >>>>>>>>> >>
> >>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
> >>>>>>>>> >>
> >>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking
> down
> >>>>>>>>>
> >>>>>>>> my
> >>>>> chain of
> >>>>>>>>> >>> thought into smaller pieces. Thank you so much.
> >>>>>>>>> >>>
> >>>>>>>>> >>> I saw an example online where the query syntax is
> written
> >>>>>>>>>
> >>>>>>>> as a
> >>>>> string on
> >>>>>>>>> >>> Jena. so my query now looks like this:
> >>>>>>>>> >>>
> >>>>>>>>> >> Use
> >>>>>>>>> >>
> >>>>>>>>> >> String.join("\n"
> >>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> >>>>>>>>>
> >>>>>>>> 02/22-rdf-syntax-ns#
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> >>>>>>>>>
> >>>>>>>> 02/22-rdf-syntax-ns#
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>>>>>> >> , "INSERT {",
> >>>>>>>>> >> ...
> >>>>>>>>> >> , "}"
> >>>>>>>>> >> );
> >>>>>>>>> >>
> >>>>>>>>> >> then you will have newlines in the string and parser
> errors
> >>>>>>>>> will have
> >>>>>>>>> >> line+column numbers that are useful.
> >>>>>>>>> >>
> >>>>>>>>> >> Andy
> >>>>>>>>> >>
> >>>>>>>>> >>
> >>>>>>>>> >>
> >>>>>>>>> >>> String queryString=
> >>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/
> 02/22-rdf-syntax-ns#
> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>>>>>> >>> "PREFIX cv:<
> >>>>>>>>> >>>
> >>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
> untitl
> >>>>>>>>> ed-ontology-6#
> >>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> untit
> >>>>>>>>> led-ontology-6#>
> >>>>>>>>> >>>> "+
> >>>>>>>>> >>> "insert {"+
> >>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
> >>>>>>>>> >>> "}"+
> >>>>>>>>> >>> "WHERE {"+
> >>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
> >>>>>>>>> >>> "where{"+
> >>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
> >>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
> >>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
> >>>>>>>>> >>> "{"+
> >>>>>>>>> >>>
> >>>>>>>>> >>> "SELECT ?r"+
> >>>>>>>>> >>> "where{"+
> >>>>>>>>> >>>
> >>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> >>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
> >>>>>>>>> >>> "}"+
> >>>>>>>>> >>> "}"+
> >>>>>>>>> >>>
> >>>>>>>>> >>>
> >>>>>>>>> >>>
> >>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
> >>>>>>>>> >>> "}";
> >>>>>>>>> >>>
> >>>>>>>>> >>> Then, also based on my research, I feed the query
> string
> >>>>>>>>>
> >>>>>>>> into
> >>>>> the parser
> >>>>>>>>> >>> and output the model.
> >>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel
> );
> >>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
> >>>>>>>>> >>> I encountered many errors but managed to get rid of
> them
> >>>>>>>>>
> >>>>>>>> all.
> >>>>> However,
> >>>>>>>>> >>> based on the output, nothing has changed.
> speedSensor1
> >>>>>>>>> and
> >>>>>>>>> speedSensor2
> >>>>>>>>> >>> do
> >>>>>>>>> >>> not have the recorded_speed property added.
> >>>>>>>>> >>>
> >>>>>>>>> >>> Of course, I tried debugging, but I could not get any
> >>>>>>>>> understanding of the
> >>>>>>>>> >>> problem.
> >>>>>>>>> >>>
> >>>>>>>>> >>>
> >>>>>>>>> >>> 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#
> >>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>>>>>> >>> "PREFIX cv:<
> >>>>>>>>> >>>
> >>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/
> untitl
> >>>>>>>>> ed-ontology-6#
> >>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> untit
> >>>>>>>>> led-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");
> >>>>> >>> 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 <
> >>>>>>>>>
> >>>>>>>> andy@apache.org
> >>>>> <ma...@apache.org>> 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" <
> >>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
> >>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
> >>>>>>>>> <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/
> >>>>>>>>> <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/
> >>>>>>>>> <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/
> >>>>>>>>> <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
> >>>>>>>>> <andy@apache.org <ma...@apache.org>>
> >>>>>>>>> >>>>>>> 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.
> >>>>>>>>> >>>>>>>>
> >>>>>>>>> >>>>>>>>
> >>>>>>>>> >>>>>>>>
> >>>>>>>>> >>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
That can't be. I tried your example b.java with my query
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#>
INSERT {
?ass cv:recorded_speed ?avg .
}
WHERE
{ SELECT ?ass (AVG(?speed) AS ?avg)
WHERE
{ ?v cv:vehicleSpeed ?speed ;
cv:Vehicle_Road ?r .
?ass cv:avgSpeedSensor_Infrastructue ?r
}
GROUP BY ?ass
}
Before execution the model contains 67 triples, afterwards 69. And the
added triples are as follows:
For SpeedSensor2:
untitled-ontology-6:SpeedSensor2
a untitled-ontology-6:Speed_Sensor ,
untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
owl:NamedIndividual ;
untitled-ontology-6:avgSpeedSensor_Infrastructue
untitled-ontology-6:Road2 ;
untitled-ontology-6:recorded_speed
50.0 ;
untitled-ontology-6:sensorLocatedInInfrastructure
true ;
untitled-ontology-6:sensorLocatedInVehicle
false .
for SpeedSensor1:
untitled-ontology-6:SpeedSensor1
a untitled-ontology-6:Speed_Sensor
, untitled-ontology-6:Sensor , untitled-ontology-6:Avg_Speed_Sensor ,
owl:NamedIndividual ;
untitled-ontology-6:avgSpeedSensor_Infrastructue
untitled-ontology-6:Road1 ;
untitled-ontology-6:recorded_speed
0.0 ;
untitled-ontology-6:sensorLocatedInInfrastructure
true ;
untitled-ontology-6:sensorLocatedInVehicle
false ;
untitled-ontology-6:sensor_id 11 .
You can, see both now have the recorded_speed value.
> And I explained that using Lorenz's example syntax is something that I have
> already tried before asking on the list and still the update to the owl
> file does not take place. I mentioned that in my previous email.
> I think the 2000+ lines u r mentioning are the full ontology file. I
> mentioned that the file called ont.owl is the full one in case needed, but
> I have already provided a short version called Yarab.owl .. Doubt that
> Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles, two
> roads instances and a couple of properties ..and it has lots of white lines
> to separate the code to blocks for readability purposes. Which file did u
> look at? I think u looked at the one I had described to be the full
> ontology.
>
> On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
>
>> " cv:Vehicle_Road ?r ;"+
>> Bad syntax. Replace ";" by "."
>>
>> Lorenz showed you the correct syntax.
>>
>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>> Print the query out and see what it looks like. Hence the earlier
>> suggestion you put newlines in the query.
>>
>> Andy
>>
>> ~2800 lines is not a minimal example.
>>
>> On 09/06/17 15:53, Aya Hamdy wrote:
>>
>>> When I do not use the subselect and write the query this way:
>>>
>>> String queryString1 =
>>> "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#
>>>> "+
>>> "INSERT {"+
>>> " ?ass cv:recorded_speed ?avg"+
>>> "}"+
>>> "WHERE {"+
>>> "SELECT (AVG(?speed) AS ?avg) {"+
>>> "?v cv:vehicleSpeed ?speed;"+
>>> " cv:Vehicle_Road ?r ;"+
>>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>>
>>>
>>>
>>> "}"+ "GROUP BY ?r ?ass"+
>>> "}";
>>>
>>> The code generates the error below when it tries to execute the update
>>> action:
>>> Exception in thread "main" org.apache.jena.query.QueryParseException:
>>> Encountered " <VAR1> "?r "" at line 1, column 299.
>>> Was expecting one of:
>>> "values" ...
>>> "graph" ...
>>> "optional" ...
>>> "minus" ...
>>> "bind" ...
>>> "service" ...
>>> "filter" ...
>>> "{" ...
>>> "}" ...
>>> ";" ...
>>> "," ...
>>> "." ...
>>>
>>> When I researched these options under "Was expecting one of:", I did not
>>> find one of those options that would fit my query.
>>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to ensure
>>> that the sensor is attached to the road on which the car is on.
>>>
>>> I group by ?r to try to ensure that the grouping is per road as well. But
>>> I
>>> think you have a point, and I should group by the sensor as well.
>>>
>>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full stop
>>> instead of a full stop the error goes away, but still, nothing happens in
>>> the owl file. Meaning, the new tuple is not added either. (I am a bit
>>> confused as to when to put a ";" and when to put a "." I believe, as far
>>> as
>>> my understanding goes, when I put a "." in the end of the
>>> " cv:Vehicle_Road ?r " the error goes away because the last line "?ass
>>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
>>> could
>>> you confirm or negate that?)
>>>
>>> Your help is truly much appreciated.
>>>
>>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>
>>> There was some formatting issue in my previous mail.
>>>> What I was wondering the need for grouping by ?r instead of ?ass.
>>>>
>>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>> PREFIX cv:
>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>> ed-ontology-6#
>>>>
>>>>>
>>>> INSERT {
>>>> ?ass cv:recorded_speed ?avg .
>>>> }
>>>> WHERE
>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>> WHERE
>>>> { ?v cv:vehicleSpeed ?speed ;
>>>> cv:Vehicle_Road ?r .
>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>> }
>>>> GROUP BY ?r ?ass
>>>> }
>>>>
>>>>
>>>>
>>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
>>>>
>>>>> That is your query:
>>>>>
>>>>> 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#>
>>>>
>>>>> INSERT {
>>>>> ?ass cv:recorded_speed ?avg .
>>>>> }
>>>>> WHERE
>>>>> { SELECT (AVG(?speed) AS ?avg)
>>>>> WHERE
>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>> cv:Vehicle_Road ?r
>>>>> { SELECT ?r
>>>>> WHERE
>>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
>>>>> }
>>>>> }
>>>>> GROUP BY ?r
>>>>> }
>>>>>
>>>>> The problem is that you use for what ever reason a sub-SELECT to get the
>>>>> ?ass value. But this value is not propagated to the outer query, thus,
>>>>> it's not bound to the INSERT part.
>>>>>
>>>>> Why not do it like here (note, I dPREFIX rdf:
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>>> PREFIX cv:
>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>>
>>>> untitled-ontology-6#>
>>>>
>>>>> INSERT {
>>>>> ?ass cv:recorded_speed ?avg .
>>>>> }
>>>>> WHERE
>>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>>> WHERE
>>>>> { ?v cv:vehicleSpeed ?speed ;
>>>>> cv:Vehicle_Road ?r .
>>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>>> }
>>>>> GROUP BY ?r ?ass
>>>>> }on't know why you group by ?r instead of ?ass, thus, added both):
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
>>>>>
>>>>>> Didn't know attachments are not allowed.
>>>>>> This is a gist of the three files.
>>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
>>>>>>
>>>>>> The code files are minimalist as you can see on the gist. Only the
>>>>>>
>>>>> query is
>>>>> included and everything else is removed. I wanted to attach them as
>>>>> files
>>>>> to avoid clutter in the email. I believe things are more organized this
>>>>> way.
>>>>>> The problem is in b.java file. The c.java file is just to prove that
>>>>>> the
>>>>>> individual parts of the query work together. And the OWL file is the
>>>>>> one
>>>>>> generated by Protege. It has no problems, but I have removed anything
>>>>>>
>>>>> that
>>>>> is not needed for this specific query.
>>>>>> I have also attached a file called "ont.owl (full)" which has the full
>>>>>> ontology in case it is needed (which I think it is not needed, but just
>>>>>>
>>>>> in
>>>>> case I misunderstand).
>>>>>> Regards,
>>>>>>
>>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
>>>>>>
>>>>>> Attachments don't get through to this list.
>>>>>>> Put them in a pastebin or guithub gist.
>>>>>>>
>>>>>>> However, if they are so large that inlining email in plain text is
>>>>>>> impractical, than it suggests they are not minimal.
>>>>>>>
>>>>>>> Andy
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>>>>>>
>>>>>>> You forgot the attachments...
>>>>>>>>
>>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>>>>>>
>>>>>>>> Attached is a file of my code and my ontology which I have imported
>>>>>>>> on
>>>>> Eclipse.
>>>>>>>>> I have finally fixed the null values issue. I am not sure if I
>>>>>>>>> understood the cause of the nulls correctly. However, it got fixed
>>>>>>>>> when I used a different way of making the ResultSet as shown below:
>>>>>>>>>
>>>>>>>>> Query query = QueryFactory.create(queryString1);
>>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>>>>>>> ontologyModel);
>>>>>>>>> ResultSet results=qexec.execSelect();
>>>>>>>>> ResultSetFormatter.out(System.out, results, query);
>>>>>>>>> qexec.close();
>>>>>>>>> I am including this bit of code here in case this helps someone else
>>>>>>>>> in the future cause I could not find it easily. It can be found in
>>>>>>>>> context in the attached c.java file.
>>>>>>>>>
>>>>>>>>> However, the original bigger problem still persists. The insert
>>>>>>>>>
>>>>>>>> SPARQL
>>>>> query still does not result in inserting the new desired subject
>>>>>>>>> predicate object triple. No errors are generated which is I suppose
>>>>>>>>> a
>>>>>>>>> good thing, but when I print the ontology after running the query, I
>>>>>>>>> can see that the new triples are not added.
>>>>>>>>>
>>>>>>>>> Attached is the owl file and the java file (b.java). I have added
>>>>>>>>> explanatory comments in the java file hoping to clarify what I am
>>>>>>>>> trying to do here.
>>>>>>>>>
>>>>>>>>> Also, hoping to clarify matters a bit more, I have two average speed
>>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1
>>>>>>>>> with
>>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
>>>>>>>>> vehicleSpeed
>>>>>>>>> of 50. Only one vehicle is modeled to be located on each road in an
>>>>>>>>> attempt to simplify things for now.
>>>>>>>>>
>>>>>>>>> The goal is to calculate the average of speeds of all vehicles on
>>>>>>>>> road1 and assign it as the value of the object property called
>>>>>>>>> recorded_speed of the speed sensor attached to the road which the
>>>>>>>>> vehicles are on. Consequently, based on my modeling, after running
>>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since only
>>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is attached
>>>>>>>>>
>>>>>>>> and
>>>>> vehicle2 has speed of 50).
>>>>>>>>> Also, attached is another java file (c.java) that has the results of
>>>>>>>>> me breaking down the big query in b.java.
>>>>>>>>> My suspicion is that the part where I am trying to invoke the insert
>>>>>>>>> query is not working, but the way I built is based on StackOverflow
>>>>>>>>> and it was supposedly working fine, so I am not sure what I am
>>>>>>>>>
>>>>>>>> missing.
>>>>>>>>> Hope this gives you a picture of what is going on and hope you can
>>>>>>>>> help me understand why I cannot get the query to update the
>>>>>>>>> ontology.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>>>>>>> <buehmann@informatik.uni-leipzig.de
>>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>>>>>>
>>>>>>>>> If results are bound it can't be a null value. Please show
>>>>>>>>> your
>>>>>>>>> updated
>>>>>>>>> code.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is nit
>>>>>>>>> the
>>>>>>>>> cause of the
>>>>>>>>> > null. When I fixed it, the results of even the simplest
>>>>>>>>>
>>>>>>>> queries
>>>>> are still
>>>>>>>>> > nulls.
>>>>>>>>> >
>>>>>>>>> > The code is not generating errors though, it is not
>>>>>>>>> generating
>>>>>>>>> the proper
>>>>>>>>> > results ...
>>>>>>>>> >
>>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
>>>>>>>>>
>>>>>>>> andy@apache.org
>>>>> <ma...@apache.org>> wrote:
>>>>>>>>> >
>>>>>>>>> >>
>>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>>>>>>> >>
>>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking down
>>>>>>>>>
>>>>>>>> my
>>>>> chain of
>>>>>>>>> >>> thought into smaller pieces. Thank you so much.
>>>>>>>>> >>>
>>>>>>>>> >>> I saw an example online where the query syntax is written
>>>>>>>>>
>>>>>>>> as a
>>>>> string on
>>>>>>>>> >>> Jena. so my query now looks like this:
>>>>>>>>> >>>
>>>>>>>>> >> Use
>>>>>>>>> >>
>>>>>>>>> >> String.join("\n"
>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>>
>>>>>>>> 02/22-rdf-syntax-ns#
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>>
>>>>>>>> 02/22-rdf-syntax-ns#
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>>> >> , "INSERT {",
>>>>>>>>> >> ...
>>>>>>>>> >> , "}"
>>>>>>>>> >> );
>>>>>>>>> >>
>>>>>>>>> >> then you will have newlines in the string and parser errors
>>>>>>>>> will have
>>>>>>>>> >> line+column numbers that are useful.
>>>>>>>>> >>
>>>>>>>>> >> Andy
>>>>>>>>> >>
>>>>>>>>> >>
>>>>>>>>> >>
>>>>>>>>> >>> String queryString=
>>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>>> >>> "PREFIX cv:<
>>>>>>>>> >>>
>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>>>> ed-ontology-6#
>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>>>>>> led-ontology-6#>
>>>>>>>>> >>>> "+
>>>>>>>>> >>> "insert {"+
>>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>>>>>>> >>> "}"+
>>>>>>>>> >>> "WHERE {"+
>>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>>>>>>> >>> "where{"+
>>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
>>>>>>>>> >>> "{"+
>>>>>>>>> >>>
>>>>>>>>> >>> "SELECT ?r"+
>>>>>>>>> >>> "where{"+
>>>>>>>>> >>>
>>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>>>>>>> >>> "}"+
>>>>>>>>> >>> "}"+
>>>>>>>>> >>>
>>>>>>>>> >>>
>>>>>>>>> >>>
>>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>>>>>>> >>> "}";
>>>>>>>>> >>>
>>>>>>>>> >>> Then, also based on my research, I feed the query string
>>>>>>>>>
>>>>>>>> into
>>>>> the parser
>>>>>>>>> >>> and output the model.
>>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>>>>>>> >>> I encountered many errors but managed to get rid of them
>>>>>>>>>
>>>>>>>> all.
>>>>> However,
>>>>>>>>> >>> based on the output, nothing has changed. speedSensor1
>>>>>>>>> and
>>>>>>>>> speedSensor2
>>>>>>>>> >>> do
>>>>>>>>> >>> not have the recorded_speed property added.
>>>>>>>>> >>>
>>>>>>>>> >>> Of course, I tried debugging, but I could not get any
>>>>>>>>> understanding of the
>>>>>>>>> >>> problem.
>>>>>>>>> >>>
>>>>>>>>> >>>
>>>>>>>>> >>> 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#
>>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>>> >>> "PREFIX cv:<
>>>>>>>>> >>>
>>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>>>> ed-ontology-6#
>>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>>>>>> led-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");
>>>>> >>> 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 <
>>>>>>>>>
>>>>>>>> andy@apache.org
>>>>> <ma...@apache.org>> 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" <
>>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>>>>>>> <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/
>>>>>>>>> <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/
>>>>>>>>> <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/
>>>>>>>>> <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
>>>>>>>>> <andy@apache.org <ma...@apache.org>>
>>>>>>>>> >>>>>>> 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.
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>>>
>>>>>>>>> >>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
And I explained that using Lorenz's example syntax is something that I have
already tried before asking on the list and still the update to the owl
file does not take place. I mentioned that in my previous email.
I think the 2000+ lines u r mentioning are the full ontology file. I
mentioned that the file called ont.owl is the full one in case needed, but
I have already provided a short version called Yarab.owl .. Doubt that
Yarab.owl is 2000+ lines, it has the basic two sensors, two vehicles, two
roads instances and a couple of properties ..and it has lots of white lines
to separate the code to blocks for readability purposes. Which file did u
look at? I think u looked at the one I had described to be the full
ontology.
On Jun 9, 2017 6:50 PM, "Andy Seaborne" <an...@apache.org> wrote:
> " cv:Vehicle_Road ?r ;"+
>>
>
> Bad syntax. Replace ";" by "."
>
> Lorenz showed you the correct syntax.
>
> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>
>
> Print the query out and see what it looks like. Hence the earlier
> suggestion you put newlines in the query.
>
> Andy
>
> ~2800 lines is not a minimal example.
>
> On 09/06/17 15:53, Aya Hamdy wrote:
>
>> When I do not use the subselect and write the query this way:
>>
>> String queryString1 =
>> "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#
>> >"+
>> "INSERT {"+
>> " ?ass cv:recorded_speed ?avg"+
>> "}"+
>> "WHERE {"+
>> "SELECT (AVG(?speed) AS ?avg) {"+
>> "?v cv:vehicleSpeed ?speed;"+
>> " cv:Vehicle_Road ?r ;"+
>> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>>
>>
>>
>> "}"+ "GROUP BY ?r ?ass"+
>> "}";
>>
>> The code generates the error below when it tries to execute the update
>> action:
>> Exception in thread "main" org.apache.jena.query.QueryParseException:
>> Encountered " <VAR1> "?r "" at line 1, column 299.
>> Was expecting one of:
>> "values" ...
>> "graph" ...
>> "optional" ...
>> "minus" ...
>> "bind" ...
>> "service" ...
>> "filter" ...
>> "{" ...
>> "}" ...
>> ";" ...
>> "," ...
>> "." ...
>>
>> When I researched these options under "Was expecting one of:", I did not
>> find one of those options that would fit my query.
>> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to ensure
>> that the sensor is attached to the road on which the car is on.
>>
>> I group by ?r to try to ensure that the grouping is per road as well. But
>> I
>> think you have a point, and I should group by the sensor as well.
>>
>> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full stop
>> instead of a full stop the error goes away, but still, nothing happens in
>> the owl file. Meaning, the new tuple is not added either. (I am a bit
>> confused as to when to put a ";" and when to put a "." I believe, as far
>> as
>> my understanding goes, when I put a "." in the end of the
>> " cv:Vehicle_Road ?r " the error goes away because the last line "?ass
>> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place.
>> could
>> you confirm or negate that?)
>>
>> Your help is truly much appreciated.
>>
>> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
>> buehmann@informatik.uni-leipzig.de> wrote:
>>
>> There was some formatting issue in my previous mail.
>>>
>>> What I was wondering the need for grouping by ?r instead of ?ass.
>>>
>>> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>> PREFIX cv:
>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>> ed-ontology-6#
>>>
>>>>
>>>>
>>> INSERT {
>>> ?ass cv:recorded_speed ?avg .
>>> }
>>> WHERE
>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>> WHERE
>>> { ?v cv:vehicleSpeed ?speed ;
>>> cv:Vehicle_Road ?r .
>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>> }
>>> GROUP BY ?r ?ass
>>> }
>>>
>>>
>>>
>>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
>>>
>>>> That is your query:
>>>>
>>>> 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#>
>>>
>>>>
>>>> INSERT {
>>>> ?ass cv:recorded_speed ?avg .
>>>> }
>>>> WHERE
>>>> { SELECT (AVG(?speed) AS ?avg)
>>>> WHERE
>>>> { ?v cv:vehicleSpeed ?speed ;
>>>> cv:Vehicle_Road ?r
>>>> { SELECT ?r
>>>> WHERE
>>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
>>>> }
>>>> }
>>>> GROUP BY ?r
>>>> }
>>>>
>>>> The problem is that you use for what ever reason a sub-SELECT to get the
>>>> ?ass value. But this value is not propagated to the outer query, thus,
>>>> it's not bound to the INSERT part.
>>>>
>>>> Why not do it like here (note, I dPREFIX rdf:
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>>> PREFIX cv:
>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>>>>
>>> untitled-ontology-6#>
>>>
>>>>
>>>> INSERT {
>>>> ?ass cv:recorded_speed ?avg .
>>>> }
>>>> WHERE
>>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>>> WHERE
>>>> { ?v cv:vehicleSpeed ?speed ;
>>>> cv:Vehicle_Road ?r .
>>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>>> }
>>>> GROUP BY ?r ?ass
>>>> }on't know why you group by ?r instead of ?ass, thus, added both):
>>>>
>>>>
>>>>
>>>>
>>>> On 09.06.2017 14:22, Aya Hamdy wrote:
>>>>
>>>>> Didn't know attachments are not allowed.
>>>>> This is a gist of the three files.
>>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
>>>>>
>>>>> The code files are minimalist as you can see on the gist. Only the
>>>>>
>>>> query is
>>>
>>>> included and everything else is removed. I wanted to attach them as
>>>>>
>>>> files
>>>
>>>> to avoid clutter in the email. I believe things are more organized this
>>>>>
>>>> way.
>>>
>>>>
>>>>> The problem is in b.java file. The c.java file is just to prove that
>>>>> the
>>>>> individual parts of the query work together. And the OWL file is the
>>>>> one
>>>>> generated by Protege. It has no problems, but I have removed anything
>>>>>
>>>> that
>>>
>>>> is not needed for this specific query.
>>>>>
>>>>> I have also attached a file called "ont.owl (full)" which has the full
>>>>> ontology in case it is needed (which I think it is not needed, but just
>>>>>
>>>> in
>>>
>>>> case I misunderstand).
>>>>>
>>>>> Regards,
>>>>>
>>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
>>>>>
>>>>> Attachments don't get through to this list.
>>>>>>
>>>>>> Put them in a pastebin or guithub gist.
>>>>>>
>>>>>> However, if they are so large that inlining email in plain text is
>>>>>> impractical, than it suggests they are not minimal.
>>>>>>
>>>>>> Andy
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>>>>>
>>>>>> You forgot the attachments...
>>>>>>>
>>>>>>>
>>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>>>>>
>>>>>>> Attached is a file of my code and my ontology which I have imported
>>>>>>>>
>>>>>>> on
>>>
>>>> Eclipse.
>>>>>>>>
>>>>>>>> I have finally fixed the null values issue. I am not sure if I
>>>>>>>> understood the cause of the nulls correctly. However, it got fixed
>>>>>>>> when I used a different way of making the ResultSet as shown below:
>>>>>>>>
>>>>>>>> Query query = QueryFactory.create(queryString1);
>>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>>>>>> ontologyModel);
>>>>>>>> ResultSet results=qexec.execSelect();
>>>>>>>> ResultSetFormatter.out(System.out, results, query);
>>>>>>>> qexec.close();
>>>>>>>> I am including this bit of code here in case this helps someone else
>>>>>>>> in the future cause I could not find it easily. It can be found in
>>>>>>>> context in the attached c.java file.
>>>>>>>>
>>>>>>>> However, the original bigger problem still persists. The insert
>>>>>>>>
>>>>>>> SPARQL
>>>
>>>> query still does not result in inserting the new desired subject
>>>>>>>> predicate object triple. No errors are generated which is I suppose
>>>>>>>> a
>>>>>>>> good thing, but when I print the ontology after running the query, I
>>>>>>>> can see that the new triples are not added.
>>>>>>>>
>>>>>>>> Attached is the owl file and the java file (b.java). I have added
>>>>>>>> explanatory comments in the java file hoping to clarify what I am
>>>>>>>> trying to do here.
>>>>>>>>
>>>>>>>> Also, hoping to clarify matters a bit more, I have two average speed
>>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1
>>>>>>>> with
>>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with
>>>>>>>> vehicleSpeed
>>>>>>>> of 50. Only one vehicle is modeled to be located on each road in an
>>>>>>>> attempt to simplify things for now.
>>>>>>>>
>>>>>>>> The goal is to calculate the average of speeds of all vehicles on
>>>>>>>> road1 and assign it as the value of the object property called
>>>>>>>> recorded_speed of the speed sensor attached to the road which the
>>>>>>>> vehicles are on. Consequently, based on my modeling, after running
>>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since only
>>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is attached
>>>>>>>>
>>>>>>> and
>>>
>>>> vehicle2 has speed of 50).
>>>>>>>>
>>>>>>>> Also, attached is another java file (c.java) that has the results of
>>>>>>>> me breaking down the big query in b.java.
>>>>>>>> My suspicion is that the part where I am trying to invoke the insert
>>>>>>>> query is not working, but the way I built is based on StackOverflow
>>>>>>>> and it was supposedly working fine, so I am not sure what I am
>>>>>>>>
>>>>>>> missing.
>>>
>>>>
>>>>>>>> Hope this gives you a picture of what is going on and hope you can
>>>>>>>> help me understand why I cannot get the query to update the
>>>>>>>> ontology.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>>>>>> <buehmann@informatik.uni-leipzig.de
>>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>>>>>
>>>>>>>> If results are bound it can't be a null value. Please show
>>>>>>>> your
>>>>>>>> updated
>>>>>>>> code.
>>>>>>>>
>>>>>>>>
>>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>>>>>> > Sorry about the x, It was a stupid mistake. But it is nit
>>>>>>>> the
>>>>>>>> cause of the
>>>>>>>> > null. When I fixed it, the results of even the simplest
>>>>>>>>
>>>>>>> queries
>>>
>>>> are still
>>>>>>>> > nulls.
>>>>>>>> >
>>>>>>>> > The code is not generating errors though, it is not
>>>>>>>> generating
>>>>>>>> the proper
>>>>>>>> > results ...
>>>>>>>> >
>>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
>>>>>>>>
>>>>>>> andy@apache.org
>>>
>>>> <ma...@apache.org>> wrote:
>>>>>>>> >
>>>>>>>> >>
>>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>>>>>> >>
>>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking down
>>>>>>>>
>>>>>>> my
>>>
>>>> chain of
>>>>>>>> >>> thought into smaller pieces. Thank you so much.
>>>>>>>> >>>
>>>>>>>> >>> I saw an example online where the query syntax is written
>>>>>>>>
>>>>>>> as a
>>>
>>>> string on
>>>>>>>> >>> Jena. so my query now looks like this:
>>>>>>>> >>>
>>>>>>>> >> Use
>>>>>>>> >>
>>>>>>>> >> String.join("\n"
>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>
>>>>>>> 02/22-rdf-syntax-ns#
>>>
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>>>>>>>>
>>>>>>> 02/22-rdf-syntax-ns#
>>>
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>>> >> , "INSERT {",
>>>>>>>> >> ...
>>>>>>>> >> , "}"
>>>>>>>> >> );
>>>>>>>> >>
>>>>>>>> >> then you will have newlines in the string and parser errors
>>>>>>>> will have
>>>>>>>> >> line+column numbers that are useful.
>>>>>>>> >>
>>>>>>>> >> Andy
>>>>>>>> >>
>>>>>>>> >>
>>>>>>>> >>
>>>>>>>> >>> String queryString=
>>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>> >>> "PREFIX cv:<
>>>>>>>> >>>
>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>>> ed-ontology-6#
>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>>>>> led-ontology-6#>
>>>>>>>> >>>> "+
>>>>>>>> >>> "insert {"+
>>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>>>>>> >>> "}"+
>>>>>>>> >>> "WHERE {"+
>>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>>>>>> >>> "where{"+
>>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>>>>>> >>> " cv:Vehicle_Road ?r;"+
>>>>>>>> >>> "{"+
>>>>>>>> >>>
>>>>>>>> >>> "SELECT ?r"+
>>>>>>>> >>> "where{"+
>>>>>>>> >>>
>>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>>>>>> >>> "}"+
>>>>>>>> >>> "}"+
>>>>>>>> >>>
>>>>>>>> >>>
>>>>>>>> >>>
>>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>>>>>> >>> "}";
>>>>>>>> >>>
>>>>>>>> >>> Then, also based on my research, I feed the query string
>>>>>>>>
>>>>>>> into
>>>
>>>> the parser
>>>>>>>> >>> and output the model.
>>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>>>>>> >>> I encountered many errors but managed to get rid of them
>>>>>>>>
>>>>>>> all.
>>>
>>>> However,
>>>>>>>> >>> based on the output, nothing has changed. speedSensor1
>>>>>>>> and
>>>>>>>> speedSensor2
>>>>>>>> >>> do
>>>>>>>> >>> not have the recorded_speed property added.
>>>>>>>> >>>
>>>>>>>> >>> Of course, I tried debugging, but I could not get any
>>>>>>>> understanding of the
>>>>>>>> >>> problem.
>>>>>>>> >>>
>>>>>>>> >>>
>>>>>>>> >>> 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#
>>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>>> >>> "PREFIX cv:<
>>>>>>>> >>>
>>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>>> ed-ontology-6#
>>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>>>>> led-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");
>>>
>>>> >>> 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 <
>>>>>>>>
>>>>>>> andy@apache.org
>>>
>>>> <ma...@apache.org>> 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" <
>>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>>>>>> <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/
>>>>>>>> <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/
>>>>>>>> <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/
>>>>>>>> <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
>>>>>>>> <andy@apache.org <ma...@apache.org>>
>>>>>>>> >>>>>>> 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.
>>>>>>>> >>>>>>>>
>>>>>>>> >>>>>>>>
>>>>>>>> >>>>>>>>
>>>>>>>> >>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>
>>>
>>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Andy Seaborne <an...@apache.org>.
> " cv:Vehicle_Road ?r ;"+
Bad syntax. Replace ";" by "."
Lorenz showed you the correct syntax.
> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
Print the query out and see what it looks like. Hence the earlier
suggestion you put newlines in the query.
Andy
~2800 lines is not a minimal example.
On 09/06/17 15:53, Aya Hamdy wrote:
> When I do not use the subselect and write the query this way:
>
> String queryString1 =
> "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#>"+
> "INSERT {"+
> " ?ass cv:recorded_speed ?avg"+
> "}"+
> "WHERE {"+
> "SELECT (AVG(?speed) AS ?avg) {"+
> "?v cv:vehicleSpeed ?speed;"+
> " cv:Vehicle_Road ?r ;"+
> "?ass cv:avgSpeedSensor_Infrastructue ?r ."+
>
>
>
> "}"+ "GROUP BY ?r ?ass"+
> "}";
>
> The code generates the error below when it tries to execute the update
> action:
> Exception in thread "main" org.apache.jena.query.QueryParseException:
> Encountered " <VAR1> "?r "" at line 1, column 299.
> Was expecting one of:
> "values" ...
> "graph" ...
> "optional" ...
> "minus" ...
> "bind" ...
> "service" ...
> "filter" ...
> "{" ...
> "}" ...
> ";" ...
> "," ...
> "." ...
>
> When I researched these options under "Was expecting one of:", I did not
> find one of those options that would fit my query.
> I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to ensure
> that the sensor is attached to the road on which the car is on.
>
> I group by ?r to try to ensure that the grouping is per road as well. But I
> think you have a point, and I should group by the sensor as well.
>
> Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full stop
> instead of a full stop the error goes away, but still, nothing happens in
> the owl file. Meaning, the new tuple is not added either. (I am a bit
> confused as to when to put a ";" and when to put a "." I believe, as far as
> my understanding goes, when I put a "." in the end of the
> " cv:Vehicle_Road ?r " the error goes away because the last line "?ass
> cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place. could
> you confirm or negate that?)
>
> Your help is truly much appreciated.
>
> On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
> buehmann@informatik.uni-leipzig.de> wrote:
>
>> There was some formatting issue in my previous mail.
>>
>> What I was wondering the need for grouping by ?r instead of ?ass.
>>
>> 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#
>>>
>>
>> INSERT {
>> ?ass cv:recorded_speed ?avg .
>> }
>> WHERE
>> { SELECT ?ass (AVG(?speed) AS ?avg)
>> WHERE
>> { ?v cv:vehicleSpeed ?speed ;
>> cv:Vehicle_Road ?r .
>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>> }
>> GROUP BY ?r ?ass
>> }
>>
>>
>>
>> On 09.06.2017 16:29, Lorenz Buehmann wrote:
>>> That is your query:
>>>
>>> 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#>
>>>
>>> INSERT {
>>> ?ass cv:recorded_speed ?avg .
>>> }
>>> WHERE
>>> { SELECT (AVG(?speed) AS ?avg)
>>> WHERE
>>> { ?v cv:vehicleSpeed ?speed ;
>>> cv:Vehicle_Road ?r
>>> { SELECT ?r
>>> WHERE
>>> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
>>> }
>>> }
>>> GROUP BY ?r
>>> }
>>>
>>> The problem is that you use for what ever reason a sub-SELECT to get the
>>> ?ass value. But this value is not propagated to the outer query, thus,
>>> it's not bound to the INSERT part.
>>>
>>> Why not do it like here (note, I dPREFIX rdf:
>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
>>> PREFIX cv:
>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/
>> untitled-ontology-6#>
>>>
>>> INSERT {
>>> ?ass cv:recorded_speed ?avg .
>>> }
>>> WHERE
>>> { SELECT ?ass (AVG(?speed) AS ?avg)
>>> WHERE
>>> { ?v cv:vehicleSpeed ?speed ;
>>> cv:Vehicle_Road ?r .
>>> ?ass cv:avgSpeedSensor_Infrastructue ?r
>>> }
>>> GROUP BY ?r ?ass
>>> }on't know why you group by ?r instead of ?ass, thus, added both):
>>>
>>>
>>>
>>>
>>> On 09.06.2017 14:22, Aya Hamdy wrote:
>>>> Didn't know attachments are not allowed.
>>>> This is a gist of the three files.
>>>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
>>>>
>>>> The code files are minimalist as you can see on the gist. Only the
>> query is
>>>> included and everything else is removed. I wanted to attach them as
>> files
>>>> to avoid clutter in the email. I believe things are more organized this
>> way.
>>>>
>>>> The problem is in b.java file. The c.java file is just to prove that the
>>>> individual parts of the query work together. And the OWL file is the one
>>>> generated by Protege. It has no problems, but I have removed anything
>> that
>>>> is not needed for this specific query.
>>>>
>>>> I have also attached a file called "ont.owl (full)" which has the full
>>>> ontology in case it is needed (which I think it is not needed, but just
>> in
>>>> case I misunderstand).
>>>>
>>>> Regards,
>>>>
>>>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>>> Attachments don't get through to this list.
>>>>>
>>>>> Put them in a pastebin or guithub gist.
>>>>>
>>>>> However, if they are so large that inlining email in plain text is
>>>>> impractical, than it suggests they are not minimal.
>>>>>
>>>>> Andy
>>>>>
>>>>>
>>>>>
>>>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>>>>
>>>>>> You forgot the attachments...
>>>>>>
>>>>>>
>>>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>>>>
>>>>>>> Attached is a file of my code and my ontology which I have imported
>> on
>>>>>>> Eclipse.
>>>>>>>
>>>>>>> I have finally fixed the null values issue. I am not sure if I
>>>>>>> understood the cause of the nulls correctly. However, it got fixed
>>>>>>> when I used a different way of making the ResultSet as shown below:
>>>>>>>
>>>>>>> Query query = QueryFactory.create(queryString1);
>>>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>>>>> ontologyModel);
>>>>>>> ResultSet results=qexec.execSelect();
>>>>>>> ResultSetFormatter.out(System.out, results, query);
>>>>>>> qexec.close();
>>>>>>> I am including this bit of code here in case this helps someone else
>>>>>>> in the future cause I could not find it easily. It can be found in
>>>>>>> context in the attached c.java file.
>>>>>>>
>>>>>>> However, the original bigger problem still persists. The insert
>> SPARQL
>>>>>>> query still does not result in inserting the new desired subject
>>>>>>> predicate object triple. No errors are generated which is I suppose a
>>>>>>> good thing, but when I print the ontology after running the query, I
>>>>>>> can see that the new triples are not added.
>>>>>>>
>>>>>>> Attached is the owl file and the java file (b.java). I have added
>>>>>>> explanatory comments in the java file hoping to clarify what I am
>>>>>>> trying to do here.
>>>>>>>
>>>>>>> Also, hoping to clarify matters a bit more, I have two average speed
>>>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
>>>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
>>>>>>> of 50. Only one vehicle is modeled to be located on each road in an
>>>>>>> attempt to simplify things for now.
>>>>>>>
>>>>>>> The goal is to calculate the average of speeds of all vehicles on
>>>>>>> road1 and assign it as the value of the object property called
>>>>>>> recorded_speed of the speed sensor attached to the road which the
>>>>>>> vehicles are on. Consequently, based on my modeling, after running
>>>>>>> the query, speedSensor1 should have recorded_speed of 0 (since only
>>>>>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>>>>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>>>>>> (since only vehicle2 is on road2 to which speedSensor2 is attached
>> and
>>>>>>> vehicle2 has speed of 50).
>>>>>>>
>>>>>>> Also, attached is another java file (c.java) that has the results of
>>>>>>> me breaking down the big query in b.java.
>>>>>>> My suspicion is that the part where I am trying to invoke the insert
>>>>>>> query is not working, but the way I built is based on StackOverflow
>>>>>>> and it was supposedly working fine, so I am not sure what I am
>> missing.
>>>>>>>
>>>>>>> Hope this gives you a picture of what is going on and hope you can
>>>>>>> help me understand why I cannot get the query to update the ontology.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>>>>> <buehmann@informatik.uni-leipzig.de
>>>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>>>>
>>>>>>> If results are bound it can't be a null value. Please show your
>>>>>>> updated
>>>>>>> code.
>>>>>>>
>>>>>>>
>>>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>>>>> > Sorry about the x, It was a stupid mistake. But it is nit the
>>>>>>> cause of the
>>>>>>> > null. When I fixed it, the results of even the simplest
>> queries
>>>>>>> are still
>>>>>>> > nulls.
>>>>>>> >
>>>>>>> > The code is not generating errors though, it is not generating
>>>>>>> the proper
>>>>>>> > results ...
>>>>>>> >
>>>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
>> andy@apache.org
>>>>>>> <ma...@apache.org>> wrote:
>>>>>>> >
>>>>>>> >>
>>>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>>>>> >>
>>>>>>> >>> Ok. That sounds reasonable so I will work on breaking down
>> my
>>>>>>> chain of
>>>>>>> >>> thought into smaller pieces. Thank you so much.
>>>>>>> >>>
>>>>>>> >>> I saw an example online where the query syntax is written
>> as a
>>>>>>> string on
>>>>>>> >>> Jena. so my query now looks like this:
>>>>>>> >>>
>>>>>>> >> Use
>>>>>>> >>
>>>>>>> >> String.join("\n"
>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>> 02/22-rdf-syntax-ns#
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
>> 02/22-rdf-syntax-ns#
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>>>> >> , "INSERT {",
>>>>>>> >> ...
>>>>>>> >> , "}"
>>>>>>> >> );
>>>>>>> >>
>>>>>>> >> then you will have newlines in the string and parser errors
>>>>>>> will have
>>>>>>> >> line+column numbers that are useful.
>>>>>>> >>
>>>>>>> >> Andy
>>>>>>> >>
>>>>>>> >>
>>>>>>> >>
>>>>>>> >>> String queryString=
>>>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>> >>> "PREFIX cv:<
>>>>>>> >>>
>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>> ed-ontology-6#
>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>>>> led-ontology-6#>
>>>>>>> >>>> "+
>>>>>>> >>> "insert {"+
>>>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>>>>> >>> "}"+
>>>>>>> >>> "WHERE {"+
>>>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>>>>> >>> "where{"+
>>>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>>>>> >>> " cv:Vehicle_Road ?r;"+
>>>>>>> >>> "{"+
>>>>>>> >>>
>>>>>>> >>> "SELECT ?r"+
>>>>>>> >>> "where{"+
>>>>>>> >>>
>>>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>>>>> >>> "}"+
>>>>>>> >>> "}"+
>>>>>>> >>>
>>>>>>> >>>
>>>>>>> >>>
>>>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>>>>> >>> "}";
>>>>>>> >>>
>>>>>>> >>> Then, also based on my research, I feed the query string
>> into
>>>>>>> the parser
>>>>>>> >>> and output the model.
>>>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>>>>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>>>>> >>> I encountered many errors but managed to get rid of them
>> all.
>>>>>>> However,
>>>>>>> >>> based on the output, nothing has changed. speedSensor1 and
>>>>>>> speedSensor2
>>>>>>> >>> do
>>>>>>> >>> not have the recorded_speed property added.
>>>>>>> >>>
>>>>>>> >>> Of course, I tried debugging, but I could not get any
>>>>>>> understanding of the
>>>>>>> >>> problem.
>>>>>>> >>>
>>>>>>> >>>
>>>>>>> >>> 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#
>>>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>>>> >>> "PREFIX cv:<
>>>>>>> >>>
>>>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>>>> ed-ontology-6#
>>>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>>>> led-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");
>>>>>>> >>> 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 <
>> andy@apache.org
>>>>>>> <ma...@apache.org>> 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" <
>>>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>>>>> <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/
>>>>>>> <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/
>>>>>>> <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/
>>>>>>> <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
>>>>>>> <andy@apache.org <ma...@apache.org>>
>>>>>>> >>>>>>> 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.
>>>>>>> >>>>>>>>
>>>>>>> >>>>>>>>
>>>>>>> >>>>>>>>
>>>>>>> >>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>
>>
>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
When I do not use the subselect and write the query this way:
String queryString1 =
"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#>"+
"INSERT {"+
" ?ass cv:recorded_speed ?avg"+
"}"+
"WHERE {"+
"SELECT (AVG(?speed) AS ?avg) {"+
"?v cv:vehicleSpeed ?speed;"+
" cv:Vehicle_Road ?r ;"+
"?ass cv:avgSpeedSensor_Infrastructue ?r ."+
"}"+ "GROUP BY ?r ?ass"+
"}";
The code generates the error below when it tries to execute the update
action:
Exception in thread "main" org.apache.jena.query.QueryParseException:
Encountered " <VAR1> "?r "" at line 1, column 299.
Was expecting one of:
"values" ...
"graph" ...
"optional" ...
"minus" ...
"bind" ...
"service" ...
"filter" ...
"{" ...
"}" ...
";" ...
"," ...
"." ...
When I researched these options under "Was expecting one of:", I did not
find one of those options that would fit my query.
I need this line: "?ass cv:avgSpeedSensor_Infrastructue ?r ." to ensure
that the sensor is attached to the road on which the car is on.
I group by ?r to try to ensure that the grouping is per road as well. But I
think you have a point, and I should group by the sensor as well.
Note: when I write the " cv:Vehicle_Road ?r ;"+ line with a full stop
instead of a full stop the error goes away, but still, nothing happens in
the owl file. Meaning, the new tuple is not added either. (I am a bit
confused as to when to put a ";" and when to put a "." I believe, as far as
my understanding goes, when I put a "." in the end of the
" cv:Vehicle_Road ?r " the error goes away because the last line "?ass
cv:avgSpeedSensor_Infrastructue ?r ." is ignored in the first place. could
you confirm or negate that?)
Your help is truly much appreciated.
On Fri, Jun 9, 2017 at 2:30 PM, Lorenz Buehmann <
buehmann@informatik.uni-leipzig.de> wrote:
> There was some formatting issue in my previous mail.
>
> What I was wondering the need for grouping by ?r instead of ?ass.
>
> 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#
> >
>
> INSERT {
> ?ass cv:recorded_speed ?avg .
> }
> WHERE
> { SELECT ?ass (AVG(?speed) AS ?avg)
> WHERE
> { ?v cv:vehicleSpeed ?speed ;
> cv:Vehicle_Road ?r .
> ?ass cv:avgSpeedSensor_Infrastructue ?r
> }
> GROUP BY ?r ?ass
> }
>
>
>
> On 09.06.2017 16:29, Lorenz Buehmann wrote:
> > That is your query:
> >
> > 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#>
> >
> > INSERT {
> > ?ass cv:recorded_speed ?avg .
> > }
> > WHERE
> > { SELECT (AVG(?speed) AS ?avg)
> > WHERE
> > { ?v cv:vehicleSpeed ?speed ;
> > cv:Vehicle_Road ?r
> > { SELECT ?r
> > WHERE
> > { ?ass cv:avgSpeedSensor_Infrastructue ?r }
> > }
> > }
> > GROUP BY ?r
> > }
> >
> > The problem is that you use for what ever reason a sub-SELECT to get the
> > ?ass value. But this value is not propagated to the outer query, thus,
> > it's not bound to the INSERT part.
> >
> > Why not do it like here (note, I dPREFIX rdf:
> > <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> > PREFIX cv:
> > <http://www.semanticweb.org/toshiba/ontologies/2017/3/
> untitled-ontology-6#>
> >
> > INSERT {
> > ?ass cv:recorded_speed ?avg .
> > }
> > WHERE
> > { SELECT ?ass (AVG(?speed) AS ?avg)
> > WHERE
> > { ?v cv:vehicleSpeed ?speed ;
> > cv:Vehicle_Road ?r .
> > ?ass cv:avgSpeedSensor_Infrastructue ?r
> > }
> > GROUP BY ?r ?ass
> > }on't know why you group by ?r instead of ?ass, thus, added both):
> >
> >
> >
> >
> > On 09.06.2017 14:22, Aya Hamdy wrote:
> >> Didn't know attachments are not allowed.
> >> This is a gist of the three files.
> >> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
> >>
> >> The code files are minimalist as you can see on the gist. Only the
> query is
> >> included and everything else is removed. I wanted to attach them as
> files
> >> to avoid clutter in the email. I believe things are more organized this
> way.
> >>
> >> The problem is in b.java file. The c.java file is just to prove that the
> >> individual parts of the query work together. And the OWL file is the one
> >> generated by Protege. It has no problems, but I have removed anything
> that
> >> is not needed for this specific query.
> >>
> >> I have also attached a file called "ont.owl (full)" which has the full
> >> ontology in case it is needed (which I think it is not needed, but just
> in
> >> case I misunderstand).
> >>
> >> Regards,
> >>
> >> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
> >>
> >>> Attachments don't get through to this list.
> >>>
> >>> Put them in a pastebin or guithub gist.
> >>>
> >>> However, if they are so large that inlining email in plain text is
> >>> impractical, than it suggests they are not minimal.
> >>>
> >>> Andy
> >>>
> >>>
> >>>
> >>> On 09/06/17 07:06, Lorenz Buehmann wrote:
> >>>
> >>>> You forgot the attachments...
> >>>>
> >>>>
> >>>> On 09.06.2017 03:02, Aya Hamdy wrote:
> >>>>
> >>>>> Attached is a file of my code and my ontology which I have imported
> on
> >>>>> Eclipse.
> >>>>>
> >>>>> I have finally fixed the null values issue. I am not sure if I
> >>>>> understood the cause of the nulls correctly. However, it got fixed
> >>>>> when I used a different way of making the ResultSet as shown below:
> >>>>>
> >>>>> Query query = QueryFactory.create(queryString1);
> >>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
> >>>>> ontologyModel);
> >>>>> ResultSet results=qexec.execSelect();
> >>>>> ResultSetFormatter.out(System.out, results, query);
> >>>>> qexec.close();
> >>>>> I am including this bit of code here in case this helps someone else
> >>>>> in the future cause I could not find it easily. It can be found in
> >>>>> context in the attached c.java file.
> >>>>>
> >>>>> However, the original bigger problem still persists. The insert
> SPARQL
> >>>>> query still does not result in inserting the new desired subject
> >>>>> predicate object triple. No errors are generated which is I suppose a
> >>>>> good thing, but when I print the ontology after running the query, I
> >>>>> can see that the new triples are not added.
> >>>>>
> >>>>> Attached is the owl file and the java file (b.java). I have added
> >>>>> explanatory comments in the java file hoping to clarify what I am
> >>>>> trying to do here.
> >>>>>
> >>>>> Also, hoping to clarify matters a bit more, I have two average speed
> >>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
> >>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
> >>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
> >>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
> >>>>> of 50. Only one vehicle is modeled to be located on each road in an
> >>>>> attempt to simplify things for now.
> >>>>>
> >>>>> The goal is to calculate the average of speeds of all vehicles on
> >>>>> road1 and assign it as the value of the object property called
> >>>>> recorded_speed of the speed sensor attached to the road which the
> >>>>> vehicles are on. Consequently, based on my modeling, after running
> >>>>> the query, speedSensor1 should have recorded_speed of 0 (since only
> >>>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
> >>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
> >>>>> (since only vehicle2 is on road2 to which speedSensor2 is attached
> and
> >>>>> vehicle2 has speed of 50).
> >>>>>
> >>>>> Also, attached is another java file (c.java) that has the results of
> >>>>> me breaking down the big query in b.java.
> >>>>> My suspicion is that the part where I am trying to invoke the insert
> >>>>> query is not working, but the way I built is based on StackOverflow
> >>>>> and it was supposedly working fine, so I am not sure what I am
> missing.
> >>>>>
> >>>>> Hope this gives you a picture of what is going on and hope you can
> >>>>> help me understand why I cannot get the query to update the ontology.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
> >>>>> <buehmann@informatik.uni-leipzig.de
> >>>>> <ma...@informatik.uni-leipzig.de>> wrote:
> >>>>>
> >>>>> If results are bound it can't be a null value. Please show your
> >>>>> updated
> >>>>> code.
> >>>>>
> >>>>>
> >>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
> >>>>> > Sorry about the x, It was a stupid mistake. But it is nit the
> >>>>> cause of the
> >>>>> > null. When I fixed it, the results of even the simplest
> queries
> >>>>> are still
> >>>>> > nulls.
> >>>>> >
> >>>>> > The code is not generating errors though, it is not generating
> >>>>> the proper
> >>>>> > results ...
> >>>>> >
> >>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <
> andy@apache.org
> >>>>> <ma...@apache.org>> wrote:
> >>>>> >
> >>>>> >>
> >>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
> >>>>> >>
> >>>>> >>> Ok. That sounds reasonable so I will work on breaking down
> my
> >>>>> chain of
> >>>>> >>> thought into smaller pieces. Thank you so much.
> >>>>> >>>
> >>>>> >>> I saw an example online where the query syntax is written
> as a
> >>>>> string on
> >>>>> >>> Jena. so my query now looks like this:
> >>>>> >>>
> >>>>> >> Use
> >>>>> >>
> >>>>> >> String.join("\n"
> >>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> 02/22-rdf-syntax-ns#
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/
> 02/22-rdf-syntax-ns#
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >>>>> >> , "INSERT {",
> >>>>> >> ...
> >>>>> >> , "}"
> >>>>> >> );
> >>>>> >>
> >>>>> >> then you will have newlines in the string and parser errors
> >>>>> will have
> >>>>> >> line+column numbers that are useful.
> >>>>> >>
> >>>>> >> Andy
> >>>>> >>
> >>>>> >>
> >>>>> >>
> >>>>> >>> String queryString=
> >>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>> >>> "PREFIX cv:<
> >>>>> >>>
> >>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> >>>>> ed-ontology-6#
> >>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
> >>>>> led-ontology-6#>
> >>>>> >>>> "+
> >>>>> >>> "insert {"+
> >>>>> >>> " ?ass cv:recorded_speed ?avg"+
> >>>>> >>> "}"+
> >>>>> >>> "WHERE {"+
> >>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
> >>>>> >>> "where{"+
> >>>>> >>> " ?v rdf:type cv:Vehicle ;"+
> >>>>> >>> "cv:vehicleSpeed ?speed;"+
> >>>>> >>> " cv:Vehicle_Road ?r;"+
> >>>>> >>> "{"+
> >>>>> >>>
> >>>>> >>> "SELECT ?r"+
> >>>>> >>> "where{"+
> >>>>> >>>
> >>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> >>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
> >>>>> >>> "}"+
> >>>>> >>> "}"+
> >>>>> >>>
> >>>>> >>>
> >>>>> >>>
> >>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
> >>>>> >>> "}";
> >>>>> >>>
> >>>>> >>> Then, also based on my research, I feed the query string
> into
> >>>>> the parser
> >>>>> >>> and output the model.
> >>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
> >>>>> >>> ontologyModel.write( System.out, "TTL" );
> >>>>> >>> I encountered many errors but managed to get rid of them
> all.
> >>>>> However,
> >>>>> >>> based on the output, nothing has changed. speedSensor1 and
> >>>>> speedSensor2
> >>>>> >>> do
> >>>>> >>> not have the recorded_speed property added.
> >>>>> >>>
> >>>>> >>> Of course, I tried debugging, but I could not get any
> >>>>> understanding of the
> >>>>> >>> problem.
> >>>>> >>>
> >>>>> >>>
> >>>>> >>> 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#
> >>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>>>> >>> "PREFIX cv:<
> >>>>> >>>
> >>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
> >>>>> ed-ontology-6#
> >>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
> >>>>> led-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");
> >>>>> >>> 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 <
> andy@apache.org
> >>>>> <ma...@apache.org>> 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" <
> >>>>> >>>>> buehmann@informatik.uni-leipzig.de
> >>>>> <ma...@informatik.uni-leipzig.de>> 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/
> >>>>> <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/
> >>>>> <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/
> >>>>> <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/
> >>>>> <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
> >>>>> <andy@apache.org <ma...@apache.org>>
> >>>>> >>>>>>> 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.
> >>>>> >>>>>>>>
> >>>>> >>>>>>>>
> >>>>> >>>>>>>>
> >>>>> >>>>>>
> >>>>>
> >>>>>
> >>>>>
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
There was some formatting issue in my previous mail.
What I was wondering the need for grouping by ?r instead of ?ass.
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#>
INSERT {
?ass cv:recorded_speed ?avg .
}
WHERE
{ SELECT ?ass (AVG(?speed) AS ?avg)
WHERE
{ ?v cv:vehicleSpeed ?speed ;
cv:Vehicle_Road ?r .
?ass cv:avgSpeedSensor_Infrastructue ?r
}
GROUP BY ?r ?ass
}
On 09.06.2017 16:29, Lorenz Buehmann wrote:
> That is your query:
>
> 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#>
>
> INSERT {
> ?ass cv:recorded_speed ?avg .
> }
> WHERE
> { SELECT (AVG(?speed) AS ?avg)
> WHERE
> { ?v cv:vehicleSpeed ?speed ;
> cv:Vehicle_Road ?r
> { SELECT ?r
> WHERE
> { ?ass cv:avgSpeedSensor_Infrastructue ?r }
> }
> }
> GROUP BY ?r
> }
>
> The problem is that you use for what ever reason a sub-SELECT to get the
> ?ass value. But this value is not propagated to the outer query, thus,
> it's not bound to the INSERT part.
>
> Why not do it like here (note, I dPREFIX rdf:
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX cv:
> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>
>
> INSERT {
> ?ass cv:recorded_speed ?avg .
> }
> WHERE
> { SELECT ?ass (AVG(?speed) AS ?avg)
> WHERE
> { ?v cv:vehicleSpeed ?speed ;
> cv:Vehicle_Road ?r .
> ?ass cv:avgSpeedSensor_Infrastructue ?r
> }
> GROUP BY ?r ?ass
> }on't know why you group by ?r instead of ?ass, thus, added both):
>
>
>
>
> On 09.06.2017 14:22, Aya Hamdy wrote:
>> Didn't know attachments are not allowed.
>> This is a gist of the three files.
>> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
>>
>> The code files are minimalist as you can see on the gist. Only the query is
>> included and everything else is removed. I wanted to attach them as files
>> to avoid clutter in the email. I believe things are more organized this way.
>>
>> The problem is in b.java file. The c.java file is just to prove that the
>> individual parts of the query work together. And the OWL file is the one
>> generated by Protege. It has no problems, but I have removed anything that
>> is not needed for this specific query.
>>
>> I have also attached a file called "ont.owl (full)" which has the full
>> ontology in case it is needed (which I think it is not needed, but just in
>> case I misunderstand).
>>
>> Regards,
>>
>> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
>>
>>> Attachments don't get through to this list.
>>>
>>> Put them in a pastebin or guithub gist.
>>>
>>> However, if they are so large that inlining email in plain text is
>>> impractical, than it suggests they are not minimal.
>>>
>>> Andy
>>>
>>>
>>>
>>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>>
>>>> You forgot the attachments...
>>>>
>>>>
>>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>>
>>>>> Attached is a file of my code and my ontology which I have imported on
>>>>> Eclipse.
>>>>>
>>>>> I have finally fixed the null values issue. I am not sure if I
>>>>> understood the cause of the nulls correctly. However, it got fixed
>>>>> when I used a different way of making the ResultSet as shown below:
>>>>>
>>>>> Query query = QueryFactory.create(queryString1);
>>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>>> ontologyModel);
>>>>> ResultSet results=qexec.execSelect();
>>>>> ResultSetFormatter.out(System.out, results, query);
>>>>> qexec.close();
>>>>> I am including this bit of code here in case this helps someone else
>>>>> in the future cause I could not find it easily. It can be found in
>>>>> context in the attached c.java file.
>>>>>
>>>>> However, the original bigger problem still persists. The insert SPARQL
>>>>> query still does not result in inserting the new desired subject
>>>>> predicate object triple. No errors are generated which is I suppose a
>>>>> good thing, but when I print the ontology after running the query, I
>>>>> can see that the new triples are not added.
>>>>>
>>>>> Attached is the owl file and the java file (b.java). I have added
>>>>> explanatory comments in the java file hoping to clarify what I am
>>>>> trying to do here.
>>>>>
>>>>> Also, hoping to clarify matters a bit more, I have two average speed
>>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
>>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
>>>>> of 50. Only one vehicle is modeled to be located on each road in an
>>>>> attempt to simplify things for now.
>>>>>
>>>>> The goal is to calculate the average of speeds of all vehicles on
>>>>> road1 and assign it as the value of the object property called
>>>>> recorded_speed of the speed sensor attached to the road which the
>>>>> vehicles are on. Consequently, based on my modeling, after running
>>>>> the query, speedSensor1 should have recorded_speed of 0 (since only
>>>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>>>> (since only vehicle2 is on road2 to which speedSensor2 is attached and
>>>>> vehicle2 has speed of 50).
>>>>>
>>>>> Also, attached is another java file (c.java) that has the results of
>>>>> me breaking down the big query in b.java.
>>>>> My suspicion is that the part where I am trying to invoke the insert
>>>>> query is not working, but the way I built is based on StackOverflow
>>>>> and it was supposedly working fine, so I am not sure what I am missing.
>>>>>
>>>>> Hope this gives you a picture of what is going on and hope you can
>>>>> help me understand why I cannot get the query to update the ontology.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>>> <buehmann@informatik.uni-leipzig.de
>>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>>
>>>>> If results are bound it can't be a null value. Please show your
>>>>> updated
>>>>> code.
>>>>>
>>>>>
>>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>>> > Sorry about the x, It was a stupid mistake. But it is nit the
>>>>> cause of the
>>>>> > null. When I fixed it, the results of even the simplest queries
>>>>> are still
>>>>> > nulls.
>>>>> >
>>>>> > The code is not generating errors though, it is not generating
>>>>> the proper
>>>>> > results ...
>>>>> >
>>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <andy@apache.org
>>>>> <ma...@apache.org>> wrote:
>>>>> >
>>>>> >>
>>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>>> >>
>>>>> >>> Ok. That sounds reasonable so I will work on breaking down my
>>>>> chain of
>>>>> >>> thought into smaller pieces. Thank you so much.
>>>>> >>>
>>>>> >>> I saw an example online where the query syntax is written as a
>>>>> string on
>>>>> >>> Jena. so my query now looks like this:
>>>>> >>>
>>>>> >> Use
>>>>> >>
>>>>> >> String.join("\n"
>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>>> >> , "INSERT {",
>>>>> >> ...
>>>>> >> , "}"
>>>>> >> );
>>>>> >>
>>>>> >> then you will have newlines in the string and parser errors
>>>>> will have
>>>>> >> line+column numbers that are useful.
>>>>> >>
>>>>> >> Andy
>>>>> >>
>>>>> >>
>>>>> >>
>>>>> >>> String queryString=
>>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>> >>> "PREFIX cv:<
>>>>> >>>
>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>> ed-ontology-6#
>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>> led-ontology-6#>
>>>>> >>>> "+
>>>>> >>> "insert {"+
>>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>>> >>> "}"+
>>>>> >>> "WHERE {"+
>>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>>> >>> "where{"+
>>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>>> >>> " cv:Vehicle_Road ?r;"+
>>>>> >>> "{"+
>>>>> >>>
>>>>> >>> "SELECT ?r"+
>>>>> >>> "where{"+
>>>>> >>>
>>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>>> >>> "}"+
>>>>> >>> "}"+
>>>>> >>>
>>>>> >>>
>>>>> >>>
>>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>>> >>> "}";
>>>>> >>>
>>>>> >>> Then, also based on my research, I feed the query string into
>>>>> the parser
>>>>> >>> and output the model.
>>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>>> >>> I encountered many errors but managed to get rid of them all.
>>>>> However,
>>>>> >>> based on the output, nothing has changed. speedSensor1 and
>>>>> speedSensor2
>>>>> >>> do
>>>>> >>> not have the recorded_speed property added.
>>>>> >>>
>>>>> >>> Of course, I tried debugging, but I could not get any
>>>>> understanding of the
>>>>> >>> problem.
>>>>> >>>
>>>>> >>>
>>>>> >>> 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#
>>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>>> >>> "PREFIX cv:<
>>>>> >>>
>>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>>> ed-ontology-6#
>>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>>> led-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");
>>>>> >>> 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 <andy@apache.org
>>>>> <ma...@apache.org>> 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" <
>>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>>> <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/
>>>>> <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/
>>>>> <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/
>>>>> <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
>>>>> <andy@apache.org <ma...@apache.org>>
>>>>> >>>>>>> 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.
>>>>> >>>>>>>>
>>>>> >>>>>>>>
>>>>> >>>>>>>>
>>>>> >>>>>>
>>>>>
>>>>>
>>>>>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
That is your query:
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#>
INSERT {
?ass cv:recorded_speed ?avg .
}
WHERE
{ SELECT (AVG(?speed) AS ?avg)
WHERE
{ ?v cv:vehicleSpeed ?speed ;
cv:Vehicle_Road ?r
{ SELECT ?r
WHERE
{ ?ass cv:avgSpeedSensor_Infrastructue ?r }
}
}
GROUP BY ?r
}
The problem is that you use for what ever reason a sub-SELECT to get the
?ass value. But this value is not propagated to the outer query, thus,
it's not bound to the INSERT part.
Why not do it like here (note, I dPREFIX rdf:
<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX cv:
<http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>
INSERT {
?ass cv:recorded_speed ?avg .
}
WHERE
{ SELECT ?ass (AVG(?speed) AS ?avg)
WHERE
{ ?v cv:vehicleSpeed ?speed ;
cv:Vehicle_Road ?r .
?ass cv:avgSpeedSensor_Infrastructue ?r
}
GROUP BY ?r ?ass
}on't know why you group by ?r instead of ?ass, thus, added both):
On 09.06.2017 14:22, Aya Hamdy wrote:
> Didn't know attachments are not allowed.
> This is a gist of the three files.
> https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
>
> The code files are minimalist as you can see on the gist. Only the query is
> included and everything else is removed. I wanted to attach them as files
> to avoid clutter in the email. I believe things are more organized this way.
>
> The problem is in b.java file. The c.java file is just to prove that the
> individual parts of the query work together. And the OWL file is the one
> generated by Protege. It has no problems, but I have removed anything that
> is not needed for this specific query.
>
> I have also attached a file called "ont.owl (full)" which has the full
> ontology in case it is needed (which I think it is not needed, but just in
> case I misunderstand).
>
> Regards,
>
> On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
>
>> Attachments don't get through to this list.
>>
>> Put them in a pastebin or guithub gist.
>>
>> However, if they are so large that inlining email in plain text is
>> impractical, than it suggests they are not minimal.
>>
>> Andy
>>
>>
>>
>> On 09/06/17 07:06, Lorenz Buehmann wrote:
>>
>>> You forgot the attachments...
>>>
>>>
>>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>>
>>>> Attached is a file of my code and my ontology which I have imported on
>>>> Eclipse.
>>>>
>>>> I have finally fixed the null values issue. I am not sure if I
>>>> understood the cause of the nulls correctly. However, it got fixed
>>>> when I used a different way of making the ResultSet as shown below:
>>>>
>>>> Query query = QueryFactory.create(queryString1);
>>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>>> ontologyModel);
>>>> ResultSet results=qexec.execSelect();
>>>> ResultSetFormatter.out(System.out, results, query);
>>>> qexec.close();
>>>> I am including this bit of code here in case this helps someone else
>>>> in the future cause I could not find it easily. It can be found in
>>>> context in the attached c.java file.
>>>>
>>>> However, the original bigger problem still persists. The insert SPARQL
>>>> query still does not result in inserting the new desired subject
>>>> predicate object triple. No errors are generated which is I suppose a
>>>> good thing, but when I print the ontology after running the query, I
>>>> can see that the new triples are not added.
>>>>
>>>> Attached is the owl file and the java file (b.java). I have added
>>>> explanatory comments in the java file hoping to clarify what I am
>>>> trying to do here.
>>>>
>>>> Also, hoping to clarify matters a bit more, I have two average speed
>>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
>>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
>>>> of 50. Only one vehicle is modeled to be located on each road in an
>>>> attempt to simplify things for now.
>>>>
>>>> The goal is to calculate the average of speeds of all vehicles on
>>>> road1 and assign it as the value of the object property called
>>>> recorded_speed of the speed sensor attached to the road which the
>>>> vehicles are on. Consequently, based on my modeling, after running
>>>> the query, speedSensor1 should have recorded_speed of 0 (since only
>>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>>> (since only vehicle2 is on road2 to which speedSensor2 is attached and
>>>> vehicle2 has speed of 50).
>>>>
>>>> Also, attached is another java file (c.java) that has the results of
>>>> me breaking down the big query in b.java.
>>>> My suspicion is that the part where I am trying to invoke the insert
>>>> query is not working, but the way I built is based on StackOverflow
>>>> and it was supposedly working fine, so I am not sure what I am missing.
>>>>
>>>> Hope this gives you a picture of what is going on and hope you can
>>>> help me understand why I cannot get the query to update the ontology.
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>>> <buehmann@informatik.uni-leipzig.de
>>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>>
>>>> If results are bound it can't be a null value. Please show your
>>>> updated
>>>> code.
>>>>
>>>>
>>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>>> > Sorry about the x, It was a stupid mistake. But it is nit the
>>>> cause of the
>>>> > null. When I fixed it, the results of even the simplest queries
>>>> are still
>>>> > nulls.
>>>> >
>>>> > The code is not generating errors though, it is not generating
>>>> the proper
>>>> > results ...
>>>> >
>>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <andy@apache.org
>>>> <ma...@apache.org>> wrote:
>>>> >
>>>> >>
>>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>>> >>
>>>> >>> Ok. That sounds reasonable so I will work on breaking down my
>>>> chain of
>>>> >>> thought into smaller pieces. Thank you so much.
>>>> >>>
>>>> >>> I saw an example online where the query syntax is written as a
>>>> string on
>>>> >>> Jena. so my query now looks like this:
>>>> >>>
>>>> >> Use
>>>> >>
>>>> >> String.join("\n"
>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>>> >> , "INSERT {",
>>>> >> ...
>>>> >> , "}"
>>>> >> );
>>>> >>
>>>> >> then you will have newlines in the string and parser errors
>>>> will have
>>>> >> line+column numbers that are useful.
>>>> >>
>>>> >> Andy
>>>> >>
>>>> >>
>>>> >>
>>>> >>> String queryString=
>>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>> >>> "PREFIX cv:<
>>>> >>>
>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>> ed-ontology-6#
>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>> led-ontology-6#>
>>>> >>>> "+
>>>> >>> "insert {"+
>>>> >>> " ?ass cv:recorded_speed ?avg"+
>>>> >>> "}"+
>>>> >>> "WHERE {"+
>>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>>> >>> "where{"+
>>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>>> >>> "cv:vehicleSpeed ?speed;"+
>>>> >>> " cv:Vehicle_Road ?r;"+
>>>> >>> "{"+
>>>> >>>
>>>> >>> "SELECT ?r"+
>>>> >>> "where{"+
>>>> >>>
>>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>> >>> "}"+
>>>> >>> "}"+
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>>> >>> "}";
>>>> >>>
>>>> >>> Then, also based on my research, I feed the query string into
>>>> the parser
>>>> >>> and output the model.
>>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>>>> >>> ontologyModel.write( System.out, "TTL" );
>>>> >>> I encountered many errors but managed to get rid of them all.
>>>> However,
>>>> >>> based on the output, nothing has changed. speedSensor1 and
>>>> speedSensor2
>>>> >>> do
>>>> >>> not have the recorded_speed property added.
>>>> >>>
>>>> >>> Of course, I tried debugging, but I could not get any
>>>> understanding of the
>>>> >>> problem.
>>>> >>>
>>>> >>>
>>>> >>> 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#
>>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>>> >>> "PREFIX cv:<
>>>> >>>
>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>>> ed-ontology-6#
>>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>>> led-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");
>>>> >>> 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 <andy@apache.org
>>>> <ma...@apache.org>> 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" <
>>>> >>>>> buehmann@informatik.uni-leipzig.de
>>>> <ma...@informatik.uni-leipzig.de>> 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/
>>>> <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/
>>>> <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/
>>>> <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/
>>>> <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
>>>> <andy@apache.org <ma...@apache.org>>
>>>> >>>>>>> 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.
>>>> >>>>>>>>
>>>> >>>>>>>>
>>>> >>>>>>>>
>>>> >>>>>>
>>>>
>>>>
>>>>
>>>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Didn't know attachments are not allowed.
This is a gist of the three files.
https://gist.github.com/AyazzHamdy/faa14ebf46b0fe32689edc808dbf85d9
The code files are minimalist as you can see on the gist. Only the query is
included and everything else is removed. I wanted to attach them as files
to avoid clutter in the email. I believe things are more organized this way.
The problem is in b.java file. The c.java file is just to prove that the
individual parts of the query work together. And the OWL file is the one
generated by Protege. It has no problems, but I have removed anything that
is not needed for this specific query.
I have also attached a file called "ont.owl (full)" which has the full
ontology in case it is needed (which I think it is not needed, but just in
case I misunderstand).
Regards,
On Fri, Jun 9, 2017 at 8:47 AM, Andy Seaborne <an...@apache.org> wrote:
> Attachments don't get through to this list.
>
> Put them in a pastebin or guithub gist.
>
> However, if they are so large that inlining email in plain text is
> impractical, than it suggests they are not minimal.
>
> Andy
>
>
>
> On 09/06/17 07:06, Lorenz Buehmann wrote:
>
>> You forgot the attachments...
>>
>>
>> On 09.06.2017 03:02, Aya Hamdy wrote:
>>
>>> Attached is a file of my code and my ontology which I have imported on
>>> Eclipse.
>>>
>>> I have finally fixed the null values issue. I am not sure if I
>>> understood the cause of the nulls correctly. However, it got fixed
>>> when I used a different way of making the ResultSet as shown below:
>>>
>>> Query query = QueryFactory.create(queryString1);
>>> QueryExecution qexec= QueryExecutionFactory.create(query,
>>> ontologyModel);
>>> ResultSet results=qexec.execSelect();
>>> ResultSetFormatter.out(System.out, results, query);
>>> qexec.close();
>>> I am including this bit of code here in case this helps someone else
>>> in the future cause I could not find it easily. It can be found in
>>> context in the attached c.java file.
>>>
>>> However, the original bigger problem still persists. The insert SPARQL
>>> query still does not result in inserting the new desired subject
>>> predicate object triple. No errors are generated which is I suppose a
>>> good thing, but when I print the ontology after running the query, I
>>> can see that the new triples are not added.
>>>
>>> Attached is the owl file and the java file (b.java). I have added
>>> explanatory comments in the java file hoping to clarify what I am
>>> trying to do here.
>>>
>>> Also, hoping to clarify matters a bit more, I have two average speed
>>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>>> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
>>> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
>>> of 50. Only one vehicle is modeled to be located on each road in an
>>> attempt to simplify things for now.
>>>
>>> The goal is to calculate the average of speeds of all vehicles on
>>> road1 and assign it as the value of the object property called
>>> recorded_speed of the speed sensor attached to the road which the
>>> vehicles are on. Consequently, based on my modeling, after running
>>> the query, speedSensor1 should have recorded_speed of 0 (since only
>>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>>> (since only vehicle2 is on road2 to which speedSensor2 is attached and
>>> vehicle2 has speed of 50).
>>>
>>> Also, attached is another java file (c.java) that has the results of
>>> me breaking down the big query in b.java.
>>> My suspicion is that the part where I am trying to invoke the insert
>>> query is not working, but the way I built is based on StackOverflow
>>> and it was supposedly working fine, so I am not sure what I am missing.
>>>
>>> Hope this gives you a picture of what is going on and hope you can
>>> help me understand why I cannot get the query to update the ontology.
>>>
>>>
>>>
>>>
>>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>>> <buehmann@informatik.uni-leipzig.de
>>> <ma...@informatik.uni-leipzig.de>> wrote:
>>>
>>> If results are bound it can't be a null value. Please show your
>>> updated
>>> code.
>>>
>>>
>>> On 07.06.2017 14:58, Aya Hamdy wrote:
>>> > Sorry about the x, It was a stupid mistake. But it is nit the
>>> cause of the
>>> > null. When I fixed it, the results of even the simplest queries
>>> are still
>>> > nulls.
>>> >
>>> > The code is not generating errors though, it is not generating
>>> the proper
>>> > results ...
>>> >
>>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <andy@apache.org
>>> <ma...@apache.org>> wrote:
>>> >
>>> >>
>>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>>> >>
>>> >>> Ok. That sounds reasonable so I will work on breaking down my
>>> chain of
>>> >>> thought into smaller pieces. Thank you so much.
>>> >>>
>>> >>> I saw an example online where the query syntax is written as a
>>> string on
>>> >>> Jena. so my query now looks like this:
>>> >>>
>>> >> Use
>>> >>
>>> >> String.join("\n"
>>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>>> >> , "INSERT {",
>>> >> ...
>>> >> , "}"
>>> >> );
>>> >>
>>> >> then you will have newlines in the string and parser errors
>>> will have
>>> >> line+column numbers that are useful.
>>> >>
>>> >> Andy
>>> >>
>>> >>
>>> >>
>>> >>> String queryString=
>>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>> >>> "PREFIX cv:<
>>> >>>
>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>> ed-ontology-6#
>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>> led-ontology-6#>
>>> >>>> "+
>>> >>> "insert {"+
>>> >>> " ?ass cv:recorded_speed ?avg"+
>>> >>> "}"+
>>> >>> "WHERE {"+
>>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>>> >>> "where{"+
>>> >>> " ?v rdf:type cv:Vehicle ;"+
>>> >>> "cv:vehicleSpeed ?speed;"+
>>> >>> " cv:Vehicle_Road ?r;"+
>>> >>> "{"+
>>> >>>
>>> >>> "SELECT ?r"+
>>> >>> "where{"+
>>> >>>
>>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>> >>> "}"+
>>> >>> "}"+
>>> >>>
>>> >>>
>>> >>>
>>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>>> >>> "}";
>>> >>>
>>> >>> Then, also based on my research, I feed the query string into
>>> the parser
>>> >>> and output the model.
>>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>>> >>> ontologyModel.write( System.out, "TTL" );
>>> >>> I encountered many errors but managed to get rid of them all.
>>> However,
>>> >>> based on the output, nothing has changed. speedSensor1 and
>>> speedSensor2
>>> >>> do
>>> >>> not have the recorded_speed property added.
>>> >>>
>>> >>> Of course, I tried debugging, but I could not get any
>>> understanding of the
>>> >>> problem.
>>> >>>
>>> >>>
>>> >>> 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#
>>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>>> >>> "PREFIX cv:<
>>> >>>
>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitl
>>> ed-ontology-6#
>>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untit
>>> led-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");
>>> >>> 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 <andy@apache.org
>>> <ma...@apache.org>> 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" <
>>> >>>>> buehmann@informatik.uni-leipzig.de
>>> <ma...@informatik.uni-leipzig.de>> 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/
>>> <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/
>>> <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/
>>> <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/
>>> <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
>>> <andy@apache.org <ma...@apache.org>>
>>> >>>>>>> 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.
>>> >>>>>>>>
>>> >>>>>>>>
>>> >>>>>>>>
>>> >>>>>>
>>>
>>>
>>>
>>
>>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Andy Seaborne <an...@apache.org>.
Attachments don't get through to this list.
Put them in a pastebin or guithub gist.
However, if they are so large that inlining email in plain text is
impractical, than it suggests they are not minimal.
Andy
On 09/06/17 07:06, Lorenz Buehmann wrote:
> You forgot the attachments...
>
>
> On 09.06.2017 03:02, Aya Hamdy wrote:
>> Attached is a file of my code and my ontology which I have imported on
>> Eclipse.
>>
>> I have finally fixed the null values issue. I am not sure if I
>> understood the cause of the nulls correctly. However, it got fixed
>> when I used a different way of making the ResultSet as shown below:
>>
>> Query query = QueryFactory.create(queryString1);
>> QueryExecution qexec= QueryExecutionFactory.create(query, ontologyModel);
>> ResultSet results=qexec.execSelect();
>> ResultSetFormatter.out(System.out, results, query);
>> qexec.close();
>> I am including this bit of code here in case this helps someone else
>> in the future cause I could not find it easily. It can be found in
>> context in the attached c.java file.
>>
>> However, the original bigger problem still persists. The insert SPARQL
>> query still does not result in inserting the new desired subject
>> predicate object triple. No errors are generated which is I suppose a
>> good thing, but when I print the ontology after running the query, I
>> can see that the new triples are not added.
>>
>> Attached is the owl file and the java file (b.java). I have added
>> explanatory comments in the java file hoping to clarify what I am
>> trying to do here.
>>
>> Also, hoping to clarify matters a bit more, I have two average speed
>> sensors (speedSensor1 and speedSensor2) and I have two vehicles
>> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
>> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
>> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
>> of 50. Only one vehicle is modeled to be located on each road in an
>> attempt to simplify things for now.
>>
>> The goal is to calculate the average of speeds of all vehicles on
>> road1 and assign it as the value of the object property called
>> recorded_speed of the speed sensor attached to the road which the
>> vehicles are on. Consequently, based on my modeling, after running
>> the query, speedSensor1 should have recorded_speed of 0 (since only
>> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
>> has speed of 0) and speedSensor2 should have recorded_speed of 50
>> (since only vehicle2 is on road2 to which speedSensor2 is attached and
>> vehicle2 has speed of 50).
>>
>> Also, attached is another java file (c.java) that has the results of
>> me breaking down the big query in b.java.
>> My suspicion is that the part where I am trying to invoke the insert
>> query is not working, but the way I built is based on StackOverflow
>> and it was supposedly working fine, so I am not sure what I am missing.
>>
>> Hope this gives you a picture of what is going on and hope you can
>> help me understand why I cannot get the query to update the ontology.
>>
>>
>>
>>
>> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
>> <buehmann@informatik.uni-leipzig.de
>> <ma...@informatik.uni-leipzig.de>> wrote:
>>
>> If results are bound it can't be a null value. Please show your
>> updated
>> code.
>>
>>
>> On 07.06.2017 14:58, Aya Hamdy wrote:
>> > Sorry about the x, It was a stupid mistake. But it is nit the
>> cause of the
>> > null. When I fixed it, the results of even the simplest queries
>> are still
>> > nulls.
>> >
>> > The code is not generating errors though, it is not generating
>> the proper
>> > results ...
>> >
>> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <andy@apache.org
>> <ma...@apache.org>> wrote:
>> >
>> >>
>> >> On 06/06/17 00:26, Aya Hamdy wrote:
>> >>
>> >>> Ok. That sounds reasonable so I will work on breaking down my
>> chain of
>> >>> thought into smaller pieces. Thank you so much.
>> >>>
>> >>> I saw an example online where the query syntax is written as a
>> string on
>> >>> Jena. so my query now looks like this:
>> >>>
>> >> Use
>> >>
>> >> String.join("\n"
>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
>> >> , "INSERT {",
>> >> ...
>> >> , "}"
>> >> );
>> >>
>> >> then you will have newlines in the string and parser errors
>> will have
>> >> line+column numbers that are useful.
>> >>
>> >> Andy
>> >>
>> >>
>> >>
>> >>> String queryString=
>> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>> >>> "PREFIX cv:<
>> >>>
>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#
>> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>
>> >>>> "+
>> >>> "insert {"+
>> >>> " ?ass cv:recorded_speed ?avg"+
>> >>> "}"+
>> >>> "WHERE {"+
>> >>> "SELECT (AVG(?speed) AS ?avg) "+
>> >>> "where{"+
>> >>> " ?v rdf:type cv:Vehicle ;"+
>> >>> "cv:vehicleSpeed ?speed;"+
>> >>> " cv:Vehicle_Road ?r;"+
>> >>> "{"+
>> >>>
>> >>> "SELECT ?r"+
>> >>> "where{"+
>> >>>
>> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
>> >>> "}"+
>> >>> "}"+
>> >>>
>> >>>
>> >>>
>> >>> "}"+"GROUP By ?ass ?avg ?r"+
>> >>> "}";
>> >>>
>> >>> Then, also based on my research, I feed the query string into
>> the parser
>> >>> and output the model.
>> >>> UpdateAction.parseExecute( queryString, ontologyModel );
>> >>> ontologyModel.write( System.out, "TTL" );
>> >>> I encountered many errors but managed to get rid of them all.
>> However,
>> >>> based on the output, nothing has changed. speedSensor1 and
>> speedSensor2
>> >>> do
>> >>> not have the recorded_speed property added.
>> >>>
>> >>> Of course, I tried debugging, but I could not get any
>> understanding of the
>> >>> problem.
>> >>>
>> >>>
>> >>> 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#
>> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
>> >>> "PREFIX cv:<
>> >>>
>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#
>> <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");
>> >>> 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 <andy@apache.org
>> <ma...@apache.org>> 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" <
>> >>>>> buehmann@informatik.uni-leipzig.de
>> <ma...@informatik.uni-leipzig.de>> 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/
>> <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/
>> <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/
>> <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/
>> <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
>> <andy@apache.org <ma...@apache.org>>
>> >>>>>>> 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.
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>>>
>> >>>>>>
>>
>>
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
You forgot the attachments...
On 09.06.2017 03:02, Aya Hamdy wrote:
> Attached is a file of my code and my ontology which I have imported on
> Eclipse.
>
> I have finally fixed the null values issue. I am not sure if I
> understood the cause of the nulls correctly. However, it got fixed
> when I used a different way of making the ResultSet as shown below:
>
> Query query = QueryFactory.create(queryString1);
> QueryExecution qexec= QueryExecutionFactory.create(query, ontologyModel);
> ResultSet results=qexec.execSelect();
> ResultSetFormatter.out(System.out, results, query);
> qexec.close();
> I am including this bit of code here in case this helps someone else
> in the future cause I could not find it easily. It can be found in
> context in the attached c.java file.
>
> However, the original bigger problem still persists. The insert SPARQL
> query still does not result in inserting the new desired subject
> predicate object triple. No errors are generated which is I suppose a
> good thing, but when I print the ontology after running the query, I
> can see that the new triples are not added.
>
> Attached is the owl file and the java file (b.java). I have added
> explanatory comments in the java file hoping to clarify what I am
> trying to do here.
>
> Also, hoping to clarify matters a bit more, I have two average speed
> sensors (speedSensor1 and speedSensor2) and I have two vehicles
> (vehicle1 and vehicle2). speedSensor1 is attached to Road1 and
> speedSensor2 is attached to Road2. vehicle1 is located on Road1 with
> vehicleSpeed of 0 and vehicle2 is located on Road2 with vehicleSpeed
> of 50. Only one vehicle is modeled to be located on each road in an
> attempt to simplify things for now.
>
> The goal is to calculate the average of speeds of all vehicles on
> road1 and assign it as the value of the object property called
> recorded_speed of the speed sensor attached to the road which the
> vehicles are on. Consequently, based on my modeling, after running
> the query, speedSensor1 should have recorded_speed of 0 (since only
> vehicle1 is on road1 to which speedSensor1 is attached and vehicle1
> has speed of 0) and speedSensor2 should have recorded_speed of 50
> (since only vehicle2 is on road2 to which speedSensor2 is attached and
> vehicle2 has speed of 50).
>
> Also, attached is another java file (c.java) that has the results of
> me breaking down the big query in b.java.
> My suspicion is that the part where I am trying to invoke the insert
> query is not working, but the way I built is based on StackOverflow
> and it was supposedly working fine, so I am not sure what I am missing.
>
> Hope this gives you a picture of what is going on and hope you can
> help me understand why I cannot get the query to update the ontology.
>
>
>
>
> On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann
> <buehmann@informatik.uni-leipzig.de
> <ma...@informatik.uni-leipzig.de>> wrote:
>
> If results are bound it can't be a null value. Please show your
> updated
> code.
>
>
> On 07.06.2017 14:58, Aya Hamdy wrote:
> > Sorry about the x, It was a stupid mistake. But it is nit the
> cause of the
> > null. When I fixed it, the results of even the simplest queries
> are still
> > nulls.
> >
> > The code is not generating errors though, it is not generating
> the proper
> > results ...
> >
> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <andy@apache.org
> <ma...@apache.org>> wrote:
> >
> >>
> >> On 06/06/17 00:26, Aya Hamdy wrote:
> >>
> >>> Ok. That sounds reasonable so I will work on breaking down my
> chain of
> >>> thought into smaller pieces. Thank you so much.
> >>>
> >>> I saw an example online where the query syntax is written as a
> string on
> >>> Jena. so my query now looks like this:
> >>>
> >> Use
> >>
> >> String.join("\n"
> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"
> >> , "INSERT {",
> >> ...
> >> , "}"
> >> );
> >>
> >> then you will have newlines in the string and parser errors
> will have
> >> line+column numbers that are useful.
> >>
> >> Andy
> >>
> >>
> >>
> >>> String queryString=
> >>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>> "PREFIX cv:<
> >>>
> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#
> <http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>
> >>>> "+
> >>> "insert {"+
> >>> " ?ass cv:recorded_speed ?avg"+
> >>> "}"+
> >>> "WHERE {"+
> >>> "SELECT (AVG(?speed) AS ?avg) "+
> >>> "where{"+
> >>> " ?v rdf:type cv:Vehicle ;"+
> >>> "cv:vehicleSpeed ?speed;"+
> >>> " cv:Vehicle_Road ?r;"+
> >>> "{"+
> >>>
> >>> "SELECT ?r"+
> >>> "where{"+
> >>>
> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
> >>> "}"+
> >>> "}"+
> >>>
> >>>
> >>>
> >>> "}"+"GROUP By ?ass ?avg ?r"+
> >>> "}";
> >>>
> >>> Then, also based on my research, I feed the query string into
> the parser
> >>> and output the model.
> >>> UpdateAction.parseExecute( queryString, ontologyModel );
> >>> ontologyModel.write( System.out, "TTL" );
> >>> I encountered many errors but managed to get rid of them all.
> However,
> >>> based on the output, nothing has changed. speedSensor1 and
> speedSensor2
> >>> do
> >>> not have the recorded_speed property added.
> >>>
> >>> Of course, I tried debugging, but I could not get any
> understanding of the
> >>> problem.
> >>>
> >>>
> >>> 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#
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#>>"+
> >>> "PREFIX cv:<
> >>>
> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#
> <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");
> >>> 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 <andy@apache.org
> <ma...@apache.org>> 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" <
> >>>>> buehmann@informatik.uni-leipzig.de
> <ma...@informatik.uni-leipzig.de>> 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/
> <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/
> <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/
> <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/
> <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
> <andy@apache.org <ma...@apache.org>>
> >>>>>>> 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.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>
>
>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Attached is a file of my code and my ontology which I have imported on
Eclipse.
I have finally fixed the null values issue. I am not sure if I understood
the cause of the nulls correctly. However, it got fixed when I used a
different way of making the ResultSet as shown below:
Query query = QueryFactory.create(queryString1);
QueryExecution qexec= QueryExecutionFactory.create(query, ontologyModel);
ResultSet results=qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
qexec.close();
I am including this bit of code here in case this helps someone else in the
future cause I could not find it easily. It can be found in context in the
attached c.java file.
However, the original bigger problem still persists. The insert SPARQL
query still does not result in inserting the new desired subject predicate
object triple. No errors are generated which is I suppose a good thing, but
when I print the ontology after running the query, I can see that the new
triples are not added.
Attached is the owl file and the java file (b.java). I have added
explanatory comments in the java file hoping to clarify what I am trying to
do here.
Also, hoping to clarify matters a bit more, I have two average speed
sensors (speedSensor1 and speedSensor2) and I have two vehicles (vehicle1
and vehicle2). speedSensor1 is attached to Road1 and speedSensor2 is
attached to Road2. vehicle1 is located on Road1 with vehicleSpeed of 0
and vehicle2 is located on Road2 with vehicleSpeed of 50. Only one vehicle
is modeled to be located on each road in an attempt to simplify things for
now.
The goal is to calculate the average of speeds of all vehicles on road1 and
assign it as the value of the object property called recorded_speed of the
speed sensor attached to the road which the vehicles are on. Consequently,
based on my modeling, after running the query, speedSensor1 should have
recorded_speed of 0 (since only vehicle1 is on road1 to which speedSensor1
is attached and vehicle1 has speed of 0) and speedSensor2 should have
recorded_speed of 50 (since only vehicle2 is on road2 to which speedSensor2
is attached and vehicle2 has speed of 50).
Also, attached is another java file (c.java) that has the results of me
breaking down the big query in b.java.
My suspicion is that the part where I am trying to invoke the insert query
is not working, but the way I built is based on StackOverflow and it was
supposedly working fine, so I am not sure what I am missing.
Hope this gives you a picture of what is going on and hope you can help me
understand why I cannot get the query to update the ontology.
On Thu, Jun 8, 2017 at 5:29 PM, Lorenz Buehmann <
buehmann@informatik.uni-leipzig.de> wrote:
> If results are bound it can't be a null value. Please show your updated
> code.
>
>
> On 07.06.2017 14:58, Aya Hamdy wrote:
> > Sorry about the x, It was a stupid mistake. But it is nit the cause of
> the
> > null. When I fixed it, the results of even the simplest queries are still
> > nulls.
> >
> > The code is not generating errors though, it is not generating the proper
> > results ...
> >
> > On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <an...@apache.org> wrote:
> >
> >>
> >> On 06/06/17 00:26, Aya Hamdy wrote:
> >>
> >>> Ok. That sounds reasonable so I will work on breaking down my chain of
> >>> thought into smaller pieces. Thank you so much.
> >>>
> >>> I saw an example online where the query syntax is written as a string
> on
> >>> Jena. so my query now looks like this:
> >>>
> >> Use
> >>
> >> String.join("\n"
> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
> >> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
> >> , "INSERT {",
> >> ...
> >> , "}"
> >> );
> >>
> >> then you will have newlines in the string and parser errors will have
> >> line+column numbers that are useful.
> >>
> >> Andy
> >>
> >>
> >>
> >>> String queryString=
> >>> "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#
> >>>> "+
> >>> "insert {"+
> >>> " ?ass cv:recorded_speed ?avg"+
> >>> "}"+
> >>> "WHERE {"+
> >>> "SELECT (AVG(?speed) AS ?avg) "+
> >>> "where{"+
> >>> " ?v rdf:type cv:Vehicle ;"+
> >>> "cv:vehicleSpeed ?speed;"+
> >>> " cv:Vehicle_Road ?r;"+
> >>> "{"+
> >>>
> >>> "SELECT ?r"+
> >>> "where{"+
> >>>
> >>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> >>> " cv:avgSpeedSensor_Infrastructure ?r"+
> >>> "}"+
> >>> "}"+
> >>>
> >>>
> >>>
> >>> "}"+"GROUP By ?ass ?avg ?r"+
> >>> "}";
> >>>
> >>> Then, also based on my research, I feed the query string into the
> parser
> >>> and output the model.
> >>> UpdateAction.parseExecute( queryString, ontologyModel );
> >>> ontologyModel.write( System.out, "TTL" );
> >>> I encountered many errors but managed to get rid of them all. However,
> >>> based on the output, nothing has changed. speedSensor1 and
> speedSensor2
> >>> do
> >>> not have the recorded_speed property added.
> >>>
> >>> Of course, I tried debugging, but I could not get any understanding of
> the
> >>> problem.
> >>>
> >>>
> >>> 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");
> >>> 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 <an...@apache.org> 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" <
> >>>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org>
> >>>>>>> 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.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
If results are bound it can't be a null value. Please show your updated
code.
On 07.06.2017 14:58, Aya Hamdy wrote:
> Sorry about the x, It was a stupid mistake. But it is nit the cause of the
> null. When I fixed it, the results of even the simplest queries are still
> nulls.
>
> The code is not generating errors though, it is not generating the proper
> results ...
>
> On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <an...@apache.org> wrote:
>
>>
>> On 06/06/17 00:26, Aya Hamdy wrote:
>>
>>> Ok. That sounds reasonable so I will work on breaking down my chain of
>>> thought into smaller pieces. Thank you so much.
>>>
>>> I saw an example online where the query syntax is written as a string on
>>> Jena. so my query now looks like this:
>>>
>> Use
>>
>> String.join("\n"
>> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
>> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
>> , "INSERT {",
>> ...
>> , "}"
>> );
>>
>> then you will have newlines in the string and parser errors will have
>> line+column numbers that are useful.
>>
>> Andy
>>
>>
>>
>>> String queryString=
>>> "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#
>>>> "+
>>> "insert {"+
>>> " ?ass cv:recorded_speed ?avg"+
>>> "}"+
>>> "WHERE {"+
>>> "SELECT (AVG(?speed) AS ?avg) "+
>>> "where{"+
>>> " ?v rdf:type cv:Vehicle ;"+
>>> "cv:vehicleSpeed ?speed;"+
>>> " cv:Vehicle_Road ?r;"+
>>> "{"+
>>>
>>> "SELECT ?r"+
>>> "where{"+
>>>
>>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>> "}"+
>>> "}"+
>>>
>>>
>>>
>>> "}"+"GROUP By ?ass ?avg ?r"+
>>> "}";
>>>
>>> Then, also based on my research, I feed the query string into the parser
>>> and output the model.
>>> UpdateAction.parseExecute( queryString, ontologyModel );
>>> ontologyModel.write( System.out, "TTL" );
>>> I encountered many errors but managed to get rid of them all. However,
>>> based on the output, nothing has changed. speedSensor1 and speedSensor2
>>> do
>>> not have the recorded_speed property added.
>>>
>>> Of course, I tried debugging, but I could not get any understanding of the
>>> problem.
>>>
>>>
>>> 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");
>>> 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 <an...@apache.org> 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" <
>>>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org>
>>>>>>> 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.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
Ehm, no - why? It's a local ontology.
On 07.06.2017 15:04, Aya Hamdy wrote:
> Does the ontology have to be posted online for instance? I found on
> StackOverflow that the URI I assign to the prefix does not have to be a
> real one. Therefore the URI for the PREFIX cv:
> "PREFIX cv:<
> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>"
> is the one generated by Protege. Did I misunderstand what I read and the
> ontology needs to be posted publically online?
>
> It is just that I think that the problem may be that in the queries the
> PREFIX called cv may be perceived as empty by the code or something.
>
> On Wed, Jun 7, 2017 at 12:58 PM, Aya Hamdy <ay...@gmail.com> wrote:
>
>> Sorry about the x, It was a stupid mistake. But it is nit the cause of the
>> null. When I fixed it, the results of even the simplest queries are still
>> nulls.
>>
>> The code is not generating errors though, it is not generating the proper
>> results ...
>>
>> On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <an...@apache.org> wrote:
>>
>>>
>>> On 06/06/17 00:26, Aya Hamdy wrote:
>>>
>>>> Ok. That sounds reasonable so I will work on breaking down my chain of
>>>> thought into smaller pieces. Thank you so much.
>>>>
>>>> I saw an example online where the query syntax is written as a string on
>>>> Jena. so my query now looks like this:
>>>>
>>> Use
>>>
>>> String.join("\n"
>>> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
>>> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
>>> , "INSERT {",
>>> ...
>>> , "}"
>>> );
>>>
>>> then you will have newlines in the string and parser errors will have
>>> line+column numbers that are useful.
>>>
>>> Andy
>>>
>>>
>>>
>>>> String queryString=
>>>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
>>>> "PREFIX cv:<
>>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitle
>>>> d-ontology-6#>"+
>>>> "insert {"+
>>>> " ?ass cv:recorded_speed ?avg"+
>>>> "}"+
>>>> "WHERE {"+
>>>> "SELECT (AVG(?speed) AS ?avg) "+
>>>> "where{"+
>>>> " ?v rdf:type cv:Vehicle ;"+
>>>> "cv:vehicleSpeed ?speed;"+
>>>> " cv:Vehicle_Road ?r;"+
>>>> "{"+
>>>>
>>>> "SELECT ?r"+
>>>> "where{"+
>>>>
>>>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>>> "}"+
>>>> "}"+
>>>>
>>>>
>>>>
>>>> "}"+"GROUP By ?ass ?avg ?r"+
>>>> "}";
>>>>
>>>> Then, also based on my research, I feed the query string into the parser
>>>> and output the model.
>>>> UpdateAction.parseExecute( queryString, ontologyModel );
>>>> ontologyModel.write( System.out, "TTL" );
>>>> I encountered many errors but managed to get rid of them all. However,
>>>> based on the output, nothing has changed. speedSensor1 and
>>>> speedSensor2 do
>>>> not have the recorded_speed property added.
>>>>
>>>> Of course, I tried debugging, but I could not get any understanding of
>>>> the
>>>> problem.
>>>>
>>>>
>>>> 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/untitle
>>>> d-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");
>>>> 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 <an...@apache.org> 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" <
>>>>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org>
>>>>>>>> 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.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Does the ontology have to be posted online for instance? I found on
StackOverflow that the URI I assign to the prefix does not have to be a
real one. Therefore the URI for the PREFIX cv:
"PREFIX cv:<
http://www.semanticweb.org/toshiba/ontologies/2017/3/untitled-ontology-6#>"
is the one generated by Protege. Did I misunderstand what I read and the
ontology needs to be posted publically online?
It is just that I think that the problem may be that in the queries the
PREFIX called cv may be perceived as empty by the code or something.
On Wed, Jun 7, 2017 at 12:58 PM, Aya Hamdy <ay...@gmail.com> wrote:
> Sorry about the x, It was a stupid mistake. But it is nit the cause of the
> null. When I fixed it, the results of even the simplest queries are still
> nulls.
>
> The code is not generating errors though, it is not generating the proper
> results ...
>
> On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <an...@apache.org> wrote:
>
>>
>>
>> On 06/06/17 00:26, Aya Hamdy wrote:
>>
>>> Ok. That sounds reasonable so I will work on breaking down my chain of
>>> thought into smaller pieces. Thank you so much.
>>>
>>> I saw an example online where the query syntax is written as a string on
>>> Jena. so my query now looks like this:
>>>
>>
>> Use
>>
>> String.join("\n"
>> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
>> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
>> , "INSERT {",
>> ...
>> , "}"
>> );
>>
>> then you will have newlines in the string and parser errors will have
>> line+column numbers that are useful.
>>
>> Andy
>>
>>
>>
>>> String queryString=
>>> "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
>>> "PREFIX cv:<
>>> http://www.semanticweb.org/toshiba/ontologies/2017/3/untitle
>>> d-ontology-6#>"+
>>> "insert {"+
>>> " ?ass cv:recorded_speed ?avg"+
>>> "}"+
>>> "WHERE {"+
>>> "SELECT (AVG(?speed) AS ?avg) "+
>>> "where{"+
>>> " ?v rdf:type cv:Vehicle ;"+
>>> "cv:vehicleSpeed ?speed;"+
>>> " cv:Vehicle_Road ?r;"+
>>> "{"+
>>>
>>> "SELECT ?r"+
>>> "where{"+
>>>
>>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>>> " cv:avgSpeedSensor_Infrastructure ?r"+
>>> "}"+
>>> "}"+
>>>
>>>
>>>
>>> "}"+"GROUP By ?ass ?avg ?r"+
>>> "}";
>>>
>>> Then, also based on my research, I feed the query string into the parser
>>> and output the model.
>>> UpdateAction.parseExecute( queryString, ontologyModel );
>>> ontologyModel.write( System.out, "TTL" );
>>> I encountered many errors but managed to get rid of them all. However,
>>> based on the output, nothing has changed. speedSensor1 and
>>> speedSensor2 do
>>> not have the recorded_speed property added.
>>>
>>> Of course, I tried debugging, but I could not get any understanding of
>>> the
>>> problem.
>>>
>>>
>>> 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/untitle
>>> d-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");
>>> 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 <an...@apache.org> 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" <
>>>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org>
>>>>>>> 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.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Sorry about the x, It was a stupid mistake. But it is nit the cause of the
null. When I fixed it, the results of even the simplest queries are still
nulls.
The code is not generating errors though, it is not generating the proper
results ...
On Tue, Jun 6, 2017 at 9:13 AM, Andy Seaborne <an...@apache.org> wrote:
>
>
> On 06/06/17 00:26, Aya Hamdy wrote:
>
>> Ok. That sounds reasonable so I will work on breaking down my chain of
>> thought into smaller pieces. Thank you so much.
>>
>> I saw an example online where the query syntax is written as a string on
>> Jena. so my query now looks like this:
>>
>
> Use
>
> String.join("\n"
> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
> , "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
> , "INSERT {",
> ...
> , "}"
> );
>
> then you will have newlines in the string and parser errors will have
> line+column numbers that are useful.
>
> Andy
>
>
>
>> String queryString=
>> "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#
>> >"+
>> "insert {"+
>> " ?ass cv:recorded_speed ?avg"+
>> "}"+
>> "WHERE {"+
>> "SELECT (AVG(?speed) AS ?avg) "+
>> "where{"+
>> " ?v rdf:type cv:Vehicle ;"+
>> "cv:vehicleSpeed ?speed;"+
>> " cv:Vehicle_Road ?r;"+
>> "{"+
>>
>> "SELECT ?r"+
>> "where{"+
>>
>> "?ass rdf:type cv:Avg_Speed_Sensor;"+
>> " cv:avgSpeedSensor_Infrastructure ?r"+
>> "}"+
>> "}"+
>>
>>
>>
>> "}"+"GROUP By ?ass ?avg ?r"+
>> "}";
>>
>> Then, also based on my research, I feed the query string into the parser
>> and output the model.
>> UpdateAction.parseExecute( queryString, ontologyModel );
>> ontologyModel.write( System.out, "TTL" );
>> I encountered many errors but managed to get rid of them all. However,
>> based on the output, nothing has changed. speedSensor1 and speedSensor2
>> do
>> not have the recorded_speed property added.
>>
>> Of course, I tried debugging, but I could not get any understanding of the
>> problem.
>>
>>
>> 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");
>> 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 <an...@apache.org> 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" <
>>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org>
>>>>>> 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.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>
>>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Andy Seaborne <an...@apache.org>.
On 06/06/17 00:26, Aya Hamdy wrote:
> Ok. That sounds reasonable so I will work on breaking down my chain of
> thought into smaller pieces. Thank you so much.
>
> I saw an example online where the query syntax is written as a string on
> Jena. so my query now looks like this:
Use
String.join("\n"
, "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "INSERT {",
...
, "}"
);
then you will have newlines in the string and parser errors will have
line+column numbers that are useful.
Andy
>
> String queryString=
> "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#>"+
> "insert {"+
> " ?ass cv:recorded_speed ?avg"+
> "}"+
> "WHERE {"+
> "SELECT (AVG(?speed) AS ?avg) "+
> "where{"+
> " ?v rdf:type cv:Vehicle ;"+
> "cv:vehicleSpeed ?speed;"+
> " cv:Vehicle_Road ?r;"+
> "{"+
>
> "SELECT ?r"+
> "where{"+
>
> "?ass rdf:type cv:Avg_Speed_Sensor;"+
> " cv:avgSpeedSensor_Infrastructure ?r"+
> "}"+
> "}"+
>
>
>
> "}"+"GROUP By ?ass ?avg ?r"+
> "}";
>
> Then, also based on my research, I feed the query string into the parser
> and output the model.
> UpdateAction.parseExecute( queryString, ontologyModel );
> ontologyModel.write( System.out, "TTL" );
> I encountered many errors but managed to get rid of them all. However,
> based on the output, nothing has changed. speedSensor1 and speedSensor2 do
> not have the recorded_speed property added.
>
> Of course, I tried debugging, but I could not get any understanding of the
> problem.
>
>
> 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");
> 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 <an...@apache.org> 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" <
>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org> 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.
>>>>>>
>>>>>>
>>>>
>>>>
>>>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
> 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 <an...@apache.org> 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" <
>>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org> 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.
>>>>>>
>>>>>>
>>>>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
Ok. That sounds reasonable so I will work on breaking down my chain of
thought into smaller pieces. Thank you so much.
I saw an example online where the query syntax is written as a string on
Jena. so my query now looks like this:
String queryString=
"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#>"+
"insert {"+
" ?ass cv:recorded_speed ?avg"+
"}"+
"WHERE {"+
"SELECT (AVG(?speed) AS ?avg) "+
"where{"+
" ?v rdf:type cv:Vehicle ;"+
"cv:vehicleSpeed ?speed;"+
" cv:Vehicle_Road ?r;"+
"{"+
"SELECT ?r"+
"where{"+
"?ass rdf:type cv:Avg_Speed_Sensor;"+
" cv:avgSpeedSensor_Infrastructure ?r"+
"}"+
"}"+
"}"+"GROUP By ?ass ?avg ?r"+
"}";
Then, also based on my research, I feed the query string into the parser
and output the model.
UpdateAction.parseExecute( queryString, ontologyModel );
ontologyModel.write( System.out, "TTL" );
I encountered many errors but managed to get rid of them all. However,
based on the output, nothing has changed. speedSensor1 and speedSensor2 do
not have the recorded_speed property added.
Of course, I tried debugging, but I could not get any understanding of the
problem.
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");
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 <an...@apache.org> 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" <
>> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org> 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.
>>>>>
>>>>>
>>>
>>>
>>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Andy Seaborne <an...@apache.org>.
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" <
> buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org> 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.
>>>>
>>
>>
>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
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" <
buehmann@informatik.uni-leipzig.de> 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 <an...@apache.org> 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.
> >>
>
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
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 <an...@apache.org> 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.
>>
Re: Sparql Update: Insert a property whose value is a calculated average
Posted by Aya Hamdy <ay...@gmail.com>.
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 <an...@apache.org> 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.
>
Re: Sparql Update: Insert a property whose value is a calculated
average
Posted by Andy Seaborne <an...@apache.org>.
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.