You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@rya.apache.org by meiercaleb <gi...@git.apache.org> on 2017/10/04 19:11:14 UTC

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

GitHub user meiercaleb opened a pull request:

    https://github.com/apache/incubator-rya/pull/237

    RYA-392-Datetime-Within

    <!--
    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.
    -->
    ## Description
    Added a Function DateTimeWithinPeriod to determine whether two datetimes were within a
    specified period of time of one another.
    
    ### Tests
    Added unit tests to test the Function and added integration tests to verify that the Function
    is correctly utilized during query evaluation.
    
    ### Links
    [Jira](https://issues.apache.org/jira/browse/RYA-392)
    
    ### Checklist
    - [ ] Code Review
    - [x] Squash Commits
    
    #### People To Reivew
    @jdasch @kchilton2 


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/meiercaleb/incubator-rya RYA-392

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-rya/pull/237.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #237
    
----
commit e82688730e94140c9a5c2e83959c1e0f97af7a24
Author: Caleb Meier <ca...@parsons.com>
Date:   2017-10-04T19:06:55Z

    RYA-392-Datetime-Within

----


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143051029
  
    --- Diff: common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinTest.java ---
    @@ -0,0 +1,184 @@
    +/*
    + * 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 static org.junit.Assert.assertEquals;
    +
    +import java.time.ZonedDateTime;
    +import java.time.format.DateTimeFormatter;
    +
    +import javax.xml.datatype.DatatypeConfigurationException;
    +import javax.xml.datatype.DatatypeFactory;
    +
    +import org.junit.Test;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +
    +public class DateTimeWithinTest {
    +
    +    private static final ValueFactory vf = new ValueFactoryImpl();
    +    private static final Literal TRUE = vf.createLiteral(true);
    +    private static final Literal FALSE = vf.createLiteral(false);
    +
    +    @Test 
    +    public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +        
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusSeconds(1);
    --- End diff --
    
    Maybe call this oneSecondEarlierZTime?


---

[GitHub] incubator-rya issue #237: RYA-392-Datetime-Within

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/237
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/517/



---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143288900
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,114 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    +
    +    static {
    +        DURATION_MAP.put(SECONDS_URI, ChronoUnit.SECONDS);
    +        DURATION_MAP.put(MINUTES_URI, ChronoUnit.MINUTES);
    +        DURATION_MAP.put(HOURS_URI, ChronoUnit.HOURS);
    +        DURATION_MAP.put(DAYS_URI, ChronoUnit.DAYS);
    +        DURATION_MAP.put(WEEKS_URI, ChronoUnit.WEEKS);
    +    }
    +
    +    /**
    +     * Verifies whether URI is a valid OWL-Time URI that is supported by this class.
    +     * @param durationURI - OWLTime URI indicating the time unit
    --- End diff --
    
    Document your nullness contract. 
    
    ```
    @param durationURI - OWLTime URI indicating the time unit. (not null)
    ```


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143482605
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +
    +import java.time.Duration;
    +import java.time.Instant;
    +
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +/**
    + * This {@link Function} determines whether two {@link XMLSchema#DATETIME}s occur within a specified period of time of
    + * one another. The method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + *
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String FUNCTION_URI = FN.NAMESPACE + "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FUNCTION_URI;
    +    }
    +
    +    /**
    +     * 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
    +     * @param values - array of Value arguments for this Function.
    +     */
    +    @Override
    +    public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143050192
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    --- End diff --
    
    Done


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143286416
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +
    +import java.time.Duration;
    +import java.time.Instant;
    +
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +/**
    + * This {@link Function} determines whether two {@link XMLSchema#DATETIME}s occur within a specified period of time of
    + * one another. The method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + *
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String FUNCTION_URI = FN.NAMESPACE + "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FUNCTION_URI;
    +    }
    +
    +    /**
    +     * 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
    +     * @param values - array of Value arguments for this Function.
    +     */
    +    @Override
    +    public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    --- End diff --
    
    Add null checks.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143482636
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,114 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    +
    +    static {
    +        DURATION_MAP.put(SECONDS_URI, ChronoUnit.SECONDS);
    +        DURATION_MAP.put(MINUTES_URI, ChronoUnit.MINUTES);
    +        DURATION_MAP.put(HOURS_URI, ChronoUnit.HOURS);
    +        DURATION_MAP.put(DAYS_URI, ChronoUnit.DAYS);
    +        DURATION_MAP.put(WEEKS_URI, ChronoUnit.WEEKS);
    +    }
    +
    +    /**
    +     * Verifies whether URI is a valid OWL-Time URI that is supported by this class.
    +     * @param durationURI - OWLTime URI indicating the time unit
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143287735
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,114 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    +
    +    static {
    +        DURATION_MAP.put(SECONDS_URI, ChronoUnit.SECONDS);
    +        DURATION_MAP.put(MINUTES_URI, ChronoUnit.MINUTES);
    +        DURATION_MAP.put(HOURS_URI, ChronoUnit.HOURS);
    +        DURATION_MAP.put(DAYS_URI, ChronoUnit.DAYS);
    +        DURATION_MAP.put(WEEKS_URI, ChronoUnit.WEEKS);
    +    }
    +
    +    /**
    +     * Verifies whether URI is a valid OWL-Time URI that is supported by this class.
    +     * @param durationURI - OWLTime URI indicating the time unit
    +     * @return - {@code true} if this URI indicates a supported OWLTime time unit
    +     */
    +    public static boolean isValidDurationType(URI durationURI) {
    +        checkNotNull(durationURI);
    +        return DURATION_MAP.containsKey(durationURI);
    +    }
    +
    +    /**
    +     * 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
    +     * @throws IllegalArgumentException if provided {@link URI} is not a valid, supported OWL-Time time unit.
    +     */
    +    public static long getMillis(int duration, URI uri) throws IllegalArgumentException {
    +        Optional<ChronoUnit> unit = getChronoUnitFromURI(uri);
    +        checkArgument(unit.isPresent(),
    +                String.format("URI %s does not indicate a valid OWLTime time unit.  URI must of be of type %s, %s, %s, %s, or %s .", uri,
    +                        SECONDS_URI, MINUTES_URI, HOURS_URI, DAYS_URI, WEEKS_URI));
    +        return duration * unit.get().getDuration().toMillis();
    +    }
    +
    +    /**
    +     * Converts the {@link OWLTime} URI time unit to a {@link ChronoUnit} time unit
    +     *
    +     * @param durationURI - OWLTime time unit URI
    +     * @return - corresponding ChronoUnit time unit
    +     */
    +    public static Optional<ChronoUnit> getChronoUnitFromURI(URI durationURI) {
    --- End diff --
    
    This function could be simplified to:
    ```java
    public static Optional<ChronoUnit> getChronoUnitFromURI(URI durationURI) {
        return Optional.ofNullable(DURATION_MAP.get(durationURI));
    }
    ```


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143049674
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String DATE_TIME_WITHIN = "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FN.NAMESPACE.toString() + DATE_TIME_WITHIN;
    +    }
    +
    --- End diff --
    
    Change to 
    ```
        private static final String FUNCTION_URI = FN.NAMESPACE + "dateTimeWithin";
    
        @Override
        public String getURI() {
            return FUNCTION_URI;
        }
    ```


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143227030
  
    --- 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 --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-rya/pull/237


---

[GitHub] incubator-rya issue #237: RYA-392-Datetime-Within

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/237
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/513/<h2>Failed Tests: <span class='status-failure'>1</span></h2><h3><a name='incubator-rya-master-with-optionals-pull-requests/org.apache.rya:rya.indexing' /><a href='https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/513/org.apache.rya$rya.indexing/testReport'>incubator-rya-master-with-optionals-pull-requests/org.apache.rya:rya.indexing</a>: <span class='status-failure'>1</span></h3><ul><li><a href='https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/513/org.apache.rya$rya.indexing/testReport/org.apache.rya.indexing.mongo/MongoEntityIndexTest/org_apache_rya_indexing_mongo_MongoEntityIndexTest/'><strong>org.apache.rya.indexing.mongo.MongoEntityIndexTest.org.apache.rya.indexing.mongo.MongoEntityIndexTest</strong></a></li></ul>



---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143227137
  
    --- 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 method has been removed.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143050918
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String DATE_TIME_WITHIN = "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FN.NAMESPACE.toString() + DATE_TIME_WITHIN;
    +    }
    +
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143049467
  
    --- 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 {
    --- End diff --
    
    It would be nice if you didn't have this static method or the static fields up top.
    
    You could have a private static final ValueFatory that you use within the Duration enum to build the URIs.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143049513
  
    --- 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 {
    --- End diff --
    
    This class could use some javadocs.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143060791
  
    --- Diff: common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinTest.java ---
    @@ -0,0 +1,184 @@
    +/*
    + * 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 static org.junit.Assert.assertEquals;
    +
    +import java.time.ZonedDateTime;
    +import java.time.format.DateTimeFormatter;
    +
    +import javax.xml.datatype.DatatypeConfigurationException;
    +import javax.xml.datatype.DatatypeFactory;
    +
    +import org.junit.Test;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +
    +public class DateTimeWithinTest {
    +
    +    private static final ValueFactory vf = new ValueFactoryImpl();
    +    private static final Literal TRUE = vf.createLiteral(true);
    +    private static final Literal FALSE = vf.createLiteral(false);
    +
    +    @Test 
    +    public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +        
    +        ZonedDateTime zTime = ZonedDateTime.now();
    --- End diff --
    
    Changed names.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143054711
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String DATE_TIME_WITHIN = "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FN.NAMESPACE.toString() + DATE_TIME_WITHIN;
    +    }
    +
    +    /**
    +     * 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
    +     * @param values - array of Value arguments for this Function.
    +     */
    +    @Override
    +    public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    +
    +        // general validation of input
    +        Preconditions.checkArgument(values.length == 4);
    +        Preconditions.checkArgument(values[0] instanceof Literal);
    --- End diff --
    
    This is a style comment. It would be a little easier to understand that this code is doing if these array indices were descriptive of what was stored in the array at that position.
    
    for exmple:
    private static final int DATE_TIME_1 = 0;
    private static final int DATE_TIME_2 = 1;
    private static final int PERIOD = 2;
    private static final int PERIOD_UNITS = 3;
    
    Then the rest of the code could look like:
    long epochTime1 = convertDatetimeToMillis((Literal) values[DATE_TIME_1]);
    long epochTime2 = convertDatetimeToMillis((Literal) values[DATE_TIME_2]);
    long periodMillis = convertPeriodToMillis((Literal) values[PERIOD], (URI) values[PERIOD_UNITS]);
    
    etc


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143226896
  
    --- 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 {
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143230685
  
    --- 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;
    --- End diff --
    
    Using ChronoUnit now.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143046354
  
    --- Diff: common/rya.api/pom.xml ---
    @@ -95,5 +95,20 @@ under the License.
                 <scope>test</scope>
             </dependency>
         </dependencies>
    +    <build>
    +        <plugins>
    +            <plugin>
    +                <groupId>org.apache.rat</groupId>
    +                <artifactId>apache-rat-plugin</artifactId>
    +                <configuration>
    +                    <excludes>
    +                        <!-- Trivial listing of classes to be loaded via 
    +                            SPI -->
    +                        <exclude>src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function</exclude>
    --- End diff --
    
    This file needs a license header.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143049987
  
    --- 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 also return an Optional<Duration> if you would rather indicate it is invalid by showing no value exists for the URI instead of throwing an exception.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143054724
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String DATE_TIME_WITHIN = "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FN.NAMESPACE.toString() + DATE_TIME_WITHIN;
    +    }
    +
    +    /**
    +     * 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
    +     * @param values - array of Value arguments for this Function.
    +     */
    +    @Override
    +    public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    +
    +        // general validation of input
    +        Preconditions.checkArgument(values.length == 4);
    --- End diff --
    
    Done


---

[GitHub] incubator-rya issue #237: RYA-392-Datetime-Within

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/237
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/512/



---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143481881
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,114 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    +
    +    static {
    +        DURATION_MAP.put(SECONDS_URI, ChronoUnit.SECONDS);
    +        DURATION_MAP.put(MINUTES_URI, ChronoUnit.MINUTES);
    +        DURATION_MAP.put(HOURS_URI, ChronoUnit.HOURS);
    +        DURATION_MAP.put(DAYS_URI, ChronoUnit.DAYS);
    +        DURATION_MAP.put(WEEKS_URI, ChronoUnit.WEEKS);
    +    }
    +
    +    /**
    +     * Verifies whether URI is a valid OWL-Time URI that is supported by this class.
    +     * @param durationURI - OWLTime URI indicating the time unit
    +     * @return - {@code true} if this URI indicates a supported OWLTime time unit
    +     */
    +    public static boolean isValidDurationType(URI durationURI) {
    +        checkNotNull(durationURI);
    +        return DURATION_MAP.containsKey(durationURI);
    +    }
    +
    +    /**
    +     * 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
    +     * @throws IllegalArgumentException if provided {@link URI} is not a valid, supported OWL-Time time unit.
    +     */
    +    public static long getMillis(int duration, URI uri) throws IllegalArgumentException {
    +        Optional<ChronoUnit> unit = getChronoUnitFromURI(uri);
    +        checkArgument(unit.isPresent(),
    +                String.format("URI %s does not indicate a valid OWLTime time unit.  URI must of be of type %s, %s, %s, %s, or %s .", uri,
    +                        SECONDS_URI, MINUTES_URI, HOURS_URI, DAYS_URI, WEEKS_URI));
    +        return duration * unit.get().getDuration().toMillis();
    +    }
    +
    +    /**
    +     * Converts the {@link OWLTime} URI time unit to a {@link ChronoUnit} time unit
    +     *
    +     * @param durationURI - OWLTime time unit URI
    +     * @return - corresponding ChronoUnit time unit
    +     */
    +    public static Optional<ChronoUnit> getChronoUnitFromURI(URI durationURI) {
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143288947
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,114 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    +
    +    static {
    +        DURATION_MAP.put(SECONDS_URI, ChronoUnit.SECONDS);
    +        DURATION_MAP.put(MINUTES_URI, ChronoUnit.MINUTES);
    +        DURATION_MAP.put(HOURS_URI, ChronoUnit.HOURS);
    +        DURATION_MAP.put(DAYS_URI, ChronoUnit.DAYS);
    +        DURATION_MAP.put(WEEKS_URI, ChronoUnit.WEEKS);
    +    }
    +
    +    /**
    +     * Verifies whether URI is a valid OWL-Time URI that is supported by this class.
    +     * @param durationURI - OWLTime URI indicating the time unit
    --- End diff --
    
    This is a general comment through out the code in this review.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143742007
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,111 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    --- End diff --
    
    Nit: Using an ImmutableMap would make your intent here clearer.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143226837
  
    --- 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) {
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143055190
  
    --- 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;
    --- End diff --
    
    Checkout TimeUnits.


---

[GitHub] incubator-rya issue #237: RYA-392-Datetime-Within

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/237
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/518/



---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143046845
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    --- End diff --
    
    change to XMLSchema.DATETIME


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143049693
  
    --- 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) {
    --- End diff --
    
    This method could also be on the Duration enumeration. Or just get and if it doesn't find a value for the provided URI, then it is implicitly not a valid Duration type.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143742329
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.Duration;
    +import java.time.Instant;
    +
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +/**
    + * This {@link Function} determines whether two {@link XMLSchema#DATETIME}s occur within a specified period of time of
    + * one another. The method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + *
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String FUNCTION_URI = FN.NAMESPACE + "dateTimeWithin";
    --- End diff --
    
    Nit:  dateTimeWithinPeriod


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143054683
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    --- End diff --
    
    Done


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143750138
  
    --- Diff: common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinPeriodTest.java ---
    @@ -0,0 +1,180 @@
    +/*
    + * 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 static org.junit.Assert.assertEquals;
    +
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.format.DateTimeFormatter;
    +
    +import javax.xml.datatype.DatatypeConfigurationException;
    +import javax.xml.datatype.DatatypeFactory;
    +
    +import org.junit.Test;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +
    +public class DateTimeWithinPeriodTest {
    +
    +    private static final ValueFactory vf = new ValueFactoryImpl();
    +    private static final Literal TRUE = vf.createLiteral(true);
    +    private static final Literal FALSE = vf.createLiteral(false);
    +
    +    @Test
    +    public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusSeconds(1);
    +        String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        Literal now = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    +        Literal nowMinusOne = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
    +
    +        DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    +
    +        assertEquals(TRUE, func.evaluate(vf, now, now, vf.createLiteral(1), OWLTime.SECONDS_URI));
    +        assertEquals(FALSE, func.evaluate(vf, now, nowMinusOne,vf.createLiteral(1), OWLTime.SECONDS_URI));
    +        assertEquals(TRUE, func.evaluate(vf, now, nowMinusOne,vf.createLiteral(2), OWLTime.SECONDS_URI));
    +    }
    +
    +    @Test
    +    public void testMinutes() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusMinutes(1);
    +        String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        Literal now = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    +        Literal nowMinusOne = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
    +
    +        DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    +
    +        assertEquals(TRUE, func.evaluate(vf, now, now,vf.createLiteral(1),OWLTime.MINUTES_URI));
    +        assertEquals(FALSE, func.evaluate(vf, now, nowMinusOne,vf.createLiteral(1),OWLTime.MINUTES_URI));
    +        assertEquals(TRUE, func.evaluate(vf, now, nowMinusOne,vf.createLiteral(2),OWLTime.MINUTES_URI));
    +    }
    +
    +
    +    @Test
    +    public void testHours() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusHours(1);
    +        String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        Literal now = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    +        Literal nowMinusOne = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
    +
    +        DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    +
    +        assertEquals(TRUE, func.evaluate(vf, now, now,vf.createLiteral(1),OWLTime.HOURS_URI));
    +        assertEquals(FALSE, func.evaluate(vf, now, nowMinusOne,vf.createLiteral(1),OWLTime.HOURS_URI));
    +        assertEquals(TRUE, func.evaluate(vf, now, nowMinusOne,vf.createLiteral(2),OWLTime.HOURS_URI));
    +    }
    +
    +
    +    @Test
    +    public void testDays() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusDays(1);
    +        String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        Literal now = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    +        Literal nowMinusOne = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
    +
    +        DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    +
    +        assertEquals(TRUE, func.evaluate(vf, now, now, vf.createLiteral(1), OWLTime.DAYS_URI));
    +        assertEquals(FALSE, func.evaluate(vf, now, nowMinusOne, vf.createLiteral(1), OWLTime.DAYS_URI));
    +        assertEquals(TRUE, func.evaluate(vf, now, nowMinusOne, vf.createLiteral(2), OWLTime.DAYS_URI));
    +    }
    +
    +    @Test
    +    public void testWeeks() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusWeeks(1);
    +        String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime2 = zTime.minusWeeks(7);
    +        String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        Literal now = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    +        Literal nowMinusOne = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
    +        Literal nowMinusSeven = vf.createLiteral(dtf.newXMLGregorianCalendar(time2));
    +
    +        DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    +
    +        assertEquals(TRUE, func.evaluate(vf, now, now, vf.createLiteral(1), OWLTime.WEEKS_URI));
    +        assertEquals(FALSE, func.evaluate(vf, now, nowMinusOne, vf.createLiteral(1), OWLTime.WEEKS_URI));
    +        assertEquals(TRUE, func.evaluate(vf, now, nowMinusOne, vf.createLiteral(2), OWLTime.WEEKS_URI));
    +        assertEquals(FALSE, func.evaluate(vf, now, nowMinusSeven, vf.createLiteral(7), OWLTime.WEEKS_URI));
    +    }
    +
    +    @Test
    +    public void testTimeZone() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +
    +        ZonedDateTime now = ZonedDateTime.now();
    +        String time = now.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = now.withZoneSameInstant(ZoneId.of("Europe/London"));
    +        String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime2 = now.withZoneSameInstant(ZoneId.of("Australia/Sydney"));
    +        String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime3 = now.minusDays(1).withZoneSameInstant(ZoneId.of("Asia/Seoul"));
    +        String time3 = zTime3.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        Literal nowLocal = vf.createLiteral(dtf.newXMLGregorianCalendar(time));
    +        Literal nowEuropeTZ = vf.createLiteral(dtf.newXMLGregorianCalendar(time1));
    +        Literal nowAustraliaTZ = vf.createLiteral(dtf.newXMLGregorianCalendar(time2));
    +        Literal nowAsiaTZMinusOne = vf.createLiteral(dtf.newXMLGregorianCalendar(time3));
    +
    +        DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    +
    +        assertEquals(TRUE, func.evaluate(vf, nowLocal, nowEuropeTZ, vf.createLiteral(1), OWLTime.SECONDS_URI));
    +        assertEquals(TRUE, func.evaluate(vf, nowLocal, nowAustraliaTZ, vf.createLiteral(1), OWLTime.SECONDS_URI));
    +        assertEquals(FALSE, func.evaluate(vf, nowLocal, nowAsiaTZMinusOne, vf.createLiteral(1), OWLTime.DAYS_URI));
    +        assertEquals(TRUE, func.evaluate(vf, nowLocal, nowAsiaTZMinusOne, vf.createLiteral(2), OWLTime.DAYS_URI));
    +    }
    --- End diff --
    
    Nit: This feels cleaner to me...
    ```
        @Test
        public void testTimeZone2() throws DatatypeConfigurationException, ValueExprEvaluationException {
            final DatatypeFactory dtf = DatatypeFactory.newInstance();
            final Literal tPlus5 = vf.createLiteral(dtf.newXMLGregorianCalendar("2017-10-10T00:00:00+05:00"));
            final Literal tPlus8 = vf.createLiteral(dtf.newXMLGregorianCalendar("2017-10-10T00:00:00+08:00"));
    
            final DateTimeWithinPeriod func = new DateTimeWithinPeriod();
    
            assertEquals(FALSE, func.evaluate(vf, tPlus5, tPlus8, vf.createLiteral(3*60), OWLTime.MINUTES_URI));
            assertEquals(FALSE, func.evaluate(vf, tPlus5, tPlus8, vf.createLiteral(3), OWLTime.HOURS_URI));
            assertEquals(TRUE, func.evaluate(vf, tPlus5, tPlus8, vf.createLiteral(3*60+1), OWLTime.MINUTES_URI));
            assertEquals(TRUE, func.evaluate(vf, tPlus5, tPlus8, vf.createLiteral(4), OWLTime.HOURS_URI));
            assertEquals(TRUE, func.evaluate(vf, tPlus5, tPlus8, vf.createLiteral(1), OWLTime.DAYS_URI));
        }
    ```


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143049589
  
    --- Diff: common/rya.api/pom.xml ---
    @@ -95,5 +95,20 @@ under the License.
                 <scope>test</scope>
             </dependency>
         </dependencies>
    +    <build>
    +        <plugins>
    +            <plugin>
    +                <groupId>org.apache.rat</groupId>
    +                <artifactId>apache-rat-plugin</artifactId>
    +                <configuration>
    +                    <excludes>
    +                        <!-- Trivial listing of classes to be loaded via 
    +                            SPI -->
    +                        <exclude>src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function</exclude>
    --- End diff --
    
    Done.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143048147
  
    --- 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) {
    --- End diff --
    
    Also, null check?


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143046217
  
    --- Diff: common/rya.api/pom.xml ---
    @@ -95,5 +95,20 @@ under the License.
                 <scope>test</scope>
             </dependency>
         </dependencies>
    +    <build>
    +        <plugins>
    +            <plugin>
    +                <groupId>org.apache.rat</groupId>
    +                <artifactId>apache-rat-plugin</artifactId>
    +                <configuration>
    +                    <excludes>
    +                        <!-- Trivial listing of classes to be loaded via 
    +                            SPI -->
    +                        <exclude>src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function</exclude>
    --- End diff --
    
    Remove this.  Add the license to the service loader.  # is the comment character
    http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143226973
  
    --- 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 {
    --- End diff --
    
    This class has been removed.


---

[GitHub] incubator-rya issue #237: RYA-392-Datetime-Within

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:

    https://github.com/apache/incubator-rya/pull/237
  
    
    Refer to this link for build results (access rights to CI server needed): 
    https://builds.apache.org/job/incubator-rya-master-with-optionals-pull-requests/519/



---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
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.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143048091
  
    --- 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) {
    --- End diff --
    
    Missing javadocs.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143060603
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String DATE_TIME_WITHIN = "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FN.NAMESPACE.toString() + DATE_TIME_WITHIN;
    +    }
    +
    +    /**
    +     * 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
    +     * @param values - array of Value arguments for this Function.
    +     */
    +    @Override
    +    public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    +
    +        // general validation of input
    +        Preconditions.checkArgument(values.length == 4);
    +        Preconditions.checkArgument(values[0] instanceof Literal);
    --- End diff --
    
    Point taken.  I think the comments clearly explain the order of the arguments.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143047847
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    +
    +    private static final String DATE_TIME_WITHIN = "dateTimeWithin";
    +
    +    @Override
    +    public String getURI() {
    +        return FN.NAMESPACE.toString() + DATE_TIME_WITHIN;
    +    }
    +
    +    /**
    +     * 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
    +     * @param values - array of Value arguments for this Function.
    +     */
    +    @Override
    +    public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException {
    +
    +        // general validation of input
    +        Preconditions.checkArgument(values.length == 4);
    --- End diff --
    
    Do you want these to throw a ValueExprEvaluationException in order to follow the Function interface contract?


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143750533
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,130 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.Duration;
    +import java.time.Instant;
    +
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +/**
    + * This {@link Function} determines whether two {@link XMLSchema#DATETIME}s occur within a specified period of time of
    + * one another. The method {@link Function#evaluate(ValueFactory, Value...)} 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>
    --- End diff --
    
    Nit: As a user, I'd love a 5th optional argument that allows me to specify exclusiveness or inclusiveness of the period.


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by kchilton2 <gi...@git.apache.org>.
Github user kchilton2 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143050856
  
    --- Diff: common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinTest.java ---
    @@ -0,0 +1,184 @@
    +/*
    + * 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 static org.junit.Assert.assertEquals;
    +
    +import java.time.ZonedDateTime;
    +import java.time.format.DateTimeFormatter;
    +
    +import javax.xml.datatype.DatatypeConfigurationException;
    +import javax.xml.datatype.DatatypeFactory;
    +
    +import org.junit.Test;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +
    +public class DateTimeWithinTest {
    +
    +    private static final ValueFactory vf = new ValueFactoryImpl();
    +    private static final Literal TRUE = vf.createLiteral(true);
    +    private static final Literal FALSE = vf.createLiteral(false);
    +
    +    @Test 
    +    public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +        
    +        ZonedDateTime zTime = ZonedDateTime.now();
    --- End diff --
    
    This test is a little hard to follow. Maybe call this variable nowZTime?


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143742559
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/OWLTime.java ---
    @@ -0,0 +1,111 @@
    +/*
    + * 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 static com.google.common.base.Preconditions.checkArgument;
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.time.temporal.ChronoUnit;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +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 {
    +
    +    private static final ValueFactory FACTORY = ValueFactoryImpl.getInstance();
    +
    +    /**
    +     * 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 = FACTORY.createURI(NAMESPACE, "seconds");
    +    /**
    +     * Minutes class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI MINUTES_URI = FACTORY.createURI(NAMESPACE, "minutes");
    +    /**
    +     * Hours class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI HOURS_URI = FACTORY.createURI(NAMESPACE, "hours");
    +    /**
    +     * Days class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI DAYS_URI = FACTORY.createURI(NAMESPACE, "days");
    +    /**
    +     * Weeks class of type DurationDescription in OWL-Time ontology
    +     */
    +    public static final URI WEEKS_URI = FACTORY.createURI(NAMESPACE, "weeks");
    +
    +    private static final Map<URI, ChronoUnit> DURATION_MAP = new HashMap<>();
    +
    +    static {
    +        DURATION_MAP.put(SECONDS_URI, ChronoUnit.SECONDS);
    +        DURATION_MAP.put(MINUTES_URI, ChronoUnit.MINUTES);
    +        DURATION_MAP.put(HOURS_URI, ChronoUnit.HOURS);
    +        DURATION_MAP.put(DAYS_URI, ChronoUnit.DAYS);
    +        DURATION_MAP.put(WEEKS_URI, ChronoUnit.WEEKS);
    +    }
    +
    +    /**
    +     * Verifies whether URI is a valid OWL-Time URI that is supported by this class.
    +     * @param durationURI - OWLTime URI indicating the time unit (not null)
    +     * @return - {@code true} if this URI indicates a supported OWLTime time unit
    +     */
    +    public static boolean isValidDurationType(URI durationURI) {
    +        checkNotNull(durationURI);
    --- End diff --
    
    Nit:  add user feedback message in the checkNotNull


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by jdasch <gi...@git.apache.org>.
Github user jdasch commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143051442
  
    --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java ---
    @@ -0,0 +1,121 @@
    +/*
    + * 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.apache.rya.api.functions.OWLTime.Duration;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.Value;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.datatypes.XMLDatatypeUtil;
    +import org.openrdf.model.vocabulary.FN;
    +import org.openrdf.model.vocabulary.XMLSchema;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +import org.openrdf.query.algebra.evaluation.function.Function;
    +
    +import com.google.common.base.Preconditions;
    +
    +/**
    + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The
    + * method {@link Function#evaluate(ValueFactory, Value...)} 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>
    + * 
    + */
    +public class DateTimeWithinPeriod implements Function {
    --- End diff --
    
    Rename `DateTimeWithinPeriod` to `DateTimeWithin`
    or
    Rename `DateTimeWithinTest` to `DateTimeWithinPeriodTest`


---

[GitHub] incubator-rya pull request #237: RYA-392-Datetime-Within

Posted by meiercaleb <gi...@git.apache.org>.
Github user meiercaleb commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/237#discussion_r143060815
  
    --- Diff: common/rya.api/src/test/java/org/apache/rya/api/functions/DateTimeWithinTest.java ---
    @@ -0,0 +1,184 @@
    +/*
    + * 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 static org.junit.Assert.assertEquals;
    +
    +import java.time.ZonedDateTime;
    +import java.time.format.DateTimeFormatter;
    +
    +import javax.xml.datatype.DatatypeConfigurationException;
    +import javax.xml.datatype.DatatypeFactory;
    +
    +import org.junit.Test;
    +import org.openrdf.model.Literal;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
    +
    +public class DateTimeWithinTest {
    +
    +    private static final ValueFactory vf = new ValueFactoryImpl();
    +    private static final Literal TRUE = vf.createLiteral(true);
    +    private static final Literal FALSE = vf.createLiteral(false);
    +
    +    @Test 
    +    public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
    +        DatatypeFactory dtf = DatatypeFactory.newInstance();
    +        
    +        ZonedDateTime zTime = ZonedDateTime.now();
    +        String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
    +
    +        ZonedDateTime zTime1 = zTime.minusSeconds(1);
    --- End diff --
    
    Updated names.


---