Пример #1
0
  public void setGraphRestriction(BinaryUnion<Variable, IRI> graphRestriction) {
    // if (this.graphRestriction == null)
    {
      if (graphRestriction != null
          && graphRestriction.isFirstType()
          && gatherVariables().contains(graphRestriction.getFirst())
          && !getProjectedVariables().contains(graphRestriction.getFirst())) {
        // graph restriction variable already used in the local graph pattern
        // and is not visible outside
        // we need to
        // 1) use a new variable v (not used in this pattern or its ancestors)  for the graph
        // restriction
        // 2) project v
        // 3) set the graph restriction to v
        // 4) add in this subselect pattern a filter ?v = ?graphRestriction
        Set<Variable> vars = HashSetFactory.make();
        Pattern top = getTopAncestor();
        if (top != null) {
          vars.addAll(Planner.gatherInScopeVariables(top));
          if (top.getOptionalPatterns() != null) {
            for (Pattern op : top.getOptionalPatterns()) {
              vars.addAll(Planner.gatherInScopeVariables(op));
            }
          }
        }
        vars.addAll(gatherVariables());
        String prefix = "graphRestrictionGeneratedVar_";
        int id = OCUtils.nextAvailableSuffixVariable(OCUtils.getVariables(vars), prefix);
        Variable v = new Variable(prefix + id);
        this.graphRestriction = new BinaryUnion<Variable, IRI>();
        this.graphRestriction.setFirst(v);

        if (selectClause.getProjectedVariables() == null
            || selectClause.getProjectedVariables().isEmpty()) {
          for (ProjectedVariable pv : gatherRealProjectedVariables()) {
            selectClause.addProjectedVariable(pv);
          }
        }
        selectClause.addProjectedVariable(new ProjectedVariable(v.getName()));
        // getParent().addFilter(new RelationalExpression(new
        // VariableExpression(graphRestriction.getFirst().getName()),
        //		 new VariableExpression(v.getName()), ERelationalOp.EQUAL));

      } else {
        this.graphRestriction = graphRestriction;
      }
    }
  }
Пример #2
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(selectClause.toString());
   sb.append("\n");
   if (graphPattern != null) sb.append("WHERE " + graphPattern.toString() + "\n");
   if (solutionModifier != null) sb.append(solutionModifier.toString());
   return sb.toString();
 }
Пример #3
0
 public List<ProjectedVariable> gatherRealProjectedVariables() {
   List<ProjectedVariable> pvList = selectClause.getProjectedVariables();
   if (pvList != null && pvList.size() > 0) {
     return pvList;
   } else {
     Set<Variable> vars = gatherProjectedVariables();
     pvList = new LinkedList<ProjectedVariable>();
     for (Variable var : vars) {
       pvList.add(new ProjectedVariable(var.getName()));
     }
     return pvList;
   }
 }
Пример #4
0
 public Set<Variable> gatherIRIBoundProjectedVariables() {
   Set<Variable> allVars = new LinkedHashSet<Variable>();
   Set<Variable> IRIBoundVars = this.gatherIRIBoundVariables();
   List<ProjectedVariable> pvList = selectClause.getProjectedVariables();
   if (pvList != null && pvList.size() > 0) {
     for (ProjectedVariable pv : pvList) {
       if (pv.getExpression() == null && IRIBoundVars.contains(pv.getVariable()))
         allVars.add(pv.getVariable());
     }
     return allVars;
   } else {
     return graphPattern.gatherIRIBoundVariables();
   }
 }
Пример #5
0
 public Set<Variable> gatherProjectedVariables() {
   Set<Variable> allVars = new LinkedHashSet<Variable>();
   List<ProjectedVariable> pvList = selectClause.getProjectedVariables();
   if (pvList != null && pvList.size() > 0) {
     for (ProjectedVariable pv : pvList) {
       allVars.add(pv.getVariable());
     }
     return allVars;
   } else {
     allVars.addAll(Planner.gatherInScopeVariables(graphPattern));
     if (graphPattern.getOptionalPatterns() != null) {
       for (Pattern op : graphPattern.getOptionalPatterns()) {
         allVars.addAll(Planner.gatherInScopeVariables(op));
       }
     }
     return allVars;
   }
 }