Package org.openrdf.query.algebra

Examples of org.openrdf.query.algebra.ProjectionElemList


    // and these solutions are projected to subject-predicate-object bindings.
    // Finally, the spo-bindings are again filtered for duplicates.
    if (distinct) {
      // Create projection that removes all bindings that are not used in the
      // constructor
      ProjectionElemList projElemList = new ProjectionElemList();

      for (Var var : constructVars) {
        // Ignore anonymous and constant vars, these will be handled after
        // the distinct
        if (!var.isAnonymous() && !var.hasValue()) {
          projElemList.addElement(new ProjectionElem(var.getName()));
        }
      }

      result = new Projection(result, projElemList);

      // Filter the duplicates from these projected bindings
      result = new Distinct(result);
    }

    // Create BNodeGenerator's for all anonymous variables
    Map<Var, ExtensionElem> extElemMap = new HashMap<Var, ExtensionElem>();

    for (Var var : constructVars) {
      if (var.isAnonymous() && !extElemMap.containsKey(var)) {
        ValueExpr valueExpr = null;

        if (var.hasValue()) {
          valueExpr = new ValueConstant(var.getValue());
        }
        else if (explicit) {
          // only generate bnodes in case of an explicit constructor
          valueExpr = new BNodeGenerator();
        }

        if (valueExpr != null) {
          extElemMap.put(var, new ExtensionElem(valueExpr, var.getName()));
        }
      }
    }

    if (!extElemMap.isEmpty()) {
      result = new Extension(result, extElemMap.values());
    }

    // Create a Projection for each StatementPattern in the constructor
    List<ProjectionElemList> projections = new ArrayList<ProjectionElemList>();

    for (StatementPattern sp : statementPatterns) {
      ProjectionElemList projElemList = new ProjectionElemList();

      projElemList.addElement(new ProjectionElem(sp.getSubjectVar().getName(), "subject"));
      projElemList.addElement(new ProjectionElem(sp.getPredicateVar().getName(), "predicate"));
      projElemList.addElement(new ProjectionElem(sp.getObjectVar().getName(), "object"));

      projections.add(projElemList);
    }

    if (projections.size() == 1) {
View Full Code Here


    throws VisitorException
  {
    TupleExpr result = (TupleExpr)data;

    Extension extension = new Extension();
    ProjectionElemList projElemList = new ProjectionElemList();

    for (ASTProjectionElem projElemNode : node.getProjectionElemList()) {
      ValueExpr valueExpr = (ValueExpr)projElemNode.getValueExpr().jjtAccept(this, null);

      String alias = projElemNode.getAlias();
      if (alias != null) {
        // aliased projection element
        extension.addElement(new ExtensionElem(valueExpr, alias));
        projElemList.addElement(new ProjectionElem(alias));
      }
      else if (valueExpr instanceof Var) {
        // unaliased variable
        Var projVar = (Var)valueExpr;
        projElemList.addElement(new ProjectionElem(projVar.getName()));
      }
      else {
        throw new IllegalStateException("required alias for non-Var projection elements not found");
      }
    }
View Full Code Here

  public TupleExpr visit(ASTSelect node, Object data)
    throws VisitorException
  {
    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

    // Create a Projection for each StatementPattern in the constructor
    List<ProjectionElemList> projList = new ArrayList<ProjectionElemList>();

    for (StatementPattern sp : statementPatterns) {
      ProjectionElemList projElemList = new ProjectionElemList();

      projElemList.addElement(new ProjectionElem(sp.getSubjectVar().getName(), "subject"));
      projElemList.addElement(new ProjectionElem(sp.getPredicateVar().getName(), "predicate"));
      projElemList.addElement(new ProjectionElem(sp.getObjectVar().getName(), "object"));

      projList.add(projElemList);
    }

    if (projList.size() == 1) {
View Full Code Here

    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

      }

      idx = nextProjectionIdx = 0;
    }

    ProjectionElemList nextProjection = projections.get(idx);
    nextProjectionIdx++;

    return ProjectionCursor.project(nextProjection, currentBindings, parentBindings);
  }
View Full Code Here

    super.meet(node);
    if (node.getArg() instanceof SelectQuery) {
      SelectQuery query = (SelectQuery)node.getArg();
      Map<String, String> bindingVars = new HashMap<String, String>();
      List<SelectProjection> selection = new ArrayList<SelectProjection>();
      ProjectionElemList list = node.getProjectionElemList();
      for (ProjectionElem e : list.getElements()) {
        String source = e.getSourceName();
        String target = e.getTargetName();
        bindingVars.put(target, source);
        SelectProjection s = query.getSelectProjection(source);
        if (s != null) {
View Full Code Here

              try {
                  Group2 group = new Group2(_builder.makeFilterTupleExpr());
                  group.addGroupElement(new GroupElem(_countVar.getName(), new Count(_itemVar)));
                  group.addGroupBindingName(_valueVar.getName());
                 
                  ProjectionElemList projectionElements = new ProjectionElemList();
                  projectionElements.addElement(new ProjectionElem(_valueVar.getName()));
                  projectionElements.addElement(new ProjectionElem(_countVar.getName()));
                 
                  Projection projection = new Projection(group, projectionElements);
                  Order order = "value".equals(_sortMode) ?
                      new Order(projection, new OrderElem(_valueVar, "forward".equals(_sortDirection))) :
                      new Order(projection, new OrderElem(_countVar, !"forward".equals(_sortDirection)));
View Full Code Here

                tupleExprs :
                new Filter(tupleExprs, conditions);
    }
   
    public Projection makeProjection(Var var) {
        return makeProjection(new ProjectionElemList(new ProjectionElem(var.getName())));
    }
View Full Code Here

            projectionElements
        );
    }
   
    public TupleQuery makeTupleQuery(Var var, SailRepositoryConnection connection) {
        return makeTupleQuery(new ProjectionElemList(new ProjectionElem(var.getName())), connection);
    }
View Full Code Here

TOP

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

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.