org.eclipse.rdf4j.query.algebra.Str Java Examples

The following examples show how to use org.eclipse.rdf4j.query.algebra.Str. 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: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Value evaluate(Str node, BindingSet bindings) throws QueryEvaluationException {
	Value argValue = evaluate(node.getArg(), bindings);

	if (argValue instanceof IRI) {
		return tripleSource.getValueFactory().createLiteral(argValue.toString());
	} else if (argValue instanceof Literal) {
		Literal literal = (Literal) argValue;

		if (QueryEvaluationUtil.isSimpleLiteral(literal)) {
			return literal;
		} else {
			return tripleSource.getValueFactory().createLiteral(literal.getLabel());
		}
	} else if (argValue instanceof Triple) {
		return tripleSource.getValueFactory().createLiteral(argValue.toString());
	} else {
		throw new ValueExprEvaluationException();
	}
}
 
Example #2
Source File: HalyardValueExprEvaluation.java    From Halyard with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluate a {@link Str} node
 * @param node the node to evaluate
 * @param bindings the set of named value bindings
 * @return a literal representation of the evaluation: a URI, the value of a simple literal or the label of any other literal
 * @throws ValueExprEvaluationException
 * @throws QueryEvaluationException
 */
private Value evaluate(Str node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException {
    Value argValue = evaluate(node.getArg(), bindings);
    if (argValue instanceof URI) {
        return valueFactory.createLiteral(argValue.toString());
    } else if (argValue instanceof Literal) {
        Literal literal = (Literal) argValue;
        if (QueryEvaluationUtil.isSimpleLiteral(literal)) {
            return literal;
        } else {
            return valueFactory.createLiteral(literal.getLabel());
        }
    } else {
        throw new ValueExprEvaluationException();
    }
}
 
Example #3
Source File: SpinRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Str node) throws RDFHandlerException {
	Resource currentSubj = subject;
	flushPendingStatement();
	handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, SP.STR));
	predicate = SP.ARG1_PROPERTY;
	node.getArg().visit(this);
	subject = currentSubj;
	predicate = null;
}
 
Example #4
Source File: TestSparqlStarParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testUseInSTR() throws Exception {
	String simpleSparqlQuery = "SELECT (str(<<<urn:a> <urn:b> <urn:c>>>) as ?str) WHERE { } ";

	ParsedQuery q = parser.parseQuery(simpleSparqlQuery, null);

	assertNotNull(q);
	assertTrue("expect projection", q.getTupleExpr() instanceof Projection);
	Projection proj = (Projection) q.getTupleExpr();
	List<ProjectionElem> list = proj.getProjectionElemList().getElements();
	final ArrayList<String> listNames = new ArrayList<>();
	list.forEach(el -> {
		listNames.add(el.getTargetName());
	});
	assertEquals("expect one binding", 1, list.size());
	assertTrue("expect str", listNames.contains("str"));

	assertTrue("expect Extension", proj.getArg() instanceof Extension);
	Extension ext = (Extension) proj.getArg();

	assertTrue("one extention element", ext.getElements().size() == 1);
	ExtensionElem elem = ext.getElements().get(0);

	assertEquals("name should match", "str", elem.getName());
	assertTrue("expect Str in extention element", elem.getExpr() instanceof Str);

	assertTrue("expect ValueExprTripleRef in extention element",
			((Str) elem.getExpr()).getArg() instanceof ValueExprTripleRef);
	ValueExprTripleRef ref = (ValueExprTripleRef) ((Str) elem.getExpr()).getArg();
	assertEquals("subject var value", "urn:a", ref.getSubjectVar().getValue().toString());
	assertEquals("predicate var name", "urn:b", ref.getPredicateVar().getValue().toString());
	assertEquals("object var name", "urn:c", ref.getObjectVar().getValue().toString());
}
 
Example #5
Source File: SPARQLValueExprRenderer.java    From semagrow with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Str theOp)
        throws Exception
{
    unaryMeet("str", theOp);
}
 
