Search in sources :

Example 1 with ExtensionElem

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

the class AggregationPipelineQueryNodeTest method testExtend.

@Test
public void testExtend() {
    final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode(collection, new LinkedList<>(), Sets.newHashSet("x", "y"), Sets.newHashSet("x", "y", "opt"), HashBiMap.create());
    // Extend with a mix of variables and constants
    List<ExtensionElem> extensionElements = Arrays.asList(new ExtensionElem(new Var("x"), "subject"), new ExtensionElem(new ValueConstant(RDF.TYPE), "predicate"), new ExtensionElem(new Var("y"), "object"));
    AggregationPipelineQueryNode node = base.clone();
    boolean success = node.extend(extensionElements);
    Assert.assertTrue(success);
    Assert.assertEquals(1, node.getPipeline().size());
    Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object"), node.getAssuredBindingNames());
    Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object", "opt"), node.getBindingNames());
    // Attempt to extend with an unsupported expression
    extensionElements = Arrays.asList(new ExtensionElem(new Var("x"), "subject"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"));
    node = base.clone();
    success = node.extend(extensionElements);
    Assert.assertFalse(success);
    Assert.assertEquals(base, node);
}
Also used : Not(org.openrdf.query.algebra.Not) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) Test(org.junit.Test)

Example 2 with ExtensionElem

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

the class SparqlToPipelineTransformVisitorTest method testUnsupportedExtension.

@Test
public void testUnsupportedExtension() throws Exception {
    StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
    List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"), new ExtensionElem(new ValueConstant(TAKES), "constant"));
    Extension extensionNode = new Extension(sp, elements);
    QueryRoot queryTree = new QueryRoot(extensionNode);
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof Extension);
    Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
    TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
    Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
    Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
Also used : Extension(org.openrdf.query.algebra.Extension) StatementPattern(org.openrdf.query.algebra.StatementPattern) Not(org.openrdf.query.algebra.Not) QueryRoot(org.openrdf.query.algebra.QueryRoot) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 3 with ExtensionElem

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

the class SparqlToPipelineTransformVisitorTest method testExtension.

@Test
public void testExtension() throws Exception {
    QueryRoot queryTree = new QueryRoot(new Extension(new StatementPattern(new Var("x"), constant(TAKES), new Var("c")), new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new ValueConstant(TAKES), "constant")));
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
    Assert.assertEquals(Sets.newHashSet("x", "c", "renamed", "constant"), pipelineNode.getAssuredBindingNames());
}
Also used : Extension(org.openrdf.query.algebra.Extension) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryRoot(org.openrdf.query.algebra.QueryRoot) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) Test(org.junit.Test)

Example 4 with ExtensionElem

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

the class HasSelfVisitorTest method testPropertyPattern_constantSubj.

@Test
public void testPropertyPattern_constantSubj() throws Exception {
    final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
    final Set<Resource> loveTypes = new HashSet<>();
    loveTypes.add(narcissist);
    when(inferenceEngine.getHasSelfImplyingProperty(love)).thenReturn(loveTypes);
    final Var subj = new Var("s", self);
    subj.setConstant(true);
    final Var obj = new Var("o");
    final Var pred = new Var("p", love);
    pred.setConstant(true);
    final Projection query = new Projection(new StatementPattern(subj, pred, obj), new ProjectionElemList(new ProjectionElem("s", "subject")));
    query.visit(new HasSelfVisitor(conf, inferenceEngine));
    Assert.assertTrue(query.getArg() instanceof Union);
    final Union union = (Union) query.getArg();
    Assert.assertTrue(union.getRightArg() instanceof StatementPattern);
    Assert.assertTrue(union.getLeftArg() instanceof Extension);
    final StatementPattern expectedRight = new StatementPattern(subj, pred, obj);
    final Extension expectedLeft = new Extension(new StatementPattern(subj, new Var(RDF.TYPE.stringValue(), RDF.TYPE), new Var("urn:Narcissist", narcissist)), new ExtensionElem(subj, "o"));
    Assert.assertEquals(expectedLeft, union.getLeftArg());
    Assert.assertEquals(expectedRight, union.getRightArg());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) Var(org.openrdf.query.algebra.Var) Resource(org.openrdf.model.Resource) Projection(org.openrdf.query.algebra.Projection) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) Union(org.openrdf.query.algebra.Union) Extension(org.openrdf.query.algebra.Extension) StatementPattern(org.openrdf.query.algebra.StatementPattern) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ExtensionElem

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

the class HasSelfVisitorTest method testPropertyPattern_constantObj.

@Test
public void testPropertyPattern_constantObj() throws Exception {
    final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
    final Set<Resource> loveTypes = new HashSet<>();
    loveTypes.add(narcissist);
    when(inferenceEngine.getHasSelfImplyingProperty(love)).thenReturn(loveTypes);
    final Var subj = new Var("s");
    final Var obj = new Var("o", self);
    obj.setConstant(true);
    final Var pred = new Var("p", love);
    pred.setConstant(true);
    final Projection query = new Projection(new StatementPattern(subj, pred, obj), new ProjectionElemList(new ProjectionElem("s", "subject")));
    query.visit(new HasSelfVisitor(conf, inferenceEngine));
    Assert.assertTrue(query.getArg() instanceof Union);
    final Union union = (Union) query.getArg();
    Assert.assertTrue(union.getRightArg() instanceof StatementPattern);
    Assert.assertTrue(union.getLeftArg() instanceof Extension);
    final StatementPattern expectedRight = new StatementPattern(subj, pred, obj);
    final Extension expectedLeft = new Extension(new StatementPattern(obj, new Var(RDF.TYPE.stringValue(), RDF.TYPE), new Var("urn:Narcissist", narcissist)), new ExtensionElem(obj, "s"));
    Assert.assertEquals(expectedLeft, union.getLeftArg());
    Assert.assertEquals(expectedRight, union.getRightArg());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) Var(org.openrdf.query.algebra.Var) Resource(org.openrdf.model.Resource) Projection(org.openrdf.query.algebra.Projection) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) Union(org.openrdf.query.algebra.Union) Extension(org.openrdf.query.algebra.Extension) StatementPattern(org.openrdf.query.algebra.StatementPattern) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ExtensionElem (org.openrdf.query.algebra.ExtensionElem)14 Extension (org.openrdf.query.algebra.Extension)11 StatementPattern (org.openrdf.query.algebra.StatementPattern)11 Test (org.junit.Test)10 Var (org.openrdf.query.algebra.Var)10 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)8 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)8 ValueConstant (org.openrdf.query.algebra.ValueConstant)8 Projection (org.openrdf.query.algebra.Projection)6 HashSet (java.util.HashSet)5 MultiProjection (org.openrdf.query.algebra.MultiProjection)5 SingletonSet (org.openrdf.query.algebra.SingletonSet)5 Resource (org.openrdf.model.Resource)3 BNodeGenerator (org.openrdf.query.algebra.BNodeGenerator)3 Value (org.openrdf.model.Value)2 Not (org.openrdf.query.algebra.Not)2 QueryRoot (org.openrdf.query.algebra.QueryRoot)2 TupleExpr (org.openrdf.query.algebra.TupleExpr)2 Union (org.openrdf.query.algebra.Union)2 BasicDBObject (com.mongodb.BasicDBObject)1