Search in sources :

Example 1 with ElementMinus

use of org.apache.jena.sparql.syntax.ElementMinus in project jena by apache.

the class WhereClauseTest method testAddMinus.

@ContractTest
public void testAddMinus() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "uri").addVar("?x").addWhere("<one>", "<two>", "three");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addMinus(sb);
    Query query = builder.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementMinus minus = new ElementMinus(epb);
    epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    WhereValidator visitor = new WhereValidator(minus);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementMinus(org.apache.jena.sparql.syntax.ElementMinus) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 2 with ElementMinus

use of org.apache.jena.sparql.syntax.ElementMinus in project jena by apache.

the class WhereQuadHolder method addMinus.

/**
 * Add a minus operation to the where clause. The prefixes will be updated with
 * the prefixes from the abstract query builder.
 *
 * @param qb the abstract builder that defines the data to subtract.
 */
public void addMinus(AbstractQueryBuilder<?> qb) {
    prefixHandler.addPrefixes(qb.getPrologHandler().getPrefixes());
    ElementGroup clause = getClause();
    ElementMinus minus = new ElementMinus(qb.getWhereHandler().getClause());
    clause.addElement(minus);
}
Also used : ElementMinus(org.apache.jena.sparql.syntax.ElementMinus) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 3 with ElementMinus

use of org.apache.jena.sparql.syntax.ElementMinus in project jena by apache.

the class WhereHandlerTest method testAddMinus.

@Test
public void testAddMinus() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", "three");
    handler.addMinus(sb);
    handler.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementMinus minus = new ElementMinus(epb);
    epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    WhereValidator visitor = new WhereValidator(minus);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementMinus(org.apache.jena.sparql.syntax.ElementMinus) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 4 with ElementMinus

use of org.apache.jena.sparql.syntax.ElementMinus in project jena by apache.

the class WhereHandler method addMinus.

/**
 * Add a minus operation to the where clause. The prolog will be updated with
 * the prefixes from the abstract query builder.
 *
 * @param qb the abstract builder that defines the data to subtract.
 */
public void addMinus(AbstractQueryBuilder<?> qb) {
    PrologHandler ph = new PrologHandler(query);
    ph.addPrefixes(qb.getPrologHandler().getPrefixes());
    ElementGroup clause = getClause();
    ElementMinus minus = new ElementMinus(qb.getWhereHandler().getClause());
    clause.addElement(minus);
}
Also used : ElementMinus(org.apache.jena.sparql.syntax.ElementMinus) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 5 with ElementMinus

use of org.apache.jena.sparql.syntax.ElementMinus in project jena by apache.

the class ElementRewriter method visit.

@Override
public void visit(ElementMinus el) {
    el.getMinusElement().visit(this);
    push(new ElementMinus(getResult()));
}
Also used : ElementMinus(org.apache.jena.sparql.syntax.ElementMinus)

Aggregations

ElementMinus (org.apache.jena.sparql.syntax.ElementMinus)5 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)2 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)2 Triple (org.apache.jena.graph.Triple)2 TriplePath (org.apache.jena.sparql.core.TriplePath)2 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)2 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)2 FrontsTriple (org.apache.jena.graph.FrontsTriple)1 Query (org.apache.jena.query.Query)1 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)1 Test (org.junit.Test)1 ContractTest (org.xenei.junit.contract.ContractTest)1