Selasa, 22 Desember 2009

Final Project Matdis

Akhirnya setelah sekian lama berusaha, selesai juga final report kita...

Berikut ini linknya..

Final Report PDF
Source Code Prolog

Rabu, 16 Desember 2009

Testing - Expert System

Untuk tugas sistem pakar sebelumnya mungkin aplikasi kami sulit untuk diwujudkan. Untuk itu sekarang kelompok kami mencoba membuat aplikasi sederhana yang dapat mengetahui jarak rumah dalam suatu komplek, siapakah keluarga yang lingkungan rumahnya sehat, apakah suatu keluarga dalam komplek tersebut bahagia, apakah rumah keluarga yang satu dengan yang lainnya dalam satu komplek tersebut dekat, dan siapakah keluarga yang memiliki rumah yang besar...

berikut adalah source codenya :


sourcecode.jpg

Lalu, berikut adalah tampilan jika kita mencobanya pada SWI prolog :


bahagia.jpg



lingkungansehat.jpg


near.jpg


rumahbersih.jpg


rumahbesar.jpg


jarakrumah.jpg

Senin, 07 Desember 2009

Jawaban Practical Exercise 6

Soal 1

Langkah pengerjaan :

  1. Buat rule prolog yang memanfaatkan predikat outsquare menggunakan metode rekursi untuk mengatur prolog mencari nilai kuadrat dari bilngan N1 selama N1 nilainya tidak lebih dari N2.(Soal1 Rule.jpg)
  2. Tuliskan perintah pada SWI prolog sesuai rule.(Soal1 SWI.jpg)


Soal1 Rule.jpg


Soal1 SWI.jpg


Soal 2

Langkah pengerjaan :

  1. Buat rule prolog yang memanfaatkan predikat repeat, go, get0 dan getrest untuk mengatur prolog membaca karakter dari input sebelum barisan karakter terakhir/pindah baris atau sebelum karakter ?.(Soal2 Rule.jpg)
  2. Tuliskan perintah pada SWI prolog sesuai rule.(Soal2 SWI.jpg)


Soal2 Rule.jpg


Soal2 SWI.jpg


Soal 3

Langkah pengerjaan :

  1. Buat rule prolog yang memanfaatkan predikat find menggunakan metode "bactracking with failure" untuk mengatur prolog mencari profesi dari orang yang berumur lebih dari 40 tahun berdasarkan person clauses yang ada pada Section 6.3.1.(Soal3 Rule.jpg)
  2. Tuliskan perintah pada SWI prolog sesuai rule.(Soal3 SWI.jpg)


Soal3 Rule.jpg


Soal3 SWI.jpg

Summary Bab 6 Loop

Chapter Aims
After reading this chapter you should be able to:
1. Define a predicate which causes a sequence of goals to be evaluated
repeatedly, either a fixed number of times or until a specified condition is
2. satisfied
Define a predicate which searches a database to find all the clauses with a
specified property.

Introduction
Most conventional programming languages have a looping facility that enables a
set of instructions to be executed repeatedly either a fixed number of times or until
a given condition is met. Prolog has no looping facilities, similar effects can be obtained that enable asequence of goals to be evaluated repeatedly. This can be done in a variety of ways, using backtracking, recursion, built-in predicates, or a combination of these.

6.1 Looping a Fixed Number of Times

Example 1
The following program outputs integers from a specified value down to 1.
loop(0).
loop(N):-N>0,write('The value is: '),write(N),nl,
M is N-1,loop(M).

The loop predicate is defined in terms of itself. The second clause can be
thought of as: 'to loop from N, first write the value of N, then subtract one to give
M, then loop from M'. This process clearly needs to be terminated and this is
achieved by the first clause: 'when the argument is zero, do nothing (and hence
stop)'. The first clause can be regarded as a terminating condition for the recursion.

?- loop(6).

The value is: 6

The value is: 5

The value is: 4

The value is: 3

The value is: 2

The value is: 1

yes



6.2 Looping Until a Condition Is Satisfied

6.2.1 Recursion

The first example below shows the use of recursion to read terms entered by the
user from the keyboard and output them to the screen, until end is encountered.