Example #6
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Value evaluate(ValueExpr expr, BindingSet bindings)
		throws QueryEvaluationException {
	if (expr instanceof Var) {
		return evaluate((Var) expr, bindings);
	} else if (expr instanceof ValueConstant) {
		return evaluate((ValueConstant) expr, bindings);
	} else if (expr instanceof BNodeGenerator) {
		return evaluate((BNodeGenerator) expr, bindings);
	} else if (expr instanceof Bound) {
		return evaluate((Bound) expr, bindings);
	} else if (expr instanceof Str) {
		return evaluate((Str) expr, bindings);
	} else if (expr instanceof Label) {
		return evaluate((Label) expr, bindings);
	} else if (expr instanceof Lang) {
		return evaluate((Lang) expr, bindings);
	} else if (expr instanceof LangMatches) {
		return evaluate((LangMatches) expr, bindings);
	} else if (expr instanceof Datatype) {
		return evaluate((Datatype) expr, bindings);
	} else if (expr instanceof Namespace) {
		return evaluate((Namespace) expr, bindings);
	} else if (expr instanceof LocalName) {
		return evaluate((LocalName) expr, bindings);
	} else if (expr instanceof IsResource) {
		return evaluate((IsResource) expr, bindings);
	} else if (expr instanceof IsURI) {
		return evaluate((IsURI) expr, bindings);
	} else if (expr instanceof IsBNode) {
		return evaluate((IsBNode) expr, bindings);
	} else if (expr instanceof IsLiteral) {
		return evaluate((IsLiteral) expr, bindings);
	} else if (expr instanceof IsNumeric) {
		return evaluate((IsNumeric) expr, bindings);
	} else if (expr instanceof IRIFunction) {
		return evaluate((IRIFunction) expr, bindings);
	} else if (expr instanceof Regex) {
		return evaluate((Regex) expr, bindings);
	} else if (expr instanceof Coalesce) {
		return evaluate((Coalesce) expr, bindings);
	} else if (expr instanceof Like) {
		return evaluate((Like) expr, bindings);
	} else if (expr instanceof FunctionCall) {
		return evaluate((FunctionCall) expr, bindings);
	} else if (expr instanceof And) {
		return evaluate((And) expr, bindings);
	} else if (expr instanceof Or) {
		return evaluate((Or) expr, bindings);
	} else if (expr instanceof Not) {
		return evaluate((Not) expr, bindings);
	} else if (expr instanceof SameTerm) {
		return evaluate((SameTerm) expr, bindings);
	} else if (expr instanceof Compare) {
		return evaluate((Compare) expr, bindings);
	} else if (expr instanceof MathExpr) {
		return evaluate((MathExpr) expr, bindings);
	} else if (expr instanceof In) {
		return evaluate((In) expr, bindings);
	} else if (expr instanceof CompareAny) {
		return evaluate((CompareAny) expr, bindings);
	} else if (expr instanceof CompareAll) {
		return evaluate((CompareAll) expr, bindings);
	} else if (expr instanceof Exists) {
		return evaluate((Exists) expr, bindings);
	} else if (expr instanceof If) {
		return evaluate((If) expr, bindings);
	} else if (expr instanceof ListMemberOperator) {
		return evaluate((ListMemberOperator) expr, bindings);
	} else if (expr instanceof ValueExprTripleRef) {
		return evaluate((ValueExprTripleRef) expr, bindings);
	} else if (expr == null) {
		throw new IllegalArgumentException("expr must not be null");
	} else {
		throw new QueryEvaluationException("Unsupported value expr type: " + expr.getClass());
	}
}
 
Example #7
Source File: AbstractQueryModelVisitor.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void meet(Str node) throws X {
	meetUnaryValueOperator(node);
}
 
Example #8
Source File: SparqlValueExprRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Str theOp) throws Exception {
	unaryMeet("str", theOp);
}
 
Example #9
Source File: SerqlValueExprRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public void meet(Str theOp) throws Exception {
	unaryMeet("str", theOp);
}
 
Example #10
Source File: TupleExprBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Object visit(ASTStr node, Object data) throws VisitorException {
	ValueExpr arg = castToValueExpr(node.jjtGetChild(0).jjtAccept(this, null));
	return new Str(arg);
}
 
