org.apache.jena.sparql.expr.NodeValue Java Examples

The following examples show how to use org.apache.jena.sparql.expr.NodeValue. 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: ITER_Call_Select.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
private List<List<NodeValue>> getListNodeValues(ResultSet result) {
    List<String> resultVars = result.getResultVars();
    List<List<NodeValue>> listNodeValues = new ArrayList<>();
    while (result.hasNext()) {
        List<NodeValue> nodeValues = new ArrayList<>();
        QuerySolution sol = result.next();
        for (String var : resultVars) {
            RDFNode rdfNode = sol.get(var);
            if (rdfNode != null) {
                NodeValue n = new NodeValueNode(rdfNode.asNode());
                nodeValues.add(n);
            } else {
                nodeValues.add(null);
            }
        }
        listNodeValues.add(nodeValues);
    }
    return listNodeValues;
}
 
Example #2
Source File: SHACLSPARQLARQFunction.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
   public NodeValue executeBody(Dataset dataset, Model defaultModel, QuerySolution bindings) {
    try( QueryExecution qexec = createQueryExecution(dataset, defaultModel, bindings) ) {
        if(arqQuery.isAskType()) {
            boolean result = qexec.execAsk();
            return NodeValue.makeBoolean(result);
        }
        else {
            ResultSet rs = qexec.execSelect();
            if(rs.hasNext()) {
                QuerySolution s = rs.nextSolution();
                List<String> resultVars = rs.getResultVars();
                String varName = resultVars.get(0);
                RDFNode resultNode = s.get(varName);
                if(resultNode != null) {
                    return NodeValue.makeNode(resultNode.asNode());
                }
            }
            throw new ExprEvalException("Empty result set for SHACL function");
        }
    }
}
 
Example #3
Source File: FUN_JSONPath.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public NodeValue exec(NodeValue json, NodeValue jsonpath) {
    if (json.getDatatypeURI() != null
            && !json.getDatatypeURI().equals(datatypeUri)
            && !json.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.debug("The datatype of the first argument should be <" + datatypeUri + ">"
                + " or <http://www.w3.org/2001/XMLSchema#string>. Got "
                + json.getDatatypeURI());
    }
    if (!jsonpath.isString()) {
        LOG.debug("The second argument should be a string. Got " + json);
    }

    try {
        Object value = JsonPath.parse(json.asNode().getLiteralLexicalForm())
                .limit(1).read(jsonpath.getString());
        return nodeForObject(value);
    } catch (Exception ex) {
        if(LOG.isDebugEnabled()) {
            Node compressed = LogUtils.compress(json.asNode());
            LOG.debug("No evaluation of " + compressed + ", " + jsonpath);
        }
        throw new ExprEvalException("No evaluation of " + jsonpath);
    }
}
 
Example #4
Source File: ParserSPARQLStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
protected Triple getBindTriplePattern( String queryString ) {
	final ElementGroup eg = getElementGroup(queryString);
	assertEquals( 1, eg.size() );
	assertTrue( "unexpected type (" + eg.get(0).getClass() + ")", 
			    eg.get(0) instanceof ElementBind );

	final ElementBind eb = (ElementBind) eg.get(0);
	assertTrue( "unexpected type (" + eb.getExpr().getClass() + ")", 
		        eb.getExpr() instanceof NodeValue );

	final Node n = ( (NodeValue) eb.getExpr() ).getNode();
	assertTrue( "unexpected type (" + n.getClass() + ")", 
		        n instanceof Node_Triple );

	return ( (Node_Triple) n ).get();
}
 
Example #5
Source File: FUN_XPath.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
public NodeValue nodeForNode(org.w3c.dom.Node xmlNode) throws TransformerException {
    if(xmlNode == null) {
        return null;
    }
    String nodeValue = xmlNode.getNodeValue();
    if (nodeValue != null) {
        return new NodeValueString(nodeValue);
    } else {
        DOMSource source = new DOMSource(xmlNode);
        StringWriter writer = new StringWriter();
        Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
        transformer.transform(source, new StreamResult(writer));
        Node node = NodeFactory.createLiteral(writer.toString(), DT);
        return new NodeValueNode(node);
    }
}
 
