Search in sources :

Example 11 with ValueConstant

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

the class PeriodicQueryUtilTest method periodicNodeNotPresentTest.

@Test
public void periodicNodeNotPresentTest() throws Exception {
    List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(12.0)), new ValueConstant(vf.createLiteral(6.0)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
    FunctionCall func = new FunctionCall("uri:func", values);
    Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
    Assert.assertEquals(false, node1.isPresent());
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Join(org.openrdf.query.algebra.Join) FunctionCall(org.openrdf.query.algebra.FunctionCall) Test(org.junit.Test)

Example 12 with ValueConstant

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

the class PeriodicQueryUtilTest method periodicNodeFractionalDurationTest.

@Test
public void periodicNodeFractionalDurationTest() throws Exception {
    List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(1)), new ValueConstant(vf.createLiteral(.5)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
    FunctionCall func = new FunctionCall(PeriodicQueryUtil.PeriodicQueryURI, values);
    Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
    Assert.assertEquals(true, node1.isPresent());
    double window = 1 * 60 * 60 * 1000;
    double period = .5 * 3600 * 1000;
    PeriodicQueryNode node2 = new PeriodicQueryNode((long) window, (long) period, TimeUnit.MILLISECONDS, "time", new Join());
    Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node1.get(), node2));
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Join(org.openrdf.query.algebra.Join) FunctionCall(org.openrdf.query.algebra.FunctionCall) Test(org.junit.Test)

Example 13 with ValueConstant

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

the class PeriodicQueryUtil method parseAndSetValues.

/**
 * @param values - Values extracted from FunctionCall representing the PeriodicQuery Filter
 * @param arg - Argument of the PeriodicQueryNode that will be created (PeriodicQueryNode is a UnaryTupleOperator)
 * @return - PeriodicQueryNode to be inserted in place of the original FunctionCall
 * @throws Exception
 */
private static PeriodicQueryNode parseAndSetValues(List<ValueExpr> values, TupleExpr arg) throws Exception {
    // general validation of input
    Preconditions.checkArgument(values.size() == 4);
    Preconditions.checkArgument(values.get(0) instanceof Var);
    Preconditions.checkArgument(values.get(1) instanceof ValueConstant);
    Preconditions.checkArgument(values.get(2) instanceof ValueConstant);
    Preconditions.checkArgument(values.get(3) instanceof ValueConstant);
    // get temporal variable
    Var var = (Var) values.get(0);
    Preconditions.checkArgument(var.getValue() == null);
    String tempVar = var.getName();
    // get TimeUnit
    TimeUnit unit = getTimeUnit((ValueConstant) values.get(3));
    // get window and period durations
    double windowDuration = parseTemporalDuration((ValueConstant) values.get(1));
    double periodDuration = parseTemporalDuration((ValueConstant) values.get(2));
    long windowMillis = convertToMillis(windowDuration, unit);
    long periodMillis = convertToMillis(periodDuration, unit);
    // period must evenly divide window at least once
    Preconditions.checkArgument(windowMillis > periodMillis);
    Preconditions.checkArgument(windowMillis % periodMillis == 0, "Period duration does not evenly divide window duration.");
    // create PeriodicMetadata.Builder
    return new PeriodicQueryNode(windowMillis, periodMillis, TimeUnit.MILLISECONDS, tempVar, arg);
}
Also used : Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) TimeUnit(java.util.concurrent.TimeUnit) PeriodicQueryNode(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryNode)

Example 14 with ValueConstant

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

the class PeriodicQueryUtilTest method periodicNodePresentTest.

@Test
public void periodicNodePresentTest() throws Exception {
    List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(12.0)), new ValueConstant(vf.createLiteral(6.0)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
    FunctionCall func = new FunctionCall(PeriodicQueryUtil.PeriodicQueryURI, values);
    Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
    Assert.assertEquals(true, node1.isPresent());
    PeriodicQueryNode node2 = new PeriodicQueryNode(12 * 60 * 60 * 1000L, 6 * 3600 * 1000L, TimeUnit.MILLISECONDS, "time", new Join());
    Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node1.get(), node2));
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Var(org.openrdf.query.algebra.Var) ValueConstant(org.openrdf.query.algebra.ValueConstant) Join(org.openrdf.query.algebra.Join) FunctionCall(org.openrdf.query.algebra.FunctionCall) Test(org.junit.Test)

Example 15 with ValueConstant

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

the class ConstructConsequentVisitorTest method testMultiProjection.

@Test
public void testMultiProjection() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(RDF.TYPE), "rdftype"), new ExtensionElem(new ValueConstant(OWL.OBJECTPROPERTY), "owlprop"), new ExtensionElem(new ValueConstant(OWL.EQUIVALENTCLASS), "owleqcls"), new ExtensionElem(new ValueConstant(OWL.CLASS), "owlclass"));
    MultiProjection projection = new MultiProjection(extension, Arrays.asList(new ProjectionElemList(new ProjectionElem("cls", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlclass", "object")), new ProjectionElemList(new ProjectionElem("prop", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlprop", "object")), new ProjectionElemList(new ProjectionElem("owleqcls", "predicate"), new ProjectionElem("cls", "object"))));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(RDF.TYPE), o(OWL.CLASS)), new StatementPattern(s(null), p(RDF.TYPE), o(OWL.OBJECTPROPERTY)), new StatementPattern(s(null), p(OWL.EQUIVALENTCLASS), 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) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Aggregations

ValueConstant (org.openrdf.query.algebra.ValueConstant)17 Var (org.openrdf.query.algebra.Var)14 Test (org.junit.Test)9 ExtensionElem (org.openrdf.query.algebra.ExtensionElem)8 ValueExpr (org.openrdf.query.algebra.ValueExpr)8 StatementPattern (org.openrdf.query.algebra.StatementPattern)6 Value (org.openrdf.model.Value)5 Extension (org.openrdf.query.algebra.Extension)5 FunctionCall (org.openrdf.query.algebra.FunctionCall)4 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)4 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)4 Join (org.openrdf.query.algebra.Join)3 MultiProjection (org.openrdf.query.algebra.MultiProjection)3 SingletonSet (org.openrdf.query.algebra.SingletonSet)3 HashSet (java.util.HashSet)2 Literal (org.openrdf.model.Literal)2 Not (org.openrdf.query.algebra.Not)2 Projection (org.openrdf.query.algebra.Projection)2 QueryRoot (org.openrdf.query.algebra.QueryRoot)2 BasicDBObject (com.mongodb.BasicDBObject)1