Github user cygri commented on a diff in the pull request:
https://github.com/apache/jena/pull/266#discussion_r123897160
--- Diff:
jena-arq/src/main/java/org/apache/jena/sparql/pfunction/library/strSplit.java
---
@@ -44,27 +47,58 @@
*/
public class strSplit extends PFuncSimpleAndList
{
+
+ @Override
+ public void build(PropFuncArg argSubject, Node predicate, PropFuncArg
argObject, ExecutionContext execCxt) {
+ super.build(argSubject, predicate, argObject, execCxt);
+
+ if (argObject.getArgListSize() != 2)
+ throw new QueryBuildException("Object list must contain
exactly two arguments, the string to split and a regular expression") ;
+ }
+
@Override
public QueryIterator execEvaluated(final Binding binding, final Node
subject, final Node predicate, final PropFuncArg object, final ExecutionContext
execCxt)
{
- if (!Var.isVar(subject))
- throw new ExprEvalException("Subject is not a variable (" +
subject + ")") ;
-
- if (object.getArgListSize() != 2)
- throw new ExprEvalException("Object list must contain exactly
two arguments, the string to split and a regular expression") ;
+ if (!object.getArg(0).isLiteral() ||
!object.getArg(1).isLiteral()) {
+ return IterLib.noResults(execCxt);
+ }
+
String s = object.getArg(0).getLiteralLexicalForm() ;
String regex = object.getArg(1).getLiteralLexicalForm() ;
- final Var subjectVar = Var.alloc(subject);
-
// StrUtils will also trim whitespace
- String[] tokens = StrUtils.split(s, regex);
- Iterator<Binding> it = Iter.map(
- Arrays.asList(tokens).iterator(),
- item -> BindingFactory.binding(binding,
subjectVar,
-
NodeFactory.createLiteral(item)));
- return new QueryIterPlainWrapper(it, execCxt);
+ List<String> tokens = Arrays.asList(StrUtils.split(s, regex));
+
+ if (Var.isVar(subject)) {
+
+ // Case: Subject is variable. Return all tokens as results.
+
+ final Var subjectVar = Var.alloc(subject);
+
+ Iterator<Binding> it = Iter.map(
+ tokens.iterator(),
+ item -> BindingFactory.binding(binding, subjectVar,
+ NodeFactory.createLiteral(item)));
+ return new QueryIterPlainWrapper(it, execCxt);
+
+ } else if (subject.isLiteral()
--- End diff --
You are right. I updated the javadoc to match the new behaviour.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---