├── README.md ├── pack.pl └── prolog ├── chat80.pl └── chat80 ├── .plrc ├── .xpce └── geometry.cnf ├── CHAT.DOC ├── COPYRIGHT ├── MIT-relicense.mail ├── README ├── TODO ├── aggreg.pl ├── border.pl ├── chat.awk ├── chat.pl ├── chatops.pl ├── chattop.pl ├── cities.pl ├── clotab.pl ├── contai.pl ├── countr.pl ├── demo ├── ndtabl.pl ├── newdic.pl ├── newg.pl ├── ptree.pl ├── qplan.pl ├── readin.pl ├── rivers.pl ├── scopes.pl ├── slots.pl ├── talkr.pl ├── templa.pl ├── world0.pl └── xgrun.pl /README.md: -------------------------------------------------------------------------------- 1 | # The classical CHAT80 natural language system 2 | 3 | The CHAT80 system has been developed in the 70s and 80s by Fernando C.N. 4 | Pereira and David H.D. Warren. It implements a natural language question 5 | answering system that answers questions about the world: countries, 6 | cities, rivers, etc. It does so by parsing the question, translate the 7 | parse to a Prolog query and run this against its database. 8 | 9 | This version is derived from the original via Quintus Prolog after some 10 | compatibility modifications for SWI-Prolog and adding a module header 11 | that allows using it safely together with other applications. 12 | 13 | The code is definitely dated. Still, it provides a nice example using 14 | Prolog for parsing, assigning meaning and querying. 15 | 16 | ## Legal 17 | 18 | On August 10 2020, the code was re-licensed on request from the original 19 | authors David H. D. Warren and Fernando C. N. Pereira on request from 20 | Vijay Saraswat. CHAT-80 is now available under the MIT license. 21 | 22 | -------------------------------------------------------------------------------- /pack.pl: -------------------------------------------------------------------------------- 1 | name(chat80). 2 | version('1.1'). 3 | title('Classic CHAT80 Prolog natural language application'). 4 | keywords(['NLP', 'world']). 5 | author( 'Fernando C.N. Pereira', 'unknown@unknown' ). 6 | author( 'David H.D. Warren', 'unknown@unknown' ). 7 | packager( 'Jan Wielemaker', 'J.Wielemaker@vu.nl' ). 8 | maintainer( 'Jan Wielemaker', 'J.Wielemaker@vu.nl' ). 9 | home( 'https://github.com/JanWielemaker/chat80.git' ). 10 | download( 'https://github.com/JanWielemaker/chat80/archive/V*.zip' ). 11 | -------------------------------------------------------------------------------- /prolog/chat80.pl: -------------------------------------------------------------------------------- 1 | /* Copyright 1986-2020 David H. D. Warren, Fernando C. N. Pereira and 2 | Jan Wielemaker. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a 5 | copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | :- module(chat80, 25 | [ chat_process/2, % +Question, -Answer 26 | 27 | chat_parse/2, % +Question, -Tree 28 | chat_semantics/2, % +Tree, -Query 29 | chat_optimize/2, % +QueryIn, -Query 30 | chat_answer/2, % +Query, -Answer 31 | 32 | chat_example/3, % ?Nr, ?Sentence, ?Correct 33 | chat_print_tree/1, % +Tree 34 | 35 | test_chat/0, 36 | rtest_chats/1 % +Times 37 | ]). 38 | :- require([ (mode)/1, 39 | display/1 40 | ]). 41 | :- ensure_loaded(chat80/chat). 42 | 43 | /** CHAT80 driver for SWI-Prolog 44 | */ 45 | 46 | %! test_chat 47 | % 48 | % Run default demo suite, showing timing and warn if the answer is 49 | % incorrect. 50 | 51 | %! rtest_chats(+Times) 52 | % 53 | % Run the test suite Times times silently. Used for timing and 54 | % profiling. 55 | 56 | %! chat_process(+Question, -Answer) 57 | % 58 | % Process Question using chat80, resulting in Answer. Question is a 59 | % list of atoms expressing words. For exampple, 60 | % 61 | % ``` 62 | % ?- chat_process([what, is, the,capital, of, france, ?], A). 63 | % A = [paris]. 64 | % ``` 65 | % 66 | % @see tokenize_atom/2. 67 | 68 | chat_process(Question, Answer) :- 69 | process(Question, Answer, _Times). 70 | 71 | %! chat_parse(+Question, -Tree) 72 | % 73 | % Perform the parsing phase of CHAT80. 74 | 75 | chat_parse(Question, Tree) :- 76 | sentence(Tree,Question,[],[],[]). 77 | 78 | %! chat_semantics(+Tree, -Query) 79 | % 80 | % Translate the NLP parse tree into a Prolog query. 81 | 82 | chat_semantics(Tree, Query) :- 83 | i_sentence(Tree,QT), 84 | clausify(QT,UE), 85 | simplify(UE,Query). 86 | 87 | %! chat_optimize(+QueryIn, -Query) 88 | % 89 | % Optimize a query 90 | 91 | chat_optimize(QueryIn, Query) :- 92 | qplan(QueryIn, Query). 93 | 94 | %! chat_answer(+Query, -Answer) 95 | % 96 | % Find answers for the Query. 97 | 98 | chat_answer(Query, Answer) :- 99 | answer(Query, Answer). 100 | 101 | %! chat_print_tree(+Tree) 102 | % 103 | % Print an NLP parse tree 104 | 105 | chat_print_tree(Tree) :- 106 | print_tree(Tree). 107 | 108 | %! chat_example(?Nr, ?Sentence, ?Correct) 109 | % 110 | % True when Nr is the (integer) id of the tokenized Sentence and 111 | % Correct is the correct answer. 112 | 113 | chat_example(Nr, Sentence, Correct) :- 114 | ed(Nr, Sentence, Correct). 115 | -------------------------------------------------------------------------------- /prolog/chat80/.plrc: -------------------------------------------------------------------------------- 1 | :- ['~/.plrc']. 2 | :- [chat]. 3 | :- guitracer. 4 | 5 | t :- 6 | trace, test_chat. 7 | -------------------------------------------------------------------------------- /prolog/chat80/.xpce/geometry.cnf: -------------------------------------------------------------------------------- 1 | /* XPCE configuration file for "persistent_frame" 2 | Saved Sun Mar 26 18:32:53 2006 by jan 3 | */ 4 | 5 | configversion(1). 6 | [persistent_frame]. 7 | 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | % Option lines starting with a `%' indicate % 10 | % the value is equal to the application default. % 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | 13 | /* (X-)geometry for persistent frames */ 14 | history/geometry/xref_frame = '674x628+159+43'. 15 | history/geometry/prof_frame = '834x389+127+60'. 16 | 17 | /* Sub-window layout for persistent frames */ 18 | history/subwindow_layout/xref_frame = layout(*, [*, layout(*, [232, *]), *]). 19 | history/subwindow_layout/prof_frame = layout(*, [*, layout(*, [309, *]), *]). 20 | -------------------------------------------------------------------------------- /prolog/chat80/CHAT.DOC: -------------------------------------------------------------------------------- 1 | /* @(#)CHAT.DOC 26.1 5/13/88 */ 2 | 3 | CHAT.DOC 4 | 5 | Quintus Computer Systems, Inc. 6 | May 1988 7 | 8 | ------------------------------------------------------------ 9 | 10 | Background 11 | ---------- 12 | 13 | This directory contains a classic Prolog program developed as part of a 14 | research project at the University of Edinburgh by Fernando C.N. Pereira 15 | and David H.D. Warren. The program, Chat, was developed between 1978 16 | and 1981, with only a few modifications since that time. Chat has the 17 | disadvantage of being a research program and is not well documented and 18 | easily usable as a tutorial on Natural Language processing in Prolog. 19 | If you are interested in taking more than a cursory look at Chat, then 20 | you should obtain the following papers on the original work: 21 | 22 | Logic for Natural Language Analysis 23 | Fernando Pereira, January 1983 24 | SRI Technical Note 275 ($15) 25 | from: Technical Notes (Dori Arceo, mail stop EJ257) 26 | Artificial Intelligence Center 27 | SRI International 28 | 333 Ravenswood Avenue 29 | Menlo Park, California 94025, USA 30 | 31 | An Efficient Easily Adaptable System 32 | for Interpreting Natural Language Queries 33 | David H.D. Warren & Fernando C.N. Pereira, 34 | IJCAI-81, Vancouver, Canada, 1981 35 | 36 | Efficient Processing of Interactive Relational Database Queries 37 | Expressed in Logic 38 | David H.D. Warren 39 | Seventh International Conference on Very Large Data Bases 40 | Cannes, France, September 1981 41 | 42 | Fernando Pereira has also written a more recent text on the general 43 | topic of using Prolog for Natural Language processing: 44 | 45 | Prolog and Natural-Language Analysis 46 | Fernando C.N. Pereira & Stuart M. Shieber 47 | CLSI Lecture Notes No. 10, Stanford 1987 48 | distributed by: University of Chicago Press 49 | 50 | 51 | Quintus uses, and supplies, Chat as a good medium-size Prolog program that 52 | does something interesting and can be used for demonstrations and 53 | performance measurements. Quintus does not warrant the programs suitability 54 | for any purpose and does not support the program. Chat can be used and 55 | modified for training and research purposes, but is not supplied for use as 56 | a basis of commercial products. The copyright of this program remains with 57 | the authors, Warren and Pereira. If you make any research use of Chat you 58 | should reference the authors appropriately. 59 | 60 | 61 | Running Chat under Quintus Prolog 62 | --------------------------------- 63 | 64 | To compile Chat type: 65 | 66 | % prolog 67 | 68 | | ?- compile(chat). 69 | 70 | 71 | The following predicates can be called to run parts of Chat: 72 | 73 | | ?- hi. % prompts for questions 74 | | ?- demo(mini). % Runs a small set of demo questions 75 | | ?- demo(main). % Runs a larger set of demo questions 76 | | ?- test_chat. % Runs the large set of demo questions 77 | % and produces a table of statistics 78 | 79 | You should examine the demonstration questions to get an idea of Chat's 80 | capabilities. These are in the file 'demo' and also in 'chattop.pl'. 81 | The hi/0 predicate prompts for questions as follows: 82 | 83 | Question: 84 | 85 | Chat is now expecting a question, which should be terminated with a period 86 | or question mark. So for example: 87 | 88 | Question: Which countries bordering mexico border the pacific? 89 | 90 | Capital letters are not distinguished from lower case. If Chat does not 91 | understand a word it prompts you to re-type it (or a synonym for it). This 92 | word must be terminated with a period. 93 | 94 | Apart from questions, the following directives are accepted by Chat: 95 | 96 | Question: bye. (exits back to the Prolog top level) 97 | 98 | Question: trace. (turns on Chat's tracing mechanism) 99 | Question: do not trace. (turns off the tracing mechanism) 100 | Question: do mini demo. (calls demo(mini)) 101 | Question: do main demo. (calls demo(main)) 102 | Question: test chat. (calls test_chat) 103 | 104 | The tracing mechanism shows all the intermediate datastructures, which are: 105 | 106 | * the syntactic parse tree of the question 107 | (a large Prolog term which is pretty-printed) 108 | 109 | * the semantic interpretation of the parse tree 110 | (a Prolog-like clause) 111 | 112 | * a query-optimized version of the semantic interpretation 113 | (a Prolog-like clause which is a reordering of the 114 | previous one, alhtough it can sometimes be identical) 115 | 116 | The various statistics show the times for each stage in milliseconds. You 117 | will see that Chat is very fast at analyzing and answering questions! 118 | 119 | 120 | Compiling Chat into a Runtime Application 121 | ----------------------------------------- 122 | 123 | Chat can also be compiled into a runtime application if you have the 124 | Quintus Runtime Generator product. The chat.pl file contains all the 125 | necessary information. To "PAC" Chat into a runtime application type: 126 | 127 | % qpc -vsoi chat chatops chat 128 | 129 | This compiles chat.pl (specified by the final 'chat'). The rest of the 130 | command specifies verbose (-v) mode so that all the compiling and 131 | linking steps will be shown; the resulting executable will be stripped 132 | (-s) and will be called 'chat' (-o chat); the file chatops.pl will be 133 | included in the compilation of every Prolog file (-i chatops) - this is 134 | neccesary because chatops.pl contains essential operators definitions. 135 | The resulting program can then be run by typing: 136 | 137 | % chat 138 | 139 | The program will then prompt with "Question:", since when Chat is run as 140 | a runtime application, runtime_entry/1 always calls hi/0. The special 141 | directives listed above can be used to call the demonstration predicates 142 | if desired. 143 | 144 | 145 | Using Chat for Benchmarking 146 | --------------------------- 147 | 148 | Also supplied is an AWK script which might prove useful when comparing 149 | two sets of data from Chat - maybe from Chat running on two different 150 | machines. On a Unix system this would be used as follows: 151 | 152 | % awk -f chat.awk data_a data_b 153 | 154 | where data_a and data_b are files which just contain the data lines 155 | printed by Chat for the 23 questions (no headings or blank lines). The 156 | awk script prints out a RATIO table with the same form as the data_a and 157 | data_b tables which shows the speed increase from data_a to data_b. 158 | 159 | -------------------------------------------------------------------------------- /prolog/chat80/COPYRIGHT: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /prolog/chat80/MIT-relicense.mail: -------------------------------------------------------------------------------- 1 | Mail from Fernando Pereira giving permission 2 | to change the license for CHAT-80. Included as proof. 3 | 4 | Return-Path: fernando.pereira@gmail.com 5 | Received: from localhost (LHLO mail.cwi.nl) (127.0.0.1) by mail.cwi.nl with 6 | LMTP; Sun, 9 Aug 2020 04:41:07 +0200 (CEST) 7 | Received: from localhost (localhost [127.0.0.1]) 8 | by mail.cwi.nl (Postfix) with ESMTP id 03B7539253 9 | for ; Sun, 9 Aug 2020 04:41:07 +0200 (CEST) 10 | Authentication-Results: mail.cwi.nl (amavisd-new); dkim=pass (2048-bit key) 11 | header.d=gmail.com 12 | Received: from mail.cwi.nl ([127.0.0.1]) 13 | by localhost (mail.cwi.nl [127.0.0.1]) (amavisd-new, port 10024) 14 | with ESMTP id 2qvODkkn7M4Y for ; 15 | Sun, 9 Aug 2020 04:41:06 +0200 (CEST) 16 | Received: from fester.cwi.nl (fester.cwi.nl [192.16.191.27]) 17 | by mail.cwi.nl (Postfix) with ESMTPS id A25E739170 18 | for ; Sun, 9 Aug 2020 04:41:06 +0200 (CEST) 19 | Received: from filter2-til.mf.surf.net (filter2-til.mf.surf.net [194.171.167.218]) 20 | by fester.cwi.nl (8.14.4/8.12.3) with ESMTP id 0792f67f011999 21 | for ; Sun, 9 Aug 2020 04:41:06 +0200 22 | Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) 23 | by filter2-til.mf.surf.net (8.14.4/8.14.4/Debian-8+deb8u2) with ESMTP id 0792f4lt145911 24 | (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) 25 | for ; Sun, 9 Aug 2020 04:41:05 +0200 26 | Received: by mail-vk1-xa29.google.com with SMTP id x2so1178411vkd.8 27 | for ; Sat, 08 Aug 2020 19:41:05 -0700 (PDT) 28 | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; 29 | d=gmail.com; s=20161025; 30 | h=mime-version:from:date:message-id:subject:to:cc; 31 | bh=NPMXJXSdcFYbo9JCuRmkFmTJFj6dZn7k4ce9yf1UJ+A=; 32 | b=rKiu5PT4A5zn2g41odt0Ot78B6s8hGZnn6ACZ9kToeYIs/H/+zNNR3lifM6ivB+l8e 33 | QSlABPqqFrsOmVX7X2QdbKPukWCNkFVTPRjM5mhD6I4DJAVBarQcQ2nPZiCEZRhnfUPs 34 | XnnijzKxtkR8/3ZIKQycPg7O7YTPkTQ1ht4fa+E6ikJZEtUC/TnL7h5AJLaEzucEk3A4 35 | 9PLsZbB0Ee7wi0JKYqxpbvBwG/zx6gfxthiK88NxawiZeLg4+eQCmmYfD+/YZtk3F86q 36 | 0+lbb1VfoteEAfb4gNHQswsvRbbJU2J4bauCQc7mjERhGr3tNZfhme57I14r13PAc4Et 37 | cZsw== 38 | X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; 39 | d=1e100.net; s=20161025; 40 | h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; 41 | bh=NPMXJXSdcFYbo9JCuRmkFmTJFj6dZn7k4ce9yf1UJ+A=; 42 | b=UG0q3PGhicAovWy0hQrS5P/MppcqvWYgkQUz4nEUuJodSazq7LTi0C5DQ04V3hW7Gi 43 | LZI7tFzYBHGeibzFHOpna/GHxMG+OFdM7L0S+8ut4nYmA7ArhFuABpuShDxEQvPam0hf 44 | Kuuay4UfsVi9JJULc4IQZFTS1rhr+u/1FEI3g7gp3XCCsAQ0IPCsccf6H2b+12GxwYam 45 | fLY27Tviye0BN/y6nfHcssaqJwwGMb6YpWBugAWjfHEtOH2PHVfYdmx2xv8YJHkH/peB 46 | aJservtaWStRH8y0Lcfb1PKLQ0Kiuvv7MnxmX02eQRda0x2DiZ9AUo6oa0v7reQ/DwuK 47 | GhKg== 48 | X-Gm-Message-State: AOAM532P0h8ljazEFEXZ0cru0v4ZJjdc0vWvA8qcVRAQV5Qo0yitnEG3 49 | dxA0Lfrg2OijXHsPrDuECwRChRFeUpt5aoXhwsstTWkzAA== 50 | X-Google-Smtp-Source: ABdhPJxGI3OU2oofZb1LPQuzk0hqOOzmuUHdUb7GQmKKhoasv0PbTvzHyba4YHWEjqJqo4MGpT+1XTsd61mJxUm5gSU= 51 | X-Received: by 2002:a1f:3d97:: with SMTP id k145mr16412905vka.8.1596940863676; 52 | Sat, 08 Aug 2020 19:41:03 -0700 (PDT) 53 | MIME-Version: 1.0 54 | From: Fernando Pereira 55 | Date: Sat, 8 Aug 2020 19:40:52 -0700 56 | Message-ID: 57 | Subject: Chat-80 license 58 | To: J.Wielemaker@cwi.nl 59 | Cc: Vijay Saraswat , 60 | David Warren 61 | Content-Type: multipart/alternative; boundary="000000000000e8266e05ac68c43a" 62 | X-Spam-Score: -0.19 () [Tag at 5.00] FREEMAIL_FROM:0.001,HTML_MESSAGE:0.001,T_KAM_HTML_FONT_INVALID:0.01,SPF(pass:-0.2),DKIM(pass:0),DMARC(DMARC_POLICY_PASS:dry-run) 63 | X-CanIt-Geo: ip=2607:f8b0:4864:20::a29; country=US; latitude=37.7510; longitude=-97.8220; http://maps.google.com/maps?q=37.7510,-97.8220&z=6 64 | X-CanItPRO-Stream: cwi:j.wielemaker@cwi.nl (inherits from cwi:cwi-default,cwi:default,base:default) 65 | Received-SPF: pass (filter2-til.mf.surf.net: domain of fernando.pereira@gmail.com 66 | designates 2607:f8b0:4864:20::a29 as permitted sender) 67 | receiver=filter2-til.mf.surf.net; client-ip=2607:f8b0:4864:20::a29; 68 | envelope-from=; helo=mail-vk1-xa29.google.com; 69 | identity=mailfrom 70 | X-Scanned-By: CanIt (www . roaringpenguin . com) 71 | 72 | --000000000000e8266e05ac68c43a 73 | Content-Type: text/plain; charset="UTF-8" 74 | 75 | Hi Jan, 76 | 77 | I hope all is well. 78 | 79 | Vijay Saraswat wrote to me recently asking whether Chat-80, which you have 80 | ported to SWI-Prolog, could have a more industry-friendly license. I 81 | checked with my local OSS license expert, and he recommended the MIT 82 | license. David and I would appreciate it if you could change the 83 | kind-of-license on GitHub with the one below. 84 | 85 | Best wishes 86 | 87 | -- Fernando 88 | 89 | Copyright 2020 David H. D. Warren and Fernando C. N. Pereira 90 | 91 | Permission is hereby granted, free of charge, to any person obtaining a 92 | copy of this software and associated documentation files (the "Software"), 93 | to deal in the Software without restriction, including without limitation 94 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 95 | and/or sell copies of the Software, and to permit persons to whom the 96 | Software is furnished to do so, subject to the following conditions: 97 | 98 | The above copyright notice and this permission notice shall be included in 99 | all copies or substantial portions of the Software. 100 | 101 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 102 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 103 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 104 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 105 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 106 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 107 | DEALINGS IN THE SOFTWARE. 108 | 109 | --000000000000e8266e05ac68c43a 110 | Content-Type: text/html; charset="UTF-8" 111 | Content-Transfer-Encoding: quoted-printable 112 | 113 |
Hi Jan,

I hope all is well.=C2=A0
= 114 |

Vijay Saraswat wrote to me recently asking whether Chat= 115 | -80, which you have ported to SWI-Prolog, could have a more industry-friend= 116 | ly license. I checked with my local OSS license expert, and he recommended = 117 | the MIT license. David and I would appreciate it if you could change the ki= 118 | nd-of-license on GitHub with the one below.

Best w= 119 | ishes

-- Fernando

Copyright 2020 David H. D. Warren and Fernando = 126 | C. N. Pereira

Permission is her= 131 | eby granted, free of charge, to any person obtaining a copy of this softwar= 132 | e and associated documentation files (the "Software"), to deal in= 133 | the Software without restriction, including without limitation the rights = 134 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell c= 135 | opies of the Software, and to permit persons to whom the Software is furnis= 136 | hed to do so, subject to the following conditions:

The above copyright notice and this permission notice s= 142 | hall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WA= 148 | RRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WA= 149 | RRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRIN= 150 | GEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR AN= 151 | Y CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT= 152 | OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR T= 153 | HE USE OR OTHER DEALINGS IN THE SOFTWARE.


