% % This program implements a temporal reasoner based on the axioms % defined in "A DAML Ontology of Time" by Jerry R. Hobbs [1]. % % The representation of time is grounded in terms of "instant" and % "interval". Both instant and interval are type of "temporal % entity". In this implementation, temporal entities are structured % as Prolog lists, and time values are described in ISO 8601 Date and % Time Formats [2]. % % For an instant, it's list representation are assumed to hold a single % elmement. For an interval, it's list representation are assumed to % hold two elements, the begining instant and the ending instant of an % interval. Elements in a list are assumed to be single-quoted % (i.e. ') date time description in the ISO 8601 format. For example, % % an instant: ['2003-12-25T20:00:30'], % an interval: ['2003-01-02T00:00:00Z','2003-12-21T00:00:30Z']. % % [1] http://www.cs.rochester.edu/~ferguson/daml/daml-time-nov2002.txt % [2] http://www.w3.org/TR/xmlschema-2 % % This program defines the following predicates: % % 1) instant(+TL) % 2) interval(+TL) % 3) begins(?BL,+TL) % 4) ends(?BL,+TL) % 5) before(+XL,+YL) % 6) after(+XL,+YL) % 7) inside(+IL,+VL) % 8) proper_interval(+VL) % 9) begins_or_in(+IL,+VL) % 10) time_between(+VL,+IL1,+IL2) % 12) int_equals(+VL1,+VL2) % 13) int_before(+VL1,+VL2) % 14) int_meets(+VL1,+VL2) % 15) int_met_by(+VL1,+VL2) % 16) int_overlaps(+VL1,+VL2) % 17) int_overlapped_by(+VL1,+VL2) % 18) int_starts(+VL1,+VL2) % 19) int_started_by(+VL1,+VL2) % 20) int_during(+VL1,+VL2) % 21) int_contains(+VL1,+VL2) % 22) int_finishes(+VL1,+VL2) % 23) int_finished_by(+VL1,+VL2) % 24) starts_or_during(+VL1,+VL2) % 25) nonoverlap(+VL1,+VL2) % % License & documentation: http://cobra.umbc.edu/time/ % % author: Harry Chen (harry.chen@umbc.edu, http://umbc.edu/~hchen4/) % % cvs: $Revision: 1.3 $, $Date: 2003/12/11 00:03:10 $ % :- ensure_loaded('time_util'). % % t_instant(+TL) % instant(TL) :- is_list(TL), length(TL,1), nth1(1,TL,M), dt_is_well_formed(M). % % t_interval(+TL) % interval(TL) :- is_list(TL), length(TL,2), nth1(1,TL,B), nth1(2,TL,E), dt_is_well_formed(B), dt_is_well_formed(E). % % begins(?BL,+TL) % begins(BL,TL) :- instant(TL), nth1(1,TL,M), BL = [M]. begins(BL,TL) :- interval(TL), nth1(1,TL,M), BL = [M]. % % ends(?EL,+TL) % ends(EL,TL) :- instant(TL), nth1(1,TL,M), EL = [M]. ends(EL,TL) :- interval(TL), nth1(2,TL,M), EL = [M]. % % before(+XL,+YL) % before(XL,YL) :- ends(EoXL,XL), begins(BoYL,YL), nth1(1,EoXL,EoX), nth1(1,BoYL,BoY), dt_before(EoX,BoY). % % after(+XL,+YL) % after(XL,YL) :- before(YL,XL). % % inside(+IL,+VL) % inside(IL,VL) :- instant(IL), interval(VL), begins(BL,VL), ends(EL,VL), before(BL,IL), before(IL,EL). proper_interval(VL) :- interval(VL), begins(BL,VL), ends(EL,VL), before(BL,EL). begins_or_in(IL,VL) :- instant(IL), interval(VL), (begins(IL,VL); inside(IL,VL)). time_between(VL,IL1,IL2) :- interval(VL), instant(IL1), instant(IL2), begins(IL1,VL), ends(IL2,VL). % % T1: B______E % T2: B______E % int_equals(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), begins(B,VL1), begins(B,VL2), ends(E,VL1), ends(E,VL2). % % T1: B______E % T2: B_____E % int_before(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), before(VL1,VL2). int_after(VL1,VL2) :- int_before(VL2,VL1). % % T1: <______X % T2: X_______> % int_meets(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), ends(X,VL1), begins(X,VL2). int_met_by(VL1,VL2) :- int_meets(VL2,VL1). % % T1: X1______X2 % T2: X3_______X4 % int_overlaps(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), begins(X1,VL1), ends(X2,VL1), begins(X3,VL2), ends(X4,VL2), before(X3,X2), before(X1,X3), before(X2,X4). int_overlapped_by(VL1,VL2) :- int_overlaps(VL2,VL1). % % T1: X1____X2 % T2: X1___________X3 % int_starts(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), begins(X1,VL1), ends(X2,VL1), begins(X1,VL2), ends(X3,VL2), before(X2,X3). int_started_by(VL1,VL2) :- int_starts(VL2,VL1). % % T1: X1_______X2 % T2: X3_____________X4 % int_during(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), begins(X1,VL1), ends(X2,VL1), begins(X3,VL2), ends(X4,VL2), before(X3,X1), after(X4,X2). int_contains(VL1,VL2) :- int_during(VL2,VL1). % % T1: X1________X2 % T2: X3_____________X2 % int_finishes(VL1,VL2) :- proper_interval(VL1), proper_interval(VL2), begins(X1,VL1), ends(X2,VL1), begins(X3,VL2), ends(X2,VL2), before(X3,X1). int_finished_by(VL1,VL2) :- int_finishes(VL2,VL1). % % T1: <_____> % T2: <____________> % % or % % T1: <_____> % T2: <____________> % starts_or_during(VL1,VL2) :- int_starts(VL1,VL2); int_during(VL1,VL2). % % T1: <___> % T2: <___> % % or % % T1: <___> % T2: <___> % % or % % T1: <___> % T2: <____> % % or % % T1: <___> % T2: <____> % nonoverlap(VL1,VL2) :- int_before(VL1,VL2); int_after(VL1,VL2); int_meets(VL1,VL2); int_met_by(VL1,VL2).