Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
944 views
in Technique[技术] by (71.8m points)

sparql - Aggregate Function AVG in GraphDB

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...