Skip to content

Commit 36f038e

Browse files
committed
Add Allen temporal interval relationship matcher and generator
1 parent 24acafe commit 36f038e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

terminusdb_client/woqlquery/woql_query.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,6 +2399,45 @@ def month_end_dates(self, date, start, end):
23992399
self._cursor["end"] = self._clean_object(end)
24002400
return self
24012401

2402+
def interval_relation(self, relation, x_start, x_end, y_start, y_end):
2403+
"""Allen's Interval Algebra: classifies or validates the relationship
2404+
between two half-open intervals [x_start, x_end) and [y_start, y_end).
2405+
2406+
When relation is a string, validates that the named relation holds.
2407+
When relation is a variable, classifies which of the 13 Allen
2408+
relations holds (deterministic).
2409+
2410+
Parameters
2411+
----------
2412+
relation : str or dict
2413+
relation name (e.g. "before") or variable for classification
2414+
x_start : str or dict
2415+
inclusive start of interval X
2416+
x_end : str or dict
2417+
exclusive end of interval X
2418+
y_start : str or dict
2419+
inclusive start of interval Y
2420+
y_end : str or dict
2421+
exclusive end of interval Y
2422+
2423+
Returns
2424+
-------
2425+
WOQLQuery object
2426+
query object that can be chained and/or execute
2427+
"""
2428+
if (relation is None or x_start is None or x_end is None
2429+
or y_start is None or y_end is None):
2430+
raise ValueError("IntervalRelation takes five parameters")
2431+
if self._cursor.get("@type"):
2432+
self._wrap_cursor_with_and()
2433+
self._cursor["@type"] = "IntervalRelation"
2434+
self._cursor["relation"] = self._clean_object(relation)
2435+
self._cursor["x_start"] = self._clean_object(x_start)
2436+
self._cursor["x_end"] = self._clean_object(x_end)
2437+
self._cursor["y_start"] = self._clean_object(y_start)
2438+
self._cursor["y_end"] = self._clean_object(y_end)
2439+
return self
2440+
24022441
def opt(self, query=None):
24032442
"""The Query in the Optional argument is specified as optional
24042443

0 commit comments

Comments
 (0)