"matches" is old code from a long time ago and probably should be removed.
----
There are two concepts of "equals"
"same term" meaning the same RDF term
"same value" means same point in the value space of datatype.
sameTerm::
Both URIs having equal strings.
Blank nodes - the same blank node.
Node.equals
For literals, it means each component is equal.
equal lexical forms, equal datatypes, equal languages,
equal text directions (RDF 1.2)
"123"^^xsd:integer and "+123"^^xsd:integer are different RDF terms
because they have different lexical forms.
This is
Node.sameTermAs(Node)
https://www.w3.org/TR/rdf12-concepts/#section-rdf-graph
sameValue:
"123"^^xsd:integer and "+123"^^xsd:integer are the same value.
and
"123"^^xsd:integer and "123.0"^^xsd:decimal are the same value.
even though they have different datatypes.
"same value" for anything that is not a literal is "same term"
SPARQL triple pattern matching is "same term".
SPARQL Filters work on values for "=", "<" etc.
specifically XPath/XQuery functions and operators ("F&O")
SPARQL has "sameTERM(term1, term2)" for non-value equality.
The Model API when used with default model,
uses GraphMemValue (renamed for 6.x - was called GraphMem)
which indexes literals by some java values inc GregorianCalendar, bit
not xsd:dateTime.
So it is nearly the same as XSD values but not quite.
This is
Node.sameValueAs(Node)
One thing to be careful of: "not the same value" isn't the negation of
"sameValue" for F&O.
"sameValue" can be "don't know" - e.g. one the datatypes is unknown e.g.
two xsd:dateTimes, one with timezone, one without, and not 14 hours apart.
Variables and matching::
A variable has a binding, "has a value", in some context.
The binding is from matching a graph.
Jena has variables as RDF terms (you can put them in triples).
So a variable as a node (RDF Term extension) is not the same term and
not the same value as a literal. "false" is right but maybe not what you
wanted.
The binding of a variables happens by matching a graph or code creating
a SPARQL Binding object.
> How do I implement nodes and triples for pattern matching?
SPARQL. This will deal with variables used across triple patterns.
To avoid the parse, dispatch overhead, use BasicPatterns and
PatternMatchData.execute.
The return is an iterator of solutions "rows", where you can lookup a
variable to get the matching RDF term.
The input is starting point : a QueryIterRoot (unless you have some
varibales bindings already).
BindingFactory makes Bindings.
Andy
All references are to 5.6.0/6.x code.
5.1.0 may not have the functional package up the same way.
On 01/12/2025 13:15, Enrico.Daga wrote:
Hi,
I need clarification on Node.matches for variable nodes (I am using Jena 5.1.0).
I was expecting the following to return true:
boolean isFalse = NodeFactory.createVariable("v").matches(
NodeFactory.createURI("http://www.example.org/"));
Then, I looked at comments on Node and the method matches is supposed to be
extended. However, I can't find it implemented in Node_Variable nor in Var.
What am I missing? How do I implement nodes and triples for pattern matching?
Best,
Enrico
--
Enrico Daga, PhD
Senior Research Fellow
Knowledge Media Institute
The Open University
http://enridaga.net
http://sparql-anything.cc