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());
}
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));
}
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);
}
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));
}
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());
}
Aggregations