Ядром вашей программы должен быть предикат, который маркирует список кодов символов, т. Е. Строит список атомов (= слов) из кодов. Ниже приводится схема:
%% tokenize(+Codes:list, -Atoms:list)
%
% Converts a list of character codes
% into a list of atoms. There can be several solutions.
tokenize([], []) :- !.
tokenize(Cs, [A | As]) :-
% Use append/3 to extract the Prefix of the code list
append(...),
% Check if the prefix constitutes a word in the dictionary,
% and convert it into an atom.
is_word(Prefix, A),
% Parse the remaining codes
tokenize(...).
Теперь вы можете определить:
is_word(Codes, Atom) :-
atom_codes(Atom, Codes),
word(Atom).
word(the).
word(there).
word(review).
word(view).
split_words(Sentence, Words) :-
atom_codes(Sentence, Codes),
tokenize(Codes, Words).
и используйте его так:
?- split_words('thereview', Ws).
Ws = [the, review] ;
Ws = [there, view] ;
false.
или используйте его в чем-то более сложном, где вы анализируете файл, чтобы получить входные данные и вывести результаты в файл.