Java Code Examples for org.eclipse.rdf4j.query.algebra.StatementPattern#getVarList()

The following examples show how to use org.eclipse.rdf4j.query.algebra.StatementPattern#getVarList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HalyardEvaluationStatistics.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@Override
protected double getCardinality(StatementPattern sp) {
    //always preffer HALYARD.SEARCH_TYPE object literals to move such statements higher in the joins tree
    Var objectVar = sp.getObjectVar();
    if (objectVar.hasValue() && (objectVar.getValue() instanceof Literal) && HALYARD.SEARCH_TYPE.equals(((Literal) objectVar.getValue()).getDatatype())) {
        return 0.0001;
    }
    Double card = spcalc == null ? null : spcalc.getCardinality(sp, boundVars);
    if (card == null) { //fallback to default cardinality calculation
        card = (hasValue(sp.getSubjectVar(), boundVars) ? 1.0 : 10.0) * (hasValue(sp.getPredicateVar(), boundVars) ? 1.0 : 10.0) * (hasValue(sp.getObjectVar(), boundVars) ? 1.0 : 10.0) * (hasValue(sp.getContextVar(), boundVars) ? 1.0 : 10.0);
    }
    for (Var v : sp.getVarList()) {
        //decrease cardinality for each priority variable present
        if (v != null && priorityVariables.contains(v.getName())) card /= 1000000.0;
    }
    return card;
}
 
Example 2
Source File: QueryStringUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * returns true iff there is at least one free variable, i.e. there is no binding for any variable
 *
 * @param stmt
 * @param bindings
 * @return whether free vars are available
 */
public static boolean hasFreeVars(StatementPattern stmt, BindingSet bindings) {
	for (Var var : stmt.getVarList()) {
		if (!var.hasValue() && !bindings.hasBinding(var.getName())) {
			return true; // there is at least one free var
		}
	}
	return false;
}
 
Example 3
Source File: QueryAlgebraUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * returns true iff there is at least one free variable, i.e. there is no binding for any variable
 *
 * @param stmt
 * @param bindings
 * @return whether there is at least one free variable
 */
public static boolean hasFreeVars(StatementPattern stmt, BindingSet bindings) {
	for (Var var : stmt.getVarList()) {
		if (!var.hasValue() && !bindings.hasBinding(var.getName())) {
			return true; // there is at least one free var
		}
	}
	return false;
}
 
Example 4
Source File: EntityTupleSet.java    From rya with Apache License 2.0 5 votes vote down vote up
private int numberOfSpVars(StatementPattern sp) {
    List<Var> varList = sp.getVarList();
    int varCount = 0;

    for(int i = 0; i < 3; i++) {
       if(!varList.get(i).isConstant()) {
           varCount++;
       }
    }

    return varCount;
}
 
Example 5
Source File: StatementMetadataNode.java    From rya with Apache License 2.0 5 votes vote down vote up
private Set<String> getVariableNames() {
    final Set<String> vars = new HashSet<>();
    for (final StatementPattern pattern : patterns) {
        for (final Var var : pattern.getVarList()) {
            if (var.getValue() == null) {
                vars.add(var.getName());
            }
        }
    }
    return vars;
}
 
Example 6
Source File: CardinalityCalcUtil.java    From rya with Apache License 2.0 5 votes vote down vote up
public static String getRow(StatementPattern sp, boolean joinTable) {

    String row = "";
    String values = "";
    List<Var> varList = sp.getVarList();
    List<String> constList = CardinalityCalcUtil.getConstantPos(sp);
    int i;

    for (String s : constList) {

      i = CardinalityCalcUtil.triplePlaceToInt(s);

      if (row.equals("subject") && s.equals("object") && joinTable) {
        row = s + row;
        if (values.length() == 0) {
          values = values + removeQuotes(varList.get(i).getValue().toString());
        } else {
          values = removeQuotes(varList.get(i).getValue().toString()) + DELIM + values;
        }
      } else {
        row = row + s;
        if (values.length() == 0) {
          values = values + removeQuotes(varList.get(i).getValue().toString());
        } else {
          values = values + DELIM + removeQuotes(varList.get(i).getValue().toString());
        }
      }

    }

    return (row + DELIM + values);

  }
 
