How to convert from list to be different name

Discussions related to Visual Prolog
Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 1 Nov 2011 11:06

Hi,
1)
can you explain the different between "class facts" and "facts"?
See
http://wiki.visual-prolog.com/index.php ... nd_Objects

Class facts and class predicates (=methods) have only one copy in your program (equivalent to modular programming). Object facts and predicates have multiple copies (probably - otherwise you would use "class"). Standard OO stuff.

2)
what must i do with the "Max", is it real or string or what?
You have declared it:

Code: Select all

class facts - maxDB     max : (real Max).  
3) The steps in your code are
a) read the file and get a list of max(). The file is assumed to contain (eg)
max(21.7).
max(45.4).
etc

b)call getAllMax(), which should be
getAllMax(MaxList) :-
MaxList=[X||max(X)].

c) Then I assume you want to set the inputs...? The I suggest, instead:

Code: Select all

getAllMax() :-         MaxList=[X||max(X)],         set(MaxList,mem_max_list). set([],_):-!. set(_,[]):-!. set([Max|MaxList],[Input|Inputs]):-      Input:=Max, %I think this should work, but I haven't tried it      set(MaxList,Inputs).


You are going up a steep learning curve, obviously. When you have learned a bit more, I think you will see that having 16 fact variables input1 to input16 is probably not a good design. I don't know exactly what you're doing, but I suggest you create a class, and then create 16 objects of that class, with one of its properties being your input fact. It will pave the way for simpler coding, less bulky coding, fewer bugs, easier expansion (say from 16 to 26...) etc.

cheers
Steve

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

Unread post by Thomas Linder Puls » 1 Nov 2011 12:31

Steve Lympany wrote:

Code: Select all

     Input:=Max, %I think this should work, but I haven't tried it
No, that will not work. As stated above the list will contain the values from the fact variables, not the fact variables themselves.

Again: The whole idea behind this mail is bad. Its a misuse of fact databases and it is a misuse of fact variables.

As mentioned above, the fact database should for example look like this:

Code: Select all

clauses observation("aplikasiPasien", 17.3). observation("sakitGigi", 0.231). ...
It does not make sense to use this instead:

Code: Select all

clauses max(17.3). max(0.231). ...
If we stick to hard coded fact variables (which may be a good idea in a learning the language/concepts program). Then it is much, much, much simpler to do it in the obvious way:

Code: Select all

class facts - observations     aplikasiPasien : real := 0.     sakitGigi : real := 0.     ...   class predicates     saveObservations : (string Filename). clauses     saveObservations(Filename) :-         file::save(Filename, observations).   class predicates     consultObservations : (string Filename). clauses     consultObservations(Filename) :-         file::consult(Filename, observations).
This gives/requires a fact file that looks like this:

Code: Select all

clauses aplikasipasien(17.3). sakitgigi(0.231). ...
Regards Thomas Linder Puls
PDC

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 2 Nov 2011 1:14

Thomas Linder Puls wrote:
Steve Lympany wrote:

Code: Select all

     Input:=Max, %I think this should work, but I haven't tried it
No, that will not work. As stated above the list will contain the values from the fact variables, not the fact variables themselves.

Again: The whole idea behind this mail is bad. Its a misuse of fact databases and it is a misuse of fact variables.

As mentioned above, the fact database should for example look like this:

Code: Select all

clauses observation("aplikasiPasien", 17.3). observation("sakitGigi", 0.231). ...
It does not make sense to use this instead:

Code: Select all

clauses max(17.3). max(0.231). ...
If we stick to hard coded fact variables (which may be a good idea in a learning the language/concepts program). Then it is much, much, much simpler to do it in the obvious way:

Code: Select all

class facts - observations     aplikasiPasien : real := 0.     sakitGigi : real := 0.     ...   class predicates     saveObservations : (string Filename). clauses     saveObservations(Filename) :-         file::save(Filename, observations).   class predicates     consultObservations : (string Filename). clauses     consultObservations(Filename) :-         file::consult(Filename, observations).
This gives/requires a fact file that looks like this:

Code: Select all

clauses aplikasipasien(17.3). sakitgigi(0.231). ...
sorry Thomas, i don't understand with your explanation, can u explain that for my project? Thanks...
Daniel

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

Unread post by Thomas Linder Puls » 2 Nov 2011 8:53

Well, actually the explanaition is for your project (as I understand it, of course).

Your fact variable input1 corresponds to my fact variable aplikasiPasien, because (as I understand it) input1 represents the observation of the symptom Aplikasi Pasien (google translate cannot translate this to a symptom).

Your fact variable input2 corresponds to my fact variable sakitGigi because input2 represents the observation of the symptom Sakit Gigi (= toothache).

Your "strange" input file:

Code: Select all

clauses max(17.3). max(0.231). ...
Which is supposed to assign 17.3 to input1, 0.231 to input2, etc.

Corresponds to my input file:

Code: Select all

clauses aplikasipasien(17.3). sakitgigi(0.231). ...
file::consult(Filename, observations) automatically assigns 17.3 to aplikasiPasien, 0.231 to sakitGigi, etc (for the right Filename).

file::save(Filename, observations) will automatically create a file in that format based on the current values of the fact variables.

You can of course learn all this by trying to solve your own problem, but it will be far more efficient if you first follow the Getting Started to obtain the basic skills and understanding of the concepts, and then solve your own problem.
Regards Thomas Linder Puls
PDC

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 4 Nov 2011 6:56

Thomas Linder Puls wrote:Well, actually the explanaition is for your project (as I understand it, of course).

Your fact variable input1 corresponds to my fact variable aplikasiPasien, because (as I understand it) input1 represents the observation of the symptom Aplikasi Pasien (google translate cannot translate this to a symptom).

Your fact variable input2 corresponds to my fact variable sakitGigi because input2 represents the observation of the symptom Sakit Gigi (= toothache).

Your "strange" input file:

Code: Select all

clauses max(17.3). max(0.231). ...
Which is supposed to assign 17.3 to input1, 0.231 to input2, etc.

Corresponds to my input file:

Code: Select all

clauses aplikasipasien(17.3). sakitgigi(0.231). ...
file::consult(Filename, observations) automatically assigns 17.3 to aplikasiPasien, 0.231 to sakitGigi, etc (for the right Filename).

file::save(Filename, observations) will automatically create a file in that format based on the current values of the fact variables.

You can of course learn all this by trying to solve your own problem, but it will be far more efficient if you first follow the Getting Started to obtain the basic skills and understanding of the concepts, and then solve your own problem.
If i change my database, like :

sakitgigi.txt :

Code: Select all

clauses sakitgigi(0.6).
sakitkepala.txt :

Code: Select all

clauses sakitkepala(0.2).
etc.

So, how can i calculate that?

Code: Select all

class predicates     saveObservations : (string Filename). clauses     saveObservations(Filename) :-         file::save(Filename, observations).   class predicates     consultObservations : (string Filename). clauses     consultObservations(Filename) :-         file::consult(Filename, observations).   clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         consultObservations(sakitgigi.txt),         consultObservations(sakitkepala.txt).
is it true?

NB : I've already add your FB, can you approve that and answer the message? thanks
Daniel

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

Unread post by Thomas Linder Puls » 4 Nov 2011 12:19

You should have all the observations in a single file.

Code: Select all

clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         consultObservations("observations.txt").
Regards Thomas Linder Puls
PDC

danepa
VIP Member
Posts: 57
Joined: 29 Sep 2011 5:54

Re:

Unread post by danepa » 4 Nov 2011 16:34

--- Problem solved ---

Thanks to Thomas and George
Daniel

Post Reply