This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit a919b5eee07dc5bfa6a9be93c544fc45ff7b486b
Author: Andy Seaborne <[email protected]>
AuthorDate: Wed Oct 22 16:31:04 2025 +0100

    Code tidy
---
 .../engine/iterator/QueryIterRepeatApply.java      |   2 +-
 .../sparql/pfunction/PropertyFunctionBase.java     | 130 ++++-----
 .../java/org/apache/jena/langtagx/LangTagX.java    |   9 +-
 .../org/apache/jena/fuseki/main/TestQuery.java     |  24 +-
 .../org/apache/jena/query/text/TextQueryFuncs.java |  63 ++--
 .../org/apache/jena/query/text/TextQueryPF.java    | 324 ++++++++++-----------
 6 files changed, 278 insertions(+), 274 deletions(-)

diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRepeatApply.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRepeatApply.java
index e36ea28fcb..18a1e53eac 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRepeatApply.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterRepeatApply.java
@@ -28,6 +28,7 @@ import org.apache.jena.sparql.engine.binding.Binding;
 
 /**
  * Repeatedly execute the subclass operation for each Binding in the input 
iterator.
+ * {@code flatmap} for {@link QueryIterator} with cancellation.
  */
 public abstract class QueryIterRepeatApply extends QueryIter1 {
     private int count = 0;
@@ -82,7 +83,6 @@ public abstract class QueryIterRepeatApply extends QueryIter1 
{
         if ( !hasNextBinding() )
             throw new NoSuchElementException(Lib.className(this) + 
".next()/finished");
         return currentStage.nextBinding();
-
     }
 
     private QueryIterator makeNextStage() {
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionBase.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionBase.java
index 1bb21ee03d..e225c4eff8 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionBase.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/pfunction/PropertyFunctionBase.java
@@ -18,105 +18,99 @@
 
 package org.apache.jena.sparql.pfunction;
 
-import org.apache.jena.atlas.io.IndentedWriter ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.QueryBuildException ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
-import org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply ;
-import org.apache.jena.sparql.serializer.SerializationContext ;
-import org.apache.jena.sparql.util.FmtUtils ;
-import org.apache.jena.sparql.util.IterLib ;
-
-/** Basic property function handler that calls the implementation
- * subclass one binding at a time */
-
-public abstract class PropertyFunctionBase implements PropertyFunction
-{
-    PropFuncArgType subjArgType ;
-    PropFuncArgType objFuncArgType ;
-
-    protected PropertyFunctionBase()
-    {
-        this(PropFuncArgType.PF_ARG_EITHER, PropFuncArgType.PF_ARG_EITHER) ;
+import org.apache.jena.atlas.io.IndentedWriter;
+import org.apache.jena.graph.Node;
+import org.apache.jena.query.QueryBuildException;
+import org.apache.jena.sparql.engine.ExecutionContext;
+import org.apache.jena.sparql.engine.QueryIterator;
+import org.apache.jena.sparql.engine.binding.Binding;
+import org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply;
+import org.apache.jena.sparql.serializer.SerializationContext;
+import org.apache.jena.sparql.util.FmtUtils;
+import org.apache.jena.sparql.util.IterLib;
+
+/**
+ * Basic property function handler that calls the implementation subclass one 
binding
+ * at a time
+ */
+
+public abstract class PropertyFunctionBase implements PropertyFunction {
+    PropFuncArgType subjArgType;
+    PropFuncArgType objFuncArgType;
+
+    protected PropertyFunctionBase() {
+        this(PropFuncArgType.PF_ARG_EITHER, PropFuncArgType.PF_ARG_EITHER);
     }
 
-    protected PropertyFunctionBase(PropFuncArgType subjArgType,  
PropFuncArgType objFuncArgType)
-    {
-        this.subjArgType = subjArgType ;
-        this.objFuncArgType = objFuncArgType ;
+    protected PropertyFunctionBase(PropFuncArgType subjArgType, 
PropFuncArgType objFuncArgType) {
+        this.subjArgType = subjArgType;
+        this.objFuncArgType = objFuncArgType;
     }
 
     @Override
-    public void build(PropFuncArg argSubject, Node predicate, PropFuncArg 
argObject, ExecutionContext execCxt)
-    {
+    public void build(PropFuncArg argSubject, Node predicate, PropFuncArg 
argObject, ExecutionContext execCxt) {
         if ( subjArgType.equals(PropFuncArgType.PF_ARG_SINGLE) )
             if ( argSubject.isList() )
-                throw new QueryBuildException("List arguments (subject) to 
"+predicate.getURI()) ;
+                throw new QueryBuildException("List arguments (subject) to " + 
predicate.getURI());
 
-        if ( subjArgType.equals(PropFuncArgType.PF_ARG_LIST) && ! 
argSubject.isList() )
-                throw new QueryBuildException("Single argument, list expected 
(subject) to "+predicate.getURI()) ;
+        if ( subjArgType.equals(PropFuncArgType.PF_ARG_LIST) && 
!argSubject.isList() )
+            throw new QueryBuildException("Single argument, list expected 
(subject) to " + predicate.getURI());
 
-        if ( objFuncArgType.equals(PropFuncArgType.PF_ARG_SINGLE) && 
argObject.isList() )
-        {
-            if ( ! argObject.isNode() )
+        if ( objFuncArgType.equals(PropFuncArgType.PF_ARG_SINGLE) && 
argObject.isList() ) {
+            if ( !argObject.isNode() )
                 // But allow rdf:nil.
-                throw new QueryBuildException("List arguments (object) to 
"+predicate.getURI()) ;
+                throw new QueryBuildException("List arguments (object) to " + 
predicate.getURI());
         }
 
         if ( objFuncArgType.equals(PropFuncArgType.PF_ARG_LIST) )
-            if ( ! argObject.isList() )
-                throw new QueryBuildException("Single argument, list expected 
(object) to "+predicate.getURI()) ;
+            if ( !argObject.isList() )
+                throw new QueryBuildException("Single argument, list expected 
(object) to " + predicate.getURI());
     }
 
     @Override
-    public QueryIterator exec(QueryIterator input, PropFuncArg argSubject, 
Node predicate, PropFuncArg argObject, ExecutionContext execCxt)
-    {
+    public QueryIterator exec(QueryIterator input, PropFuncArg argSubject, 
Node predicate, PropFuncArg argObject,
+                              ExecutionContext execCxt) {
         // This is the property function equivalent of Substitute.
         // To allow property functions to see the whole input stream,
         // the exec() operation allows the PF implementation to get at the
-        // input iterator.  Normally, we just want that applied one binding at 
a time.
+        // input iterator. Normally, we just want that applied one binding at 
a time.
 
-        return new RepeatApplyIteratorPF(input, argSubject, predicate, 
argObject, execCxt) ;
+        return new RepeatApplyIteratorPF(input, argSubject, predicate, 
argObject, execCxt);
     }
 
-    public abstract QueryIterator exec(Binding binding, PropFuncArg 
argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) ;
-
+    public abstract QueryIterator exec(Binding binding, PropFuncArg 
argSubject, Node predicate, PropFuncArg argObject,
+                                       ExecutionContext execCxt);
 
-    class RepeatApplyIteratorPF extends QueryIterRepeatApply
-    {
-        private final PropFuncArg argSubject ;
-        private final Node predicate ;
-        private final PropFuncArg argObject ;
+    class RepeatApplyIteratorPF extends QueryIterRepeatApply {
+        private final PropFuncArg argSubject;
+        private final Node predicate;
+        private final PropFuncArg argObject;
 
-        public RepeatApplyIteratorPF(QueryIterator input, PropFuncArg 
argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt)
-        {
-            super(input, execCxt) ;
-            this.argSubject = argSubject ;
-            this.predicate = predicate ;
-            this.argObject = argObject ;
+        public RepeatApplyIteratorPF(QueryIterator input, PropFuncArg 
argSubject, Node predicate, PropFuncArg argObject,
+                                     ExecutionContext execCxt) {
+            super(input, execCxt);
+            this.argSubject = argSubject;
+            this.predicate = predicate;
+            this.argObject = argObject;
         }
 
         @Override
-        protected QueryIterator nextStage(Binding binding)
-        {
-            QueryIterator iter = exec(binding, argSubject, predicate, 
argObject, getExecContext()) ;
+        protected QueryIterator nextStage(Binding binding) {
+            QueryIterator iter = exec(binding, argSubject, predicate, 
argObject, getExecContext());
             if ( iter == null )
-                iter = IterLib.noResults(getExecContext()) ;
-            return iter ;
+                iter = IterLib.noResults(getExecContext());
+            return iter;
         }
 
         @Override
-        protected void details(IndentedWriter out, SerializationContext sCxt)
-        {
-            out.print("PropertyFunction ["+FmtUtils.stringForNode(predicate, 
sCxt)+"]") ;
-            out.print("[") ;
-            argSubject.output(out, sCxt) ;
-            out.print("][") ;
-            argObject.output(out, sCxt) ;
-            out.print("]") ;
-            out.println() ;
+        protected void details(IndentedWriter out, SerializationContext sCxt) {
+            out.print("PropertyFunction [" + FmtUtils.stringForNode(predicate, 
sCxt) + "]");
+            out.print("[");
+            argSubject.output(out, sCxt);
+            out.print("][");
+            argObject.output(out, sCxt);
+            out.print("]");
+            out.println();
         }
     }
 }
diff --git a/jena-core/src/main/java/org/apache/jena/langtagx/LangTagX.java 
b/jena-core/src/main/java/org/apache/jena/langtagx/LangTagX.java
index 475d19874a..6685031dcf 100644
--- a/jena-core/src/main/java/org/apache/jena/langtagx/LangTagX.java
+++ b/jena-core/src/main/java/org/apache/jena/langtagx/LangTagX.java
@@ -24,11 +24,18 @@ import org.apache.jena.langtag.LangTags;
 import org.apache.jena.shared.JenaException;
 
 /**
- * This class defined the Jena side policies for language tags and maps 
operations to
+ * This class defines the Jena-side policies for language tags
+ * and maps operations to one implementation.
+ * <p>
+ * Language tags do not include text direction.
+ *
  * {@link org.apache.jena.langtag.LangTags}.
  */
 public class LangTagX {
 
+    // If needed, convert to singleton.
+    // public LangOps get() { ... }
+
     /**
      * Create a {@link LangTag} object, using the Jena system default
      * implementation of the {@code LangTag} interface.
diff --git 
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestQuery.java
 
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestQuery.java
index 0196573573..f9a8863315 100644
--- 
a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestQuery.java
+++ 
b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/TestQuery.java
@@ -158,7 +158,7 @@ public class TestQuery extends AbstractFusekiTest {
     @Test
     public void query_construct_quad_01()
     {
-        String queryString = " CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } 
WHERE {?s ?p ?oq}";
+        String queryString = "CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } 
WHERE {?s ?p ?oq}";
         Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
 
         try ( QueryExecutionHTTP qExec = 
QueryExecutionHTTP.service(serviceQuery(), query) ) {
@@ -172,7 +172,7 @@ public class TestQuery extends AbstractFusekiTest {
     @Test
     public void query_construct_quad_02()
     {
-        String queryString = " CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } 
WHERE {?s ?p ?oq}";
+        String queryString = "CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } 
WHERE {?s ?p ?oq}";
         Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
 
         try ( QueryExecution qExec = QueryExecution.service(serviceQuery(), 
query) ) {
@@ -185,7 +185,7 @@ public class TestQuery extends AbstractFusekiTest {
     @Test
     public void query_construct_01()
     {
-        String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
+        String query = "CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
         try ( QueryExecution qExec = QueryExecution.service(serviceQuery(), 
query) ) {
             Iterator<Triple> result = qExec.execConstructTriples();
             assertTrue(result.hasNext());
@@ -195,7 +195,7 @@ public class TestQuery extends AbstractFusekiTest {
     @Test
     public void query_construct_02()
     {
-        String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
+        String query = "CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
         try ( QueryExec qExec = 
QueryExec.service(serviceQuery()).query(query).build() ) {
             Graph result = qExec.construct();
             assertEquals(1, result.size());
@@ -224,7 +224,7 @@ public class TestQuery extends AbstractFusekiTest {
 
     @Test
     public void query_construct_conneg() throws IOException {
-        String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
+        String query = "CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
         for (MediaType type : rdfOfferTest.entries()) {
 
             String contentType = type.toHeaderString();
@@ -244,7 +244,7 @@ public class TestQuery extends AbstractFusekiTest {
 
     @Test
     public void query_construct_quad_conneg() throws IOException {
-        String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH 
?g {?s ?p ?o}}";
+        String queryString = "CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH 
?g {?s ?p ?o}}";
         Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
         for (MediaType type : quadsOfferTest.entries()) {
             String contentType = type.toHeaderString();
@@ -285,8 +285,11 @@ public class TestQuery extends AbstractFusekiTest {
     }
 
     public void query_json_01() throws IOException {
-        Query query = QueryFactory.create("JSON { \"s\": ?s , \"p\": ?p , 
\"o\" : ?o } "
-                + "WHERE { ?s ?p ?o }", Syntax.syntaxARQ);
+        Query query = QueryFactory.create("""
+                JSON { "s": ?s , "p": ?p , "o" : ?o }
+                WHERE { ?s ?p ?o }
+                """,
+                Syntax.syntaxARQ);
         try ( QueryExecution qExec = QueryExecution.service(serviceQuery(), 
query) ) {
             JsonArray result = qExec.execJson();
             assertEquals(1, result.size());
@@ -295,8 +298,9 @@ public class TestQuery extends AbstractFusekiTest {
 
     @Test
     public void query_json_02() throws IOException {
-        String qs = Convert.encWWWForm("JSON { \"s\": ?s , \"p\": ?p , \"o\" : 
?o } "
-                + "WHERE { ?s ?p ?o }");
+        String qs = Convert.encWWWForm("""
+                JSON { "s": ?s , "p": ?p , "o" : ?o }
+                WHERE { ?s ?p ?o }""");
         String url = serviceQuery() + "?query=" + qs;
         String result = null;
         try ( TypedInputStream in = HttpOp.httpGet(url) ) {
diff --git 
a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryFuncs.java 
b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryFuncs.java
index b3296022c9..790867f961 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryFuncs.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryFuncs.java
@@ -18,77 +18,76 @@
 
 package org.apache.jena.query.text;
 
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.sparql.core.Quad ;
-import org.apache.jena.sparql.util.FmtUtils ;
+import org.apache.jena.atlas.logging.Log;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.core.Quad;
+import org.apache.jena.sparql.util.FmtUtils;
 
 /** Functions relating to text query */
 public class TextQueryFuncs {
 
-    /** Create a string to put in a Lucene index for the subject node */  
+    /** Create a string to put in a Lucene index for the subject node */
     public static String subjectToString(Node s) {
         if ( s == null )
-            throw new IllegalArgumentException("Subject node can not be null") 
;
+            throw new IllegalArgumentException("Subject node can not be null");
         if ( ! (s.isURI() || s.isBlank() ) )
-            throw new TextIndexException("Found a subject that is not a URI 
nor a blank node: "+s) ; 
-        return nodeToString(s) ;
+            throw new TextIndexException("Found a subject that is not a URI 
nor a blank node: "+s);
+        return nodeToString(s);
     }
 
-    /** Create a string to put in a Lucene index for a graph node */  
+    /** Create a string to put in a Lucene index for a graph node */
     public static String graphNodeToString(Node g) {
         if ( g == null )
-            return null ;
+            return null;
         if ( ! (g.isURI() || g.isBlank() ) )
-            throw new TextIndexException("Found a graph label that is not a 
URI nor a blank node: "+g) ; 
-        return nodeToString(g) ;
+            throw new TextIndexException("Found a graph label that is not a 
URI nor a blank node: "+g);
+        return nodeToString(g);
     }
 
     private static String nodeToString(Node n) {
-        return (n.isURI() ) ? n.getURI() : "_:" + n.getBlankNodeLabel() ;
+        return (n.isURI() ) ? n.getURI() : "_:" + n.getBlankNodeLabel();
     }
 
     /** Recover a Node from a stored Lucene string */
     public static Node stringToNode(String v) {
         if ( v.startsWith("_:") ) {
-            v = v.substring("_:".length()) ;
-            return NodeFactory.createBlankNode(v) ;
+            v = v.substring("_:".length());
+            return NodeFactory.createBlankNode(v);
         }
         else
-            return NodeFactory.createURI(v) ;
+            return NodeFactory.createURI(v);
     }
 
     /** Create an Entity from a quad.
      * Returns null if the quad is not a candidate for indexing.
      */
     public static Entity entityFromQuad(EntityDefinition defn , Quad quad ) {
-        return entityFromQuad(defn, quad.getGraph(), quad.getSubject(), 
quad.getPredicate(), quad.getObject()) ;
+        return entityFromQuad(defn, quad.getGraph(), quad.getSubject(), 
quad.getPredicate(), quad.getObject());
     }
 
     /** Create an Entity from a quad (as g/s/p/o).
      * Returns null if the quad is not a candidate for indexing.
      */
     public static Entity entityFromQuad(EntityDefinition defn , Node g , Node 
s , Node p , Node o ) {
-        String field = defn.getField(p) ;
+        String field = defn.getField(p);
         if ( field == null )
-            return null ;
+            return null;
         if ( !o.isLiteral() ) {
             Log.warn(TextQuery.class, "Not a literal value for mapped 
field-predicate: " + field + " :: "
-                     + FmtUtils.stringForString(field)) ;
-            return null ;
+                     + FmtUtils.stringForString(field));
+            return null;
         }
-        String x = TextQueryFuncs.subjectToString(s) ;
-        String graphText = TextQueryFuncs.graphNodeToString(g) ;
+        String x = TextQueryFuncs.subjectToString(s);
+        String graphText = TextQueryFuncs.graphNodeToString(g);
 
-        String language = o.getLiteral().language() ;
-        RDFDatatype datatype = o.getLiteral().getDatatype() ;
-        Entity entity = new Entity(x, graphText, language, datatype) ;
-    
-        entity.put(field, o.getLiteralLexicalForm()) ;
-        return entity ;
-    }
+        String language = o.getLiteral().language();
+        RDFDatatype datatype = o.getLiteral().getDatatype();
+        Entity entity = new Entity(x, graphText, language, datatype);
 
+        entity.put(field, o.getLiteralLexicalForm());
+        return entity;
+    }
 }
 
diff --git 
a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java 
b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
index 95228dfa96..c01b34bcce 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
@@ -16,57 +16,57 @@
  * limitations under the License.
  */
 
-package org.apache.jena.query.text ;
+package org.apache.jena.query.text;
 
-import java.util.ArrayList ;
-import java.util.Collection ;
-import java.util.Iterator ;
-import java.util.List ;
-import java.util.function.Function ;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.Function;
 
 import org.apache.commons.collections4.ListValuedMap;
 import org.apache.commons.collections4.MultiMapUtils;
 import org.apache.jena.atlas.io.IndentedLineBuffer;
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.lib.Cache ;
-import org.apache.jena.atlas.lib.CacheFactory ;
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.datatypes.RDFDatatype ;
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
-import org.apache.jena.graph.Graph ;
-import org.apache.jena.graph.Node ;
-import org.apache.jena.query.QueryBuildException ;
-import org.apache.jena.query.QueryExecException ;
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.atlas.lib.Cache;
+import org.apache.jena.atlas.lib.CacheFactory;
+import org.apache.jena.atlas.logging.Log;
+import org.apache.jena.datatypes.RDFDatatype;
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.graph.Node;
+import org.apache.jena.query.QueryBuildException;
+import org.apache.jena.query.QueryExecException;
 import org.apache.jena.query.text.analyzer.Util;
 import org.apache.jena.rdf.model.Property;
 import org.apache.jena.rdf.model.Resource;
 import org.apache.jena.rdf.model.ResourceFactory;
-import org.apache.jena.sparql.core.* ;
-import org.apache.jena.sparql.engine.ExecutionContext ;
-import org.apache.jena.sparql.engine.QueryIterator ;
-import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.core.*;
+import org.apache.jena.sparql.engine.ExecutionContext;
+import org.apache.jena.sparql.engine.QueryIterator;
+import org.apache.jena.sparql.engine.binding.Binding;
 import org.apache.jena.sparql.engine.binding.BindingBuilder;
-import org.apache.jena.sparql.engine.binding.BindingFactory ;
-import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper ;
-import org.apache.jena.sparql.engine.iterator.QueryIterSlice ;
-import org.apache.jena.sparql.mgt.Explain ;
-import org.apache.jena.sparql.pfunction.PropFuncArg ;
-import org.apache.jena.sparql.pfunction.PropertyFunctionBase ;
-import org.apache.jena.sparql.util.IterLib ;
-import org.apache.jena.sparql.util.NodeFactoryExtra ;
-import org.apache.jena.sparql.util.Symbol ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
+import org.apache.jena.sparql.engine.binding.BindingFactory;
+import org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper;
+import org.apache.jena.sparql.engine.iterator.QueryIterSlice;
+import org.apache.jena.sparql.mgt.Explain;
+import org.apache.jena.sparql.pfunction.PropFuncArg;
+import org.apache.jena.sparql.pfunction.PropertyFunctionBase;
+import org.apache.jena.sparql.util.IterLib;
+import org.apache.jena.sparql.util.NodeFactoryExtra;
+import org.apache.jena.sparql.util.Symbol;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** property function that accesses a text index */
 public class TextQueryPF extends PropertyFunctionBase {
-    private static Logger log = LoggerFactory.getLogger(TextQueryPF.class) ;
+    private static Logger log = LoggerFactory.getLogger(TextQueryPF.class);
     /*
      * (?uri ?score) :queryPF (property? "string" limit? score?)
      */
 
-    private TextIndex     textIndex        = null ;
-    private boolean       warningIssued = false ;
+    private TextIndex     textIndex        = null;
+    private boolean       warningIssued = false;
 
     public TextQueryPF() {}
 
@@ -75,9 +75,9 @@ public class TextQueryPF extends PropertyFunctionBase {
 
     @Override
     public void build(PropFuncArg argSubject, Node predicate, PropFuncArg 
argObject, ExecutionContext execCxt) {
-        super.build(argSubject, predicate, argObject, execCxt) ;
-        DatasetGraph dsg = execCxt.getDataset() ;
-        textIndex = chooseTextIndex(execCxt, dsg) ;
+        super.build(argSubject, predicate, argObject, execCxt);
+        DatasetGraph dsg = execCxt.getDataset();
+        textIndex = chooseTextIndex(execCxt, dsg);
 
         if (argSubject.isList()) {
             int size = argSubject.getArgListSize();
@@ -87,23 +87,23 @@ public class TextQueryPF extends PropertyFunctionBase {
         }
 
         if (argObject.isList()) {
-            List<Node> list = argObject.getArgList() ;
+            List<Node> list = argObject.getArgList();
             int sz = list.size();
 
             if (sz == 0)
-                throw new QueryBuildException("Zero-length argument list") ;
+                throw new QueryBuildException("Zero-length argument list");
 
-            int numProps = 0 ;
+            int numProps = 0;
             while (numProps < sz && list.get(numProps).isURI()) {
-                numProps++ ;
+                numProps++;
             }
 
             if (sz-numProps < 1) {
-                throw new QueryBuildException("No query string just properties 
in list : " + list) ;
+                throw new QueryBuildException("No query string just properties 
in list : " + list);
             }
 
             if (sz-numProps > 4) {
-                throw new QueryBuildException("Too many arguments in list : " 
+ list) ;
+                throw new QueryBuildException("Too many arguments in list : " 
+ list);
             }
         }
     }
@@ -124,19 +124,19 @@ public class TextQueryPF extends PropertyFunctionBase {
      */
     private static TextIndex chooseTextIndex(ExecutionContext execCxt, 
DatasetGraph dsg) {
 
-        Object obj = execCxt.getContext().get(TextQuery.textIndex) ;
+        Object obj = execCxt.getContext().get(TextQuery.textIndex);
 
         if ( obj instanceof TextIndex )
-            return (TextIndex)obj ;
+            return (TextIndex)obj;
         if ( obj != null )
-            Log.warn(TextQueryPF.class, "Context setting '" + 
TextQuery.textIndex + "' is not a TextIndex") ;
+            Log.warn(TextQueryPF.class, "Context setting '" + 
TextQuery.textIndex + "' is not a TextIndex");
 
         if (dsg instanceof DatasetGraphText) {
-            DatasetGraphText x = (DatasetGraphText)dsg ;
-            return x.getTextIndex() ;
+            DatasetGraphText x = (DatasetGraphText)dsg;
+            return x.getTextIndex();
         }
-        Log.warn(TextQueryPF.class, "Failed to find the text index : tried 
context and as a text-enabled dataset") ;
-        return null ;
+        Log.warn(TextQueryPF.class, "Failed to find the text index : tried 
context and as a text-enabled dataset");
+        return null;
     }
 
     private String extractArg(String prefix, List<Node> objArgs) {
@@ -158,23 +158,23 @@ public class TextQueryPF extends PropertyFunctionBase {
                               PropFuncArg argSubject, Node predicate, 
PropFuncArg argObject,
                               ExecutionContext execCxt) {
         if (log.isTraceEnabled()) {
-            IndentedLineBuffer subjBuff = new IndentedLineBuffer() ;
-            argSubject.output(subjBuff, null) ;
-            IndentedLineBuffer objBuff = new IndentedLineBuffer() ;
-            argObject.output(objBuff, null) ;
-            log.trace("exec: {} text:query {}", subjBuff, objBuff) ;
+            IndentedLineBuffer subjBuff = new IndentedLineBuffer();
+            argSubject.output(subjBuff, null);
+            IndentedLineBuffer objBuff = new IndentedLineBuffer();
+            argObject.output(objBuff, null);
+            log.trace("exec: {} text:query {}", subjBuff, objBuff);
         }
         if (textIndex == null) {
             if (!warningIssued) {
-                Log.warn(getClass(), "No text index - no text search 
performed") ;
-                warningIssued = true ;
+                Log.warn(getClass(), "No text index - no text search 
performed");
+                warningIssued = true;
             }
             // Not a text dataset - no-op
-            return IterLib.result(binding, execCxt) ;
+            return IterLib.result(binding, execCxt);
         }
 
-        argSubject = Substitute.substitute(argSubject, binding) ;
-        argObject = Substitute.substitute(argObject, binding) ;
+        argSubject = Substitute.substitute(argSubject, binding);
+        argObject = Substitute.substitute(argObject, binding);
 
         Node s = null;
         Node score = null;
@@ -189,44 +189,44 @@ public class TextQueryPF extends PropertyFunctionBase {
             if (argSubject.getArgListSize() > 1) {
                 score = argSubject.getArg(1);
                 if (!score.isVariable())
-                    throw new QueryExecException("Hit score is not a variable: 
"+argSubject) ;
+                    throw new QueryExecException("Hit score is not a variable: 
"+argSubject);
             }
 
             if (argSubject.getArgListSize() > 2) {
                 literal = argSubject.getArg(2);
                 if (!literal.isVariable())
-                    throw new QueryExecException("Hit literal is not a 
variable: "+argSubject) ;
+                    throw new QueryExecException("Hit literal is not a 
variable: "+argSubject);
             }
 
             if (argSubject.getArgListSize() > 3) {
                 graph = argSubject.getArg(3);
                 if (!graph.isVariable())
-                    throw new QueryExecException("Hit graph is not a variable: 
"+argSubject) ;
+                    throw new QueryExecException("Hit graph is not a variable: 
"+argSubject);
             }
 
             if (argSubject.getArgListSize() > 4) {
                 prop = argSubject.getArg(4);
                 if (!prop.isVariable())
-                    throw new QueryExecException("Hit prop is not a variable: 
"+argSubject) ;
+                    throw new QueryExecException("Hit prop is not a variable: 
"+argSubject);
             }
         } else {
-            s = argSubject.getArg() ;
+            s = argSubject.getArg();
         }
 
         if (s.isLiteral())
             // Does not match
-            return IterLib.noResults(execCxt) ;
+            return IterLib.noResults(execCxt);
 
-        StrMatch match = objectToStruct(argObject, true) ;
+        StrMatch match = objectToStruct(argObject, true);
         if (match == null) {
             // can't match
-            return IterLib.noResults(execCxt) ;
+            return IterLib.noResults(execCxt);
         }
 
-        QueryIterator qIter = prepareQuery(binding, s, score, literal, graph, 
prop, match, execCxt) ;
+        QueryIterator qIter = prepareQuery(binding, s, score, literal, graph, 
prop, match, execCxt);
         if (match.getLimit() >= 0)
-            qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt) ;
-        return qIter ;
+            qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
+        return qIter;
     }
 
     private static void addIf(BindingBuilder builder, Var var, Node node) {
@@ -236,12 +236,12 @@ public class TextQueryPF extends PropertyFunctionBase {
     }
 
     private QueryIterator resultsToQueryIterator(Binding binding, Node subj, 
Node score, Node literal, Node graph, Node prop, Collection<TextHit> results, 
ExecutionContext execCxt) {
-        log.trace("resultsToQueryIterator CALLED with results: {}", results) ;
-        Var sVar = Var.isVar(subj) ? Var.alloc(subj) : null ;
-        Var scoreVar = (score==null) ? null : Var.alloc(score) ;
-        Var literalVar = (literal==null) ? null : Var.alloc(literal) ;
-        Var graphVar = (graph==null) ? null : Var.alloc(graph) ;
-        Var propVar = (prop==null) ? null : Var.alloc(prop) ;
+        log.trace("resultsToQueryIterator CALLED with results: {}", results);
+        Var sVar = Var.isVar(subj) ? Var.alloc(subj) : null;
+        Var scoreVar = (score==null) ? null : Var.alloc(score);
+        Var literalVar = (literal==null) ? null : Var.alloc(literal);
+        Var graphVar = (graph==null) ? null : Var.alloc(graph);
+        Var propVar = (prop==null) ? null : Var.alloc(prop);
 
         Function<TextHit,Binding> converter = (TextHit hit) -> {
             if (score == null && literal == null)
@@ -252,17 +252,17 @@ public class TextQueryPF extends PropertyFunctionBase {
             addIf(bmap, literalVar, hit.getLiteral());
             addIf(bmap, graphVar, hit.getGraph());
             addIf(bmap, propVar, hit.getProp());
-            log.trace("resultsToQueryIterator RETURNING bmap: {}", bmap) ;
+            log.trace("resultsToQueryIterator RETURNING bmap: {}", bmap);
             return bmap.build();
-        } ;
+        };
 
         Iterator<Binding> bIter = Iter.map(results.iterator(), converter);
         QueryIterator qIter = QueryIterPlainWrapper.create(bIter, execCxt);
-        return qIter ;
+        return qIter;
     }
 
     private QueryIterator prepareQuery(Binding binding, Node subj, Node score, 
Node literal, Node graph, Node prop, StrMatch match, ExecutionContext execCxt) {
-        log.trace("prepareQuery with subject: {}; params: {}", subj, match) ;
+        log.trace("prepareQuery with subject: {}; params: {}", subj, match);
         ListValuedMap<String,TextHit> rezList;
 
         if (!Var.isVar(subj))
@@ -271,9 +271,9 @@ public class TextQueryPF extends PropertyFunctionBase {
         rezList = query(subj, match, execCxt);
 
         if ( rezList == null ) // null return value - empty result
-            return IterLib.noResults(execCxt) ;
+            return IterLib.noResults(execCxt);
 
-        Collection<TextHit> hits ;
+        Collection<TextHit> hits;
         if (Var.isVar(subj)) {
             hits = rezList.values();
         } else {
@@ -295,14 +295,14 @@ public class TextQueryPF extends PropertyFunctionBase {
 
         if (textIndex.getDocDef().areQueriesCached()) {
             // Cache-key does not matter if lang or graphURI are null
-            String cacheKey = subj + " " + limit + " " + match.getProps() + " 
" + qs + " " + lang + " " + graphURI ;
+            String cacheKey = subj + " " + limit + " " + match.getProps() + " 
" + qs + " " + lang + " " + graphURI;
             Cache<String, ListValuedMap<String, TextHit>> queryCache = 
prepareCache(execCxt);
 
-            log.trace("Caching Text query: {} with key: >>{}<< in cache: {}", 
qs, cacheKey, queryCache) ;
+            log.trace("Caching Text query: {} with key: >>{}<< in cache: {}", 
qs, cacheKey, queryCache);
 
             return queryCache.get(cacheKey, (k)->performQuery(subj, match, qs, 
graphURI, lang, limit, highlight));
         } else {
-            log.trace("Executing w/o cache Text query: {}", qs) ;
+            log.trace("Executing w/o cache Text query: {}", qs);
             return performQuery(subj, match, qs, graphURI, lang, limit, 
highlight);
         }
     }
@@ -321,11 +321,11 @@ public class TextQueryPF extends PropertyFunctionBase {
 
     private void explainQuery(String queryString, int limit, ExecutionContext 
execCxt, String graphURI) {
         if ( graphURI == null ) {
-            Explain.explain(execCxt.getContext(), "Text query: "+queryString) ;
-            log.debug("Text query: {} ({})", queryString, limit) ;
+            Explain.explain(execCxt.getContext(), "Text query: "+queryString);
+            log.debug("Text query: {} ({})", queryString, limit);
         } else {
-            Explain.explain(execCxt.getContext(), "Text query <"+graphURI+">: 
"+queryString) ;
-            log.debug("Text query: {} <{}> ({})", queryString, graphURI, 
limit) ;
+            Explain.explain(execCxt.getContext(), "Text query <"+graphURI+">: 
"+queryString);
+            log.debug("Text query: {} <{}> ({})", queryString, graphURI, 
limit);
         }
     }
 
@@ -335,19 +335,19 @@ public class TextQueryPF extends PropertyFunctionBase {
         Graph activeGraph = execCxt.getActiveGraph();
 
         if (textIndex.getDocDef().getGraphField() != null && activeGraph 
instanceof NamedGraph) {
-            NamedGraph namedGraph = (NamedGraph)activeGraph ;
+            NamedGraph namedGraph = (NamedGraph)activeGraph;
             if (!Quad.isUnionGraph(namedGraph.getGraphName())) {
                 graphURI = namedGraph.getGraphName() != null
                         ? 
TextQueryFuncs.graphNodeToString(namedGraph.getGraphName())
-                        : Quad.defaultGraphNodeGenerated.getURI() ;
+                        : Quad.defaultGraphNodeGenerated.getURI();
             }
         }
         return graphURI;
     }
 
     private ListValuedMap<String,TextHit> performQuery(Node subj, StrMatch 
match, String queryString, String graphURI, String lang, int limit, String 
highlight) {
-        List<TextHit> resultList = null ;
-        resultList = textIndex.query(subj, match.getProps(), queryString, 
graphURI, lang, limit, highlight) ;
+        List<TextHit> resultList = null;
+        resultList = textIndex.query(subj, match.getProps(), queryString, 
graphURI, lang, limit, highlight);
         return mapResult(resultList);
     }
 
@@ -362,20 +362,20 @@ public class TextQueryPF extends PropertyFunctionBase {
     private boolean isIndexed(List<Resource> props) {
         for (Resource prop : props) {
             if (! isIndexed(prop.asNode())) {
-                return false ;
+                return false;
             }
         }
-        return true ;
+        return true;
     }
 
     private boolean isIndexed(Node predicate) {
-        EntityDefinition docDef = textIndex.getDocDef() ;
-        String field = docDef.getField(predicate) ;
+        EntityDefinition docDef = textIndex.getDocDef();
+        String field = docDef.getField(predicate);
         if (field == null) {
-            log.warn("Predicate not indexed: " + predicate) ;
-            return false ;
+            log.warn("Predicate not indexed: " + predicate);
+            return false;
         }
-        return true ;
+        return true;
     }
 
     /**
@@ -384,92 +384,92 @@ public class TextQueryPF extends PropertyFunctionBase {
      * static check, or for runtime execution.
      */
     private StrMatch objectToStruct(PropFuncArg argObject, boolean 
executionTime) {
-        List<Resource> props = new ArrayList<>() ;
+        List<Resource> props = new ArrayList<>();
 
         if (argObject.isNode()) {
             // should be a single query string that will be searched on the 
text:defaultField
-            Node o = argObject.getArg() ;
+            Node o = argObject.getArg();
             if (!o.isLiteral()) {
                 if ( executionTime )
-                    log.warn("Object to text:query is not a literal " + 
argObject) ;
-                return null ;
+                    log.warn("Object to text:query is not a literal " + 
argObject);
+                return null;
             }
 
             String lang = o.getLiteralLanguage();
-            RDFDatatype dt = o.getLiteralDatatype() ;
+            RDFDatatype dt = o.getLiteralDatatype();
             if (lang.isEmpty()) {
                 if (dt != null && dt != XSDDatatype.XSDstring) {
-                    log.warn("Object to text query is not a string") ;
-                    return null ;
+                    log.warn("Object to text query is not a string");
+                    return null;
                 }
                 lang = null;
             }
 
-            String qs = o.getLiteralLexicalForm() ;
-            return new StrMatch(props, qs, lang, -1, 0, null) ;
+            String qs = o.getLiteralLexicalForm();
+            return new StrMatch(props, qs, lang, -1, 0, null);
         }
 
-        List<Node> list = argObject.getArgList() ;
+        List<Node> list = argObject.getArgList();
 
         if (list.size() == 0)
-            throw new TextIndexException("text:query object list can not be 
empty") ;
+            throw new TextIndexException("text:query object list can not be 
empty");
 
-        int idx = 0 ;
-        Node x = list.get(idx) ;
+        int idx = 0;
+        Node x = list.get(idx);
         // Property?
         while (x.isURI()) {
-            Property prop = ResourceFactory.createProperty(x.getURI()) ;
-            log.trace("objectToStruct: x.isURI(), prop: " + prop + " at idx: " 
+ (idx)) ;
-            List<Resource> pList = Util.getPropList(prop) ;
-            log.trace("objectToStruct: PROPERTY at " + idx + " IS " + prop + " 
WITH pList: " + pList) ;
+            Property prop = ResourceFactory.createProperty(x.getURI());
+            log.trace("objectToStruct: x.isURI(), prop: " + prop + " at idx: " 
+ (idx));
+            List<Resource> pList = Util.getPropList(prop);
+            log.trace("objectToStruct: PROPERTY at " + idx + " IS " + prop + " 
WITH pList: " + pList);
             if (pList != null) {
-                props.addAll(pList) ;
+                props.addAll(pList);
             } else {
-                props.add(prop) ;
+                props.add(prop);
             }
-            idx++ ;
+            idx++;
             if (idx >= list.size())
-                throw new TextIndexException("List of properties specified but 
no query string : " + list) ;
+                throw new TextIndexException("List of properties specified but 
no query string : " + list);
             if (! isIndexed(props)) {
-                log.warn("objectToStruct: props are not indexed " + props) ;
-                return null ;
+                log.warn("objectToStruct: props are not indexed " + props);
+                return null;
             }
-            x = list.get(idx) ;
+            x = list.get(idx);
         }
 
         // String!
         if (!x.isLiteral()) {
             if ( executionTime )
-                log.warn("Text query string is not a literal " + list + " AT 
idx: " + idx) ;
-            return null ;
+                log.warn("Text query string is not a literal " + list + " AT 
idx: " + idx);
+            return null;
         }
         String lang = x.getLiteralLanguage();
         if (lang.isEmpty()) {
             if (x.getLiteralDatatype() != null && 
!x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
-                log.warn("Text query is not a string " + list) ;
-                return null ;
+                log.warn("Text query is not a string " + list);
+                return null;
             }
             lang = null;
         }
 
-        String queryString = x.getLiteralLexicalForm() ;
-        idx++ ;
+        String queryString = x.getLiteralLexicalForm();
+        idx++;
 
-        int limit = -1 ;
-        float score = 0 ;
+        int limit = -1;
+        float score = 0;
 
         if (idx < list.size()) {
             // Limit?
-            x = list.get(idx) ;
-            idx++ ;
+            x = list.get(idx);
+            idx++;
             if ( ! x.isLiteral() ) {
                 if ( executionTime )
-                    log.warn("Text query limit is not an integer " + x) ;
-                return null ;
+                    log.warn("Text query limit is not an integer " + x);
+                return null;
             }
 
-            int v = NodeFactoryExtra.nodeToInt(x) ;
-            limit = (v < 0) ? -1 : v ;
+            int v = NodeFactoryExtra.nodeToInt(x);
+            limit = (v < 0) ? -1 : v;
         }
 
         //extract extra lang arg if present and if is usable.
@@ -480,31 +480,31 @@ public class TextQueryPF extends PropertyFunctionBase {
 
         String highlight = extractArg("highlight", list);
 
-        return new StrMatch(props, queryString, lang, limit, score, highlight) 
;
+        return new StrMatch(props, queryString, lang, limit, score, highlight);
     }
 
     class StrMatch {
-        private final List<Resource>   props ;
-        private final String queryString ;
-        private final String lang ;
-        private final int    limit ;
-        private       int    queryLimit ;
-        private final float  scoreLimit ;
-        private final String highlight ;
+        private final List<Resource>   props;
+        private final String queryString;
+        private final String lang;
+        private final int    limit;
+        private       int    queryLimit;
+        private final float  scoreLimit;
+        private final String highlight;
 
         public StrMatch(List<Resource> props, String queryString, String lang, 
int limit, float scoreLimit, String highlight) {
-            super() ;
-            this.props = props ;
-            this.queryString = queryString ;
-            this.lang = lang ;
-            this.limit = limit ;
-            this.queryLimit = limit ;
-            this.scoreLimit = scoreLimit ;
+            super();
+            this.props = props;
+            this.queryString = queryString;
+            this.lang = lang;
+            this.limit = limit;
+            this.queryLimit = limit;
+            this.scoreLimit = scoreLimit;
             this.highlight = highlight;
         }
 
         public List<Resource> getProps() {
-            return props ;
+            return props;
         }
 
         public boolean hasProps() {
@@ -512,31 +512,31 @@ public class TextQueryPF extends PropertyFunctionBase {
         }
 
         public String getQueryString() {
-            return queryString ;
+            return queryString;
         }
 
         public String getLang() {
-            return lang ;
+            return lang;
         }
 
         public int getLimit() {
-            return limit ;
+            return limit;
         }
 
         public void setQueryLimit(int qLimit) {
-            queryLimit = qLimit ;
+            queryLimit = qLimit;
         }
 
         public int getQueryLimit() {
-            return queryLimit ;
+            return queryLimit;
         }
 
         public float getScoreLimit() {
-            return scoreLimit ;
+            return scoreLimit;
         }
 
         public String getHighlight() {
-            return highlight ;
+            return highlight;
         }
 
         @Override


Reply via email to