go:-loop(start). /* start is a dummy value used to get
the looping process started.*/
loop(end).
loop(X):-X\=end,write('Type end to end'),read(Word),
write('Input was '),write(Word),nl,loop(Word).

?- go.

Type end to end: university.

Input was university

Type end to end: of.

Input was of

Type end to end: portsmouth.

Input was portsmouth

Type end to end: end.

Input was end

Yes

Using the disjunction operator ;/2 which was defined in Section 4.4 the above
program can be rewritten as a single clause.

loop:-write('Type end to end'),read(Word),
write('Input was '),write(Word),nl,
(Word=end;loop).

The 'disjunctive goal' (Word=end;loop) succeeds if variable Word is bound to
the atom end. If not, the system attempts to satisfy the goal loop recursively.

?- loop.

Type end to end: university.

Input was university

Type end to end: of.

Input was of

Type end to end: portsmouth.

Input was portsmouth

Type end to end: end.

Input was end
yes
This recursive program repeatedly prompts the user to enter a term until either
yes or no is entered.

get_answer(Ans):-write('Enter answer to question'),
nl,get_answer2(Ans).
get_answer2(Ans):-
write('answer yes or no'),
read(A),
((valid(A),Ans=A,write('Answer is '),
write(A),nl);get_answer2(Ans)).
valid(yes). valid(no).

?- get_answer(Myanswer).

Enter answer to question

answer yes or no: maybe.

answer yes or no: possibly.

answer yes or no: yes.

Answer is yes

Myanswer = yes

6.2.2 Using the 'repeat' Predicate

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, as shown in the examples below.

get_answer(Ans):-
write('Enter answer to question'),nl,
repeat,write('answer yes or no'),read(Ans),
valid(Ans),write('Answer is '),write(Ans),nl.
valid(yes). valid(no).



The first five goals in the body of get_answer will always succeed. Evaluating
the fifth goal: read(Ans) will prompt the user to enter a term. If the term input is
anything but yes or no, say unsure, the following goal valid(Ans) will fail. Prolog
will then backtrack over read(Ans) and write('answer yes or no'), both of which
are unresatisfiable, i.e. will always fail on backtracking.
Backtracking will then reach the predicate repeat and succeed, causing
evaluation to proceed forward (left-to-right) again, with write('answer yes or no')
and read(Ans) both succeeding, followed by a further evaluation of valid(Ans).
Depending on the value of Ans, i.e. the user's input, the valid(Ans) goal will
either fail, in which case Prolog will backtrack as far as repeat, as before, or it will
succeed in which case the final three goals write('Answer is'), write(Ans) and nl
will all succeed. The overall effect is that the two goals write('answer yes or no')
and read(Ans) are called repeatedly until the terminating condition valid(Ans) is
satisfied, effectively creating a loop between repeat and valid(Ans).

?- get_answer(X).

Enter answer to question

answer yes or no: unsure.

answer yes or no: possibly.

answer yes or no: no.

answer is no

X = no

6.3 Backtracking with Failure

As the name implies, the predicate fail always fails, whether on 'standard'
evaluation left-to-right or on backtracking. Advantage can be taken of this,
combined with Prolog's automatic backtracking, to search through the database to
find all the clauses with a specified property.

6.3.1 Searching the Prolog Database

Supposing the database contains clauses such as

dog(fido).
dog(fred).
dog(jonathan).

Each dog clause can be processed in turn using the alldogs predicate defined
below.

alldogs:-dog(X),write(X),write(' is a dog'),nl,fail.
alldogs.






Calling alldogs will cause dog(X) to be matched with the dog clauses in the
database. Initially X will be bound to fido and 'fido is a dog' will be output. The
final goal in the first clause of the alldogs predicate will then cause evaluation to
fail. Prolog will then backtrack over nl and the two write goals (all of which are
unresatisfiable) until it reaches dog(X). This goal will succeed for a second time
causing X to be bound to fred.
This process will continue until fido, fred and jonathan have all been output,
when evaluation will again fail. This time the call to dog(X) will also fail as there
are no further dog clauses in the database. This will cause the first clause for
alldogs to fail and Prolog to examine the second clause of alldogs. This will
succeed and evaluation will stop.
The effect is to loop through the database finding all possible values of X that
satisfy the goal dog(X).

