<<

CaTTS: Types and Constraints for Web Applications

Franc¸ois Bry Frank-Andr´e Rieß Stephanie Spranger University of Munich, Germany University of Munich, Germany University of Munich, Germany [email protected]fi.lmu.de [email protected]fi.lmu.de [email protected]fi.lmu.de

ABSTRACT CaTTS Data referring to cultural such as the widespread CaTTS-DL Gregorian dates but also dates after the Chinese, Hebrew, or CaTTS-CL Islamic calendars as well as data referring to professional cal- CaTTS-TDL CaTTS-FDL endars like fiscal years or teaching terms are omnipresent on the Web. Formalisms such as XML Schema have acknowl- Figure 1: Languages of CATTS. edged this by offering a rather extensive set of Gregorian dates and as basic data types. This article introduces into CaTTS, the Calendar and Type System. CaTTS goes far beyond predefined date and time types after the This article introduces into CaTTS, the Calendar and as supported by XML Schema. CaTTS Time Type System that goes far beyond predefined date first gives rise to declaratively specify more or less complex and time types after the Gregorian calendar. CaTTS con- cultural or professional calendars including specificities such sists of two languages, a type definition language, CaTTS- as leap , leap years, and time zones. CaTTS fur- DL, and a constraint language, CaTTS-CL, of a (common) ther offers a tool for the static type checking (of data typed parser for both languages, and of a language processor for after calendar(s) defined in CaTTS). CaTTS finally offers each language. a language for declaratively expressing and a solver for effi- Using the (type) definition language CaTTS-DL, one can ciently solving temporal constraints (referring to calendar(s) specify in a rather simple manner more or less complex, expressed in CaTTS). CaTTS complements data modeling cultural or professional calendars [3]. Specificities like leap and reasoning methods designed for generic Semantic Web seconds, leap years, and time zones can be easily expressed applications such as RDF or OWL with methods specific to in CaTTS-DL. Calendars expressed in CaTTS-DL are com- the particular application domain of calendars and time. posable in the sense that the language offers a means for modules. Thus, one can extend a standard calendar such as Categories and Subject Descriptors the Gregorian calendar used in Germany with a particular I.2.4 [Artificial Intelligence]: Knowledge Representation teaching calendar, e.g. the one of a specific German univer- Formalisms and Methods—representation languages; D.3.1 sity. [Programming Languages]: Formal Definition and The- CaTTS-DL gives rise to defining both, calendric data types ory—syntax specific to a particular calendar – such as “working day”, “Easter Monday”, “exam week”, or “CS123 lecture” (defin- General Terms ing the times when the Computer Science lecture number Languages 123 takes place) – using the language fragment CaTTS- Keywords TDL (for Type Definition Language) of CaTTS-DL, and data formats for such data types – such as “5.10.2004”, time, calendars, types, Web reasoning “2004/10/05”, or “Tue Oct 5 16:39:36 CEST 2004” – using the language fragment CaTTS-FDL (for Format Definition 1. INTRODUCTION Language) of CaTTS-DL. Data referring to cultural calendars such as the widespread The language processor for CaTTS-DL consists of two Gregorian dates but also dates after the Chinese, Hebrew, software components, a static type checker and a predicate or Islamic calendars as well as data referring to professional interpreter. Consider a calendar C specified in CaTTS- calendars like fiscal years or teaching terms are omnipresent DL and a program P in the language CaTTS-CL, XQuery, on the Web. Most likely, they will play an essential role on XSLT or any other program P with type annotations re- the Semantic Web, too. Formalisms such as XML Schema ferring to types and/or formats specified in the calendar C. CaTTS’ static type checker verifies and/or extends the type have acknowledged this by offering a rather extensive set of Gregorian dates and times as basic data types. annotations in P generating a type checked version P of P : Copyright is held by the International World Wide Web Conference Com- mittee (IW3C2). Distribution of these papers is limited to classroom use, and personal use by others. WWW 2005, May 10-14, 2005, Chiba, Japan. ACM 1-59593-046-9/05/0005.

702

