这是我的约会数据库的Z架构。
|--AppointmentDB----------------
|attendees : P Person /** those involved in the appointment **/
|
|/** a new TYPE object to store attendees, schedule and purpose **/
|appointments : P APPOINTMENT
|hasAppointment : Person <-> APPOINTMENT
|schedule : APPOINTMENT -> DateTime
|purpose : APPOINTMENT -> Report
|
|/** a forward relation compositions to relate attendees with purpose and schedule **/
|attendeePurpose : hasAppointment;purpose
|attendeeSchedule : hasAppointment;schedule
|-----------------------------
|attendees ⊆ dom(hasAppointment)
|attendees ⊆ dom(attendeePurpose)
|appointments ⊆ ran(hasAppointment)
|-----------------------------
我想创建一个搜索功能,根据attendees
的名称查找约会。
我该如何设计?
以下是我的观点:
|--FindAppointment---------------------------------------------------
|ΞAppointmentDB
|attendees? : Person
|appointmentAttendees! : P Person
|appointmentPurpose! : Report
|appointmentSchedule! : DateTime
|-----------------------------
|/** if name of any attendees is given, then it must exist in appointments' domain
|respectively before this function can run**/
|attendees? ∈ dom(attendees)
|
|/** return the set of attendees of the same APPOINTMENT using attendees? as input **/
|appointmentAttendees! = hasAppointment~(|{attendees?}|)
|
|/** Get the image of both forward relational compositions according to set of
|attendees?**/
|appointmentPurpose! = attendeePurpose(|{attendees?}|)
|appointmentSchedule! = attendeeSchedule(|{attendees?}|)
|----------------------------------------------------------------------
答案 0 :(得分:1)
您是否键入了检查规格?
您的声明subject? : P Person
声明subject?
是一组人,但subject? : dom(attendees)
表示subject?
是一个人。
如果你想要一个人或一个人,你可以在函数式编程语言中引入类似于Maybe monad的数据类型(或其他编程语言中的null值):
MaybePerson ::= NoPerson | JustPerson <<Person>>
然后你可以声明像
这样的输入subject? : MaybePerson
然后我建议限制一个输入的可能解决方案
subject? : ran(JustPerson) => schedule! : schedule(|{ JustPerson~ subject? }|)
如果subject?
是一组人,您可以通过以下方式实现相同目标:
subject? /= {} => schedule! : schedule(|subject?|)
然后就其他可能的输入做同样的事情。您还可以添加一个条件,而不是两个条目都应该NoPerson
。并非两个输入集都应为空。