Package org.openrdf.query.algebra

Examples of org.openrdf.query.algebra.Var


    throws VisitorException
  {
    List<Var> nodeVars = new ArrayList<Var>();

    for (ASTNodeElem nodeElem : node.getNodeElemList()) {
      Var nodeVar = (Var)nodeElem.jjtAccept(this, null);
      nodeVars.add(nodeVar);
    }

    // Create any implicit unequalities
    for (int i = 0; i < nodeVars.size() - 1; i++) {
      Var var1 = nodeVars.get(i);

      for (int j = i + 1; j < nodeVars.size(); j++) {
        Var var2 = nodeVars.get(j);

        // At least one of the variables should be non-constant
        // for the unequality to make any sense:
        if (!var1.hasValue() || !var2.hasValue()) {
          graphPattern.addConstraint(new Not(new SameTerm(var1, var2)));
        }
      }
    }
View Full Code Here


  public Var visit(ASTReifiedStat node, Object data)
    throws VisitorException
  {
    assert node.getID() != null : "ID variable not set";

    Var subjVar = (Var)node.getSubject().jjtAccept(this, null);
    Var predVar = (Var)node.getPredicate().jjtAccept(this, null);
    Var objVar = (Var)node.getObject().jjtAccept(this, null);
    Var idVar = (Var)node.getID().jjtAccept(this, null);

    Var contextVar = graphPattern.getContextVar();
    StatementPattern.Scope spScope = graphPattern.getStatementPatternScope();

    Var rdfType = new Var("_rdfType", RDF.TYPE);
    Var rdfStatement = new Var("_rdfStatement", RDF.STATEMENT);
    Var rdfSubject = new Var("_rdfSubject", RDF.SUBJECT);
    Var rdfPredicate = new Var("_rdfPredicate", RDF.PREDICATE);
    Var rdfObject = new Var("_rdfObject", RDF.OBJECT);

    graphPattern.addRequiredTE(new StatementPattern(spScope, idVar, rdfType, rdfStatement, contextVar));
    graphPattern.addRequiredTE(new StatementPattern(spScope, idVar, rdfSubject, subjVar, contextVar));
    graphPattern.addRequiredTE(new StatementPattern(spScope, idVar, rdfPredicate, predVar, contextVar));
    graphPattern.addRequiredTE(new StatementPattern(spScope, idVar, rdfObject, objVar, contextVar));
View Full Code Here

  @Override
  public Var visit(ASTVar node, Object data)
    throws VisitorException
  {
    Var var = new Var(node.getName());
    var.setAnonymous(node.isAnonymous());
    return var;
  }
View Full Code Here

  }

  public Cursor<BindingSet> evaluate(StatementPattern sp, BindingSet bindings)
    throws StoreException
  {
    final Var subjVar = sp.getSubjectVar();
    final Var predVar = sp.getPredicateVar();
    final Var objVar = sp.getObjectVar();
    final Var conVar = sp.getContextVar();

    Value subjValue = getVarValue(subjVar, bindings);
    Value predValue = getVarValue(predVar, bindings);
    Value objValue = getVarValue(objVar, bindings);
    Value contextValue = getVarValue(conVar, bindings);
View Full Code Here

      // TODO: skip this step if old variable name is not used
      // Replace SameTerm-filter with an Extension, the old variable name
      // might still be relevant to nodes higher in the tree
      Extension extension = new Extension(filter.getArg());
      extension.addElement(new ExtensionElem(new Var(newVar.getName()), oldVar.getName()));
      filter.replaceWith(extension);
    }
View Full Code Here

      throw new IllegalArgumentException("valueExpr is a: " + valueExpr.getClass());
    }
  }

  private Var createConstVar(Value value) {
    Var var = createAnonVar("-const-" + constantVarID++);
    var.setValue(value);
    return var;
  }
View Full Code Here

    var.setValue(value);
    return var;
  }

  private Var createAnonVar(String varName) {
    Var var = new Var(varName);
    var.setAnonymous(true);
    return var;
  }
View Full Code Here

    TupleExpr result = (TupleExpr)data;

    ProjectionElemList projElemList = new ProjectionElemList();

    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      Var projVar = (Var)node.jjtGetChild(i).jjtAccept(this, null);
      projElemList.addElement(new ProjectionElem(projVar.getName()));
    }

    result = new Projection(result, projElemList);

    if (node.isReduced()) {
View Full Code Here

  {
    TupleExpr result = (TupleExpr)data;

    // Create a graph query that produces the statements that have the
    // requests resources as subject or object
    Var subjVar = createAnonVar("-descr-subj");
    Var predVar = createAnonVar("-descr-pred");
    Var objVar = createAnonVar("-descr-obj");
    StatementPattern sp = new StatementPattern(subjVar, predVar, objVar);

    if (result == null) {
      result = sp;
    }
    else {
      result = new Join(result, sp);
    }

    List<SameTerm> sameTerms = new ArrayList<SameTerm>(2 * node.jjtGetNumChildren());

    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      ValueExpr resource = (ValueExpr)node.jjtGetChild(i).jjtAccept(this, null);

      sameTerms.add(new SameTerm(subjVar.clone(), resource));
      sameTerms.add(new SameTerm(objVar.clone(), resource));
    }

    ValueExpr constraint = new Or(sameTerms);

    result = new Filter(result, constraint);

    ProjectionElemList projElemList = new ProjectionElemList();
    projElemList.addElement(new ProjectionElem(subjVar.getName(), "subject"));
    projElemList.addElement(new ProjectionElem(predVar.getName(), "predicate"));
    projElemList.addElement(new ProjectionElem(objVar.getName(), "object"));
    result = new Projection(result, projElemList);

    return new Reduced(result);
  }
View Full Code Here

  @Override
  public Object visit(ASTGraphGraphPattern node, Object data)
    throws VisitorException
  {
    Var oldContext = graphPattern.getContextVar();
    Scope oldScope = graphPattern.getStatementPatternScope();

    ValueExpr newContext = (ValueExpr)node.jjtGetChild(0).jjtAccept(this, null);

    graphPattern.setContextVar(valueExpr2Var(newContext));
View Full Code Here

TOP

Related Classes of org.openrdf.query.algebra.Var

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.