2016-10-20 2 views
0

나는 사용자 입력에 따라 자극 상황을 결정하는 코드 조각을 썼다. 그러나 문제는 그것이 항상 동일한 출력을 제공하고 규칙에 따라 올바르지 않다는 것이다. 이 내 코드입니다 :이 간단한 코드가 Prolog에서 올바르게 실행되지 않는 이유는 무엇입니까?

start:- readenviroment(X),check(X,SS),environment(X,SS),write(SS). 


readenviroment(X):- 
write("What sort of environment is a trainee dealing with on the job?"),nl, 
read(X). 

environment(X,SS):- 
    visual(X,SS) ; verbal(X,SS). 

visual(X,SS):- 
((X == pictures ; X == illustrations ; X == photographs ; X== diagrams)->assert(yes(SS,cars))). 

verbal(X,SS):- 
((X == papers ; X == manuals ; X == documents ; X == textbooks)->assert(yes(SS,verbal))). 


:- dynamic yes/2. 
check(XX,SS):- 
verify(XX,SS),!. 

verify(XX,SS):- 
yes(XX,SS)->true. 

그리고 이것은 출력입니다 :

 2 ?- start. 
What sort of environment is a trainee dealing with on the job? 
|: textbook. 
verbal 
true. 

3 ?- start. 
What sort of environment is a trainee dealing with on the job? 
|: diagram. 

false. 

4 ?- start. 
What sort of environment is a trainee dealing with on the job? 
|: diagrams. 
verbal 
true. 

이 두 가지 규칙에 따르면.

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 

아무도 도와 줄 수 있습니까?! 또한 사전에 감사드립니다.

+0

있습니다/이 규칙들이 인코딩 되었습니까? 그들은 코드에 나타나지 않는 것들을 참조합니다. –

+0

@ScottHunter이 규칙은 시각적 및 언어 적 기능으로 인코딩됩니다. –

+0

게시 된 코드의 내용은 논문, 매뉴얼, 문서, 교과서, 그림, 삽화, 사진 또는 다이어그램을 의미하지 않습니다. –

답변

0

코드에 많은 문제가 있습니다. 직접적인 문제는 check/2environment/2 전에 호출된다는 것입니다.

그러나 Prolog 통역사에 대한 이해가있는 것은 아닙니다. 예를 들어 변수 SS은 코드의 아무 곳이나 바인딩되지 않습니다.

당신은 다음과 같은 규칙을 모델링하여 시작할 수 있습니다

:

다음
env_stim(Env, verbal) :- member(Env, [paper, manuals, documents, textbooks]) 
env_stim(Env, visual) :- member(Env, <etc>). 
<etc>. 

방금의 Env 변수에 대해 사용자에게 env_stim(Env, Stim)를 호출하고 응답 쓰는 : 어떻게

start :- 
    writeln('What is the environment?'), 
    read(Env), 
    env_stim(Env, Stim), 
    writeln(Stim). 
관련 문제