?- alldogs.

fido is a dog

fred is a dog

jonathan is a dog

yes

Note the importance of the second clause of the alldogs predicate. It is there to
ensure that, after the database has been searched, the goal succeeds. With only the
first line, any call to alldogs will eventually fail.

alldogs:-dog(X),write(X),write(' is a dog'),nl,fail.

?- alldogs.

fido is a dog

fred is a dog

jonathan is a dog

no









6.3.2 Finding Multiple Solutions

Backtracking with failure can also be used to find all the ways of satisfying a goal.
Suppose that a predicate findroute(Town1,Town2,Route) finds a route Route
between two towns Town1 and Town2. The details of this predicate are irrelevant
here. It may be assumed that Town1 and Town2 are atoms and that Route is a list.
Backtracking with failure can then be used to find all possible routes between
Town1 and Town2 and write out each one on a separate line, as follows:

find_all_routes(Town1,Town2):-
findroute(Town1,Town2,Route),
write('Possible route: '),write(Route),nl,fail.
find_all_routes(_,_).

Rabu, 25 November 2009

Jawaban Practical Exercise 5

Soal 1

Langkah pengerjaan :
  1. Buat rule prolog yang memanfaatkan predikat makelower untuk mengatur prolog mengubah huruf kapital menjadi huruf kecil.(Soal1 Rule.jpg)
  2. Tuliskan perintah sesuai rule, kemudian tuliskan kalimat yang terdapat huruf kapital untuk kemudian diubah menjadi huruf kecil.(Soal1 SWI.jpg)
Soal1 Rule.jpg


Soal1 SWI.jpg
Soal 2

Langkah pengerjaan :
  1. Buat dua textfile sebagai input dan output.
  2. Input yang terdiri dari beberapa pernyataan dituliskan ke dalam sebuah textfile bernama input.txt(Soal2 Input.jpg)
  3. Buat rule prolog yang memanfaatkan predikat copyterms untuk mengatur prolog mengkopi isi dari textfile input ke dalam textfile output dan di dalam textfile output masing-masing pernyataan ada pada baris yang berbeda.(Soal2 Rule.jpg)
  4. Tuliskan perintah sesuai rule pada prolog(Soal2 SWI.jpg)
  5. Hasilnya akan keluar pada textfile output(Soal2 Output.jpg)


Soal2 Input.jpg

Soal2 Rule.jpg

Soal2 SWI.jpg

Soal2 Output.jpg
Soal 3

Langkah-langkah pengerjaan :
  1. Buatlah sebuah file bernama testa.txt yang digunakan sebagai input dan tuliskan beberapa karakter di dalamnya.(Soal3 Input.jpg)
  2. Buat rule prolog yang memanfaatkan predikat readfile untuk mengatur prolog membaca masing-masing karakter yang terdapat pada textfile input untuk kemudian dicari nilai ASCII dari masing-masing kareakter tersebut.(Soal2 Rule.jpg)
  3. Tuliskan perintah sesuai rule pada prolog sehingga keluar nilai ASCII dari masing-masing karakter pada input(Soal2 SWI.jpg)
  4. Nilai yang muncul seharusnya seperti berikut :
?- readfile('testa.txt').
97
98
99
100
101
13
10
102
103
104
105
106
13
10
-1
yes

Karena hasil yang keluar pada prolog kami tidak seperti itu, berarti versi prolog yang kami gunakan menggunakan cara yang berbeda dari yang ada prolog yang digunakan dalam E-Book Logic Programming with Prolog dalam merepresentasikan end of file, end of record, atau keduanya

Soal3 Input.jpg

Soal3 Rule.jpg

Soal3 SWI.jpg

Soal 4

