本文整理汇总了Java中org.eclipse.rdf4j.query.algebra.Var类的典型用法代码示例。如果您正苦于以下问题:Java Var类的具体用法?Java Var怎么用?Java Var使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Var类属于org.eclipse.rdf4j.query.algebra包,在下文中一共展示了Var类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructStatementCheckId
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Construct the statement string, i.e. "s p ?o_varID FILTER ?o_N=o ". This kind of statement
* pattern is necessary to later on identify available results.
*
* @param stmt
* @param varID
* @param varNames
* @param bindings
* @return
*/
protected static TupleExpr constructStatementCheckId(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings) {
String _varID = Integer.toString(varID);
Var subj = appendVarId(stmt.getSubjectVar(), _varID, varNames, bindings);
Var pred = appendVarId(stmt.getPredicateVar(), _varID, varNames, bindings);
Var obj = new Var("o_" + _varID);
varNames.add("o_" + _varID);
Value objValue;
if (stmt.getObjectVar().hasValue()) {
objValue = stmt.getObjectVar().getValue();
} else if (bindings.hasBinding(stmt.getObjectVar().getName())){
objValue = bindings.getBinding(stmt.getObjectVar().getName()).getValue();
} else {
// just to make sure that we see an error, will be deleted soon
throw new RuntimeException("Unexpected.");
}
Compare cmp = new Compare(obj, new ValueConstant(objValue));
cmp.setOperator(CompareOp.EQ);
Filter filter = new Filter( new StatementPattern(subj, pred, obj), cmp);
return filter;
}
示例2: evaluateZeroLengthPath
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Evaluate {@link ZeroLengthPath} query model nodes
* @param parent
* @param zlp
* @param bindings
*/
private void evaluateZeroLengthPath(BindingSetPipe parent, ZeroLengthPath zlp, BindingSet bindings) {
final Var subjectVar = zlp.getSubjectVar();
final Var objVar = zlp.getObjectVar();
final Var contextVar = zlp.getContextVar();
Value subj = subjectVar.getValue() == null ? bindings.getValue(subjectVar.getName()) : subjectVar.getValue();
Value obj = objVar.getValue() == null ? bindings.getValue(objVar.getName()) : objVar.getValue();
if (subj != null && obj != null) {
if (!subj.equals(obj)) {
try {
parent.push(null);
} catch (InterruptedException e) {
parent.handleException(e);
}
return;
}
}
//temporary solution using copy of the original iterator
//re-writing this to push model is a bit more complex task
HalyardStatementPatternEvaluation.enqueue(parent, new ZeroLengthPathIteration(parentStrategy, subjectVar, objVar, subj, obj, contextVar, bindings), zlp);
}
示例3: renderTupleExpr
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Renders the tuple expression as a query string. It creates a new
* SparqlTupleExprRenderer rather than reusing this one.
*
* @param theExpr
* the expr to render
* @return the rendered expression
* @throws Exception
* if there is an error while rendering
*/
private String renderTupleExpr(TupleExpr theExpr)
throws Exception
{
SPARQLTupleExprRenderer aRenderer = new SPARQLTupleExprRenderer();
// aRenderer.mProjection = new ArrayList<ProjectionElemList>(mProjection);
// aRenderer.mDistinct = mDistinct;
// aRenderer.mReduced = mReduced;
// aRenderer.mExtensions = new HashMap<String, ValueExpr>(mExtensions);
// aRenderer.mOrdering = new ArrayList<OrderElem>(mOrdering);
// aRenderer.mLimit = mLimit;
// aRenderer.mOffset = mOffset;
aRenderer.mIndent = mIndent;
aRenderer.mContexts = new HashMap<TupleExpr, Var>(mContexts);
return aRenderer.render(theExpr);
}
示例4: computeVars
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Compute the variable names occurring in the service expression using tree
* traversal, since these are necessary for building the SPARQL query.
*
* @return the set of variable names in the given service expression
*/
protected Set<String> computeVars(TupleExpr serviceExpression) {
final Set<String> res = new HashSet<String>();
serviceExpression.visit(new AbstractQueryModelVisitor<RuntimeException>() {
@Override
public void meet(Var node)
throws RuntimeException {
// take only real vars, i.e. ignore blank nodes
if (!node.hasValue() && !node.isAnonymous())
res.add(node.getName());
}
// TODO maybe stop tree traversal in nested SERVICE?
// TODO special case handling for BIND
});
return res;
}
示例5: transformPattern
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
private Collection<FuzzyEntry<StatementPattern>> transformPattern(StatementPattern pattern)
{
Set<FuzzyEntry<StatementPattern>> transformedPatterns = new HashSet<FuzzyEntry<StatementPattern>>();
//queryTransformation.retrieveEquivalentURIs(pattern)
Var sVar = pattern.getSubjectVar();
Var pVar = pattern.getPredicateVar();
Var oVar = pattern.getObjectVar();
double patternProximity = 1.0;
for (FuzzyEntry<Var> sVar1 : transformVar(sVar)) {
for (FuzzyEntry<Var> pVar1 : transformVar(pVar)) {
for (FuzzyEntry<Var> oVar1 : transformVar(oVar)) {
StatementPattern p = new StatementPattern(sVar1.getElem(), pVar1.getElem(), oVar1.getElem());
if (!p.equals(pattern)) {
double prox = Math.min(Math.min(sVar1.getProximity(), pVar1.getProximity()), oVar1.getProximity());
transformedPatterns.add(new FuzzyEntry<StatementPattern>(p, prox));
}
}
}
}
return transformedPatterns;
}
示例6: transformVar
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
private Collection<FuzzyEntry<Var>> transformVar(Var v) {
Set<FuzzyEntry<Var>> vars = new HashSet<FuzzyEntry<Var>>();
Value val = v.getValue();
if (val != null && val instanceof IRI) {
Collection<EquivalentIRI> uris = getEquivalentURI(v);
for(EquivalentIRI uri : uris)
{
Var v1 = transformVar(v,uri);
vars.add(new FuzzyEntry<Var>(v1, uri.getProximity()));
}
}
else {
vars.add(new FuzzyEntry<Var>(v));
}
return vars;
}
示例7: enforceDataProps
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
protected Collection<Plan> enforceDataProps(Plan plan, RequestedDataProperties dataProps) {
if (!dataProps.isCoveredBy(plan.getProperties().getDataProperties()))
{
if (dataProps.ordering.isPresent()) {
org.eclipse.rdf4j.query.algebra.Order o = new org.eclipse.rdf4j.query.algebra.Order(plan);
Iterator<Ordering.OrderedVariable> vars = dataProps.ordering.get().getOrderedVariables();
while (vars.hasNext()) {
Ordering.OrderedVariable v = vars.next();
boolean asc = v.getOrder() == Order.ASCENDING;
// FIXME: if v.getOrder() == ANY then produce all possible orders (i.e. ASC and DESC)
o.addElement(new OrderElem(new Var(v.getVariable()),asc));
}
return Collections.singleton(asPlan(o));
}
}
return Collections.singleton(plan);
}
示例8: hasStatements
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
@Override
public boolean hasStatements(RepositoryConnection conn, Resource subj,
IRI pred, Value obj, Resource... contexts)
throws RepositoryException {
if (!useASKQueries) {
StatementPattern st = new StatementPattern(new Var("s", subj), new Var("p", pred), new Var("o", obj));
try {
return hasStatements(st, conn, EmptyBindingSet.getInstance());
} catch (Exception e) {
throw new RepositoryException(e);
}
}
return super.hasStatements(conn, subj, pred, obj, contexts);
}
示例9: toStatementPattern
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
public static StatementPattern toStatementPattern(Resource subj, IRI pred, Value obj) {
Var s = subj==null ? new Var("s") : new Var("const_s", subj);
Var p = pred==null ? new Var("p") : new Var("const_p", pred);
Var o = obj==null ? new Var("o") : new Var("const_o", obj);
// TODO context
return new StatementPattern(s, p, o);
}
示例10: appendVarId
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Clone the specified variable and attach bindings, moreover change name of variable
* by appending "_varId" to it.
*
* @param sb
* @param var
* @param varNames
* @param bindings
*
* @return
*/
protected static Var appendVarId(Var var, String varID, Set<String> varNames, BindingSet bindings) {
Var res = var.clone();
if (!var.hasValue()) {
if (bindings.hasBinding(var.getName())) {
res.setValue( bindings.getValue(var.getName()) );
} else {
String newName = var.getName() + "_" + varID;
varNames.add(newName);
res.setName(newName);
}
}
return res;
}
示例11: append
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
protected static void append(ValueExpr expr, StringBuilder sb) throws FilterConversionException {
if (expr instanceof Compare) {
append((Compare)expr, sb);
} else if (expr instanceof Var) {
append((Var)expr, sb);
} else if (expr instanceof ValueConstant) {
append((ValueConstant)expr, sb);
} else {
// TODO add more!
throw new FilterConversionException("Expression type not supported, fallback to sesame evaluation: " + expr.getClass().getCanonicalName());
}
}
示例12: toValue
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
protected static Value toValue(Var var, BindingSet bindings) {
if (var.hasValue())
return var.getValue();
if (bindings.hasBinding(var.getName()))
return bindings.getValue(var.getName());
return null;
}
示例13: Vertex
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Vertex constructor
* @param label Label of a vertex
*/
public Vertex(Var val, String label) {
this.var = val;
this.label = label;
inEdges = new HashSet<HyperEdge>();
outEdges = new HashSet<HyperEdge>();
}
示例14: collectVertex
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
private Vertex collectVertex(Var var, String label, Map<String, Vertex> v) {
Vertex resultVertex = v.get(label);
if (null == resultVertex) {
resultVertex = new Vertex(var, label);
v.put(label, resultVertex);
}
return resultVertex;
}
示例15: getVarValue
import org.eclipse.rdf4j.query.algebra.Var; //导入依赖的package包/类
/**
* Gets a value from a {@code Var} if it has a {@code Value}. If it does not then the method will attempt to get it
* from the bindings using the name of the Var
* @param var
* @param bindings
* @return the matching {@code Value} or {@code null} if var is {@code null}
*/
private static Value getVarValue(Var var, BindingSet bindings) {
if (var == null) {
return null;
} else if (var.hasValue()) {
return var.getValue();
} else {
return bindings.getValue(var.getName());
}
}