/* EVERYTHING WHAT CAN BE REPRESENTED IN FLORA IS NOT IN COMMENTS namespace default:http://www.wsmo.org/2004/d3/d3.2/v0.1/dateAndTime.wsml# xsd:http://something.w3c.org/withXSD# ontology http://www.wsmo.org/2004/d3/d3.2/v0.1/dateAndTime.wsml non-functional-properties title "Date and Time Ontology" creator "Holger Lausen" version "$Version$" description "The main ontologies taken into consideration for developing this representation in F-Logic: An entry sub-ontology of time: http://www.isi.edu/~pan/damltime/time-entry.owl This ontology uses abstract temporal concepts like instant, interval and event and uses the Gregorian calendar as representation (partly using own encoding and partly using XSD encoding). Axioms are defined in the accompanying paper (in first order logic.) and there is also a LISP version of these axioms available at: http://www.cs.rochester.edu/~ferguson/daml/daml-time-20030728.lisp Other ontologies like COBRA calenderclock ontology (http://daml.umbc.edu/ontologies/cobra/0.4/calendarclock) are only a straight forward representation of the Gregorian calendar, without any abstraction of concepts and description of axioms. Widely used concrete representations are defined in ISO 8601 (Numeric representation of Dates and Time) and in the XML Schema Definition (http://www.w3.org/TR/xmlschema-2/), which is based on ISO 8601. This ontology uses the Gregorian calendar (representation based on the definition in http://www.w3.org/TR/xmlschema-2/" concept instant non-functional-properties description "An instant represents a particular point in time [1]" */ instant[ ]. /* concept interval non-functional-properties description "An interval represents a duration between 2 points in time [1]" start oftype instant end oftype instant */ interval[ start=>instant, end=>instant ]. /* concept date non-functional-properties title "Date Class" description "conceptdefintion for the class date and its representation according to the Gregorian calendar" dayOfMonth oftype dayOfMonth monthOfYear oftype monthOfYear year oftype year */ date[ dayOfMonth=>dayOfMonth, monthOfYear=>monthOfYear, year=>year ]. /* axiom axiomValidDate non-functional-properties totöe "Axiom for a valid date" description "A date is valid if the day, month and year are valiud, leap years and checks on days (28/29/30) are not yet done" definedBy invalid(X) :- X oftype data AND (invalid(X.dayOfMonth) OR invalid(X.monthOfYear) OR invalid(X.year)) //michael you may skip the "axiomValidDate" thing, this is a necessary flora hack in order to identify what axiom is violated */ invalid(X,"axiomValidDate") :- X:date, (invalid(X.dayOfMonth); invlaid(X.monthOfYear); invalid(X.year) ). /* concept dayOfMonth subClassOf integer non-functional-properties title "Day of the Month" */ dayOfMonth::integer. //integrety constraint for valid dayOfMonths: invalid(X,"invalid dayOfMonth") :- X:dayOfMonth, (X<0; X>31). //a year is represented by an integer year::integer. //a monthOfYear is represented by an integer //and has additional properties, concrete month are defined as instances //acording to this class definition: monthOfYear::integer[ name=>string, daysAfterBeginOfYear=>integer ]. //integrety constraint for valid monthOfYear: invalid(X, "monthOfYear"):- X:monthOfYear, (X<0; X>12). /* instance 1 non-functional-properties description "describing a particulat month of a year" daysAfterBeginOfYear hasValue 31 name hasValue "January" */ 1:monthOfYear[daysAfterBeginOfYear->31, name-> 'January']. 2:monthOfYear[daysAfterBeginOfYear->59, name-> 'February']. 3:monthOfYear[daysAfterBeginOfYear->90, name-> 'March']. 4:monthOfYear[daysAfterBeginOfYear->120, name-> 'April']. 5:monthOfYear[daysAfterBeginOfYear->151, name-> 'May']. 6:monthOfYear[daysAfterBeginOfYear->181, name-> 'June']. 7:monthOfYear[daysAfterBeginOfYear->212, name-> 'July']. 8:monthOfYear[daysAfterBeginOfYear->243, name-> 'August']. 9:monthOfYear[daysAfterBeginOfYear->273, name-> 'September']. 10:monthOfYear[daysAfterBeginOfYear->304, name-> 'October']. 11:monthOfYear[daysAfterBeginOfYear->334, name-> 'November']. 12:monthOfYear[daysAfterBeginOfYear->365, name-> 'December']. //conceptdefintion of the time class time[ hourOfDay=>hourOfDay, minuteOfHour=>minuteOfHour, secondOfMinute=>secondOfMinute ]. //integrety constraint for valid time: invalid(X, "invalidTime") :- X:time, (invalid(X.hourOfDay); invalid(X.minuteOfHour); invalid(X.secondOfMinute)). //a secondOfMinute is represented by an integer secondOfMinute::integer. //integrety constraint for valid secondOfMinute: invalid(X,"invalidsecondOfMinute") :- X:secondOfMinute, (X<0; X>59). //a minuteOfHour is represented by an integer minuteOfHour::integer. //integrety constraint for valid minuteOfHour: invalid(X,"invalidminuteOfHour") :- X:minuteOfHour, (X<0; X>59). //a hourOfDay is represented by an integer hourOfDay::integer. //integrety constraint for valid hourOfDay: invalid(X,"invalidhourOfDay") :- X:hourOfDay, (X<0; X>23). //conceptdefintion of the date and time class //this represents together a specific point of time (instant) dateAndTime::instant[ date=>date, time=>time ]. //integrety constraint for valid dateAndTimes: invalid(X) :- X:dateAndTime, (invalid(X.date); invalid(X.time)). // computes equality of a date equal(X,Y) :- Y:date, X:date, X.dayOfMonth = Y.dayOfMonth, X.monthOfYear = Y.monthOfYear, X.year = Y.year. // computes if a given date X is before another date Y before(X, Y) :- Y:date, X:date, ((X.dayOfMonth < Y.dayOfMonth, X.monthOfYear = Y.monthOfYear, X.year = Y.year); (X.monthOfYear < Y.monthOfYear, X.year = Y.year); (X.year < Y.year)). // computes if a given date X is after another date Y after(X, Y) :- Y:date, X:date, ((X.dayOfMonth > Y.dayOfMonth, X.monthOfYear = Y.monthOfYear, X.year = Y.year); (X.monthOfYear > Y.monthOfYear, X.year = Y.year); (X.year > Y.year)). // this is simplified and ignores leap years a proper algorithm as // e.g. found at http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html // calulates correctly for Gregorian Calendar dates (after 1582 // (at keast for most countries, see // http://members.brabant.chello.nl/~h.reints/cal/whenjul2greg.htm // for an exact dates per country (e.g. Yugoslavia changed 1919))) // can be represented in f-logic as follows: julianDayNumber(X,JDN) :- X:date, X.monthOfYear<3, Y is X.year-1, M is X.monthOfYear+12, D is X.dayOfMonth, A is '//'(Y,100)@prolog(), B is '//'(A,4)@prolog(), C is 2-A+B, E is floor(365.25*(Y+4716))@prolog(), F is floor(30.6001*(M+1))@prolog(), JDN is C+D+E+F-1524. julianDayNumber(X,JDN) :- X:date, X.monthOfYear>2, Y is X.year, M is X.monthOfYear, D is X.dayOfMonth, A is '//'(Y,100)@prolog(), B is '//'(A,4)@prolog(), C is 2-A+B, E is floor(365.25*(Y+4716))@prolog(), F is floor(30.6001*(M+1))@prolog(), JDN is C+D+E+F-1524. // however due to a bug in XSB (float number arithemtics do not work proper) // this could not be implemented and a simplified version that aproximates the days // after Christ is used. daysAfterChrist(D,X) :- D:date, Z is D.monthOfYear, X is (D.dayOfMonth + Z.daysAfterBeginOfYear + (D.year*365)). //the difference in days between 2 dates daysBetween(D1,D2,X) :- D1:date, D2:date, daysAfterChrist(D1,DAC_D1), daysAfterChrist(D2,DAC_D2), X is DAC_D1 - DAC_D2. // computes if two given times are the same equal(X,Y) :- X:time, Y:time, X.secondOfMinute = Y.secondOfMinute, X.minuteOfHour = Y.minuteOfHour, X.hourOfDay = Y.hourOfDay. // computes if a given time X is before another time Y before(X,Y) :- X:time, Y:time, ((X.secondOfMinute < Y.secondOfMinute, X.minuteOfHour = Y.minuteOfHour, X.hourOfDay = Y.hourOfDay); (X.minuteOfHour < Y.minuteOfHour, X.hourOfDay = Y.hourOfDay); (X.hourOfDay < Y.hourOfDay)). // computes if a given time X is after another time Y after(X,Y) :- X:time, Y:time, ((X.secondOfMinute > Y.secondOfMinute, X.minuteOfhour = Y.minuteOfhour, X.hourOfDay = Y.hourOfDay); (X.minuteOfhour > Y.minuteOfhour, X.hourOfDay = Y.hourOfDay); (X.hourOfDay > Y.hourOfDay)). //computes the amount of seconds from midnight secondsFromMidnight(T,X) :- T:time, X is T.secondOfMinute + (T.minuteOfHour*60) + (T.hourOfDay*60*60). //the difference in seconds between 2 times secondsBetween(T1, T2, X) :- T1:time, T2:time, secondsFromMidnight(T1,SFM_T1), secondsFromMidnight(T2,SFM_T2), X is SFM_T1 - SFM_T2. //computes if Date and Time are equal equal(X,Y) :- X:dateAndTime, Y:dateAndTime, equal(X.date,Y.date), equal(X.time,Y.time). //computes if a given date and time X is before another date and time Y before(X,Y) :- X:dateAndTime, Y:dateAndTime, ((equal(X.date,Y.date), before(X.time,Y.time)); before(X.date,Y.date)). //computes if a given date and time X is after another date and time Y after(X,Y) :- X:dateAndTime, Y:dateAndTime, ((equal(X.date,Y.date), after(X.time,Y.time)); after(X.date,Y.date)). //computes the difference in seconds between two different DateAndTime secondsBetween(D1, D2, X) :- D1:dateAndTime, D2:dateAndTime, daysAfterChrist(D1.date,DAC_D1), daysAfterChrist(D2.date,DAC_D2), secondsFromMidnight(D1.time,SFM_T1), secondsFromMidnight(D2.time,SFM_T2), X is SFM_T1 + DAC_D1 * 24 * 60 * 60 - (SFM_T2 + DAC_D2 * 24 * 60 * 60). //the difference in (decimal) days between two different DateAndTime daysBetween(D1, D2, X) :- D1:dateAndTime, D2:dateAndTime, secondsBetween(D1,D2,Z), X is Z/60/60/24. //#################STUFF FOR intervall###################### //computes if a interval X contains a second interval Y contains(X,Y) :- X:interval, Y:interval, (before(X.start, Y.start);equal(X.start, Y.start)), (after(X.end, Y.end);equal(X.end, Y.end)). //computes if a interval X contains a instant Y contains(X,Y) :- X:interval, Y:instant, (before(X.start, Y);equal(X.start, Y)), (after(X.end, Y);equal(X.end, Y)). // REFERENCES // [1] F. Pan and R. Hobbs: Time in OWL-S, avaliable at: http://www.isi.edu/~pan/damltime/AAAIsymp2004.pdf //test instance: //The current Date manually since we do not have build in function yet currentDate:dateAndTime[ date->date1:date[dayOfMonth->28,monthOfYear->2,year->2001], time->time1:time[hourOfDay->23,minuteOfHour->40,secondOfMinute->12] ]. currentDate2:dateAndTime[ date->date2:date[dayOfMonth->29,monthOfYear->2,year->2001], time->time2:time[hourOfDay->23,minuteOfHour->40,secondOfMinute->00] ]. currentDate3:dateAndTime[ date->date3:date[dayOfMonth->1,monthOfYear->3,year->2001], time->time3:time[hourOfDay->22,minuteOfHour->40,secondOfMinute->00] ]. currentDate4:dateAndTime[ date->date4:date[dayOfMonth->2,monthOfYear->3,year->2001], time->time4:time[hourOfDay->23,minuteOfHour->40,secondOfMinute->12] ]. int1:interval[ start->currentDate, end->currentDate4 ]. int2:interval[ start->currentDate2, end->currentDate3 ].