Java Code Examples for org.apache.jena.sparql.expr.ExprList#size()
The following examples show how to use
org.apache.jena.sparql.expr.ExprList#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ST_Incr.java From sparql-generate with Apache License 2.0 | 6 votes |
@Override public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) { if (args == null) { throw new ARQInternalErrorException("FunctionBase: Null args list"); } if (args.size() != 0) { throw new ExprEvalException("Expecting zero argument"); } IndentedWriter writer = ContextUtils.getTemplateOutput(env.getContext()); if(writer != null) { writer.incIndent(); } else { LOG.warn("calling st:incr() outside TEMPLATE context."); } return EMPTY_NODE; }
Example 2
Source File: ExpandPrefixFunction.java From tarql with BSD 2-Clause "Simplified" License | 5 votes |
@Override public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) { if (args == null) { throw new ARQInternalErrorException("ExpandPrefixFunction: Null args list"); } if (args.size() != 1) { throw new ExprEvalException("ExpandPrefixFunction: Wrong number of arguments: Wanted 1, got " + args.size()); } return exec(args.get(0).eval(binding, env), env.getContext()); }
Example 3
Source File: IteratorFunctionBase0.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 0) { throw new QueryBuildException("Iterator function '" + this.getClass().getName() + "' takes no arguments"); } }
Example 4
Source File: IteratorFunctionBase3.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 3) { throw new QueryBuildException("Selector '" + this.getClass().getName() + "' takes three arguments"); } }
Example 5
Source File: IteratorFunctionBase1.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 1) { throw new QueryBuildException("Selector '" + this.getClass().getName() + "' takes one argument"); } }
Example 6
Source File: IteratorFunctionBase5.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 5) { throw new QueryBuildException("Selector '" + this.getClass().getName() + "' takes 5 arguments"); } }
Example 7
Source File: IteratorStreamFunctionBase3.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 3) { throw new QueryBuildException("Selector '" + this.getClass().getName() + "' takes three arguments"); } }
Example 8
Source File: ExpandPrefixedNameFunction.java From tarql with BSD 2-Clause "Simplified" License | 5 votes |
@Override public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) { if (args == null) { throw new ARQInternalErrorException("ExpandPrefixFunction: Null args list"); } if (args.size() != 1) { throw new ExprEvalException("ExpandPrefixFunction: Wrong number of arguments: Wanted 1, got " + args.size()); } return exec(args.get(0).eval(binding, env), env.getContext()); }
Example 9
Source File: IteratorStreamFunctionBase5.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 5) { throw new QueryBuildException("Selector '" + this.getClass().getName() + "' takes 5 arguments"); } }
Example 10
Source File: IteratorFunctionBase4.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void checkBuild(ExprList args) { if (args.size() != 4) { throw new QueryBuildException("Selector '" + this.getClass().getName() + "' takes 4 arguments"); } }
Example 11
Source File: ITER_WebSocket.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void checkBuild(ExprList args) { if (args.size() != 1 && args.size() != 2) { throw new QueryBuildException("Function '" + this.getClass().getName() + "' takes two arguments: (1) " + "the server URI to connect to, (2) the message to be sent to" + " the server (e.g., a json query)."); } }
Example 12
Source File: ST_Concat.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public final void build(String uri, ExprList args) { if (args.size() < 1) { throw new ExprEvalException("Expecting at least one argument"); } }
Example 13
Source File: FUN_PrefixedIRI.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public final void build(String uri, ExprList args) { if (args.size() < 1) { throw new ExprEvalException("Expecting at least one argument"); } }
Example 14
Source File: FUN_PrefixedIRI.java From sparql-generate with Apache License 2.0 | 4 votes |
/** * * @param binding * @param args * @param uri * @param env * @return */ @Override public NodeValue exec( final Binding binding, final ExprList args, final String uri, final FunctionEnv env) { if (args == null) { throw new ARQInternalErrorException("FunctionBase: Null args list"); } if (args.size() != 1) { throw new ExprEvalException("Expecting one argument"); } NodeValue node = args.get(0).eval(binding, env); if (node == null) { throw new ExprEvalException("The input did not resolve to a IRI: " + args.get(0)); } if (!node.isIRI()) { LOG.debug("The input should be a IRI. Got " + node); throw new ExprEvalException("The input should be a IRI. Got " + node); } String longIRI = node.asNode().getURI(); Dataset dataset = ContextUtils.getDataset(env.getContext()); final Map<String, String> prefixMap = dataset.getDefaultModel().getNsPrefixMap(); final Set<String> prefixes = prefixMap.keySet(); String prefix = null; String localName = uri; for (String p : prefixes) { String ns = prefixMap.get(p); if (longIRI.startsWith(ns)) { String ln = longIRI.substring(ns.length()); if (ln.length() <= localName.length()) { prefix = p; localName = ln; } } } if(prefix != null) { return new NodeValueString(prefix + ":" + localName); } else { return new NodeValueString(longIRI); } }
Example 15
Source File: ST_Decr.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public final void build(String uri, ExprList args) { if (args.size() != 0) { throw new ExprEvalException("Expecting zero argument"); } }
Example 16
Source File: ST_Call_Template.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public final void build(String uri, ExprList args) { if (args.size() < 1) { throw new ExprEvalException("Expecting at least one argument"); } }
Example 17
Source File: ST_Call_Template.java From sparql-generate with Apache License 2.0 | 4 votes |
/** * * @param binding * @param args * @param uri * @param env * @return */ @Override public NodeValue exec( final Binding binding, final ExprList args, final String uri, final FunctionEnv env) { if (args == null) { throw new ARQInternalErrorException("FunctionBase: Null args list"); } if (args.size() < 1) { throw new ExprEvalException("Expecting at least one argument"); } NodeValue queryNode = args.get(0).eval(binding, env); if (!(queryNode.isIRI() || queryNode.isLiteral() && SPARQLExt.MEDIA_TYPE_URI.equals(queryNode.getDatatypeURI()))) { throw new ExprEvalException("Name of sub query " + "should be a URI or a literal with datatype " + SPARQLExt.MEDIA_TYPE_URI + ". Got: " + queryNode); } if (queryNode.isLiteral() && args.size() > 1) { throw new ExprEvalException("Expecting at most one argument when first argument is a literal."); } final Context context = env.getContext(); final QueryExecutor queryExecutor = ContextUtils.getQueryExecutor(context); try(ByteArrayOutputStream baos = new ByteArrayOutputStream(); IndentedWriter writer = new IndentedWriter(baos);) { Context newContext = ContextUtils.fork(context).setTemplateOutput(writer).fork(); if (queryNode.isIRI()) { String queryName = queryNode.asNode().getURI(); List<List<Node>> callParameters = new ArrayList<>(); callParameters.add(EvalUtils.eval(args.subList(1, args.size()), binding, env)); queryExecutor.execTemplateFromName(queryName, callParameters, newContext); return new NodeValueString(new String(baos.toByteArray())); } String queryString = queryNode.asNode().getLiteralLexicalForm(); queryExecutor.execTemplateFromString(queryString, binding, newContext); String result = new String(baos.toByteArray()); writer.close(); // need to flush. One before the other isn't important. boas.close is the only variant that doesn't work. return new NodeValueString(result); } catch (IOException ex) { throw new ExprEvalException(ex); } }
Example 18
Source File: FUN_Select_Call_Template.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public final void build(String uri, ExprList args) { if (args.size() < 2) { throw new ExprEvalException("Expecting at least two arguments"); } }
Example 19
Source File: FUN_Select_Call_Template.java From sparql-generate with Apache License 2.0 | 4 votes |
/** * * @param binding * @param args * @param uri * @param env * @return */ @Override public NodeValue exec( final Binding binding, final ExprList args, final String uri, final FunctionEnv env) { if (args == null) { throw new ARQInternalErrorException("FunctionBase: Null args list"); } if (args.size() < 2) { throw new ExprEvalException("Expecting at least two arguments"); } NodeValue selectQueryNode = null; if(args.get(0) != null) { selectQueryNode = args.get(0).eval(binding, env); if (!(selectQueryNode.isLiteral() && SPARQLExt.MEDIA_TYPE_URI.equals(selectQueryNode.getDatatypeURI()))) { throw new ExprEvalException("First argument must be a literal with datatype " + SPARQLExt.MEDIA_TYPE_URI + ". Got: " + selectQueryNode); } } NodeValue templateQueryNode = args.get(1).eval(binding, env); if (!(templateQueryNode.isIRI())) { throw new ExprEvalException("Second argument must be a URI. Got: " + templateQueryNode); } ExprList callArgs = args.subList(2, args.size()); final Context context = env.getContext(); final QueryExecutor queryExecutor = ContextUtils.getQueryExecutor(context); final List<List<Node>> callParameters = new ArrayList<>(); if(selectQueryNode != null) { RootPlan selectPlan = queryExecutor.getPlanFromString(selectQueryNode.asString(), null); List<Binding> bindings = new ArrayList<>(); bindings.add(binding); ResultSet resultSet = selectPlan.execSelect(bindings, context); for(;resultSet.hasNext();) { Binding newBinding = resultSet.nextBinding(); callParameters.add(EvalUtils.eval(callArgs, newBinding, env)); } } else { callParameters.add(EvalUtils.eval(callArgs, binding, env)); } String templateQueryName = templateQueryNode.asNode().getURI(); try(ByteArrayOutputStream baos = new ByteArrayOutputStream(); IndentedWriter writer = new IndentedWriter(baos);) { Context newContext = ContextUtils.fork(context).setTemplateOutput(writer).fork(); queryExecutor.execTemplateFromName(templateQueryName, callParameters, newContext); String result = new String(baos.toByteArray()); writer.close(); // need to flush. One before the other isn't important. boas.close is the only variant that doesn't work. return new NodeValueString(result); } catch (IOException ex) { throw new ExprEvalException(ex); } }
Example 20
Source File: FUN_Property.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public final void build(String uri, ExprList args) { if (args.size() != 2) { throw new ExprEvalException("Expecting two argument"); } }