Prolog 2 properties must be true

Ee3d05a661ec63c49a0fef31613b6354
0
asilter79 101 Dec 15, 2004 at 08:53

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.

3 Replies

Please log in or register to post a reply.

E72f771c34f4e58f34a2eac1844b214e
0
Trident 101 Dec 15, 2004 at 09:35
is_Sentence(Person,Verb):- 
proper_noun(Person),
verb(Verb),!.
is_Sentence(Person,Verb):- 
pronoun(Person),verb(Verb),!.

Tested in GNU Prolog.

E72f771c34f4e58f34a2eac1844b214e
0
Trident 101 Dec 15, 2004 at 09:39

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.

E72f771c34f4e58f34a2eac1844b214e
0
Trident 101 Dec 15, 2004 at 09:53

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).