Skip to content

Commit

Permalink
Update result set testing for triple terms
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Feb 5, 2025
1 parent 2da94d8 commit b631ffe
Show file tree
Hide file tree
Showing 46 changed files with 2,368 additions and 1,037 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public static RowSetRewindable create(RowSet rowSet) {
* @param other The other RowSetMem object
*/
private RowSetMem(RowSetMem other) {
// Share vars and rows but not the iterator.
vars = other.vars;
// Share results (not the iterator).
rows = other.rows;
reset();
}
Expand All @@ -61,7 +61,6 @@ private RowSetMem(RowSetMem other) {
* necessary internal datastructures are shared. This operation destroys
* (uses up) a RowSet object that is not an in-memory one.
*/

private RowSetMem(RowSet other) {
if ( other instanceof RowSetMem rsm ) {
// See also the RowSetMem(RowSetMem) constructor.
Expand Down
29 changes: 11 additions & 18 deletions jena-arq/src/main/java/org/apache/jena/sparql/expr/NodeValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,37 +253,33 @@ public static NodeValue booleanReturn(boolean b)
// ----------------------------------------------------------------
// ---- Construct NodeValue from graph nodes

public static NodeValue makeNode(Node n)
{
public static NodeValue makeNode(Node n) {
return nodeToNodeValue(n);
}

public static NodeValue makeNode(String lexicalForm, RDFDatatype dtype)
{
public static NodeValue makeNode(String lexicalForm, RDFDatatype dtype) {
Node n = NodeFactory.createLiteralDT(lexicalForm, dtype);
return NodeValue.makeNode(n);
}

// Convenience - knows that lang tags aren't allowed with datatypes.
public static NodeValue makeNode(String lexicalForm, String langTag, Node datatype)
{
String uri = (datatype==null) ? null : datatype.getURI();
return makeNode(lexicalForm, langTag, uri);
public static NodeValue makeNode(String lexicalForm, String langTag, Node datatype) {
String uri = (datatype == null) ? null : datatype.getURI();
return makeNode(lexicalForm, langTag, uri);
}

public static NodeValue makeNode(String lexicalForm, String langTag, String datatype)
{
public static NodeValue makeNode(String lexicalForm, String langTag, String datatype) {
if ( datatype != null && datatype.equals("") )
datatype = null;

if ( langTag != null && datatype != null )
// raise??
Log.warn(NodeValue.class, "Both lang tag and datatype defined (lexcial form '"+lexicalForm+"')");
Log.warn(NodeValue.class, "Both lang tag and datatype defined (lexcial form '" + lexicalForm + "')");

Node n = null;
if ( langTag != null )
n = NodeFactory.createLiteralLang(lexicalForm, langTag);
else if ( datatype != null) {
else if ( datatype != null ) {
RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(datatype);
n = NodeFactory.createLiteralDT(lexicalForm, dType);
} else
Expand Down Expand Up @@ -366,21 +362,18 @@ public NodeValue eval(Binding binding, FunctionEnv env)

// NodeValues are immutable so no need to duplicate.
@Override
public Expr copySubstitute(Binding binding)
{
public Expr copySubstitute(Binding binding) {
return this;
}

@Override
public Expr applyNodeTransform(NodeTransform transform)
{
public Expr applyNodeTransform(NodeTransform transform) {
Node n = asNode();
n = transform.apply(n);
return makeNode(n);
}

public Node evalNode(Binding binding, ExecutionContext execCxt)
{
public Node evalNode(Binding binding, ExecutionContext execCxt) {
return asNode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.jena.irix.IRIs;
import org.apache.jena.irix.IRIx;
import org.apache.jena.query.ARQ;
import org.apache.jena.rdf.model.impl.Util;
import org.apache.jena.riot.out.NodeFmtLib;
import org.apache.jena.riot.system.RiotLib;
import org.apache.jena.sparql.expr.ExprEvalException;
Expand Down Expand Up @@ -127,22 +126,31 @@ public static NodeValue sameTerm(NodeValue nv1, NodeValue nv2) {
return NodeValue.booleanReturn(sameTerm(nv1.asNode(), nv2.asNode()));
}

// Jena - up to Jena 4.
// Language tags were kept in the case form they were given as.
// Jena5 - language tags are canonicalised.

/** sameTerm(x,y) */
public static boolean sameTerm(Node node1, Node node2) {
if ( node1.equals(node2) )
return true;
if ( Util.isLangString(node1) && Util.isLangString(node2) ) {
String lex1 = node1.getLiteralLexicalForm();
String lex2 = node2.getLiteralLexicalForm();
if ( !lex1.equals(lex2) )
return false;
return node1.getLiteralLanguage().equalsIgnoreCase(node2.getLiteralLanguage());
}
if ( node1.isTripleTerm() && node2.isTripleTerm() ) {
return sameTriples(node1.getTriple(), node2.getTriple());
}
return false;
}
return node1.sameTermAs(node2);
}

// /** sameTerm(x,y) */
// public static boolean sameTerm(Node node1, Node node2) {
// if ( node1.equals(node2) )
// return true;
// if ( Util.isLangString(node1) && Util.isLangString(node2) ) {
// String lex1 = node1.getLiteralLexicalForm();
// String lex2 = node2.getLiteralLexicalForm();
// if ( !lex1.equals(lex2) )
// return false;
// return node1.getLiteralLanguage().equalsIgnoreCase(node2.getLiteralLanguage());
// }
// if ( node1.isTripleTerm() && node2.isTripleTerm() ) {
// return sameTriples(node1.getTriple(), node2.getTriple());
// }
// return false;
// }

private static boolean sameTriples(Triple t1, Triple t2) {
return sameTerm(t1.getSubject(), t2.getSubject())
Expand Down
Loading

0 comments on commit b631ffe

Please sign in to comment.