RE: Complex SPARQL Query

2017-03-15 Thread Ullah, Izhar
Well, you are right, I'll get the desired output using your method but the 
question arises then why don't/can't I use the MAX() function here to get the 
same result.

Best,

Izhar

From: Lorenz B. [buehm...@informatik.uni-leipzig.de]
Sent: 15 March 2017 07:15
To: users@jena.apache.org
Subject: Re: Complex SPARQL Query

Sure, you don't need grouping here. You could just use ORDER BY
ASC(?nodecount) LIMIT 1, i.e. sorting in the other direction and just
take the first result.

> Hi Lorenz,
>
> Yes, that's true but I can't retrieve all features along with their number of 
> sensing nodes. So, when I run one sub-query separately I get the correct 
> number of nodes in that feature.
>
> I slightly changed my ontology and then ran the following query against my 
> ontology file:
>
> SELECT?feature (MAX(?nodecount) AS ?featuremaxnodes)  WHERE {
>
>   {
>   SELECT  ?feature(COUNT(?node) AS ?nodecount) WHERE {
>
>   ?featurerdf:typeenviot:Field ;
>   ssn:hasDeployment   ?node .
>   ?node   rdf:typeenviot:SoilSensingNode .
>
>   }
>   GROUP BY ?feature
>   ORDER BY DESC(?nodecount)
>}
>   }
>   GROUP BY ?feature
>   ORDER BY DESC(?nodecount)
>
> The output of the above query is:
>
>
>  feature   featuremaxnodes
>
> 1 enviot:A_Hilltop "3"^^xsd:integer
>
> 2 enviot:A_Riverbank   "5"^^xsd:integer
>
> 3 enviot:A_Swale   "7"^^xsd:integer
>
> Now I am very close to my desired output but still not getting it i.e. I need 
> to show the feature having maximum number of nodes. In other words, I need to 
> show the following:
>
>  feature   featuremaxnodes
>
> enviot:A_Swale "7"^^xsd:integer
>
> Any idea how to get the above output?
>
> Many thanks for your time, help and patience.
>
> Best regards,
>
> Izhar
> 
> From: Lorenz B. [buehm...@informatik.uni-leipzig.de]
> Sent: 14 March 2017 06:56
> To: users@jena.apache.org
> Subject: Re: Complex SPARQL Query
>
> Just to clarify, each of the sub-SELECT queries returns the number of
> nodes for the features Hilltop, Riverbank and Swale, right? And if you
> run such a SELECT query separately, the number is correct?
>> Dear Lorenz,
>>
>> Apologies for the belated reply, for I was travelling, arrived today.
>>
>> Let me post the whole question again below:
>>
>> I have a question related to SPARQL query which is a bit complex one. I 
>> would appreciate if someone could help me out. I have 15 Sensing Nodes with 
>> their corresponding Point(longitude latitude) geometries given below:
>>
>> Table 1: Showing results from 1 to 15 of 15. Query took 0.127 s.
>>
>> node gwkt
>>
>> enviot:A0_SoilSensingNode"POINT(-3.783065 
>> 53.202158)"^^
>> enviot:A1_SoilSensingNode "POINT(-3.782898 
>> 53.201828)"^^
>> enviot:A2_SoilSensingNode"POINT(-3.783092 
>> 53.202007)"^^
>> enviot:A3_SoilSensingNode "POINT(-3.781964 
>> 53.201765)"^^
>> enviot:A5_SoilSensingNode  "POINT(-3.783055 
>> 53.202777)"^^
>> enviot:A6_SoilSensingNode  "POINT(-3.78 
>> 53.202777)"^^
>> enviot:A7_SoilSensingNode "POINT(-3.78 
>> 53.202777)"^^
>> enviot:A8_SoilSensingNode  "POINT(-3.780833 
>> 53.203055)"^^
>> enviot:A9_SoilSensingNode  "POINT(-3.780833 
>> 53.20)"^^
>> enviot:AA_SoilSensingNode "POINT(-3.783063 
>> 53.202309)"^^
>> enviot:AB_SoilSensingNode "POINT(-3.782638 
>> 53.202189)"^^
>> enviot:AC_SoilSensingNode "POINT(-3.783003 
>> 53.202191)"^^
>> enviot:AD_SoilSensingNode "POINT(-3.782518 
>> 53.201841)"^^
>> enviot:AE_SoilSensingNode  "POINT(-3.782024 
>> 53.202193)"^^
>> enviot:AF_SoilSensingNode  "POINT(-3.782877 
>> 53.201788)"^^
>>
>> These sensing nodes are deployed in a field having three features named 
>> Hilltop (it has 3 nodes), Swale (it has 7 nodes) and Riverbank (it has 5 
>> nodes). Each of these features has their own geometries like 'Line String', 
>> 'Polygon' and 'Line String' 

