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

The following examples show how to use org.openrdf.query.algebra.StatementPattern#getSubjectVar() . 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: 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 5
Source File: CumulusQueryOptimizer.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
@Override
public void meet(final StatementPattern statement) {

	if (statement instanceof RangeStatementPattern) {

		if (statement.getObjectVar().equals(_var)) {

			boolean equals_lower = ((RangeStatementPattern) statement).getLowerBoundEquals();
			boolean equals_upper = ((RangeStatementPattern) statement).getUpperBoundEquals();

			Literal lower = ((RangeStatementPattern) statement).getLowerBound();
			Literal upper = ((RangeStatementPattern) statement).getUpperBound();
			Literal equal = ((RangeStatementPattern) statement).getEquals();

			if (_comp.equals(CompareOp.GE) || _comp.equals(CompareOp.GT)) {
				if (lower == null) {
					lower = _bound;
					equals_lower = _comp.equals(CompareOp.GE);
				} else {
					double currentLower = Double.parseDouble(lower.getLabel());
					double newLower = Double.parseDouble(_bound.getLabel());
					if (newLower > currentLower) {
						lower = _bound;
						equals_lower = _comp.equals(CompareOp.GE);
					}
				}
			} else if (_comp.equals(CompareOp.LE) || _comp.equals(CompareOp.LT)) {
				if (upper == null) {
					upper = _bound;
					equals_upper = _comp.equals(CompareOp.LE);
				} else {
					double currentUpper = Double.parseDouble(upper.getLabel());
					double newUpper = Double.parseDouble(_bound.getLabel());
					if (newUpper < currentUpper) {
						upper = _bound;
						equals_upper = _comp.equals(CompareOp.LE);
					}
				}
			} else if (_comp.equals(CompareOp.EQ)) {
				equal = _bound;
			}

			((RangeStatementPattern) statement).setLowerBound(lower);
			((RangeStatementPattern) statement).setUpperBound(upper);

			((RangeStatementPattern) statement).setUpperBoundEquals(equals_upper);
			((RangeStatementPattern) statement).setLowerBoundEquals(equals_lower);

			((RangeStatementPattern) statement).setEquals(equal);
		}
	} else {

		if (statement.getObjectVar().equals(_var)) {

			boolean equals_lower = false, equals_upper = false;
			boolean replace = false;

			Literal upper = null, lower = null, equals = null;

			if (_comp.equals(CompareOp.GE) || _comp.equals(CompareOp.GT)) {
				lower = _bound;
				equals_lower = _comp.equals(CompareOp.GE);
				replace = true;
			} else if (_comp.equals(CompareOp.EQ)) {
				equals = _bound;
				replace = true;
			} else if (_comp.equals(CompareOp.LE) || _comp.equals(CompareOp.LT)) {
				upper = _bound;
				equals_upper = _comp.equals(CompareOp.LE);
				replace = true;
			}

			if (replace) {
				RangeStatementPattern newP = new RangeStatementPattern(statement.getSubjectVar(), statement.getPredicateVar(),
						statement.getObjectVar(), lower, equals_lower, upper, equals_upper, equals);
				statement.replaceWith(newP);
			}
		}
	}
}