(In-Package "ONTOLINGUA-USER")

;;; Written by user Rse from session "hacking2" owned by group JUST-ME
;;; Date: Oct 27, 1995  15:23


(Define-Ontology
     Simple-Time
     (Frame-Ontology Slot-Constraint-Sugar ranges)
   " A TIME-POINT is a specification of a single point in historical time. CALENDAR-DATE is a time-point at the resolution of days; that is, the day, month, and year are known.  A CALENDAR-YEAR is a time-point at the resolution of years. "
   :Io-Package
   "ONTOLINGUA-USER"
   :Generality
   :high
   :maturity :moderate
   :Issues
   ("Extracted from Bibliographic-Data, October 24, 1995."))


(In-Ontology (Quote Simple-Time))




;;; ------------------ Classes --------------

;;; Calendar-Date

(Define-Class Calendar-Date
              (?T)
              "a specification of a point in absolute calendar time, at the 
resolution of one day."
              :Def
              (And (Time-Point ?T)
               (Has-One ?T Day-of)
               (Has-One ?T Month-of)
               (Has-One ?T Year-of)))


;;; Calendar-Year

(Define-Class Calendar-Year
              (?T)
              "a specification of a point in absolute calendar time, at the 
resolution of one year."
              :Def
              (And (Time-Point ?T)
		   (Has-One ?T Year-of)))


;;; Day-Number

(define-class DAY-NAME (?day)
    "DAY-NAME denotes a name of a day of a week."
    :iff-def (member ?day
		     (setof sunday monday tuesday wednesday thursday
			    friday saturday))
)

(define-instance sunday (day-name))
(define-instance monday (day-name))
(define-instance tuesday (day-name))
(define-instance wednesday (day-name))
(define-instance thursday (day-name))
(define-instance friday (day-name))
(define-instance saturday (day-name))

;;; Month-Name

