Search in sources :

Example 1 with SingletonSet

use of org.openrdf.query.algebra.SingletonSet in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testConcreteSP.

@Test
public void testConcreteSP() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"), new ExtensionElem(new ValueConstant(RDF.TYPE), "y"), new ExtensionElem(new ValueConstant(OWL.CLASS), "z"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(FOAF.PERSON), p(RDF.TYPE), o(OWL.CLASS)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 2 with SingletonSet

use of org.openrdf.query.algebra.SingletonSet in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testMissingVariables.

@Test
public void testMissingVariables() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"), new ExtensionElem(new ValueConstant(RDF.TYPE), "y"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "s"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(RDF.TYPE), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 3 with SingletonSet

use of org.openrdf.query.algebra.SingletonSet in project incubator-rya by apache.

the class FilterSerializer method serialize.

/**
 * Converts a {@link Filter} to a SPARQL query containing only the SPARQL representation
 * of the Filter along with a Select clause that return all variables.  The argument of the
 * Filter is replaced by a {@link SingletonSet} so that the body of the SPARQL query consists of only a
 * single Filter clause.
 * @param filter - Filter to be serialized
 * @return - SPARQL String containing a single Filter clause that represents the serialized Filter
 * @throws FilterParseException
 */
public static String serialize(Filter filter) throws FilterParseException {
    Filter clone = filter.clone();
    clone.setArg(new SingletonSet());
    try {
        return removeAngularBracketsFromNonUriFunctions(renderer.render(new ParsedTupleQuery(clone)));
    } catch (Exception e) {
        throw new FilterParseException("Unable to parse Filter.", e);
    }
}
Also used : SingletonSet(org.openrdf.query.algebra.SingletonSet) Filter(org.openrdf.query.algebra.Filter) ParsedTupleQuery(org.openrdf.query.parser.ParsedTupleQuery)

Example 4 with SingletonSet

use of org.openrdf.query.algebra.SingletonSet in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testBNode.

@Test
public void testBNode() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new Var("x"), "x"), new ExtensionElem(new BNodeGenerator(), "z"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), anon(o(null))));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) BNodeGenerator(org.openrdf.query.algebra.BNodeGenerator) SingletonSet(org.openrdf.query.algebra.SingletonSet) Var(org.openrdf.query.algebra.Var) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 5 with SingletonSet

use of org.openrdf.query.algebra.SingletonSet in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testGenericSP.

@Test
public void testGenericSP() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new Var("z"), "z"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) Var(org.openrdf.query.algebra.Var) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Aggregations

SingletonSet (org.openrdf.query.algebra.SingletonSet)6 Test (org.junit.Test)5 Extension (org.openrdf.query.algebra.Extension)5 ExtensionElem (org.openrdf.query.algebra.ExtensionElem)5 MultiProjection (org.openrdf.query.algebra.MultiProjection)5 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)5 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)5 StatementPattern (org.openrdf.query.algebra.StatementPattern)5 Projection (org.openrdf.query.algebra.Projection)4 ValueConstant (org.openrdf.query.algebra.ValueConstant)3 Var (org.openrdf.query.algebra.Var)2 BNodeGenerator (org.openrdf.query.algebra.BNodeGenerator)1 Filter (org.openrdf.query.algebra.Filter)1 ParsedTupleQuery (org.openrdf.query.parser.ParsedTupleQuery)1