1

For my project in GraphDB 9.4.1 I created a repository with owl rl (optimized).

In my data I need to query the average value of a data property. When I follow the steps according to SPARQL instruction, the result is empty. I used the following Query:

PREFIX : <http://www.BLB.de/Ontologie#>
select ?s (AVG(?TP) as ?AP) where { 
?s a :MachinestatusID .
?s :hastotalpower_Kalender ?TP.
?s <http://www.BLB.de/Ontologie#Is_switched_on_Kalender> ?K
} Group by ?s ?K 

Result:

s                                                     AP
http://www.BLB.de/Daten/Anlagenstatus/id/1  
http://www.BLB.de/Daten/Anlagenstatus/id/2  
http://www.BLB.de/Daten/Anlagenstatus/id/3  

To validate the data, I already selected the data without the aggregate function. Al ?TP are values between 0 and 5000. There is no data format specified. ?K is 1 or 0. Due to GraphDB documentation AVG function is support.

s                                           TP      K
http://www.BLB.de/Daten/Anlagenstatus/id/1  4186    1
http://www.BLB.de/Daten/Anlagenstatus/id/2  4183    1
http://www.BLB.de/Daten/Anlagenstatus/id/3  4177    1
http://www.BLB.de/Daten/Anlagenstatus/id/4  4171    1

Is there any solution to get the real average as output?

PhilippGr
  • 76
  • 6
  • the query looks correct. With empty you mean no results at all? What does `select ?s ?TP where { ?s a :MachinestatusID . ?s :hastotalpower_Kalender ?TP. ?s ?K }` return? – UninformedUser Jan 12 '21 at 10:06
  • Here is the first values of the select query: s TP K http://www.BLB.de/Daten/Anlagenstatus/id/1 4186 1 http://www.BLB.de/Daten/Anlagenstatus/id/2 4183 1 http://www.BLB.de/Daten/Anlagenstatus/id/3 4177 1 http://www.BLB.de/Daten/Anlagenstatus/id/4 4171 1 http://www.BLB.de/Daten/Anlagenstatus/id/5 4167 1 I only use ?K to simplify the query. In the original i used another pattern to order the IDs. Exactly the AVG doesn't show anything at all. Like this: s AP http://www.BLB.de/Daten/Anlagenstatus/id/1 http://www.BLB.de/Daten/Anlagenstatus/id/2 – PhilippGr Jan 12 '21 at 10:18
  • 2
    just to clarify, "nothing" is for me "no rows at all". I don't mean nothing for column AP. What is the datatype of the `?TP` values? is it a numerical datatype? can you try `(AVG(xsd:integer(?TP)) as ?AP)` please? – UninformedUser Jan 12 '21 at 10:45
  • Thanks alot! Problem solved with the extension. It seems i can't mark it as answered because it is commented or im a new contributor. – PhilippGr Jan 12 '21 at 12:38
  • hm, but this leads me to the question: 1) what is the datatype of the literals in your data? or 2) is there some data where no such `?TP` exist? Because otherwise, explicit casting shouldn't be necessary – UninformedUser Jan 12 '21 at 13:33
  • you can also create an answer and accept your own answer - this is fine. – UninformedUser Jan 12 '21 at 13:34
  • The data isnt't cast as any Data Type. I transformed .csv files with OntoRefine without spezifing the data type. All Values are between 0 and 5000. There is no NULL or empty values. – PhilippGr Jan 12 '21 at 14:56
  • hm, ok. But in OntoRefine you're able to set datatypes: https://graphdb.ontotext.com/documentation/free/loading-data-using-ontorefine.html - this way sound more correct in my opinion. Everything starts with the data, so try to generate it as "good" as possible. Datatype for literals are very helpful for many things – UninformedUser Jan 12 '21 at 15:27

1 Answers1

2

The data format of ?TP needed to be casted explizitly. Modifing the average function to the following solved the problem:

(AVG(xsd:integer(?TP)) as ?AP)
PhilippGr
  • 76
  • 6