Example #6
Source File: FUN_MixedCase.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public NodeValue exec(NodeValue node) {
    if (!node.isString()) {
        LOG.debug("The input should be a string. Got " + node);
        throw new ExprEvalException("The input should be a string. Got " + node);
    }
    String string = node.getString();
    StringBuilder converted = new StringBuilder();
    boolean convertNext = false;
    for (char ch : string.toCharArray()) {
        if (Character.isWhitespace(ch)) {
            convertNext = true;
        } else if (!Character.isLetterOrDigit(ch)) {
        } else if (convertNext) {
            converted.append(Character.toUpperCase(ch));
            convertNext = false;
        } else {
            converted.append(ch);
        }
    }
    return new NodeValueString(converted.toString());
}
 
Example #7
Source File: FUN_Property.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@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() != 2) {
        throw new ExprEvalException("Expecting two argument");
    }
    NodeValue file = args.get(0).eval(binding, env);
    NodeValue propertyNode = args.get(1).eval(binding, env);
    if (!propertyNode.isString()) {
        throw new ExprEvalException("Second argument must be a string. Got " + propertyNode);
    }
    Properties properties;
    try {
        properties = getProperties(file, env);
    } catch (IOException ex) {
        throw new ExprEvalException("IOException while extracting properties document " + file, ex);
    }
    String prop = properties.getProperty(propertyNode.getString());
    if (prop == null) {
        throw new ExprEvalException("Property " + prop + " not found in properties document " + file);
    }
    return new NodeValueString(prop);
}
 
Example #8
Source File: SHACLFunctionsCache.java    From shacl with Apache License 2.0 6 votes vote down vote up
public NodeValue execute(SHACLARQFunction function, Dataset dataset, Model defaultModel, QuerySolution bindings, Node[] args) {
	Key key = new Key(function.getSHACLFunction().getURI(), args);
	Result result = cache.get(key);
	if(result == null) {
		result = new Result();
		try {
			result.nodeValue = function.executeBody(dataset, defaultModel, bindings);
		}
		catch(ExprEvalException ex) {
			result.ex = ex;
		}
		cache.put(key, result);
	}
	if(result.ex != null) {
		throw new ExprEvalException(result.ex.getMessage());
	}
	else {
		return result.nodeValue;
	}
}
 
Example #9
Source File: ST_Decr.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@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.decIndent();
    } else {
    	LOG.warn("calling st:decr() outside TEMPLATE context.");
    }
    return EMPTY_NODE;
}
 
Example #10
Source File: IsValidForDatatypeFunction.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
protected NodeValue exec(Node literalNode, Node datatypeNode, FunctionEnv env) {
	
	if(literalNode == null || !literalNode.isLiteral()) {
		throw new ExprEvalException();
	}
	String lex = literalNode.getLiteralLexicalForm();
	
	if(!datatypeNode.isURI()) {
		throw new ExprEvalException();
	}
	RDFDatatype datatype = TypeMapper.getInstance().getTypeByName(datatypeNode.getURI());
	
	if(datatype == null) {
		return NodeValue.TRUE;
	}
	else {
		boolean valid = datatype.isValid(lex);
		return NodeValue.makeBoolean(valid);
	}
}
 
Example #11
Source File: AbstractClusiveConstraintExecutor.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
public void executeConstraint(Constraint constraint, ValidationEngine engine, Collection<RDFNode> focusNodes) {
	long startTime = System.currentTimeMillis();
	NodeValue cmpValue = NodeValue.makeNode(constraint.getParameterValue().asNode());
	for(RDFNode focusNode : focusNodes) {
		for(RDFNode valueNode : engine.getValueNodes(constraint, focusNode)) {				
			try {
		        NodeValue value = NodeValue.makeNode(valueNode.asNode());
				int c = NodeValue.compare(cmpValue, value);
				if (c == Expr.CMP_INDETERMINATE) {
					engine.createValidationResult(constraint, focusNode, valueNode, () -> "Indeterminant comparison with " + engine.getLabelFunction().apply(constraint.getParameterValue())); 
				}
				else if(!condition.test(c)) {
					engine.createValidationResult(constraint, focusNode, valueNode, () -> "Value is not " + operator + " " + engine.getLabelFunction().apply(constraint.getParameterValue())); 
				}
			}
			catch (ExprNotComparableException ex) {
				engine.createValidationResult(constraint, focusNode, valueNode, () -> "Cannot compare with " + engine.getLabelFunction().apply(constraint.getParameterValue())); 
			}
		}
		engine.checkCanceled();
	}
	addStatistics(constraint, startTime);
}
 