Langkah-langkah pengerjaan :
  1. Buat dua textfile untuk input dan satu textfile untuk output.
  2. Isikan beberapa pernyataan yang berbeda pada textfile input dan tuliskan pernyataan end pada baris terakhir.(Soal4 Input1.jpg, Soal4 Input2.jpg)
  3. Buat rule prolog yang memanfaatkan predikat combine untuk menggabungkan pernyataan-pernyataan dari kedua textfile input yang hasil gabungannya akan muncul pada textfile output dan pernyataan end hanya ada pada baris terakhir.(Soal4 Rule.jpg)
  4. Tuliskan perintah sesuai rule yang dibuat.(Soal4 SWI.jpg)
  5. Hasil gabungan akan keluar textfile output.(Soal4 Output.jpg)

Soal4 Input1.jpg

Soal4 Input2.jpg

Soal4 Rule.jpg

Soal4 SWI.jpg

Soal4 Output.jpg

Soal 5

Langkah-langkah pengerjaan :
  1. Buat dua textfile untuk input.
  2. Isikan beberapa pernyataan sembarang boleh sama boleh beda pada textfile input dan tuliskan pernyataan end pada baris terakhir.(Soal5 Input1.jpg, Soal5 Input2.jpg)
  3. Buat rule prolog yang memanfaatkan predikat compare untuk membandingkan pernyataan-pernyataan dari kedua textfile input.(Soal5 Rule.jpg)
  4. Tuliskan perintah sesuai rule yang dibuat dan hasil perbandingan akan keluar.(Soal5 SWI.jpg)

Soal5 Input1.jpg

Soal5 Input2.jpg

Soal5 Rule.jpg

Soal5 SWI.jpg

Selasa, 24 November 2009

Sumary bab 5

Input Output

Chapter Aims

After reading this chapter you should be able to:

• Use the built-in predicates that read from and write to either the user'sterminal (keyboard and screen) or a file, both term by term and characterby-character in your own programs
• Use ASCII values to manipulate strings of characters

Introduction

Prolog has facilities to enable input and output either of terms or of characters.
Using terms is simpler and will be described first. Initially, it will be assumed that
all output is to the user's screen and all input is from the user's keyboard.
5.1 Outputting Terms

The main built-in predicate provided for outputting terms is write/1, which has
already been used many times in this book.
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 meaning of current outpu
stream will be explained in Sections 5.7 and 5.8. At present it can simply be taken
to mean the user's screen.)
5.2 Inputting Terms

In the input stream, the term must be followed by a dot ('.') and at least one
white space character, such as space or newline. The dot and white space
characters are read in but are not considered part of the term.

.


5.3 Input and Output Using Characters

Although input and output of terms is straightforward, the use of quotes and full
stops can be cumbersome and is not always suitable. For example, it would be
tedious to define a predicate (using read) which would read a series of characters
from the keyboard and count the number of vowels. A much better approach for
problems of this kind is to input a character at a time. To do this it is first necessary
to know about the ASCII value of a character.
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.

5.4 Outputting Characters

Characters are output using the built-in predicate put/1. The predicate takes a
single argument, which must be a number from 0 to 255 or an expression that
evaluates to an integer in that range.

5.5 Inputting Characters

Two built-in predicates are provided to input a single character: get0/1 and get/1.
The get0 predicate takes a single argument, which must be a variable. Evaluating a
get0 goal causes a character to be read from the current input stream. The variable
is then unified with the ASCII value of this character.



5.6 Using Characters: Examples

The first example shows how to read in a series of characters from the keyboard
finishing with * and to output their corresponding ASCII values one per line (for
all characters excluding *).
The predicate readin is defined recursively. It causes a single character to be
input and variable X to be bound to its (numerical) ASCII value. The action taken
(the process(X) goal) depends on whether or not X has the value 42 signifying a *

character. If it has, the evaluation of the goal stops. If not, the value of X is output,
followed by a new line, followed by a further call to readin. This process goes on
indefinitely until a * character is read. (In the example below, the ASCII values of
characters P, r, o etc. are correctly shown to be 80, 114, 111 etc.)

5.7 Input and Output Using Files

Prolog takes all input from the current input stream and writes all output to the
current output stream. By default both of these are the stream named user,
denoting the user's terminal, i.e. keyboard for input and screen for output. 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.

5.8 File Output: Changing the Current Output Stream