calendar C program P approach is a form of “theory reasoning” like “paramodula- @ @R © tion”. Like paramodulation ensures natural expressing and CaTTS’ static efficient processing of equality in resolution theorem proving, type checker CaTTS makes a user friendly expression and an efficient pro- cessing of calendric types and constraints possible. CaTTS ? type checked version P of P departs from time ontologies such as the DAML Ontology of Time [4] or time in OWL-S [10] as follows: Consider a type definition T (e.g. “working day” or “exam • CaTTS considerably simplifies the modeling of speci- week”) from a calendar specified in CaTTS-DL and a data ficities of cultural calendars (such as leap years, sun- item D (e.g. “2004/10/05”). CaTTS’ predicate interpreter based cycles like Gregorian years, or lunar-based cycles detects whether the data item D has type T (e.g. whether like Hebrew months), “2004/10/05” is a “working day” or an “exam week” - the later being probably false): • CaTTS provides both, a static type checker and type predicates for every CaTTS calendar(s) specification, type definition T data item D • CaTTS comes along with a constraint solver dedicated @ to calendar definitions that (1) processes CaTTS type @R predicate © annotations as constraints and (2) the language of whi- interpreter ch is amenable to CaTTS static type checking. ? yes/no 3. CATTS’ MODEL IN A NUTSHELL This section is a mathematical prologue that can be skipped Both CaTTS-DL and CaTTS-CL provide (the same) pre- in a first reading. defined functions (e.g. shift forward and backward, during, CaTTS’ notion of time is linear. CaTTS is not intended and usual arithmetics). Using these functions, one can ex- for expressing possible futures, hence it is not based on a press for example, “the day after working day X” (in “branching time”. Most common-sense, Web and Semantic CaTTS: shift X:working day forward 2 day). Web and many Web service application can be conveniently CaTTS’ type checker can be used for static type checking modeled in a linear time framework. of programs or specifications in any language (e.g. XQuery, CaTTS’ notion of time is purely interval-based, i.e. tem- XSLT, XML Schema), using date formats enriched with type poral data of every kind have a duration. This reflects a annotations after some calendar specified in CaTTS-DL. In widespread common-sense understanding of time according particular, it is used for the static type checking of temporal to which one mostly refer to time interval, not to time points. constraint programs in CaTTS-CL, the constraint language E.g. one refers to “2004/10/05”, a day, or to “1st week of Oc- of CaTTS. tober 2004”, a week. Even time point-like data such as 9:25 Using CaTTS’ constraint language CaTTS-CL, one can can be perceived as having a duration, possibly as small as express a wide range of temporal constraints referring to the one second or one millisecond. Considering only time inter- types defined in calendar(s) specified in the definition lan- vals and no time points has two advantages. First, it signif- guage CaTTS-DL. For example, if one specifies in CaTTS- icantly simplifies data modeling, an advantage for CaTTS’ DL a calendar defining both, the Gregorian calendar (with users. Second, it simplifies data processing, i.e. static type types such as “Easter Monday” or “holiday”) and the teach- checking and constraint reasoning, an advantage for CaTTS’ ing calendar of a given university (with types such as “work- language processors. However, CaTTS can deal with time ing day”, “CS123 lecture”, and “exam week”), then one can point-like data like the beginning of a week or whether a day refer in CaTTS-CL to “days that are neither holidays, nor d falls into a week w or not, as well. days within an examination week” and express constraints In order to formalize CaTTS (time point-less) model, how- on such days such as “strictly after Easter Monday and be- ever, time points have to be considered: fore June”. Thus, using CaTTS-CL one can express real-life, T Web, Semantic Web, and Web service related problems such Definition 1. A base time line is a pair ( ,

such as first-order logic theorem provers. discrete, i.e. isomorphic to . The notion of time granularity [2] formalizes such “discretizations” of the time line:

2. CATTS AND THE SEMANTIC WEB Definition 2. Let (T ,

{ }  CaTTS complements data modeling and reasoning meth- gi | i ∈  be a set isomorphic to . Let’s call the elements ods such as RDF [15] or OWL [14] designed for generic Se- of G granules.Atime granularity is a (non-necessarily mantic Web applications with methods specific toaparticu- total) function G from G in the set of intervals over T such

lar application domain, that of calendars and time. CaTTS that for all i, j ∈  with i

703

012weekend G  ∅ G  ∅ ∈G 1. if (gi) = and (gj ) = , then for all ti (gi)and 01 2week for all tj ∈G(gj ) ti

704

time granularity “second”). The type millisecond is an- chored at (denoted @) second 1 (denoted reference(1)), calendar type STD = sig since millisecond(1) is the first millisecond in the interval type second ; of milliseconds specifying the first second (i.e. reference(1)). type minute <: second; Thus, in CaTTS types such as reference or millisecond type hour <: minute ; type day <:hour; induces clear integer indices of its data items. This indexing type week <:day; of data items turns out to be extremely useful in practice type month <:day; (cf. below). type year <:month; group day of week c : day; type weekend day c : day ; 4.2 Predicate Subtypes group holiday c : day; Infinite sets are logically encoded by predicates: for any end → set A, the predicate p : A  defines the set of those elements of A that satisfy p. Such sets are called predi- Figure 3: Signature of a standard calendar in CaTTS-DL. cate sets. In type theory, predicate sets are interpreted as predicate subtypes, particularly used to express dependent function types [11]. CaTTS uses predicate subtypes in a specifies the infinite set of those days satisfying the predicate different manner and not for theoretical, but instead prac- “saturday” as previously expressed in CaTTS-DL. In the tical purposes. same manner, the type sunday is defined. Finally, the type CaTTS uses predicate subtypes as a means to define cal- weekend day satisfies either the predicate of type saturday endric types. E.g. one can describe the time granularity or (denoted “|”) the predicate of type sunday.Thetypes “week” as the subset of those time intervals over the time saturday, sunday, and weekend day are inclusion subtypes granularity “day” having a duration of 7 days and beginning of the type day (cf. Definition 5), written e.g. weekend day on Mondays. This can be directly expressed in CaTTS-DL c : day in CaTTS’ syntax, and read as “weekend day is an as follows: inclusion of day”. In CaTTS-DL, inclusion subtypes are con- type week = aggregate 7 day @ day( −2); structed by the select constructor by specifying a predicate as a combination of any operation predefined in CaTTS (cf. The type week is an aggregation of days such that each data Appendix A for the complete syntax of CaTTS) following item is an interval with duration “7 days”. The first week the reserved word where, or by a set-based constructor: “|” (i.e. week(1)) is anchored at (denoted @) day(-2), i.e. the (“or”), “&” (“and”), and “\” (“except”), in fact ordinary first day of the interval of days aggregated to the data item set operations interpreted as predicate subtype constructors week(1). Since day(1) is a Thursday (recall that CaTTS’ in CaTTS-DL. As illustrated in Figure 2, the indexing of in- implements Unix time with Thursday, January 1, 1970 as clusion subtypes is successive. The indexing of any inclusion fixed point indexed by 1), day(-2) is a Monday. Any fur- subtype is however implicitly related to that of its inclusion ther index can be computed relative to this anchor (cf. Fig- supertype, appropriately choosing the data item indexed by ure 2). Thus, the predicate subtype week:day →  speci- 0 relative to that one of the supertype. fies the infinite set of those day time intervals satisfying the Note that weekend days may alternatively be defined as a predicate “week” as previously expressed in CaTTS-DL. The group, i.e. a named collection of type definitions in CaTTS- type week is an aggregation subtype of the type day (cf. Def- DL: inition 4), written week <: day in CaTTS’ syntax, and read as “week is an aggregation of day”. In CaTTS-DL, aggre- group weekend day = with select day( i ) where ( relative i in week)==j gation subtypes are constructed by the aggregate construc- type saturday where j==6 tor, or by the predicates “#<” (“coarser restriction”) and type sunday where j==7 “#>” (“finer restriction”), set-based operations defined for end CaTTS due to predicative set aggregation. E.g. aggregating Having defined the group weekend day, one can either refer- the type weekend day into the type week yielding the type ring to data items of the group weekend day, or, more spe- weekend, a coarser restriction of week to weekend day. The cific, to data items of one of the types (saturday, sunday) two set-based aggregation predicates may also be used to de- defined within the group, explicitly defined belonging to a fine types having non-convex data items like “working week” less specific “kind”, i.e. a group of a CaTTS’ type. (a coarser restriction of working days, i.e. days that are nei- Furthermore, CaTTS provides a polytypic constructor: ther weekend days nor holidays, into weeks). Note that one | τ | (durations of τ)thatdescribesforanytypeτ a duration might define aggregations having data items of different - (cf. Definition 3) whose data items are drawn from τ.For rations involving often complex conditions (e.g. Gregorian example, |day| is the type of durations of days. or Hebrew months), as well. Note that CaTTS’ type constructors provide a natural One can describe the time granularity “weekend day” as way to obtain periodic events, e.g. the CS123 lecture of- the subset of those granules of time granularity “day” that fered within the summer term 2004 (referred to as ST04)(in are either Saturdays or Sundays. This can be directly ex- CaTTS X:CS123 lecture during ST04)oftypeCS123 lec- pressed in CaTTS-DL as follows: ture. Note that periodic events are very frequently consid- type saturday = select day( i ) where ered in current research. The authors believe that CaTTS relative i in week == 6; type sunday = select day( i ) where offers a particularly convenient and intuitive manner to spec- relative i in week == 7; ify periodic events. type weekend day = saturday | sunday ; The type saturday is a selection of the 6th day relative in → each week. Thus, the predicate subtype saturday:day 

705

( relative i in week) == j import LeapSeconds; type saturday where j==6 calendar Gregorian :STD = type sunday where j==7 cal end type second = reference ; type week = aggregate 7 day @ day (0); type minute = aggregate minute ( i ) type weekend = week #< weekend day ; alternate end | i == 1051200 (∗ 1.1.1972 ∗) − > 70 second | hasLeapSec?( i ) −> 61 second Note that day is a user-defined reference type (isomorphic to | otherwise −> 60 second the integers) without any further specifications. The identi- end @ second(1); type hour = aggregate 60 minute @ minute (1); fiers in a calendar are qualified. For example, the qualified type day = aggregate 24 hour @ hour (1); identifier Cal.week refers to the component week in the cal- type week = aggregate 7 day @ day( −2); endar definition Cal. type month = aggregate month( i ) 31 day named january , alternate 4.3.2 Calendar Signatures | (( i div 12)−1970) mod 4 == 0 && Calendar signatures are kinds of “types” for calendars de- ((( i div 12)−1970) mod 100 != 0 || (( i div 12)−1970) mod 400 == 0) − > 29 day fined in CaTTS-DL, similar to ML [9] signatures or XML | otherwise −> 28 day Schema declarations [12]. Calendar signatures specify iden- end named february , tifiers and abstract predicate subtypes in terms of inclusion 31 day named march , 30 day named april , or aggregation supertypes for each of the components of a 31 day named may , calendar implementing the signature. The following specifi- 30 day named june , cation binds a calendar signature to the identifier SIG. 31 day named july , 31 day named august , calendar type SIG = 30 day named september , sig 31 day named october , type day ; 30 day named november , group weekend day c : day ; 31 day named december @ day (1); type week <:day; type year = aggregate 12 month @ month ( 1 ) ; type weekend c : weekend day ; group day of week = end with select day( i ) where ( relative i in week) == j This calendar signature describes those calendars having a type monday where j==1 type day, agroupweekend day, where each type belong- type tuesday where j==2 ing to must be an inclusion subtype of day and types week type wednesday where j==3 type thursday where j==4 as aggregation subtype of day and weekend as aggregation type friday where j==5 subtype of weekend day. Since the calendar Cal introduced type saturday where j==6 above satisfies this calendar signature, it is said to match type sunday where j==7 end the calendar signature SIG. Note that a defined calendar type weekend day = saturday | sunday ; usually matches more than one calendar signature, and vice group holiday = with select day( i ) where versa, a calendar signature may be implemented by more ( relative i in M) = = j type all saints where j==2for M= november than one calendar. Calendar signatures in CaTTS-DL may type christmas where j==25for M = december be used to define views of calendars due to ascription, i.e. end specifying less components than implemented in any match- end ing calendar. The non-specified components are thus local to its calendar specification. Figure 4: The Gregorian calendar in CaTTS-DL. 4.3.3 Calendar Functions Calendar functions are user-defined functions on calen- 4.3 Calendar as Type dars using a syntax similar to function declarations in many The basic entities of CaTTS-DL calendar definitions (cf. programming languages. A calendar function CF defining Definition 6) are calendars, calendar signatures, and calen- Hebrew weekend days can be declared in CaTTS as follows: dar functions. cal fun CF(C:SIG):SIG = cal group weekend day = with select C. day( i ) 4.3.1 Calendars where ( relative i in C. week) == j A calendar is a packaged, finite collection of CaTTS type type friday where j==5 definitions and calendar specifications, assigning types to type saturday where j==6 end type identifiers, groups to group identifiers, and calendars end to calendar identifiers, similar to ML structures [9] or XML documents [13]. The types and calendars specified in a cal- The calendar function CF takes as argument any calendar C endar are delimited by the keywords cal and end.Thefol- matching the calendar signature SIG, and yields as result lowing specification binds a calendar to the identifier Cal. a calendar also matching SIG. When applied to a suitable This calendar defines an environment mapping day, weeken- calendar, the calendar function CF yields as result the calen- d day, week, and weekend to their respective group and dar whose group weekend day is that of (Hebrew) weekend type definitions. days, i.e. Fridays and Saturdays. Furthermore, any type definition in C depending on that of weekend day is changed calendar Cal = respectively to the calendar function CF when applied to C. cal type day ; E.g. applying CF to the previously illustrated calendar defi- group weekend day = with select day( i ) where nition Cal yields a “new” group weekend day and the type

706

weekend is changed, as well. Since the calendar function in Tel Aviv. Besides the various constraints to schedule CF may be applied to any calendar matching the signature the phone conference, the business men use different calen- SIG, the function is polymorph, thus define a parameterized dars. Both use the Gregorian calendar to schedule every- calendar. day times and dates, but shifted according to different time zones. The Tel Aviv-based business man uses the Hebrew 4.4 CaTTS-FDL calendar for holidays to be considered, but, for the same With most applications, one would appreciate not to spec- reason, the Munich-based business man uses the Gregorian. ify dates and times using indices of the data items of CaTTS The CaTTS-DL calendar signature in Figure 3, assigned types like day(23) or second(-123), but instead date for- to the identifier STD, describes standard calendar types and mats like “5.10.2004”, “2004/10/05”, or “Tue Oct 5 16:39:36 groups matched by most calendars. second is a non-further CEST 2004”. CaTTS-FDL provides a means for defining specified type identifier. date formats. The calendar definition given in Figure 4 binds a calen- A CaTTS-FDL date format is defined by a sequence of dar to the identifier Gregorian such that this calendar must string constants and/or placeholders, the latter appearing match the calendar signature STD (denoted Gregorian:STD). as variable names optionally followed by a representation CaTTS allows for importing external libraries using the re- 3 descriptor . Consider the following example: served word import. The calendar Gregorian imports a li- format stdfmt :day = y "-" m "-" d where brary LeapSeconds, containing, among other things, a boole- stdfmt within year(y) , an function hasLeapSec? over minutes. in- stdfmt within M: month , sertion into UTC-time (recall that reference is the time m== relative index M in year , d== relative index stdfmt in month ; granularity of UTC-seconds) started in 1972 (Gregorian); 10 leap seconds have been inserted into the first minute of This CaTTS-FDL format specification binds the identifier the year 1972. In the present CaTTS-DL modeling, the in- stdfmt to a standard format for data items of type day. dex of this minute is directly referred to. The type identifier Both a parser and a render function (i.e. String → day as second is assigned to the predefined base type reference. well as day → String) can be computed by resolving the The rules for the Gregorian leap month February are ex- constraints associated with stdfmt. Given “1970-1-1”, we pressed by a suitable combination of operations predefined get that y = 1970, m =1andd = 1 and can thus solve the in CaTTS. The predefined arithmetic function relative i constraints to get e.g. Gregorian.day(1). Vice versa, given in M (used in the group holiday) selects specific data items (Gregorian.)day(1), we find that it is within year(1970), i of type day relatively located to each data item in type st within M, which is equal to month(1) and is the 1 in a M, a local macro variable substituted by a CaTTS-DL type. st year, and that day(1) is the 1 in a month, yielding the Any further type definition is straightforward following the same values for y, m and d as above. rules of the Gregorian calendar [5]. Catalogs are collections of formats specifying to which cal- The calendar definition given in Figure 5 binds a calen- endar signature these formats can be applied. Such catalogs dar to the identifier Hebrew such that this calendar must may be nested, applying to common scoping rules. match the calendar signature STD (denoted Hebrew:STD). catalog ISO : STD = The Hebrew day “23 Tevet 5730”, a Wednesday (yom re- vii) is the day corresponding to the Unix (“1 Jan- (∗ nested catalog for extended ISO formats ∗) uary 1970” (Gregorian)). To implement an alignment of catalog Extended = 4 5 cat Hebrew regaim and halaqim (Hebrew partitions of hours) format stdfmt :day = y "-" m "-" d where with CaTTS’ reference type a respective shift (denoted by stdfmt within year(y) , the definition of ref) is defined. The type identifiers second stdfmt within M: month , and minute are used to match the with the m== relative index M in year , 6 d==relative index stdfmt in month ; standard signature STD . Note that Hebrew weeks start on end Sundays (yom rishon), and that the first month in any He- end brew year is Tishri. Since Hebrew computations As with calendars, identifiers defined within a catalog are depend on the Metonic cycle aligning 19 sun-based years to qualified, e.g. ISO.Extended.stdfmt is the full name of the 235 lunar-based months, the index 1 for Hebrew months is above format. Date formats specified in CaTTS-FDL may respectively moved form “Tevet 5730” to “Nisan 5720” by be imported into a program in the language CaTTS-CL, resetting this month’s index (133) relatively to the index 1 XQuery, or any other language using calendric data typed (denoted ˜@133). To simplify the modeling of the Hebrew after CaTTS-DL calendar specifications by CaTTS’ import calendar in CaTTS-DL, the library HebrewLeapYear,con- mechanism for formats use format. taining the various functions (e.g. isLeapAdarRishon? and isHebrewLeapYear?) used in the present calendar specifica- 4.5 Use Case: Specifying Calendars tion is imported. Such functions may however be directly To express and find solutions to real-life, Web, Seman- specified within a CaTTS-DL calendar definition by a user- tic Web, and Web Service related problems such as train defined “macro”. E.g. isLeapAdarRishon? (i.e. the sec- scheduling or making appointments, context-dependent se- ond to last month in a Hebrew year which depends on the mantics considering both cultural and professional calendars 4 and time zones is necessary. Plural of rega. 5Plural of heleq. Consider the following scenario: A Munich-based business 6 man needs to schedule a phone conference with a colleague Whether such an alignment of the Hebrew calendar to the STD calendar signature is appropriated or not, does not have 3If none is given, that portion of the format is interpreted to be discussed here. The present example aims at showing as a variable-length unsigned integer. that it is possible and easy to express with CaTTS.

707

Metonic cycle) can be specified by the following two CaTTS- DL macros: import HebrewLeapYear ; calendar Hebrew :STD = macro isLeapAdarRishonInCycle?( i ) = cal i== 36 || i== 73 || i== 98 || i == 135 type ref = refinement 114 @ reference ( −43199); || i == 172 || i == 209 || i == 234; type second = aggregate 5 ref ; macro isLeapAdarRishon ?(m) = type rega = second ; isLeapAdarRishonInCycle?((m mod 235) + 1); type minute = aggregate 76 second; type heleq = minute ; All rules implement in the CaTTS-DL definition of the He- type hour = aggregate 1080 minute; brew calendar are those suggested in [5]. type day = aggregate 24 hour ; type week = aggregate 7 day @ day( −2); Note that only a few Gregorian and Hebrew holidays are type month = aggregate month( i ) specified with the two present CaTTS-DL calendars. Fur- 30 day named nisan , ther can be similarly specified in CaTTS-DL. 29 day named iyyar , 30 day named sivan , Since reference is UTC-time and since UTC-time is ad- 29 day named tammuz , justed to the (GMT), the 30 day named av , previously mentioned calendars Gregorian and Hebrew cor- 29 day named elul , 30 day named tishri , respond to this time zone. Any further calendar C matching alternate also the calendar signature STD, but which refers to other | newYearDelay( i ) == 2 time zones can be expressed by a (user-defined) calendar −> 30 day named long marheshvan | − > function, redefining the definition of type by choosing otherwise 29 day named short marheshvan day end named marheshvan , suitable anchors for the considered time zones (cf. Figure alternate 6). If the calendar function EET is applied to the calendar | newYearDelay( i ) > 0 −> Gregorian or Hebrew, then any (aggregation or inclusion) 30 day named long kislev | otherwise − > 29 day named short kislev subtype of day is respectively changed. end named kislev , 29 day named tevet , 30 day named shevat , 5. CATTS-CL: CONSTRAINT LANGUAGE alternate | isLeapAdarRishon ?( i ) − > 30 day CaTTS-CL, CaTTS’ constraint language, is statically ty- named adar rishon ped after CaTTS-DL type definitions. CaTTS-CL is a lan- | otherwise none guage to declaratively express a wide range of temporal end , 29 day named adar sheni @ day(−21) ˜@ 133; and calendric constraint problems. Such problems are then type adar = adar rishon | adar−sheni ; solved by CaTTS-CL’s constraint solver. Given a CaTTS- type year = aggregate DL specification of the Gregorian calendar (with types such alternate year( i ) | isHebrewLeapYear?( i ) − > 13 month as “weekend day”) and the teaching calendar of a given | otherwise −> 12 month university (with types such as “exam week”), one can re- end @ month(7) ˜@ 5730; fer in CaTTS-CL programs to weekend days. One can fur- group day of week = ther express constraints on such days such as “after exam with select day( i ) where ( relative i in week) == j week” and “before June 2004” (assuming that the used date type yom rishon where j==1 formats are specified in CaTTS-FDL). This problem is ex- type yom sheni where j==2 pressed in CaTTS-CL as follows: type yom shelishi where j==3 type yom revii where j==4 X: weekend day && X after Y: exam week && type yom hamishi where j==5 7 type yom shishi where j==6 X before "2004-06" type yom shabbat where j==7 end The constraint variable X ranges over values of type weekend- type weekend day = yom shishi | yom shabbat ; day and Y over exam week. The constraints “after an ex- group holiday = with select day( i ) where amination week” (in CaTTS-CL X after Y:exam week)and ( relative i in M) = = j type yom kippur where j==10for M = tishri “before June 2004” (in CaTTS-CL X before "2004-06") type passover where j==15for M= nisan are straightforwardly expressed as illustrated. The con- end straints of CaTTS-CL are given in Appendix A. end CaTTS-CL provides function symbols for data items of types defined in CaTTS-DL, value constructors for time in- Figure 5: The Hebrew calendar in CaTTS-DL. tervals and durations, arithmetic functions, and condition- als. CaTTS-CL’s constraint symbols are common equation symbols, Allen’s 13 interval relations [1], and the symbol “:” ∗ ∗ for type annotations. The complete syntax (of all CaTTS ( CET: Central European Time , GMT + 1 , Munich ) calendar function CET( C : STD ) : STD = language fragments including CaTTS-CL) is given in Ap- cal pendix A. type day = aggregate 24 C. hour @ C. hour (2); The constraint X:τ assigns to a variable X a finite do- end (∗EET: Eastern European Time , GMT + 2 , Tel Aviv∗) main over values of type τ (defined in CaTTS-DL). Note calendar function EET(C : STD ) : STD = that the function symbols provided with CaTTS-CL are es- cal sentially the same as those provided with CaTTS-DL. Fur- type day = aggregate 24 C. hour @ C. hour (3); end thermore, the constraint symbols provided with CaTTS-CL

7 In this and the following examples, constraint variables Figure 6: Calendars in different time zones in CaTTS-DL. start with capital letters.

708

have the same names as the predicate symbols provided 6.2 Constraint Solver with CaTTS-DL because type defining predicates and con- CaTTS’ constraint solver essentially works on arbitrary straints are both boolean functions. However, there is an finite domains with type annotations after calendars defined elementary difference between a CaTTS-CL constraint and in CaTTS-DL. It departs from constraint systems over finite a CaTTS-DL predicate: a constraint specifies the proper- domains [6] due to (i) typed constraint variables, and (ii) ties and relationships among partially unknown “objects”. constraint variables that may range either over single values All possible solutions satisfying the constraint are computed or over intervals of values; thus, reasoning over (possibly by the constraint solver. In contrast, a predicate specifies periodic) intervals. The constraint solver refers to and relies the condition(s) to be satisfied by the elements belonging on the type predicates generated from a calendar definition to some predicate subtype. E.g. the type defining predicate in CaTTS-DL. This makes search space restrictions possible, “holiday” specifies the infinite set of all holidays, and the and furthermore, obtains the semantics of calendric data and constraint “X:holiday” computes the (infinite) set of all hol- constraints introduced with CaTTS-DL type definitions. idays. Thus, the values satisfying any CaTTS-CL constraint are computed, whereas a predicate only specifies the infinite set of values of some CaTTS-DL predicate subtype without 7. RELATED WORK performing any computations. CaTTS complements data type definition languages and A CaTTS-CL program is a finite collection of CaTTS-CL data modeling and reasoning methods for the Semantic such constraints. Calendars defined in CaTTS-TDL are referred as XML Schema [12], RDF [15], and OWL [14]: XML Schema to by the use calendar construct, data formats defined in provides a considerably large set of predefined time and date CaTTS-FDL are referred to by the use format construct, data types dedicated to the Gregorian calendar whereas and external libraries are referred to by the import con- CaTTS enables user-defined data types dedicated to any struct. The constraints specified in a CaTTS-CL program calendar. RDF and OWL are designed for generic Seman- are delimited by the reserved words prog and end. tic Web applications. In contrast, CaTTS provides with 5.1 Use Case (Continued): Multi-Calendar methods specific to particular application domains, that of Appointment Scheduling calendars and time. CaTTS departs from time ontologies such as the KIF time Turning attention back to the two business men schedul- ontology [8], time in OWL-S [10], and the DAML time on- ing a phone conference (cf. Section 4.5) during the 1st week tology [4], in many aspects. in October 2004, they specify the necessary constraints in CaTTS considerably simplifies the modeling of specifici- a CaTTS-DL program (cf. Figure 7). The day, the phone ties of cultural calendars (such as leap years, sun-based cy- conference might take place should be a Monday, Tuesday, cles like Gregorian years, or lunar-based cycles like Hebrew Wednesday, or Thursday in Tel Aviv. The conference itself months) as well as the modeling of professional calendars of- (denoted by the variable Conf) has a maximal duration of 1 ten involving “gaps” in time (e.g. “working day”), “gapped” hour, and it should be between 9 a.m. and 5 p.m. consider- data items (e.g. data items of type “working week”), and ing both time zones involved in this scenario. Furthermore, periodic events (e.g. “CS123 lecture”) due to predicate sub- the telephone conference should take place in the first week types. of October 2004. The well-known advantages of statically typed languages such as error detecting, language safety, efficiency, abstrac- 6. STATIC TYPE CHECKING AND tion, and documentation whereas the two latter obtain par- CONSTRAINT REASONING ticular interest due to overloaded semantics of calendric data apply to CaTTS, as well. Beyond this, CaTTS’ static type SUMMARIZED checker provides both meta-type checking of predicate sub- This section briefly summarizes the characteristics of type definitions in CaTTS-DL and type checking of con- CaTTS’ language processors. A static type checker to en- straints in CaTTS-CL, obtaining the semantics of different sure the behavior and semantics of calendric data and con- time granularities even for reasoning with their granules. straints, and a constraint solver to reason with such data. CaTTS comes along with a constraint solver dedicated to calendar definitions in CaTTS-DL; this dedication makes 6.1 Static Type Checker considerable search space restrictions, hence gains in effi- In programming languages such as ML [9] static type ciency, possible. checking is used as a “lightweight formal method” (i.e. merely While (time) ontologies follow the (automated reason- syntactically tractable) for program analyses ensuring cor- ing) approach of “axiomatic reasoning”, CaTTS is based rect behavior of programs and/or systems w.r.t. some spec- on a (specific) form of “theory reasoning”, an approach ification. CaTTS, however, uses static type checking for well-known through paramodulation. Like paramodulation semantic restrictions of inherent ambiguous and/or impre- ensures efficient processing of equality in resolution theo- cise calendric data and constraints ensuring correct inter- rem proving, CaTTS provides the user with convenient con- pretation of CaTTS-CL programs w.r.t. some CaTTS-DL structs for calendric types and efficient processing of data calendar specification. For space reasons, the typing and and constraints over those types. subtyping relations of CaTTS’ static type checker cannot CaTTS inherently differs from specification languages for be presented in this article. First experimental results with temporal expressions in natural language text like TimeML a prototype implementation of CaTTS’ type checker point [7]. TimeML is a language for annotating temporal informa- to a good efficiency (i.e. type checking is polynomial). Fur- tion in text corpora whereas CaTTS is designed as a type ther investigations concerning efficiency as well as soundness language specialized in calendar and time modeling and rea- and completeness results are undergo. soning, for Semantic Web applications and Web Services.

709

program TelConference = use calendar unqualified Gregorian ; use calendar Hebrew , CET(C) , EET(C) ; use format unqualified ISO. Extended;

prog Conf : hour during X: week && X during "2004-10" && relative index X in october == 1 && relative index Conf in CET(Gregorian ). day >=9&& relative index Conf in CET(Gregorian ). day <=17&& relative index Conf in EET( G r e g o r i a n ) . d ay >=9&& relative index Conf in EET( G r e g o r i a n ) . d ay <=17&& Conf during EET( G r e g o r i a n ) . ( monday | tuesday | wednesday| thursday) end

Figure 7: A scheduling problem in CaTTS-CL.

8. CONCLUSIONS [8] Knowledge Systems Laboratories, Stanford. Time This article has introduced CaTTS, consisting of Ontology in KIF, 1994. [9] R. Milner, M. Tofte, and R. W. Harper. The • CaTTS-DL, a definition language, itself consisting of Definition of Standard ML. MIT Press, 1990. – CaTTS-TDL, a type definition language and [10] F. Pan and J. R. Hobbs. Time in OWL-S. In Semantic – CaTTS-FDL, a date format definition language Web Services, AAAI Spring Symposium Series, 2004. [11] B. C. Pierce. Types and Programming Languages.MIT • CaTTS-CL, a constraint language typed by CaTTS- Press, 2002. DL definitions. [12] W3C, World Wide Web Consortium. XML Schema CaTTS’ predicate subtype constructors allow for defining Part 2: Datatypes, 2001. arbitrary time granularities as types in CaTTS-DL. The two [13] W3C, World Wide Web Consortium. Extensible subtype relations aggregation subtype of and inclusion sub- Markup Language (XML) 1.0 (Third Edition), 2004. type of provide means for conversions between those types [14] W3C, World Wide Web Consortium. OWL Web during constraint reasoning with calendric data of those Ontology Language Overview, 2004. types, particularly in CaTTS-CL. CaTTS’ polytypic con- [15] W3C, World Wide Web Consortium. RDF Primer, structors provide a convenient and intuitive manner to spec- 2004. ify periodic events. Interpreting calendars as types and their parameterization ensures maintenance and reuse of calen- dars, where the “type” of a calendar provides a summary of that calendar. CaTTS facilitates the modeling and efficient processing of calendar and time data in Web and Semantic Web appli- cations and Web Services, especially compared to ontology- based modeling and reasoning. 9. REFERENCES [1] J. F. Allen. Maintaining Knowledge about Temporal Intervals. Communications of the ACM, 26(11):832–843, 1983. [2] C. Bettini, S. Jajodia, and S. X. Wang. Time Granularities in Databases, Data Mining, and Temporal Reasoning. Springer-Verlag, 2000. [3] F. Bry and S. Spranger. Towards a Multi-calendar Temporal Type System for (Semantic) Web Query Languages. In Proc. 2nd Int. Workshop Principles and Practice in Semantic Web Reasoning, LNCS 3208. Springer-Verlag, 2004. [4] DARPA Agent Markup Language. ADAMLOntology of Time, 2002. [5] N. Dershowitz and E. Reingold. Calendrical Calculations: The Edition. Cambridge University Press, 2001. [6] T. Fr¨uhwirth and S. Abdennadher. Constraint-Programmierung. Springer-Verlag, 1997. [7] B. Ingria and J. Pustejovsky. TimeML: A Formal Specification Language for Events and Temporal Expressions. 2004.

710

APPENDIX caldcl ::= cal decls: dcl declaration A. SYNTAX OF CATTS calendar calbind calendar empty caldcl;caldcl sequential calbind ::= cal binds: A.1 Identifiers 〈 〉 ∈ c (:sige) =cale t TyVar type identifiers long cal exprs: ∈ cale ::= c CalId calendar identifiers long generative ∈ cal caldcl end s CalSigId calendar signature identifiers identifier ∈ longc f CalFunId calendar function identifiers f(cale) fun appl p ∈ ProgId program identifiers fdcl ::= fun decls: For each class of identifiers X marked “long” there is a cal fun fbind generative class longX of long identifiers;ifx ranges over X then longx empty ranges over longX. The syntax of the long identifiers is given fdcl;fdcl sequential by the following: fbind ::= fun binding: longx ::= long identifiers: f(c:s):s’ = cale x identifier c1.....cn.x qualified identifier n ≥ 1 sigdcl ::= sdecls: calendar type sigbind generative The long identifiers constitute a link between declarations empty and calendars. sigdcl;sigdcl sequential sigbind ::= sbindings: s=sige A.2 Grammar sige ::= sexprs: sig spec end generative CaTTS grammar, including the syntactic forms for both s identifier language formalisms CaTTS-DL and CaTTS-CL is given in spec ::= specs: a BNF-like notation (〈...〉denote n ≤ 0 repetitions). type t <: ty aggregation e::= exprs: type t c : ty inclusion k constant group t c : ty group calendar c:sige calendar nty duration, n ∈ Æ binOp e e binary op spec;spec sequential unOp e unary op alternate x:ty 〈| e → e〉 alternate pdcl ::= pdecls: ce constraints ce constraint ce ::= constraints: use calendar x variable 〈unqualified〉 x:ty domain constraint longc1 ...longcn ; n ≥ 1 ce iRel ce interval relation import ce aRel ce arithm. relation 〈unqualified〉 ce && ce conjunction lib1 ...libn; n ≥ 1 use format 〈 〉 binOp ::= shift forward | shift backward | unqualified n ≥ relative to | + |−|relative in | cate1 ...caten ; 1 ∗|\|mod | div | max | min program pbind generative unOp ::= duration of | begin of | end of | index empty iRel ::= equals | before | after | starts | pdcl;pdcl sequential started by | finishes | finished by | pbind ::= pbinds: during | contains | meets | met by | p proge overlaps | overlapped by proge ::= pexprs: aRel ::= == | <= | < | > | >= | != prog pdcl end declaration p identifier ty ::= types: cat decls: longt type identifier catdcl ::= generative reference reference catalog catbind ∈ format fid:ty = format refinement n @ e refine, n Æ d where e aggregate e〈,e〉@e aggregation empty select x:ty where e〈e〉 inclusion sequential |ty| duration catdcl;catdcl 〈 〉 catbind ::= cat binds: ty&ty&ty conjunction 〈 〉 ty | ty〈| ty〉 disjunction cd :s = cate cat exprs: ty \ ty except cate ::= generative ty #< ty coarser-restrict cat catdcl end cd identifier ty #> ty finer-restrict qual id dcl ::= decls: cate.cd catalog type t = ty type catalog cd group t = wspec group dcl;dcl sequential wspec ::= with specs: with ty 〈type t where e;e for t1=t2〉

711