You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Luis Daniel Ibáñez González <ld...@gmail.com> on 2016/09/22 16:01:37 UTC

Node equality issue

Hi,

I am extracting the subjects,predicates and objects in queries in log by
using this handy snippet here [1]. My goal is to compare them with other
sets of Nodes coming from other sources.
However, the .equals between the Node coming from the snippet and a Node
created with NodeFactory is not working as expected. Roughly:

Node var = NodeFactory.createVariable("movie");
QueryStr = "SELECT ?movie WHERE {?movie .......}" ;
Got the subjects of the query with [1], that is, a set containing the
variable '?movie' (let's call it 'sub')

My issue is that sub.equals(var) is false when I expected the opposite.

What I'm missing here?

I'm attaching a minimal test case for those keen to execute it.

Regards,
Luis.

P.S. ARQ 3.1.0 from maven repo on Java 8, if it matters.

[1]
http://stackoverflow.com/questions/15203838/how-to-get-all-of-the-subjects-of-a-jena-query

-- 
Ing. Luis Daniel Ibáñez G.

Re: Node equality issue

Posted by Andy Seaborne <an...@apache.org>.
Hi Luis,

SPARQL queries use Var, a sub-class of Node_Variable, as returned by 
NodeFactory.createVariable.

Use

Var s = Var.alloc("movie") ;

Use

Var s = Var.alloc(Node_Variable) ;

to downcast.

Var.alloc(var) ;

is safe.

	Andy

On 22/09/16 17:01, Luis Daniel Ibez Gonzlez wrote:
> Hi,
>
> I am extracting the subjects,predicates and objects in queries in log by
> using this handy snippet here [1]. My goal is to compare them with other
> sets of Nodes coming from other sources.
> However, the .equals between the Node coming from the snippet and a Node
> created with NodeFactory is not working as expected. Roughly:
>
> Node var = NodeFactory.createVariable("movie");
> QueryStr = "SELECT ?movie WHERE {?movie .......}" ;
> Got the subjects of the query with [1], that is, a set containing the
> variable '?movie' (let's call it 'sub')
>
> My issue is that sub.equals(var) is false when I expected the opposite.
>
> What I'm missing here?
>
> I'm attaching a minimal test case for those keen to execute it.
>
> Regards,
> Luis.
>
> P.S. ARQ 3.1.0 from maven repo on Java 8, if it matters.
>
> [1]
> http://stackoverflow.com/questions/15203838/how-to-get-all-of-the-subjects-of-a-jena-query
>
> --
> Ing. Luis Daniel Ibez G.
>