1/*  Copyright 1986-2020 David H. D. Warren and Fernando C. N. Pereira
    2
    3    Permission is hereby granted, free of charge, to any person obtaining a
    4    copy of this software and associated documentation files (the
    5    "Software"), to deal in the Software without restriction, including
    6    without limitation the rights to use, copy, modify, merge, publish,
    7    distribute, sublicense, and/or sell copies of the Software, and to
    8    permit persons to whom the Software is furnished to do so, subject to
    9    the following conditions:
   10
   11    The above copyright notice and this permission notice shall be included
   12    in all copies or substantial portions of the Software.
   13
   14    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   15    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   16    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   17    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   18    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   19    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   20    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   21*/
   22
   23% Data for the World Database.
   24% ---------------------------
   25
   26
   27% Interface.
   28% ---------
   29
   30% Interface.
   31% ---------
   32
   33database(aggregate(X,Y,Z)) :- aggregate(X,Y,Z).
   34database(one_of(X,Y)) :- one_of(X,Y).
   35database(ratio(X,Y,Z)) :- ratio(X,Y,Z).
   36database(card(X,Y)) :- card(X,Y).
   37database(african(X)) :- african(X).
   38database(american(X)) :- american(X).
   39database(area(X)) :- area(X).
   40database(area(X,Y)) :- area(X,Y).
   41database(asian(X)) :- asian(X).
   42database(borders(X,Y)) :- borders(X,Y).
   43database(capital(X)) :- capital(X).
   44database(capital(X,Y)) :- capital(X,Y).
   45database(circle_of_latitude(X)) :- circle_of_latitude(X).
   46database(city(X)) :- city(X).
   47database(continent(X)) :- continent(X).
   48database(country(X)) :- country(X).
   49database(drains(X,Y)) :- drains(X,Y).
   50database(eastof(X,Y)) :- eastof(X,Y).
   51database(european(X)) :- european(X).
   52database(exceeds(X,Y)) :- exceeds(X,Y).
   53database(flows(X,Y)) :- flows(X,Y).
   54database(flows(X,Y,Z)) :- flows(X,Y,Z).
   55database(in(X,Y)) :- in(X,Y).
   56database(latitude(X)) :- latitude(X).
   57database(latitude(X,Y)) :- latitude(X,Y).
   58database(longitude(X)) :- longitude(X).
   59database(longitude(X,Y)) :- longitude(X,Y).
   60database(northof(X,Y)) :- northof(X,Y).
   61database(ocean(X)) :- ocean(X).
   62database(place(X)) :- place(X).
   63%database(person(X)) :- person(X).	% JW: person is not defined
   64database(population(X)) :- population(X).
   65database(population(X,Y)) :- population(X,Y).
   66database(region(X)) :- region(X).
   67database(rises(X,Y)) :- rises(X,Y).
   68database(river(X)) :- river(X).
   69database(sea(X)) :- sea(X).
   70database(seamass(X)) :- seamass(X).
   71database(southof(X,Y)) :- southof(X,Y).
   72database(westof(X,Y)) :- westof(X,Y).
   73
   74:-op(500,xfy,--).   75
   76exceeds(X--U,Y--U) :- !, X > Y.
   77exceeds(X1--U1,X2--U2) :- ratio(U1,U2,M1,M2), X1*M1 > X2*M2.
   78
   79ratio(thousand,million,1,1000).
   80ratio(million,thousand,1000,1).
   81ratio(ksqmiles,sqmiles,1000,1).
   82ratio(sqmiles,ksqmiles,1,1000).
   83
   84area(X--ksqmiles).
   85capital(C) :- capital(X,C).
   86city(C) :- city(C,_,_).
   87country(C) :- country(C,_,_,_,_,_,_,_,_,_).
   88latitude(X--degrees).
   89longitude(X--degrees).
   90place(X) :- continent(X); region(X); seamass(X); country(X).
   91population(X--million).
   92population(X--thousand).
   93region(R) :- in_continent(R,_).
   94
   95african(X) :- in(X,africa).
   96american(X) :- in(X,america).
   97asian(X) :- in(X,asia).
   98european(X) :- in(X,europe).
   99
  100in(X,Y) :- var(X), nonvar(Y), !, contains(Y,X).
  101in(X,Y) :- in0(X,W), ( W=Y ; in(W,Y) ).
  102
  103in0(X,Y) :- in_continent(X,Y).
  104in0(X,Y) :- city(X,Y,_).
  105in0(X,Y) :- country(X,Y,_,_,_,_,_,_,_,_).
  106in0(X,Y) :- flows(X,Y).
  107
  108eastof(X1,X2) :- longitude(X1,L1), longitude(X2,L2), exceeds(L2,L1).
  109northof(X1,X2) :- latitude(X1,L1), latitude(X2,L2), exceeds(L1,L2).
  110southof(X1,X2) :- latitude(X1,L1), latitude(X2,L2), exceeds(L2,L1).
  111westof(X1,X2) :- longitude(X1,L1), longitude(X2,L2), exceeds(L1,L2).
  112
  113circle_of_latitude(equator).
  114circle_of_latitude(tropic_of_cancer).
  115circle_of_latitude(tropic_of_capricorn).
  116circle_of_latitude(arctic_circle).
  117circle_of_latitude(antarctic_circle).
  118
  119latitude(equator,0--degrees).
  120latitude(tropic_of_cancer,23--degrees).
  121latitude(tropic_of_capricorn,-23--degrees).
  122latitude(arctic_circle,67--degrees).
  123latitude(antarctic_circle,-67--degrees).
  124
  125latitude(C,L--degrees) :- country(C,_,L,_,_,_,_,_,_,_).
  126longitude(C,L--degrees) :- country(C,_,_,L,_,_,_,_,_,_).
  127area(C,A--ksqmiles) :- country(C,_,_,_,A,_,_,_,_,_).
  128population(C,P--thousand) :- city(C,_,P).
  129population(C,P--million) :- country(C,_,_,_,_,_,P,_,_,_).
  130capital(C,Cap) :- country(C,_,_,_,_,_,_,_,Cap,_).
  131
  132continent(africa).
  133continent(america).
  134continent(antarctica).
  135continent(asia).
  136continent(australasia).
  137continent(europe).
  138
  139in_continent(scandinavia, europe).
  140in_continent(western_europe, europe).
  141in_continent(eastern_europe, europe).
  142in_continent(southern_europe, europe).
  143in_continent(north_america, america).
  144in_continent(central_america, america).
  145in_continent(caribbean, america).
  146in_continent(south_america, america).
  147in_continent(north_africa, africa).
  148in_continent(west_africa, africa).
  149in_continent(central_africa, africa).
  150in_continent(east_africa, africa).
  151in_continent(southern_africa, africa).
  152in_continent(middle_east,  asia).
  153in_continent(indian_subcontinent, asia).
  154in_continent(southeast_east, asia).
  155in_continent(far_east, asia).
  156in_continent(northern_asia, asia).
  157
  158seamass(X) :- ocean(X).
  159seamass(X) :- sea(X).
  160
  161ocean(arctic_ocean).
  162ocean(atlantic).
  163ocean(indian_ocean).
  164ocean(pacific).
  165ocean(southern_ocean).
  166
  167sea(baltic).
  168sea(black_sea).
  169sea(caspian).
  170sea(mediterranean).
  171sea(persian_gulf).
  172sea(red_sea).
  173
  174river(R) :- river(R,L).
  175
  176rises(R,C) :- river(R,L), last(L,C).
  177
  178drains(R,S) :- river(R,L), first(L,S).
  179
  180flows(R,C) :- flows(R,C,_).
  181
  182flows(R,C1,C2) :- river(R,L), links(L,C2,C1).
  183
  184first([X|_],X).
  185
  186% last([X],X).					% (SWI-system predicate)
  187% last([_|L],X) :- last(L,X).
  188
  189links([X1,X2|_],X1,X2).
  190links([_|L],X1,X2) :- links(L,X1,X2)