2016-10-19 2 views
0

나는 프롤로그 언어에 새로 온 사람과 내가 프롤로그에서 프로그램 할 필요가오류 [편집]

Rule 1: 
if the environment is papers 
or the environment is manuals 
or the environment is documents 
or the environment is textbooks 
then stimulus_situation is verbal 
Rule 2: 
if the environment is pictures 
if the environment is illustrations 
if the environment is photographs 
if the environment is diagrams 
then stimulus_situation is visual 
Rule 3: 
if the environment is machines 
if the environment is buildings 
if the environment is tools 
then stimulus_situation is 'physical object' 
Rule 4: 
if the environment is numbers 
or the environment is formulas 
or the environment is 'computer programs' 
then stimulus_situation is symbolic 

시스템이다 4 개 규칙을 구현하려는 가 : 입력 할 때. 시스템은 사용자에게 환경 입력을 요청합니다. 입력 된 텍스트가 환경 중 하나 인 경우 시스템은 stimulus_situation을 출력해야합니다.

그래서이 코드를 작성하려고했지만 작동하지 않습니다. 그리고 왜 저를 도와 줄 수 있는지 모르겠습니다.

go:- check(Env), write('enviroment is :'),write(Env),nl,undo. 

check(verbal):- verbal,!. 
check(visual):- visual,!. 


verbal :- verify(enviroment). 
visual :- verify(pictures). 

ask(Question) :- 
     write('What is the Env?!'), 
     write(Question), write('? '), 
     read(Response), nl, 
     ((Response == papers ; Response == manuals ; Response == manuals; Response == textbook) 
     -> assert(yes(Question)) ; 
     assert(no(Question)), fail). 
:- dynamic yes/1,no/1. 

verify(S) :- (yes(S) -> true ; (no(S) -> fail ; ask(S))). 

시도하기 위해 2 가지 규칙으로 작성했지만 작동하지 않습니다.

미리 감사드립니다. 나는 당신의 설명에서 알 수있는 바와 같이

+0

당신이 "그렇지 일을 수행"을 의미합니까를? – coder

+0

@coder 전혀 작동하지 않습니다 –

+0

변수가 무엇입니까? – Eyal

답변

1

당신은 쓸 수 :

go:- ask("What is the Environment",Response), check(Response,Result),write('stimulus situation :'),write(Result). 

verify(X,Y) :- yes(X,Y) -> true. 


check(X,Y):- verify(X,Y),!. 


ask(Question,Response) :- 
     write(Question), write('? '), 
     read(Response), nl, 
     ((Response == papers ; Response == manuals ; Response == manuals; Response == textbook) 
     -> assert(yes(Response,verbal)) ; 
      (Response==machines)->assert(yes(Response,object))). 


:- dynamic yes/2. 

예 :

문제가 무엇인지 정확하게
  ?- go. 
What is the Environment? textbook. 

stimulus situation :verbal 
true. 


?- go. 
What is the Environment? machines. 

stimulus situation :object 
true. 
+0

코드를 보내 주셔서 감사하지만 오해가 있습니다. 구현하려고하는 시스템 : –

+0

1 - 입력 할 때 프로그램을 실행하십시오. - go. –

+0

2 시스템에서 환경이란 무엇인가 물어보십시오! 사용자가 규칙에 명시된 환경 중 하나를 입력하면 시스템에서 "stimulus_situation is"메시지와 stimulus_situation 유형을 입력해야합니다. –