Re: Complex SPARQL Query

2017-03-15 Thread Lorenz B.
Sure, you don't need grouping here. You could just use ORDER BY
ASC(?nodecount) LIMIT 1, i.e. sorting in the other direction and just
take the first result.

> Hi Lorenz,
>
> Yes, that's true but I can't retrieve all features along with their number of 
> sensing nodes. So, when I run one sub-query separately I get the correct 
> number of nodes in that feature.
>
> I slightly changed my ontology and then ran the following query against my 
> ontology file:
>
> SELECT?feature (MAX(?nodecount) AS ?featuremaxnodes)  WHERE {
>   
>   {
>   SELECT  ?feature(COUNT(?node) AS ?nodecount) WHERE {
>   
>   ?featurerdf:typeenviot:Field ;
>   ssn:hasDeployment   ?node .
>   ?node   rdf:typeenviot:SoilSensingNode .
>   
>   }
>   GROUP BY ?feature
>   ORDER BY DESC(?nodecount)
>}
>   }
>   GROUP BY ?feature
>   ORDER BY DESC(?nodecount)
>
> The output of the above query is:
>
>
>  feature   featuremaxnodes
>
> 1 enviot:A_Hilltop "3"^^xsd:integer
>
> 2 enviot:A_Riverbank   "5"^^xsd:integer
>
> 3 enviot:A_Swale   "7"^^xsd:integer
>
> Now I am very close to my desired output but still not getting it i.e. I need 
> to show the feature having maximum number of nodes. In other words, I need to 
> show the following:
>
>  feature   featuremaxnodes
>
> enviot:A_Swale "7"^^xsd:integer
>
> Any idea how to get the above output?
>
> Many thanks for your time, help and patience.
>
> Best regards,
>
> Izhar
> 
> From: Lorenz B. [buehm...@informatik.uni-leipzig.de]
> Sent: 14 March 2017 06:56
> To: users@jena.apache.org
> Subject: Re: Complex SPARQL Query
>
> Just to clarify, each of the sub-SELECT queries returns the number of
> nodes for the features Hilltop, Riverbank and Swale, right? And if you
> run such a SELECT query separately, the number is correct?
>> Dear Lorenz,
>>
>> Apologies for the belated reply, for I was travelling, arrived today.
>>
>> Let me post the whole question again below:
>>
>> I have a question related to SPARQL query which is a bit complex one. I 
>> would appreciate if someone could help me out. I have 15 Sensing Nodes with 
>> their corresponding Point(longitude latitude) geometries given below:
>>
>> Table 1: Showing results from 1 to 15 of 15. Query took 0.127 s.
>>
>> node gwkt
>>
>> enviot:A0_SoilSensingNode"POINT(-3.783065 
>> 53.202158)"^^
>> enviot:A1_SoilSensingNode "POINT(-3.782898 
>> 53.201828)"^^
>> enviot:A2_SoilSensingNode"POINT(-3.783092 
>> 53.202007)"^^
>> enviot:A3_SoilSensingNode "POINT(-3.781964 
>> 53.201765)"^^
>> enviot:A5_SoilSensingNode  "POINT(-3.783055 
>> 53.202777)"^^
>> enviot:A6_SoilSensingNode  "POINT(-3.78 
>> 53.202777)"^^
>> enviot:A7_SoilSensingNode "POINT(-3.78 
>> 53.202777)"^^
>> enviot:A8_SoilSensingNode  "POINT(-3.780833 
>> 53.203055)"^^
>> enviot:A9_SoilSensingNode  "POINT(-3.780833 
>> 53.20)"^^
>> enviot:AA_SoilSensingNode "POINT(-3.783063 
>> 53.202309)"^^
>> enviot:AB_SoilSensingNode "POINT(-3.782638 
>> 53.202189)"^^
>> enviot:AC_SoilSensingNode "POINT(-3.783003 
>> 53.202191)"^^
>> enviot:AD_SoilSensingNode "POINT(-3.782518 
>> 53.201841)"^^
>> enviot:AE_SoilSensingNode  "POINT(-3.782024 
>> 53.202193)"^^
>> enviot:AF_SoilSensingNode  "POINT(-3.782877 
>> 53.201788)"^^
>>
>> These sensing nodes are deployed in a field having three features named 
>> Hilltop (it has 3 nodes), Swale (it has 7 nodes) and Riverbank (it has 5 
>> nodes). Each of these features has their own geometries like 'Line String', 
>> 'Polygon' and 'Line String' respectively along with their geometric 
>> coordinates given below:
>>
>> Table 2: Showing results from 1 to 3 of 3. Query took 0.081 s.
>>
>> featurefgeo  
>>  fwkt
>> enviot:A_Hilltop