How to add new records to a database.

Discussions related to Visual Prolog
ahmednadi
VIP Member
Posts: 197
Joined: 15 Sep 2009 14:06

How to add new records to a database.

Unread post by ahmednadi » 14 Jul 2012 11:46

Dear Sir;
If you could help me to add new records to a database without deleting the old ones and then I want to write all records to a file.
Best regards;
AHMED NADY

User avatar
Thomas Linder Puls
VIP Member
Posts: 2447
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 14 Jul 2012 13:58

Do you mean a fact database? In that case you assert more facts.
Regards Thomas Linder Puls
PDC

ahmednadi
VIP Member
Posts: 197
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 14 Jul 2012 14:20

Dear Mr. Thomas;

It is a fact database.

Your prompt action will be highly appreciated.

AHMED NADY

Paul Cerkez
VIP Member
Posts: 388
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 14 Jul 2012 14:57

for one of us to do it would require the factbase information used your application.

look up in the help how to use assertz(). it is really easy to implement. if you can create a factbase, you can do an assertz().

for multi-fact factbases, an assert does not delete other entries. the only time a a factbase overwrites what is there is when it is a 'single' (more correctly understood as a fact "variable")


P.
AI Rules!
P.

ahmednadi
VIP Member
Posts: 197
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 14 Jul 2012 17:56

Dear Sir;
I do like this but when I try to print it out on a file.
the result is "noClause"
May I do something wrong?
So, please help me.
regards;
Ahmed Nady

User avatar
Thomas Linder Puls
VIP Member
Posts: 2447
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 14 Jul 2012 18:37

My guess is also that you are doing something wrong ;-), so I suggest that you show your code.

It could be that you assert the facts in one object, but save them from another object.
Regards Thomas Linder Puls
PDC

ahmednadi
VIP Member
Posts: 197
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 14 Jul 2012 20:02

Code: Select all

foreach ID=list::getMember_nd (IDList) do get_wordID(ID,Ew,Aw,Gender,Nature), assertz(wordtemp1(ID,Ew,Aw,Gender,Nature)) end foreach, file::save("Temp1.txt",temp1),

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 14 Jul 2012 21:38

Hi,

Maybe IDList is empty...

ahmednadi
VIP Member
Posts: 197
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 15 Jul 2012 8:16

Dear Sir;
As you said may IDList empty.
But there are many old records which are asserted at temp1.
regards;
AHMED NADY

User avatar
Thomas Linder Puls
VIP Member
Posts: 2447
Joined: 28 Feb 2000 0:01

Re:

Unread post by Thomas Linder Puls » 15 Jul 2012 11:39

IDList is empty, so the part of the code you have chosen to show is not really interesting for the problem (the code looks fine, however).
ahmednadi wrote:But there are many old records which are asserted at temp1.
Well, that does not sound plausible. Can you see the facts in the dobugger? Or how do you conclude that they are there?

Is it class facts or objects facts you have? If it is object facts, are you then sure that you use the correct object?
Regards Thomas Linder Puls
PDC

ahmednadi
VIP Member
Posts: 197
Joined: 15 Sep 2009 14:06

Unread post by ahmednadi » 15 Jul 2012 14:03

Code: Select all

foreach Ew=list::getMember_nd (WList) do get_wordID(ID,Ew,Aw,Gender,Nature), assertz(wordtemp1(ID,Ew,Aw,Gender,Nature)) end foreach,
this part of code is positioned at a position prior to that part of code.

temp1 is a class fact

Steve Lympany
VIP Member
Posts: 695
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 15 Jul 2012 14:37

Woops - I just repeated Thomas' class facts solution...please ignore this post.
cheers
s

Paul Cerkez
VIP Member
Posts: 388
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 15 Jul 2012 14:42

of both of your fech ststemeents, the foreach will not process anything is the lists are empty.

sometimes this is hard to see in the debugge.r (for me anyway) so what I do when i run into this kind of problem is to simply put a write statement temporarily inthe code.

in the case of what you have, I would do

Code: Select all

stdio::write(WList), foreach Ew=list::getMember_nd (WList) do get_wordID(ID,Ew,Aw,Gender,Nature), assertz(wordtemp1(ID,Ew,Aw,Gender,Nature)) end foreach,
if the list has any values in it, it will dump to your screen. once you verify the list is not empty, move into your foreach lop and verify get_word1 is actually returning correct information (use the debugger or another write statement). a foreach loop code must never fail inside the loop, so you may have code in get_word1 that ensures 'succes' but does not really succeed in the way you want. this in turn may affect your assertz.

as I mentioned, to really help, we need to see your code. sometimes the failure is not inthe most obvious place, it could be in another predicate that you are calling and you are getting unintended consequences.

I receommend posting a bit more of your code so we can see it in context.

P.
AI Rules!
P.

User avatar
Tonton Luc
VIP Member
Posts: 814
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 16 Jul 2012 10:50

:idea:

Code: Select all

stdio::write(WList), file::save("Temp1_before_foreach.txt",temp1), foreach ID=list::getMember_nd (IDList) do get_wordID(ID,Ew,Aw,Gender,Nature), assertz(wordtemp1(ID,Ew,Aw,Gender,Nature)) end foreach, file::save("Temp1.txt",temp1),

Post Reply