Example #12
Source File: ElementTransformSPARQLStar.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
@Override
public Element transform( ElementBind eb, Var v, Expr expr2 )
{
	if (    ( eb.getExpr() instanceof NodeValue )
	     && ( ((NodeValue) eb.getExpr()).getNode() instanceof Node_Triple ) )
	{
		final NodeValue nv = (NodeValue) eb.getExpr();
		final Node_Triple nt = (Node_Triple) nv.getNode();
		final Triple tp = nt.get();

		final ElementPathBlock epb = new ElementPathBlock();
		unNestBindClause(tp, epb, v);
		return epb;
	}
	else
		return super.transform(eb, v, expr2);
}
 
Example #13
Source File: IteratorFunctionBase3.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 3) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 3, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    return exec(v1, v2, v3);
}
 
Example #14
Source File: BindPlan.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
protected final Binding exec(Binding binding, Context context) {
    LOG.debug("Start " + this);
    context.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
    final FunctionEnv env = new FunctionEnvBase(context);
    try {
        final NodeValue n = expr.eval(binding, env);
        if (LOG.isTraceEnabled()) {
            LOG.trace("New binding " + var + " = " + LogUtils.compress(n.asNode()));
        }
        return BindingFactory.binding(binding, var, n.asNode());
    } catch(ExprEvalException ex) {
        LOG.trace("No evaluation for " + this + " " + ex.getMessage());
        return binding;
    }
}
 
Example #15
Source File: ITER_Call_Select.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public void exec(
        final List<NodeValue> args,
        final Consumer<List<List<NodeValue>>> collectionListNodeValue) {
    if (args.isEmpty()) {
        LOG.debug("There should be at least one IRI parameter.");
        throw new ExprEvalException("There should be at least one IRI parameter.");
    }
    if (!args.get(0).isIRI()) {
        LOG.debug("The first parameter must be a IRI.");
        throw new ExprEvalException("The first parameter must be a IRI.");
    }
    String queryName = args.get(0).asNode().getURI();

    final List<List<Node>> callParameters = new ArrayList<>();
    callParameters.add(EvalUtils.eval(args.subList(1, args.size())));

    final Context context = ContextUtils.fork(getContext()).setSelectOutput((result) -> {
        List<List<NodeValue>> list = getListNodeValues(result);
        collectionListNodeValue.accept(list);
    }).fork();
    final QueryExecutor queryExecutor = ContextUtils.getQueryExecutor(context);
    queryExecutor.execSelectFromName(queryName, callParameters, context);
}
 
Example #16
Source File: JenaUtil.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static Node invokeFunction(Resource function, ExprList args, Dataset dataset) {

		if (dataset == null) {
	        dataset = ARQFactory.get().getDataset(ModelFactory.createDefaultModel());
	    }
		
		E_Function expr = new E_Function(function.getURI(), args);
		DatasetGraph dsg = dataset.asDatasetGraph();
		Context cxt = ARQ.getContext().copy();
		cxt.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
		FunctionEnv env = new ExecutionContext(cxt, dsg.getDefaultGraph(), dsg, null);
		try {
			NodeValue r = expr.eval(BindingRoot.create(), env);
			if(r != null) {
				return r.asNode();
			}
		}
		catch(ExprEvalException ex) {
		}
		return null;
	}
 