The current output stream can be changed using the tell/1 predicate. This takes a
single argument, which is an atom or variable representing a file name, e.g.
tell('outfile.txt').
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.



5.9 File Input: Changing the Current Input Stream

The current input stream can be changed using the see/1 predicate. This takes a
single argument, which is an atom or variable representing a file name, e.g.
see('myfile.txt').
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.
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.

5.9.1 Reading from Files: End of File

If the end of file is encountered when evaluating the goal read(X), variable X will
be bound to the atom end_of_file.
If the end of file is encountered while evaluating the goal get(X) or get0(X),
variable X will be bound to a 'special' numerical value. As ASCII values must be in
the range 0 to 255 inclusive, this will typically be -1, but may vary from one
implementation of Prolog to another.

5.9.2 Reading from Files: End of Record

Depending on the version of Prolog used, there may be an incompatibility for
character input between reading the end of a record (i.e. the character(s) that
signify the end of a line) from the user's terminal and from a file.
Typically the end of a line of input at the user's terminal will be indicated by
the character with ASCII value 13. The end of a record in a file will generally be
indicated by two ASCII values: 13 followed by 10.
The following program shows how to read in a series of characters from the
keyboard and print them out, one per line.

Senin, 23 November 2009

Office Voice Recognition Integrated (OVRI)

1.Latar Belakang

Saat ini banyak sekali beredar aplikasi office untuk membantu pekerjaan kantor kita, seperti MS Office, Open Office.org, dll. Banyak fitur yang ditawarkan untuk mempermudah pekerjaan kita seperti fitur ribbon yang ada pada MS Office. Namun, semua itu masih memiliki beberapa kekurangan, di antara lain efisiensi waktu pengetikan. Kita lihat jika kita mengetik membutuhkan waktu yang lama dan sering terjadi salah pengetikan. Untuk mengatasi masalah ini kita mempunyai solusi cerdas.

2.Penjelasan Ide

Kita mempunyai ide untuk membuat aplikasi Office yang berbeda. Aplikasi ini dapat mengenali suara yang kemudian akan diterjemahkan dalam bentuk tulisan pada lembar kerja kita. Oleh karena itu aplikasi ini kita beri nama Office Voice Recognition Integrated (OVRI). Seperti MS Office pada umumnya, OVRI juga menyediakan fitur ribbon yang berguna apabila user ingin mengetikkan sesuatu secara manual. Dengan begitu OVRI memiliki dua cara kerja, yaitu secara otomatis dan manual. Apabila user ingin mengaktifkan mode otomatis, user cukup menambahkan alat seperti microphone, headphone atau sejenisnya yang dapat digunakan untuk merekam lalu user berkomentar di depan microphone tersebut dan kalimat apa yang diucapkan akan ditampilkan pada workspace kita. Aplikasi OVRI ini juga dapat mendeteksi suara pada frekuensi yang tidak begitu tinggi.
Cara kerja OVRI sendiri adalah dengan memilah-milah kata demi kata yang kita ucapkan serta rendering lalu diterjemahkan dalam bentuk tulisan pada workspace kita dengan penginisialisasian suara dan bentuk huruf, angka atau sebagainya lalu dihubungkan satu sama lain yang kesemuanya itu terdapat dalam database aplikasi ini.
Keuntungan dari aplikasi OVRI ini adalah efisiensi waktu pengetikan dan meminimalisir kesalahan pengetikan ketika user terlalu cepat mengetik dan tidak memperhatikan pengejaan tiap katanya. Selain itu, kita juga dapat menghemat tenaga kita yang tidak harus susah-susah mengetik lagi apalagi ketika harus mengetik berlembar-lembar dan terburu-buru oleh deadline.

3.Kesimpulan

Jadi, dengan software ini terintregasi dengan software-software office, software ini akan melakukan efisiensi yang sangat besar. Kita tidak usah lagi capek-capek mengetik atau mengulang lagi jika ada salah ketik. Semuanya akan otomatis terketik jika kita mengucapkan suatu kata pada microphone. Kita harap ide ini akan segera terealisasikan secepetnya karena sangat membantu kita di saat bekerja dengan software office.