read_in([W|Ws]) :- get0(C), readword(C,W,C1), restsent(W,C1,Ws). /* Given a word and the character after it, read in the rest of the sentence */ restsent(W,10,[]) :- !. restsent(W,_,[]) :- lastword(W), !. restsent(W,C,[W1|Ws]) :- readword(C,W1,C1), restsent(W1,C1,Ws). /* Read in a single word, given an initial character (C), and remembering what character came after the word */ readword(C,W,C1) :- single_char(C,W), !, get0(C1). readword(C,W,C2) :- in_word(C,NewC), !, get0(C1), restword(C1,Cs,C2), name(W,[NewC|Cs]). readword(C,W,C2) :- get0(C1), readword(C1,W,C2). /* When in a word, get the rest of it */ restword(C,[NewC|Cs],C2) :- in_word(C,NewC), !, get0(C1), restword(C1,Cs,C2). restword(C,[],C). /* These are single character words */ single_char(X,W) :- in_set(X,[[33,45],[58,64],[91,94],96,[123,126]]), name(W,[X]). in_set(X,[X|_]):-!. in_set(X,[[Lo,Hi]|_]) :- X>=Lo,X=Hi, !, in_set(X,Z). in_set(X,[[Lo,Hi]|_]) :- XY, !, in_set(X,Z). /* These characters can be inside a word. The second clause lowers upper case letters */ in_word(C,C) :- C>96, C<123. in_word(C,L) :- C>64, C<91, L is C+32. in_word(46,46). in_word(C,C) :- C>47, C<58. in_word(95,95). /* These terminate a sentence */ lastword('\').