[ https://issues.apache.org/jira/browse/JENA-1367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16061904#comment-16061904 ]
ASF GitHub Bot commented on JENA-1367: -------------------------------------- Github user kinow commented on a diff in the pull request: https://github.com/apache/jena/pull/266#discussion_r123874995 --- 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 -- I think this doesn't match the current Javadoc? Maybe this change requires some changes to the text in the class Javadoc, that explain the new behaviour. > Property function apf:strSplit is not well-behaved > -------------------------------------------------- > > Key: JENA-1367 > URL: https://issues.apache.org/jira/browse/JENA-1367 > Project: Apache Jena > Issue Type: Bug > Affects Versions: Jena 3.3.0 > Reporter: Richard Cyganiak > Priority: Minor > > The property function apf:strSplit is not well-behaved in cases where it's > invoked on node types other than the obvious case (subject is variable, > object is list of two literals). For example: > {code} > ?x apf:strSplit (?unbound "some regex") > {code} > Assuming {{?unbound}} is an unbound variable, this should simply not match, > but throws a {{NotLiteralException}}. > {code} > "foo" apf:strSplit ("foo;bar" ";") > {code} > This should presumably evaluate to true, but evaluates to false (the property > function itself throws ExprEvalException). -- This message was sent by Atlassian JIRA (v6.4.14#64029)