Java Code Examples for org.eclipse.rdf4j.query.algebra.Var#equals()

The following examples show how to use org.eclipse.rdf4j.query.algebra.Var#equals() . 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: TupleExprBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<StatementPattern> replaceSameTermVars(List<StatementPattern> statementPatterns,
		Set<SameTerm> sameTermConstraints) {
	if (sameTermConstraints != null) {
		for (SameTerm st : sameTermConstraints) {
			Var left = (Var) st.getLeftArg();
			Var right = (Var) st.getRightArg();
			for (StatementPattern sp : statementPatterns) {
				Var subj = sp.getSubjectVar();
				Var obj = sp.getObjectVar();

				if (subj.equals(left) || subj.equals(right)) {
					if (obj.equals(left) || obj.equals(right)) {
						sp.setObjectVar(subj);
					}
				}
			}
		}
	}
	return statementPatterns;
}
 
Example 2
Source File: FederationJoinOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(LeftJoin node) throws RepositoryException {
	super.meet(node);
	Var leftSubject = getLocalSubject(node.getLeftArg());
	Var rightSubject = getLocalSubject(node.getRightArg());
	// if local then left and right can be combined
	boolean local = leftSubject != null && leftSubject.equals(rightSubject);
	RepositoryConnection leftOwner = getSingleOwner(node.getLeftArg());
	RepositoryConnection rightOwner = getSingleOwner(node.getRightArg());
	addOwners(node, leftOwner, rightOwner, local);
}
 
Example 3
Source File: FederationJoinOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void local(Var subj) {
	if (isLocal && relative == null) {
		relative = subj;
	} else if (!subj.equals(relative)) {
		notLocal();
	}
}
 
Example 4
Source File: FederationJoinOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * If two basic graph patterns have the same subject and can be run on the same member, we can change the order.
 */
private LocalJoin findLocalJoin(Var subj, List<LocalJoin> vars) {
	LocalJoin result = null;
	if ((!vars.isEmpty()) && vars.get(vars.size() - 1).getVar() == subj) {
		result = vars.get(vars.size() - 1);
	} else {
		for (LocalJoin local : vars) {
			if (subj != null && subj.equals(local.getVar())) {
				result = local;
				break;
			}
		}
	}
	return result;
}
 
Example 5
Source File: CopyRule.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public void meet(final Var node) {
    final String oldName = node.getName();
    if (rule.varMap.containsKey(oldName)) {
        node.setName(rule.varMap.get(oldName).getName());
    }
    else {
        if (node.hasValue() || node.equals(SUBJ_VAR) || node.equals(PRED_VAR) || node.equals(OBJ_VAR) || node.equals(CON_VAR)) {
            return;
        }
        node.setName(UNDEFINED_VAR.getName());
    }
}
 
Example 6
Source File: SameTermFilterOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void meet(Var var) {
	if (var.equals(oldVar)) {
		var.replaceWith(newVar.clone());
	}
}
 
Example 7
Source File: StarQuery.java    From rya with Apache License 2.0 4 votes vote down vote up
public static boolean isValidStarQuery(final Collection<StatementPattern> nodes) {

        Set<String> bindings = null;
        boolean contextSet = false;
        Var context = null;

        if(nodes.size() < 2) {
            return false;
        }

        for(final StatementPattern sp: nodes) {

            final Var tempContext = sp.getContextVar();
            final Var predVar = sp.getPredicateVar();

            //does not support variable context
            if(tempContext != null && !tempContext.isConstant()) {
               return false;
            }
            if(!contextSet) {
                context = tempContext;
                contextSet = true;
            } else {

                if(context == null && tempContext != null) {
                    return false;
                } else if (context != null && !context.equals(tempContext)) {
                    return false;
                }
            }

            if(!predVar.isConstant()) {
                return false;
            }

            if(bindings == null ) {
                bindings = sp.getBindingNames();
                if(bindings.size() == 0) {
                    return false;
                }
            } else {
                bindings = Sets.intersection(bindings, sp.getBindingNames());
                if(bindings.size() == 0) {
                    return false;
                }
            }

        }


        return isBindingsetValid(bindings);
    }
 
Example 8
Source File: StatementMetadataNode.java    From rya with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies StatementPatterns define a reified pattern with associated
 * metadata properties.
 *
 * @param patterns
 *            - The patterns to check. (not null)
 * @throws IllegalStateException
 *             No Type or the wrong Type is specified by the patterns.
 */
public static boolean verifyHasCorrectTypePattern(final Collection<StatementPattern> patterns)
        throws IllegalStateException {
    requireNonNull(patterns);

    boolean subjFound = false;
    boolean objFound = false;
    boolean predFound = false;
    boolean statementFound = false;
    boolean valid = true;
    boolean contextSet = false;
    Var context = null;

    for (final StatementPattern pattern : patterns) {
        final RyaIRI predicate = new RyaIRI(pattern.getPredicateVar().getValue().toString());

        if (!contextSet) {
            context = pattern.getContextVar();
            contextSet = true;
        } else {
            if(context != null && !context.equals(pattern.getContextVar())) {
                return false;
            }
        }

        if (predicate.equals(TYPE_ID_URI)) {
            final Value objectValue = pattern.getObjectVar().getValue();
            if (objectValue != null) {
                final RyaIRI statementID = new RyaIRI(objectValue.stringValue());
                if (statementID.equals(STATEMENT_ID_URI)) {
                    statementFound = true;
                } else {
                    // contains more than one Statement containing TYPE_ID_URI
                    // as Predicate
                    // and STATEMENT_ID_URI as Object
                    valid = false;
                }
            } else {
                valid = false;
            }
        }

        if (predicate.equals(SUBJ_ID_URI)) {
            if (!subjFound) {
                subjFound = true;
            } else {
                // contains more than Subject SP
                valid = false;
            }

        }

        if (predicate.equals(PRED_ID_URI)) {
            if (!predFound) {
                predFound = true;
            } else {
                // contains more than one Predicate SP
                valid = false;
            }
        }

        if (predicate.equals(OBJ_ID_URI)) {
            if (!objFound) {
                objFound = true;
            } else {
                // contains more than one Object SP
                valid = false;
            }
        }
    }

    return valid && statementFound && subjFound && predFound && objFound;
}