Skip to content

Commit

Permalink
[#1398] Add temporal predicates (#1404)
Browse files Browse the repository at this point in the history
fixes #1398
  • Loading branch information
Rascat authored and ChrizZz110 committed Oct 4, 2019
1 parent cfcd0f1 commit c5cbb03
Show file tree
Hide file tree
Showing 13 changed files with 428 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>AsOf</b> predicate.
* Given a certain time-stamp, this predicate will match all time-stamps before or at that time
Expand All @@ -32,14 +36,24 @@ public class AsOf implements TemporalPredicate {
private final long queryTimestamp;

/**
* Creates a AsOf instance with the given time-stamp.
* Creates an <b>AsOf</b> instance with the given time-stamp.
*
* @param timestamp The timestamp to match in Milliseconds since Unix Epoch.
*/
public AsOf(long timestamp) {
this.queryTimestamp = timestamp;
}

/**
* Creates an <b>AsOf</b> instance with the given time-stamp.
* The provided {@link LocalDateTime} value will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param timestamp The timestamp to match.
*/
public AsOf(LocalDateTime timestamp) {
this.queryTimestamp = toEpochMilli(timestamp);
}

@Override
public boolean test(long from, long to) {
return from <= queryTimestamp && to > queryTimestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>Between</b> temporal predicate.
* Given a certain time-interval, this predicate will match all intervals that start
Expand All @@ -37,7 +41,7 @@ public class Between implements TemporalPredicate {
private final long queryTo;

/**
* Creates a Between instance with the given time stamps.
* Creates a <b>Between</b> instance with the given time stamps.
*
* @param from The start of the query time-interval in Milliseconds since Unix Epoch.
* @param to The end of the query time-interval in Milliseconds since Unix Epoch.
Expand All @@ -47,6 +51,18 @@ public Between(long from, long to) {
queryTo = to;
}

/**
* Creates a <b>Between</b> instance with the given time stamps.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval.
* @param to The end of the query time-interval.
*/
public Between(LocalDateTime from, LocalDateTime to) {
queryFrom = toEpochMilli(from);
queryTo = toEpochMilli(to);
}

@Override
public boolean test(long from, long to) {
return from <= queryTo && to > queryFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>ContainedIn</b> temporal predicate.
* Given a certain time interval, this predicate will match all intervals that are a subset of that interval.
Expand All @@ -36,7 +40,7 @@ public class ContainedIn implements TemporalPredicate {
private final long queryTo;

/**
* Creates a ContainedIn instance with the given time stamps.
* Creates a <b>ContainedIn</b> instance with the given time stamps.
*
* @param from The start of the query time-interval in Milliseconds since Unix Epoch.
* @param to The end of the query time-interval in Milliseconds since Unix Epoch.
Expand All @@ -46,6 +50,18 @@ public ContainedIn(long from, long to) {
queryTo = to;
}

/**
* Creates a <b>ContainedIn</b> instance with the given time-interval.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval.
* @param to The end of the query time-interval.
*/
public ContainedIn(LocalDateTime from, LocalDateTime to) {
queryFrom = toEpochMilli(from);
queryTo = toEpochMilli(to);
}

@Override
public boolean test(long from, long to) {
return queryFrom <= from && to <= queryTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>CreatedIn</b> temporal predicate.
* Given a certain time-interval, this predicate matches all intervals starting during that interval.
Expand All @@ -36,7 +40,7 @@ public class CreatedIn implements TemporalPredicate {
private final long queryTo;

/**
* Creates a CreatedIn instance with the given time stamps.
* Creates a <b>CreatedIn</b> instance with the given time stamps.
*
* @param from The start of the query time-interval in Milliseconds since Unix Epoch.
* @param to The end of the query time-interval in Milliseconds since Unix Epoch.
Expand All @@ -46,6 +50,18 @@ public CreatedIn(long from, long to) {
queryTo = to;
}

/**
* Creates a <b>CreatedIn</b> instance with the given time-interval.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval.
* @param to The end of the query time-interval.
*/
public CreatedIn(LocalDateTime from, LocalDateTime to) {
queryFrom = toEpochMilli(from);
queryTo = toEpochMilli(to);
}

@Override
public boolean test(long from, long to) {
return queryFrom <= from && from <= queryTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>DeletedIn</b> temporal predicate.
* Given a certain time-interval, this predicate will match all intervals ending during that interval.
Expand All @@ -36,7 +40,7 @@ public class DeletedIn implements TemporalPredicate {
private final long queryTo;

/**
* Creates a DeletedIn instance with the given time stamps.
* Creates a <b>DeletedIn</b> instance with the given time stamps.
*
* @param from The start of the query time-interval in Milliseconds since Unix Epoch.
* @param to the end of the query time-interval in Milliseconds since Unix Epoch.
Expand All @@ -46,6 +50,18 @@ public DeletedIn(long from, long to) {
queryTo = to;
}

/**
* Creates a <b>DeletedIn</b> instance with the given time-interval.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval.
* @param to The end of the query time-interval.
*/
public DeletedIn(LocalDateTime from, LocalDateTime to) {
queryFrom = toEpochMilli(from);
queryTo = toEpochMilli(to);
}

@Override
public boolean test(long from, long to) {
return queryFrom <= to && to <= queryTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>FromTo</b> temporal predicate.
* Given a time-interval, this predicate will match all intervals that were valid during that interval.
Expand All @@ -36,7 +40,7 @@ public class FromTo implements TemporalPredicate {
private final long queryTo;

/**
* Creates a FromTo instance with the given time stamps.
* Creates a <b>FromTo</b> instance with the given time stamps.
*
* @param from The start of the query time-interval in Milliseconds since Unix Epoch.
* @param to The end of the query time-interval in Milliseconds since Unix Epoch.
Expand All @@ -46,6 +50,18 @@ public FromTo(long from, long to) {
queryTo = to;
}

/**
* Creates a <b>FromTo</b> instance with the given time-interval.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval.
* @param to The end of the query time-interval.
*/
public FromTo(LocalDateTime from, LocalDateTime to) {
queryFrom = toEpochMilli(from);
queryTo = toEpochMilli(to);
}

@Override
public boolean test(long from, long to) {
return from < queryTo && to > queryFrom;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright © 2014 - 2019 Leipzig University (Database Research Group)
*
* Licensed 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.gradoop.temporal.model.impl.functions.predicates;

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>Overlaps</b> temporal predicate.
* Given a certain time interval, this predicates matches all intervals that overlap with that interval.
* <p>
* Predicate: {@code max(from, queryFrom) < min(to, queryTo)}
*/
public class Overlaps implements TemporalPredicate {

/**
* Beginning of query time-interval to be matched.
*/
private final long queryFrom;

/**
* End of query time-interval to be matched.
*/
private final long queryTo;

/**
* Creates a <b>Overlaps</b> instance with the given time-interval.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval
* @param to The end of the query time-interval.
*/
public Overlaps(LocalDateTime from, LocalDateTime to) {
this.queryFrom = toEpochMilli(from);
this.queryTo = toEpochMilli(to);
}

/**
* Creates a <b>Overlaps</b> instance with the given time-interval.
*
* @param from The beginning of the interval to match in milliseconds since Unix Epoch.
* @param to The end of the interval to match in milliseconds since Unix Epoch.
*/
public Overlaps(long from, long to) {
this.queryFrom = from;
this.queryTo = to;
}

@Override
public boolean test(long from, long to) {
return Math.max(from, queryFrom) < Math.min(to, queryTo);
}

@Override
public String toString() {
return String.format("OVERLAPS (%d, %d)", queryFrom, queryTo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright © 2014 - 2019 Leipzig University (Database Research Group)
*
* Licensed 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.gradoop.temporal.model.impl.functions.predicates;

import org.gradoop.temporal.model.api.functions.TemporalPredicate;

import java.time.LocalDateTime;

import static org.gradoop.temporal.util.TimeFormatConversion.toEpochMilli;

/**
* Implementation of the <b>Precedes</b> predicate.
* Given a certain time stamp, this predicate will match all all all time-stamps that precede it.
* <p>
* Predicate: {@code from <= queryFrom && to <= queryFrom}
*/
public class Precedes implements TemporalPredicate {

/**
* Beginning of query time-interval to be matched.
*/
private final long queryFrom;

/**
* End of query time-interval to be matched.
*/
private final long queryTo;

/**
* Creates a <b>Precedes</b> instance with the the given time-interval.
* The provided arguments will be converted to milliseconds since Unix Epoch for UTC time zone.
*
* @param from The beginning of the query time-interval.
* @param to The end of the query time-interval.
*/
public Precedes(LocalDateTime from, LocalDateTime to) {
this.queryFrom = toEpochMilli(from);
this.queryTo = toEpochMilli(to);
}

/**
* Creates a <b>Precedes</b> instance with the give time-interval.
*
* @param from The beginning of the interval to match in milliseconds since Unix Epoch.
* @param to The end of the interval to match in milliseconds since Unix Epoch.
*/
public Precedes(long from, long to) {
this.queryFrom = from;
this.queryTo = to;
}

@Override
public boolean test(long from, long to) {
return from <= queryFrom && to <= queryFrom;
}

@Override
public String toString() {
return String.format("PRECEDES (%d, %d)", queryFrom, queryTo);
}
}
Loading

0 comments on commit c5cbb03

Please sign in to comment.