PDA

View Full Version : Prolog 2 properties must be true


asilter79
12-15-2004, 01:53 AM
if an input has 2 properties, how can i handle it?

exp:

mary is a proper_noun or the true case can also be a pronoun. how will i define it?
when i write the codes like:

////////////////////////////////////
pronoun(she).
pronoun(he).

female(mary).
male(john).

proper_noun(mary).
proper_noun(john).

verb(slept).

is_Sentence(Person,Verb):-
pronoun(Person),
proper_noun(Person),
verb(Verb).
////////////////////////////////////
when i ask the program:

is_Sentence(mary,slept).

it says 'no'.
what can i do to get the answer 'yes'? because mary or a pronoun should make program say 'yes'. "he slept" also must be true.

plz help
thanks all.

Trident
12-15-2004, 02:35 AM
is_Sentence(Person,Verb):-
proper_noun(Person),
verb(Verb),!.
is_Sentence(Person,Verb):-
pronoun(Person),verb(Verb),!.


Tested in GNU Prolog.

Trident
12-15-2004, 02:39 AM
BTW, you'r really new to Prolog so check that cuts ("!" predicates) do, they are needed here in order to not to get ambiguous "yes, no" answer bnut may interfere if you expand your program further.

Trident
12-15-2004, 02:53 AM
Oops again. You do not really need those cuts:
with cuts:

GNU Prolog 1.2.16
By Daniel Diaz
Copyright (C) 1999-2002 Daniel Diaz
| ?- [mary].
compiling H:\GNU-Prolog\bin\mary.pl for byte code...
H:\GNU-Prolog\bin\mary.pl compiled, 15 lines read - 1380 bytes written, 20 ms

yes
| ?- is_Sentence(X,slept).

X = mary

yes
| ?-


Without cuts:

[mary].
compiling H:\GNU-Prolog\bin\mary.pl for byte code...
H:\GNU-Prolog\bin\mary.pl compiled, 15 lines read - 1265 bytes written, 10 ms

yes
| ?- is_Sentence(X,slept).

X = mary ? a

X = john

X = she

X = he

yes
| ?-


Second variant gives us complete answer, wich is better in this case.

So, is_Sentence(Person,Verb):-
proper_noun(Person),
verb(Verb).
is_Sentence(Person,Verb):-
pronoun(Person),verb(Verb).