use of org.openrdf.query.algebra.evaluation.ValueExprEvaluationException in project incubator-rya by apache.
the class DateTimeWithinPeriod method evaluate.
/**
* Determines whether two datetimes occur within a specified period of time of one another. This method expects four
* values, where the first two values are the datetimes, the third value is an integer indicating the period, and
* the fourth value is a URI indicating the time unit of the period. The URI must be of Type DurationDescription in
* the OWL-Time ontology (see <a href ="https://www.w3.org/TR/owl-time/">https://www.w3.org/TR/owl-time/</a>).
* Examples of valid time unit URIs can be found in the class {@link OWLTime} and below
* <ul>
* <li>http://www.w3.org/2006/time#days</li>
* <li>http://www.w3.org/2006/time#hours</li>
* <li>http://www.w3.org/2006/time#minutes</li>
* <li>http://www.w3.org/2006/time#seconds</li>
* </ul>
*
* @param valueFactory - factory for creating values (not null)
* @param values - array of Value arguments for this Function (not null).
*/
@Override
public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
checkNotNull(valueFactory);
checkNotNull(values);
try {
// general validation of input
checkArgument(values.length == 4);
checkArgument(values[0] instanceof Literal);
checkArgument(values[1] instanceof Literal);
checkArgument(values[2] instanceof Literal);
checkArgument(values[3] instanceof URI);
Instant dateTime1 = convertToInstant((Literal) values[0]);
Instant dateTime2 = convertToInstant((Literal) values[1]);
long periodMillis = convertPeriodToMillis((Literal) values[2], (URI) values[3]);
long timeBetween = Math.abs(Duration.between(dateTime1, dateTime2).toMillis());
return valueFactory.createLiteral(timeBetween < periodMillis);
} catch (Exception e) {
throw new ValueExprEvaluationException(e);
}
}
use of org.openrdf.query.algebra.evaluation.ValueExprEvaluationException in project incubator-rya by apache.
the class TemporalIntervalRelationFunction method evaluate.
@Override
public Value evaluate(final ValueFactory valueFactory, final Value... args) throws ValueExprEvaluationException {
if (args.length != 2) {
throw new ValueExprEvaluationException(getURI() + " requires exactly 2 arguments, got " + args.length);
}
final String[] strInterval = args[1].stringValue().split("/");
if (strInterval.length != 2) {
throw new ValueExprEvaluationException(getURI() + " requires the second argument: " + args[1] + " to be 2 dates seperated by a \'/\'");
}
try {
final ZonedDateTime date1 = ZonedDateTime.parse(args[0].stringValue());
final ZonedDateTime[] interval = new ZonedDateTime[] { ZonedDateTime.parse(strInterval[0]), ZonedDateTime.parse(strInterval[1]) };
final boolean result = relation(date1, interval);
return valueFactory.createLiteral(result);
} catch (final DateTimeParseException e) {
throw new ValueExprEvaluationException("Date/Times provided must be of the ISO-8601 format. Example: 2007-04-05T14:30Z");
}
}
Aggregations