Пролог - тексты программ для тех, кто не смог их скачать и другие вспомогательные материалы

Как нужно понимать выполнение программы на Прологе

...



Пролог - язык декларативного типа.

Это значит, что выполнение своей программы он трактует как достижение цели в ответ на вопрос (запрос) и для этого сам выстраивает соответствующую процедуру, которую ни программист, ни тем более пользователь программы не видит и не знает, а разве что представляет общий механизм нахождения ответа на вопрос, который трактуется как поиск цели.

Вопрос к системе - это всегда последовательность, состоящая из одной или нескольких целей. Что значит достичь цели?

Достичь цели - это значит показать, что утверждения, содержащиеся в запросе истинны. Другими словами, достичь цели - это значит показать, что она ЛОГИЧЕСКИ (логика входит в название Пролога - ВР) следует из фактов и правил программы.

Если вопрос содержит переменные, система должна к тому же найти конкретные объекты которые (будучи подставленными вместо переменных) обеспечивают достижение цели. Найденные конкретизации сообщаются пользователю. Если для некоторой конкретизации система не в состоянии вывести цель из остальных предложений программы, то ее ответом на вопрос будет "нет".

Таким образом, подходящей интерпретацией пролог-программы в математических терминах будет следующее - пролог программа рассматривает факты и правила в качестве множества аксиом, а вопрос пользователя - как теорему. Затем она пытается ДОКАЗАТЬ эту теорему, то есть показать, что ее можно логически вывести из аксиом.

Это можно проиллюстрировать на примере др-гр силлогизма - Все люди смертны - Скорат человек - Сократ смертен

Здесь первые два предиката входят в программу - а третий - запрос

Как мы увидим в след семестре - пролог программа выводит НОВОЕ ЗНАНИЕ.


Из книги и по книге Братко Программирование на Прологе

...


...

SENAN - программа рассчитана на Пролог 5.2

...

Sentence Analyzer - это точнее чем блефистское semantic, которое есть тогда уж syntactic - ВР

Тем не менее -

The file SEN_AN is a very good example of an English sentence analyzer. The program can, just as the GEOBASE, easily be modified to be able to parse more types of sentences. The input to the semantic analyzer is of course a sentence, and the output is a list of Prolog clauses, that shows that every part of the sentence has been recognized as a grammatical component: verbp (for verbphrase), nounp (for nounphrase) etc.
The program SEN_AN.PRO demonstrates the basics of how a programmer can put together an English sentence analyzer in Prolog. When run, the sentence analyzer prompts the user to enter an English sentence. The program then attempts to parse (break apart) the sentence into a form that the analyzer can understand.
The resulting data object is known as a parse tree. After the parser creates a parse tree successfully, it can pass the tree on to a routine that specifies a task to be performed. SEN_AN passes the parse tree on to a routine that draws a graphic representation of the user''s sentence input. If SEN_AN cannot parse the sentence successfully, it will display an error message indicating the failure. If you enter a word that is not part of the dictionary, SEN_AN will show an error message indicating the word not recognized.
The syntax shows that an English sentence (In the Sen_an microworld) is made up of a noun phrase and a verb phrase. A noun phrase is made up of an optional determiner, followed by a noun, followed by a relational clause. A determiner can be empty (no determiner), or it can be one of the determiners found in the dictionary. A noun must be listed in the dictionary. The relational clause can be empty, or it can be a relative followed by a verb phrase. A verb phrase can either be a verb or a verb followed by a noun phrase.
For example, if you enter the sentence a mother loves her children, the parser will break this sentence down into the following Prolog data object:
sent(nounp(determ("a"), "mother", none),
verbp("loves", nounp(determ("her"), "children", none)))
This data object shows that the sentence is made up of the noun phrase a mother and the verb phrase loves her children.
In order to parse the sentences SEN_AN uses a context-free grammar. A more complex grammar can be specified, which would enable the parser to break down more complex sentences. Take a look at the parser code; you may want to start creating a parser that accepts more complex English sentences.
SEN_AN.PRO uses a limited set of English grammar rules to parse sentences. More complex sentences will need to have more rules of the English language coded into the parser. These rules, known as productions, are the heart of the analyzing procedure. Detailed productions make for a more thorough parser (or analyzer). Although intricate productions can be created to deal with the more complicated parts of English, the complexity of the English language creates a domain in which even the most specific productions have exceptions. For this reason, natural language processing (or NLP--not to be confused with Neuro Linguistic Programming) is a heavily-studied branch of Artificial Intelligence.

...

Source Code for Semantic analyzer

Сам код - см. ссылку внизу




...

GEOBASE - программа рассчитана на Пролог 5.2 - сам текст - см ссылку внизу

...

Geobase - A Geographical Database
Geobase demonstrates a natural language interface to a database on U.S. geography written in Visual Prolog.. It shouldn''t be too difficult to modify it to your own purposes, so that this will be the first step on the way to designing natural language interfaces to your programs. As all Prolog programs, Geobase is highly extendible. Try yourself to extend Geobase rule base, so that Geobase can manage more sentences. It isn''t that difficult! Geobase allows you to query its database in English rather than "computerese"-commands.
Geobase is by no means a complete geographical database of the United States, nor is it a complete English language interface. If you plan to write similar routines in your own programs, studying how the code is put together and how certain routines are implemented should help. Again, we urge you to modify Geobase to be a more complete program. This will not only sharpen your Visual Prolog programming skills, but it will also keep you off the streets late at night.
You can access the information stored in the Geobase database with natural language (in this case, the natural language is English). The database supplied with Geobase is built upon the geography of the United States. You can enter queries (questions) in English and Geobase will parse (translate) these questions into a form that Visual Prolog understands. Geobase will give answers to the queries to the best of its knowledge. The Geobase application demonstrates one of the important areas where Visual Prolog shines: understanding natural language.
One of the most exciting features of Geobase is that you can examine and edit the source code. The code of Geobase is fully documented; you can take any section and modify it to suit your needs. Take a look at the database and modify it to include your home town! Soon you''ll be on the road to creating your own natural language interfaces.
Sample queries:
What are the cities of New York?What is the highest mountain in California?What are the name of the states which border New Mexico?Which rivers run through the state that border the state with the capital Olympia?

Execute the program as a CGI script by pressing the "Run Query" button on the form below



...


Исходные тексты

Senan

Geobase

Отсюда можно скачать Пролог 5.2 и примеры

E-mail: rykov2000@mail.ru



Hosted by uCoz