Java源码示例:org.eclipse.rdf4j.query.algebra.Lang
示例1
@Override
public void meet(Lang node) throws RDFHandlerException {
Resource currentSubj = subject;
flushPendingStatement();
handler.handleStatement(valueFactory.createStatement(subject, RDF.TYPE, SP.LANG));
predicate = SP.ARG1_PROPERTY;
node.getArg().visit(this);
subject = currentSubj;
predicate = null;
}
示例2
public Value evaluate(Lang node, BindingSet bindings)
throws QueryEvaluationException {
Value argValue = evaluate(node.getArg(), bindings);
if (argValue instanceof Literal) {
Literal literal = (Literal) argValue;
return tripleSource.getValueFactory().createLiteral(literal.getLanguage().orElse(""));
}
throw new ValueExprEvaluationException();
}
示例3
/**
* Evaluate a {@link Lang} node
* @param node the node to evaluate
* @param bindings the set of named value bindings
* @return a {@link Literal} of the language tag of the {@code Literal} returned by evaluating the argument of the {@code node} or a
* {code Literal} representing an empty {@code String} if there is no tag
* @throws ValueExprEvaluationException
* @throws QueryEvaluationException
*/
private Value evaluate(Lang node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException {
Value argValue = evaluate(node.getArg(), bindings);
if (argValue instanceof Literal) {
Literal literal = (Literal) argValue;
Optional<String> langTag = literal.getLanguage();
if (langTag.isPresent()) {
return valueFactory.createLiteral(langTag.get());
}
return valueFactory.createLiteral("");
}
throw new ValueExprEvaluationException();
}
示例4
/**
* @inheritDoc
*/
@Override
public void meet(Lang theOp)
throws Exception
{
unaryMeet("lang", theOp);
}
示例5
@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());
}
}
示例6
@Override
public void meet(Lang node) throws X {
meetUnaryValueOperator(node);
}
示例7
/**
* @inheritDoc
*/
@Override
public void meet(Lang theOp) throws Exception {
unaryMeet("lang", theOp);
}
示例8
/**
* @inheritDoc
*/
@Override
public void meet(Lang theOp) throws Exception {
unaryMeet("lang", theOp);
}
示例9
public static LangMatches langMatches(String theVar, String theLang) {
return new LangMatches(new Lang(new Var(theVar)),
new ValueConstant(SimpleValueFactory.getInstance().createLiteral(theLang)));
}
示例10
@Override
public Lang visit(ASTLang node, Object data) throws VisitorException {
ValueExpr arg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null);
return new Lang(arg);
}
示例11
@Override
public Lang visit(ASTLang node, Object data) throws VisitorException {
return new Lang((ValueExpr) super.visit(node, data));
}
示例12
/**
* 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());
}
}