1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| subject(i).
subject(you).
subject(he).
subject(she).
subject(we).
subject(they).
antinomie(negative, positive).
antinomie(no, yes).
antinomie(true, false).
antinomie(born, dead).
antinomie(peace, war).
antinomie(dead, life).
antinomie(i, you).
antinomie(we, they).
antinomie(win, loose).
synonyme(no, negative).
synonyme(negative, false).
synonyme(yes, positive).
synonyme(positive, true).
synonyme(affirmative, positive).
synonyme(born, life).
synonyme(i, me).
synonyme(love, like).
synonyme(war, dead).
synonyme(kill, war).
synonyme(life, will).
[no_analyze([X|_], S) :-
(search_synonyme(X, Y),
search_antinomie(Y, A),
search_synonyme(A, S), !
;
search_antinomie(X, S), !
;
S = X).
yes_analyze([X|_], A) :-
(search_antinomie(X, Y),
search_synonyme(Y, S),
search_antinomie(S, A), !
;
search_synonyme(X, A), !
;
A = X).
no :- write('no, ').
yes :- write('yes, ').
no([X|L], S) :- no_analyze(L, S).
yes([X|L], A) :- yes_analyze(L, A).
is_affirmative([Subject, Verb | Complement]) :- subject(Subject).
is_interrogative([Verb, Subject | Complement]) :- subject(Subject).
is_affirmative(List, End) :- (End == 33; End == 46),
is_affirmative(List).
is_interrogative(List, End) :- End == 63,
is_interrogative(List).
inverse_affirmative([Subject, Verb | Complement], [C, V, S]) :-
yes_analyze([Subject], S),
yes_analyze([Verb], V),
yes_analyze(Complement, C).
inverse_interrogative([Verb, Subject | Complement], [R, S, V, C]) :-
(yes_analyze([Subject], S),
yes_analyze([Verb], V),
yes_analyze(Complement, C), !,
R = yes
;
no_analyze([Subject], S),
no_analyze([Verb], V),
no_analyze(Complement, C), !,
R = no).
words_to_list(Index, Words, List) :-
nth0(Index, Words, S),
nth0(Index, List, A),
atom_codes(A, S).
output_to_list(String, List, Sentence) :-
split_string(String, "-', ", ", ", String_List),
length(String_List, Length),
length(List, Length + 1),
Last is Length - 1,
foreach(between(0, Last, Index),
words_to_list(Index, String_List, List)),
length(Sentence, Length),
foreach(between(0, Last, Index),
words_to_list(Index, String_List, Sentence)).
input_to_list(String, List, Sentence) :-
split_string(String, "-', ", ", ", String_List),
length(String_List, Length),
List_Length is Length + 1,
length(List, List_Length),
Last is Length - 1,
foreach(between(0, Last, Index),
words_to_list(Index, String_List, List)),
length(Sentence, Length),
foreach(between(0, Last, Index),
words_to_list(Index, String_List, Sentence)).
pnl :-
read_string(user_input, "!?.", """\n", End, String),
input_to_list(String, List, Sentence),
length(List, Length),
nth1(Length, List, At_End),
char_code(At_End, End),
nth1(1, Sentence, Head),
(
Head == yes ->
delete(Sentence, yes, Affirmative),
%yes(Affirmative, Yes),
inverse_affirmative(Affirmative, Response),
atomics_to_string(Response, ' ', Result),
write(Result), writeln(At_End) ;
Head == no ->
delete(Sentence, no, Interrogative),
%no(Interrogative, No),
inverse_affirmative(Interrogative, Response),
atomics_to_string(Response, ' ', Result),
write(Result), writeln('?') ;
(is_affirmative(List, End) ->
inverse_affirmative(Sentence, Response),
atomics_to_string(Response, ' ', Result),
write(Result), writeln(At_End) ;
(is_interrogative(List, End) ->
inverse_interrogative(Sentence, R),
nth1(1, R, A),
(
A == yes ->
delete(R, yes, Affirmative),
%yes(Affirmative, Yes),
inverse_affirmative(Affirmative, Response),
atomics_to_string(Response, ' ', Result),
yes, write(Result), writeln(At_End) ;
A == no ->
delete(R, no, Interrogative),
%no(Interrogative, No),
inverse_affirmative(No, Response),
atomics_to_string(Response, ' ', Result),
no, write(Result), writeln('?')
;
atomics_to_string(R, ' ', Result),
write(Result), writeln('?')
)
)
)
),
pnl. |
Partager