Example #11
Source File: QueryModelBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Str visit(ASTStr node, Object data) throws VisitorException {
	return new Str((ValueExpr) super.visit(node, data));
}
 
Example #12
Source File: HalyardValueExprEvaluation.java    From Halyard with Apache License 2.0 4 votes vote down vote up
/**
 * Determines which evaluate method to call based on the type of {@link ValueExpr}
 * @param expr the expression to evaluate
 * @param bindings the set of named value bindings the set of named value bindings
 * @return the {@link Value} resulting from the evaluation
 * @throws ValueExprEvaluationException
 * @throws QueryEvaluationException
 */
Value evaluate(ValueExpr expr, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException {
    if (expr instanceof Var) {
        return evaluate((Var) expr, bindings);
    } else if (expr instanceof ValueConstant) {
        return evaluate((ValueConstant) expr, bindings);
    } else if (expr instanceof BNodeGenerator) {
        return evaluate((BNodeGenerator) expr, bindings);
    } else if (expr instanceof Bound) {
        return evaluate((Bound) expr, bindings);
    } else if (expr instanceof Str) {
        return evaluate((Str) expr, bindings);
    } else if (expr instanceof Label) {
        return evaluate((Label) expr, bindings);
    } else if (expr instanceof Lang) {
        return evaluate((Lang) expr, bindings);
    } else if (expr instanceof LangMatches) {
        return evaluate((LangMatches) expr, bindings);
    } else if (expr instanceof Datatype) {
        return evaluate((Datatype) expr, bindings);
    } else if (expr instanceof Namespace) {
        return evaluate((Namespace) expr, bindings);
    } else if (expr instanceof LocalName) {
        return evaluate((LocalName) expr, bindings);
    } else if (expr instanceof IsResource) {
        return evaluate((IsResource) expr, bindings);
    } else if (expr instanceof IsURI) {
        return evaluate((IsURI) expr, bindings);
    } else if (expr instanceof IsBNode) {
        return evaluate((IsBNode) expr, bindings);
    } else if (expr instanceof IsLiteral) {
        return evaluate((IsLiteral) expr, bindings);
    } else if (expr instanceof IsNumeric) {
        return evaluate((IsNumeric) expr, bindings);
    } else if (expr instanceof IRIFunction) {
        return evaluate((IRIFunction) expr, bindings);
    } else if (expr instanceof Regex) {
        return evaluate((Regex) expr, bindings);
    } else if (expr instanceof Coalesce) {
        return evaluate((Coalesce) expr, bindings);
    } else if (expr instanceof Like) {
        return evaluate((Like) expr, bindings);
    } else if (expr instanceof FunctionCall) {
        return evaluate((FunctionCall) expr, bindings);
    } else if (expr instanceof And) {
        return evaluate((And) expr, bindings);
    } else if (expr instanceof Or) {
        return evaluate((Or) expr, bindings);
    } else if (expr instanceof Not) {
        return evaluate((Not) expr, bindings);
    } else if (expr instanceof SameTerm) {
        return evaluate((SameTerm) expr, bindings);
    } else if (expr instanceof Compare) {
        return evaluate((Compare) expr, bindings);
    } else if (expr instanceof MathExpr) {
        return evaluate((MathExpr) expr, bindings);
    } else if (expr instanceof In) {
        return evaluate((In) expr, bindings);
    } else if (expr instanceof CompareAny) {
        return evaluate((CompareAny) expr, bindings);
    } else if (expr instanceof CompareAll) {
        return evaluate((CompareAll) expr, bindings);
    } else if (expr instanceof Exists) {
        return evaluate((Exists) expr, bindings);
    } else if (expr instanceof If) {
        return evaluate((If) expr, bindings);
    } else if (expr instanceof ListMemberOperator) {
        return evaluate((ListMemberOperator) expr, bindings);
    } else if (expr == null) {
        throw new IllegalArgumentException("expr must not be null");
    } else {
        throw new QueryEvaluationException("Unsupported value expr type: " + expr.getClass());
    }
}