3

can anyone help me to display untranslated word? for example i want to translate, 'i want to eat', in fact, there is no argument of to...so it will display 'saya mahu to makan'...the word to is remain the same it is and need to display it..this is the sample of my code..

:-dynamic(item/1).

kamus(saya,i).
kamus(suka,love).
kamus(awak,you).

run:-
  write('Enter a sentence:'),
  read(V),
  printed(V,C). 

%malay to eng

check(S,W,R):-
  kamus(R,S),name(S,W).

%eng to malay

check(S,W,R):-
  kamus(S,R),name(S,W).

check(Y,R):-
  item(Z),name(Z,Y).

try2(P,R):- 
  name(P,Q),
  split(Q,32,E),
  member(Z,E),
  assert(item(Z)),
  (check(Y,R);check(S,W,R)),Z=W.

printed(V,C):- 
  try2(V,C),write(C),write(' '),fail.

split(String, Space, [Word|List]) :-
  append(Word, [Space|Tail], String),
  !,
  split(Tail, Space, List).

split(String, _Space, [String]).

example of output:

?-run.
Enter the sentence : 'saya benci awak'.

i you no.

**there is no 'benci' in the fact but i need it to display in the output---> 'i benci you'

4

1 回答 1

2

尝试在切上瘾之后添加“包罗万象”规则

check(S,W,R):-
  kamus(S,R),name(S,W), !.

% after edit. HTH    
check(S,_,R):-
  name(S,R).

check(Y,R):-
  item(Z),name(Z,Y), !.

check(Y,Y).

cut 确保在您的规则数据库中列出的更合适的规则时不使用默认值。

编辑:我没有注意到第一次检查有 arity 3(然后第一次切割没用)。当然,另一个默认值应该放在上面提到的地方。

于 2013-06-01T06:17:08.233 回答