Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to find an element in a variable list.

Status
Not open for further replies.

auto

MIS
Aug 30, 1999
9
US
Hi,
I have a program that receives an argument and stores it into a variable. I need to determine if a specific word is part of the argument that was received. I was successful when matching one word to one other word. However, when the argument is a sentence I can not get the program to loop through the sentence and compare every word in the sentence to the one I am looking for. I am having little success using the examples in the Prolog reference manual. Can someone provide a brief example of how I can accomplish this?
Thanks
 
It is useful to represent a sentence as a list of words. It's a nasty but efficient way. There are existing functions to implement this. Now I have a course of "Natural Language Processing" and we use program read_sent from (Clocksin, Mellish 1987), it is also available in Clive Matthews' "Introduction to NLP through PROLOG". It just reads a keyboard input and yields a list of words. Try to find this program! When your word list is completed you can easily process it (for example for translation purposes):
translate([],[]).
translate[Word|T],[WordTr|T1]):-
translation(Word,WordTr),
translate(T,T1).
translation(something1,something2).
...
If you just want to find out whether the specified word is present, use the following:
exist(Word,[Word|_]):-!.
exist(Word,[_|T]):-
exist(Word,T).
Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top