Re: Unable to build the below query using jena query builder

2023-12-08 Thread Andy Seaborne




On 08/12/2023 02:08, Dhamotharan, Kishan wrote:

Hello Lorenz,

Thanks for your response.


...



Since query builder 3.5 does not have addWhereValueVar is there any other way 
to build the query ?

It’s a very painful process to pull in three party / open source libraries, 
requires multiple approvals and adding a new version would involve a very 
tedious task of manually upgrading and pulling in the dependences and get them 
to work with the in house build system. Would be great if we have a workaround 
for this.


If you're unwilling to upgrade (and the 6 year old 3.5.0 has CVE issues 
raise against it so upgrading would be a very good idea) then you could 
consider taking the query builder source code. It is a self-contained 
feature of Apache Jena should back-port quite easily.


Andy


Re: Unable to build the below query using jena query builder

2023-12-07 Thread Dhamotharan, Kishan
Hello Lorenz, 

Thanks for your response. 

Yes I did try using the mentioned flow, but it did not work

SelectBuilder sb = new SelectBuilder();

SelectBuilder sb_g1 = new SelectBuilder();

sb_g1. addValueVar( 

SelectBuilder sb_g2 = new SelectBuilder();

sb_g2.addValueVar( .

sb.addUnion(sb_g1)
sb.addUnion(sb_g2)

Resulted in :

SELECT  ?s ?p ?o
WHERE
  {   {  }
UNION
  {  }
  }


And System.out.print(sb_g1) was 

SELECT  *
WHERE
  {  }
VALUES ( ?s ?p ?o  ) {
  ("foo1" "foo2" "foo3")
}

Since query builder 3.5 does not have addWhereValueVar is there any other way 
to build the query ? 

It’s a very painful process to pull in three party / open source libraries, 
requires multiple approvals and adding a new version would involve a very 
tedious task of manually upgrading and pulling in the dependences and get them 
to work with the in house build system. Would be great if we have a workaround 
for this. 





On 12/6/23, 12:30 AM, "Lorenz Buehmann" mailto:buehm...@informatik.uni-leipzig.de>> wrote:


CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you can confirm the sender and know the 
content is safe.






Hi,


did you try addGraph method on the SelectBuilder object with another
SelectBuilder object on which you add the VALUES clause and the triple
pattern?


In your case with the UNION I think the flow should be something like




SelectBuilder sb = ...


SelectBuilder sb_g1 = ... // first graph pattern
sb_g1.addValueVar(


SelectBuilder sb_g2 = ... // second graph pattern


sb.addUnion(sb_g1)
sb.addUnion(sb_g2)




But, I think there might be some bug or limitation:


While


SelectBuilder sb1 = new SelectBuilder()
.addWhere("?s", "?p", "?o")
.addWhereValueVar("?s", "foo1")
.addWhereValueVar("?p", "foo1")
.addWhereValueVar("?o", "foo1");
System.out.println(sb1.buildString());




Returns the expected query


SELECT *
WHERE
{ ?s ?p ?o
VALUES ( ?s ?p ?o ) {
( "foo1" "foo1" "foo1" )
}
}


passing that builder to another builder where it is supposed to make the
graph


Node g1 = NodeFactory.createURI("http://example/g1;);
SelectBuilder sb2 = new SelectBuilder().addGraph(g1,
new SelectBuilder()
.addWhere("?s", "?p", "?o")
.addWhereValueVar("?s", "foo1")
.addWhereValueVar("?p", "foo1")
.addWhereValueVar("?o", "foo1"));
System.out.println(sb2.buildString());




leads to only


SELECT *
WHERE
{ GRAPH 
{ ?s ?p ?o}}




From the code I'd say the issue is that the build() method isn't being
called before adding the query pattern as element to the graph. But
that's just a guess.




So what works is to force a build() on the WhereHandler explicitly
before passing it to the graph:




Node g1 = NodeFactory.createURI("http://example/g1;);
SelectBuilder sbG1 = new SelectBuilder()
.addWhere("?s", "?p", "?o")
.addWhereValueVar("?s", "foo1")
.addWhereValueVar("?p", "foo1")
.addWhereValueVar("?o", "foo1");
sbG1.getWhereHandler().build(); // the important line
SelectBuilder sb2 = new SelectBuilder().addGraph(g1,
sbG1);
System.out.println(sb2.buildString());




then we get




SELECT *
WHERE
{ GRAPH 
{ ?s ?p ?o
VALUES ( ?s ?p ?o ) {
( "foo1" "foo1" "foo1" )
}
}}




It don't know if this is intended or if you want to open an issue or
wait for Claude Warren which is the principle maintainer of the query
builder code and he'll provide a better answer than me.




I have one question, any reason for using Jena 3.5.0 which is 6 years old?


On 06.12.23 01:33, Dhamotharan, Kishan wrote:
> Hi All,
>
> I have been trying to construct the below query using Jena query builder. I 
> have tried multiple different ways to build it, nothing seems to work. Adding 
> values block inside Graph seems to be not possible. We are using Jena 3.5.
>
>
> SELECT ?subject ?predicate ?object ?graph
> WHERE {
>
> {
> GRAPH  {
> ?subject ?predicate ?object
>
> VALUES (?subject ?predicate ?object) {
> (  )
> (  )
> (  )
> }
>
> BIND( AS ?graph)
> }
> }
>
> UNION
>
> {
> GRAPH  {
> ?subject ?predicate ?object
>
> VALUES (?subject ?predicate ?object) {
> (  )
> (  )
> (  )
> }
>
> BIND( AS ?graph)
> }
> }
>
> Can anyone suggest on how this can be done ? Any help is appreciated 
>
>
> Thanks
> Kishan Dhamotharan


--
Lorenz Bühmann
Research Associate/Scientific Developer


Email buehm...@infai.org 


Institute for Applied Informatics e.V. (InfAI) | Goerdelerring 9 | 04109 
Leipzig | Germany







Re: Unable to build the below query using jena query builder

2023-12-06 Thread Lorenz Buehmann

Hi,

did you try addGraph method on the SelectBuilder object with another 
SelectBuilder object on which you add the VALUES clause and the triple 
pattern?


In your case with the UNION I think the flow should be something like


SelectBuilder sb = ...

SelectBuilder sb_g1 = ... // first graph pattern
sb_g1.addValueVar(

SelectBuilder sb_g2 = ... // second graph pattern

sb.addUnion(sb_g1)
sb.addUnion(sb_g2)


But, I think there might be some bug or limitation:

While

SelectBuilder sb1 = new SelectBuilder()
    .addWhere("?s", "?p", "?o")
    .addWhereValueVar("?s", "foo1")
    .addWhereValueVar("?p", "foo1")
    .addWhereValueVar("?o", "foo1");
System.out.println(sb1.buildString());


Returns the expected query

SELECT  *
WHERE
  { ?s  ?p  ?o
    VALUES ( ?s ?p ?o ) {
  ( "foo1" "foo1" "foo1" )
    }
  }

passing that builder to another builder where it is supposed to make the 
graph


Node g1 = NodeFactory.createURI("http://example/g1;);
SelectBuilder sb2 = new SelectBuilder().addGraph(g1,
    new SelectBuilder()
    .addWhere("?s", "?p", "?o")
    .addWhereValueVar("?s", "foo1")
    .addWhereValueVar("?p", "foo1")
    .addWhereValueVar("?o", "foo1"));
System.out.println(sb2.buildString());


leads to only

SELECT  *
WHERE
  { GRAPH 
  { ?s  ?p  ?o}}


From the code I'd say the issue is that the build() method isn't being 
called before adding the query pattern as element to the graph. But 
that's just a guess.



So what works is to force a build() on the WhereHandler explicitly 
before passing it to the graph:



Node g1 = NodeFactory.createURI("http://example/g1;);
SelectBuilder sbG1 = new SelectBuilder()
    .addWhere("?s", "?p", "?o")
    .addWhereValueVar("?s", "foo1")
    .addWhereValueVar("?p", "foo1")
    .addWhereValueVar("?o", "foo1");
sbG1.getWhereHandler().build(); // the important line
SelectBuilder sb2 = new SelectBuilder().addGraph(g1,
    sbG1);
System.out.println(sb2.buildString());


then we get


SELECT  *
WHERE
  { GRAPH 
  { ?s  ?p  ?o
    VALUES ( ?s ?p ?o ) {
  ( "foo1" "foo1" "foo1" )
    }
  }}


It don't know if this is intended or if you want to open an issue or 
wait for Claude Warren which is the principle maintainer of the query 
builder code and he'll provide a better answer than me.



I have one question, any reason for using Jena 3.5.0 which is 6 years old?

On 06.12.23 01:33, Dhamotharan, Kishan wrote:

Hi All,

I have been trying to construct the below query using Jena query builder. I 
have tried multiple different ways to build it, nothing seems to work. Adding 
values block inside Graph seems to be not possible. We are using Jena 3.5.


SELECT ?subject ?predicate ?object ?graph
WHERE {

{
   GRAPH  {
 ?subject ?predicate ?object

   VALUES (?subject ?predicate ?object) {
   (  )
   (  )
   (  )
  }

 BIND( AS ?graph)
   }
}

UNION

{
   GRAPH  {
 ?subject ?predicate ?object

   VALUES (?subject ?predicate ?object) {
   (  )
   (  )
   (  )
}

 BIND( AS ?graph)
   }
}

Can anyone suggest on how this can be done ? Any help is appreciated 


Thanks
Kishan Dhamotharan


--
Lorenz Bühmann
Research Associate/Scientific Developer

Email buehm...@infai.org

Institute for Applied Informatics e.V. (InfAI) | Goerdelerring 9 | 04109 
Leipzig | Germany



Unable to build the below query using jena query builder

2023-12-05 Thread Dhamotharan, Kishan
Hi All,

I have been trying to construct the below query using Jena query builder. I 
have tried multiple different ways to build it, nothing seems to work. Adding 
values block inside Graph seems to be not possible. We are using Jena 3.5.


SELECT ?subject ?predicate ?object ?graph
WHERE {

{
  GRAPH  {
?subject ?predicate ?object

  VALUES (?subject ?predicate ?object) {
  (  )
  (  )
  (  )
 }

BIND( AS ?graph)
  }
}

UNION

{
  GRAPH  {
?subject ?predicate ?object

  VALUES (?subject ?predicate ?object) {
  (  )
  (  )
  (  )
   }

BIND( AS ?graph)
  }
}

Can anyone suggest on how this can be done ? Any help is appreciated 


Thanks
Kishan Dhamotharan