Alright, I gave it a go, in CQL. Note: this uses features of CQL that aren't yet released, and even a couple that aren't yet implemented
. I didn't produce the derivation for the grand prize, but a derivation for the first three prizes for each event is given (if there's an equal first, next will be third place).
I can't preview this; I hope the forum doesn't make it unreadable.
vocabulary FelineAssociationShows;
Feline Association is identified by its Name;
example: FelineAssociation 'New Hampshire Feline Appreciation Club';
Year is written as Integer restricted to {2000..};
Month is written as Integer restricted to {1..12};
Day of Month is written as Integer restricted to {1..31};
Hour is written as Integer restricted to {0..23};
Minute is written as Integer restricted to {0..59};
Time is identified by Hour and Minute where
Time has one Hour,
Time has one Minute;
Show is where
Feline Association holds show in Year;
Show is held in at most one Month;
Show starts on one Day of Month;
Show Day is written as Integer restricted to {1..};
example: /* compound fact instance with an objectification join */
Show (where FelineAssociation 'New Hampshire Feline Appreciation Club' holds show in Year 2010)
is held in Month 10;
Event is identified by its Name;
example: Event 'Cat Show Buffet';
example: Event 'Best Burmese';
Show Event is where Show includes Event;
Show Event is called at most one Name;
Show Event starts at one Time (as StartTime);
Show Event ends at most one ending-Time;
Show Event is held on one Show Day;
PhoneNr is written as String;
Cat Owner is identified by first Name and last Name and contact Phone where
Cat Owner is called one first-Name,
Cat Owner has one last-Name,
Cat Owner has one contact-PhoneNr;
Cat is identified by its Name;
Cat Breed is identified by its Name;
Cat is of one Cat Breed;
Fur Colour is written as String;
Cat Fur Colour is where
Cat has at least one and at most three Fur Colour;
Cat belongs to at least one Cat Owner;
Cat Owner owns Cat;
Registered Cat is where
Cat is registered for one Show;
// External join frequency constraint - not currently supported by CQL compiler:
for each Cat Owner, Show:
Cat Owner owns at most 2 Cat which is registered for Show;
Collar is identified by its Number;
Registered Cat is assigned one Collar;
Participation is where
Registered Cat participates in Show Event,
Show Event is entered by Registered Cat;
Score is written as Integer;
Participation is awarded at most one Score;
Event Prize is identified by Show Event where
Event Prize is awarded for Show Event,
Show Event has at most 3 Event Prize;
// Derived fact type:
Registered Cat receives Score in Show Event where
Participation (where Registered Cat participates in Show Event) is awarded Score;
// If there's a tie (equal first, say), the next place will be third:
Registered Cat receives Place for Participation in Show Event where
Registered Cat receives Score for Participation in Show Event,
Place = count(
other-Participation (where other-Registered Cat participates in Show Event) is awarded other-Score,
other-Score > Score
) + 1;
Event Prize in Place is awarded to Cat Owner for Participation where
Event Prize is awarded for Show Event (where Show includes Event),
Registered Cat (where Cat is registered for Show) receives Place for Participation in Show Event,
Cat belongs to Cat Owner,
Place <= 3;
// and similarly for grand prizes...