155 | 156 | --000000000000e8266e05ac68c43a-- 157 | -------------------------------------------------------------------------------- /prolog/chat80/README: -------------------------------------------------------------------------------- 1 | /* @(#)README 24.1 4/13/88 */ 2 | 3 | This README file is a simple description about how to run the 4 | programs in this directory. Read BENCH.DOC for a better 5 | description. 6 | 7 | To run chat: 8 | 9 | | ?- compile(chat). 10 | ....... 11 | | ?- demo(mini). % Runs a small set of demo questions 12 | | ?- demo(main). % Runs a larger set of demo questions 13 | | ?- test_chat. % Runs the large set of demo questions 14 | % and produces a table of statistics 15 | 16 | or you can run chat interactively by giving the goal 17 | | ?- hi. % prompts for questions 18 | then gives you the prompt 19 | 20 | Question: 21 | 22 | Chat is now expecting a question. E.g. 23 | 24 | Question: where is France? 25 | 26 | Capital letters are not distinguished from lower case. If Chat does not 27 | understand a word it prompts you to re-type it (or a synonym for it). This 28 | word must be terminated with a period. 29 | 30 | Apart from questions, the following directives are accepted by Chat: 31 | 32 | Question: bye. (exits back to the Prolog top level) 33 | 34 | Question: trace. (turns on Chat's tracing mechanism) 35 | Question: do not trace. (turns off the tracing mechanism) 36 | Question: do mini demo. (calls demo(mini)) 37 | Question: do main demo. (calls demo(main)) 38 | Question: test chat. (calls test_chat) 39 | -------------------------------------------------------------------------------- /prolog/chat80/TODO: -------------------------------------------------------------------------------- 1 | * Normalisation of clauses that are lost in the compiler: 2 | 3 | - (a | b) --> (a ; b) 4 | - (a, b), c --> a, b, c. 5 | - a :- true --> a. 6 | 7 | I.e. the unify_clause code. 8 | -------------------------------------------------------------------------------- /prolog/chat80/aggreg.pl: -------------------------------------------------------------------------------- 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 | :- public aggregate/3, one_of/2, ratio/3, card/2. 24 | 25 | :- mode aggregate(+,+,?), 26 | dimensioned(+), 27 | one_of(+,?), 28 | i_aggr(+,+,?), 29 | u_aggr(+,+,?), 30 | i_total(+,?), 31 | i_maxs(+,?), 32 | i_mins(+,?), 33 | i_maxs0(+,+,+,?,?), 34 | i_mins0(+,+,+,?,?), 35 | u_total(+,?), 36 | u_sum(+,+,?), 37 | u_maxs(+,?), 38 | u_mins(+,?), 39 | i_maxs0(+,+,+,?,?), 40 | i_mins0(+,+,+,?,?), 41 | u_lt(+,+). 42 | 43 | aggregate(Fn,Set,Val) :- 44 | dimensioned(Set), !, 45 | u_aggr(Fn,Set,Val). 46 | aggregate(Fn,Set,Val) :- 47 | i_aggr(Fn,Set,Val). 48 | 49 | i_aggr(average,Set,Val) :- 50 | i_total(Set,T), 51 | length(Set,N), 52 | Val is T//N. 53 | i_aggr(total,Set,Val) :- 54 | i_total(Set,Val). 55 | i_aggr(max,Set,Val) :- 56 | i_maxs(Set,List), 57 | one_of(List,Val). 58 | i_aggr(min,Set,Val) :- 59 | i_mins(Set,List), 60 | one_of(List,Val). 61 | i_aggr(maximum,[V0:O|S],V) :- 62 | i_maxs0(S,V0,[O],_,V). 63 | i_aggr(minimum,[V0:O|S],V) :- 64 | i_mins0(S,V0,[O],_,V). 65 | 66 | u_aggr(average,Set,V--U) :- 67 | u_total(Set,T--U), 68 | length(Set,N), 69 | V is T//N. 70 | u_aggr(total,Set,Val) :- 71 | u_total(Set,Val). 72 | u_aggr(max,Set,Val) :- 73 | u_maxs(Set,List), 74 | one_of(List,Val). 75 | u_aggr(min,Set,Val) :- 76 | u_mins(Set,List), 77 | one_of(List,Val). 78 | u_aggr(maximum,[V0:O|S],V) :- 79 | u_maxs0(S,V0,[O],_,V). 80 | u_aggr(minimum,[V0:O|S],V) :- 81 | u_mins0(S,V0,[O],_,V). 82 | 83 | i_total([],0). 84 | i_total([V:_|R],T) :- 85 | i_total(R,T0), 86 | T is V+T0. 87 | 88 | i_maxs([V:X|Set],List) :- 89 | i_maxs0(Set,V,[X],List,_). 90 | 91 | i_maxs0([],V,L,L,V). 92 | i_maxs0([V0:X|R],V0,L0,L,V) :- !, 93 | i_maxs0(R,V0,[X|L0],L,V). 94 | i_maxs0([U:X|R],V,_,L,W) :- 95 | U>V, !, 96 | i_maxs0(R,U,[X],L,W). 97 | i_maxs0([_|R],V,L0,L,W) :- 98 | i_maxs0(R,V,L0,L,W). 99 | 100 | i_mins([V:X|Set],List) :- 101 | i_mins0(Set,V,[X],List,_). 102 | 103 | i_mins0([],V,L,L,V). 104 | i_mins0([V:X|R],V,L0,L,W) :- !, 105 | i_mins0(R,V,[X|L0],L,W). 106 | i_mins0([U:X|R],V,_,L,W) :- 107 | UM1, !, 121 | Z is X + (Y*M1)//M. 122 | u_sum(X--U1,Y--U,Z--U) :- 123 | ratio(U,U1,M,M1), M>M1, !, 124 | Z is (X*M1)//M + Y. 125 | 126 | u_maxs([V:X|Set],List) :- 127 | u_maxs0(Set,V,[X],List,_). 128 | 129 | u_maxs0([],V,L,L,V). 130 | u_maxs0([V0:X|R],V0,L0,L,V) :- !, 131 | u_maxs0(R,V0,[X|L0],L,V). 132 | u_maxs0([U:X|R],V,_,L,W) :- 133 | u_lt(V,U), !, 134 | u_maxs0(R,U,[X],L,W). 135 | u_maxs0([_|R],V,L0,L,W) :- 136 | u_maxs0(R,V,L0,L,W). 137 | 138 | u_mins([V:X|Set],List) :- 139 | u_mins0(Set,V,[X],List,_). 140 | 141 | u_mins0([],V,L,L,V). 142 | u_mins0([V:X|R],V,L0,L,W) :- !, 143 | u_mins0(R,V,[X|L0],L,W). 144 | u_mins0([U:X|R],V,_,L,W) :- 145 | u_lt(U,V), !, 146 | u_mins0(R,U,[X],L,W). 147 | u_mins0([_|R],V,L0,L,W) :- 148 | u_mins0(R,V,L0,L,W). 149 | 150 | u_lt(A,X--U) :- 151 | Y is -X, 152 | u_sum(A,Y--U,Z--_), 153 | Z<0. 154 | 155 | dimensioned([(_--_):_|_]). 156 | 157 | one_of([X|_],X). 158 | one_of([_|R],X) :- 159 | one_of(R,X). 160 | 161 | ratio(N,M,R) :- R is (N*100)//M. 162 | 163 | card(S,N) :- length(S,N). 164 | 165 | 166 | -------------------------------------------------------------------------------- /prolog/chat80/border.pl: -------------------------------------------------------------------------------- 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 | % Facts about Europe. 24 | % ------------------ 25 | 26 | borders(X,C) :- var(X), nonvar(C), !, borders(C,X). 27 | 28 | borders(albania,greece). 29 | borders(albania,yugoslavia). 30 | borders(albania,mediterranean). 31 | 32 | borders(andorra,france). 33 | borders(andorra,spain). 34 | 35 | borders(austria,czechoslovakia). 36 | borders(austria,hungary). 37 | borders(austria,italy). 38 | borders(austria,liechtenstein). 39 | borders(austria,switzerland). 40 | borders(austria,west_germany). 41 | borders(austria,yugoslavia). 42 | 43 | borders(belgium,france). 44 | borders(belgium,luxembourg). 45 | borders(belgium,netherlands). 46 | borders(belgium,west_germany). 47 | borders(belgium,atlantic). 48 | 49 | borders(bulgaria,greece). 50 | borders(bulgaria,romania). 51 | borders(bulgaria,turkey). 52 | borders(bulgaria,yugoslavia). 53 | borders(bulgaria,black_sea). 54 | 55 | borders(cyprus,mediterranean). 56 | 57 | borders(czechoslovakia,austria). 58 | borders(czechoslovakia,east_germany). 59 | borders(czechoslovakia,hungary). 60 | borders(czechoslovakia,poland). 61 | borders(czechoslovakia,soviet_union). 62 | borders(czechoslovakia,west_germany). 63 | 64 | borders(denmark,west_germany). 65 | borders(denmark,atlantic). 66 | borders(denmark,baltic). 67 | 68 | borders(eire,united_kingdom). 69 | borders(eire,atlantic). 70 | 71 | borders(finland,norway). 72 | borders(finland,soviet_union). 73 | borders(finland,sweden). 74 | borders(finland,baltic). 75 | 76 | borders(france,andorra). 77 | borders(france,belgium). 78 | borders(france,italy). 79 | borders(france,luxembourg). 80 | borders(france,monaco). 81 | borders(france,spain). 82 | borders(france,switzerland). 83 | borders(france,west_germany). 84 | borders(france,atlantic). 85 | borders(france,mediterranean). 86 | 87 | borders(east_germany,czechoslovakia). 88 | borders(east_germany,poland). 89 | borders(east_germany,west_germany). 90 | borders(east_germany,baltic). 91 | 92 | borders(greece,albania). 93 | borders(greece,bulgaria). 94 | borders(greece,turkey). 95 | borders(greece,yugoslavia). 96 | borders(greece,mediterranean). 97 | 98 | borders(hungary,austria). 99 | borders(hungary,czechoslovakia). 100 | borders(hungary,romania). 101 | borders(hungary,soviet_union). 102 | borders(hungary,yugoslavia). 103 | 104 | borders(iceland,atlantic). 105 | 106 | borders(italy,austria). 107 | borders(italy,france). 108 | borders(italy,san_marino). 109 | borders(italy,switzerland). 110 | borders(italy,yugoslavia). 111 | borders(italy,mediterranean). 112 | 113 | borders(liechtenstein,austria). 114 | borders(liechtenstein,switzerland). 115 | 116 | borders(luxembourg,belgium). 117 | borders(luxembourg,france). 118 | borders(luxembourg,west_germany). 119 | 120 | borders(malta,mediterranean). 121 | 122 | borders(monaco,france). 123 | borders(monaco,mediterranean). 124 | 125 | borders(netherlands,belgium). 126 | borders(netherlands,west_germany). 127 | borders(netherlands,atlantic). 128 | 129 | borders(norway,finland). 130 | borders(norway,sweden). 131 | borders(norway,soviet_union). 132 | borders(norway,arctic_ocean). 133 | borders(norway,atlantic). 134 | 135 | borders(poland,czechoslovakia). 136 | borders(poland,east_germany). 137 | borders(poland,soviet_union). 138 | borders(poland,baltic). 139 | 140 | borders(portugal,spain). 141 | borders(portugal,atlantic). 142 | 143 | borders(romania,bulgaria). 144 | borders(romania,hungary). 145 | borders(romania,soviet_union). 146 | borders(romania,yugoslavia). 147 | borders(romania,black_sea). 148 | 149 | borders(san_marino,italy). 150 | borders(san_marino,mediterranean). 151 | 152 | borders(spain,andorra). 153 | borders(spain,france). 154 | borders(spain,portugal). 155 | borders(spain,atlantic). 156 | borders(spain,mediterranean). 157 | 158 | borders(sweden,finland). 159 | borders(sweden,norway). 160 | borders(sweden,atlantic). 161 | borders(sweden,baltic). 162 | 163 | borders(switzerland,austria). 164 | borders(switzerland,france). 165 | borders(switzerland,italy). 166 | borders(switzerland,liechtenstein). 167 | borders(switzerland,west_germany). 168 | 169 | borders(west_germany,austria). 170 | borders(west_germany,belgium). 171 | borders(west_germany,czechoslovakia). 172 | borders(west_germany,denmark). 173 | borders(west_germany,east_germany). 174 | borders(west_germany,france). 175 | borders(west_germany,luxembourg). 176 | borders(west_germany,netherlands). 177 | borders(west_germany,switzerland). 178 | borders(west_germany,atlantic). 179 | borders(west_germany,baltic). 180 | 181 | borders(united_kingdom,eire). 182 | borders(united_kingdom,atlantic). 183 | 184 | borders(yugoslavia,albania). 185 | borders(yugoslavia,austria). 186 | borders(yugoslavia,bulgaria). 187 | borders(yugoslavia,greece). 188 | borders(yugoslavia,hungary). 189 | borders(yugoslavia,italy). 190 | borders(yugoslavia,romania). 191 | borders(yugoslavia,mediterranean). 192 | 193 | % Facts about Asia. 194 | % ---------------- 195 | 196 | borders(afghanistan,china). 197 | borders(afghanistan,iran). 198 | borders(afghanistan,pakistan). 199 | borders(afghanistan,soviet_union). 200 | 201 | borders(bahrain,persian_gulf). 202 | 203 | borders(bangladesh,burma). 204 | borders(bangladesh,india). 205 | borders(bangladesh,indian_ocean). 206 | 207 | borders(bhutan,china). 208 | borders(bhutan,india). 209 | 210 | borders(burma,bangladesh). 211 | borders(burma,china). 212 | borders(burma,india). 213 | borders(burma,laos). 214 | borders(burma,thailand). 215 | borders(burma,indian_ocean). 216 | 217 | borders(cambodia,laos). 218 | borders(cambodia,thailand). 219 | borders(cambodia,vietnam). 220 | borders(cambodia,pacific). 221 | 222 | borders(china,afghanistan). 223 | borders(china,bhutan). 224 | borders(china,burma). 225 | borders(china,india). 226 | borders(china,laos). 227 | borders(china,mongolia). 228 | borders(china,nepal). 229 | borders(china,north_korea). 230 | borders(china,pakistan). 231 | borders(china,soviet_union). 232 | borders(china,vietnam). 233 | borders(china,pacific). 234 | 235 | borders(india,bangladesh). 236 | borders(india,bhutan). 237 | borders(india,burma). 238 | borders(india,china). 239 | borders(india,nepal). 240 | borders(india,pakistan). 241 | borders(india,indian_ocean). 242 | 243 | borders(indonesia,malaysia). 244 | borders(indonesia,papua_new_guinea). 245 | borders(indonesia,indian_ocean). 246 | borders(indonesia,pacific). 247 | 248 | borders(iran,afghanistan). 249 | borders(iran,iraq). 250 | borders(iran,pakistan). 251 | borders(iran,soviet_union). 252 | borders(iran,turkey). 253 | borders(iran,caspian). 254 | borders(iran,persian_gulf). 255 | borders(iran,indian_ocean). 256 | 257 | borders(iraq,iran). 258 | borders(iraq,jordan). 259 | borders(iraq,kuwait). 260 | borders(iraq,saudi_arabia). 261 | borders(iraq,syria). 262 | borders(iraq,turkey). 263 | borders(iraq,persian_gulf). 264 | 265 | borders(israel,egypt). 266 | borders(israel,jordan). 267 | borders(laos,burma). 268 | borders(laos,cambodia). 269 | borders(laos,china). 270 | borders(laos,thailand). 271 | borders(laos,vietnam). 272 | 273 | borders(israel,lebanon). 274 | borders(israel,syria). 275 | borders(israel,mediterranean). 276 | borders(israel,red_sea). 277 | 278 | borders(japan,pacific). 279 | 280 | borders(jordan,iraq). 281 | borders(jordan,israel). 282 | borders(jordan,saudi_arabia). 283 | borders(jordan,syria). 284 | borders(jordan,red_sea). 285 | 286 | borders(kuwait,iraq). 287 | borders(kuwait,saudi_arabia). 288 | borders(kuwait,persian_gulf). 289 | 290 | borders(lebanon,israel). 291 | borders(lebanon,syria). 292 | borders(lebanon,mediterranean). 293 | 294 | borders(malaysia,indonesia). 295 | borders(malaysia,singapore). 296 | borders(malaysia,thailand). 297 | borders(malaysia,indian_ocean). 298 | borders(malaysia,pacific). 299 | 300 | borders(maldives,indian_ocean). 301 | 302 | borders(mongolia,china). 303 | borders(mongolia,soviet_union). 304 | 305 | borders(nepal,china). 306 | borders(nepal,india). 307 | 308 | borders(north_korea,china). 309 | borders(north_korea,south_korea). 310 | borders(north_korea,soviet_union). 311 | borders(north_korea,pacific). 312 | 313 | borders(oman,saudi_arabia). 314 | borders(oman,united_arab_emirates). 315 | borders(oman,south_yemen). 316 | borders(oman,indian_ocean). 317 | 318 | borders(pakistan,afghanistan). 319 | borders(pakistan,china). 320 | borders(pakistan,india). 321 | borders(pakistan,iran). 322 | borders(pakistan,indian_ocean). 323 | 324 | borders(philippines,pacific). 325 | 326 | borders(qatar,saudi_arabia). 327 | borders(qatar,united_arab_emirates). 328 | borders(qatar,persian_gulf). 329 | 330 | borders(saudi_arabia,iraq). 331 | borders(saudi_arabia,jordan). 332 | borders(saudi_arabia,kuwait). 333 | borders(saudi_arabia,oman). 334 | borders(saudi_arabia,qatar). 335 | borders(saudi_arabia,south_yemen). 336 | borders(saudi_arabia,united_arab_emirates). 337 | borders(saudi_arabia,yemen). 338 | borders(saudi_arabia,persian_gulf). 339 | borders(saudi_arabia,red_sea). 340 | 341 | borders(singapore,malaysia). 342 | borders(singapore,pacific). 343 | 344 | borders(south_korea,north_korea). 345 | borders(south_korea,pacific). 346 | 347 | borders(south_yemen,oman). 348 | borders(south_yemen,saudi_arabia). 349 | borders(south_yemen,yemen). 350 | borders(south_yemen,indian_ocean). 351 | 352 | borders(soviet_union,afghanistan). 353 | borders(soviet_union,china). 354 | borders(soviet_union,czechoslovakia). 355 | borders(soviet_union,finland). 356 | borders(soviet_union,hungary). 357 | borders(soviet_union,iran). 358 | borders(soviet_union,mongolia). 359 | borders(soviet_union,north_korea). 360 | borders(soviet_union,norway). 361 | borders(soviet_union,poland). 362 | borders(soviet_union,romania). 363 | borders(soviet_union,turkey). 364 | borders(soviet_union,arctic_ocean). 365 | borders(soviet_union,baltic). 366 | borders(soviet_union,black_sea). 367 | borders(soviet_union,caspian). 368 | borders(soviet_union,pacific). 369 | 370 | borders(sri_lanka,indian_ocean). 371 | 372 | borders(syria,iraq). 373 | borders(syria,israel). 374 | borders(syria,jordan). 375 | borders(syria,lebanon). 376 | borders(syria,turkey). 377 | borders(syria,mediterranean). 378 | 379 | borders(taiwan,pacific). 380 | 381 | borders(thailand,burma). 382 | borders(thailand,cambodia). 383 | borders(thailand,laos). 384 | borders(thailand,malaysia). 385 | borders(thailand,indian_ocean). 386 | borders(thailand,pacific). 387 | 388 | borders(turkey,bulgaria). 389 | borders(turkey,greece). 390 | borders(turkey,iran). 391 | borders(turkey,iraq). 392 | borders(turkey,soviet_union). 393 | borders(turkey,syria). 394 | borders(turkey,black_sea). 395 | borders(turkey,mediterranean). 396 | 397 | borders(united_arab_emirates,oman). 398 | borders(united_arab_emirates,qatar). 399 | borders(united_arab_emirates,saudi_arabia). 400 | borders(united_arab_emirates,persian_gulf). 401 | 402 | borders(vietnam,cambodia). 403 | borders(vietnam,china). 404 | borders(vietnam,laos). 405 | borders(vietnam,pacific). 406 | 407 | borders(yemen,south_yemen). 408 | borders(yemen,saudi_arabia). 409 | borders(yemen,red_sea). 410 | 411 | % Facts about Africa. 412 | % ------------------ 413 | 414 | borders(algeria,libya). 415 | borders(algeria,mali). 416 | borders(algeria,mauritania). 417 | borders(algeria,morocco). 418 | borders(algeria,niger). 419 | borders(algeria,tunisia). 420 | borders(algeria,mediterranean). 421 | 422 | borders(angola,congo). 423 | borders(angola,south_africa). 424 | borders(angola,zaire). 425 | borders(angola,zambia). 426 | borders(angola,atlantic). 427 | 428 | borders(botswana,south_africa). 429 | borders(botswana,zimbabwe). 430 | 431 | borders(burundi,rwanda). 432 | borders(burundi,tanzania). 433 | borders(burundi,zaire). 434 | 435 | borders(cameroon,central_african_republic). 436 | borders(cameroon,chad). 437 | borders(cameroon,congo). 438 | borders(cameroon,equatorial_guinea). 439 | borders(cameroon,gabon). 440 | borders(cameroon,nigeria). 441 | borders(cameroon,atlantic). 442 | 443 | borders(central_african_republic,cameroon). 444 | borders(central_african_republic,chad). 445 | borders(central_african_republic,congo). 446 | borders(central_african_republic,sudan). 447 | borders(central_african_republic,zaire). 448 | 449 | borders(chad,cameroon). 450 | borders(chad,central_african_republic). 451 | borders(chad,libya). 452 | borders(chad,niger). 453 | borders(chad,nigeria). 454 | borders(chad,sudan). 455 | 456 | borders(congo,angola). 457 | borders(congo,cameroon). 458 | borders(congo,central_african_republic). 459 | borders(congo,gabon). 460 | borders(congo,zaire). 461 | borders(congo,atlantic). 462 | 463 | borders(dahomey,niger). 464 | borders(dahomey,nigeria). 465 | borders(dahomey,togo). 466 | borders(dahomey,upper_volta). 467 | borders(dahomey,atlantic). 468 | 469 | borders(djibouti,ethiopia). 470 | borders(djibouti,somalia). 471 | borders(djibouti,indian_ocean). 472 | 473 | borders(egypt,israel). 474 | borders(egypt,libya). 475 | borders(egypt,sudan). 476 | borders(egypt,mediterranean). 477 | borders(egypt,red_sea). 478 | 479 | borders(equatorial_guinea,cameroon). 480 | borders(equatorial_guinea,gabon). 481 | borders(equatorial_guinea,atlantic). 482 | 483 | borders(ethiopia,djibouti). 484 | borders(ethiopia,kenya). 485 | borders(ethiopia,somalia). 486 | borders(ethiopia,sudan). 487 | borders(ethiopia,red_sea). 488 | 489 | borders(gabon,cameroon). 490 | borders(gabon,congo). 491 | borders(gabon,equatorial_guinea). 492 | borders(gabon,atlantic). 493 | 494 | borders(gambia,senegal). 495 | borders(gambia,atlantic). 496 | 497 | borders(ghana,ivory_coast). 498 | borders(ghana,togo). 499 | borders(ghana,upper_volta). 500 | borders(ghana,atlantic). 501 | 502 | borders(guinea,guinea_bissau). 503 | borders(guinea,ivory_coast). 504 | borders(guinea,liberia). 505 | borders(guinea,mali). 506 | borders(guinea,senegal). 507 | borders(guinea,sierra_leone). 508 | borders(guinea,atlantic). 509 | 510 | borders(guinea_bissau,guinea). 511 | borders(guinea_bissau,senegal). 512 | borders(guinea_bissau,atlantic). 513 | 514 | borders(ivory_coast,ghana). 515 | borders(ivory_coast,guinea). 516 | borders(ivory_coast,liberia). 517 | borders(ivory_coast,mali). 518 | borders(ivory_coast,upper_volta). 519 | borders(ivory_coast,atlantic). 520 | 521 | borders(kenya,ethiopia). 522 | borders(kenya,somalia). 523 | borders(kenya,sudan). 524 | borders(kenya,tanzania). 525 | borders(kenya,uganda). 526 | borders(kenya,indian_ocean). 527 | 528 | borders(lesotho,south_africa). 529 | 530 | borders(liberia,ivory_coast). 531 | borders(liberia,guinea). 532 | borders(liberia,sierra_leone). 533 | borders(liberia,atlantic). 534 | 535 | borders(libya,algeria). 536 | borders(libya,chad). 537 | borders(libya,egypt). 538 | borders(libya,niger). 539 | borders(libya,sudan). 540 | borders(libya,tunisia). 541 | borders(libya,mediterranean). 542 | 543 | borders(malagasy,indian_ocean). 544 | 545 | borders(malawi,mozambique). 546 | borders(malawi,tanzania). 547 | borders(malawi,zambia). 548 | 549 | borders(mali,algeria). 550 | borders(mali,guinea). 551 | borders(mali,ivory_coast). 552 | borders(mali,mauritania). 553 | borders(mali,niger). 554 | borders(mali,senegal). 555 | borders(mali,upper_volta). 556 | 557 | borders(mauritania,algeria). 558 | borders(mauritania,mali). 559 | borders(mauritania,morocco). 560 | borders(mauritania,senegal). 561 | borders(mauritania,atlantic). 562 | 563 | borders(mauritius,indian_ocean). 564 | 565 | borders(morocco,algeria). 566 | borders(morocco,mauritania). 567 | borders(morocco,atlantic). 568 | borders(morocco,mediterranean). 569 | 570 | borders(mozambique,malawi). 571 | borders(mozambique,south_africa). 572 | borders(mozambique,swaziland). 573 | borders(mozambique,tanzania). 574 | borders(mozambique,zambia). 575 | borders(mozambique,zimbabwe). 576 | borders(mozambique,indian_ocean). 577 | 578 | borders(niger,algeria). 579 | borders(niger,chad). 580 | borders(niger,dahomey). 581 | borders(niger,libya). 582 | borders(niger,mali). 583 | borders(niger,nigeria). 584 | borders(niger,upper_volta). 585 | 586 | borders(nigeria,cameroon). 587 | borders(nigeria,chad). 588 | borders(nigeria,dahomey). 589 | borders(nigeria,niger). 590 | borders(nigeria,atlantic). 591 | 592 | borders(rwanda,burundi). 593 | borders(rwanda,tanzania). 594 | borders(rwanda,uganda). 595 | borders(rwanda,zaire). 596 | 597 | borders(senegal,gambia). 598 | borders(senegal,guinea). 599 | borders(senegal,guinea_bissau). 600 | borders(senegal,mali). 601 | borders(senegal,mauritania). 602 | borders(senegal,atlantic). 603 | 604 | borders(seychelles,indian_ocean). 605 | 606 | borders(sierra_leone,guinea). 607 | borders(sierra_leone,liberia). 608 | borders(sierra_leone,atlantic). 609 | 610 | borders(somalia,djibouti). 611 | borders(somalia,ethiopia). 612 | borders(somalia,kenya). 613 | borders(somalia,indian_ocean). 614 | 615 | borders(south_africa,angola). 616 | borders(south_africa,botswana). 617 | borders(south_africa,lesotho). 618 | borders(south_africa,mozambique). 619 | borders(south_africa,swaziland). 620 | borders(south_africa,zambia). 621 | borders(south_africa,zimbabwe). 622 | borders(south_africa,atlantic). 623 | borders(south_africa,indian_ocean). 624 | 625 | borders(sudan,chad). 626 | borders(sudan,central_african_republic). 627 | borders(sudan,egypt). 628 | borders(sudan,ethiopia). 629 | borders(sudan,kenya). 630 | borders(sudan,libya). 631 | borders(sudan,uganda). 632 | borders(sudan,zaire). 633 | borders(sudan,red_sea). 634 | 635 | borders(swaziland,mozambique). 636 | borders(swaziland,south_africa). 637 | 638 | borders(tanzania,burundi). 639 | borders(tanzania,kenya). 640 | borders(tanzania,malawi). 641 | borders(tanzania,mozambique). 642 | borders(tanzania,rwanda). 643 | borders(tanzania,uganda). 644 | borders(tanzania,zaire). 645 | borders(tanzania,zambia). 646 | borders(tanzania,indian_ocean). 647 | 648 | borders(togo,dahomey). 649 | borders(togo,ghana). 650 | borders(togo,upper_volta). 651 | borders(togo,atlantic). 652 | 653 | borders(tunisia,algeria). 654 | borders(tunisia,libya). 655 | borders(tunisia,mediterranean). 656 | 657 | borders(uganda,kenya). 658 | borders(uganda,rwanda). 659 | borders(uganda,sudan). 660 | borders(uganda,tanzania). 661 | borders(uganda,zaire). 662 | 663 | borders(upper_volta,dahomey). 664 | borders(upper_volta,ghana). 665 | borders(upper_volta,ivory_coast). 666 | borders(upper_volta,mali). 667 | borders(upper_volta,niger). 668 | borders(upper_volta,togo). 669 | 670 | borders(zaire,angola). 671 | borders(zaire,burundi). 672 | borders(zaire,central_african_republic). 673 | borders(zaire,congo). 674 | borders(zaire,rwanda). 675 | borders(zaire,sudan). 676 | borders(zaire,tanzania). 677 | borders(zaire,uganda). 678 | borders(zaire,zambia). 679 | borders(zaire,atlantic). 680 | 681 | borders(zambia,angola). 682 | borders(zambia,malawi). 683 | borders(zambia,mozambique). 684 | borders(zambia,south_africa). 685 | borders(zambia,tanzania). 686 | borders(zambia,zaire). 687 | borders(zambia,zimbabwe). 688 | 689 | borders(zimbabwe,botswana). 690 | borders(zimbabwe,mozambique). 691 | borders(zimbabwe,south_africa). 692 | borders(zimbabwe,zambia). 693 | 694 | 695 | % Facts about America. 696 | % ------------------- 697 | 698 | borders(argentina,bolivia). 699 | borders(argentina,brazil). 700 | borders(argentina,chile). 701 | borders(argentina,paraguay). 702 | borders(argentina,uruguay). 703 | borders(argentina,atlantic). 704 | 705 | borders(bahamas,atlantic). 706 | 707 | borders(barbados,atlantic). 708 | 709 | borders(belize,guatemala). 710 | borders(belize,mexico). 711 | borders(belize,atlantic). 712 | 713 | borders(bolivia,argentina). 714 | borders(bolivia,brazil). 715 | borders(bolivia,chile). 716 | borders(bolivia,paraguay). 717 | borders(bolivia,peru). 718 | 719 | borders(brazil,argentina). 720 | borders(brazil,bolivia). 721 | borders(brazil,colombia). 722 | borders(brazil,french_guiana). 723 | borders(brazil,guyana). 724 | borders(brazil,paraguay). 725 | borders(brazil,peru). 726 | borders(brazil,surinam). 727 | borders(brazil,uruguay). 728 | borders(brazil,venezuela). 729 | borders(brazil,atlantic). 730 | 731 | borders(canada,united_states). 732 | borders(canada,arctic_ocean). 733 | borders(canada,atlantic). 734 | borders(canada,pacific). 735 | 736 | borders(chile,argentina). 737 | borders(chile,bolivia). 738 | borders(chile,peru). 739 | borders(chile,pacific). 740 | 741 | borders(colombia,brazil). 742 | borders(colombia,ecuador). 743 | borders(colombia,panama). 744 | borders(colombia,peru). 745 | borders(colombia,venezuela). 746 | borders(colombia,atlantic). 747 | borders(colombia,pacific). 748 | 749 | borders(costa_rica,nicaragua). 750 | borders(costa_rica,panama). 751 | borders(costa_rica,atlantic). 752 | borders(costa_rica,pacific). 753 | 754 | borders(cuba,atlantic). 755 | 756 | borders(dominican_republic,haiti). 757 | borders(dominican_republic,atlantic). 758 | 759 | borders(ecuador,colombia). 760 | borders(ecuador,peru). 761 | borders(ecuador,pacific). 762 | 763 | borders(el_salvador,guatemala). 764 | borders(el_salvador,honduras). 765 | borders(el_salvador,pacific). 766 | 767 | borders(french_guiana,brazil). 768 | borders(french_guiana,surinam). 769 | 770 | borders(greenland,arctic_ocean). 771 | borders(greenland,atlantic). 772 | 773 | borders(grenada,atlantic). 774 | 775 | borders(guatemala,belize). 776 | borders(guatemala,el_salvador). 777 | borders(guatemala,honduras). 778 | borders(guatemala,mexico). 779 | borders(guatemala,atlantic). 780 | borders(guatemala,pacific). 781 | 782 | borders(guyana,brazil). 783 | borders(guyana,surinam). 784 | borders(guyana,venezuela). 785 | borders(guyana,atlantic). 786 | 787 | borders(haiti,dominican_republic). 788 | borders(haiti,atlantic). 789 | 790 | borders(honduras,el_salvador). 791 | borders(honduras,guatemala). 792 | borders(honduras,nicaragua). 793 | borders(honduras,atlantic). 794 | borders(honduras,pacific). 795 | 796 | borders(jamaica,atlantic). 797 | 798 | borders(mexico,belize). 799 | borders(mexico,guatemala). 800 | borders(mexico,united_states). 801 | borders(mexico,atlantic). 802 | borders(mexico,pacific). 803 | 804 | borders(nicaragua,costa_rica). 805 | borders(nicaragua,honduras). 806 | borders(nicaragua,atlantic). 807 | borders(nicaragua,pacific). 808 | 809 | borders(panama,colombia). 810 | borders(panama,costa_rica). 811 | borders(panama,atlantic). 812 | borders(panama,pacific). 813 | 814 | borders(paraguay,argentina). 815 | borders(paraguay,bolivia). 816 | borders(paraguay,brazil). 817 | 818 | borders(peru,bolivia). 819 | borders(peru,brazil). 820 | borders(peru,chile). 821 | borders(peru,colombia). 822 | borders(peru,ecuador). 823 | borders(peru,pacific). 824 | 825 | borders(surinam,brazil). 826 | borders(surinam,french_guiana). 827 | borders(surinam,guyana). 828 | 829 | borders(trinidad_and_tobago,atlantic). 830 | 831 | borders(united_states,canada). 832 | borders(united_states,mexico). 833 | borders(united_states,arctic_ocean). 834 | borders(united_states,atlantic). 835 | borders(united_states,pacific). 836 | 837 | borders(uruguay,argentina). 838 | borders(uruguay,brazil). 839 | borders(uruguay,atlantic). 840 | 841 | borders(venezuela,brazil). 842 | borders(venezuela,colombia). 843 | borders(venezuela,guyana). 844 | borders(venezuela,atlantic). 845 | 846 | % Facts about Australasia. 847 | % ----------------------- 848 | 849 | borders(australia,indian_ocean). 850 | borders(australia,pacific). 851 | 852 | borders(fiji,pacific). 853 | 854 | borders(new_zealand,pacific). 855 | 856 | borders(papua_new_guinea,indonesia). 857 | borders(papua_new_guinea,pacific). 858 | 859 | borders(tonga,pacific). 860 | 861 | borders(western_samoa,pacific). 862 | 863 | borders(antarctica,southern_ocean). 864 | 865 | % Facts about oceans and seas. 866 | % --------------------------- 867 | 868 | borders(arctic_ocean,atlantic). 869 | borders(arctic_ocean,pacific). 870 | 871 | borders(atlantic,arctic_ocean). 872 | borders(atlantic,indian_ocean). 873 | borders(atlantic,pacific). 874 | borders(atlantic,southern_ocean). 875 | borders(atlantic,baltic). 876 | borders(atlantic,mediterranean). 877 | 878 | borders(indian_ocean,atlantic). 879 | borders(indian_ocean,pacific). 880 | borders(indian_ocean,southern_ocean). 881 | borders(indian_ocean,persian_gulf). 882 | borders(indian_ocean,red_sea). 883 | 884 | borders(pacific,arctic_ocean). 885 | borders(pacific,atlantic). 886 | borders(pacific,indian_ocean). 887 | borders(pacific,southern_ocean). 888 | 889 | borders(southern_ocean,atlantic). 890 | borders(southern_ocean,indian_ocean). 891 | borders(southern_ocean,pacific). 892 | 893 | borders(baltic,atlantic). 894 | 895 | borders(black_sea,mediterranean). 896 | 897 | borders(mediterranean,atlantic). 898 | borders(mediterranean,black_sea). 899 | 900 | borders(persian_gulf,indian_ocean). 901 | 902 | borders(red_sea,indian_ocean). 903 | 904 | % Countries bordering each ocean and sea. 905 | % -------------------------------------- 906 | 907 | borders(arctic_ocean,norway). 908 | borders(arctic_ocean,soviet_union). 909 | borders(arctic_ocean,canada). 910 | borders(arctic_ocean,greenland). 911 | borders(arctic_ocean,united_states). 912 | 913 | borders(atlantic,belgium). 914 | borders(atlantic,denmark). 915 | borders(atlantic,eire). 916 | borders(atlantic,france). 917 | borders(atlantic,iceland). 918 | borders(atlantic,netherlands). 919 | borders(atlantic,norway). 920 | borders(atlantic,portugal). 921 | borders(atlantic,spain). 922 | borders(atlantic,sweden). 923 | borders(atlantic,west_germany). 924 | borders(atlantic,united_kingdom). 925 | borders(atlantic,angola). 926 | borders(atlantic,cameroon). 927 | borders(atlantic,congo). 928 | borders(atlantic,dahomey). 929 | borders(atlantic,equatorial_guinea). 930 | borders(atlantic,gabon). 931 | borders(atlantic,gambia). 932 | borders(atlantic,ghana). 933 | borders(atlantic,guinea). 934 | borders(atlantic,guinea_bissau). 935 | borders(atlantic,ivory_coast). 936 | borders(atlantic,liberia). 937 | borders(atlantic,mauritania). 938 | borders(atlantic,morocco). 939 | borders(atlantic,nigeria). 940 | borders(atlantic,senegal). 941 | borders(atlantic,sierra_leone). 942 | borders(atlantic,south_africa). 943 | borders(atlantic,togo). 944 | borders(atlantic,zaire). 945 | borders(atlantic,argentina). 946 | borders(atlantic,bahamas). 947 | borders(atlantic,barbados). 948 | borders(atlantic,belize). 949 | borders(atlantic,brazil). 950 | borders(atlantic,canada). 951 | borders(atlantic,colombia). 952 | borders(atlantic,costa_rica). 953 | borders(atlantic,cuba). 954 | borders(atlantic,dominican_republic). 955 | borders(atlantic,french_guiana). 956 | borders(atlantic,greenland). 957 | borders(atlantic,grenada). 958 | borders(atlantic,guatemala). 959 | borders(atlantic,guyana). 960 | borders(atlantic,haiti). 961 | borders(atlantic,honduras). 962 | borders(atlantic,jamaica). 963 | borders(atlantic,mexico). 964 | borders(atlantic,nicaragua). 965 | borders(atlantic,panama). 966 | borders(atlantic,surinam). 967 | borders(atlantic,trinidad_and_tobago). 968 | borders(atlantic,united_states). 969 | borders(atlantic,uruguay). 970 | borders(atlantic,venezuela). 971 | 972 | borders(indian_ocean,bangladesh). 973 | borders(indian_ocean,burma). 974 | borders(indian_ocean,india). 975 | borders(indian_ocean,indonesia). 976 | borders(indian_ocean,iran). 977 | borders(indian_ocean,malaysia). 978 | borders(indian_ocean,maldives). 979 | borders(indian_ocean,oman). 980 | borders(indian_ocean,pakistan). 981 | borders(indian_ocean,south_yemen). 982 | borders(indian_ocean,sri_lanka). 983 | borders(indian_ocean,thailand). 984 | borders(indian_ocean,djibouti). 985 | borders(indian_ocean,kenya). 986 | borders(indian_ocean,malagasy). 987 | borders(indian_ocean,mauritius). 988 | borders(indian_ocean,mozambique). 989 | borders(indian_ocean,seychelles). 990 | borders(indian_ocean,somalia). 991 | borders(indian_ocean,south_africa). 992 | borders(indian_ocean,tanzania). 993 | borders(indian_ocean,australia). 994 | 995 | borders(pacific,cambodia). 996 | borders(pacific,china). 997 | borders(pacific,indonesia). 998 | borders(pacific,japan). 999 | borders(pacific,malaysia). 1000 | borders(pacific,north_korea). 1001 | borders(pacific,philippines). 1002 | borders(pacific,singapore). 1003 | borders(pacific,south_korea). 1004 | borders(pacific,soviet_union). 1005 | borders(pacific,taiwan). 1006 | borders(pacific,thailand). 1007 | borders(pacific,vietnam). 1008 | borders(pacific,canada). 1009 | borders(pacific,chile). 1010 | borders(pacific,colombia). 1011 | borders(pacific,costa_rica). 1012 | borders(pacific,ecuador). 1013 | borders(pacific,el_salvador). 1014 | borders(pacific,guatemala). 1015 | borders(pacific,honduras). 1016 | borders(pacific,mexico). 1017 | borders(pacific,nicaragua). 1018 | borders(pacific,panama). 1019 | borders(pacific,peru). 1020 | borders(pacific,united_states). 1021 | borders(pacific,australia). 1022 | borders(pacific,fiji). 1023 | borders(pacific,new_zealand). 1024 | borders(pacific,papua_new_guinea). 1025 | borders(pacific,tonga). 1026 | borders(pacific,western_samoa). 1027 | 1028 | borders(southern_ocean,antarctica). 1029 | 1030 | borders(baltic,denmark). 1031 | borders(baltic,finland). 1032 | borders(baltic,east_germany). 1033 | borders(baltic,poland). 1034 | borders(baltic,sweden). 1035 | borders(baltic,west_germany). 1036 | borders(baltic,soviet_union). 1037 | 1038 | borders(black_sea,bulgaria). 1039 | borders(black_sea,romania). 1040 | borders(black_sea,soviet_union). 1041 | borders(black_sea,turkey). 1042 | 1043 | borders(caspian,iran). 1044 | borders(caspian,soviet_union). 1045 | 1046 | borders(mediterranean,albania). 1047 | borders(mediterranean,cyprus). 1048 | borders(mediterranean,france). 1049 | borders(mediterranean,greece). 1050 | borders(mediterranean,italy). 1051 | borders(mediterranean,malta). 1052 | borders(mediterranean,monaco). 1053 | borders(mediterranean,san_marino). 1054 | borders(mediterranean,spain). 1055 | borders(mediterranean,yugoslavia). 1056 | borders(mediterranean,israel). 1057 | borders(mediterranean,lebanon). 1058 | borders(mediterranean,syria). 1059 | borders(mediterranean,turkey). 1060 | borders(mediterranean,algeria). 1061 | borders(mediterranean,egypt). 1062 | borders(mediterranean,libya). 1063 | borders(mediterranean,morocco). 1064 | borders(mediterranean,tunisia). 1065 | 1066 | borders(persian_gulf,bahrain). 1067 | borders(persian_gulf,iran). 1068 | borders(persian_gulf,iraq). 1069 | borders(persian_gulf,kuwait). 1070 | borders(persian_gulf,qatar). 1071 | borders(persian_gulf,saudi_arabia). 1072 | borders(persian_gulf,united_arab_emirates). 1073 | 1074 | borders(red_sea,israel). 1075 | borders(red_sea,jordan). 1076 | borders(red_sea,saudi_arabia). 1077 | borders(red_sea,yemen). 1078 | borders(red_sea,egypt). 1079 | borders(red_sea,ethiopia). 1080 | borders(red_sea,sudan). 1081 | -------------------------------------------------------------------------------- /prolog/chat80/chat.awk: -------------------------------------------------------------------------------- 1 | # @(#)chat.awk 24.2 4/14/88 2 | 3 | # chat.awk : Produce a table showing all the ratios from two sets of Chat 4 | # performance data. Assumes that the input is the concatenation 5 | # of two lots of output from Chat with each line being of the 6 | # form: "1 | 3 4 5 6". There should be no other formatting lines 7 | # in the input, and the inputs should NOT include any TOTAL line 8 | # either (this will be calculated). 9 | # 10 | BEGIN { x = 0; count1 = 0; count2 = 0; } 11 | x == 0 { x = 1; marker = $1; markcount = 1; } 12 | x == 1 { 13 | if ($1 == marker && markcount++ > 1) x = 2; 14 | else { 15 | a[$1] = $3; 16 | b[$1] = $4; 17 | c[$1] = $5; 18 | d[$1] = $6; 19 | e[$1] = $7; 20 | count1++; 21 | } 22 | } 23 | x == 2 { 24 | if ($3 == 0) a[$1] = 0; else a[$1] = a[$1] / $3; 25 | if ($4 == 0) b[$1] = 0; else b[$1] = b[$1] / $4; 26 | if ($5 == 0) c[$1] = 0; else c[$1] = c[$1] / $5; 27 | if ($6 == 0) d[$1] = 0; else d[$1] = d[$1] / $6; 28 | if ($7 == 0) e[$1] = 0; else e[$1] = e[$1] / $7; 29 | count2++; 30 | } 31 | END { 32 | 33 | if (count1 != count2) 34 | printf("WARNING: Two input sets are not the same size (%d != %d)\n", \ 35 | count1, count2); 36 | 37 | printf("RATIO TABLE\n\n") 38 | printf("%10s |%10s%10s%10s%10s%10s\n", \ 39 | "Test", "Parse", "Semantics", "Planning", "Reply", "TOTAL"); 40 | for (i = 1; i <= 23; i++) { 41 | printf("%10d |%10.2f%10.2f%10.2f%10.2f%10.2f\n", \ 42 | i, a[i], b[i], c[i], d[i], e[i]); 43 | atotal += a[i]; 44 | btotal += b[i]; 45 | ctotal += c[i]; 46 | dtotal += d[i]; 47 | etotal += e[i]; 48 | } 49 | atotal /= count1; 50 | btotal /= count1; 51 | ctotal /= count1; 52 | dtotal /= count1; 53 | etotal /= count1; 54 | printf("\n%10s |%10.2f%10.2f%10.2f%10.2f%10.2f\n", \ 55 | "TOTAL", atotal, btotal, ctotal, dtotal, etotal); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /prolog/chat80/chat.pl: -------------------------------------------------------------------------------- 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 | /* SWI-Prolog modifications: 24 | 25 | - include library Quintus for enhanced compatibility 26 | - put discontiguous between brackets 27 | - rename plus/3 and index/1 to be my_plus; my_index 28 | - remove last/2: system predicate with equivalent definition. 29 | */ 30 | 31 | :- use_module(library(quintus), [no_style_check/1]). 32 | :- op(1150, fx, [(mode), (public)]). 33 | 34 | :- no_style_check(single_var). 35 | :- no_style_check((discontiguous)). 36 | 37 | :- consult(chatops). 38 | 39 | :- consult(readin). % sentence input, ASCII VERSION 40 | :- consult(ptree). % print trees 41 | :- consult(xgrun). % XG runtimes 42 | :- consult(newg). % clone + lex 43 | :- consult(clotab). % attachment tables 44 | :- consult(newdic). % syntactic dictionary 45 | :- consult(slots). % fits arguments into predicates 46 | :- consult(scopes). % quantification and scoping 47 | :- consult(templa). % semantic dictionary 48 | :- consult(qplan). % query planning 49 | :- consult(talkr). % query evaluation 50 | :- consult(ndtabl). % relation info. 51 | :- consult(aggreg). % aggregation operators 52 | :- consult(world0). % geographic data base 53 | :- consult(rivers). 54 | :- consult(cities). 55 | :- consult(countr). 56 | :- consult(contai). 57 | :- consult(border). 58 | :- consult(chattop). % top level control 59 | 60 | save_chat :- 61 | qsave_program(chat, [goal(hi)]). 62 | 63 | -------------------------------------------------------------------------------- /prolog/chat80/chatops.pl: -------------------------------------------------------------------------------- 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 | :- op(900,xfx,~=). 24 | :- op(900,xfx,=+). 25 | :- op(900,xfx,=:). 26 | :- op(450,xfy,:). 27 | :- op(400,xfy,&). 28 | :- op(300,fx,~). 29 | :- op(200,xfx,--). 30 | :- op(359,xf,ject). 31 | -------------------------------------------------------------------------------- /prolog/chat80/chattop.pl: -------------------------------------------------------------------------------- 1 | /* @(#)chattop.pl 26.1 5/13/88 */ 2 | 3 | /* 4 | Copyright 1986, Fernando C.N. Pereira and David H.D. Warren, 5 | 6 | All Rights Reserved 7 | */ 8 | 9 | % CHATTOP.PL 10 | 11 | :-public hi/0, hi/1, quote/1. 12 | 13 | :- mode control(+), 14 | doing(+,+), 15 | uses(+,?), 16 | process(+), 17 | simplify(+,?), 18 | simplify(+,?,?), 19 | simplify_not(+,?), 20 | revand(+,+,?), 21 | report(?,+,+,+), 22 | report_item(+,?). 23 | 24 | 25 | /* ---------------------------------------------------------------------- 26 | Simple questions 27 | These question do not require setof/3 and are useful for early 28 | testing of a system. 29 | ---------------------------------------------------------------------- */ 30 | 31 | eg( [ does, america, contain, new_york, ? ] ). 32 | eg( [ does, mexico, border, the, united_states, ? ] ). 33 | eg( [ is, the, population, of, china, greater, than, nb(200), million, ? ] ). 34 | eg( [ does, the, population, of, china, exceed, nb(1000), million, ? ] ). 35 | eg( [ is, the, population, of, china, nb(840), million, ? ] ). 36 | eg( [ does, the, population, of, china, exceed, the, population, of, 37 | india, ? ] ). 38 | eg( [ is, spain, bordered, by, the, pacific, ? ] ). 39 | eg( [ does, the, atlantic, border, spain, ? ] ). 40 | eg( [ is, the, rhine, in, switzerland, ? ] ). 41 | eg( [ is, the, united_kingdom, in, europe, ? ] ). 42 | 43 | 44 | /* ---------------------------------------------------------------------- 45 | Standard question set 46 | This is the standard chat question set, originally put together 47 | by David and Fernando and use in their papers. Quintus uses this 48 | set as a standard for performance comparisons. 49 | ---------------------------------------------------------------------- */ 50 | 51 | ed( 1, [ what, rivers, are, there, ? ], 52 | 53 | [amazon, amu_darya, amur, brahmaputra, colorado, 54 | congo_river, cubango, danube, don, elbe, euphrates, ganges, 55 | hwang_ho, indus, irrawaddy, lena, limpopo, mackenzie, 56 | mekong, mississippi, murray, niger_river, nile, ob, oder, 57 | orange, orinoco, parana, rhine, rhone, rio_grande, salween, 58 | senegal_river, tagus, vistula, volga, volta, yangtze, 59 | yenisei, yukon, zambesi] ). 60 | 61 | ed( 2, [ does, afghanistan, border, china, ? ], 62 | 63 | [true] ). 64 | 65 | ed( 3, [ what, is, the, capital, of, upper_volta, ? ], 66 | 67 | [ouagadougou] ). 68 | 69 | ed( 4, [ where, is, the, largest, country, ? ], 70 | 71 | [asia, northern_asia] ). 72 | 73 | ed( 5, [ which, countries, are, european, ? ], 74 | 75 | [albania, andorra, austria, belgium, bulgaria, cyprus, 76 | czechoslovakia, denmark, east_germany, eire, finland, 77 | france, greece, hungary, iceland, italy, liechtenstein, 78 | luxembourg, malta, monaco, netherlands, norway, poland, 79 | portugal, romania, san_marino, spain, sweden, switzerland, 80 | united_kingdom, west_germany, yugoslavia] ). 81 | 82 | ed( 6, [ which, country, '''', s, capital, is, london, ? ], 83 | 84 | [united_kingdom] ). 85 | 86 | ed( 7, [ which, is, the, largest, african, country, ? ], 87 | 88 | [sudan] ). 89 | 90 | ed( 8, [ how, large, is, the, smallest, american, country, ? ], 91 | 92 | [0--ksqmiles] ). 93 | 94 | ed( 9, [ what, is, the, ocean, that, borders, african, countries, 95 | and, that, borders, asian, countries, ? ], 96 | 97 | [indian_ocean] ). 98 | 99 | ed( 10, [ what, are, the, capitals, of, the, countries, bordering, the, 100 | baltic, ? ], 101 | 102 | [[[denmark]:[copenhagen], [east_germany]:[east_berlin], 103 | [finland]:[helsinki], [poland]:[warsaw], 104 | [soviet_union]:[moscow], [sweden]:[stockholm], 105 | [west_germany]:[bonn]]] ). 106 | 107 | ed( 11, [ which, countries, are, bordered, by, two, seas, ? ], 108 | 109 | [egypt, iran, israel, saudi_arabia, turkey] ). 110 | 111 | ed( 12, [ how, many, countries, does, the, danube, flow, through, ? ], 112 | 113 | [6] ). 114 | 115 | ed( 13, [ what, is, the, total, area, of, countries, south, of, the, equator, 116 | and, not, in, australasia, ? ], 117 | 118 | [10228--ksqmiles] ). 119 | 120 | ed( 14, [ what, is, the, average, area, of, the, countries, in, each, 121 | continent, ? ], 122 | 123 | [[africa,233--ksqmiles], [america,496--ksqmiles], 124 | [asia,485--ksqmiles], [australasia,543--ksqmiles], 125 | [europe,58--ksqmiles]] ). 126 | 127 | ed( 15, [ is, there, more, than, one, country, in, each, continent, ? ], 128 | 129 | [false] ). 130 | 131 | ed( 16, [ is, there, some, ocean, that, does, not, border, any, country, ? ], 132 | 133 | [true] ). 134 | 135 | ed( 17, [ what, are, the, countries, from, which, a, river, flows, into, 136 | the, black_sea, ? ], 137 | 138 | [[romania,soviet_union]] ). 139 | 140 | ed( 18, [ what, are, the, continents, no, country, in, which, contains, more, 141 | than, two, cities, whose, population, exceeds, nb(1), million, ? ], 142 | 143 | [[africa,antarctica,australasia]] ). 144 | 145 | ed( 19, [ which, country, bordering, the, mediterranean, borders, a, country, 146 | that, is, bordered, by, a, country, whose, population, exceeds, 147 | the, population, of, india, ? ], 148 | 149 | [turkey] ). 150 | 151 | ed( 20, [ which, countries, have, a, population, exceeding, nb(10), 152 | million, ? ], 153 | 154 | [afghanistan, algeria, argentina, australia, bangladesh, 155 | brazil, burma, canada, china, colombia, czechoslovakia, 156 | east_germany, egypt, ethiopia, france, india, indonesia, 157 | iran, italy, japan, kenya, mexico, morocco, nepal, 158 | netherlands, nigeria, north_korea, pakistan, peru, 159 | philippines, poland, south_africa, south_korea, 160 | soviet_union, spain, sri_lanka, sudan, taiwan, tanzania, 161 | thailand, turkey, united_kingdom, united_states, venezuela, 162 | vietnam, west_germany, yugoslavia, zaire] ). 163 | 164 | ed( 21, [ which, countries, with, a, population, exceeding, nb(10), million, 165 | border, the, atlantic, ? ], 166 | 167 | [argentina, brazil, canada, colombia, france, mexico, 168 | morocco, netherlands, nigeria, south_africa, spain, 169 | united_kingdom, united_states, venezuela, west_germany, 170 | zaire] ). 171 | 172 | ed( 22, [ what, percentage, of, countries, border, each, ocean, ? ], 173 | 174 | [[arctic_ocean,2], [atlantic,35], [indian_ocean,14], 175 | [pacific,20]] ). 176 | 177 | ed( 23, [ what, countries, are, there, in, europe, ? ], 178 | 179 | [albania, andorra, austria, belgium, bulgaria, cyprus, 180 | czechoslovakia, denmark, east_germany, eire, finland, 181 | france, greece, hungary, iceland, italy, liechtenstein, 182 | luxembourg, malta, monaco, netherlands, norway, poland, 183 | portugal, romania, san_marino, spain, sweden, switzerland, 184 | united_kingdom, west_germany, yugoslavia] ). 185 | 186 | 187 | /* ---------------------------------------------------------------------- 188 | Simple Access to demonstrations 189 | ---------------------------------------------------------------------- */ 190 | 191 | demo(Type) :- demo(Type,L), inform(L), check_words(L,S), process(S). 192 | 193 | demo(mini,List) :- eg(List). 194 | demo(main,List) :- ed(_,List,_). 195 | 196 | inform(L) :- nl, write('Question: '), inform1(L), nl, !. 197 | 198 | inform1([]). 199 | inform1([H|T]) :- write(H), put(0' ), inform1(T). 200 | 201 | 202 | /* ---------------------------------------------------------------------- 203 | Top level processing for verification and performance analysis 204 | ---------------------------------------------------------------------- */ 205 | 206 | test_chat :- test_chat(_). 207 | 208 | test_chat(N) :- 209 | show_title, 210 | ed(N,Sentence,CorrectAnswer), 211 | process(Sentence,CorrectAnswer,Status,Times), 212 | show_results(N,Status,Times), 213 | fail. 214 | test_chat(_). 215 | 216 | test :- 217 | time(rtest_chats(20)). 218 | 219 | % run a specific sentence 220 | test_chat(N, Sentence, CorrectAnswer) :- 221 | ed(N,Sentence,CorrectAnswer), 222 | process(Sentence,CorrectAnswer,_Status,_Times). 223 | % added JW 224 | rtest_chats(0) :- !. 225 | rtest_chats(N) :- 226 | rtest_chat(1), 227 | NN is N - 1, 228 | rtest_chats(NN). 229 | 230 | rtest_chat(N) :- 231 | ed(N,Sentence,CorrectAnswer), !, 232 | process(Sentence,CorrectAnswer,Status,_Times), 233 | ( Status == true 234 | -> true 235 | ; format(user_error, 'Test ~w failed!~n', [N]) 236 | ), 237 | NN is N + 1, 238 | rtest_chat(NN). 239 | rtest_chat(_). 240 | 241 | show_title :- 242 | format('Chat Natural Language Question Anwering Test~n~n',[]), 243 | show_format(F), 244 | format(F, ['Test','Parse','Semantics','Planning','Reply','TOTAL']), 245 | nl. 246 | 247 | show_results(N,Status,Times) :- 248 | show_format(F), 249 | format(F, [N|Times]), 250 | ( Status = true -> 251 | nl 252 | ; otherwise -> 253 | tab(2), write(Status), nl 254 | ). 255 | 256 | show_format( '~t~w~10+ |~t~w~12+~t~w~10+~t~w~10+~t~w~10+~t~w~10+' ). 257 | 258 | 259 | process(Sentence,CorrectAnswer,Status,Times) :- 260 | process(Sentence,Answer,Times), 261 | !, 262 | check_answer(Answer,CorrectAnswer,Status). 263 | process(_,_,failed,[0,0,0,0,0]). 264 | 265 | 266 | process(Sentence,Answer,[Time1,Time2,Time3,Time4,TotalTime]) :- 267 | statistics(runtime, [T0, _]), 268 | 269 | sentence(E,Sentence,[],[],[]), 270 | 271 | statistics(runtime, [T1, _]), 272 | Time1 is T1 - T0, 273 | statistics(runtime, [T2, _]), 274 | 275 | i_sentence(E,QT), 276 | clausify(QT,UE), 277 | simplify(UE,S), 278 | 279 | statistics(runtime, [T3, _]), 280 | Time2 is T3 - T2, 281 | statistics(runtime, [T4, _]), 282 | 283 | qplan(S,S1), !, 284 | 285 | statistics(runtime, [T5, _]), 286 | Time3 is T5 - T4, 287 | statistics(runtime, [T6, _]), 288 | 289 | answer(S1,Answer), !, 290 | 291 | statistics(runtime, [T7, _]), 292 | Time4 is T7 - T6, 293 | TotalTime is Time1 + Time2 + Time3 + Time4. 294 | 295 | 296 | % Version of answer/1 from TALKR which returns answer 297 | answer((answer([]):-E),[B]) :- !, holds(E,B). 298 | answer((answer([X]):-E),S) :- !, seto(X,E,S). 299 | answer((answer(X):-E),S) :- seto(X,E,S). 300 | 301 | check_answer(A,A,true) :- !. 302 | check_answer(_,_,'wrong answer'). 303 | 304 | 305 | /* ---------------------------------------------------------------------- 306 | Top level for runtime version, and interactive demonstrations 307 | ---------------------------------------------------------------------- */ 308 | 309 | runtime_entry(start) :- 310 | version, 311 | format(user,'~nChat Demonstration Program~n~n',[]), 312 | hi. 313 | 314 | hi :- 315 | hi(user). 316 | 317 | hi(File) :- 318 | repeat, 319 | ask(File,P), 320 | control(P), !, 321 | end(File). 322 | 323 | ask(user,P) :- !, 324 | format('~N'), 325 | prompt1('Question: '), 326 | setup_call_cleanup( 327 | prompt(Old, 'Question: '), 328 | read_in(P), 329 | prompt(_, Old)). 330 | ask(File,P) :- 331 | seeing(Old), 332 | see(File), 333 | read_in(P), 334 | nl, 335 | doing(P,0), 336 | nl, 337 | see(Old). 338 | 339 | doing([],_) :- !. 340 | doing([X|L],N0) :- 341 | out(X), 342 | advance(X,N0,N), 343 | doing(L,N). 344 | 345 | out(nb(X)) :- !, 346 | write(X). 347 | out(A) :- 348 | write(A). 349 | 350 | advance(X,N0,N) :- 351 | uses(X,K), 352 | M is N0+K, 353 | ( M>72, !, 354 | nl, 355 | N is 0; 356 | N is M+1, 357 | put(" ")). 358 | 359 | uses(nb(X),N) :- !, 360 | chars(X,N). 361 | uses(X,N) :- 362 | chars(X,N). 363 | 364 | chars(X,N) :- atomic(X), !, 365 | name(X,L), 366 | length(L,N). 367 | chars(_,2). 368 | 369 | end(user) :- !. 370 | end(F) :- 371 | close(F). 372 | 373 | control([bye,'.']) :- !, 374 | format('Cheerio.~n'). 375 | control([trace,'.']) :- !, 376 | tracing ~= on, 377 | format('Tracing from now on!~n'), fail. 378 | control([do,not,trace,'.']) :- !, 379 | tracing ~= off, 380 | format('No longer tracing.~n'), fail. 381 | control([do,mini,demo,'.']) :- !, 382 | format('Executing mini demo...~n'), 383 | demo(mini), fail. 384 | control([do,main,demo,'.']) :- !, 385 | format('Executing main demo...~n'), 386 | demo(main), fail. 387 | control([test,chat,'.']) :- !, 388 | test_chat, fail. 389 | control(U0) :- 390 | check_words(U0,U), 391 | process(U), 392 | fail. 393 | 394 | process(U) :- 395 | statistics(runtime, [_, _]), 396 | sentence(E,U,[],[],[]), 397 | statistics(runtime, [_, Et0]), 398 | report(E,'Parse',Et0,tree), 399 | statistics(runtime, [_, _]), 400 | i_sentence(E,QT), 401 | clausify(QT,UE), 402 | simplify(UE,S), 403 | statistics(runtime, [_, Et1]), 404 | report(S,'Semantics',Et1,expr), 405 | statistics(runtime, [_, _]), 406 | qplan(S,S1), !, 407 | statistics(runtime, [_, Et2]), 408 | report(S1,'Planning',Et2,expr), 409 | statistics(runtime, [_, _]), 410 | answer(S1), !, nl, 411 | statistics(runtime, [_, Et3]), 412 | report(_,'Reply',Et3,none). 413 | process(_) :- 414 | failure. 415 | 416 | failure :- 417 | format('I don''t understand!~n'). 418 | 419 | report(Item,Label,Time,Mode) :- 420 | tracing =: on, !, 421 | format('~N~w: ~wmsec.~n', [Label, Time]), 422 | report_item(Mode,Item). 423 | report(_,_,_,_). 424 | 425 | report_item(none,_). 426 | report_item(expr,Item) :- 427 | write_tree(Item), nl. 428 | report_item(tree,Item) :- 429 | print_tree(Item), nl. 430 | 431 | quote(A&R) :- 432 | atom(A), !, 433 | quote_amp(R). 434 | quote(_-_). 435 | quote(_--_). 436 | quote(_+_). 437 | quote(verb(_,_,_,_,_)). 438 | quote(wh(_)). 439 | quote(name(_)). 440 | quote(prep(_)). 441 | quote(det(_)). 442 | quote(quant(_,_)). 443 | quote(int_det(_)). 444 | 445 | quote_amp('$VAR'(_)) :- !. 446 | quote_amp(R) :- 447 | quote(R). 448 | 449 | 450 | simplify(C,(P:-R)) :- !, 451 | unequalise(C,(P:-Q)), 452 | simplify(Q,R,true). 453 | 454 | simplify(setof(X,P0,S),R,R0) :- !, 455 | simplify(P0,P,true), 456 | revand(R0,setof(X,P,S),R). 457 | simplify((P,Q),R,R0) :- 458 | simplify(Q,R1,R0), 459 | simplify(P,R,R1). 460 | simplify(true,R,R) :- !. 461 | simplify(X^P0,R,R0) :- !, 462 | simplify(P0,P,true), 463 | revand(R0,X^P,R). 464 | simplify(numberof(X,P0,Y),R,R0) :- !, 465 | simplify(P0,P,true), 466 | revand(R0,numberof(X,P,Y),R). 467 | simplify(\+P0,R,R0) :- !, 468 | simplify(P0,P1,true), 469 | simplify_not(P1,P), 470 | revand(R0,P,R). 471 | simplify(P,R,R0) :- 472 | revand(R0,P,R). 473 | 474 | simplify_not(\+P,P) :- !. 475 | simplify_not(P,\+P). 476 | 477 | revand(true,P,P) :- !. 478 | revand(P,true,P) :- !. 479 | revand(P,Q,(Q,P)). 480 | 481 | unequalise(C0,C) :- 482 | numbervars(C0,1,N), 483 | functor(V,v,N), 484 | functor(M,v,N), 485 | inv_map(C0,V,M,C). 486 | 487 | inv_map('$VAR'(I),V,_,X) :- !, 488 | arg(I,V,X). 489 | inv_map(A=B,V,M,T) :- !, 490 | drop_eq(A,B,V,M,T). 491 | inv_map(X^P0,V,M,P) :- !, 492 | inv_map(P0,V,M,P1), 493 | exquant(X,V,M,P1,P). 494 | inv_map(A,_,_,A) :- atomic(A), !. 495 | inv_map(T,V,M,R) :- 496 | functor(T,F,K), 497 | functor(R,F,K), 498 | inv_map_list(K,T,V,M,R). 499 | 500 | inv_map_list(0,_,_,_,_) :- !. 501 | inv_map_list(K0,T,V,M,R) :- 502 | arg(K0,T,A), 503 | arg(K0,R,B), 504 | inv_map(A,V,M,B), 505 | K is K0-1, 506 | inv_map_list(K,T,V,M,R). 507 | 508 | drop_eq('$VAR'(I),'$VAR'(J),V,M,true) :- !, 509 | ( I=\=J, !, 510 | irev(I,J,K,L), 511 | arg(K,M,L), 512 | arg(K,V,X), 513 | arg(L,V,X); 514 | true). 515 | drop_eq('$VAR'(I),T,V,M,true) :- !, 516 | deref(I,M,J), 517 | arg(J,V,T), 518 | arg(J,M,0). 519 | drop_eq(T,'$VAR'(I),V,M,true) :- !, 520 | deref(I,M,J), 521 | arg(J,V,T), 522 | arg(J,M,0). 523 | drop_eq(X,Y,_,_,X=Y). 524 | 525 | deref(I,M,J) :- 526 | arg(I,M,X), 527 | (var(X), !, I=J; 528 | deref(X,M,J)). 529 | 530 | exquant('$VAR'(I),V,M,P0,P) :- 531 | arg(I,M,U), 532 | ( var(U), !, 533 | arg(I,V,X), 534 | P=(X^P0); 535 | P=P0). 536 | 537 | irev(I,J,I,J) :- I>J, !. 538 | irev(I,J,J,I). 539 | 540 | :- mode check_words(+,-). 541 | 542 | check_words([],[]). 543 | check_words([Word|Words],[RevWord|RevWords]) :- 544 | check_word(Word,RevWord), 545 | check_words(Words,RevWords). 546 | 547 | :- mode check_word(+,-). 548 | 549 | check_word(Word,Word) :- word(Word), !. 550 | check_word(Word,NewWord) :- 551 | format(atom(Prompt), '? ~w -> (!. to abort) ', [Word]), 552 | prompt1(Prompt), 553 | read(NewWord0), 554 | NewWord0 \== !, 555 | check_word(NewWord0,NewWord). 556 | 557 | :- mode ~=(+,+), =+(+,-), =:(+,?). 558 | 559 | Var ~= Val :- 560 | ( recorded(Var,val(_),P), erase(P) 561 | ; true), !, 562 | recordz(Var,val(Val),_). 563 | 564 | Var =+ Val :- 565 | ( recorded(Var,val(Val0),P), erase(P) 566 | ; Val0 is 0), !, 567 | Val is Val0+1, 568 | recordz(Var,val(Val),_). 569 | 570 | Var =: Val :- 571 | recorded(Var,val(Val),_). 572 | -------------------------------------------------------------------------------- /prolog/chat80/cities.pl: -------------------------------------------------------------------------------- 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 | % Facts about cities. 24 | % ------------------ 25 | city(belle_mead,united_states,8). 26 | city(athens,greece,1368). 27 | city(bangkok,thailand,1178). 28 | city(barcelona,spain,1280). 29 | city(berlin,east_germany,3481). 30 | city(birmingham,united_kingdom,1112). 31 | city(bombay,india,2839). 32 | city(brussels,belgium,986). 33 | city(bucharest,romania,1237). 34 | city(budapest,hungary,1757). 35 | city(buenos_aires,argentina,3404). 36 | city(cairo,egypt,2373). 37 | city(calcutta,india,2549). 38 | city(canton,china,1496). 39 | city(caracas,venezuela,488). 40 | city(chicago,united_states,3621). 41 | city(chungking,china,1100). 42 | city(dairen,china,544). 43 | city(delhi,india,1744). 44 | city(detroit,united_states,1850). 45 | city(glasgow,united_kingdom,1090). 46 | city(hamburg,west_germany,1700). 47 | city(harbin,china,760). 48 | city(hongkong_city,hongkong,2440). 49 | city(hyderabad,india,1086). 50 | city(istanbul,turkey,1215). 51 | city(jakarta,indonesia,533). 52 | city(johannesburg,south_africa,880). 53 | city(karachi,pakistan,1126). 54 | city(kiev,soviet_union,991). 55 | city(kobe,japan,765). 56 | city(kowloon,china,547). 57 | city(kyoto,japan,1204). 58 | city(leningrad,soviet_union,2800). 59 | city(lima,peru,835). 60 | city(london,united_kingdom,8346). 61 | city(los_angeles,united_states,1970). 62 | city(madras,india,1416). 63 | city(madrid,spain,1700). 64 | city(manila,philippines,1025). 65 | city(melbourne,australia,1595). 66 | city(mexico_city,mexico,3796). 67 | city(milan,italy,1269). 68 | city(montreal,canada,1109). 69 | city(moscow,soviet_union,4800). 70 | city(mukden,china,1551). 71 | city(nagoya,japan,1337). 72 | city(nanking,japan,1020). 73 | city(naples,italy,1012). 74 | city(new_york,united_states,7795). 75 | city(osaka,japan,2547). 76 | city(paris,france,2850). 77 | city(peking,china,2031). 78 | city(philadelphia,united_states,2072). 79 | city(pusan,south_korea,474). 80 | city(rio_de_janeiro,brazil,2413). 81 | city(rome,italy,1760). 82 | city(saigon,vietnam,695). 83 | city(santiago,chile,1350). 84 | city(sao_paulo,brazil,2228). 85 | city(seoul,south_korea,1446). 86 | city(shanghai,china,5407). 87 | city(sian,china,629). 88 | city(singapore_city,singapore,1264). 89 | city(sydney,australia,1898). 90 | city(tehran,iran,1010). 91 | city(tientsin,china,1795). 92 | city(tokyo,japan,8535). 93 | city(toronto,canada,668). 94 | city(vienna,austria,1766). 95 | city(warsaw,poland,965). 96 | city(yokohama,japan,1143). 97 | city(toronto,canada,668). 98 | city(vienna,austria,1766). 99 | city(warsaw,poland,965). 100 | city(yokohama,japan,1143). 101 | 102 | -------------------------------------------------------------------------------- /prolog/chat80/clotab.pl: -------------------------------------------------------------------------------- 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 | % Normal form masks 24 | 25 | is_pp(#(1,_,_,_)). 26 | 27 | is_pred(#(_,1,_,_)). 28 | 29 | is_trace(#(_,_,1,_)). 30 | 31 | is_adv(#(_,_,_,1)). 32 | 33 | do_trace(#(_,_,1,_),#(0,0,0,0)). 34 | 35 | do_trace(#(0,0,1,0)). 36 | 37 | adv(#(0,0,0,1)). 38 | 39 | empty(#(0,0,0,0)). 40 | 41 | np_all(#(1,1,1,0)). 42 | 43 | s_all(#(1,0,1,1)). 44 | 45 | np_no_trace(#(1,1,0,0)). 46 | 47 | % Mask operations 48 | 49 | my_plus(#(B1,B2,B3,B4),#(C1,C2,C3,C4),#(D1,D2,D3,D4)) :- 50 | or(B1,C1,D1), 51 | or(B2,C2,D2), 52 | or(B3,C3,D3), 53 | or(B4,C4,D4). 54 | 55 | minus(#(B1,B2,B3,B4),#(C1,C2,C3,C4),#(D1,D2,D3,D4)) :- 56 | anot(B1,C1,D1), 57 | anot(B2,C2,D2), 58 | anot(B3,C3,D3), 59 | anot(B4,C4,D4). 60 | 61 | or(1,_,1). 62 | or(0,1,1). 63 | or(0,0,0). 64 | 65 | anot(X,0,X). 66 | anot(X,1,0). 67 | 68 | % Noun phrase position features 69 | 70 | role(subj,_,#(1,0,0)). 71 | role(compl,_,#(0,_,_)). 72 | role(undef,main,#(_,0,_)). 73 | role(undef,aux,#(0,_,_)). 74 | role(undef,decl,_). 75 | role(nil,_,_). 76 | 77 | subj_case(#(1,0,0)). 78 | verb_case(#(0,1,0)). 79 | prep_case(#(0,0,1)). 80 | compl_case(#(0,_,_)). 81 | -------------------------------------------------------------------------------- /prolog/chat80/contai.pl: -------------------------------------------------------------------------------- 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 | % Inversion of the 'in' relation. 24 | % ------------------------------ 25 | 26 | :-mode contains0(+,?). 27 | 28 | contains(X,Y) :- contains0(X,Y). 29 | contains(X,Y) :- contains0(X,W), contains(W,Y). 30 | 31 | contains0(africa,central_africa). 32 | contains0(africa,east_africa). 33 | contains0(africa,north_africa). 34 | contains0(africa,southern_africa). 35 | contains0(africa,west_africa). 36 | 37 | contains0(america,caribbean). 38 | contains0(america,central_america). 39 | contains0(america,north_america). 40 | contains0(america,south_america). 41 | 42 | contains0(asia,far_east). 43 | contains0(asia,indian_subcontinent). 44 | contains0(asia,middle_east). 45 | contains0(asia,northern_asia). 46 | contains0(asia,southeast_east). 47 | 48 | contains0(australasia,australia). 49 | contains0(australasia,fiji). 50 | contains0(australasia,new_zealand). 51 | contains0(australasia,papua_new_guinea). 52 | contains0(australasia,tonga). 53 | contains0(australasia,western_samoa). 54 | 55 | contains0(europe,eastern_europe). 56 | contains0(europe,scandinavia). 57 | contains0(europe,southern_europe). 58 | contains0(europe,western_europe). 59 | 60 | contains0(scandinavia,denmark). 61 | contains0(scandinavia,finland). 62 | contains0(scandinavia,norway). 63 | contains0(scandinavia,sweden). 64 | 65 | contains0(western_europe,austria). 66 | contains0(western_europe,belgium). 67 | contains0(western_europe,eire). 68 | contains0(western_europe,france). 69 | contains0(western_europe,iceland). 70 | contains0(western_europe,liechtenstein). 71 | contains0(western_europe,luxembourg). 72 | contains0(western_europe,netherlands). 73 | contains0(western_europe,switzerland). 74 | contains0(western_europe,united_kingdom). 75 | contains0(western_europe,west_germany). 76 | 77 | contains0(eastern_europe,bulgaria). 78 | contains0(eastern_europe,czechoslovakia). 79 | contains0(eastern_europe,east_germany). 80 | contains0(eastern_europe,hungary). 81 | contains0(eastern_europe,poland). 82 | contains0(eastern_europe,romania). 83 | 84 | contains0(southern_europe,albania). 85 | contains0(southern_europe,andorra). 86 | contains0(southern_europe,cyprus). 87 | contains0(southern_europe,greece). 88 | contains0(southern_europe,italy). 89 | contains0(southern_europe,malta). 90 | contains0(southern_europe,monaco). 91 | contains0(southern_europe,portugal). 92 | contains0(southern_europe,san_marino). 93 | contains0(southern_europe,spain). 94 | contains0(southern_europe,yugoslavia). 95 | 96 | contains0(north_america,canada). 97 | contains0(north_america,united_states). 98 | 99 | contains0(central_america,belize). 100 | contains0(central_america,costa_rica). 101 | contains0(central_america,el_salvador). 102 | contains0(central_america,guatemala). 103 | contains0(central_america,honduras). 104 | contains0(central_america,mexico). 105 | contains0(central_america,nicaragua). 106 | contains0(central_america,panama). 107 | 108 | contains0(caribbean,bahamas). 109 | contains0(caribbean,barbados). 110 | contains0(caribbean,cuba). 111 | contains0(caribbean,dominican_republic). 112 | contains0(caribbean,grenada). 113 | contains0(caribbean,haiti). 114 | contains0(caribbean,jamaica). 115 | contains0(caribbean,trinidad_and_tobago). 116 | 117 | contains0(south_america,argentina). 118 | contains0(south_america,bolivia). 119 | contains0(south_america,brazil). 120 | contains0(south_america,chile). 121 | contains0(south_america,colombia). 122 | contains0(south_america,ecuador). 123 | contains0(south_america,french_guiana). 124 | contains0(south_america,guyana). 125 | contains0(south_america,paraguay). 126 | contains0(south_america,peru). 127 | contains0(south_america,surinam). 128 | contains0(south_america,uruguay). 129 | contains0(south_america,venezuela). 130 | 131 | contains0(north_africa,algeria). 132 | contains0(north_africa,egypt). 133 | contains0(north_africa,libya). 134 | contains0(north_africa,morocco). 135 | contains0(north_africa,tunisia). 136 | 137 | contains0(west_africa,cameroon). 138 | contains0(west_africa,dahomey). 139 | contains0(west_africa,equatorial_guinea). 140 | contains0(west_africa,gambia). 141 | contains0(west_africa,ghana). 142 | contains0(west_africa,guinea). 143 | contains0(west_africa,guinea_bissau). 144 | contains0(west_africa,ivory_coast). 145 | contains0(west_africa,liberia). 146 | contains0(west_africa,mali). 147 | contains0(west_africa,mauritania). 148 | contains0(west_africa,niger). 149 | contains0(west_africa,nigeria). 150 | contains0(west_africa,senegal). 151 | contains0(west_africa,sierra_leone). 152 | contains0(west_africa,togo). 153 | contains0(west_africa,upper_volta). 154 | 155 | contains0(central_africa,burundi). 156 | contains0(central_africa,central_african_republic). 157 | contains0(central_africa,chad). 158 | contains0(central_africa,congo). 159 | contains0(central_africa,gabon). 160 | contains0(central_africa,rwanda). 161 | contains0(central_africa,sudan). 162 | contains0(central_africa,zaire). 163 | 164 | contains0(east_africa,djibouti). 165 | contains0(east_africa,ethiopia). 166 | contains0(east_africa,kenya). 167 | contains0(east_africa,seychelles). 168 | contains0(east_africa,somalia). 169 | contains0(east_africa,tanzania). 170 | contains0(east_africa,uganda). 171 | 172 | contains0(southern_africa,angola). 173 | contains0(southern_africa,botswana). 174 | contains0(southern_africa,lesotho). 175 | contains0(southern_africa,malagasy). 176 | contains0(southern_africa,malawi). 177 | contains0(southern_africa,mauritius). 178 | contains0(southern_africa,mozambique). 179 | contains0(southern_africa,south_africa). 180 | contains0(southern_africa,swaziland). 181 | contains0(southern_africa,zambia). 182 | contains0(southern_africa,zimbabwe). 183 | 184 | contains0(middle_east,bahrain). 185 | contains0(middle_east,iran). 186 | contains0(middle_east,iraq). 187 | contains0(middle_east,israel). 188 | contains0(middle_east,jordan). 189 | contains0(middle_east,kuwait). 190 | contains0(middle_east,lebanon). 191 | contains0(middle_east,oman). 192 | contains0(middle_east,qatar). 193 | contains0(middle_east,saudi_arabia). 194 | contains0(middle_east,south_yemen). 195 | contains0(middle_east,syria). 196 | contains0(middle_east,turkey). 197 | contains0(middle_east,united_arab_emirates). 198 | contains0(middle_east,yemen). 199 | 200 | contains0(indian_subcontinent,afghanistan). 201 | contains0(indian_subcontinent,bangladesh). 202 | contains0(indian_subcontinent,bhutan). 203 | contains0(indian_subcontinent,india). 204 | contains0(indian_subcontinent,maldives). 205 | contains0(indian_subcontinent,nepal). 206 | contains0(indian_subcontinent,pakistan). 207 | contains0(indian_subcontinent,sri_lanka). 208 | 209 | contains0(southeast_east,burma). 210 | contains0(southeast_east,cambodia). 211 | contains0(southeast_east,indonesia). 212 | contains0(southeast_east,laos). 213 | contains0(southeast_east,malaysia). 214 | contains0(southeast_east,philippines). 215 | contains0(southeast_east,singapore). 216 | contains0(southeast_east,thailand). 217 | contains0(southeast_east,vietnam). 218 | 219 | contains0(far_east,china). 220 | contains0(far_east,japan). 221 | contains0(far_east,north_korea). 222 | contains0(far_east,south_korea). 223 | contains0(far_east,taiwan). 224 | 225 | contains0(northern_asia,mongolia). 226 | contains0(northern_asia,soviet_union). 227 | 228 | contains0(afghanistan,amu_darya). 229 | 230 | contains0(angola,cubango). 231 | contains0(angola,zambesi). 232 | 233 | contains0(argentina,buenos_aires). 234 | contains0(argentina,parana). 235 | 236 | contains0(australia,melbourne). 237 | contains0(australia,murray). 238 | contains0(australia,sydney). 239 | 240 | contains0(austria,danube). 241 | contains0(austria,vienna). 242 | 243 | contains0(bangladesh,brahmaputra). 244 | 245 | contains0(belgium,brussels). 246 | 247 | contains0(brazil,amazon). 248 | contains0(brazil,parana). 249 | contains0(brazil,rio_de_janeiro). 250 | contains0(brazil,sao_paulo). 251 | 252 | contains0(burma,irrawaddy). 253 | contains0(burma,salween). 254 | 255 | contains0(cambodia,mekong). 256 | 257 | contains0(canada,mackenzie). 258 | contains0(canada,montreal). 259 | contains0(canada,toronto). 260 | contains0(canada,yukon). 261 | 262 | contains0(chile,santiago). 263 | 264 | contains0(china,amur). 265 | contains0(china,brahmaputra). 266 | contains0(china,canton). 267 | contains0(china,chungking). 268 | contains0(china,dairen). 269 | contains0(china,ganges). 270 | contains0(china,harbin). 271 | contains0(china,hwang_ho). 272 | contains0(china,indus). 273 | contains0(china,kowloon). 274 | contains0(china,mekong). 275 | contains0(china,mukden). 276 | contains0(china,peking). 277 | contains0(china,salween). 278 | contains0(china,shanghai). 279 | contains0(china,sian). 280 | contains0(china,tientsin). 281 | contains0(china,yangtze). 282 | 283 | contains0(colombia,orinoco). 284 | 285 | contains0(czechoslovakia,danube). 286 | contains0(czechoslovakia,elbe). 287 | contains0(czechoslovakia,oder). 288 | 289 | contains0(east_germany,berlin). 290 | contains0(east_germany,elbe). 291 | 292 | contains0(egypt,cairo). 293 | contains0(egypt,nile). 294 | 295 | contains0(france,paris). 296 | contains0(france,rhone). 297 | 298 | contains0(ghana,volta). 299 | 300 | contains0(greece,athens). 301 | 302 | contains0(guinea,niger_river). 303 | contains0(guinea,senegal_river). 304 | 305 | contains0(hungary,budapest). 306 | contains0(hungary,danube). 307 | 308 | contains0(india,bombay). 309 | contains0(india,calcutta). 310 | contains0(india,delhi). 311 | contains0(india,ganges). 312 | contains0(india,hyderabad). 313 | contains0(india,indus). 314 | contains0(india,madras). 315 | 316 | contains0(indonesia,jakarta). 317 | 318 | contains0(iran,tehran). 319 | 320 | contains0(iraq,euphrates). 321 | 322 | contains0(italy,milan). 323 | contains0(italy,naples). 324 | contains0(italy,rome). 325 | 326 | contains0(japan,kobe). 327 | contains0(japan,kyoto). 328 | contains0(japan,nagoya). 329 | contains0(japan,nanking). 330 | contains0(japan,osaka). 331 | contains0(japan,tokyo). 332 | contains0(japan,yokohama). 333 | 334 | contains0(laos,mekong). 335 | 336 | contains0(lesotho,orange). 337 | 338 | contains0(mali,niger_river). 339 | contains0(mali,senegal_river). 340 | 341 | contains0(mexico,colorado). 342 | contains0(mexico,mexico_city). 343 | contains0(mexico,rio_grande). 344 | 345 | contains0(mongolia,amur). 346 | contains0(mongolia,yenisei). 347 | 348 | contains0(mozambique,limpopo). 349 | contains0(mozambique,zambesi). 350 | 351 | contains0(netherlands,rhine). 352 | 353 | contains0(niger,niger_river). 354 | 355 | contains0(nigeria,niger_river). 356 | 357 | contains0(pakistan,indus). 358 | contains0(pakistan,karachi). 359 | 360 | contains0(paraguay,parana). 361 | 362 | contains0(peru,amazon). 363 | contains0(peru,lima). 364 | 365 | contains0(philippines,manila). 366 | 367 | contains0(poland,oder). 368 | contains0(poland,vistula). 369 | contains0(poland,warsaw). 370 | 371 | contains0(portugal,tagus). 372 | 373 | contains0(romania,bucharest). 374 | contains0(romania,danube). 375 | 376 | contains0(senegal,senegal_river). 377 | 378 | contains0(singapore,singapore_city). 379 | 380 | contains0(south_africa,cubango). 381 | contains0(south_africa,johannesburg). 382 | contains0(south_africa,limpopo). 383 | contains0(south_africa,orange). 384 | 385 | contains0(south_korea,pusan). 386 | contains0(south_korea,seoul). 387 | 388 | contains0(soviet_union,amu_darya). 389 | contains0(soviet_union,amur). 390 | contains0(soviet_union,don). 391 | contains0(soviet_union,kiev). 392 | contains0(soviet_union,lena). 393 | contains0(soviet_union,leningrad). 394 | contains0(soviet_union,moscow). 395 | contains0(soviet_union,ob). 396 | contains0(soviet_union,volga). 397 | contains0(soviet_union,yenisei). 398 | 399 | contains0(spain,barcelona). 400 | contains0(spain,madrid). 401 | contains0(spain,tagus). 402 | 403 | contains0(sudan,nile). 404 | 405 | contains0(switzerland,rhine). 406 | contains0(switzerland,rhone). 407 | 408 | contains0(syria,euphrates). 409 | 410 | contains0(thailand,bangkok). 411 | 412 | contains0(turkey,euphrates). 413 | contains0(turkey,istanbul). 414 | 415 | contains0(uganda,nile). 416 | 417 | contains0(united_kingdom,birmingham). 418 | contains0(united_kingdom,glasgow). 419 | contains0(united_kingdom,london). 420 | 421 | contains0(united_states,chicago). 422 | contains0(united_states,colorado). 423 | contains0(united_states,detroit). 424 | contains0(united_states,los_angeles). 425 | contains0(united_states,mississippi). 426 | contains0(united_states,new_york). 427 | contains0(united_states,philadelphia). 428 | contains0(united_states,rio_grande). 429 | contains0(united_states,yukon). 430 | 431 | contains0(upper_volta,volta). 432 | 433 | contains0(venezuela,caracas). 434 | contains0(venezuela,orinoco). 435 | 436 | contains0(vietnam,mekong). 437 | contains0(vietnam,saigon). 438 | 439 | contains0(west_germany,danube). 440 | contains0(west_germany,elbe). 441 | contains0(west_germany,hamburg). 442 | contains0(west_germany,rhine). 443 | 444 | contains0(yugoslavia,danube). 445 | 446 | contains0(zaire,congo_river). 447 | 448 | contains0(zambia,congo_river). 449 | contains0(zambia,zambesi). 450 | 451 | -------------------------------------------------------------------------------- /prolog/chat80/countr.pl: -------------------------------------------------------------------------------- 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 | % Facts about countries. 24 | % --------------------- 25 | 26 | % country(Country,Region,Latitude,Longitude, 27 | % Area/1000,Area mod 1000, 28 | % Population/1000000,Population mod 1000000 / 1000, 29 | % Capital,Currency) 30 | 31 | country(afghanistan,indian_subcontinent,33,-65,254,861,18,290,kabul,afghani). 32 | country(albania,southern_europe,41,-20,11,100,2,350,tirana,lek). 33 | country(algeria,north_africa,35,-11,919,951,15,770,algiers,dinar). 34 | country(andorra,southern_europe,42,-1,0,179,0,25,andorra_la_villa, 35 | franc_peseta). 36 | country(angola,southern_africa,-12,-18,481,351,5,810,luanda,?). 37 | country(argentina,south_america,-35,66,1072,67,23,920,buenos_aires,peso). 38 | country(australia,australasia,-23,-135,2967,909,13,268,canberra, 39 | australian_dollar). 40 | country(austria,western_europe,47,-14,32,374,7,520,vienna,schilling). 41 | country(bahamas,caribbean,24,74,4,404,0,190,nassau,bahamian_dollar). 42 | country(bahrain,middle_east,26,-50,0,231,0,230,manama,dinar). 43 | country(bangladesh,indian_subcontinent,24,-90,55,126,71,317,dacca,taka). 44 | country(barbados,caribbean,13,59,0,166,0,240,bridgetown,east_carribean_dollar). 45 | country(belgium,western_europe,51,-5,11,779,9,711,brussels,franc). 46 | country(belize,central_america,17,88,8,866,0,82,belize_town,?). 47 | country(bhutan,indian_subcontinent,27,-90,19,305,1,150,thimphu,indian_rupee). 48 | country(bolivia,south_america,-17,64,424,162,5,330,sucre,peso). 49 | country(botswana,southern_africa,-22,-24,219,815,0,650,gaborone, 50 | south_african_rand). 51 | country(brazil,south_america,-13,53,3286,470,105,137,brasilia,cruzeiro). 52 | country(bulgaria,eastern_europe,43,-25,42,829,8,620,sofia,lev). 53 | country(burma,southeast_east,21,-96,261,789,29,560,rangoon,kyat). 54 | country(burundi,central_africa,-3,-30,10,739,3,600,bujumbura,franc). 55 | country(cambodia,southeast_east,12,-105,69,898,7,640,phnom_penh,riel). 56 | country(cameroon,west_africa,3,-12,183,568,6,170,yaounde,cfa_franc). 57 | country(canada,north_america,60,100,3851,809,22,47,ottawa,canadian_dollar). 58 | country(central_african_republic,central_africa,7,-20,241,313,1,720,bangui, 59 | cfa_franc). 60 | country(chad,central_africa,12,-17,495,752,3,870,n_djamena,cfa_franc). 61 | country(chile,south_america,-35,71,286,396,10,230,santiago,escudo). 62 | country(china,far_east,30,-110,3691,502,840,0,peking,yuan). 63 | country(colombia,south_america,4,73,455,335,23,210,bogota,peso). 64 | country(congo,central_africa,-1,-16,132,46,1,1,brazzaville,cfa_franc). 65 | country(costa_rica,central_america,10,84,19,653,1,890,san_jose,colon). 66 | country(cuba,caribbean,22,79,44,218,8,870,havana,peso). 67 | country(cyprus,southern_europe,35,-33,3,572,0,660,nicosia,pound). 68 | country(czechoslovakia,eastern_europe,49,-17,49,371,14,580,prague,koruna). 69 | country(dahomey,west_africa,8,-2,43,483,2,910,porto_novo,cfa_franc). 70 | country(denmark,scandinavia,55,-9,16,615,5,130,copenhagen,krone). 71 | country(djibouti,east_africa,12,-42,9,71,0,45,djibouti,?). 72 | country(dominican_republic,caribbean,19,70,18,704,4,430,santa_domingo,peso). 73 | country(east_germany,eastern_europe,52,-12,40,646,16,980,east_berlin,ddr_mark). 74 | country(ecuador,south_america,-2,78,105,685,6,730,quito,sucre). 75 | country(egypt,north_africa,28,-31,386,872,35,620,cairo,egyptian_pound). 76 | country(eire,western_europe,53,8,26,600,3,30,dublin,irish_pound). 77 | country(el_salvador,central_america,14,89,8,260,3,860,san_salvador,colon). 78 | country(equatorial_guinea,west_africa,1,-10,10,832,0,300,santa_isabel,peveta). 79 | country(ethiopia,east_africa,8,-40,457,142,26,80,addis_ababa,ethiopean_dollar). 80 | country(fiji,australasia,-17,-179,7,55,0,550,suva,fiji_dollar). 81 | country(finland,scandinavia,65,-27,130,119,4,660,helsinki,markka). 82 | country(france,western_europe,47,-3,212,973,52,350,paris,franc). 83 | country(french_guiana,south_america,4,53,34,740,0,27,cayenne,?). 84 | country(gabon,central_africa,0,-10,102,317,0,520,libreville,cfa_franc). 85 | country(gambia,west_africa,13,16,4,3,0,490,banjul,dalasi). 86 | country(ghana,west_africa,6,1,92,100,9,360,accra,cedi). 87 | country(greece,southern_europe,40,-23,50,547,9,30,athens,drachma). 88 | country(grenada,caribbean,12,61,0,133,0,100,st_georges,east_caribbean_dollar). 89 | country(guatemala,central_america,15,90,42,42,5,540,guatamala_city,quetzal). 90 | country(guinea,west_africa,10,10,94,925,4,210,conakry,syli). 91 | country(guinea_bissau,west_africa,12,15,13,948,0,510,bissau,pataca). 92 | country(guyana,south_america,5,59,83,0,0,760,georgetown,guyana_dollar). 93 | country(haiti,caribbean,19,72,10,714,5,200,port_au_prince,gourde). 94 | country(honduras,central_america,14,86,43,277,2,780,tegucigalpa,lempira). 95 | country(hungary,eastern_europe,47,-19,35,919,10,410,budapest,forint). 96 | country(iceland,western_europe,65,19,39,702,0,210,reykjavik,krona). 97 | country(india,indian_subcontinent,20,-80,1229,919,574,220,new_delhi,rupee). 98 | country(indonesia,southeast_east,-5,-115,735,268,124,600,jakarta,rupiah). 99 | country(iran,middle_east,33,-53,636,363,32,1,tehran,rial). 100 | country(iraq,middle_east,33,-44,167,567,10,410,baghdad,dinar). 101 | country(israel,middle_east,32,-35,34,493,3,228,jerusalem,israeli_pound). 102 | country(italy,southern_europe,42,-13,116,303,55,262,rome,lira). 103 | country(ivory_coast,west_africa,7,5,124,503,4,640,abidjan,cfa_franc). 104 | country(jamaica,caribbean,18,77,4,411,1,980,kingston,jamaican_dollar). 105 | country(japan,far_east,36,-136,143,574,108,710,tokyo,yen). 106 | country(jordan,middle_east,31,-36,32,297,2,560,amman,dinar). 107 | country(kenya,east_africa,1,-38,224,960,12,480,nairobi,kenya_shilling). 108 | country(kuwait,middle_east,29,-47,7,780,0,880,kuwait_city,kuwaiti_dinar). 109 | country(laos,southeast_east,18,-105,3,180,3,180,vientiane,kip). 110 | country(lebanon,middle_east,34,-36,4,15,3,213,beirut,lebanese_pound). 111 | country(lesotho,southern_africa,-30,-28,11,716,1,200,masero,rand). 112 | country(liberia,west_africa,6,9,43,0,1,660,monrovia,us_dollar). 113 | country(libya,north_africa,28,-17,679,536,2,257,tripoli,libyan_dinar). 114 | country(liechtenstein,western_europe,47,-9,0,62,0,23,vaduz,swiss_franc). 115 | country(luxembourg,western_europe,50,-6,0,999,0,350,luxembourg, 116 | luxembourg_franc). 117 | country(malagasy,southern_africa,-20,-47,203,35,7,655,tananarive,ariary). 118 | country(malawi,southern_africa,-13,-34,45,747,4,790,zomba,kwacha). 119 | country(malaysia,southeast_east,5,-110,128,328,10,920,kuala_lumpa, 120 | malaysian_dollar). 121 | country(maldives,indian_subcontinent,2,-73,0,115,0,123,male,rupee). 122 | country(mali,west_africa,15,10,464,873,5,380,bamako,mali_franc). 123 | country(malta,southern_europe,36,-14,0,122,0,319,valetta,pound). 124 | country(mauritania,west_africa,21,10,419,229,1,260,nouakchott,ouguiya). 125 | country(mauritius,southern_africa,-20,-57,0,787,0,870,port_louis,rupee). 126 | country(mexico,central_america,20,100,761,601,54,300,mexico_city,peso). 127 | country(monaco,southern_europe,44,-7,0,1,0,30,monaco,french_franc). 128 | country(mongolia,northern_asia,47,-103,604,247,1,360,ulan_bator,tighrik). 129 | country(morocco,north_africa,32,6,171,953,16,310,rabat,dirham). 130 | country(mozambique,southern_africa,-19,-35,303,373,8,820,maputo,?). 131 | country(nepal,indian_subcontinent,28,-84,54,362,12,20,katmandu,nepalese_rupee). 132 | country(netherlands,western_europe,52,-5,14,192,13,500,amsterdam,guilder). 133 | country(new_zealand,australasia,-40,-176,103,736,2,962,wellington, 134 | new_zealand_dollar). 135 | country(nicaragua,central_america,12,85,57,143,2,10,managua,cordoba). 136 | country(niger,west_africa,13,-10,489,206,4,300,niamey,cfa_franc). 137 | country(nigeria,west_africa,8,-8,356,669,79,759,lagos,naira). 138 | country(north_korea,far_east,40,-127,46,768,15,90,pvongvang,won). 139 | country(norway,scandinavia,64,-11,125,181,3,960,oslo,krone). 140 | country(oman,middle_east,23,-58,82,0,0,720,muscat,riyal_omani). 141 | country(pakistan,indian_subcontinent,30,-70,342,750,66,750,islamad,rupee). 142 | country(panama,central_america,9,80,28,753,1,570,panama,balboa). 143 | country(papua_new_guinea, 144 | australasia,-8,-145,183,540,2,580,port_harcourt,australian_dollar). 145 | country(paraguay,south_america,-23,57,157,47,2,670,asuncion,guarani). 146 | country(peru,south_america,-8,75,496,222,14,910,lima,sol). 147 | country(philippines,southeast_east,12,-123,115,707,40,220,quezon_city,piso). 148 | country(poland,eastern_europe,52,-20,120,359,33,360,warsaw,zloty). 149 | country(portugal,southern_europe,40,7,35,340,8,560,lisbon,escudo). 150 | country(qatar,middle_east,25,-51,4,0,0,115,doha,riyal). 151 | country(romania,eastern_europe,46,-25,91,699,5,690,bucharest,leu). 152 | country(rwanda,central_africa,-2,-30,10,169,3,980,kigali,rwanda_franc). 153 | country(san_marino,southern_europe,44,-12,0,24,0,20,san_marino,italian_lira). 154 | country(saudi_arabia,middle_east,26,-44,873,0,8,100,riyadh,riyal). 155 | country(senegal,west_africa,14,14,76,124,4,230,dakar,cfa_franc). 156 | country(seychelles,east_africa,-4,-55,0,40,0,156,victoria,rupee). 157 | country(sierra_leone,west_africa,9,12,27,925,2,860,freetown,leone). 158 | country(singapore,southeast_east,1,-104,0,226,2,190,singapore, 159 | singapore_dollar). 160 | country(somalia,east_africa,7,-47,246,155,3,100,mogadishu,somali_shilling). 161 | country(south_africa,southern_africa,-30,-25,471,819,23,720,pretoria,rand). 162 | country(south_korea,far_east,36,-128,38,31,33,333,seoul,won). 163 | country(south_yemen,middle_east,15,-48,111,0,1,600,aden,dinar). 164 | country(soviet_union,northern_asia,57,-80,8347,250,250,900,moscow,ruble). 165 | country(spain,southern_europe,40,5,194,883,34,860,madrid,peseta). 166 | country(sri_lanka,indian_subcontinent,7,-81,25,332,13,250,colombo,rupee). 167 | country(sudan,central_africa,15,-30,967,491,16,900,khartoum,pound). 168 | country(surinam,south_america,4,56,55,0,0,208,paramaribo,?). 169 | country(swaziland,southern_africa,-26,-31,6,705,0,460,mbabane,lilageru). 170 | country(sweden,scandinavia,63,-15,173,665,8,144,stockholm,krona). 171 | country(switzerland,western_europe,46,-8,15,941,6,440,bern,franc). 172 | country(syria,middle_east,35,-38,71,498,6,895,damascus,syrian_pound). 173 | country(taiwan,far_east,23,-121,13,592,15,737,taipei,taiwan_dollar). 174 | country(tanzania,east_africa,-7,-34,363,708,14,0,dar_es_salaam, 175 | tanzanian_shilling). 176 | country(thailand,southeast_east,16,-102,198,455,39,950,bangkok,baht). 177 | country(togo,west_africa,8,-1,21,853,2,120,lome,cfa_franc). 178 | country(tonga,australasia,-20,173,0,269,0,90,nukualofa,pa_anga). 179 | country(trinidad_and_tobago,caribbean,10,61,1,979,5,510,port_of_spain, 180 | trinidad_and_tobago_dollar). 181 | country(tunisia,north_africa,33,-9,63,378,5,510,tunis,dinar). 182 | country(turkey,middle_east,39,-36,301,380,37,930,ankara,lira). 183 | country(uganda,east_africa,2,-32,91,134,10,810,kampala,uganda_shilling). 184 | country(united_arab_emirates,middle_east,24,-54,32,278,0,210,abu_dhabi,dirham). 185 | country(united_kingdom,western_europe,54,2,94,209,55,930,london,pound). 186 | country(united_states,north_america,37,96,3615,122,211,210,washington,dollar). 187 | country(upper_volta,west_africa,12,2,105,869,5,740,ouagadougou,cfa_franc). 188 | country(uruguay,south_america,-32,55,68,548,2,990,montevideo,peso). 189 | country(venezuela,south_america,8,65,352,143,11,520,caracas,bolivar). 190 | country(vietnam,southeast_east,17,-107,126,436,41,850,hanoi,dong). 191 | country(west_germany,western_europe,52,-9,95,815,61,970,bonn,deutsche_mark). 192 | country(western_samoa,australasia,-14,172,1,133,0,150,apia,tala). 193 | country(yemen,middle_east,15,-44,75,289,1,600,sana,rial). 194 | country(yugoslavia,southern_europe,44,-20,98,766,21,126,belgrade,dinar). 195 | country(zaire,central_africa,-3,-23,905,63,23,560,kinshasa,zaire). 196 | country(zambia,southern_africa,-15,-28,290,724,4,640,lusaka,kwacha). 197 | country(zimbabwe,southern_africa,-20,-30,150,333,5,690,salisbury, 198 | rhodesian_dollar). 199 | 200 | -------------------------------------------------------------------------------- /prolog/chat80/demo: -------------------------------------------------------------------------------- 1 | 2 | Trace. 3 | What rivers are there? 4 | Does Afghanistan border China? 5 | What is the capital of Upper_Volta? 6 | Where is the largest country? 7 | Which countries are European? 8 | Which country's capital is London? 9 | Which is the largest african country? 10 | How large is the smallest american country? 11 | What is the ocean that borders African countries 12 | and that borders Asian countries? 13 | What are the capitals of the countries bordering the Baltic? 14 | Which countries are bordered by two seas? 15 | How many countries does the Danube flow through? 16 | What is the total area of countries south of the Equator 17 | and not in Australasia? 18 | What is the average area of the countries in each continent? 19 | Is there more than one country in each continent? 20 | Is there some ocean that does not border any country? 21 | What are the countries from which a river flows into the Black_Sea? 22 | What are the continents no country in which contains more than 23 | two cities whose population exceeds 1 million? 24 | Which country bordering the Mediterranean borders a country 25 | that is bordered by a country whose population exceeds 26 | the population of India? 27 | Which countries have a population exceeding 10 million? 28 | Which countries with a population exceeding 10 million border 29 | the Atlantic? 30 | What percentage of countries border each ocean? 31 | What countries are there in Europe? 32 | Bye. 33 | -------------------------------------------------------------------------------- /prolog/chat80/ndtabl.pl: -------------------------------------------------------------------------------- 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 | % NDTABL - Meta-information about database relations. 24 | 25 | :-mode 26 | nd(+,-,-), 27 | nd(+,-,-,-), 28 | nd(+,-,-,-,-). 29 | 30 | nd(african,19,26). 31 | nd(american,19,26). 32 | nd(area,51,51). 33 | nd(area,22,22,51). 34 | nd(asian,21,26). 35 | nd(aggregate,103,3,100,51). 36 | nd(one_of,99,200,-99). 37 | nd(ratio,99,51,51,3). 38 | nd(card,99,100,3). 39 | nd(borders,29,22,22). 40 | nd(capital,22,22). 41 | nd(capital,22,22,23). 42 | nd(city,18,18). 43 | nd(continent,8,8). 44 | nd(country,22,22). 45 | nd(drains,16,16,10). 46 | nd(eastof,40,22,22). 47 | nd(european,19,26). 48 | nd(exceeds,99,51,51). 49 | nd(flows,19,16,22). 50 | nd(flows,19,16,22,22). 51 | nd(in,29,26,15). 52 | nd(latitude,23,23). 53 | nd(latitude,22,22,23). 54 | nd(longitude,26,26). 55 | nd(longitude,22,22,26). 56 | nd(northof,40,22,22). 57 | nd(ocean,7,7). 58 | nd(population,51,51). 59 | nd(population,23,23,51). 60 | nd(region,12,12). 61 | nd(rises,16,16,22). 62 | nd(river,16,16). 63 | nd(sea,8,8). 64 | nd(place,23,23). 65 | nd(seamass,10,10). 66 | nd(southof,40,22,22). 67 | nd(westof,40,22,22). 68 | nd(=<,99,51,51). 69 | nd(<,99,51,51). 70 | nd(>,99,51,51). 71 | nd(>=,99,51,51). 72 | 73 | -------------------------------------------------------------------------------- /prolog/chat80/newdic.pl: -------------------------------------------------------------------------------- 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 | % Modes 24 | 25 | :- mode word(+). 26 | :- mode ~(+). 27 | :- mode conj(+). 28 | :- mode adverb(+). 29 | :- mode sup_adj(+,?). 30 | :- mode rel_adj(+,?). 31 | :- mode adj(+,?). 32 | :- mode name_template(+,-). 33 | :- mode name(+). 34 | :- mode terminator(+,?). 35 | :- mode pers_pron(+,?,?,?,?). 36 | :- mode poss_pron(+,?,?,?). 37 | :- mode rel_pron(+,?). 38 | :- mode regular_past(+,?). 39 | :- mode regular_pres(+). 40 | :- mode verb_root(+). 41 | :- mode verb_form(+,?,?,?). 42 | :- mode noun_sin(+). 43 | :- mode noun_plu(+,?). 44 | :- mode noun_form(+,?,?). 45 | :- mode prep(+). 46 | :- mode quantifier_pron(+,?,?). 47 | :- mode tr_number(+,?). 48 | :- mode number(+,?,?). 49 | :- mode det(+,?,?,?). 50 | :- mode int_art(+,?,?,?). 51 | :- mode int_pron(+,?). 52 | 53 | % ================================================================= 54 | % General Dictionary 55 | 56 | word(Word) :- ~(Word). 57 | word(Word) :- conj(Word). 58 | word(Word) :- adverb(Word). 59 | word(Word) :- sup_adj(Word,_). 60 | word(Word) :- rel_adj(Word,_). 61 | word(Word) :- adj(Word,_). 62 | word(Word) :- name(Word). 63 | word(Word) :- terminator(Word,_). 64 | word(Word) :- pers_pron(Word,_,_,_,_). 65 | word(Word) :- poss_pron(Word,_,_,_). 66 | word(Word) :- rel_pron(Word,_). 67 | word(Word) :- verb_form(Word,_,_,_). 68 | word(Word) :- noun_form(Word,_,_). 69 | word(Word) :- prep(Word). 70 | word(Word) :- quantifier_pron(Word,_,_). 71 | word(Word) :- number(Word,_,_). 72 | word(Word) :- det(Word,_,_,_). 73 | word(Word) :- int_art(Word,_,_,_). 74 | word(Word) :- int_pron(Word,_). 75 | word(Word) :- loc_pred(Word,_). 76 | 77 | ~how. 78 | ~whose. 79 | ~there. 80 | ~of. 81 | ~(''''). 82 | ~(','). 83 | ~s. 84 | ~than. 85 | ~at. 86 | ~the. 87 | ~not. 88 | ~(as). 89 | ~that. 90 | ~less. 91 | ~more. 92 | ~least. 93 | ~most. 94 | ~many. 95 | ~where. 96 | ~when. 97 | conj(and). 98 | conj(or). 99 | 100 | int_pron(what,undef). 101 | int_pron(which,undef). 102 | int_pron(who,subj). 103 | int_pron(whom,compl). 104 | 105 | int_art(what,X,_,int_det(X)). 106 | int_art(which,X,_,int_det(X)). 107 | 108 | det(the,No,the(No),def). 109 | det(a,sin,a,indef). 110 | det(an,sin,a,indef). 111 | det(every,sin,every,indef). 112 | det(some,_,some,indef). 113 | det(any,_,any,indef). 114 | det(all,plu,all,indef). 115 | det(each,sin,each,indef). 116 | det(no,_,no,indef). 117 | 118 | number(W,I,Nb) :- 119 | tr_number(W,I), 120 | ag_number(I,Nb). 121 | 122 | tr_number(nb(I),I). 123 | tr_number(one,1). 124 | tr_number(two,2). 125 | tr_number(three,3). 126 | tr_number(four,4). 127 | tr_number(five,5). 128 | tr_number(six,6). 129 | tr_number(seven,7). 130 | tr_number(eight,8). 131 | tr_number(nine,9). 132 | tr_number(ten,10). 133 | 134 | ag_number(1,sin). 135 | ag_number(N,plu) :- N>1. 136 | 137 | quantifier_pron(everybody,every,person). 138 | quantifier_pron(everyone,every,person). 139 | quantifier_pron(everything,every,thing). 140 | quantifier_pron(somebody,some,person). 141 | quantifier_pron(someone,some,person). 142 | quantifier_pron(something,some,thing). 143 | quantifier_pron(anybody,any,person). 144 | quantifier_pron(anyone,any,person). 145 | quantifier_pron(anything,any,thing). 146 | quantifier_pron(nobody,no,person). 147 | quantifier_pron(nothing,no,thing). 148 | 149 | prep(as). 150 | prep(at). 151 | prep(of). 152 | prep(to). 153 | prep(by). 154 | prep(with). 155 | prep(in). 156 | prep(on). 157 | prep(from). 158 | prep(into). 159 | prep(through). 160 | 161 | noun_form(Plu,Sin,plu) :- noun_plu(Plu,Sin). 162 | noun_form(Sin,Sin,sin) :- noun_sin(Sin). 163 | 164 | verb_form(V,V,inf,_) :- verb_root(V). 165 | verb_form(V,V,pres+fin,Agmt) :- 166 | regular_pres(V), 167 | root_form(Agmt), 168 | verb_root(V). 169 | verb_form(Past,Root,past+_,_) :- 170 | regular_past(Past,Root). 171 | 172 | root_form(1+sin). 173 | root_form(2+_). 174 | root_form(1+plu). 175 | root_form(3+plu). 176 | 177 | verb_root(be). 178 | verb_root(have). 179 | verb_root(do). 180 | 181 | verb_form(am,be,pres+fin,1+sin). 182 | verb_form(are,be,pres+fin,2+sin). 183 | verb_form(is,be,pres+fin,3+sin). 184 | verb_form(are,be,pres+fin,_+plu). 185 | verb_form(was,be,past+fin,1+sin). 186 | verb_form(were,be,past+fin,2+sin). 187 | verb_form(was,be,past+fin,3+sin). 188 | verb_form(were,be,past+fin,_+plu). 189 | verb_form(been,be,past+part,_). 190 | verb_form(being,be,pres+part,_). 191 | 192 | verb_type(be,aux+be). 193 | 194 | regular_pres(have). 195 | 196 | regular_past(had,have). 197 | 198 | verb_form(has,have,pres+fin,3+sin). 199 | verb_form(having,have,pres+part,_). 200 | 201 | verb_type(have,aux+have). 202 | 203 | regular_pres(do). 204 | 205 | verb_form(does,do,pres+fin,3+sin). 206 | verb_form(did,do,past+fin,_). 207 | verb_form(doing,do,pres+part,_). 208 | verb_form(done,do,past+part,_). 209 | 210 | verb_type(do,aux+ditrans). 211 | 212 | rel_pron(who,subj). 213 | rel_pron(whom,compl). 214 | rel_pron(which,undef). 215 | 216 | poss_pron(my,_,1,sin). 217 | poss_pron(your,_,2,_). 218 | poss_pron(his,masc,3,sin). 219 | poss_pron(her,fem,3,sin). 220 | poss_pron(its,neut,3,sin). 221 | poss_pron(our,_,1,plu). 222 | poss_pron(their,_,3,plu). 223 | 224 | pers_pron(i,_,1,sin,subj). 225 | pers_pron(you,_,2,_,_). 226 | pers_pron(he,masc,3,sin,subj). 227 | pers_pron(she,fem,3,sin,subj). 228 | pers_pron(it,neut,3,sin,_). 229 | pers_pron(we,_,1,plu,subj). 230 | pers_pron(them,_,3,plu,subj). 231 | pers_pron(me,_,1,sin,compl(_)). 232 | pers_pron(him,masc,3,sin,compl(_)). 233 | pers_pron(her,fem,3,sin,compl(_)). 234 | pers_pron(us,_,1,plu,compl(_)). 235 | pers_pron(them,_,3,plu,compl(_)). 236 | 237 | terminator(.,_). 238 | terminator(?,?). 239 | terminator(!,!). 240 | 241 | name(Name) :- 242 | name_template(Name,_), !. 243 | 244 | % ================================================================= 245 | % Specialised Dictionary 246 | 247 | loc_pred(east,prep(eastof)). 248 | loc_pred(west,prep(westof)). 249 | loc_pred(north,prep(northof)). 250 | loc_pred(south,prep(southof)). 251 | 252 | adj(minimum,restr). 253 | adj(maximum,restr). 254 | adj(average,restr). 255 | adj(total,restr). 256 | adj(african,restr). 257 | adj(american,restr). 258 | adj(asian,restr). 259 | adj(european,restr). 260 | adj(great,quant). 261 | adj(big,quant). 262 | adj(small,quant). 263 | adj(large,quant). 264 | adj(old,quant). 265 | adj(new,quant). 266 | adj(populous,quant). 267 | 268 | rel_adj(greater,great). 269 | rel_adj(less,small). 270 | rel_adj(bigger,big). 271 | rel_adj(smaller,small). 272 | rel_adj(larger,large). 273 | rel_adj(older,old). 274 | rel_adj(newer,new). 275 | 276 | sup_adj(biggest,big). 277 | sup_adj(smallest,small). 278 | sup_adj(largest,large). 279 | sup_adj(oldest,old). 280 | sup_adj(newest,new). 281 | 282 | noun_form(proportion,proportion,_). 283 | noun_form(percentage,percentage,_). 284 | 285 | noun_sin(average). 286 | noun_sin(total). 287 | noun_sin(sum). 288 | noun_sin(degree). 289 | noun_sin(sqmile). 290 | noun_sin(ksqmile). 291 | noun_sin(thousand). 292 | noun_sin(million). 293 | noun_sin(time). 294 | noun_sin(place). 295 | noun_sin(area). 296 | noun_sin(capital). 297 | noun_sin(city). 298 | noun_sin(continent). 299 | noun_sin(country). 300 | noun_sin(latitude). 301 | noun_sin(longitude). 302 | noun_sin(ocean). 303 | noun_sin(person). 304 | noun_sin(population). 305 | noun_sin(region). 306 | noun_sin(river). 307 | noun_sin(sea). 308 | noun_sin(seamass). 309 | noun_sin(number). 310 | 311 | noun_plu(averages,average). 312 | noun_plu(totals,total). 313 | noun_plu(sums,sum). 314 | noun_plu(degrees,degree). 315 | noun_plu(sqmiles,sqmile). 316 | noun_plu(ksqmiles,ksqmile). 317 | noun_plu(million,million). 318 | noun_plu(thousand,thousand). 319 | noun_plu(times,time). 320 | noun_plu(places,place). 321 | noun_plu(areas,area). 322 | noun_plu(capitals,capital). 323 | noun_plu(cities,city). 324 | noun_plu(continents,continent). 325 | noun_plu(countries,country). 326 | noun_plu(latitudes,latitude). 327 | noun_plu(longitudes,longitude). 328 | noun_plu(oceans,ocean). 329 | noun_plu(persons,person). noun_plu(people,person). 330 | noun_plu(populations,population). 331 | noun_plu(regions,region). 332 | noun_plu(rivers,river). 333 | noun_plu(seas,sea). 334 | noun_plu(seamasses,seamass). 335 | noun_plu(numbers,number). 336 | 337 | verb_root(border). 338 | verb_root(contain). 339 | verb_root(drain). 340 | verb_root(exceed). 341 | verb_root(flow). 342 | verb_root(rise). 343 | 344 | regular_pres(rise). 345 | 346 | verb_form(rises,rise,pres+fin,3+sin). 347 | verb_form(rose,rise,past+fin,_). 348 | verb_form(risen,rise,past+part,_). 349 | 350 | regular_pres(border). 351 | 352 | regular_past(bordered,border). 353 | 354 | verb_form(borders,border,pres+fin,3+sin). 355 | verb_form(bordering,border,pres+part,_). 356 | 357 | regular_pres(contain). 358 | 359 | regular_past(contained,contain). 360 | 361 | verb_form(contains,contain,pres+fin,3+sin). 362 | verb_form(containing,contain,pres+part,_). 363 | 364 | regular_pres(drain). 365 | 366 | regular_past(drained,drain). 367 | 368 | verb_form(drains,drain,pres+fin,3+sin). 369 | verb_form(draining,drain,pres+part,_). 370 | 371 | regular_pres(exceed). 372 | 373 | regular_past(exceeded,exceed). 374 | 375 | verb_form(exceeds,exceed,pres+fin,3+sin). 376 | verb_form(exceeding,exceed,pres+part,_). 377 | 378 | verb_type(rise,main+intrans). 379 | verb_type(border,main+trans). 380 | verb_type(contain,main+trans). 381 | verb_type(drain,main+intrans). 382 | verb_type(exceed,main+trans). 383 | 384 | regular_pres(flow). 385 | 386 | regular_past(flowed,flow). 387 | 388 | verb_form(flows,flow,pres+fin,3+sin). 389 | verb_form(flowing,flow,pres+part,_). 390 | 391 | verb_type(flow,main+intrans). 392 | 393 | adverb(yesterday). 394 | adverb(tomorrow). 395 | 396 | -------------------------------------------------------------------------------- /prolog/chat80/newg.pl: -------------------------------------------------------------------------------- 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 | sentence(B,C,D,E,F) :- 24 | declarative(B,C,G,E,H), 25 | terminator(.,G,D,H,F). 26 | sentence(B,C,D,E,F) :- 27 | wh_question(B,C,G,E,H), 28 | terminator(?,G,D,H,F). 29 | sentence(B,C,D,E,F) :- 30 | topic(C,G,E,H), 31 | wh_question(B,G,I,H,J), 32 | terminator(?,I,D,J,F). 33 | sentence(B,C,D,E,F) :- 34 | yn_question(B,C,G,E,H), 35 | terminator(?,G,D,H,F). 36 | sentence(B,C,D,E,F) :- 37 | imperative(B,C,G,E,H), 38 | terminator(!,G,D,H,F). 39 | 40 | 41 | pp(B,C,D,E,F,F,G,H) :- 42 | virtual(pp(B,C,D,E),G,H). 43 | pp(pp(B,C),D,E,F,G,H,I,J) :- 44 | prep(B,G,K,I,L), 45 | prep_case(M), 46 | np(C,N,M,O,D,E,F,K,H,L,J). 47 | 48 | 49 | topic(B,C,D,x(gap,nonterminal,pp(E,compl,F,G),H)) :- 50 | pp(E,compl,F,G,B,I,D,J), 51 | opt_comma(I,C,J,H). 52 | 53 | 54 | opt_comma(B,C,D,E) :- 55 | ~(',',B,C,D,E). 56 | opt_comma(B,B,C,C). 57 | 58 | 59 | declarative(decl(B),C,D,E,F) :- 60 | s(B,G,C,D,E,F). 61 | 62 | 63 | wh_question(whq(B,C),D,E,F,G) :- 64 | variable_q(B,H,I,J,D,K,F,L), 65 | question(I,J,C,K,E,L,G). 66 | 67 | 68 | np(B,C,D,E,F,G,H,I,I,J,K) :- 69 | virtual(np(B,C,D,E,F,G,H),J,K). 70 | np(np(B,C,[]),B,D,def,E,F,G,H,I,J,K) :- 71 | is_pp(F), 72 | pers_pron(C,B,L,H,I,J,K), 73 | empty(G), 74 | role(L,decl,D). 75 | np(np(B,C,D),B,E,F,G,H,I,J,K,L,M) :- 76 | is_pp(H), 77 | np_head(C,B,F+N,O,D,J,P,L,Q), 78 | np_all(R), 79 | np_compls(N,B,G,O,R,I,P,K,Q,M). 80 | np(part(B,C),3+D,E,indef,F,G,H,I,J,K,L) :- 81 | is_pp(G), 82 | determiner(B,D,indef,I,M,K,N), 83 | ~(of,M,O,N,P), 84 | s_all(Q), 85 | prep_case(R), 86 | np(C,3+plu,R,def,F,Q,H,O,J,P,L). 87 | 88 | 89 | variable_q(B,C,D,E,F,G,H,x(gap,nonterminal,np(I,C,E,J,K,L,M),N)) :- 90 | whq(B,C,I,D,F,G,H,N), 91 | do_trace(L,M). 92 | variable_q(B,C,compl,D,E,F,G,x(gap,nonterminal,pp(pp(H,I),compl,J,K),L)) :- 93 | prep(H,E,M,G,N), 94 | whq(B,C,I,O,M,F,N,L), 95 | do_trace(J,K), 96 | compl_case(D). 97 | variable_q(B,C,compl,D,E,F,G,x(gap,nonterminal,adv_phrase(pp(H,np(C,np_head(int_det(B),[],I),[])),J,K),L)) :- 98 | context_pron(H,I,E,F,G,L), 99 | do_trace(J,K), 100 | verb_case(D). 101 | variable_q(B,C,compl,D,E,F,G,x(gap,nonterminal,pred(adj,value(H,wh(B)),I),J)) :- 102 | ~(how,E,K,G,L), 103 | adj(quant,H,K,F,L,J), 104 | empty(I), 105 | verb_case(D). 106 | 107 | 108 | adv_phrase(B,C,D,E,E,F,G) :- 109 | virtual(adv_phrase(B,C,D),F,G). 110 | adv_phrase(pp(B,C),D,E,F,G,H,I) :- 111 | loc_pred(B,F,J,H,K), 112 | pp(pp(prep(of),C),compl,D,E,J,G,K,I). 113 | 114 | 115 | pred(B,C,D,E,E,F,G) :- 116 | virtual(pred(B,C,D),F,G). 117 | pred(B,C,D,E,F,G,H) :- 118 | adj_phrase(C,D,E,F,G,H). 119 | pred(neg,B,C,D,E,F,G) :- 120 | s_all(H), 121 | pp(B,compl,H,C,D,E,F,G). 122 | pred(B,C,D,E,F,G,H) :- 123 | s_all(I), 124 | adv_phrase(C,I,D,E,F,G,H). 125 | 126 | 127 | whq(B,C,D,undef,E,F,G,H) :- 128 | int_det(B,C,E,I,G,J), 129 | s_all(K), 130 | np(D,C,L,M,subj,K,N,I,F,J,H). 131 | whq(B,3+C,np(3+C,wh(B),[]),D,E,F,G,H) :- 132 | int_pron(D,E,F,G,H). 133 | 134 | 135 | int_det(B,3+C,D,E,F,G) :- 136 | whose(B,C,D,E,F,G). 137 | int_det(B,3+C,D,E,F,G) :- 138 | int_art(B,C,D,E,F,G). 139 | 140 | 141 | np_head0(B,C,D,E,E,F,G) :- 142 | virtual(np_head0(B,C,D),F,G). 143 | np_head0(name(B),3+sin,def+proper,C,D,E,F) :- 144 | name(B,C,D,E,F). 145 | np_head0(np_head(B,C,D),3+E,F+common,G,H,I,J) :- 146 | determiner(B,E,F,G,K,I,L), 147 | adjs(C,K,M,L,N), 148 | noun(D,E,M,H,N,J). 149 | np_head0(B,C,def+proper,D,E,F,x(nogap,nonterminal,gen_marker,G)) :- 150 | poss_pron(B,C,D,E,F,G). 151 | np_head0(np_head(B,[],C),3+sin,indef+common,D,E,F,G) :- 152 | quantifier_pron(B,C,D,E,F,G). 153 | 154 | 155 | gen_marker(B,B,C,D) :- 156 | virtual(gen_marker,C,D). 157 | gen_marker(B,C,D,E) :- 158 | ~('''',B,F,D,G), 159 | an_s(F,C,G,E). 160 | 161 | 162 | whose(B,C,D,E,F,x(nogap,nonterminal,np_head0(wh(B),C,proper),x(nogap,nonterminal,gen_marker,G))) :- 163 | ~(whose,D,E,F,G). 164 | 165 | 166 | question(B,C,D,E,F,G,H) :- 167 | subj_question(B), 168 | role(subj,I,C), 169 | s(D,J,E,F,G,H). 170 | question(B,C,D,E,F,G,H) :- 171 | fronted_verb(B,C,E,I,G,J), 172 | s(D,K,I,F,J,H). 173 | 174 | 175 | det(B,C,D,E,E,F,G) :- 176 | virtual(det(B,C,D),F,G). 177 | det(det(B),C,D,E,F,G,H) :- 178 | terminal(I,E,F,G,H), 179 | det(I,C,B,D). 180 | det(generic,B,generic,C,C,D,D). 181 | 182 | 183 | int_art(B,C,D,E,F,x(nogap,nonterminal,det(G,C,def),H)) :- 184 | int_art(B,C,G,D,E,F,H). 185 | 186 | 187 | subj_question(subj). 188 | 189 | 190 | subj_question(undef). 191 | 192 | 193 | yn_question(q(B),C,D,E,F) :- 194 | fronted_verb(nil,G,C,H,E,I), 195 | s(B,J,H,D,I,F). 196 | 197 | 198 | verb_form(B,C,D,E,F,F,G,H) :- 199 | virtual(verb_form(B,C,D,E),G,H). 200 | verb_form(B,C,D,E,F,G,H,I) :- 201 | terminal(J,F,G,H,I), 202 | verb_form(J,B,C,D). 203 | 204 | 205 | neg(B,C,D,D,E,F) :- 206 | virtual(neg(B,C),E,F). 207 | neg(aux+B,neg,C,D,E,F) :- 208 | ~(not,C,D,E,F). 209 | neg(B,pos,C,C,D,D). 210 | 211 | 212 | fronted_verb(B,C,D,E,F,x(gap,nonterminal,verb_form(G,H,I,J),x(nogap,nonterminal,neg(K,L),M))) :- 213 | verb_form(G,H,I,N,D,O,F,P), 214 | verb_type(G,aux+Q), 215 | role(B,J,C), 216 | neg(R,L,O,E,P,M). 217 | 218 | 219 | imperative(imp(B),C,D,E,F) :- 220 | imperative_verb(C,G,E,H), 221 | s(B,I,G,D,H,F). 222 | 223 | 224 | imperative_verb(B,C,D,x(nogap,terminal,you,x(nogap,nonterminal,verb_form(E,imp+fin,2+sin,main),F))) :- 225 | verb_form(E,inf,G,H,B,C,D,F). 226 | 227 | 228 | s(s(B,C,D,E),F,G,H,I,J) :- 229 | subj(B,K,L,G,M,I,N), 230 | verb(C,K,L,O,M,P,N,Q), 231 | empty(R), 232 | s_all(S), 233 | verb_args(L,O,D,R,T,P,U,Q,V), 234 | minus(S,T,W), 235 | my_plus(S,T,X), 236 | verb_mods(E,W,X,F,U,H,V,J). 237 | 238 | 239 | subj(there,B,C+be,D,E,F,G) :- 240 | ~(there,D,E,F,G). 241 | subj(B,C,D,E,F,G,H) :- 242 | s_all(I), 243 | subj_case(J), 244 | np(B,C,J,K,subj,I,L,E,F,G,H). 245 | 246 | 247 | np_head(B,C,D,E,F,G,H,I,J) :- 248 | np_head0(K,L,M,G,N,I,O), 249 | possessive(K,L,M,P,P,B,C,D,E,F,N,H,O,J). 250 | 251 | 252 | np_compls(proper,B,C,[],D,E,F,F,G,G) :- 253 | empty(E). 254 | np_compls(common,B,C,D,E,F,G,H,I,J) :- 255 | np_all(K), 256 | np_mods(B,C,L,D,E,M,K,N,G,O,I,P), 257 | relative(B,L,M,N,F,O,H,P,J). 258 | 259 | 260 | possessive(B,C,D,[],E,F,G,H,I,J,K,L,M,N) :- 261 | gen_case(K,O,M,P), 262 | np_head0(Q,R,S,O,T,P,U), 263 | possessive(Q,R,S,V,[pp(poss,np(C,B,E))|V],F,G,H,I,J,T,L,U,N). 264 | possessive(B,C,D,E,F,B,C,D,E,F,G,G,H,H). 265 | 266 | 267 | gen_case(B,C,D,x(nogap,terminal,the,E)) :- 268 | gen_marker(B,C,D,E). 269 | 270 | 271 | an_s(B,C,D,E) :- 272 | ~(s,B,C,D,E). 273 | an_s(B,B,C,C). 274 | 275 | 276 | determiner(B,C,D,E,F,G,H) :- 277 | det(B,C,D,E,F,G,H). 278 | determiner(B,C,D,E,F,G,H) :- 279 | quant_phrase(B,C,D,E,F,G,H). 280 | 281 | 282 | quant_phrase(quant(B,C),D,E,F,G,H,I) :- 283 | quant(B,E,F,J,H,K), 284 | number(C,D,J,G,K,I). 285 | 286 | 287 | quant(B,indef,C,D,E,F) :- 288 | neg_adv(G,B,C,H,E,I), 289 | comp_adv(G,H,J,I,K), 290 | ~(than,J,D,K,F). 291 | quant(B,indef,C,D,E,F) :- 292 | ~(at,C,G,E,H), 293 | sup_adv(I,G,D,H,F), 294 | sup_op(I,B). 295 | quant(the,def,B,C,D,E) :- 296 | ~(the,B,C,D,E). 297 | quant(same,indef,B,B,C,C). 298 | 299 | 300 | neg_adv(B,not+B,C,D,E,F) :- 301 | ~(not,C,D,E,F). 302 | neg_adv(B,B,C,C,D,D). 303 | 304 | 305 | sup_op(least,not+less). 306 | sup_op(most,not+more). 307 | 308 | 309 | np_mods(B,C,D,[E|F],G,H,I,J,K,L,M,N) :- 310 | np_mod(B,C,E,G,O,K,P,M,Q), 311 | do_trace(R), 312 | my_plus(R,O,S), 313 | minus(G,S,T), 314 | my_plus(O,G,U), 315 | np_mods(B,C,D,F,T,H,U,J,P,L,Q,N). 316 | np_mods(B,C,D,D,E,E,F,F,G,G,H,H). 317 | 318 | 319 | np_mod(B,C,D,E,F,G,H,I,J) :- 320 | pp(D,C,E,F,G,H,I,J). 321 | np_mod(B,C,D,E,F,G,H,I,J) :- 322 | reduced_relative(B,D,E,F,G,H,I,J). 323 | 324 | 325 | verb_mods([B|C],D,E,F,G,H,I,J) :- 326 | verb_mod(B,D,K,G,L,I,M), 327 | do_trace(N), 328 | my_plus(N,K,O), 329 | minus(D,O,P), 330 | my_plus(K,D,Q), 331 | verb_mods(C,P,Q,F,L,H,M,J). 332 | verb_mods([],B,C,C,D,D,E,E). 333 | 334 | 335 | verb_mod(B,C,D,E,F,G,H) :- 336 | adv_phrase(B,C,D,E,F,G,H). 337 | verb_mod(B,C,D,E,F,G,H) :- 338 | is_adv(C), 339 | adverb(B,E,F,G,H), 340 | empty(D). 341 | verb_mod(B,C,D,E,F,G,H) :- 342 | pp(B,compl,C,D,E,F,G,H). 343 | 344 | 345 | adjs([B|C],D,E,F,G) :- 346 | pre_adj(B,D,H,F,I), 347 | adjs(C,H,E,I,G). 348 | adjs([],B,B,C,C). 349 | 350 | 351 | pre_adj(B,C,D,E,F) :- 352 | adj(G,B,C,D,E,F). 353 | pre_adj(B,C,D,E,F) :- 354 | sup_phrase(B,C,D,E,F). 355 | 356 | 357 | sup_phrase(sup(most,B),C,D,E,F) :- 358 | sup_adj(B,C,D,E,F). 359 | sup_phrase(sup(B,C),D,E,F,G) :- 360 | sup_adv(B,D,I,F,J), 361 | adj(quant,C,I,E,J,G). 362 | 363 | 364 | comp_phrase(comp(B,C,D),E,F,G,H,I) :- 365 | comp(B,C,F,J,H,K), 366 | % np_no_do_trace(L), % JW: Not defined 367 | prep_case(M), 368 | np(D,N,M,O,compl,L,E,J,G,K,I). 369 | 370 | 371 | comp(B,C,D,E,F,G) :- 372 | comp_adv(B,D,H,F,I), 373 | adj(quant,C,H,J,I,K), 374 | ~(than,J,E,K,G). 375 | comp(more,B,C,D,E,F) :- 376 | rel_adj(B,C,G,E,H), 377 | ~(than,G,D,H,F). 378 | comp(same,B,C,D,E,F) :- 379 | ~(as,C,G,E,H), 380 | adj(quant,B,G,I,H,J), 381 | ~(as,I,D,J,F). 382 | 383 | 384 | relative(B,[C],D,E,F,G,H,I,J) :- 385 | is_pred(D), 386 | rel_conj(B,K,C,F,G,H,I,J). 387 | relative(B,[],C,D,D,E,E,F,F). 388 | 389 | 390 | rel_conj(B,C,D,E,F,G,H,I) :- 391 | rel(B,J,K,F,L,H,M), 392 | rel_rest(B,C,J,D,K,E,L,G,M,I). 393 | 394 | 395 | rel_rest(B,C,D,E,F,G,H,I,J,K) :- 396 | conj(C,L,D,M,E,H,N,J,O), 397 | rel_conj(B,L,M,G,N,I,O,K). 398 | rel_rest(B,C,D,D,E,E,F,F,G,G). 399 | 400 | 401 | rel(B,rel(C,D),E,F,G,H,I) :- 402 | xopen(F,J,H,K), 403 | variable(B,C,J,L,K,M), 404 | s(D,N,L,O,M,P), 405 | do_trace(Q), 406 | minus(N,Q,E), 407 | close(O,G,P,I). 408 | 409 | 410 | variable(B,C,D,E,F,x(gap,nonterminal,np(np(B,wh(C),[]),B,G,H,I,J,K),L)) :- 411 | ~(that,D,E,F,L), 412 | do_trace(J,K). 413 | variable(B,C,D,E,F,x(gap,nonterminal,np(G,H,I,J,K,L,M),N)) :- 414 | wh(C,B,G,H,I,D,E,F,N), 415 | do_trace(L,M). 416 | variable(B,C,D,E,F,x(gap,nonterminal,pp(pp(G,H),compl,I,J),K)) :- 417 | prep(G,D,L,F,M), 418 | wh(C,B,H,N,O,L,E,M,K), 419 | do_trace(I,J), 420 | compl_case(O). 421 | 422 | 423 | wh(B,C,np(C,wh(B),[]),C,D,E,F,G,H) :- 424 | rel_pron(I,E,F,G,H), 425 | role(I,decl,D). 426 | wh(B,C,np(D,E,[pp(F,G)]),D,H,I,J,K,L) :- 427 | np_head0(E,D,M+common,I,N,K,O), 428 | prep(F,N,P,O,Q), 429 | wh(B,C,G,R,S,P,J,Q,L). 430 | wh(B,C,D,E,F,G,H,I,J) :- 431 | whose(B,C,G,K,I,L), 432 | s_all(M), 433 | np(D,E,F,def,subj,M,N,K,H,L,J). 434 | 435 | 436 | reduced_relative(B,C,D,E,F,G,H,I) :- 437 | is_pred(D), 438 | reduced_rel_conj(B,J,C,E,F,G,H,I). 439 | 440 | 441 | reduced_rel_conj(B,C,D,E,F,G,H,I) :- 442 | reduced_rel(B,J,K,F,L,H,M), 443 | reduced_rel_rest(B,C,J,D,K,E,L,G,M,I). 444 | 445 | 446 | reduced_rel_rest(B,C,D,E,F,G,H,I,J,K) :- 447 | conj(C,L,D,M,E,H,N,J,O), 448 | reduced_rel_conj(B,L,M,G,N,I,O,K). 449 | reduced_rel_rest(B,C,D,D,E,E,F,F,G,G). 450 | 451 | 452 | reduced_rel(B,reduced_rel(C,D),E,F,G,H,I) :- 453 | xopen(F,J,H,K), 454 | reduced_wh(B,C,J,L,K,M), 455 | s(D,N,L,O,M,P), 456 | do_trace(Q), 457 | minus(N,Q,E), 458 | close(O,G,P,I). 459 | 460 | 461 | reduced_wh(B,C,D,E,F,x(nogap,nonterminal,np(np(B,wh(C),[]),B,G,H,I,J,K),x(nogap,nonterminal,verb_form(be,pres+fin,B,main),x(nogap,nonterminal,neg(L,M),x(nogap,nonterminal,pred(M,N,O),P))))) :- 462 | neg(Q,M,D,R,F,S), 463 | pred(M,N,O,R,E,S,P), 464 | do_trace(J,K), 465 | subj_case(G). 466 | reduced_wh(B,C,D,E,F,x(nogap,nonterminal,np(np(B,wh(C),[]),B,G,H,I,J,K),x(nogap,nonterminal,verb(L,M,N,O),P))) :- 467 | participle(L,N,O,D,E,F,P), 468 | do_trace(J,K), 469 | subj_case(G). 470 | reduced_wh(B,C,D,E,F,x(nogap,nonterminal,np(G,H,I,J,K,L,M),x(gap,nonterminal,np(np(B,wh(C),[]),B,N,O,P,Q,R),S))) :- 471 | s_all(T), 472 | subj_case(I), 473 | verb_case(N), 474 | np(G,H,U,J,subj,T,V,D,E,F,S), 475 | do_trace(L,M), 476 | do_trace(Q,R). 477 | 478 | 479 | verb(B,C,D,E,F,F,G,H) :- 480 | virtual(verb(B,C,D,E),G,H). 481 | verb(verb(B,C,D+fin,E,F),G,H,C,I,J,K,L) :- 482 | verb_form(M,D+fin,G,N,I,O,K,P), 483 | verb_type(M,Q), 484 | neg(Q,F,O,R,P,S), 485 | rest_verb(N,M,B,C,E,R,J,S,L), 486 | verb_type(B,H). 487 | 488 | 489 | rest_verb(aux,have,B,C,[perf|D],E,F,G,H) :- 490 | verb_form(I,past+part,J,K,E,L,G,M), 491 | have(I,B,C,D,L,F,M,H). 492 | rest_verb(aux,be,B,C,D,E,F,G,H) :- 493 | verb_form(I,J,K,L,E,M,G,N), 494 | be(J,I,B,C,D,M,F,N,H). 495 | rest_verb(aux,do,B,active,[],C,D,E,F) :- 496 | verb_form(B,inf,G,H,C,D,E,F). 497 | rest_verb(main,B,B,active,[],C,C,D,D). 498 | 499 | 500 | have(be,B,C,D,E,F,G,H) :- 501 | verb_form(I,J,K,L,E,M,G,N), 502 | be(J,I,B,C,D,M,F,N,H). 503 | have(B,B,active,[],C,C,D,D). 504 | 505 | 506 | be(past+part,B,B,passive,[],C,C,D,D). 507 | be(pres+part,B,C,D,[prog],E,F,G,H) :- 508 | passive(B,C,D,E,F,G,H). 509 | 510 | 511 | passive(be,B,passive,C,D,E,F) :- 512 | verb_form(B,past+part,G,H,C,D,E,F), 513 | verb_type(B,I), 514 | passive(I). 515 | passive(B,B,active,C,C,D,D). 516 | 517 | 518 | participle(verb(B,C,inf,D,E),F,C,G,H,I,J) :- 519 | neg(K,E,G,L,I,M), 520 | verb_form(B,N,O,P,L,H,M,J), 521 | participle(N,C,D), 522 | verb_type(B,F). 523 | 524 | 525 | passive(B+trans). 526 | passive(B+ditrans). 527 | 528 | 529 | participle(pres+part,active,[prog]). 530 | participle(past+part,passive,[]). 531 | 532 | 533 | close(B,B,C,D) :- 534 | virtual(close,C,D). 535 | 536 | 537 | xopen(B,B,C,x(gap,nonterminal,close,C)). 538 | 539 | 540 | verb_args(B+C,D,E,F,G,H,I,J,K) :- 541 | advs(E,L,M,H,N,J,O), 542 | verb_args(C,D,L,F,G,N,I,O,K). 543 | verb_args(trans,active,[arg(dir,B)],C,D,E,F,G,H) :- 544 | verb_arg(np,B,D,E,F,G,H). 545 | verb_args(ditrans,B,[arg(C,D)|E],F,G,H,I,J,K) :- 546 | verb_arg(np,D,L,H,M,J,N), 547 | object(C,E,L,G,M,I,N,K). 548 | verb_args(be,B,[void],C,C,D,E,F,G) :- 549 | terminal(there,D,E,F,G). 550 | verb_args(be,B,[arg(pred,C)],D,E,F,G,H,I) :- 551 | pred_conj(J,C,E,F,G,H,I). 552 | verb_args(be,B,[arg(dir,C)],D,E,F,G,H,I) :- 553 | verb_arg(np,C,E,F,G,H,I). 554 | verb_args(have,active,[arg(dir,B)],C,D,E,F,G,H) :- 555 | verb_arg(np,B,D,E,F,G,H). 556 | verb_args(B,C,[],D,D,E,E,F,F) :- 557 | no_args(B). 558 | 559 | 560 | object(B,C,D,E,F,G,H,I) :- 561 | adv(J), 562 | minus(J,D,K), 563 | advs(C,L,K,F,M,H,N), 564 | obj(B,L,D,E,M,G,N,I). 565 | 566 | 567 | obj(ind,[arg(dir,B)],C,D,E,F,G,H) :- 568 | verb_arg(np,B,D,E,F,G,H). 569 | obj(dir,[],B,B,C,C,D,D). 570 | 571 | 572 | pred_conj(B,C,D,E,F,G,H) :- 573 | pred(I,J,K,E,L,G,M), 574 | pred_rest(B,J,C,K,D,L,F,M,H). 575 | 576 | 577 | pred_rest(B,C,D,E,F,G,H,I,J) :- 578 | conj(B,K,C,L,D,G,M,I,N), 579 | pred_conj(K,L,F,M,H,N,J). 580 | pred_rest(B,C,C,D,D,E,E,F,F). 581 | 582 | 583 | verb_arg(np,B,C,D,E,F,G) :- 584 | s_all(H), 585 | verb_case(I), 586 | np(B,J,I,K,compl,H,C,D,E,F,G). 587 | 588 | 589 | advs([B|C],D,E,F,G,H,I) :- 590 | is_adv(E), 591 | adverb(B,F,J,H,K), 592 | advs(C,D,E,J,G,K,I). 593 | advs(B,B,C,D,D,E,E). 594 | 595 | 596 | adj_phrase(B,C,D,E,F,G) :- 597 | adj(H,B,D,E,F,G), 598 | empty(C). 599 | adj_phrase(B,C,D,E,F,G) :- 600 | comp_phrase(B,C,D,E,F,G). 601 | 602 | 603 | no_args(trans). 604 | no_args(ditrans). 605 | no_args(intrans). 606 | 607 | 608 | conj(conj(B,C),conj(B,D),E,F,conj(B,E,F),G,H,I,J) :- 609 | conj(B,C,D,G,H,I,J). 610 | 611 | 612 | noun(B,C,D,E,F,G) :- 613 | terminal(H,D,E,F,G), 614 | noun_form(H,B,C). 615 | 616 | 617 | adj(B,adj(C),D,E,F,G) :- 618 | terminal(C,D,E,F,G), 619 | adj(C,B). 620 | 621 | 622 | prep(prep(B),C,D,E,F) :- 623 | terminal(B,C,D,E,F), 624 | prep(B). 625 | 626 | 627 | rel_adj(adj(B),C,D,E,F) :- 628 | terminal(G,C,D,E,F), 629 | rel_adj(G,B). 630 | 631 | 632 | sup_adj(adj(B),C,D,E,F) :- 633 | terminal(G,C,D,E,F), 634 | sup_adj(G,B). 635 | 636 | 637 | comp_adv(less,B,C,D,E) :- 638 | ~(less,B,C,D,E). 639 | comp_adv(more,B,C,D,E) :- 640 | ~(more,B,C,D,E). 641 | 642 | 643 | sup_adv(least,B,C,D,E) :- 644 | ~(least,B,C,D,E). 645 | sup_adv(most,B,C,D,E) :- 646 | ~(most,B,C,D,E). 647 | 648 | 649 | rel_pron(B,C,D,E,F) :- 650 | terminal(G,C,D,E,F), 651 | rel_pron(G,B). 652 | 653 | 654 | name(B,C,D,E,F) :- 655 | opt_the(C,G,E,H), 656 | terminal(B,G,D,H,F), 657 | name(B). 658 | 659 | 660 | int_art(B,plu,quant(same,wh(B)),C,D,E,F) :- 661 | ~(how,C,G,E,H), 662 | ~(many,G,D,H,F). 663 | int_art(B,C,D,E,F,G,H) :- 664 | terminal(I,E,F,G,H), 665 | int_art(I,B,C,D). 666 | 667 | 668 | int_pron(B,C,D,E,F) :- 669 | terminal(G,C,D,E,F), 670 | int_pron(G,B). 671 | 672 | 673 | adverb(adv(B),C,D,E,F) :- 674 | terminal(B,C,D,E,F), 675 | adverb(B). 676 | 677 | 678 | poss_pron(pronoun(B),C+D,E,F,G,H) :- 679 | terminal(I,E,F,G,H), 680 | poss_pron(I,B,C,D). 681 | 682 | 683 | pers_pron(pronoun(B),C+D,E,F,G,H,I) :- 684 | terminal(J,F,G,H,I), 685 | pers_pron(J,B,C,D,E). 686 | 687 | 688 | quantifier_pron(B,C,D,E,F,G) :- 689 | terminal(H,D,E,F,G), 690 | quantifier_pron(H,B,C). 691 | 692 | 693 | context_pron(prep(in),place,B,C,D,E) :- 694 | ~(where,B,C,D,E). 695 | context_pron(prep(at),time,B,C,D,E) :- 696 | ~(when,B,C,D,E). 697 | 698 | 699 | number(nb(B),C,D,E,F,G) :- 700 | terminal(H,D,E,F,G), 701 | number(H,B,C). 702 | 703 | 704 | terminator(B,C,D,E,F) :- 705 | terminal(G,C,D,E,F), 706 | terminator(G,B). 707 | 708 | 709 | opt_the(B,B,C,C). 710 | opt_the(B,C,D,E) :- 711 | ~(the,B,C,D,E). 712 | 713 | 714 | conj(B,list,list,C,D,E,F) :- 715 | terminal(',',C,D,E,F). 716 | conj(B,list,end,C,D,E,F) :- 717 | terminal(B,C,D,E,F), 718 | conj(B). 719 | 720 | 721 | loc_pred(B,C,D,E,F) :- 722 | terminal(G,C,D,E,F), 723 | loc_pred(G,B). 724 | 725 | 726 | ~(B,C,D,E,F) :- 727 | terminal(B,C,D,E,F), 728 | ~B. 729 | 730 | -------------------------------------------------------------------------------- /prolog/chat80/ptree.pl: -------------------------------------------------------------------------------- 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 | /* Print term as a tree */ 24 | 25 | :- mode print_tree(+). 26 | :- mode pt(+,+). 27 | :- mode pl(+,+). 28 | :- mode as_is(+). 29 | 30 | :- public print_tree/1. 31 | 32 | print_tree(T) :- 33 | numbervars(T,1,_), 34 | pt(T,0), nl, fail. 35 | print_tree(_). 36 | 37 | pt(A,I) :- 38 | as_is(A), !, 39 | tab(I), write(A), nl. 40 | pt([T|Ts],I) :- !, 41 | pt(T,I), 42 | pl(Ts,I). 43 | pt(T,I) :- !, 44 | T=..[F|As], 45 | tab(I), write(F), nl, 46 | I0 is I+3, 47 | pl(As,I0). 48 | 49 | pl([],_) :- !. 50 | pl([A|As],I) :- !, 51 | pt(A,I), 52 | pl(As,I). 53 | 54 | as_is(A) :- atomic(A), !. 55 | as_is('$VAR'(_)) :- !. 56 | as_is(X) :- 57 | quote(X). 58 | 59 | 60 | -------------------------------------------------------------------------------- /prolog/chat80/qplan.pl: -------------------------------------------------------------------------------- 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 | % QPLAN - supplies the control information (ie. sequencing and cuts) needed 24 | % for efficient execution of a query. 25 | 26 | :-public qplan/2. 27 | 28 | :-mode 29 | qplan(+,-), 30 | qplan(+,+,-,-), 31 | mark(+,-,+,-), 32 | subquery(+,-,?,?,?,?), 33 | negate(+,+,-), 34 | negationcost(+,-), 35 | setofcost(+,+,-), 36 | variables(+,+,-), 37 | variables(+,+,+,-), 38 | quantificate(+,+,?,-), 39 | log2(+,-), 40 | schedule(+,+,-), 41 | schedule1(+,+,-), 42 | maybe_cut(+,+,?,-), 43 | plan(+,+,+,+,-), 44 | is_conjunction(+), 45 | marked(+,?,?,?), 46 | freevars(+,?), 47 | best_goal(+,+,+,?,?,-), 48 | instantiate(+,+,-), 49 | instantiate0(+,+,+,-), 50 | recombine(+,+,-), 51 | incorporate(+,+,+,+,+,-), 52 | incorporate0(+,+,+,+,-), 53 | minimum(+,+,-), 54 | add_keys(+,-), 55 | strip_keys(+,-), 56 | strip_key(+,?), 57 | variablise(+,+,-), 58 | variablise(+,+,+,+), 59 | cost(+,+,-), 60 | cost(+,+,+,+,-), 61 | instantiated(+,+,-). 62 | 63 | qplan((P:-Q),(P1:-Q1)) :- qplan(P,Q,P1,Q1), !. 64 | qplan(P,P). 65 | 66 | qplan(X0,P0,X,P) :- 67 | numbervars(X0,0,I), variables(X0,0,Vg), 68 | numbervars(P0,I,N), 69 | mark(P0,L,0,Vl), 70 | schedule(L,Vg,P1), 71 | quantificate(Vl,0,P1,P2), 72 | functor(VA,$,N), 73 | variablise(X0,VA,X), 74 | variablise(P2,VA,P). 75 | 76 | mark(X^P,L,Q0,Q) :- !, variables(X,Q0,Q1), mark(P,L,Q1,Q). 77 | mark((P1,P2),L,Q0,Q) :- !, 78 | mark(P1,L1,Q0,Q1), 79 | mark(P2,L2,Q1,Q), 80 | recombine(L1,L2,L). 81 | mark(\+P,L,Q,Q) :- !, mark(P,L0,0,Vl), negate(L0,Vl,L). 82 | mark(SQ,[m(V,C,SQ1)],Q0,Q0) :- subquery(SQ,SQ1,X,P,N,Q), !, 83 | mark(P,L,0,Vl), 84 | L=[Q], % Too bad about the general case! 85 | marked(Q,Vq,C0,_), 86 | variables(X,Vl,Vlx), 87 | setminus(Vq,Vlx,V0), 88 | setofcost(V0,C0,C), 89 | variables(N,V0,V). 90 | mark(P,[m(V,C,P)],Q,Q) :- 91 | variables(P,0,V), 92 | cost(P,V,C). 93 | 94 | subquery(setof(X,P,S),setof(X,Q,S),X,P,S,Q). 95 | subquery(numberof(X,P,N),numberof(X,Q,N),X,P,N,Q). 96 | 97 | negate([],_,[]). 98 | negate([P|L],Vl,[m(Vg,C,\+P)|L1]) :- 99 | freevars(P,V), 100 | setminus(V,Vl,Vg), 101 | negationcost(Vg,C), 102 | negate(L,Vl,L1). 103 | 104 | negationcost(0,0) :- !. 105 | negationcost(V,1000). 106 | 107 | setofcost(0,_,0) :- !. 108 | setofcost(_,C,C). 109 | 110 | variables('$VAR'(N),V0,V) :- !, setplusitem(V0,N,V). 111 | variables(T,V,V) :- atomic(T), !. 112 | variables(T,V0,V) :- functor(T,_,N), variables(N,T,V0,V). 113 | 114 | variables(0,_,V,V) :- !. 115 | variables(N,T,V0,V) :- N1 is N-1, 116 | arg(N,T,X), 117 | variables(X,V0,V1), 118 | variables(N1,T,V1,V). 119 | 120 | quantificate(W-V,N,P0,P) :- !, N1 is N+18, 121 | quantificate(V,N,P1,P), 122 | quantificate(W,N1,P0,P1). 123 | quantificate(0,_,P,P) :- !. 124 | quantificate(V,N,P0,'$VAR'(Nr)^P) :- 125 | Vr is V /\ -(V), % rightmost bit 126 | log2(Vr,I), 127 | Nr is N+I, 128 | N1 is Nr+1, 129 | V1 is V >> (I+1), 130 | quantificate(V1,N1,P0,P). 131 | 132 | log2(1,0) :- !. 133 | log2(2,1) :- !. 134 | log2(4,2) :- !. 135 | log2(8,3) :- !. 136 | log2(N,I) :- N1 is N>>4, N1=\=0, log2(N1,I1), I is I1+4. 137 | 138 | schedule([P],Vg,Q) :- !, schedule1(P,Vg,Q). 139 | schedule([P1|P2],Vg,(Q1,Q2)) :- !, schedule1(P1,Vg,Q1), schedule(P2,Vg,Q2). 140 | 141 | schedule1(m(V,C,P),Vg,Q) :- 142 | maybe_cut(V,Vg,Q0,Q), 143 | plan(P,V,C,Vg,Q0). 144 | 145 | maybe_cut(V,Vg,P,{P}) :- disjoint(V,Vg), !. 146 | maybe_cut(V,Vg,P,P). 147 | 148 | plan(\+P,Vg,_,_,\+Q) :- !, Vg = 0, 149 | marked(P,V,C,P1), 150 | plan(P1,V,C,Vg,Q1), 151 | quantificate(V,0,Q1,Q). 152 | plan(SQ,Vg,_,_,SQ1) :- subquery(SQ,SQ1,X,P,_,Q), !, 153 | marked(P,V,C,P1), 154 | variables(X,Vg,Vgx), 155 | setminus(V,Vgx,Vl), 156 | quantificate(Vl,0,Q1,Q), 157 | plan(P1,V,C,Vgx,Q1). 158 | plan(P,V,C,Vg,(Q,R)) :- is_conjunction(P), !, 159 | best_goal(P,V,C,P0,V0,PP), 160 | plan(P0,V0,C,Vg,Q), 161 | instantiate(PP,V0,L), 162 | add_keys(L,L1), 163 | keysort(L1,L2), 164 | strip_keys(L2,L3), 165 | schedule(L3,Vg,R). 166 | plan(P,_,_,_,P). 167 | 168 | is_conjunction((_,_)). 169 | 170 | marked(m(V,C,P),V,C,P). 171 | 172 | freevars(m(V,_,_),V). 173 | 174 | best_goal((P1,P2),V,C,P0,V0,m(V,C,Q)) :- !, 175 | ( marked(P1,Va,C,Pa), Q=(Pb,P2) ; marked(P2,Va,C,Pa), Q=(P1,Pb) ), !, 176 | best_goal(Pa,Va,C,P0,V0,Pb). 177 | best_goal(P,V,C,P,V,true). 178 | 179 | instantiate(true,_,[]) :- !. 180 | instantiate(P,Vi,[P]) :- freevars(P,V), disjoint(V,Vi), !. 181 | instantiate(m(V,_,P),Vi,L) :- instantiate0(P,V,Vi,L). 182 | 183 | instantiate0((P1,P2),_,Vi,L) :- 184 | instantiate(P1,Vi,L1), 185 | instantiate(P2,Vi,L2), 186 | recombine(L1,L2,L). 187 | instantiate0(\+P,V,Vi,L) :- !, 188 | instantiate(P,Vi,L0), 189 | freevars(P,Vf), setminus(Vf,V,Vl), 190 | negate(L0,Vl,L). 191 | instantiate0(SQ,Vg,Vi,[m(V,C,SQ1)]) :- subquery(SQ,SQ1,X,P,_,Q), !, 192 | instantiate(P,Vi,L), 193 | L=[Q], % Too bad about the general case! 194 | marked(Q,Vq,C0,_), 195 | setminus(Vg,Vi,V), 196 | variables(X,0,Vx), 197 | setminus(V,Vx,V0), 198 | setofcost(V0,C0,C). 199 | instantiate0(P,V,Vi,[m(V1,C,P)]) :- 200 | setminus(V,Vi,V1), 201 | cost(P,V1,C). 202 | 203 | recombine(L,[],L) :- !. 204 | recombine([],L,L). 205 | recombine([P1|L1],[P2|L2],L) :- 206 | marked(P1,V1,C1,_), nonempty(V1), 207 | incorporate(P1,V1,C1,P2,L2,L3), !, 208 | recombine(L1,L3,L). 209 | recombine([P|L1],L2,[P|L]) :- recombine(L1,L2,L). 210 | 211 | incorporate(P0,V0,C0,P1,L1,L) :- 212 | marked(P1,V1,C1,_), 213 | intersect(V0,V1), !, 214 | setplus(V0,V1,V), 215 | minimum(C0,C1,C), 216 | incorporate0(m(V,C,(P0,P1)),V,C,L1,L). 217 | incorporate(P0,V0,C0,P1,[P2,L1],[P1|L]) :- incorporate(P0,V0,C0,G2,L1,L). 218 | 219 | incorporate0(P0,V0,C0,[P1|L1],L) :- incorporate(P0,V0,C0,P1,L1,L), !. 220 | incorporate0(P,_,_,L,[P|L]). 221 | 222 | minimum(N1,N2,N1) :- N1 =< N2, !. 223 | minimum(N1,N2,N2). 224 | 225 | add_keys([],[]). 226 | add_keys([P|L],[C-P|L1]) :- marked(P,_,C,_), add_keys(L,L1). 227 | 228 | strip_keys([],[]). 229 | strip_keys([X|L],[P|L1]) :- strip_key(X,P), strip_keys(L,L1). 230 | 231 | strip_key(C-P,P). 232 | 233 | variablise('$VAR'(N),VV,V) :- !, N1 is N+1, arg(N1,VV,V). 234 | variablise(T,_,T) :- atomic(T), !. 235 | variablise(T,VV,T1) :- 236 | functor(T,F,N), 237 | functor(T1,F,N), 238 | variablise(N,T,VV,T1). 239 | 240 | variablise(0,_,_,_) :- !. 241 | variablise(N,T,VV,T1) :- N1 is N-1, 242 | arg(N,T,X), 243 | arg(N,T1,X1), 244 | variablise(X,VV,X1), 245 | variablise(N1,T,VV,T1). 246 | 247 | cost(+P,0,N) :- !, cost(P,0,N). 248 | cost(+P,V,1000) :- !. 249 | cost(P,V,N) :- functor(P,F,I), cost(I,F,P,V,N). 250 | 251 | cost(1,F,P,V,N) :- 252 | arg(1,P,X1), instantiated(X1,V,I1), 253 | nd(F,N0,N1), 254 | N is N0-I1*N1. 255 | cost(2,F,P,V,N) :- 256 | arg(1,P,X1), instantiated(X1,V,I1), 257 | arg(2,P,X2), instantiated(X2,V,I2), 258 | nd(F,N0,N1,N2), 259 | N is N0-I1*N1-I2*N2. 260 | cost(3,F,P,V,N) :- 261 | arg(1,P,X1), instantiated(X1,V,I1), 262 | arg(2,P,X2), instantiated(X2,V,I2), 263 | arg(3,P,X3), instantiated(X3,V,I3), 264 | nd(F,N0,N1,N2,N3), 265 | N is N0-I1*N1-I2*N2-I3*N3. 266 | 267 | instantiated([X|_],V,N) :- !, instantiated(X,V,N). 268 | instantiated('$VAR'(N),V,0) :- setcontains(V,N), !. 269 | instantiated(_,_,1). 270 | 271 | /*-------------------------Put in reserve-------------------- 272 | 273 | sort_parts([],[]) :- !. 274 | sort_parts([X],[X]) :- !. 275 | sort_parts(L,R) :- 276 | divide(L,L1,L2), 277 | sort_parts(L1,R1), 278 | sort_parts(L2,R2), 279 | merge(R1,R2,R). 280 | 281 | divide([X1|L0],[X1|L1],[X2|L2]) :- list(L0,X2,L), !, divide(L,L1,L2). 282 | divide(L,L,[]). 283 | 284 | list([X|L],X,L). 285 | 286 | merge([],R,R) :- !. 287 | merge([X|R1],R2,[X|R]) :- precedes(X,R2), !, merge(R1,R2,R). 288 | merge(R1,[X|R2],[X|R]) :- !, merge(R1,R2,R). 289 | merge(R,[],R). 290 | 291 | precedes(G1,[G2|_]) :- goal_info(G1,_,N1), goal_info(G2,_,N2), N1 =< N2. 292 | 293 | -------------------------------------------------------------*/ 294 | 295 | :-mode 296 | nonempty(+), 297 | setplus(+,+,-), 298 | setminus(+,+,-), 299 | mkset(+,+,-), 300 | setplusitem(+,+,-), 301 | setcontains(+,+), 302 | intersect(+,+), 303 | disjoint(+,+). 304 | 305 | nonempty(0) :- !, fail. 306 | nonempty(_). 307 | 308 | setplus(W1-V1,W2-V2,W-V) :- !, V is V1 \/ V2, setplus(W1,W2,W). 309 | setplus(W-V1,V2,W-V) :- !, V is V1 \/ V2. 310 | setplus(V1,W-V2,W-V) :- !, V is V1 \/ V2. 311 | setplus(V1,V2,V) :- V is V1 \/ V2. 312 | 313 | setminus(W1-V1,W2-V2,S) :- !, V is V1 /\ \(V2), 314 | setminus(W1,W2,W), mkset(W,V,S). 315 | setminus(W-V1,V2,W-V) :- !, V is V1 /\ \(V2). 316 | setminus(V1,W-V2,V) :- !, V is V1 /\ \(V2). 317 | setminus(V1,V2,V) :- V is V1 /\ \(V2). 318 | 319 | mkset(0,V,V) :- !. 320 | mkset(W,V,W-V). 321 | 322 | setplusitem(W-V,N,W-V1) :- N < 18, !, V1 is V \/ 1< word(V),!,blanks,words(U). 50 | words([]) --> []. 51 | 52 | word(U1) --> [K],{lc(K,K1)},!,alphanums(U2),{name(U1,[K1|U2])}. 53 | word(nb(N)) --> [K],{digit(K)},!,digits(U),{name(N,[K|U])}. 54 | word(V) --> [K],{name(V,[K])}. 55 | 56 | alphanums([K1|U]) --> [K],{alphanum(K,K1)},!,alphanums(U). 57 | alphanums([]) --> []. 58 | 59 | alphanum(95,95) :- !. 60 | alphanum(K,K1):-lc(K,K1). 61 | alphanum(K,K):-digit(K). 62 | 63 | digits([K|U]) --> [K],{digit(K)},!,digits(U). 64 | digits([]) --> []. 65 | 66 | blanks--> [K],{K=<32},!,blanks. 67 | blanks --> []. 68 | 69 | digit(K):-K>47,K<58. 70 | 71 | lc(K,K1):-K>64,K<91,!,K1 is K\/8'40. 72 | lc(K,K):-K>96,K<123. 73 | 74 | to_nl :- 75 | repeat, 76 | get0(10), !. 77 | 78 | -------------------------------------------------------------------------------- /prolog/chat80/rivers.pl: -------------------------------------------------------------------------------- 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 | % Facts about rivers. 24 | % ------------------ 25 | 26 | river(amazon,[atlantic,brazil,peru]). 27 | river(amu_darya,[aral_sea,soviet_union,afghanistan]). 28 | river(amur,[pacific,soviet_union,china,mongolia]). 29 | river(brahmaputra,[indian_ocean,bangladesh,china]). 30 | river(colorado,[pacific,mexico,united_states]). 31 | river(congo_river,[atlantic,zaire,zambia]). 32 | river(cubango,[botswana,south_africa,angola]). 33 | river(danube,[black_sea,romania,yugoslavia,hungary,czechoslovakia,austria, 34 | west_germany]). 35 | river(don,[black_sea,soviet_union]). 36 | river(elbe,[atlantic,west_germany,east_germany,czechoslovakia]). 37 | river(euphrates,[persian_gulf,iraq,syria,turkey]). 38 | river(ganges,[indian_ocean,india,china]). 39 | river(hwang_ho,[pacific,china]). 40 | river(indus,[indian_ocean,pakistan,india,china]). 41 | river(irrawaddy,[indian_ocean,burma]). 42 | river(lena,[arctic_ocean,soviet_union]). 43 | river(limpopo,[indian_ocean,mozambique,south_africa]). 44 | river(mackenzie,[arctic_ocean,canada]). 45 | river(mekong,[pacific,vietnam,cambodia,laos,china]). 46 | river(mississippi,[atlantic,united_states]). 47 | river(murray,[indian_ocean,australia]). 48 | river(niger_river,[atlantic,nigeria,niger,mali,guinea]). 49 | river(nile,[mediterranean,egypt,sudan,uganda]). 50 | river(ob,[arctic_ocean,soviet_union]). 51 | river(oder,[baltic,poland,czechoslovakia]). 52 | river(orange,[atlantic,south_africa,lesotho]). 53 | river(orinoco,[atlantic,venezuela,colombia]). 54 | river(parana,[atlantic,argentina,paraguay,brazil]). 55 | river(rhine,[atlantic,netherlands,west_germany,switzerland]). 56 | river(rhone,[mediterranean,france,switzerland]). 57 | river(rio_grande,[atlantic,mexico,united_states]). 58 | river(salween,[indian_ocean,burma,china]). 59 | river(senegal_river,[atlantic,senegal,mali,guinea]). 60 | river(tagus,[atlantic,portugal,spain]). 61 | river(vistula,[baltic,poland]). 62 | river(volga,[black_sea,soviet_union]). 63 | river(volta,[atlantic,ghana,upper_volta]). 64 | river(yangtze,[pacific,china]). 65 | river(yenisei,[arctic_ocean,soviet_union,mongolia]). 66 | river(yukon,[pacific,united_states,canada]). 67 | river(zambesi,[indian_ocean,mozambique,zambia,angola]). 68 | 69 | -------------------------------------------------------------------------------- /prolog/chat80/scopes.pl: -------------------------------------------------------------------------------- 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 | clausify(question(V0,P),(answer(V):-B)) :- 24 | quantify(P,Quants,[],R0), 25 | split_quants(question(V0),Quants,HQuants,[],BQuants,[]), 26 | chain_apply(BQuants,R0,R1), 27 | head_vars(HQuants,B,R1,V,V0). 28 | 29 | quantify(quant(Det,X,Head,Pred,Args,Y),Above,Right,true) :- 30 | close_tree(Pred,P2), 31 | quantify_args(Args,AQuants,P1), 32 | split_quants(Det,AQuants,Above,[Q|Right],Below,[]), 33 | pre_apply(Head,Det,X,P1,P2,Y,Below,Q). 34 | quantify(conj(Conj,LPred,LArgs,RPred,RArgs),Up,Up,P) :- 35 | close_tree(LPred,LP0), 36 | quantify_args(LArgs,LQs,LP1), 37 | chain_apply(LQs,(LP0,LP1),LP), 38 | close_tree(RPred,RP0), 39 | quantify_args(RArgs,RQs,RP1), 40 | chain_apply(RQs,(RP0,RP1),RP), 41 | conj_apply(Conj,LP,RP,P). 42 | quantify(pred(Subj,Op,Head,Args),Above,Right,P) :- 43 | quantify(Subj,SQuants,[],P0), 44 | quantify_args(Args,AQuants,P1), 45 | split_quants(Op,AQuants,Up,Right,Here,[]), 46 | conc(SQuants,Up,Above), 47 | chain_apply(Here,(P0,Head,P1),P2), 48 | op_apply(Op,P2,P). 49 | quantify(~P,Q,Q,P). 50 | quantify(P&Q,Above,Right,(S,T)) :- 51 | quantify(Q,Right0,Right,T), 52 | quantify(P,Above,Right0,S). 53 | 54 | head_vars([],P,P,L,L0) :- 55 | strip_types(L0,L). 56 | head_vars([Quant|Quants],(P,R0),R,[X|V],V0) :- 57 | extract_var(Quant,P,X), 58 | head_vars(Quants,R0,R,V,V0). 59 | 60 | strip_types([],[]). 61 | strip_types([_-X|L0],[X|L]) :- 62 | strip_types(L0,L). 63 | 64 | extract_var(quant(_,_-X,P,_-X),P,X). 65 | 66 | chain_apply(Q0,P0,P) :- 67 | sort_quants(Q0,Q,[]), 68 | chain_apply0(Q,P0,P). 69 | 70 | chain_apply0([],P,P). 71 | chain_apply0([Q|Quants],P0,P) :- 72 | chain_apply0(Quants,P0,P1), 73 | det_apply(Q,P1,P). 74 | 75 | quantify_args([],[],true). 76 | quantify_args([Arg|Args],Quants,(P,Q)) :- 77 | quantify_args(Args,Quants0,Q), 78 | quantify(Arg,Quants,Quants0,P). 79 | 80 | pre_apply(~Head,set(I),X,P1,P2,Y,Quants,Quant) :- 81 | indices(Quants,I,Indices,RestQ), 82 | chain_apply(RestQ,(Head,P1),P), 83 | setify(Indices,X,(P,P2),Y,Quant). 84 | pre_apply(~Head,Det,X,P1,P2,Y,Quants,quant(Det,X,(P,P2),Y)) :- 85 | ( unit_det(Det); 86 | index_det(Det,_)), 87 | chain_apply(Quants,(Head,P1),P). 88 | pre_apply(apply(F,P0),Det,X,P1,P2,Y, 89 | Quants0,quant(Det,X,(P3,P2),Y)) :- 90 | but_last(Quants0,quant(lambda,Z,P0,Z),Quants), 91 | chain_apply(Quants,(F,P1),P3). 92 | pre_apply(aggr(F,Value,L,Head,Pred),Det,X,P1,P2,Y,Quants, 93 | quant(Det,X, 94 | (S^(setof(Range:Domain,P,S), 95 | aggregate(F,S,Value)),P2),Y)) :- 96 | close_tree(Pred,R), 97 | complete_aggr(L,Head,(R,P1),Quants,P,Range,Domain). 98 | 99 | but_last([X|L0],Y,L) :- 100 | but_last0(L0,X,Y,L). 101 | 102 | but_last0([],X,X,[]). 103 | but_last0([X|L0],Y,Z,[Y|L]) :- 104 | but_last0(L0,X,Z,L). 105 | 106 | close_tree(T,P) :- 107 | quantify(T,Q,[],P0), 108 | chain_apply(Q,P0,P). 109 | 110 | meta_apply(~G,R,Q,G,R,Q). 111 | meta_apply(apply(F,(R,P)),R,Q0,F,true,Q) :- 112 | but_last(Q0,quant(lambda,Z,P,Z),Q). 113 | 114 | indices([],_,[],[]). 115 | indices([Q|Quants],I,[Q|Indices],Rest) :- 116 | open_quant(Q,Det,_,_,_), 117 | index_det(Det,I), 118 | indices(Quants,I,Indices,Rest). 119 | indices([Q|Quants],I,Indices,[Q|Rest]) :- 120 | open_quant(Q,Det,_,_,_), 121 | unit_det(Det), 122 | indices(Quants,I,Indices,Rest). 123 | 124 | setify([],Type-X,P,Y,quant(set,Type-([]:X),true:P,Y)). 125 | setify([Index|Indices],X,P,Y,Quant) :- 126 | pipe(Index,Indices,X,P,Y,Quant). 127 | 128 | pipe(quant(int_det(_,Z),Z,P1,Z), 129 | Indices,X,P0,Y,quant(det(a),X,P,Y)) :- 130 | chain_apply(Indices,(P0,P1),P). 131 | pipe(quant(index(_),_-Z,P0,_-Z),Indices,Type-X,P,Y, 132 | quant(set,Type-([Z|IndexV]:X),(P0,P1):P,Y)) :- 133 | index_vars(Indices,IndexV,P1). 134 | 135 | index_vars([],[],true). 136 | index_vars([quant(index(_),_-X,P0,_-X)|Indices], 137 | [X|IndexV],(P0,P)) :- 138 | index_vars(Indices,IndexV,P). 139 | 140 | complete_aggr([Att,Obj],~G,R,Quants,(P,R),Att,Obj) :- 141 | chain_apply(Quants,G,P). 142 | complete_aggr([Att],Head,R0,Quants0,(P1,P2,R),Att,Obj) :- 143 | meta_apply(Head,R0,Quants0,G,R,Quants), 144 | set_vars(Quants,Obj,Rest,P2), 145 | chain_apply(Rest,G,P1). 146 | complete_aggr([],~G,R,[quant(set,_-(Obj:Att),S:T,_)], 147 | (G,R,S,T),Att,Obj). 148 | 149 | set_vars([quant(set,_-(I:X),P:Q,_-X)],[X|I],[],(P,Q)). 150 | set_vars([],[],[],true). 151 | set_vars([Q|Qs],[I|Is],R,(P,Ps)) :- 152 | open_quant(Q,Det,X,P,Y), 153 | set_var(Det,X,Y,I), !, 154 | set_vars(Qs,Is,R,Ps). 155 | set_vars([Q|Qs],I,[Q|R],P) :- 156 | set_vars(Qs,I,R,P). 157 | 158 | set_var(Det,_-X,_-X,X) :- 159 | setifiable(Det). 160 | 161 | sort_quants([],L,L). 162 | sort_quants([Q|Qs],S,S0) :- 163 | open_quant(Q,Det,_,_,_), 164 | split_quants(Det,Qs,A,[],B,[]), 165 | sort_quants(A,S,[Q|S1]), 166 | sort_quants(B,S1,S0). 167 | 168 | split_quants(_,[],A,A,B,B). 169 | split_quants(Det0,[Quant|Quants],Above,Above0,Below,Below0) :- 170 | compare_dets(Det0,Quant,Above,Above1,Below,Below1), 171 | split_quants(Det0,Quants,Above1,Above0,Below1,Below0). 172 | 173 | compare_dets(Det0,Q,[quant(Det,X,P,Y)|Above],Above,Below,Below) :- 174 | open_quant(Q,Det1,X,P,Y), 175 | governs(Det1,Det0), !, 176 | bubble(Det0,Det1,Det). 177 | compare_dets(Det0,Q0,Above,Above,[Q|Below],Below) :- 178 | lower(Det0,Q0,Q). 179 | 180 | open_quant(quant(Det,X,P,Y),Det,X,P,Y). 181 | 182 | % ================================================================= 183 | % Determiner Properties 184 | 185 | index_det(index(I),I). 186 | index_det(int_det(I,_),I). 187 | 188 | unit_det(set). 189 | unit_det(lambda). 190 | unit_det(quant(_,_)). 191 | unit_det(det(_)). 192 | unit_det(question(_)). 193 | unit_det(id). 194 | unit_det(void). 195 | unit_det(not). 196 | unit_det(generic). 197 | unit_det(int_det(_)). 198 | unit_det(proportion(_)). 199 | 200 | det_apply(quant(Det,Type-X,P,_-Y),Q0,Q) :- 201 | apply(Det,Type,X,P,Y,Q0,Q). 202 | 203 | apply(generic,_,X,P,X,Q,X^(P,Q)). 204 | apply(proportion(Type-V),_,X,P,Y,Q, 205 | S^(setof(X,P,S), 206 | N^(numberof(Y,(one_of(S,Y),Q),N), 207 | M^(card(S,M),ratio(N,M,V))))). 208 | apply(id,_,X,P,X,Q,(P,Q)). 209 | apply(void,_,X,P,X,Q,X^(P,Q)). 210 | apply(set,_,Index:X,P0,S,Q,S^(P,Q)) :- 211 | apply_set(Index,X,P0,S,P). 212 | apply(int_det(Type-X),Type,X,P,X,Q,(P,Q)). 213 | apply(index(_),_,X,P,X,Q,X^(P,Q)). 214 | apply(quant(Op,N),Type,X,P,X,Q,R) :- 215 | value(N,Type,Y), 216 | quant_op(Op,Z,Y,numberof(X,(P,Q),Z),R). 217 | apply(det(Det),_,X,P,Y,Q,R) :- 218 | apply0(Det,X,P,Y,Q,R). 219 | 220 | apply0(Some,X,P,X,Q,X^(P,Q)) :- 221 | some(Some). 222 | apply0(All,X,P,X,Q,\+X^(P,\+Q)) :- 223 | all(All). 224 | apply0(no,X,P,X,Q,\+X^(P,Q)). 225 | apply0(notall,X,P,X,Q,X^(P,\+Q)). 226 | 227 | quant_op(same,X,X,P,P). 228 | quant_op(Op,X,Y,P,X^(P,F)) :- 229 | quant_op(Op,X,Y,F). 230 | 231 | quant_op(not+more,X,Y,X==Y). 233 | quant_op(less,X,Y,XY). 235 | 236 | value(wh(Type-X),Type,X). 237 | value(nb(X),_,X). 238 | 239 | all(all). 240 | all(every). 241 | all(each). 242 | all(any). 243 | 244 | some(a). 245 | some(the(sin)). 246 | some(some). 247 | 248 | apply_set([],X,true:P,S,setof(X,P,S)). 249 | apply_set([I|Is],X,Range:P,S, 250 | setof([I|Is]:V,(Range,setof(X,P,V)),S)). 251 | 252 | 253 | governs(Det,set(J)) :- 254 | index_det(Det,I), 255 | I \== J. 256 | governs(Det0,Det) :- 257 | index_det(Det0,_), 258 | ( index_det(Det,_); 259 | Det=det(_); 260 | Det=quant(_,_)). 261 | governs(_,void). 262 | governs(_,lambda). 263 | governs(_,id). 264 | governs(det(each),question([_|_])). 265 | governs(det(each),det(each)). 266 | governs(det(any),not). 267 | governs(quant(same,wh(_)),Det) :- 268 | weak(Det). 269 | 270 | governs(det(Strong),Det) :- 271 | strong0(Strong), 272 | weak(Det). 273 | 274 | strong(det(Det)) :- 275 | strong0(Det). 276 | 277 | strong0(each). 278 | strong0(any). 279 | 280 | weak(det(Det)) :- 281 | weak0(Det). 282 | weak(quant(_,_)). 283 | weak(index(_)). 284 | weak(int_det(_,_)). 285 | weak(set(_)). 286 | weak(int_det(_)). 287 | weak(generic). 288 | weak(proportion(_)). 289 | 290 | weak0(no). 291 | weak0(a). 292 | weak0(all). 293 | weak0(some). 294 | weak0(every). 295 | weak0(the(sin)). 296 | weak0(notall). 297 | 298 | lower(question(_),Q,quant(det(a),X,P,Y)) :- 299 | open_quant(Q,det(any),X,P,Y), !. 300 | lower(_,Q,Q). 301 | 302 | setifiable(generic). 303 | setifiable(det(a)). 304 | setifiable(det(all)). 305 | 306 | % ================================================================= 307 | % Operators (currently, identity, negation and 'and') 308 | 309 | op_apply(id,P,P). 310 | op_apply(not,P,\+P). 311 | 312 | bubble(not,det(any),det(every)) :- !. 313 | bubble(_,D,D). 314 | 315 | 316 | conj_apply(and,P,Q,(P,Q)). 317 | 318 | -------------------------------------------------------------------------------- /prolog/chat80/slots.pl: -------------------------------------------------------------------------------- 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 | i_sentence(q(S),question([],P)) :- 24 | i_s(S,P,[],0). 25 | i_sentence(whq(X,S),question([X],P)) :- 26 | i_s(S,P,[],0). 27 | i_sentence(imp(s(_,Verb,VArgs,VMods)),imp(V,Args)) :- 28 | i_verb(Verb,V,_,active,pos,Slots0,[],transparent), 29 | i_verb_args(VArgs,[],[],Slots0,Slots,Args,Args0,Up,-0), 30 | conc(Up,VMods,Mods), 31 | i_verb_mods(Mods,_,[],Slots,Args0,Up,+0). 32 | 33 | i_np(there,Y,quant(void,_X,~true,~true,[],Y),[],_,_,XA,XA). 34 | i_np(NP,Y,Q,Up,Id0,Index,XA0,XA) :- 35 | i_np_head(NP,Y,Q,Det,Det0,X,Pred,QMods,Slots0,Id0), 36 | held_arg(XA0,XA,Slots0,Slots,Id0,Id), 37 | i_np_rest(NP,Det,Det0,X,Pred,QMods,Slots,Up,Id,Index). 38 | 39 | i_np_head(np(_,Kernel,_),Y, 40 | quant(Det,T,Head,Pred0,QMods,Y), 41 | Det,Det0,X,Pred,QMods,Slots,_Id) :- 42 | i_np_head0(Kernel,X,T,Det0,Head,Pred0,Pred,Slots), 43 | Type-_=Y, Type-_=T. 44 | 45 | i_np_rest(np(_,_,Mods),Det,Det0,X,Pred,QMods,Slots,Up,Id,Index) :- 46 | index_args(Det0,Index,Id,Det,IndexA), 47 | i_np_mods(Mods,X,Slots,Pred,QMods,Up,Id,IndexA). 48 | 49 | held_arg(held_arg(Case,-Id,X),[],S0,S,Id,+Id) :- 50 | in_slot(S0,Case,X,Id,S,_). 51 | held_arg(XA,XA,S,S,Id,Id). 52 | 53 | i_np_head0(np_head(Det,Adjs,Noun),X,T,Det,Head0,Pred0,Pred,Slots) :- 54 | i_adjs(Adjs,X,T,X,Head0,Head,Pred0,Pred), 55 | i_noun(Noun,X,Head,Slots). 56 | i_np_head0(np_head(int_det(V),Adjs,Noun), 57 | Type-X,Type-X,Det,~true,Pred,Pred, 58 | [slot(prep(of),Type,X,_,comparator)]) :- 59 | comparator(Noun,Type,V,Adjs,Det). 60 | i_np_head0(np_head(quant(Op0,N),Adjs,Noun), 61 | Type-X,Type-X,void,~P,Pred,Pred,[]) :- 62 | measure(Noun,Type,Adjs,Units), 63 | conversion(N,Op0,Type,V,Op), 64 | measure_op(Op,X,V--Units,P). 65 | i_np_head0(name(Name), 66 | Type-Name,Type-Name,id,~true,Pred,Pred,[]) :- 67 | name_template(Name,Type). 68 | i_np_head0(wh(X),X,X,id,~true,Pred,Pred,[]). 69 | 70 | i_np_mods(Mods,_,[],~true,[],Mods,_,_). 71 | i_np_mods([Mod|Mods],X,Slots0,Pred0,QMods0,Up,Id,Index) :- 72 | i_np_mod(Mod,X,Slots0,Slots, 73 | Pred0,Pred,QMods0,QMods,Up0,-Id,Index), 74 | conc(Up0,Mods,Mods0), 75 | i_np_mods(Mods0,X,Slots,Pred,QMods,Up,+Id,Index). 76 | i_np_mods(Mods,_,[Slot|Slots],~true,QMods,Mods,Id,_) :- 77 | i_voids([Slot|Slots],QMods,Id). 78 | 79 | i_voids([],[],_). 80 | i_voids([Slot|Slots],[quant(void,X,~true,~true,[],_)|QMods],Id) :- 81 | nominal_slot(Slot,X,-Id), !, 82 | i_voids(Slots,QMods,+Id). 83 | i_voids([_|Slots],QMods,Id) :- 84 | i_voids(Slots,QMods,Id). 85 | 86 | i_rel(rel(X,S),X,P&Pred,Pred,QMods,QMods,Up,Id) :- 87 | i_s(S,P,Up,Id). 88 | i_rel(reduced_rel(X,S),X,Pred,Pred,[A|QMods],QMods,Up,Id) :- 89 | i_s(S,A,Up,Id). 90 | i_rel(conj(Conj,Left,Right),X, 91 | conj(Conj,LPred,LQMods,RPred,RQMods)&Pred,Pred, 92 | QMods,QMods,Up,Id) :- 93 | i_rel(Left,X,LPred,~true,LQMods,[],[],-Id), 94 | i_rel(Right,X,RPred,~true,RQMods,[],Up,+Id). 95 | 96 | i_np_mod(pp(Prep,NP), 97 | X,Slots0,Slots,Pred,Pred,[QMod|QMods],QMods,Up,Id0,Index0) :- 98 | i_np_head(NP,Y,Q,LDet,LDet0,LX,LPred,LQMods,LSlots0,Id0), 99 | i_bind(Prep,Slots0,Slots1,X,Y,Id0,Function,P,PSlots,XArg), 100 | conc(PSlots,Slots1,Slots), 101 | i_np_modify(Function,P,Q,QMod,Index0,Index), 102 | held_arg(XArg,[],LSlots0,LSlots,Id0,Id), 103 | i_np_rest(NP,LDet,LDet0,LX,LPred,LQMods,LSlots,Up,Id,Index). 104 | i_np_mod(Mod,X,Slots,Slots,Pred0,Pred,QMods0,QMods,Up,Id,_) :- 105 | i_rel(Mod,X,Pred0,Pred,QMods0,QMods,Up,Id). 106 | 107 | i_noun(Noun,Type-X,P,Slots) :- 108 | noun_template(Noun,Type,X,P,Slots). 109 | 110 | i_bind(Prep,Slots0,Slots,_,X,Id,arg,P,[],[]) :- 111 | in_slot(Slots0,Case,X,Id,Slots,P), 112 | deepen_case(Prep,Case). 113 | i_bind(prep(Prep),Slots,Slots,X,Y,_,adjoin,~P,PSlots,XArg) :- 114 | i_adjoin(Prep,X,Y,PSlots,XArg,P). 115 | 116 | i_np_modify(adjoin,P,N,N&P,_,unit). 117 | i_np_modify(arg,F,N,N,Index0,Index) :- 118 | index_slot(F,Index0,Index). 119 | 120 | in_slot([Slot|Slots],Case,X,Id,Slots,F) :- 121 | slot_match(Slot,Case,X,Id,F). 122 | in_slot([Slot|Slots0],Case,X,Id,[Slot|Slots],F) :- 123 | in_slot(Slots0,Case,X,Id,Slots,F). 124 | 125 | slot_match(slot(Case,Type,X,Id,F),Case,Type-X,Id,F). 126 | 127 | i_adjs([],_X,T,T,Head,Head,Pred,Pred). 128 | i_adjs([Adj|Adjs],X,T,T0,Head0,Head,Pred0,Pred) :- 129 | i_adj(Adj,X,T,T1,Head0,Head1,Pred0,Pred1), 130 | i_adjs(Adjs,X,T1,T0,Head1,Head,Pred1,Pred). 131 | 132 | i_adj(adj(Adj),Type-X,T,T,Head,Head,~P&Pred,Pred) :- 133 | restriction(Adj,Type,X,P). 134 | i_adj(adj(Adj),TypeX-X,TypeV-V,_, 135 | aggr(F,V,[X],Head,Pred),Head,~true,Pred) :- 136 | aggr_adj(Adj,TypeV,TypeX,F). 137 | i_adj(sup(Op0,adj(Adj)),Type-X,Type-V,_, 138 | aggr(F,V,[Y,X],Head,~P&Pred),Head,~true,Pred) :- 139 | chat_sign(Adj,Sign), 140 | inverse(Op0,Sign,Op), 141 | i_sup_op(Op,F), 142 | attribute(Adj,Type,X,_,Y,P). 143 | %JW: Not called and standard/4 is undefined 144 | %i_adj(adj(Adj),TypeX-X,T,T,_, 145 | % Head,Head,quant(void,TypeX-Y,~P,~Q&Pred,[],_),Pred) :- 146 | % attribute(Adj,TypeX,X,_,Y,P), 147 | % standard(Adj,TypeX,Y,Q). 148 | 149 | i_s(s(Subj,Verb,VArgs,VMods),Pred,Up,Id) :- 150 | i_verb(Verb,P,Tense,Voice,Neg,Slots0,XA0,Meta), 151 | i_subj(Voice,Subj,Slots0,Slots1,QSubj,SUp,-(-Id)), 152 | conc(SUp,VArgs,TArgs), 153 | i_verb_args(TArgs,XA0,XA,Slots1,Slots,Args0,Args,Up0,+(-Id)), 154 | conc(Up0,VMods,Mods), 155 | i_verb_mods(Mods,Tense,XA,Slots,Args,Up,+Id), 156 | reshape_pred(Meta,QSubj,Neg,P,Args0,Pred). 157 | 158 | i_verb(verb(Root,Voice,Tense,_Aspect,Neg), 159 | P,Tense,Voice,Det,Slots,XArg,Meta) :- 160 | verb_template(Root,P,Slots,XArg,Meta), 161 | i_neg(Neg,Det). 162 | 163 | reshape_pred(transparent,S,N,P,A,pred(S,N,P,A)). 164 | reshape_pred(have,Subj,Neg,Verb0, 165 | [quant(Det,X,Head0,Pred,QArgs,Y)|MRest], 166 | pred(Subj,Neg,Verb,[quant(Det,X,Head,Pred,QArgs,Y)|MRest])) :- 167 | have_pred(Head0,Verb0,Head,Verb). 168 | 169 | have_pred(~Head,Verb,~true,(Head,Verb)). 170 | have_pred(Head,Verb,Head,Verb) :- 171 | meta_head(Head). 172 | 173 | meta_head(apply(_,_)). 174 | meta_head(aggr(_,_,_,_,_)). 175 | 176 | i_neg(pos,id). 177 | i_neg(neg,not). 178 | 179 | i_subj(Voice,Subj,Slots0,Slots,Quant,Up,Id) :- 180 | subj_case(Voice,Case), 181 | verb_slot(arg(Case,Subj),[],[],Slots0,Slots,[Quant],[],Up,Id). 182 | 183 | i_verb_args(VArgs,XA0,XA,Slots0,Slots,Args0,Args,Up,Id) :- 184 | fill_verb(VArgs,XA0,XA,Slots0,Slots,Args0,Args,Up,Id). 185 | 186 | subj_case(active,subj). 187 | subj_case(passive,s_subj). 188 | 189 | fill_verb([],XA,XA,Slots,Slots,Args,Args,[],_). 190 | fill_verb([Node|Nodes0],XA0,XA,Slots0,Slots,Args0,Args,Up,Id) :- 191 | verb_slot(Node,XA0,XA1,Slots0,Slots1,Args0,Args1,Up0,-Id), 192 | conc(Up0,Nodes0,Nodes), 193 | fill_verb(Nodes,XA1,XA,Slots1,Slots,Args1,Args,Up,+Id). 194 | 195 | verb_slot(pp(Prep,NP), 196 | XArg0,XArg,Slots0,Slots,[Q|Args],Args,Up,Id) :- 197 | i_np(NP,X,Q,Up,Id,unit,XArg0,XArg), 198 | in_slot(Slots0,Case,X,Id,Slots,_), 199 | deepen_case(Prep,Case). 200 | verb_slot(void,XA,XA,Slots,Slots,Args,Args,[],_) :- 201 | in_slot(Slots,pred,_,_,_,_). 202 | verb_slot(pp(prep(Prep),NP), 203 | TXArg,TXArg,Slots0,Slots,[Q& ~P|Args],Args,Up,Id0) :- 204 | in_slot(Slots0,pred,X,Id0,Slots1,_), 205 | i_adjoin(Prep,X,Y,PSlots,XArg,P), 206 | i_np_head(NP,Y,Q,LDet,LDet0,LX,LPred,LQMods,LSlots0,Id0), 207 | held_arg(XArg,[],LSlots0,LSlots,Id0,Id), 208 | i_np_rest(NP,LDet,LDet0,LX,LPred,LQMods,LSlots,Up,Id,free), 209 | conc(PSlots,Slots1,Slots). 210 | verb_slot(arg(SCase,NP), 211 | XArg0,XArg,Slots0,Slots,[Q|Args],Args,Up,Id) :- 212 | i_np(NP,X,Q,Up,Id,unit,XArg0,XArg), 213 | in_slot(Slots0,Case,X,Id,Slots,_), 214 | deepen_case(SCase,Case). 215 | %JW: Commented out as adv_template/4 is not defined 216 | %verb_slot(adverb(Adv),XA,XA,Slots0,Slots,[~P|Args],Args,[],Id) :- 217 | % adv_template(Adv,Case,X,P), 218 | % in_slot(Slots0,Case,X,Id,Slots,_). 219 | verb_slot(arg(pred,AP),XA,XA,Slots0,Slots,Args0,Args,Up,Id) :- 220 | in_slot(Slots0,pred,X,Id,Slots,_), 221 | i_pred(AP,X,Args0,Args,Up,Id). 222 | 223 | i_pred(conj(Conj,Left,Right),X, 224 | [conj(Conj,~true,LQMods,~true,RQMods)|QMods], 225 | QMods,Up,Id) :- 226 | i_pred(Left,X,LQMods,[],[],-Id), 227 | i_pred(Right,X,RQMods,[],Up,+Id). 228 | i_pred(AP,T,[~Head&Pred|As],As,[],_) :- 229 | i_adj(AP,T,_,_,Head,true,Pred,~true). 230 | i_pred(value(adj(Adj),wh(TypeY-Y)),Type-X,[~H|As],As,[],_) :- 231 | attribute(Adj,Type,X,TypeY,Y,H). 232 | i_pred(comp(Op0,adj(Adj),NP),X,[P1 & P2 & ~P3,Q|As],As,Up,Id) :- 233 | i_np(NP,Y,Q,Up,Id,unit,[],[]), 234 | chat_sign(Adj,Sign), 235 | i_measure(X,Adj,Type,U,P1), 236 | i_measure(Y,Adj,Type,V,P2), 237 | inverse(Op0,Sign,Op), 238 | measure_op(Op,U,V,P3). 239 | i_pred(pp(prep(Prep),NP),X,[~H,Q|As],As,Up,Id) :- 240 | i_np(NP,Y,Q,Up,Id,unit,[],[]), 241 | adjunction(Prep,X,Y,H). 242 | 243 | i_adjoin(with,TS-S,TV-Y,[slot(prep(of),TV,Z,_,free)], 244 | held_arg(poss,-_Id,TS-S), 245 | Y=Z). 246 | i_adjoin(Prep,X,Y,[],[],P) :- 247 | adjunction(Prep,X,Y,P). 248 | 249 | i_measure(Type-X,Adj,Type,X,~true) :- 250 | units(Adj,Type). 251 | i_measure(TypeX-X,Adj,TypeY,Y,quant(void,TypeY-Y,~P,~true,[],_)) :- 252 | attribute(Adj,TypeX,X,TypeY,Y,P). 253 | 254 | i_verb_mods(Mods,_,XA,Slots0,Args0,Up,Id) :- 255 | fill_verb(Mods,XA,[],Slots0,Slots,Args0,Args,Up,-Id), 256 | i_voids(Slots,Args,+Id). 257 | 258 | nominal_slot(slot(Kind,Type,X,Id,_),Type-X,Id) :- 259 | nominal_kind(Kind). 260 | 261 | nominal_kind(prep(_)). 262 | nominal_kind(poss). 263 | nominal_kind(subj). 264 | nominal_kind(dir). 265 | nominal_kind(ind). 266 | 267 | i_sup_op(least,min). 268 | i_sup_op(most,max). 269 | 270 | conversion(wh(Type-X),same,Type,X,id). 271 | conversion(nb(N),Op,_,N,Op). 272 | 273 | measure_op(id,X,X,true). 274 | measure_op(same,X,Y,X=Y). 275 | measure_op(less,X,Y,exceeds(Y,X)). 276 | measure_op(not+less,X,Y,\+exceeds(Y,X)). 277 | measure_op(more,X,Y,exceeds(X,Y)). 278 | measure_op(not+more,X,Y,\+exceeds(X,Y)). 279 | 280 | inverse(most,-,least). 281 | inverse(least,-,most). 282 | inverse(same,-,same). 283 | inverse(less,-,more). 284 | inverse(more,-,less). 285 | inverse(X,+,X). 286 | 287 | noun_template(Noun,TypeV,V,~P, 288 | [slot(poss,TypeO,O,Os,index)|Slots]) :- 289 | property(Noun,TypeV,V,TypeO,O,P,Slots,Os,_). 290 | noun_template(Noun,TypeV,V,aggr(F,V,[],~true,~true), 291 | [slot(prep(of),TypeS,_,_,free)]) :- 292 | aggr_noun(Noun,TypeV,TypeS,F). 293 | noun_template(Noun,Type,X,~P,Slots) :- 294 | thing(Noun,Type,X,P,Slots,_). 295 | noun_template(Noun,TypeV,V,apply(F,P), 296 | [slot(prep(of),TypeX,X,_,apply)]) :- 297 | meta_noun(Noun,TypeV,V,TypeX,X,P,F). 298 | 299 | verb_template(have,Y=Z, 300 | [slot(subj,TypeS,S,-Id,free), 301 | slot(dir,TypeV,Y,_,free), 302 | slot(prep(of),TypeV,Z,_,free)], 303 | held_arg(poss,-(-(+Id)),TypeS-S), have). 304 | verb_template(have,Y=Z, 305 | [slot(subj,TypeS,S,-(-(Id)),free), 306 | slot(dir,TypeV,Y,_,free), 307 | slot(prep(as),TypeV,Z,_,free)], 308 | held_arg(poss,-(-(-(+Id))),TypeS-S), have). 309 | verb_template(Verb,Pred, 310 | [slot(subj,TypeS,S,_,free)|Slots],[],transparent) :- 311 | verb_type(Verb,_+Kind), 312 | verb_kind(Kind,Verb,TypeS,S,Pred,Slots). 313 | 314 | verb_kind(be,_,TypeS,S,S=A,[slot(dir,TypeS,A,_,free)]). 315 | verb_kind(be,_,TypeS,S,true,[slot(pred,TypeS,S,_,free)]). 316 | verb_kind(intrans,Verb,TypeS,S,Pred,Slots) :- 317 | intrans(Verb,TypeS,S,Pred,Slots,_). 318 | verb_kind(trans,Verb,TypeS,S,Pred, 319 | [slot(dir,TypeD,D,SlotD,free)|Slots]) :- 320 | trans(Verb,TypeS,S,TypeD,D,Pred,Slots,SlotD,_). 321 | % JW: commented out as ditrans/12 is not defined 322 | %verb_kind(ditrans,Verb,TypeS,S,Pred, 323 | % [slot(dir,TypeD,D,SlotD,free), 324 | % slot(ind,TypeI,I,SlotI,free)|Slots]) :- 325 | % ditrans(Verb,TypeS,S,TypeD,D,TypeI,I,Pred,Slots,SlotD,SlotI,_). 326 | 327 | deepen_case(prep(at),time). 328 | deepen_case(s_subj,dir). 329 | deepen_case(s_subj,ind). 330 | deepen_case(prep(by),subj). 331 | deepen_case(prep(to),ind). 332 | deepen_case(prep(of),poss). 333 | deepen_case(X,X). 334 | 335 | % ================================================================ 336 | % Determiner Indexing Table 337 | 338 | index_slot(index,I,I). 339 | index_slot(free,_,unit). 340 | index_slot(apply,_,apply). 341 | index_slot(comparator,_,comparator). 342 | 343 | index_args(det(the(plu)),unit,I,set(I),index(I)) :- !. 344 | index_args(int_det(X),index(I),_,int_det(I,X),unit) :- !. 345 | index_args(generic,apply,_,lambda,unit) :-!. 346 | index_args(D,comparator,_,id,unit) :- 347 | ( indexable(D); D=generic), !. 348 | index_args(D,unit,_,D,unit) :- !. 349 | index_args(det(D),I,_,I,I) :- 350 | indexable(D), 351 | my_index(I), !. 352 | index_args(D,I,_,D,I). 353 | 354 | indexable(the(plu)). 355 | indexable(all). 356 | 357 | my_index(index(_I)). 358 | 359 | % ================================================================ 360 | % Utilities 361 | 362 | conc([],L,L). 363 | conc([X|L1],L2,[X|L3]) :- 364 | conc(L1,L2,L3). 365 | -------------------------------------------------------------------------------- /prolog/chat80/talkr.pl: -------------------------------------------------------------------------------- 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 | /* Simplifying and executing the logical form of a NL query. */ 24 | 25 | :-public write_tree/1, answer/1. 26 | 27 | :-mode write_tree(+). 28 | :-mode wt(+,+). 29 | :-mode header(+). 30 | :-mode decomp(+,-,-). 31 | :-mode complex(+). 32 | :-mode othervars(+,-,-). 33 | 34 | write_tree(T):- 35 | numbervars(T,0,_), 36 | wt(T,0), 37 | fail. 38 | write_tree(_). 39 | 40 | wt((P:-Q),L) :- !, L1 is L+3, 41 | write(P), tab(1), write((:-)), nl, 42 | tab(L1), wt(Q,L1). 43 | wt((P,Q),L) :- !, L1 is L-2, 44 | wt(P,L), nl, 45 | tab(L1), put("&"), tab(1), wt(Q,L). 46 | wt({P},L) :- complex(P), !, L1 is L+2, 47 | put("{"), tab(1), wt(P,L1), tab(1), put("}"). 48 | wt(E,L) :- decomp(E,H,P), !, L1 is L+2, 49 | header(H), nl, 50 | tab(L1), wt(P,L1). 51 | wt(E,_) :- write(E). 52 | 53 | header([]). 54 | header([X|H]) :- write(X), tab(1), header(H). 55 | 56 | decomp(setof(X,P,S),[S,=,setof,X],P). 57 | decomp(\+(P),[\+],P) :- complex(P). 58 | decomp(numberof(X,P,N),[N,=,numberof,X],P). 59 | decomp(X^P,[exists,X|XX],P1) :- othervars(P,XX,P1). 60 | 61 | othervars(X^P,[X|XX],P1) :- !, othervars(P,XX,P1). 62 | othervars(P,[],P). 63 | 64 | complex((_,_)). 65 | complex({_}). 66 | complex(setof(_,_,_)). 67 | complex(numberof(_,_,_)). 68 | complex(_^_). 69 | complex(\+P) :- complex(P). 70 | 71 | % Query execution. 72 | 73 | :-mode respond(?). 74 | :-mode holds(+,?). 75 | :-mode answer(+). 76 | :-mode yesno(+). :-mode replies(+). 77 | :-mode reply(+). 78 | :-mode seto(?,+,-). 79 | :-mode satisfy(+,-,?,?). 80 | :-mode pickargs(+,+,+). 81 | :-mode pick(+,?). 82 | 83 | respond([]) :- display('Nothing satisfies your question.'), nl. 84 | respond([A|L]) :- reply(A), replies(L). 85 | 86 | answer((answer([]):-E)) :- !, holds(E,B), yesno(B). 87 | answer((answer([X]):-E)) :- !, seto(X,E,S), respond(S). 88 | answer((answer(X):-E)) :- seto(X,E,S), respond(S). 89 | 90 | seto(X,E,S) :- 91 | % portray_clause(({X} :- E)), 92 | phrase(satisfy(E,G),Vars), 93 | % portray_clause(({X} :- G)), 94 | ( setof(X,Vars^G,S) 95 | -> true 96 | ; S = [] 97 | ). 98 | 99 | holds(E,True) :- 100 | phrase(satisfy(E, G), _), 101 | ( G 102 | -> True = true 103 | ; True = false 104 | ). 105 | 106 | yesno(true) :- display('Yes.'). 107 | yesno(false) :- display('No.'). 108 | 109 | replies([]) :- display('.'). 110 | replies([A]) :- display(' and '), reply(A), display('.'). 111 | replies([A|X]) :- display(', '), reply(A), replies(X). 112 | 113 | reply(N--U) :- !, write(N), display(' '), write(U). 114 | reply(X) :- write(X). 115 | 116 | %% satisfy(+Term, -Goal)// 117 | % 118 | % Originally, Term was meta-interpreted. If we do not want every 119 | % ^/2-term to act as an existential quantification, this no longer 120 | % works. Hence, we now compile the term into a goal and compute 121 | % the existentially quantified variables. 122 | 123 | satisfy((P0,Q0), (P,Q)) --> !, satisfy(P0, P), satisfy(Q0, Q). 124 | satisfy({P0}, (P->true)) --> !, satisfy(P0, P). 125 | satisfy(X^P0, P) --> !, satisfy(P0, P), [X]. 126 | satisfy(\+P0, \+P) --> !, satisfy(P0, P). 127 | satisfy(numberof(X,P0,N), (setof(X,Vars^P,S),length(S,N))) --> !, 128 | { phrase(satisfy(P0,P),Vars) }, 129 | [S], Vars. % S is an internal variable! 130 | satisfy(setof(X,P0,S), setof(X,Vars^P,S)) --> !, 131 | { phrase(satisfy(P0,P),Vars) }, 132 | Vars. 133 | satisfy(+P0, \+ exceptionto(P)) --> !, 134 | satisfy(P0, P). 135 | satisfy(X !. 136 | satisfy(X= !. 137 | satisfy(X>=Y, X>=Y) --> !. 138 | satisfy(X>Y, X>Y) --> !. 139 | satisfy(P, database(P)) --> []. 140 | 141 | exceptionto(P) :- 142 | functor(P,F,N), functor(P1,F,N), 143 | pickargs(N,P,P1), 144 | exception(P1). 145 | 146 | exception(P) :- database(P), !, fail. 147 | exception(_P). 148 | 149 | pickargs(0,_,_) :- !. 150 | pickargs(N,P,P1) :- N1 is N-1, 151 | arg(N,P,S), 152 | pick(S,X), 153 | arg(N,P1,X), 154 | pickargs(N1,P,P1). 155 | 156 | pick([X|_],X). 157 | pick([_|S],X) :- !, pick(S,X). 158 | pick([],_) :- !, fail. 159 | pick(X,X). 160 | 161 | -------------------------------------------------------------------------------- /prolog/chat80/templa.pl: -------------------------------------------------------------------------------- 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 | /* Nouns */ 24 | 25 | property(area,measure&area,X,feature&place&_,Y,area(Y,X),[],_,_). 26 | property(capital,feature&city,X,feature&place&country,Y, 27 | capital(Y,X),[],_,_). 28 | property(latitude, 29 | measure&position,X,feature&_,Y,latitude(Y,X),[],_,_). 30 | property(longitude,measure&position,X,feature&_,Y, 31 | longitude(Y,X),[],_,_). 32 | property(population, 33 | measure&heads,X,feature&_,Y,population(Y,X),[],_,_). 34 | 35 | thing(place,feature&place&_,X,place(X),[],_). 36 | thing(area,measure&area,X,area(X),[],_). 37 | thing(capital,feature&city,X,capital(X),[],_). 38 | thing(city,feature&city,X,city(X),[],_). 39 | thing(continent,feature&place&continent,X,continent(X),[],_). 40 | thing(country,feature&place&country,X,country(X),[],_). 41 | thing(latitude,measure&position,X,latitude(X),[],_). 42 | thing(longitude,measure&position,X,longitude(X),[],_). 43 | thing(ocean,feature&place&seamass,X,ocean(X),[],_). 44 | thing(person,_,X,person(X),[],_). 45 | thing(population,measure&heads,X,population(X),[],_). 46 | thing(region,feature&place&_,X,region(X),[],_). 47 | thing(river,feature&river,X,river(X),[],_). 48 | thing(sea,feature&place&seamass,X,sea(X),[],_). 49 | thing(seamass,feature&place&seamass,X,seamass(X),[],_). 50 | 51 | aggr_noun(average,_,_,average). 52 | aggr_noun(sum,_,_,total). 53 | aggr_noun(total,_,_,total). 54 | 55 | meta_noun(number,_,V,feature&_,X,P,numberof(X,P,V)). 56 | 57 | /* Proper nouns */ 58 | 59 | name_template(X,feature&circle) :- circle_of_latitude(X). 60 | name_template(X,feature&city) :- city(X). 61 | name_template(X,feature&place&continent) :- continent(X). 62 | name_template(X,feature&place&country) :- country(X). 63 | name_template(X,feature&place&_) :- region(X). 64 | name_template(X,feature&river) :- river(X). 65 | name_template(X,feature&place&seamass) :- seamass(X). 66 | 67 | /* Verbs */ 68 | 69 | trans(border, 70 | feature&place&_,X,feature&place&_,Y,borders(X,Y),[],_,_). 71 | trans(contain,feature&place&_,X,feature&_,Y,in(Y,X),[],_,_). 72 | trans(exceed,measure&Type,X,measure&Type,Y,exceeds(X,Y),[],_,_). 73 | 74 | intrans(drain,feature&river,X,drains(X,Y), 75 | [slot(prep(into),feature&place&_,Y,_,free)],_). 76 | intrans(flow,feature&river,X,flows(X,Y), 77 | [slot(prep(through),feature&place&_,Y,_,free)],_). 78 | intrans(flow,feature&river,X,flows(X,Y,Z), 79 | [slot(prep(into),feature&place&_,Z,_,free), 80 | slot(prep(from),feature&place&_,Y,_,free)],_). 81 | intrans(rise,feature&river,X,rises(X,Y), 82 | [slot(prep(in),feature&place&_,Y,_,free)],_). 83 | 84 | /* Adjectives */ 85 | 86 | restriction(african,feature&_,X,african(X)). 87 | restriction(american,feature&_,X,american(X)). 88 | restriction(asian,feature&_,X,asian(X)). 89 | restriction(european,feature&_,X,european(X)). 90 | 91 | attribute(large,feature&place&_,X,measure&area,Y,area(X,Y)). 92 | attribute(small,feature&place&_,X,measure&area,Y,area(X,Y)). 93 | attribute(great,measure&Type,X,measure&Type,Y,X=Y). 94 | attribute(populous,feature&_,X,measure&heads,Y,population(Y,X)). 95 | 96 | aggr_adj(average,_,_,average). 97 | aggr_adj(total,_,_,total). 98 | aggr_adj(minimum,_,_,minimum). 99 | aggr_adj(maximum,_,_,maximum). 100 | 101 | /* Prepositions */ 102 | 103 | adjunction(in,feature&_-X,feature&place&_-Y,in(X,Y)). 104 | adjunction(eastof,feature&_-X,feature&_-Y,eastof(X,Y)). 105 | adjunction(westof,feature&_-X,feature&_-Y,westof(X,Y)). 106 | adjunction(northof,feature&_-X,feature&_-Y,northof(X,Y)). 107 | adjunction(southof,feature&_-X,feature&_-Y,southof(X,Y)). 108 | 109 | /* Measure */ 110 | 111 | measure(ksqmile,measure&area,[],ksqmiles). 112 | measure(sqmile,measure&area,[],sqmiles). 113 | measure(degree,measure&position,[],degrees). 114 | measure(thousand,measure&heads,[],thousand). 115 | measure(million,measure&heads,[],million). 116 | 117 | units(large,measure&_). 118 | units(small,measure&_). 119 | 120 | chat_sign(large,+). 121 | chat_sign(small,-). 122 | chat_sign(great,+). 123 | 124 | /* Proportions and the like */ 125 | 126 | comparator(proportion,_,V,[],proportion(V)). 127 | comparator(percentage,_,V,[],proportion(V)). 128 | -------------------------------------------------------------------------------- /prolog/chat80/world0.pl: -------------------------------------------------------------------------------- 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 | 33 | database(aggregate(X,Y,Z)) :- aggregate(X,Y,Z). 34 | database(one_of(X,Y)) :- one_of(X,Y). 35 | database(ratio(X,Y,Z)) :- ratio(X,Y,Z). 36 | database(card(X,Y)) :- card(X,Y). 37 | database(african(X)) :- african(X). 38 | database(american(X)) :- american(X). 39 | database(area(X)) :- area(X). 40 | database(area(X,Y)) :- area(X,Y). 41 | database(asian(X)) :- asian(X). 42 | database(borders(X,Y)) :- borders(X,Y). 43 | database(capital(X)) :- capital(X). 44 | database(capital(X,Y)) :- capital(X,Y). 45 | database(circle_of_latitude(X)) :- circle_of_latitude(X). 46 | database(city(X)) :- city(X). 47 | database(continent(X)) :- continent(X). 48 | database(country(X)) :- country(X). 49 | database(drains(X,Y)) :- drains(X,Y). 50 | database(eastof(X,Y)) :- eastof(X,Y). 51 | database(european(X)) :- european(X). 52 | database(exceeds(X,Y)) :- exceeds(X,Y). 53 | database(flows(X,Y)) :- flows(X,Y). 54 | database(flows(X,Y,Z)) :- flows(X,Y,Z). 55 | database(in(X,Y)) :- in(X,Y). 56 | database(latitude(X)) :- latitude(X). 57 | database(latitude(X,Y)) :- latitude(X,Y). 58 | database(longitude(X)) :- longitude(X). 59 | database(longitude(X,Y)) :- longitude(X,Y). 60 | database(northof(X,Y)) :- northof(X,Y). 61 | database(ocean(X)) :- ocean(X). 62 | database(place(X)) :- place(X). 63 | %database(person(X)) :- person(X). % JW: person is not defined 64 | database(population(X)) :- population(X). 65 | database(population(X,Y)) :- population(X,Y). 66 | database(region(X)) :- region(X). 67 | database(rises(X,Y)) :- rises(X,Y). 68 | database(river(X)) :- river(X). 69 | database(sea(X)) :- sea(X). 70 | database(seamass(X)) :- seamass(X). 71 | database(southof(X,Y)) :- southof(X,Y). 72 | database(westof(X,Y)) :- westof(X,Y). 73 | 74 | :-op(500,xfy,--). 75 | 76 | exceeds(X--U,Y--U) :- !, X > Y. 77 | exceeds(X1--U1,X2--U2) :- ratio(U1,U2,M1,M2), X1*M1 > X2*M2. 78 | 79 | ratio(thousand,million,1,1000). 80 | ratio(million,thousand,1000,1). 81 | ratio(ksqmiles,sqmiles,1000,1). 82 | ratio(sqmiles,ksqmiles,1,1000). 83 | 84 | area(X--ksqmiles). 85 | capital(C) :- capital(X,C). 86 | city(C) :- city(C,_,_). 87 | country(C) :- country(C,_,_,_,_,_,_,_,_,_). 88 | latitude(X--degrees). 89 | longitude(X--degrees). 90 | place(X) :- continent(X); region(X); seamass(X); country(X). 91 | population(X--million). 92 | population(X--thousand). 93 | region(R) :- in_continent(R,_). 94 | 95 | african(X) :- in(X,africa). 96 | american(X) :- in(X,america). 97 | asian(X) :- in(X,asia). 98 | european(X) :- in(X,europe). 99 | 100 | in(X,Y) :- var(X), nonvar(Y), !, contains(Y,X). 101 | in(X,Y) :- in0(X,W), ( W=Y ; in(W,Y) ). 102 | 103 | in0(X,Y) :- in_continent(X,Y). 104 | in0(X,Y) :- city(X,Y,_). 105 | in0(X,Y) :- country(X,Y,_,_,_,_,_,_,_,_). 106 | in0(X,Y) :- flows(X,Y). 107 | 108 | eastof(X1,X2) :- longitude(X1,L1), longitude(X2,L2), exceeds(L2,L1). 109 | northof(X1,X2) :- latitude(X1,L1), latitude(X2,L2), exceeds(L1,L2). 110 | southof(X1,X2) :- latitude(X1,L1), latitude(X2,L2), exceeds(L2,L1). 111 | westof(X1,X2) :- longitude(X1,L1), longitude(X2,L2), exceeds(L1,L2). 112 | 113 | circle_of_latitude(equator). 114 | circle_of_latitude(tropic_of_cancer). 115 | circle_of_latitude(tropic_of_capricorn). 116 | circle_of_latitude(arctic_circle). 117 | circle_of_latitude(antarctic_circle). 118 | 119 | latitude(equator,0--degrees). 120 | latitude(tropic_of_cancer,23--degrees). 121 | latitude(tropic_of_capricorn,-23--degrees). 122 | latitude(arctic_circle,67--degrees). 123 | latitude(antarctic_circle,-67--degrees). 124 | 125 | latitude(C,L--degrees) :- country(C,_,L,_,_,_,_,_,_,_). 126 | longitude(C,L--degrees) :- country(C,_,_,L,_,_,_,_,_,_). 127 | area(C,A--ksqmiles) :- country(C,_,_,_,A,_,_,_,_,_). 128 | population(C,P--thousand) :- city(C,_,P). 129 | population(C,P--million) :- country(C,_,_,_,_,_,P,_,_,_). 130 | capital(C,Cap) :- country(C,_,_,_,_,_,_,_,Cap,_). 131 | 132 | continent(africa). 133 | continent(america). 134 | continent(antarctica). 135 | continent(asia). 136 | continent(australasia). 137 | continent(europe). 138 | 139 | in_continent(scandinavia, europe). 140 | in_continent(western_europe, europe). 141 | in_continent(eastern_europe, europe). 142 | in_continent(southern_europe, europe). 143 | in_continent(north_america, america). 144 | in_continent(central_america, america). 145 | in_continent(caribbean, america). 146 | in_continent(south_america, america). 147 | in_continent(north_africa, africa). 148 | in_continent(west_africa, africa). 149 | in_continent(central_africa, africa). 150 | in_continent(east_africa, africa). 151 | in_continent(southern_africa, africa). 152 | in_continent(middle_east, asia). 153 | in_continent(indian_subcontinent, asia). 154 | in_continent(southeast_east, asia). 155 | in_continent(far_east, asia). 156 | in_continent(northern_asia, asia). 157 | 158 | seamass(X) :- ocean(X). 159 | seamass(X) :- sea(X). 160 | 161 | ocean(arctic_ocean). 162 | ocean(atlantic). 163 | ocean(indian_ocean). 164 | ocean(pacific). 165 | ocean(southern_ocean). 166 | 167 | sea(baltic). 168 | sea(black_sea). 169 | sea(caspian). 170 | sea(mediterranean). 171 | sea(persian_gulf). 172 | sea(red_sea). 173 | 174 | river(R) :- river(R,L). 175 | 176 | rises(R,C) :- river(R,L), last(L,C). 177 | 178 | drains(R,S) :- river(R,L), first(L,S). 179 | 180 | flows(R,C) :- flows(R,C,_). 181 | 182 | flows(R,C1,C2) :- river(R,L), links(L,C2,C1). 183 | 184 | first([X|_],X). 185 | 186 | % last([X],X). % (SWI-system predicate) 187 | % last([_|L],X) :- last(L,X). 188 | 189 | links([X1,X2|_],X1,X2). 190 | links([_|L],X1,X2) :- links(L,X1,X2). 191 | 192 | -------------------------------------------------------------------------------- /prolog/chat80/xgrun.pl: -------------------------------------------------------------------------------- 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 | :- mode terminal(?,+,?,+,?), 24 | gap(+), 25 | virtual(+,+,?). 26 | 27 | terminal(T,S,S,x(_,terminal,T,X),X). 28 | terminal(T,[T|S],S,X,X) :- 29 | gap(X). 30 | 31 | gap(x(gap,_,_,_)). 32 | gap([]). 33 | 34 | virtual(NT,x(_,nonterminal,NT,X),X). 35 | --------------------------------------------------------------------------------