0

这是我的约会数据库的 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.

  1. 我希望搜索功能返回约会对象的所有详细信息。

我该如何设计它?


这是我的看法:

|--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?}|)
|----------------------------------------------------------------------
4

1 回答 1

1

你有没有检查过你的规范?您的声明声明subject? : P Personsubject?是一组人,但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相应的。不是两个输入集都应该为空。

于 2015-04-20T14:46:58.880 回答