Example #17
Source File: IteratorFunctionBase4.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 4) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 4, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    return exec(v1, v2, v3, v4);
}
 
Example #18
Source File: SPARQLExtIteratorFunction.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
private List<List<NodeValue>> getListNodeValues(ResultSet result) {
	List<String> resultVars = result.getResultVars();
	List<List<NodeValue>> listNodeValues = new ArrayList<>();
	while (result.hasNext()) {
		List<NodeValue> nodeValues = new ArrayList<>();
		QuerySolution sol = result.next();
		for (String var : resultVars) {
			RDFNode rdfNode = sol.get(var);
			if (rdfNode != null) {
				NodeValue n = new NodeValueNode(rdfNode.asNode());
				nodeValues.add(n);
			} else {
				nodeValues.add(null);
			}
		}
		listNodeValues.add(nodeValues);
	}
	return listNodeValues;
}
 
Example #19
Source File: IteratorFunctionBase5.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 5) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 5, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    NodeValue v5 = args.get(4);
    return exec(v1, v2, v3, v4, v5);
}
 
Example #20
Source File: IteratorStreamFunctionBase2.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 2) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 2, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    exec(v1, v2, nodeValuesStream);
}
 
Example #21
Source File: IteratorStreamFunctionBase5.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 5) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 5, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    NodeValue v5 = args.get(4);
    exec(v1, v2, v3, v4, v5, nodeValuesStream);
}
 
Example #22
Source File: IteratorStreamFunctionBase.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public final void exec(
        final Binding binding,
        final ExprList args,
        final FunctionEnv env,
        final Consumer<List<List<NodeValue>>> collectionListNodeValue) {

    this.env = env;
    if (args == null) {
        throw new ARQInternalErrorException("IteratorFunctionBase:"
                + " Null args list");
    }

    List<NodeValue> evalArgs = new ArrayList<>();
    for (Expr e : args) {
        try {
            NodeValue x = e.eval(binding, env);
            evalArgs.add(x);
        } catch (ExprEvalException ex) {
            LOG.trace("Cannot evaluate node " + e + ": " + ex.getMessage());
            evalArgs.add(null);
        }
    }
    exec(evalArgs, collectionListNodeValue);
}
 
Example #23
Source File: MaxExpression.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
public ExtendedIterator<RDFNode> eval(RDFNode focusNode, NodeExpressionContext context) {
	RDFNode max = null;
	ExtendedIterator<RDFNode> it = evalInput(focusNode, context);
	while(it.hasNext()) {
		RDFNode next = it.next();
		if(max == null || NodeValue.compareAlways(NodeValue.makeNode(max.asNode()), NodeValue.makeNode(next.asNode())) < 0) {
			max = next;
		}
	}
	if(max == null) {
		return WrappedIterator.emptyIterator();
	}
	else {
		return WrappedIterator.create(Collections.singletonList(max).iterator());
	}
}
 
Example #24
Source File: IteratorFunctionBase1.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException("SelectorBase1:"
                + " Null args list");
    }
    if (args.size() != 1) {
        throw new ExprEvalException("SelectorBase1: Wrong number of"
                + " arguments: Wanted 1, got " + args.size());
    }
    NodeValue v1 = args.get(0);
    return exec(v1);
}
 
Example #25
Source File: ITER_CSVHeaders.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public List<List<NodeValue>> exec(NodeValue csv) {
    if (csv.getDatatypeURI() != null
            && !csv.getDatatypeURI().equals(datatypeUri)
            && !csv.getDatatypeURI().equals("http://www.w3.org/2001/XMLSchema#string")) {
        LOG.debug("The URI of NodeValue1 MUST be <" + datatypeUri + ">"
                + "or <http://www.w3.org/2001/XMLSchema#string>."
        );
    }
    try {
        String sourceCSV = String.valueOf(csv.asNode().getLiteralLexicalForm());

        InputStream is = new ByteArrayInputStream(sourceCSV.getBytes("UTF-8"));
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

        CsvMapReader mapReader = new CsvMapReader(br, CsvPreference.STANDARD_PREFERENCE);
        String headers_str[] = mapReader.getHeader(true);

        final List<List<NodeValue>> listNodeValues = new ArrayList<>();
        Node node;
        NodeValue nodeValue;
        for (String header : headers_str) {
            node = NodeFactory.createLiteral(header);
            nodeValue = new NodeValueNode(node);
            listNodeValues.add(Collections.singletonList(nodeValue));
        }
        return listNodeValues;
    } catch (Exception ex) {
        if(LOG.isDebugEnabled()) {
            Node compressed = LogUtils.compress(csv.asNode());
            LOG.debug("No evaluation for " + compressed, ex);
        }
        throw new ExprEvalException("No evaluation ", ex);
    }
}
 
