Selasa, 22 Desember 2009
Download Kode dan Laporan Simple Expert System for Identifying Human Desease
untuk rule pada notepad dan dalam format prolog
sedangkan untuk mengunduh file report Simple Expert System for identifying human desease silahkan klik disini
Sabtu, 19 Desember 2009
defining the disease using SWI-Prolog
chek this out..
1 . first write this rule into notepad .
2. and then save it with name coba.pl
3. open SWI-Prolog then consult he file
4. after that write definisi(Penyakit,Virus,_,_,_). to list all of the disease and the virus .
5. to list Gejala we can write definisi(Penyakit,Virus,_,Gejala,_).
6. if you want to list all of the disease and alternatif , ou can write this definisi(Penyakit,Virus,Menyerang,Gejal,Solusi).
7. please don't forget to give (.) ont the end of command .
Sabtu, 05 Desember 2009
LOOP (Exercise 6)
ok now we will do exercise 6 from book Logic Programing with Prolog .
Practical Exercise 6
(1) Define a predicate to output the values of the squares of the integers from N1 to N2 inclusive and test it with N1 = 6 and N2 = 12.
for answer number 1 its very easy . you should do it step by step .
ok, lets se the step .
1. first you must write a rules in notepad .
2. second you save it .pl
3. and then open the Prolog and and consult the file.
4. then you should write the instruction outsquare(7,10) . for this, you can write everything number that you like .
5.push enter .
6. so the result is :
(2) Define and test a predicate to read in a series of characters input by the user and output all of those before the first new line or ? character.
for number 2 , we should be careful .
lets do it together .
1. for step one , we must write a rules in notepad an then save .pl .
2. step two, open the prolog and consult the file .
3. then write instruction go. , push enter .
4. and then we can write everything you like, push enter again .
5. so, the result is :
6. but if you insert a character like '?' . it is only repeat word before character , but if you write again, it can't be repeat . it only once .
if you confuse , this is the example .
(3) Using the person clauses given in Section 6.3.1, find the professions of all those over 40.
this is the step to answer number 3.
1. first you must write a rule in notepad .
2. save it .pl
3. open the prolog and consult this file .
4. then write an instruction find. , and the result are is :finish . ^.^
LOOPS
1.1 Looping a Fixed Number of Times
No such facility loop in prolog, but a similar effect can be obtained using recursion.
Ex :
1. Make a new rule notepad.
2. then save .pl
3. and then open prolog consult that file and write an instruction ?- loop(6). And then push enter .
Ex 2 :
1. make a rule in notepad.
2. then save .pl
3. and consult in prolog .
4. and then write a instruction output_values(4,10). And the result is :
1.2Looping Until a Condition Is Satisfied
No such facility a set of instructions to be executed repeatedly until a given condition is met available directly in Prolog, but a similar effect can be obtained in several ways.
1.2.1 Recursion
Ex1 :
1. Make a new rule in notepad.
2. The second save .pl
3. And then open in prolog and consult the file .
4. Write a instruction go. Then push enter , and then write the the answer (without spasi and don’t forget to give (.) ).
5. The result is :
Ex 2 :
1. Make a rule in notepad .
2. Second step is you must ave it .pl
3. And then open prolog , consult the file .
4. In prolog you must write an instruction get_answer(Myanswer).
5. The result is :
1.2.2 Using the ‘repeat’ predicate.
Another method that is often used is based on the built-in predicate repeat. The name of this predicate is really a misnomer. The goal repeat does not repeat anything; it merely succeeds whenever it is called. The great value of repeat is that it also succeeds (as many times as necessary) on backtracking. The effect of this, as for any other goal succeeding, is to change the order of evaluating goals from 'right to left' (i.e. backtracking) back to 'left-to-right'. This can be used to create a looping effect.
Ex1 :
1. First make a rule in notepad .
2. Second save it with format .pl
3. Then consult this file in prolog .
4. Write the instruction get_answer(Y). then push enter .
5. Show the evaluation will prompt the user to enter a term.
6. Answer it with yes or no, it can’t stop until you aswer Yes or No.
Ex 2 :
1. Make a rule in notepad then save .pl
2. Then make a new file with name myfile.txt
3. Open prolog and consult the file .
4. And then write an instruction readterms(‘myfile.txt’). please don’t forget to bring (.).
5. The result is :
1.3Backtracking with Failure
1.3.1 Searching the Prolog Database
Ex 1 :
1. Make a rule in notepad and save .pl
2. Then consult the file in prolog .
3. And then write alldogs. in prolog
4. And the result is :
5. But if in rule you write this
The next program is designed to search a database containing clauses representing the name, age, place of residence and occupation of a number of people.
Ex 2 :
1. Make a rule in notepad and then save .pl
2. Second open the prolog and consult the file
3. Write allteachers. In prolog
1.3.2 Finding Multiple Solutions
Backtracking with failure can also be used to find all the ways of satisfying a goal.
Rabu, 25 November 2009
INPUT AND OUTPUT in Prolog.
- Outputting Terms
The write/1 predicate takes a single argument, which must be a valid Prolog term. Evaluating the predicate causes the term to be written to the current output stream, which by default is the user's screen. The built-in predicate nl/0 has also been used many times previously in this book. It takes no arguments. Evaluating a nl goal causes a new line to be output to the current output stream.
Examples
?- write(26),nl.
26
yes
?- write('a string of characters'),nl.
a string of characters
yes
?- write([a,b,c,d,[x,y,z]]),nl.
[a,b,c,d,[x,y,z]]
yes
?- write(mypred(a,b,c)),nl.
mypred(a,b,c)
yes
?- write('Example of use of nl'),nl,nl,write('end of example'),nl.
Example of use of nl
end of example
yes
If it is important to output the quotes, the writeq/1 predicate can be used.
- Inputting Terms
example :
?- read(X).
: jim.
X = jim
?- read(X).
: 26.
X = 26
?- read(X).
: mypred(a,b,c).
X = mypred(a,b,c)
?- read(Z).
: [a,b,mypred(p,q,r),[z,y,x]].
Z = [a,b,mypred(p,q,r),[z,y,x]]
- Input and Output Using Characters
All printing characters and many non-printing characters (such as space and tab) have a corresponding ASCII (American Standard Code for Information Interchange) value, which is an integer from 0 to 255. The table below gives the numerical ASCII values corresponding to the main printable characters and some others.
- Outputting Characters
Evaluating a put goal causes a single character to be output to the current output stream. This is the character corresponding to the numerical value (ASCII value) of its argument, for example
?- put(97),nl.
a
yes
?- put(122),nl.
z
yes
- Inputting Characters
Assuming the argument variable is unbound (which will usually be the case), it
is bound to the ASCII value of the input character.
?- get0(N).
: a
N = 97
?- get0(N).
: Z
N = 90
- Using Characters: Examples
The final example is a recursive program, based on the previous two, which shows how to read in a series of characters ending with * and count the number of vowels. Characters are read in one by one until a character with ASCII value 42 (signifying *) is encountered.
Here the two arguments of the count predicate can be interpreted as 'the number of vowels so far' and 'the total number of vowels'. The three arguments of the process predicate can be read as 'the ASCII value of an input character', 'the number of vowels up to but not including that character' and 'the total number of vowels', respectively.
The first two arguments of the processChar predicate can be interpreted in the same way as for process, but the third argument is 'the number of vowels up to and including the character (first argument)'.
Predicate vowel tests for one of the 10 possible vowels (five upper case and five lower case), using their ASCII values.
- Input and Output Using Files
The same facilities available for input and output from and to the user's terminal either term by term or character by character are also available for input and output from and to files (e.g. files on a hard disk or a CD-ROM).
The user may open and close input and output streams associated with any number of named files but there can only be one current input stream and one current output stream at any time. Note that no file can be open for both input and output at the same time (except user) and that the user input and output streams cannot be closed.
- File Output: Changing the Current Output Stream
Evaluating a tell goal causes the named file to become the current output stream. If the file is not already open, a file with the specified name is first created (any existing file with the same name is deleted).
Note that the file corresponding to the previous current output stream remains open when a new current output stream is selected. Only the current output stream can be closed (using the told predicate described below).
The default current output stream is user, i.e. the user's terminal. This value can be restored either by using the told predicate or by tell(user).
The built-in predicate told/0 takes no arguments. Evaluating a told goal causes the current output file to be closed and the current output stream to be reset to user, i.e. the user's terminal.
The built-in predicate telling/1 takes one argument, which must be a variable and will normally be unbound. Evaluating a telling goal causes the variable to be bound to the name of the current output stream.
- File Input: Changing the Current Input Stream
Evaluating a see goal causes the named file to become the current input stream. If the file is not already open it is first opened (for read access only). If it is not possible to open a file with the given name, an error will be generated. Note that the file corresponding to the previous current input stream remains open when a new current input stream is selected. Only the current input stream can be closed (using the seen predicate described below).
The default current input stream is user, i.e. the user's terminal. This value can be restored either by using the seen predicate or by see(user).
The built-in predicate seen/0 takes no arguments. Evaluating a see goal causes the current input file to be closed and the current input stream to be reset to user, i.e. the user's terminal.
The built-in predicate seeing/1 takes one argument, which must be a variable and will normally be unbound. Evaluating a seeing goal causes the variable to be bound to the name of the current input stream .
INPUT AND OUTPUT in Prolog (Eercise 5)
Hei .. hei .. hei ..
Seperti yang sebelumnya , kali ini kita akan melanjutkan exercise yang selanjutnya .
Kali ini kita akan membahas exercise 5 .
Ok . let’s start from number 1 .
1. Pertama buatlah rule dahulu pada notepad .
2. Kemudian beri nama dan save dengan format .pl
3. Kemudian buka prolog , dan consult le tersebut .
4. Lalu ketik makelower pada PROLOG , kemudian enter .
5. Lalu ketiklah kata-kata terserah anda , maka yang keluar adalah seperti ini .
2.
1. Pertama buat rule pada notepad .
2. Kemudian save as dengan format .pl .
3. Lalu buka PROLOG dan consult file tersebut .
4. Setelah itu buat file baru dinotepad .
5. kemudian ketik copyterms(‘Infile.txt’,'Outfile.txt’). pada PROLOG.
6. Lalu tekan enter dan hasilnya adalah sebagai berikut .
3.
1. Buat rule pada notepad .
2. Save .pl
3. Kemudian buka prolog dan consult file tersebut
4. Lalu buat file baru pada notepad yang isinya
5. Kemudian pada PROLOG tulisakan perintah readfile(‘testa.txt’).
6. Maka hasilnya adalah
4.
1. Buat rule pada notepad .
2. Kemudian save .pl
3. Buka prolog dan consult file tersebut .
4. Lalu buat file baru yang bernama in1.txt
5. Lalu buat lagi file baru yang bernama in2.txt,
6. Lalu ketik combine(‘in1.txt’,'in2.txt’,'out.txt’). pada prolog .
7. Maka hasil yang keluar adalh sebagai berikut .
5.
1. Pertama buatlah rule pada notead , kemudian save denganformat .pl
2. Kemudain buka PROLOG dan consult file tersebut .
3. lalu buat file bernama 1.txt pada notepad ,
4. kemudian buat lagi file bernama 2.txt
5. Lalu pada prolog ketik perintah compare(‘1.txt’,'2.txt’).
6. Maka hasilnya adalah sebagai berikut :