2
8
11
12
13
14:-op(600,xfy,--). 15
16
19:- export(database80/1). 20database80(X):- catch(database_u(X),E,(dmsg(error(E,database_u(X))),trace,database_u(X))).
21
22database_t(aggregate(X,Y,Z)) :- aggregate(X,Y,Z).
23database_t(one_of(X,Y)) :- one_of(X,Y).
24database_t(ratio(X,Y,Z)) :- ratio(X,Y,Z).
25database_t(cardinality(X,Y)) :- cardinality(X,Y).
26
27database_u(X):- nonvar(X),database_t(X).
28database_u(african(X)) :- african(X).
29database_u(american(X)) :- american(X).
30database_u(area(X)) :- area(X).
31database_u(area(X,Y)) :- area(X,Y).
32database_u(asian(X)) :- asian(X).
33database_u(borders(X,Y)) :- borders(X,Y).
34database_u(capital(X)) :- capital(X).
35database_u(capital(X,Y)) :- capital(X,Y).
36database_u(circle_of_latitude(X)) :- circle_of_latitude(X).
37database_u(city(X)) :- city(X).
38database_u(continent(X)) :- continent(X).
39database_u(country(X)) :- country(X).
40database_u(drains(X,Y)) :- drains(X,Y).
41database_u(eastof(X,Y)) :- eastof(X,Y).
42database_u(european(X)) :- european(X).
43database_u(exceeds(X,Y)) :- exceeds(X,Y).
44database_u(flows(X,Y)) :- flows(X,Y).
45database_u(flows(X,Y,Z)) :- flows(X,Y,Z).
46database_u(in(X,Y)) :- in(X,Y).
47database_u(latitude(X)) :- latitude(X).
48database_u(latitude(X,Y)) :- latitude(X,Y).
49database_u(longitude(X)) :- longitude(X).
50database_u(longitude(X,Y)) :- longitude(X,Y).
51database_u(northof(X,Y)) :- northof(X,Y).
52database_u(ocean(X)) :- ocean(X).
53database_u(place(X)) :- place(X).
55database_u(population(X)) :- population(X).
56database_u(population(X,Y)) :- population(X,Y).
57database_u(region(X)) :- region(X).
58database_u(rises(X,Y)) :- rises(X,Y).
59database_u(river(X)) :- river(X).
60database_u(sea(X)) :- sea(X).
61database_u(seamass(X)) :- seamass(X).
62database_u(southof(X,Y)) :- southof(X,Y).
63database_u(westof(X,Y)) :- westof(X,Y).
64
65:-op(500,xfy,--). 66
68exceeds(X--_,Y--_):- (var(X);var(Y)),!,fail.
69exceeds(X--U1,Y--U2) :- U1=U2, !, X > Y.
70exceeds(X1--U1,X2--U2) :- ratio(U1,U2,M1,M2), X1*M1 > X2*M2.
71
72ratio(thousand,million,1,1000).
73ratio(million,thousand,1000,1).
74ratio(ksqmiles,sqmiles,1000,1).
75ratio(sqmiles,ksqmiles,1,1000).
76
77area(_X--ksqmiles).
78capital(C) :- capital(_X,C).
79city(C) :- city(C,_,_).
80country(C) :- country(C,_, _,_,_, _,_,_, _,_).
81latitude(_X--degrees).
82longitude(_X--degrees).
83place(X) :- continent(X); region(X); seamass(X); country(X).
84population(_X--million).
85population(_X--thousand).
86region(R) :- in_continent(R,_).
87
88african(X) :- in(X,africa).
89american(X) :- in(X,america).
90asian(X) :- in(X,asia).
91european(X) :- in(X,europe).
92
93in(X,Y) :- var(X), nonvar(Y), !, contains(Y,X).
94in(X,Y) :- in0(X,W), ( W=Y ; in(W,Y) ).
95
96in0(X,Y) :- in_continent(X,Y).
97in0(X,Y) :- city(X,Y,_).
98in0(X,Y) :- country(X,Y,_,_,_, _,_,_, _,_).
99in0(X,Y) :- flows(X,Y).
100
101eastof(X1,X2) :- longitude(X1,L1), longitude(X2,L2), exceeds(L2,L1).
102northof(X1,X2) :- latitude(X1,L1), latitude(X2,L2), exceeds(L1,L2).
103southof(X1,X2) :- latitude(X1,L1), latitude(X2,L2), exceeds(L2,L1).
104westof(X1,X2) :- longitude(X1,L1), longitude(X2,L2), exceeds(L1,L2).
105
106circle_of_latitude(equator).
107circle_of_latitude(tropic_of_cancer).
108circle_of_latitude(tropic_of_capricorn).
109circle_of_latitude(arctic_circle).
110circle_of_latitude(antarctic_circle).
111
112latitude(equator,0--degrees).
113latitude(tropic_of_cancer,23--degrees).
114latitude(tropic_of_capricorn,-23--degrees).
115latitude(arctic_circle,67--degrees).
116latitude(antarctic_circle,-67--degrees).
117
118latitude(C,L--degrees) :- country(C,_,L,_,_,_,_,_,_,_).
119longitude(C,L--degrees) :- country(C,_,_,L,_,_,_,_,_,_).
120area(C,A--ksqmiles) :- country(C,_,_,_,A,_,_,_,_,_).
121population(C,P--thousand) :- city(C,_,P).
122population(C,P--million) :- country(C,_,_,_,_,_,P,_,_,_).
123capital(C,Cap) :- country(C,_,_,_,_,_,_,_,Cap,_).
124
125continent(africa).
126continent(america).
127continent(antarctica).
128continent(asia).
129continent(australasia).
130continent(europe).
131
132in_continent(scandinavia, europe).
133in_continent(western_europe, europe).
134in_continent(eastern_europe, europe).
135in_continent(southern_europe, europe).
136in_continent(north_america, america).
137in_continent(central_america, america).
138in_continent(caribbean, america).
139in_continent(south_america, america).
140in_continent(north_africa, africa).
141in_continent(west_africa, africa).
142in_continent(central_africa, africa).
143in_continent(east_africa, africa).
144in_continent(southern_africa, africa).
145in_continent(middle_east, asia).
146in_continent(indian_subcontinent, asia).
147in_continent(southeast_east, asia).
148in_continent(far_east, asia).
149in_continent(northern_asia, asia).
150
151seamass(X) :- ocean(X).
152seamass(X) :- sea(X).
153
154ocean(arctic_ocean).
155ocean(atlantic).
156ocean(indian_ocean).
157ocean(pacific).
158ocean(southern_ocean).
159
160sea(baltic).
161sea(black_sea).
162sea(caspian).
163sea(mediterranean).
164sea(persian_gulf).
165sea(red_sea).
166
167river(R) :- river(R,_L).
168
169rises(R,C) :- river(R,L), last(L,C).
170
171drains(R,S) :- river(R,L), first(L,S).
172
173flows(R,C) :- flows(R,C,_).
174
175flows(R,C1,C2) :- river(R,L), links(L,C2,C1).
176
177first([X|_],X).
178
181
182links([X1,X2|_],X1,X2).
183links([_|L],X1,X2) :- links(L,X1,X2)