[[
✎ pl:prolog:pllib:sentence2atoms
]]
aiWiki
Pokaż stronę
Ostatnie zmiany
Indeks
Zaloguj
Ta strona jest tylko do odczytu. Możesz wyświetlić źródła tej strony ale nie możesz ich zmienić.
====== Sentence2atoms ====== {{tag>language lists cut}} ===== Description ===== A procedure to transform a sentence into a list of atoms. **Source**: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7. ===== Download ===== Program source code: {{sentence2atoms.pl}} ===== Listing ===== <code prolog> % Figure 6.2 A procedure to transform a sentence into a list of atoms. /* Procedure getsentence reads in a sentence and combines the words into a list of atoms. For example getsentence( Wordlist) produces Wordlist = [ 'Mary', was, pleased, to, see, the, robot, fail] if the input sentence is: Mary was pleased to see the robot fail. */ getsentence( Wordlist) :- get0( Char), getrest( Char, Wordlist). getrest( 46, [] ) :- !. % End of sentence: 46 = ASCII for '.' getrest( 32, Wordlist) :- !, % 32 = ASCII for blank getsentence( Wordlist). % Skip the blank getrest( Letter, [Word | Wordlist] ) :- getletters( Letter, Letters, Nextchar), % Read letters of current word name( Word, Letters), getrest( Nextchar, Wordlist). getletters( 46, [], 46) :- !. % End of word: 46 = full stop getletters( 32, [], 32) :- !. % End of word: 32 = blank getletters( Let, [Let | Letters], Nextchar) :- get0( Char), getletters( Char, Letters, Nextchar). </code> ===== Comments =====
pl/prolog/pllib/sentence2atoms.txt
· ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
Pokaż stronę
Poprzednie wersje
Menadżer multimediów
Do góry