Example #26
Source File: IteratorFunctionBase0.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException("Iterator function '"
                + this.getClass().getName() + " Null args list");
    }
    if (!args.isEmpty()) {
        throw new ExprEvalException("Iterator function '"
                + this.getClass().getName() + " Wanted 0, got "
                + args.size());
    }
    return exec();
}
 
Example #27
Source File: FUN_TitleCase.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public NodeValue exec(NodeValue node) {
    if (!node.isString()) {
        LOG.debug("The input should be a string. Got " + node);
        throw new ExprEvalException("The input should be a string. Got " + node);
    }
    String string = node.getString();
    StringBuilder converted = new StringBuilder();
    boolean firstSpace = false;
    boolean convertNext = true;
    for (char ch : string.toCharArray()) {
        if (Character.isWhitespace(ch)) {
            if(firstSpace) {
                converted.append(' ');
                firstSpace = false;
                convertNext = true;
            }
        } else if (!Character.isLetterOrDigit(ch)) {
        } else if (convertNext) {
            converted.append(Character.toUpperCase(ch));
            convertNext = false;
            firstSpace = true;
        } else {
            converted.append(ch);
            firstSpace = true;
        }
    }
    return new NodeValueString(converted.toString());
}
 
Example #28
Source File: AbstractFunction6.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeValue exec(Node[] nodes, FunctionEnv env) {
	Node arg1 = nodes.length > 0 ? nodes[0] : null;
	Node arg2 = nodes.length > 1 ? nodes[1] : null;
	Node arg3 = nodes.length > 2 ? nodes[2] : null;
	Node arg4 = nodes.length > 3 ? nodes[3] : null;
	Node arg5 = nodes.length > 4 ? nodes[4] : null;
	Node arg6 = nodes.length > 5 ? nodes[5] : null;
	return exec(arg1, arg2, arg3, arg4, arg5, arg6, env);
}
 
Example #29
Source File: FUN_CSSPath.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public NodeValue select(Element htmldoc, String selectPath) throws ExprEvalException {
    if (selectPath.endsWith("/text()")) {
        selectPath = selectPath.substring(0, selectPath.length() - 7);
        return selectText(htmldoc, selectPath);
    } else if (selectPath.matches(".*@[^\"'>/=^$*~]+$")) {
        final String attributeName = selectPath.substring(1 + selectPath.lastIndexOf("@"));
        selectPath = selectPath.replaceAll("@[^\"'>/=^$*~@]+$", "");
        return selectAttribute(htmldoc, selectPath, attributeName);
    } else {
        return selectElement(htmldoc, selectPath);
    }
}
 
Example #30
Source File: DatasetDeclarationPlan.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private String evalSourceURI(Binding binding, Context context, Expr sourceExpr) {
	if (binding == null) {
		throw new NullPointerException("No binding to evaluate the source expression " + sourceExpr);
	}
	try {
		FunctionEnv env = new FunctionEnvBase(context);
		NodeValue nodeValue = sourceExpr.eval(binding, env);
		if (!nodeValue.isIRI()) {
			throw new IllegalArgumentException("FROM source expression did not eval to a URI " + sourceExpr);
		}
		return nodeValue.asNode().getURI();
	} catch (ExprEvalException ex) {
		throw new IllegalArgumentException("Exception when evaluating the source expression " + sourceExpr, ex);
	}
}