(Define-Class Month-Name
              (?Month)
              "The months of the year, specified as an extensionally-defined
 (i.e., enumerated) set of objects, in English.
  Instances of this class of months are not symbols, they are months
that may be denoted by object constants."
              :Iff-Def
              (Member ?Month
               (Setof January February March April May June July August
                September October November December))
              :Issues
              (("Why not specify them as an ordered sequence?"
                "The class only defines the set of months.  Their order would
             be given by an ordering predicate: a binary relation.")))




;;; Time-Point

(Define-Frame Time-Point
              :Own-Slots
              ((Arity 1)
               (Documentation
                "A time-point is a point in real, historical time (on earth).  
It is independent of observer and context.  A time-point is not
a measurement of time, nor is it a specification of time.
It is the point in time. The time-points at which events occur can 
be known with various degrees of precision and approximation,
but conceptually time-points are point-like and not interval-like.
That is, it doesn't make sense to talk about what happens during
a time-point, or how long the time-point lasts.")
               (Domain-Of Day-of Minutes-of Month-of Seconds-of Year-of)
               (Instance-Of Class) (Subclass-Of individual)))




(define-relation EQUALS (?time-point-1 ?time-point-2)
  " a time point ?time-point-1 is equal to a time point ?time-point-2.
    a time range ?time-range-1 is identical to a time range ?time-range-2."
  :axiom-def
  ((=> (and (time-point ?time-point-1) (time-point ?time-point-2))
       (<=> (equals ?time-point-1 ?time-point-2)
	    (and (= (year-of ?time-point-1) (year-of ?time-point-2))
		 (= (month-of ?time-point-1) (month-of ?time-point-2))
		 (= (day-of ?time-point-1) (day-of ?time-point-2))
		 (= (hour-of ?time-point-1) (hour-of ?time-point-2))
		 (= (minute-of ?time-point-1) (minute-of ?time-point-2))
		 (= (second-of ?time-point-1) (second-of ?time-point-2)))))
   (=> (and (time-range ?time-range-1) (time-range ?time-range-2))
       (<=> (EQUALS ?time-range-1 ?time-range-2)
	    (and (equals (START-TIME-OF ?time-range-1)
			 (START-TIME-OF ?time-range-2))
		 (equals (end-time-of ?time-range-1)
			 (end-time-of ?time-range-2)))))))

(define-relation < (?time-point-1 ?time-point-2)
  "a time point ?time-point-1 preceeds a time point ?time-point-2."
  :axiom-def
  (=> (and (time-point ?time-point-1) (time-point ?time-point-2))
      (<=> (< ?time-point-1 ?time-point-2)
	   (or (< (year-of ?time-point-1)
		  (year-of ?time-point-2))
	       (and (= (year-of ?time-point-1)
		       (year-of ?time-point-2))
		    (or (< (month-of ?time-point-1)
			   (month-of ?time-point-2))
			(and (= (month-of ?time-point-1)
				(month-of ?time-point-2))
			     (or (< (day-of ?time-point-1)
				    (day-of ?time-point-2))
				 (and (= (day-of ?time-point-1)
					 (day-of ?time-point-2))
				      (or (< (hour-of ?time-point-1)
					     (hour-of ?time-point-2))
					  (and (= (hour-of ?time-point-1)
						  (hour-of ?time-point-2))
					       (or (< (minute-of ?time-point-1)
						      (minute-of ?time-point-2))
						   (and (= (minute-of
							    ?time-point-1)
							   (minute-of
							    ?time-point-2))
							(or (< (second-of
								?time-point-1)
							       (second-of
								?time-point-2
								))))))))))))))))



(define-relation > (?time-point-1 ?time-point-2)
  "a time point ?time-point-1 preceeds a time point ?time-point-2."
  :axiom-def
  (=> (and (time-point ?time-point-1) (time-point ?time-point-2))
      (<=> (> ?time-point-1 ?time-point-2)
	   (< ?time-point-2 ?time-point-1))))


(define-function MONTH-NAME-of (?time-point) :-> ?month
    "MONTH-OF-NAME denotes a name of a month of a time point."
    :def (and (time-point ?time-point)
	      (month-name ?month))
)

(define-function DAY-of (?time-point) :-> ?day
    "DAY-OF denotes a day of a time point."
    :def (and (time-point ?time-point)
	      (day-number ?day))
)

(define-function DAY-NAME-of (?time-point) :-> ?day
    "DAY-NAME-of denotes a name of a day of a time point."
    :def (and (time-point ?time-point)
	      (day-name ?day))
)

(define-function HOUR-of (?time-point) :-> ?hour
    "HOUR-OF denotes an hour of a time point."
    :def (and (time-point ?time-point)
	      (hour-number ?hour))
)

(define-function MINUTE-of (?time-point) :-> ?minute
    "MINUTE-OF denotes a minute of a time point."
    :def (and (time-point ?time-point)
	      (minute-number ?minute))
)

(define-function SECOND-of (?time-point) :-> ?second
    "TIME-SECOND denotes a second of a time point."	      
    :def (and (time-point ?time-point)
	      (second-number ?second))
)
		      
(define-function UNIT-of (?time-point) :-> ?unit
    "TIME-UNIT denotes a unit of a time point."
    :def (and (time-point ?time-point)
	      (duration ?unit))
)


;;; Year-Number

(Define-Class Year-Number
              (?Year)
              "A year expressed as the number of years A.D."
              :Def
              (Integer ?Year))



;;; ------------------ Relations --------------


;;; ------------------ Functions --------------

;;; Day

;;; Minutes

(Define-Function Minutes-of
                 (?Time-Point)
                 :->
                 ?Minutes
                 "function from time points to integers representing the minutes
component of the time specification."
                 :Def
                 (And (Time-Point ?Time-Point) (Integer ?Minutes)
                  (=< 0 ?Minutes) (=< ?Minutes 59)))


;;; Month

(Define-Function Month-of
                 (?Time-Point)
                 :->
                 ?Month
                 "function from time points to months, representing the month component of
the time specification.  Months are not integers, but named objects."
                 :Def
                 (And (Time-Point ?Time-Point) (Month-Name ?Month)))


;;; Seconds

(Define-Function Seconds-of
                 (?Time-Point)
                 :->
                 ?Seconds
                 "function from time points to integers representing the seconds component of
the time specification.  This is not the internal representation of the
universal time, (e.g., number seconds since some historical date).
seconds is the number of seconds past the minute, hour, day, etc.
specified in the other components of the "
                 :Def
                 (And (Time-Point ?Time-Point) (Integer ?Seconds)
                  (=< 0 ?Seconds) (=< ?Seconds 59)))


;;; Year

(Define-Function Year-of
                 (?Time-Point)
                 :->
                 ?Year
                 "function from time points to integers representing the year
component of the time specification.  The integer represents
the number of years A.D., e.g., 1992."
                 :Def
                 (And (Time-Point ?Time-Point) (Year-Number ?Year)))



(define-class MONTH-NUMBER (?month)
    "MONTH-NUMBER deontes a month of a year."
    :axiom-def (and (integer-range month-number)
		    (= (i-lower-bound month-number) 1)
		    (= (i-upper-bound month-number) 12))
)

(define-class DAY-NUMBER (?day)
    "DAY-NUMBER denotes a day of a month."
    :axiom-def (and (integer-range day-number)
		    (= (i-lower-bound day-number) 1)
		    (= (i-upper-bound day-number) 31))
)

(define-class HOUR-NUMBER (?hour)
    "HOUR-NUMBER denotes an hour of a day."
    :axiom-def (and (integer-range hour-number)
		    (= (i-lower-bound hour-number) 0)
		    (= (i-upper-bound hour-number) 23))
)

(define-class MINUTE-NUMBER (?minute)
    "MINUTE-NUMBER denotes a minute of a hour."
    :axiom-def (and (integer-range minute-number)
		    (= (i-lower-bound minute-number) 0)
		    (= (i-upper-bound minute-number) 59))
)

(define-class SECOND-NUMBER (?second)
    "SECOND-NUMBER denotes a second of a minute."
    :axiom-def (and (real-range second-number)
		    (= (r-lower-bound second-number) 0)
		    (= (r-upper-bound second-number) 59))
)


;;; ------------------ Instance --------------

;;; April

(Define-Instance April (Month-Name))


;;; August

(Define-Instance August (Month-Name))


;;; December

(Define-Instance December (Month-Name))


;;; February

(Define-Instance February (Month-Name))


;;; January

(Define-Instance January (Month-Name))


;;; July

(Define-Instance July (Month-Name))


;;; June

(Define-Instance June (Month-Name))


;;; March

(Define-Instance March (Month-Name))


;;; May

(Define-Instance May (Month-Name))


;;; November

(Define-Instance November (Month-Name))


;;; October

(Define-Instance October (Month-Name))


;;; September

(Define-Instance September (Month-Name))



;;; ------------------ Axiom --------------


;;; ------------------ Other --------------


(define-class TIME-RANGE (?time-range) 
    "TIME-RANGE denotes a certain period of time. It consists of a
start time, an end time. A start time must proceed an end time.
Relations between TIME-RANGEs are defined after James Allen's interval
relations."
    :def (individual ?time-range)
    :constraints (equals  (+ (START-TIME-OF ?time-range)
			    (duration-of ?time-range))
		       (end-time-of ?time-range))
)

(define-function START-TIME-OF (?time-range) :-> ?time-point
    "(START-TIME-OF 'tr) denotes a start time of a time range tr."
    :def (and (time-range ?time-range)
	      (time-point ?time-point))
)

(define-function END-TIME-OF (?time-range) :-> ?time-point
    "(END-TIME-OF 'tr) denotes an end time of a time range tr."
    :def (and (time-range ?time-range)
	      (time-point ?time-point))
)

(define-function DURATION-OF (?time-range) :-> ?duration
    "(DURATION-OF 'tr) denotes a duration of a time range tr."
    :def (and (time-range ?time-range)
	      (duration ?duration))
)

(define-relation BEFORE (?time-range-1 ?time-range-2)
    "a time range ?time-range-1 preceeds a time ranage ?time-range-2."
  :iff-def (< (end-time-of ?time-range-1)
		  (START-TIME-OF ?time-range-2))
)

(define-relation AFTER (?time-range-1 ?time-range-2)
    "a time range ?time-range-1 succeeds a time range ?time-range-2."
    :iff-def (< (end-time-of ?time-range-2)
		  (START-TIME-OF ?time-range-1))
    :equivalent (before ?time-range-2 ?time-range-1)
)

(define-relation MEETS (?time-range-1 ?time-range-2)
    "a time range ?time-range-1 ends at the same time a time range
     ?time-range-2 starts."
    :iff-def (equals (end-time-of ?time-range-1)
		  (START-TIME-OF ?time-range-2))
)		 



(define-relation DURING (?time-range-1 ?time-range-2)
  "a time range ?time-range-1 is properly included in a time range
   ?time-range-2."
  :iff-def (and (> (START-TIME-OF ?time-range-1)
		   (START-TIME-OF ?time-range-2))
		(< (end-time-of ?time-range-1)
		   (end-time-of ?time-range-2)))
)

(define-relation OVERLAPS (?time-range-1 ?time-range-2)
    "a time range ?time-range-1 and a time range ?time-range-2 overlaps."
    :iff-def (and (< (START-TIME-OF ?time-range-1)
		     (START-TIME-OF ?time-range-2))
		  (< (START-TIME-OF ?time-range-2)
		     (end-time-of ?time-range-1))
		  (< (end-time-of ?time-range-1)
		     (end-time-of ?time-range-2)))
)

(define-relation STARTS (?time-range-1 ?time-range-2)
    "a time range ?time-range-1 and a time range ?time-range-2 starts at the
     same time and a duration of ?time-range-1 is shorter than that of
     ?time-range-2."
    :iff-def (and (equals (START-TIME-OF ?time-range-1)
		       (START-TIME-OF ?time-range-2))
		  (< (end-time-of ?time-range-1)
		     (end-time-of ?time-range-2)))
)

(define-relation FINISHES (?time-range-1 ?time-range-2)
    "a time range ?time-range-1 and a time range ?time-range-2 ends at the
     same time and a duration of ?time-range-1 is shorter than that of
     ?time-range-2."
    :iff-def (and (> (START-TIME-OF ?time-range-1)
		     (START-TIME-OF ?time-range-2))
		  (equals (end-time-of ?time-range-1)
			  (end-time-of ?time-range-2)))
)

(define-relation BEFORE= (?time-range-1 ?time-range-2)
    :iff-def (or (before ?time-range-1 ?time-range-2)
		 (meets ?time-range-1 ?time-range-2))
)

(define-relation AFTER= (?time-range-1 ?time-range-2)
    :iff-def (or (after ?time-range-1 ?time-range-2)
		 (meets ?time-range-2 ?time-range-1))
)

(define-relation DURING= (?time-range-1 ?time-range-2)
    :iff-def (or (during ?time-range-1 ?time-range-2)
		 (starts ?time-range-1 ?time-range-2)
		 (finishes ?time-range-1 ?time-range-2)
		 (equals ?time-range-1 ?time-range-2))
)

(define-relation OVERLAPS= (?time-range-1 ?time-range-2)
    :iff-def (or (overlaps ?time-range-1 ?time-range-2)
		 (meets ?time-range-1 ?time-range-2))
)

(define-relation START= (?time-range-1 ?time-range-2)
    :iff-def (or (starts ?time-range-1 ?time-range-2)
		 (equals ?time-range-1 ?time-range-2))
)

(define-relation FINISHES= (?time-range-1 ?time-range-2)
    :iff-def (or (finishes ?time-range-1 ?time-range-2)
		 (equals ?time-range-1 ?time-range-2))
)

(define-relation DISJOINT-TIME-RANGES (?time-range-1 ?time-range-2)
    "time ranges ?time-range-1 and ?time-range-2 do not overlap"
    :iff-def (or (before ?time-range-1 ?time-range-2)
		 (before ?time-range-2 ?time-range-1)))

(define-function + (?time-range-1 ?duration) :-> ?time-range-2
    "+ denotes a time range ?time-range-2 whose length is longer
     that ?time-range-1 by a duration ?duration.
     A difference between two time points ?time-point-1 and ?time-point-2 is a
     duration ?duration."
  :axiom-def
  ((=> (and (time-range ?time-range-1)
	     (duration ?duration))
	(<=> (= (+ ?time-range-1 ?duration) ?time-range-2)
	     (and (= (START-TIME-OF ?time-range-1)
		     (START-TIME-OF ?time-range-2))
		  (= (+ (end-time-of ?time-range-1) ?duration)
		     (end-time-of ?time-range-2)))))
   (=> (and (time-point ?time-range-1)
	   (duration ?duration))
      (=> (= (+ ?time-point-1 ?duration) ?time-point-2)
	  (and (time-point ?time-point-1)
	       (duration ?duration)
	       (time-point ?time-point-2))))
   (=> (and (duration ?duration-1) (duration ?duration-2))
       (=> (= (+ ?duration-1 ?duration-2) ?duration-3)
	   (duration ?duration-3)))))


;==============================================================================


(define-class DURATION (?duration)
    "DURATION denotes a period of time. It consists of a value and a
     measure"
    :def (individual ?duration))

(define-function VALUE-OF (?duration) :-> ?value
    "VALUE-OF returns a length of a duration in a cetain measure."
    :def (and (duration ?duration)
	      (integer ?value)))

;;; Universal-Time-Spec

(Define-Class Universal-Time-Spec
              (?T)
  "a specification of a point in real-world, historical, wall-clock time,
   independent of timezone and with one second resolution."
              :Def (And (Time-Point ?T) (Has-One ?T seconds-of)
			(Has-One ?T minutes-of) (Has-One ?T day-of)
			(Has-One ?T month-of) (Has-One ?T year-of)))