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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call the thing i save in another .pl?

Status
Not open for further replies.

khor86

Programmer
Oct 8, 2008
3
MY
How to call the thing i save in another .pl, coz i doing dictionary, when the word in not in database, then i set it will automatic save to a database with extension .pl. But, now i facing the problem is how to call out the word that i saved when i use the dictionary again. wat is the coding? anyone can help?
 
i using LPA prolog, for example, i key in a word in the prolog version command line dictionary, then read the word whether in the knowledge base or not, if not then will save it to another .pl. then next time if i key the same word, then it will appear the meaning of the word, bcoz last time i ady saved the meaning of that word. my problem is i dunno how to call out the word that i saved. u have any method of coding it?
 
Tis is one of learner.pl example. my problem is how to call out kb.pl in my command line dictionary that i created.

start :-
consult('kb.pl'),nl,
write('Note! Type names entirely in'),nl,
write('lower case, followed by a period.'),nl,
write('Type "stop." to quit.'),nl,
nl,
process_a_query.

process_a_query :-
write('State? '),
read(State),
answer(State).

/* If user typed "stop." then save the knowledge base and quit. */
answer(stop) :-
write('Saving the knowledge base...'),nl,
tell('kb.pl'),
listing(capital_of/2),
told,
write('Done.'),nl.

/* If the state is in the knowledge base, display it, then loop back to process_a_query */
answer(State) :-
capital_of(State,City),
write('The capital of '),
write(State),
write(' is '),
write(City),nl,
nl,
process_a_query.

/* If the state is not in the knowledge base, ask the user for information, add it to the knowledge base, and loop back to process_a_query*/
answer(State) :-
not capital_of(State,_),
write('I do not know the capital of that state.'),nl,
write('Please tell me.'),nl,
write('Capital? '),
read(City),
write('Thank you.'),nl,nl,
assertz(capital_of(State,City)),
process_a_query.
 
I'm not sure to have understood what you mean.
Do you search for things like that in command line ?
Code:
1 ?-  consult('D:/Developpements/Prolog/DVP/kb.pl').
% D:/Developpements/Prolog/DVP/kb.pl compiled 0.00 sec, 576 bytes

Yes
2 ?- capital_of(france,X).

X = paris ;

No
3 ?- capital_of(norvege, oslo).

No
4 ?- assert(capital_of(norvege, oslo)).

Yes
5 ?- capital_of(norvege, oslo).

Yes
6 ?- tell('D:/Developpements/Prolog/DVP/kb.pl').

Yes
7 ?- listing(capital_of/2).

Yes
8 ?- told.

Yes
The result in kb.pl is
Code:
:- dynamic capital_of/2.

capital_of(belgique, bruxelle).
capital_of(france, paris).
capital_of(germany, berlin).
capital_of(italy, rome).
capital_of(norvege, oslo).
I use SWI-Prolog.
But you can just add facts with notepad.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top