Java Code Examples for org.openrdf.query.algebra.StatementPattern#clone()

The following examples show how to use org.openrdf.query.algebra.StatementPattern#clone() . 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: SubClassOf.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Transform a statement pattern according to OWL-2 subclass axiom.
 *
 * @param node the node to transform
 * @return list of nodes to visit next
 */
@Override
public List<QueryModelNode> apply(StatementPattern node) {
	List<QueryModelNode> next = newNextList();
	StatementPattern left = node.clone();
	// replace the object with the subclass
	StatementPattern right
			= new StatementPattern(
					node.getSubjectVar(),
					node.getPredicateVar(),
					new ConstVar(vf.createURI(ce1)),
					node.getContextVar());
	node.replaceWith(
			new Union(left, right));
	next.add(left);
	next.add(right);
	return next;
}
 
Example 2
Source File: SubPropertyOf.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Transform a statement pattern according to OWL-2 subproperty axiom.
 *
 * @param node the node to transform
 * @return list of nodes to visit next
 */
@Override
public List<QueryModelNode> apply(StatementPattern node) {
	List<QueryModelNode> next = newNextList();
	StatementPattern left = node.clone();
	// replace the predicate with the subproperty
	StatementPattern right
			= new StatementPattern(
					node.getSubjectVar(),
					new ConstVar(vf.createURI(op1)),
					node.getObjectVar(),
					node.getContextVar());
	node.replaceWith(
			new Union(left, right));
	next.add(left);
	next.add(right);
	return next;
}
 
Example 3
Source File: InverseObjectProperties.java    From neo4j-sparql-extension with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Transform a statement pattern according to OWL-2 inverse properties
 * axiom.
 *
 * @param node the node to transform
 * @return list of nodes to visit next
 */
@Override
public List<QueryModelNode> apply(StatementPattern node) {
	List<QueryModelNode> next = newNextList();
	Var s = node.getSubjectVar();
	Var p = node.getPredicateVar();
	Var o = node.getObjectVar();
	Var c = node.getContextVar();
	URI uri = (URI) p.getValue();
	String op = uri.stringValue();
	Var p2;
	// check if need to replace with op1 or op2
	if (op.equals(op1)) {
		p2 = new ConstVar(vf.createURI(op2));
	} else {
		p2 = new ConstVar(vf.createURI(op1));
	}
	StatementPattern left = node.clone();
	// switch subject and object and replace predicate
	StatementPattern right = new StatementPattern(o, p2, s, c);
	node.replaceWith(new Union(left, right));
	next.add(left);
	next.add(right);
	return next;
}
 
Example 4
Source File: PredicateVariable.java    From neo4j-sparql-extension with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Transform a statement pattern to infer triples for a predicate variable.
 * 
 * @param node the node to transform
 * @return list of nodes to visit next
 */
@Override
public List<QueryModelNode> apply(StatementPattern node) {
	List<QueryModelNode> next = newNextList();
	StatementPattern left = node.clone();
	next.add(left);
	TupleExpr right = assignPredicates(predicates, node.clone(), next);
	node.replaceWith(new Union(left, right));
	return next;
}
 
Example 5
Source File: ObjectPropertyChain.java    From neo4j-sparql-extension with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Transform a statement pattern according to OWL-2 property chain
 * axiom.
 * 
 * @param node the node to transform
 * @return list of nodes to visit next
 */
@Override
public List<QueryModelNode> apply(StatementPattern node) {
	List<QueryModelNode> next = newNextList();
	Var s = node.getSubjectVar();
	Var o = node.getObjectVar();
	Var c = node.getContextVar();
	TupleExpr left  = node.clone();
	TupleExpr right = getChain(s, o, c);
	node.replaceWith(new Union(left, right));
	next.add(left);
	next.add(right);
	return next;
}
 
Example 6
Source File: StatementUnifier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Computes the Most General Unifier (MGU) for two n-ary atoms.
 * 
 * @param first
 * @param second
 * @return the substitution corresponding to this unification.
 */
public static Substitution getMGU(StatementPattern st1, StatementPattern st2) {

	Var term1;
	Var term2;

	Substitution mgu = new SubstitutionImpl();

	for (int i = 0; i < 3; i++) {
		term1 = st1.getVarList().get(i);
		term2 = st2.getVarList().get(i);
		Substitution s = getUnifier(term1, term2);
		if (s == null)
			return null;
		if (s instanceof NeutralSubstitution)
			continue;

		SingletonSubstituion ss = (SingletonSubstituion) s;
		mgu.compose(ss.original, ss.substition);

		st1 = st1.clone();
		st2 = st2.clone();

		applySubstitution(mgu, st1);
		applySubstitution(mgu, st2);
	}
	if (mgu.isEmpty())
		return new NeutralSubstitution();
	
	return mgu;

}