% % File: dinosaur % % contributed by: % John-David N. Dionisio % UCLA % dondi@cs.ucla.edu % % Schema Definition % database( { taxonomy(Super: string, Sub: string), characteristics( Group: string, % The primary classification. Food: {string}, % What does this group eat? Armor: {string}, % What kind of armor did it have? Teeth: {string}, % What kind of teeth did it have? Feet: string % Is this group bipedal or quadrupedal? ), dinosaur(Name: string, AgeName: string, Size: real), % % Size indicates length of the dinosaur (i.e. the distance from its % head to its tail). All measurements are in meters. % % % Supporting relations. % ageNames(Previous: string, Next: string), food(Name: string, Kind: string) } ). % % Exported Query Forms % % A. Generic dinosaur data. % export listDinosaur(Name, AgeName, Size). export listDinosaur($Name, AgeName, Size). export listDinosaur(Name, $AgeName, Size). export listDinosaur(Name, AgeName, $Size). % % Etc. etc. ...the listDinosaur query can be extended to many different % permutations and combinations. % % % B. Dinosaur classification. % export kindOf($Group, $Subgroup). export kindOf($Group, Subgroup). export kindOf(Group, $Subgroup). export kindOf(Group, Subgroup). export profile($Dinosaur, Genus, Food, Armor, Teeth, Feet, MinSize, MaxSize). export profile(Dinosaur, $Genus, Food, Armor, Teeth, Feet, MinSize, MaxSize). export profile(Dinosaur, Genus, $Food, Armor, Teeth, Feet, MinSize, MaxSize). export profile(Dinosaur, Genus, Food, $Armor, Teeth, Feet, MinSize, MaxSize). export profile(Dinosaur, Genus, Food, Armor, $Teeth, Feet, MinSize, MaxSize). export profile(Dinosaur, Genus, Food, $Armor, $Teeth, Feet, MinSize, MaxSize). export profile(Dinosaur, Genus, Food, Armor, Teeth, Feet, MinSize, MaxSize). % % Etc. etc. ...the profile query can be extended to many different % permutations and combinations. % % % C. Dinosaur age and ancestry. % export precedes(OldAge, NewAge). export precedes($OldAge, NewAge). export precedes(NewAge, $OldAge). export older($OldDino, YoungDino). export older(OldDino, $YoungDino). export older(OldDino, YoungDino). export younger($YoungDino, OldDino). export younger(YoungDino, $OldDino). export younger(YoungDino, OldDino). export ancestor($OldDino, YoungDino). export ancestor(OldDino, $YoungDino). export ancestor(OldDino, YoungDino). export descendant($YoungDino, OldDino). export descendant(YoungDino, $OldDino). export descendant(YoungDino, OldDino). % % D. Dinosaur eating habits. % export eats($Dinosaur, Food). export eats(Dinosaur, $Food). export herbivore($Dinosaur). export herbivore(Dinosaur). export carnivore($Dinosaur). export carnivore(Dinosaur). export omnivore($Dinosaur). export omnivore(Dinosaur). % % Rules % listDinosaur(Name, AgeName, Size) <- dinosaur(Name, AgeName, Size). %%%%%%%%%% kindOf(Group, Subgroup) <- taxonomy(Group, Subgroup). kindOf(Group, Subgroup) <- taxonomy(Group, BetweenGroup), kindOf(BetweenGroup, Subgroup). sizesOfGenus(Genus, ) <- dinosaur(Dinosaur, _, Size), kindOf(Genus, Dinosaur). profile(Dinosaur, Genus, Food, Armor, Teeth, Feet, MinSize, MaxSize) <- dinosaur(Dinosaur, _, Size), kindOf(Genus, Dinosaur), characteristics(Genus, Food, Armor, Teeth, Feet), sizesOfGenus(Genus, SizeSet), min(SizeSet, MinSize), max(SizeSet, MaxSize). %%%%%%%%%% precedes(OldAge, NewAge) <- ageNames(OldAge, NewAge). precedes(OldAge, NewAge) <- ageNames(OldAge, BetweenAge), precedes(BetweenAge, NewAge). older(OldDino, YoungDino) <- dinosaur(OldDino, OldAge, _), dinosaur(YoungDino, NewAge, _), precedes(OldAge, NewAge). younger(YoungDino, OldDino) <- older(OldDino, YoungDino). ancestor(OldDino, YoungDino) <- dinosaur(OldDino, _, _), taxonomy(Genus, OldDino), dinosaur(YoungDino, _, _), taxonomy(Genus, YoungDino), older(OldDino, YoungDino). descendant(YoungDino, OldDino) <- ancestor(OldDino, YoungDino). %%%%%%%%%% eats(Dinosaur, Food) <- dinosaur(Dinosaur, _, _), kindOf(Group, Dinosaur), characteristics(Group, FoodSet, _, _, _), member(Food, FoodSet). plant(Food) <- food(Food, Kind), Kind = plant. meat(Food) <- food(Food, Kind), Kind = meat. eatsPlants(Dinosaur) <- eats(Dinosaur, Food), plant(Food). eatsMeat(Dinosaur) <- eats(Dinosaur, Food), meat(Food). herbivore(Dinosaur) <- eatsPlants(Dinosaur), ~eatsMeat(Dinosaur). carnivore(Dinosaur) <- eatsMeat(Dinosaur), ~eatsPlants(Dinosaur). omnivore(Dinosaur) <- eatsPlants(Dinosaur), eatsMeat(Dinosaur). %%%%%%%%%% min(S, N) <- aggregate(min, S, N). empty(min, 0). single(min, X, X). multi(min, N1, N2, N3) <- if(N1 < N2 then N3 = N1 else N3 = N2). max(S, N) <- aggregate(max, S, N). empty(max, 0). single(max, X, X). multi(max, N1, N2, N3) <- if(N1 > N2 then N3 = N1 else N3 = N2).