Example 7
Source File: CardinalityCalcUtil.java    From rya with Apache License 2.0 5 votes vote down vote up
private static List<String> getJoinType(StatementPattern sp1, StatementPattern sp2) {

    List<String> joinList = new ArrayList<String>();
    List<Var> spList1 = sp1.getVarList();
    List<Var> spList2 = sp2.getVarList();

    List<String> pos1 = CardinalityCalcUtil.getVariablePos(sp1);
    List<String> pos2 = CardinalityCalcUtil.getVariablePos(sp2);

    int i, j;

    for (String s : pos1) {
      for (String t : pos2) {
        i = CardinalityCalcUtil.triplePlaceToInt(s);
        j = CardinalityCalcUtil.triplePlaceToInt(t);

        if (spList1.get(i).getName().equals(spList2.get(j).getName())) {
          joinList.add(s);
          joinList.add(t);

        }

      }
    }
    if (joinList.size() == 4) {
      return orderJoinType(joinList);
    }

    return joinList;

  }
 
Example 8
Source File: EvaluationStatistics.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected double getCardinality(StatementPattern pattern) {
	Set<Var> vars = new HashSet<>(pattern.getVarList());
	int constantVarCount = countConstantVars(vars);
	double unboundVarFactor = (double) (vars.size() - constantVarCount) / vars.size();
	return Math.pow(1000.0, unboundVarFactor);
}
 
Example 9
Source File: QueryVariableNormalizer.java    From rya with Apache License 2.0 4 votes vote down vote up
private static boolean genConstantCompare(StatementPattern queryNode, StatementPattern indexNode) {
    
    

    ArrayList<Var> vars1 = (ArrayList<Var>) queryNode.getVarList();
    ArrayList<Var> vars2 = (ArrayList<Var>) indexNode.getVarList();

    
    for (int i = 0; i < vars1.size(); i++) {

        if (vars1.get(i).isConstant() && vars2.get(i).isConstant()) {

            if (!vars1.get(i).equals(vars2.get(i))) {
                return false;

            }

        } else if(!vars1.get(i).isConstant() && vars2.get(i).isConstant() ) {
                return false;
        }

    }

    return true;

}
 
Example 10
Source File: QueryStringUtil.java    From CostFed with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * returns true iff there is at least one free variable, i.e. there is no binding
 * for any variable
 * 
 * @param stmt
 * @param bindings
 * @return
 */
public static boolean hasFreeVars(StatementPattern stmt, BindingSet bindings) {
	for (Var var : stmt.getVarList()) {
		if(!var.hasValue() && !bindings.hasBinding(var.getName()))
			return true;	// there is at least one free var				
	}
	return false;
}
 
Example 11
Source File: QueryAlgebraUtil.java    From CostFed with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * returns true iff there is at least one free variable, i.e. there is no binding
 * for any variable
 * 
 * @param stmt
 * @param bindings
 * @return
 */
public static boolean hasFreeVars(StatementPattern stmt, BindingSet bindings) {
	for (Var var : stmt.getVarList()) {
		if(!var.hasValue() && !bindings.hasBinding(var.getName()))
			return true;	// there is at least one free var				
	}
	return false;
}
 
Example 12
Source File: CardinalityCalcUtil.java    From rya with Apache License 2.0 3 votes vote down vote up
private static List<String> getVariablePos(StatementPattern sp) {

    List<String> posList = new ArrayList<String>();
    List<Var> varList = sp.getVarList();

    for (int i = 0; i < 3; i++) {
      if (!varList.get(i).isConstant()) {
        posList.add(intToTriplePlace(i));

      }
    }

    return posList;

  }
 
Example 13
Source File: CardinalityCalcUtil.java    From rya with Apache License 2.0 3 votes vote down vote up
private static List<String> getConstantPos(StatementPattern sp) {

    List<String> posList = new ArrayList<String>();
    List<Var> varList = sp.getVarList();

    for (int i = 0; i < 3; i++) {
      if (varList.get(i).isConstant()) {
        posList.add(intToTriplePlace(i));

      }
    }

    return posList;

  }