[
https://issues.apache.org/jira/browse/RYA-392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16193655#comment-16193655
]
ASF GitHub Bot commented on RYA-392:
------------------------------------
Github user kchilton2 commented on a diff in the pull request:
https://github.com/apache/incubator-rya/pull/237#discussion_r143049174
--- Diff:
common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rya.api.functions;
+
+import org.openrdf.model.URI;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.ValueFactoryImpl;
+
+/**
+ * Constants for OWL-Time primitives in the OWL-Time namespace.
+ *
+ */
+public class OWLTime {
+
+ /**
+ * Indicates namespace of OWL-Time ontology
+ */
+ public static final String NAMESPACE = "http://www.w3.org/2006/time#";
+ /**
+ * Seconds class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI SECONDS_URI;
+ /**
+ * Minutes class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI MINUTES_URI;
+ /**
+ * Hours class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI HOURS_URI;
+ /**
+ * Days class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI DAYS_URI;
+ /**
+ * Weeks class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI WEEKS_URI;
+ /**
+ * Months class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI MONTHS_URI;
+ /**
+ * Years class of type DurationDescription in OWL-Time ontology
+ */
+ public static final URI YEARS_URI;
+
+ public static boolean isValidDurationType(URI duration) {
+ return (duration.equals(SECONDS_URI) ||
duration.equals(MINUTES_URI) || duration.equals(HOURS_URI) ||
duration.equals(DAYS_URI)
+ || duration.equals(WEEKS_URI) ||
duration.equals(MONTHS_URI) || duration.equals(YEARS_URI));
+ }
+
+ static {
+ ValueFactory factory = ValueFactoryImpl.getInstance();
+ SECONDS_URI = factory.createURI(NAMESPACE, "seconds");
+ MINUTES_URI = factory.createURI(NAMESPACE, "minutes");
+ HOURS_URI = factory.createURI(NAMESPACE, "hours");
+ DAYS_URI = factory.createURI(NAMESPACE, "days");
+ WEEKS_URI = factory.createURI(NAMESPACE, "weeks");
+ MONTHS_URI = factory.createURI(NAMESPACE, "months");
+ YEARS_URI = factory.createURI(NAMESPACE, "years");
+ }
+
+ public static enum Duration {
+ SECONDS(1000, SECONDS_URI),
+ MINUTES(60000, MINUTES_URI),
+ HOURS(3600000, HOURS_URI),
+ DAYS(86400000, DAYS_URI),
+ WEEKS(604800000, WEEKS_URI),
+ MONTHS(2592000000L, MONTHS_URI),
+ YEARS(31536000000L, YEARS_URI);
+
+ private final URI uri;
+ private final long millisConversion;
+
+ Duration(long millisConversion, URI uri) {
+ this.uri = uri;
+ this.millisConversion = millisConversion;
+ }
+
+ public long millisConversion() {
+ return millisConversion;
+ }
+
+ public URI uri() {
+ return uri;
+ }
+
+ /**
+ * Returns the duration in milliseconds
+ *
+ * @param duration - amount of time in the units indicated by the
provided {@link OWLTime} URI
+ * @param uri - OWLTime URI indicating the time unit of duration
+ * @return - the amount of time in milliseconds
+ */
+ public static long getMillis(int duration, URI uri) {
+ Duration durEnum = getDurationFromURI(uri);
+ return duration * durEnum.millisConversion();
+ }
+
+ /**
+ * Provides the Duration from the given duration URI.
+ * @param uri
+ * @return - Duration enum type
+ */
+ public static Duration getDurationFromURI(URI uri) {
--- End diff --
This could be map based. Build out a static map of URI to Duration, then
return it from here.
> Temporal Difference Function
> ----------------------------
>
> Key: RYA-392
> URL: https://issues.apache.org/jira/browse/RYA-392
> Project: Rya
> Issue Type: New Feature
> Affects Versions: 3.2.11
> Reporter: Caleb Meier
> Assignee: Caleb Meier
>
> Currently Rya does not provide a Function that determines whether two
> temporal literals are within a given period of time of one another. This is
> extremely useful for filtering on query results that occurred within a fixed
> period of time of a given instant. Currently, if one attempts to form the
> following filter Filter(?time1 - ?time2 < "24"^^xsd:hour), an exception will
> be thrown if ?time1 and ?time2 are date time literals. I propose
> implementing a Function that takes in two temporal literals, an integer and a
> time unit and determines whether the date times are within the prescribed
> period of one another.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)