our Final project Report ..

download disini ..

FP Report Matdis

Visit Indonesia (Expert System)

Visit Indonesia

Semakin padatnya rutinitas manusia, semakin tinggi tingkat stres yang dialami. Banyak orang-orang yang memanfaatkan objek-objek wisata sebagai sarana refreshing dan untuk melepaskan penat setelah setiap hari bekerja. Dengan expert system ini kami menawarkan beberapa pilihan tempat wisata yang bisa menjadi rujukan saat liburan. Disini kami tidak hanya menunjukkan lokasinya saja, namun juga tentang penilaian masyarakat terhadap objek wisata tersebut, Diharapkan dengan adanya ini, orang-orang tidak salah dalam memilih tempat wisata, sehingga mereka dapat melepaskan stres mereka tanpa rasa kecewa.

1. Ketikkan  seperti pada notepad dibawah ini kemudian save dengan ekstensi “.pl”

2. Kemudian setelah itu compile file-file tersebut dan untuk menjalankannya ketik “find.”

Dan hasilnya akan seperti ini:

Dengan demikian, maka masyarakat dapat mengetahui tempat-tempat wisata di Indonesia dan kondisinya.

LOOPS in Prolog

QUESTION 1

Pertama, deklarasikan isi notepad di bawah. Lalu simpan dengan ekstensi ‘.pl’

Lalu, consultkan file ke PROLOG. Setelah itu, ketik ?- outsquare(3,13). dan enter, hasilnya bisa dilihat dibawah.

QUESTION 2

Pertama, deklarasikan isi notepad di bawah. Lalu simpan dengan ekstensi ‘.pl’

Lalu, consultkan file ke PROLOG. Setelah itu, ketik ?- go. dan enter, lalu ketik terserah anda, saya di sini mengetik “hey” dan hasilnya bisa dilihat dibawah.

QUESTION 3

Pertama, deklarasikan isi notepad di bawah. Lalu simpan dengan ekstensi ‘.pl’

Lalu, consultkan file ke PROLOG. Setelah itu, ketik ?- find. dan enter dan hasilnya bisa dilihat di bawah.

Resume Chapter 6 (LOOPS)

Prolog tidak memiliki fasilitas perulangan, efek yang sama dapat diperoleh yang memungkinkan sesorang urutan tujuan untuk dievaluasi berulang kali. Hal ini dapat dilakukan dalam berbagai
cara, menggunakan backtracking, rekursi, built-in predikat, atau kombinasi dari semuanya.

6.1 Looping a Fixed Number of Times

Banyak bahasa pemrograman menyediakan ‘untuk loop’ yang memungkinkan satu set instruksi
akan dieksekusi tetap beberapa kali. Tidak ada fasilitas tersebut tersedia dalam Prolog
(secara langsung), tetapi efek yang sama dapat diperoleh dengan menggunakan rekursi, seperti ditunjukkan dalam
contoh program di bawah ini.

Contoh 1
Keluaran program berikut bilangan bulat dari nilai tertentu ke 1.

loop(0).

loop(N):-N>0,write(‘The value is: ‘),write(N),nl,

M is N-1,loop(M).

Predikat loop didefinisikan dalam istilah itu sendiri. Kalimat kedua dapat
dianggap sebagai: ‘loop dari N, pertama menulis nilai N, kemudian kurangi satu untuk memberikan
M, kemudian loop dari M ‘. Proses ini jelas harus dihentikan dan ini
dicapai oleh klausa pertama: ‘ketika argumen adalah nol, melakukan apa-apa (dan karenanya
berhenti) ‘. Klausa pertama dapat dianggap sebagai suatu kondisi untuk menghentikan rekursi.

?- 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

Perhatikan penggunaan dua gol M adalah N-1, loop (M) dalam kalimat kedua untuk
loop predikat. Alternatif yang jelas loop (N-1) tidak akan bekerja. Prolog hanya
mengevaluasi pernyataan seperti N-1 ketika mengevaluasi tujuan dengan atau functor adalah salah satu dari
operator relasional, seperti dijelaskan dalam Bab 4. N-1 jika digunakan sebagai argumen
suatu predikat itu diartikan istilah dengan infiks operator – (yaitu tanda minus) dan
argumen N dan 1. Ini sangat tidak mungkin apa yang dimaksudkan!

Contoh 2
Program berikutnya keluaran bilangan bulat dari First to Last inklusif.

/* output integers from First to Last inclusive */

output_values(Last,Last):- write(Last),nl,

write(‘end of example’),nl.

output_values(First,Last):-First=\=Last,write(First),

nl,N is First+1,output_values(N,Last).

output_values memiliki dua argumen, yang dapat dibaca sebagai ‘output
bilangan bulat dari First to Last inklusif ‘. Loop berakhir ketika kedua argumen
sama.

?- output_values(5,12).

56789

10

11

12

end of example

yes

Contoh 3

/* sum the integers from 1 to N (the first argument)

inclusive */

sumto(1,1).

sumto(N,S):-N>1,N1 is N-1,sumto(N1,S1),S is S1+N.

?- sumto(100,N).

N = 5050

?- sumto(1,1).

Yes

Perhatikan bahwa menggunakan N1 variabel tambahan untuk menyimpan nilai N-1 adalah
penting. Menulis sumto (N-1, S1), dll bukannya tidak akan bekerja dengan benar. N-1 adalah
istilah, bukan nilai numerik.

Contoh 4
Tentukan sebuah predikat untuk keluaran kuadrat N pertama bilangan bulat, satu per baris.
Ini dapat diprogram paling mudah jika perombakan pertama dalam bentuk rekursif

/* output the first N squares, one per line */

writesquares(1):-write(1),nl.

writesquares(N):-N>1,N1 is N-1,writesquares(N1),

Nsq is N*N,write(Nsq),nl.

?- writesquares(6).

149

16

25

36

yes

6.2 Looping Until a Condition Is Satisfied
Banyak bahasa memiliki ‘setelah loop’ yang memungkinkan sebuah set instruksi yang akan
dieksekusi berulang kali sampai kondisi tertentu terpenuhi. Sekali lagi, tidak ada fasilitas seperti
tersedia secara langsung di Prolog, tetapi efek yang sama dapat diperoleh dengan beberapa cara.

6.2.1 Recursion
Contoh pertama di bawah ini menunjukkan penggunaan istilah rekursi untuk membaca
dimasukkan oleh
pengguna dari keyboard dan output mereka ke layar, sampai akhir.

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

Program rekursif ini berulang kali mendorong pengguna untuk memasukkan istilah sampai baik
ya atau tidak dimasukkan.

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

Program ini berulang kali mendorong pengguna untuk memasukkan istilah sampai entah ya atau tidak dimasukkan. Ini adalah alternatif dari program rekursif ditampilkan di bagian akhir
bagian sebelumnya. Dalam hal ini masih diperdebatkan apakah menggunakan mengulang adalah
perbaikan menggunakan rekursi, tetapi contoh adalah termasuk untuk tujuan
ilustrasi.

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).

?- 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

Tujuan ke kiri repeat dalam tubuh klausa tidak akan pernah tercapai di backtracking.
Program berikutnya membaca urutan istilah dari file tertentu dan output
mereka ke sungai keluaran sekarang sampai akhir istilah dijumpai.

readterms(Infile):-

seeing(S),see(Infile),

repeat,read(X),write(X),nl,X=end,

seen,see(user).

Program ini menunjukkan bagaimana untuk mengimplementasikan suatu struktur menu yang loop kembali berulang kali untuk meminta lebih banyak masukan. Memasuki pergi pada prompt menyebabkan Prolog untuk output
menu dari mana pengguna dapat memilih satu kegiatan pada satu waktu sampai opsi d adalah
dipilih. Perhatikan bahwa semua input adalah istilah-istilah dan harus diikuti oleh sebuah titik
karakter.

go:- write(‘This shows how a repeated menu works’),

menu.

menu:-nl,write(‘MENU’),nl,

write(‘a. Activity A’),nl,write(‘b. Activity B’),nl,

write(‘c. Activity C’),nl,write(‘d. End’),nl,

read(Choice),nl,choice(Choice).

choice(a):-write(‘Activity A chosen’),menu.

choice(b):-write(‘Activity B chosen’),menu.

choice(c):-write(‘Activity C chosen’),menu.

choice(d):-write(‘Goodbye!’),nl.

choice(_):-write(‘Please try again!’),menu.

?- go.

This shows how a repeated menu works

MENU

a. Activity A

b. Activity B

c. Activity C

d. End

: b.

Activity B chosen

MENU

a. Activity A

b. Activity B

c. Activity C

d. End

: xxx.

Please try again!

MENU

a. Activity A

b. Activity B

c. Activity C

d. End

: d.

Goodbye!

Yes

6.3 Backtracking with Failure
Seperti namanya, predikat gagal selalu gagal, apakah pada ‘standar’
evaluasi kiri-ke-kanan atau pada kemunduran. Keuntungan dapat diambil dari ini,
dikombinasikan dengan otomatis Prolog backtracking, untuk pencarian melalui database untuk
menemukan semua klausa dengan properti tertentu.

6.3.1 Searching the Prolog Database
Misalkan database berisi klausa seperti

dog(fido).

dog(fred).

dog(jonathan).
Setiap dog klausul dapat diproses pada gilirannya menggunakan predikat alldogs didefinisikan
di bawah.

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

Alldogs.

?- alldogs.

fido is a dog

fred is a dog

jonathan is a dog

yes

Catatan pentingnya klausa kedua dari alldogs predikat. Hal ini ada untuk
memastikan bahwa, setelah database telah digeledah, tujuan berhasil. Dengan hanya
baris pertama, setiap panggilan ke alldogs akhirnya akan gagal.

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

Program berikutnya dirancang untuk mencari database yang berisi klausa
mewakili nama, umur, tempat tinggal dan pekerjaan sejumlah
orang-orang.
Jika database berisi lima klausa

person(john,smith,45,london,doctor).

person(martin,williams,33,birmingham,teacher).

person(henry,smith,26,manchester,plumber).

person(jane,wilson,62,london,teacher).

person(mary,smith,29,glasgow,surveyor).

Nama semua guru dapat ditemukan dengan menggunakan allteachers predikat.

allteachers:-person(Forename,Surname,_,_,teacher),

write(Forename),write(‘ ‘),write(Surname),nl,

fail.

Allteachers.

Efek menggunakan backtracking dengan kegagalan dalam kasus ini adalah untuk menemukan semua
guru dalam database

?- allteachers.

martin williams

jane wilson

yes

Jika kedua klausa allteachers dihilangkan, baik guru masih akan
ditemukan tetapi evaluasi allteachers akan berakhir dengan kegagalan. Ini adalah yang sedikit atau
tidak penting ketika tujuan yang dimasukkan pada sistem prompt, tetapi jika allteachers itu
digunakan sebagai tujuan dalam tubuh aturan itu jelas akan mudah untuk dilaksanakan untuk memastikan bahwa
selalu berhasil.
Perlu dicatat bahwa tidak selalu perlu untuk menggunakan ‘backtracking dengan kegagalan ‘untuk mencari database. Sebagai contoh, predikat somepeople / 0 didefinisikan

di bawah ini akan menemukan semua orang dalam database yang diberikan sebelumnya, turun ke williams,
standar hanya menggunakan backtracking

somepeople:-person(Forename,Surname,_,_,_),

write(Forename),write(‘ ‘),write(Surname),nl,

Surname=williams.

Somepeople.

Tujuan Nama Keluarga = williams berhasil jika variabel terikat Nama Keluarga
williams. Jika tidak, itu gagal. Efeknya adalah untuk mencari basis data hingga dan termasuk
orang klausul dengan argumen kedua williams.

?- somepeople.

john smith

martin williams

yes

6.3.2 Finding Multiple Solutions

Backtracking dengan kegagalan juga dapat digunakan untuk mencari semua cara untuk memuaskan tujuan.
Misalkan sebuah predikat findroute (Town1, Town2, Route) menemukan sebuah rute Route
antara dua kota Town1 dan Town2. Rincian predikat ini tidak relevan
di sini. Ini dapat diasumsikan bahwa Town1 dan Town2 adalah atom dan bahwa rute ini adalah daftar.
Backtracking dengan kegagalan kemudian dapat digunakan untuk mencari semua kemungkinan rute antara
Town1 dan Town2 dan menulis masing-masing satu di baris terpisah, sebagai berikut:

find_all_routes(Town1,Town2):-

findroute(Town1,Town2,Route),

write(‘Possible route: ‘),write(Route),nl,fail.

find_all_routes(_,_).

Input dan Output

BAB 5

5.1 OUTPUTTING

predikat built-in utama yang disediakan untuk istilah output write/ 1, yang d gunakan dalam resume ini

write/ 1 predikat mengambil satu argumen, yang harus yang valid dengan syarat prolog.  Evaluasi predikat menyebabkan syarat akan ditulis ke current output stream, , yang secara default adalah layar user.

Built-in predikat nl / 0 juga telah digunakan berkali-kali sebelumnya dalam hal ini

buku. Tanpa membutuhkan argumen. Mengevaluasi sebuah tujuan nl menyebabkan baris baru untuk menjadi output untuk

output stream.

Contoh

? – write(26), nl.

26

ya

? – write( ‘string karakter’), nl.

string karakter

ya

? – write([a, b, c, d, [x, y, z]]), nl.

[a, b, c, d, [x, y, z]]

ya

? – write (mypred (a, b, c)), nl.

mypred (a, b, c)

ya

? – write( ‘Contoh useran nl’), nl, nl, write( ‘akhir contoh’), nl.

Contoh useran nl

contoh akhir

ya

Perhatikan bahwa atom yang harus dikutip pada input (misalnya ‘Paulus’, ‘hello world’) tidak

dikutip ketika output menggunakan menulis. Jika penting untuk output tanda kutip, yang

writeq / 1 predikat dapat digunakan. Hal ini identik dengan write/ 1, kecuali bahwa atom yang

memerlukan tanda kutip untuk input adalah output antara tanda kutip (atom lain tidak).

? – writeq ( ‘string karakter’), nl.

‘string karakter’

ya

?-writeq (anjing), nl.

anjing

ya

? – writeq ( ‘anjing’), nl.

anjing

ya

Input dan Output

5.2 INPUT

Built-in predikat read/ 1 disediakan untuk memasukkan istilah. Dibutuhkan satu argumen,

yang harus menjadi variabel.

Mengevaluasi itu menyebabkan istilah berikutnya untuk dibaca dari input stream,

yang secara default adalah user keyboard.

Dalam input stream, istilah harus diikuti oleh sebuah titik (‘.’) dan setidaknya satu

spasi putih, seperti spasi atau baris baru. Titik dan spasi karakter dibaca dalam tetapi tidak dianggap bagian dari istilah.

Perhatikan bahwa untuk input dari keyboard (hanya) sebuah prompt karakter seperti titik dua

biasanya akan ditampilkan untuk menunjukkan bahwa input user diperlukan. Mungkin perlu

untuk tekan tombol ‘kembali’ tombol sebelum Prolog akan menerima input. Kedua tidak

berlaku untuk input dari file.  Ketika sebuah tujuan membaca dievaluasi, istilah input disatukan dengan argumen variabel. Jika variabel tidak terikat (yang biasanya terjadi) itu adalah terikat pada

input nilai.

? – 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]]

? – Read (Y).

: ‘String karakter’.

Y = ‘string karakter’

Jika variabel argumen sudah terikat , tujuan berhasil jika input istilah identik dengan nilai terikat sebelumnya.

? – X = fred, read (X).

: Jim.

tidak

? – X = fred, read (X).

: Fred.

X = fred

5.3 INPUT dan OUTPUT MENGGUNAKAN KARAKTER

Meskipun input dan output sangat mudah,tapi useran tanda kutip dan titik dapat menjadi rumit dan tidak selalu sesuai. Sebuah pendekatan yang lebih baik untuk  masalah semacam ini adalah untuk input sebuah karakter pada satu waktu. Untuk melakukan hal ini, pertama-tama perlu

untuk mengetahui tentang nilai ASCII karakter.

Semua mencetak karakter dan banyak karakter non-cetak (seperti ruang dan

tab) memiliki sesuai ASCII (American Standard Code for  Information

Interchange) nilai, yang merupakan integer 0-255. Tabel di bawah ini memberikan nilai ASCII numerik yang sesuai

 

9 Tab
10 End of record
32 Space
33 !
34
35 #
36 $
37 %
38 &
39
40 (
41 )
42 *
43 +
44 ,
45
46 .
48-57 0-9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65-90 A to Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97-122 a to z
123 {
124 |
125 }
126 ~

 

 

`

 

 

 

 

 

 

 

 

 

 

 

5.4 OUTPUTTING KARAKTER

Karakter adalah output dengan menggunakan built-in predikat meletakkan / 1. Predikat mengambil

argumen tunggal, yang harus menjadi nomor 0-255 atau ekspresi yang

mengevaluasi ke integer dalam jangkauan.

Mengevaluasi tujuan put menyebabkan satu karakter untuk menjadi output untuk saat ini

output stream. Ini adalah karakter yang sesuai dengan nilai numerik (ASCII

nilai) dari argumen, misalnya

?- put(97),nl.

a

yes

?- put(122),nl.

z

yes

?- put(64),nl.

@

Yes

5.5 INPUT KARAKTER

Dua predikat built-in disediakan untuk memasukkan satu karakter: get0 / 1 da n get/ 1.

Get0 predikat yang mengambil satu argumen, yang harus menjadi variabel. Mengevaluasi

tujuan get0 menyebabkan karakter untuk dibaca dari input saat ini stream. Variabel

kemudian disatukan dengan nilai ASCII karakter ini.

Mengasumsikan argumen variabel tak terikat (yang biasanya akan terjadi), itu

terikat ke nilai ASCII karakter input.

? – Get0 (N).

: A

N = 97

? – Get0 (N).

: Z

N = 90

Logika Pemrograman Dengan 74 Prolog

? – Get0 (M)

)

M = 41

Jika variabel argumen sudah terikat, tujuan berhasil jika dan hanya jika memiliki

nilai numerik yang sama dengan nilai ASCII karakter input.

?- get0(X).

: a

X = 97

?- M is 41,get0(M).

: )

M = 41

?- M=dog,get0(M).

: )

no

?- M=41.001,get0(M).

: )

No

predikat mengambil satu argumen, yang harus menjadi variabel. Mengevaluasi

get berikutnya menyebabkan tujuan non-white-space karakter (yaitu ASCII karakter dengan

nilai kurang dari atau sama dengan 32) untuk dibaca dari input saat ini stream. Itu

variabel ini kemudian disatukan dengan nilai ASCII karakter ini dengan cara yang sama seperti

untuk get0.

?- get(X).

: Z

X = 90

?- get(M).

: Z

M = 90

5.6 MENGGUNAKAN KARKTER :CONTOH

Contoh pertama menunjukkan bagaimana membaca dalam serangkaian karakter dari keyboard

finishing dengan * dan untuk output nilai-nilai ASCII yang berhubungan satu per baris

predikat readin  didefinisikan secara rekursif. Ini menyebabkan satu karakter untuk

input dan variabel X untuk terikat kepada para (numerik) nilai ASCII. Tindakan diambil

(proses (X) tujuan) tergantung pada apakah atau tidak X memiliki nilai 42 berarti a *

karakter. Jika memiliki, evaluasi tujuan berhenti. Jika tidak, nilai dari X adalah output,

diikuti oleh baris baru, diikuti dengan sebuah panggilan ke readin lebih lanjut. Proses ini berlangsung

tanpa batas waktu sampai a * karakter yang dibaca. (Pada contoh di bawah ini, nilai-nilai ASCII

karakter P, r, o dll benar ditunjukkan untuk menjadi sebesar 80, 114, 111 dll)

?- readin.

: Prolog Example*

80

114

111

108

111

103

32

69

120

97

109

112

108

101

Yes

Contoh berikut adalah versi yang diperluas di atas. Kali ini ASCII

nilai-nilai input adalah karakter yang tidak output, tetapi jumlah karakter

(termasuk *) adalah output. Predikat hitungan didefinisikan dengan dua argumen

yang dapat dibaca sebagai ‘jumlah karakter dihitung sejauh ini’ dan ‘jumlah total

karakter sebelum * ‘.

go(Total):-count(0,Total).

count(Oldcount,Result):-

get0(X),process(X,Oldcount,Result).

process(42,Oldcount,Oldcount).

process(X,Oldcount,Result):-

X=\=42,New is Oldcount+1,count(New,Result).

Contoh terakhir adalah program rekursif, yang didasarkan pada dua sebelumnya, yang

menunjukkan bagaimana membaca dalam serangkaian diakhiri dengan karakter * dan menghitung jumlah

vokal. Karakter dibaca dalam satu demi satu sampai sebuah karakter dengan nilai ASCII 42

(menandakan *) adalah dijumpai.

Di sini, dua argumen dari predikat hitungan dapat diartikan sebagai ”

jumlah vokal sejauh ini ‘dan’ jumlah total vokal ‘. Tiga argumen

proses predikat dapat dibaca sebagai “nilai ASCII karakter input ‘,’ yang

jumlah vokal sampai dengan tetapi tidak termasuk karakter ‘dan’ jumlah total

vokal ‘, masing-masing.

Pertama dua argumen dari predikat processChar dapat ditafsirkan dalam

cara yang sama seperti untuk proses, tetapi argumen ketiga adalah “jumlah vokal hingga dan

termasuk karakter (argumen pertama) ‘.

Predikat vokal tes untuk salah satu dari 10 kemungkinan vokal (lima huruf dan

lima huruf kecil), menggunakan nilai-nilai ASCII.

go(Vowels):-count(0,Vowels).

count(Oldvowels,Totvowels):-

get0(X),process(X,Oldvowels,Totvowels).

process(42,Oldvowels,Oldvowels).

process(X,Oldvowels,Totalvowels):-

X=\=42,processChar(X,Oldvowels,New),

count(New,Totalvowels).

processChar(X,Oldvowels,New):-vowel(X),

New is Oldvowels+1.

processChar(X,Oldvowels,Oldvowels).

vowel(65). /* A */

vowel(69). /* E */

vowel(73). /* I */

vowel(79). /* O */

vowel(85). /* U */

vowel(97). /* a */

vowel(101). /* e */

vowel(105). /* i */

Input and Output 77

vowel(111). /* o */

vowel(117). /* u */

?- go(Vowels).

: In the beginning was the word*

Vowels = 8

?- go(Vowels).

: pqrst*

Vowels = 0

5.7 Input and Output Using Files

Prolog mengambil semua input dari input stream dan menulis semua output ke

output stream. Secara default kedua stream ini bernama user,

menunjukkan user terminal, yaitu untuk input keyboard dan layar untuk memperoleh output.

Fasilitas yang sama yang tersedia untuk input dan output dari dan ke user

terminal kedua istilah tersebut dengan istilah atau karakter demi karakter juga tersedia untuk input

dan output dari dan ke file (misalnya file pada hard disk atau CD-ROM).

User dapat membuka dan menutup streaminput dan output yang terkait dengan

jumlah nama file, tapi hanya ada satu streaminput dan satu

stream output pada setiap saat. Perhatikan bahwa tidak ada file bisa terbuka untuk input maupun

output pada waktu yang sama (kecuali user) dan bahwa user input dan output stream

tidak dapat ditutup.

5.8 Output: Mengubah Current Output Stream

Stream output dapat diubah menggunakan tell / 1 predikat. Ini membutuhkan

argumen tunggal, yang merupakan atom atau variabel yang mewakili nama file, misalnya

kirim ( ‘outfile.txt’).

Mengevaluasi sebuah tujuan kirim menyebabkan file bernama untuk menjadi arus output

arus. Jika file belum terbuka, file dengan nama tertentu pertama kali diciptakan

(semua file yang sudah ada dengan nama yang sama akan dihapus).

Perhatikan bahwa file yang sesuai dengan stream output sebelumnya tetap

terbuka ketika arus output baru stream dipilih. Hanya stream output

dapat ditutup (menggunakan predikat kata yang dijelaskan di bawah).

Arus output default stream user, yaitu user terminal. Nilai ini dapat

dikembalikan baik dengan menggunakan kata predikat atau dengan kirim (user).

Built-in predikat tell/ 0 mengambil tanpa argumen. Mengevaluasi sebuah tujuan kepada penyebab

arus output file yang akan ditutup dan arus output stream untuk diatur ulang ke user,

i.e. user.

Built-in predikat tell / 1 memerlukan satu argumen, yang harus menjadi variabel

dan biasanya akan terikat. Mengevaluasi sebuah tujuan memberitahu menyebabkan variabel yang akan

terikat nama output stream.

File 5.9 Input: Mengubah Input Current Stream

Input stream yang aktif dapat diubah dengan menggunakan see/ 1 predikat. Ini membutuhkan

argumen tunggal, yang merupakan atom atau variabel yang mewakili nama file, misalnya

see( ‘myfile.txt’).

Mengevaluasi sebuah tujuan see menyebabkan file bernama input yang menjadi stream.

Jika file ini belum terbuka itu pertama kali dibuka (untuk akses baca saja). Jika tidak

mungkin untuk membuka file dengan nama yang diberikan, kesalahan akan dihasilkan.

Catatan bahwa file yang sesuai dengan arus input yang sebelumnya tetap

terbuka ketika sebuah arus input yang baru dipilih. Hanya arus input

dapat ditutup. Default input stream user, yaitu user. Nilai ini dapat

dipulihkan baik dengan menggunakan dilihat predikat atau dengan see (user).

Built-in predikat see/ 1 memerlukan satu argumen, yang harus menjadi variabel

dan biasanya akan terikat. Mengevaluasi sebuah tujuan see menyebabkan variabel yang akan

terikat nama input stream.

5.9.1 Membaca dari File: End of File

Jika akhir file ditemukan ketika mengevaluasi tujuan read (X), variabel X akan

terikat ke atom end_of_file.

Jika akhir file ditemukan saat mengevaluasi tujuan get(X) atau get0 (X),

variabel X akan terikat kepada seorang ‘khusus’ nilai numerik. Sebagai nilai-nilai ASCII harus dalam

kisaran 0-255 inklusif, ini biasanya akan menjadi -1, tetapi dapat bervariasi dari satu

Prolog pelaksanaan lain.

5.9.2 Membaca dari File: End of Record

Tergantung pada versi Prolog digunakan, mungkin ada ketidakcocokan untuk

karakter input antara membaca akhir sebuah catatan dari terminal user dan dari sebuah file.

Biasanya akhir baris dari input pada terminal user akan ditunjukkan oleh

karakter dengan nilai ASCII 13. Akhir sebuah catatan dalam sebuah file umumnya akan

ditunjukkan oleh dua nilai ASCII: 13 diikuti oleh 10.

Program berikut menunjukkan bagaimana membaca dalam serangkaian karakter dari

keyboard dan mencetak mereka keluar, satu per baris.

Readline:-get0 (X), proses (X).

proses (13).

proses (X):-X = \ = 13, memakai (X), nl, Readline.

Perhatikan useran meletakkan daripada menulis dan bahwa tes untuk nilai ASCII 13

menghindari kebutuhan untuk karakter seperti * untuk menunjukkan ‘akhir input’.

? – Readline.

: Prolog test

Pr

ol

og

t

est

ya

5.10 Menggunakan File: Contoh

Menetapkan predikat readterms membaca empat istilah yang pertama dari file tertentu dan

output mereka untuk file ditentukan lain, satu per baris.

Yang sesuai definisi yang diberikan di bawah ini.

readterms (infile, OUTFILE): —

see (infile), seen (OUTFILE),

read (T1), write (T1), nl, read (T2), write (T2), nl,

read (T3),write (T3), nl, read (T4), write (T4), nl,

seen, told.

Dengan asumsi isi file textfile.txt adalah tiga baris:

‘Istilah pertama’. ‘kedua kalinya’.

‘masa jabatan ketiga’.

‘keempat istilah’. ‘kelima istilah’.

menggunakan readterms memberikan output singkat berikut:

? – Readterms ( ‘textfile.txt’, ‘outfile.txt’).

ya

dan membuat sebuah file dengan empat baris teks

Istilah pertama

jabatan kedua

jabatan ketiga

istilah keempat

Meskipun definisi readterms di atas adalah benar sejauh it goes, akhir

Dua istilah (see dan tell) akan menyebabkan stream input dan output harus ditetapkan

user. Ini dapat menyebabkan masalah jika readterms digunakan sebagai subgoal yang lebih besar

program dimana input dan output streamtidak selalu baik user

ketika dipanggil.

Ini adalah praktek pemrograman yang baik untuk mengembalikan asli input dan output stream

sebagai langkah-langkah akhir ketika tujuan seperti readterms dievaluasi. Hal ini dapat dicapai

untuk input dengan menempatkan tujuan see (S) dan see (S) sebelum dan setelah istilah lainnya

dalam tubuh dari sebuah aturan. Mantan mengikat S untuk nama stream input;

yang terakhir me-reset input stream untuk S.

Dampak yang sama dapat dicapai untuk memperoleh output dengan menempatkan tujuan memberitahu (T) dan

kirim (T) sebelum dan sesudah istilah lain dalam tubuh sebuah aturan. Mantan mengikat T

nama output stream; yang terakhir arus output reset stream untuk

T.

Dengan menggunakan konvensi ini, yang telah direvisi readterms definisi adalah sebagai berikut:

readterms (infile, Output): —

see (S), lihat (infile), mengatakan (T), mengatakan (OUTFILE),

read (T1), write(T1), nl, read (T2), write (T2), nl,

read (T3), write (T3), nl, read (T4), write (T4), nl,

see, see (S), told, tell (T).

 

Practical Exercise 5 (Input & Output)

  1. Ketik perintah seperti pada gambar ini kemudian save dengan nama “matdis.pl”.

Keterangan kode-kode dalam notepad:

  • readline:-get0(P),process(P).

get: berguna untuk mengonvert karakter menjadi kode ASCII

process: berguna untuk memroses argumen yang dinyatakan.

  • Kemudian ketik “case(P,Q):-P>64,P<91 is P+32” dan “case(P,Q):-Q is P+0.” Ini adalah kode-kode untuk menentukan kode bilangan ke huruf kecil.
  • “process(P):-P=\=13,case(P,Q),put(Q),nl,readline.” Bagian ini untuk melakukan proses.
  • Dan kode “nl” adalah perintah untuk ganti baris (berjajar secara vertikal).

Kemudian consult dalam program prolog.

  • Hal ini berarti jika kita menginputkan tulisan “Nisyyah” maka akan dijabarkan vertikal ke bawah.
  • Begitu juga jika mengetikkan kata “Sistem Informasi”. Tampilannya akan seperti ini.

Jadi, kata yang diinputkan akan menjabarkan secara vertikal.

 

2. Ketik seperti contoh dibawah ini kemudian save dengan nama “test1.txt”.

Ketik seperti ini juga namun save dengan nama “test1.pl”

Kemudian jalankan pada program prolog. Dengan mengetikkan seperti ini.

Setelah dijalankan dan keluar yes, maka secara otomatis akan terbentuk output file yang berbentuk (‘.txt’)

3. Ketikkan seperti di bawah ini.

    Kemudian ketik seperti diatas namun dalam file ‘.pl’.

    Kemudian buka program prolog. Dan ketikkan seperti dibawah ini

    4. Ketik dalam notepad seperti ini.

      Dan ketik lagi seperti ini.

      Kemudian ketik seperti ini namun dalam format (.pl).

      Dan jalankan dalam program prolog.

      Dan output akan tersimpan otomatis dalam format ‘.txt’

      5.  Ketikkan seperti ini dalam file (.txt)

        Kemudian ketikkan lagi seperti ini juga dalam format (‘.txt).

        Selanjutnya seperti ini namun dalam format (.pl)

        Selanjutnya jalankan dalam program prolog.

        Rule-Base Expert System

        Expert System

        An expert system is software that attempts to provide an answer to a problem, or clarify uncertainties where normally one or more human experts would need to be consulted. Expert systems are most common in a specific problem domain, and is a traditional application and/or subfield of artifical intelligent. A wide variety of methods can be used to simulate the performance of the expert however common to most or all are 1) the creation of a so-called “knowledgebase” which uses some knowledge representation formalism to capture the Subject Matter Expert’s (SME) knowledge and 2) a process of gathering that knowledge from the SME and codifying it according to the formalism, which is called knowledge engineering. Expert systems may or may not have learning components but a third common element is that once the system is developed it is proven by being placed in the same real world problem solving situation as the human SME, typically as an aid to human workers or a supplement to some information system.

        Expert systems were introduced by Edward Fenginbaum, the first truly successful form of AI software. The topic of expert systems has many points of contact with general system theori, operations research, bussiness process reenginering and various topics in applied mathematics and management science.

        Expert systems topics

        Chaining

        Two methods of reasoning when using inference rules are backward chaining and forward chaining.

        Forward chaining starts with the data available and uses the inference rules to conclude more data until a desired goal is reached. An inference engine using forward chaining searches the inference rules until it finds one in which the if clause is known to be true. It then concludes the then clause and adds this information to its data. It would continue to do this until a goal is reached. Because the data available determines which inference rules are used, this method is also called data driven.

        Backward chaining starts with a list of goals and works backwards to see if there is data which will allow it to conclude any of these goals. An inference engine using backward chaining would search the inference rules until it finds one which has a then clause that matches a desired goal. If the if clause of that inference rule is not known to be true, then it is added to the list of goals. For example, suppose a rule base contains

        1. If Fritz is green then Fritz is a frog.
        2. If Fritz is a frog then Fritz hops.

        Suppose a goal is to conclude that Fritz hops. The rule base would be searched and rule (2) would be selected because its conclusion (the then clause) matches the goal. It is not known that Fritz is a frog, so this “if” statement is added to the goal list. The rule base is again searched and this time rule (1) is selected because its then clause matches the new as certainty factors. A human, when reasoning, does not always conclude things with 100% confidence: he might venture, “If Fritz is green, then he is probably a frog” (after all, he might be a chameleon). This type of reasoning can be imitated by using numeric values called confidences. For example, if it is known that Fritz is green, it might be concluded with 0.85 confidence that he is a frog; or, if it is known that he is a frog, it might be concluded with 0.95 confidence that he hops. These numbers are probabilities in a Bayesian sense, in that they quantify uncertainty.

        Expert system architecture

        The following general points about expert systems and their architecture have been illustrated.

        1. The sequence of steps taken to reach a conclusion is dynamically synthesized with each new case. It is not explicitly programmed when the system is built.
        2. Expert systems can process multiple values for any problem parameter. This permits more than one line of reasoning to be pursued and the results of incomplete (not fully determined) reasoning to be presented.
        3. Problem solving is accomplished by applying specific knowledge rather than specific technique. This is a key idea in expert systems technology. It reflects the belief that human experts do not process their knowledge differently from others, but they do possess different knowledge. With this philosophy, when one finds that their expert system does not produce the desired results, work begins to expand the knowledge base, not to re-program the procedures.

        There are various expert systems in which a rulebase and an inference engine cooperate to simulate the reasoning process that a human expert pursues in analyzing a problem and arriving at a conclusion. In these systems, in order to simulate the human reasoning process, a vast amount of knowledge needed to be stored in the knowledge base. Generally, the knowledge base of such an expert system consisted of a relatively large number of “if then” type of statements that were interrelated in a manner that, in theory at least, resembled the sequence of mental steps that were involved in the human reasoning process.

        Because of the need for large storage capacities and related programs to store the rulebase, most expert systems have, in the past, been run only on large information handling systems. Recently, the storage capacity of personal computers has increased to a point where it is becoming possible to consider running some types of simple expert systems on personal computers.

        In some applications of expert systems, the nature of the application and the amount of stored information necessary to simulate the human reasoning process for that application is just too vast to store in the active memory of a computer. In other applications of expert systems, the nature of the application is such that not all of the information is always needed in the reasoning process. An example of this latter type application would be the use of an expert system to diagnose a data processing system comprising many separate components, some of which are optional. When that type of expert system employs a single integrated rulebase to diagnose the minimum system configuration of the data processing system, much of the rulebase is not required since many of the components which are optional units of the system will not be present in the system. Nevertheless, earlier expert systems require the entire rulebase to be stored since all the rules were, in effect, chained or linked together by the structure of the rulebase.

        When the rulebase is segmented, preferably into contextual segments or units, it is then possible to eliminate portions of the Rulebase containing data or knowledge that is not needed in a particular application. The segmenting of the rulebase also allows the expert system to be run with systems or on systems having much smaller memory capacities than was possible with earlier arrangements since each segment of the rulebase can be paged into and out of the system as needed. The segmenting of the rulebase into contextual segments requires that the expert system manage various intersegment relationships as segments are paged into and out of memory during execution of the program. Since the system permits a rulebase segment to be called and executed at any time during the processing of the first rulebase, provision must be made to store the data that has been accumulated up to that point so that at some time later in the process, when the system returns to the first segment, it can proceed from the last point or rule node that was processed. Also, provision must be made so that data that has been collected by the system up to that point can be passed to the second segment of the rulebase after it has been paged into the system and data collected during the processing of the second segment can be passed to the first segment when the system returns to complete processing that segment.

        The user interface and the procedure interface are two important functions in the information collection process.

        End user

        The end-user usually sees an expert system through an interactive dialog, an example of which follows:

        Q. Do you know which restaurant you want to go to?
        A. No
        Q. Is there any kind of food you would particularly like?
        A. No
        Q. Do you like spicy food?
        A. No
        Q. Do you usually drink wine with meals?
        A. Yes
        Q. When you drink wine, is it French wine?
        A. Yes

        As can be seen from this dialog, the system is leading the user through a set of questions, the purpose of which is to determine a suitable set of restaurants to recommend. This dialog begins with the system asking if the user already knows the restaurant choice (a common feature of expert systems) and immediately illustrates a characteristic of expert systems; users may choose not to respond to any question. In expert systems, dialogs are not pre-planned. There is no fixed control structure. Dialogs are synthesized from the current information and the contents of the knowledge base. Because of this, not being able to supply the answer to a particular question does not stop the consultation.

        Explanation system

        Another major distinction between expert systems and traditional systems is illustrated by the following answer given by the system when the user answers a question with another question, “Why”, as occurred in the above example. The answer is:

        A. I am trying to determine the type of restaurant to suggest. So far Chinese is not a likely choice. It is possible that French is a likely choice. I know that if the diner is a wine drinker, and the preferred wine is French, then there is strong evidence that the restaurant choice should include French.

        It is very difficult to implement a general explanation system (answering questions like “Why” and “How”) in a traditional computer program. An expert system can generate an explanation by retracing the steps of its reasoning. The response of the expert system to the question WHY is an exposure of the underlying knowledge structure. It is a rule; a set of antecedent conditions which, if true, allow the assertion of a consequent. The rule references values, and tests them against various constraints or asserts constraints onto them. This, in fact, is a significant part of the knowledge structure. There are values, which may be associated with some organizing entity. For example, the individual diner is an entity with various attributes (values) including whether they drink wine and the kind of wine. There are also rules, which associate the currently known values of some attributes with assertions that can be made about other attributes. It is the orderly processing of these rules that dictates the dialog itself.

        Expert systems versus problem-solving systems

        The principal distinction between expert systems and traditional problem solving programs is the way in which the problem related expertise is coded. In traditional applications, problem expertise is encoded in both program and data structures. In the expert system approach all of the problem related expertise is encoded in data structures only; no problem-specific information is encoded in the program structure. This organization has several benefits.

        An example may help contrast the traditional problem solving program with the expert system approach. The example is the problem of tax advice. In the traditional approach data structures describe the taxpayer and tax tables, and a program in which there are statements representing an expert tax consultant’s knowledge, such as statements which relate information about the taxpayer to tax table choices. It is this representation of the tax expert’s knowledge that is difficult for the tax expert to understand or modify.

        In the expert system approach, the information about taxpayers and tax computations is again found in data structures, but now the knowledge describing the relationships between them is encoded in data structures as well. The programs of an expert system are independent of the problem domain (taxes) and serve to process the data structures without regard to the nature of the problem area they describe. For example, there are programs to acquire the described data values through user interaction, programs to represent and process special organizations of description, and programs to process the declarations that represent semantic relationships within the problem domain and an algorithm to control the processing sequence and focus.

        The general architecture of an expert system involves two principal components: a problem dependent set of data declarations called the knowledge base or rule base, and a problem independent (although highly data structure dependent) program which is called the inference engine.

        Individuals involved with expert systems

        There are generally three individuals having an interaction with expert systems. Primary among these is the end-user; the individual who uses the system for its problem solving assistance. In the building and maintenance of the system there are two other roles: the problem domain expert who builds and supplies the knowledge base providing the domain expertise, and a knowledge engineer who assists the experts in determining the representation of their knowledge, enters this knowledge into an explanation module and who defines the inference technique required to obtain useful problem solving activity. Usually, the knowledge engineer will represent the problem solving activity in the form of rules which is referred to as a rule-based expert system. When these rules are created from the domain expertise, the knowledge base stores the rules of the expert system.

        Inference rule

        An understanding of the “inference rule” concept is important to understand expert systems. An inference rule is a statement that has two parts, an if clause and a then clause. This rule is what gives expert systems the ability to find solutions to diagnostic and prescriptive problems. An example of an inference rule is:

        If the restaurant choice includes French, and the occasion is romantic,
        Then the restaurant choice is definitely Paul Bocuse.

        An expert system’s rulebase is made up of many such inference rules. They are entered as separate rules and it is the inference engine that uses them together to draw conclusions. Because each rule is a unit, rules may be deleted or added without affecting other rules (though it should affect which conclusions are reached). One advantage of inference rules over traditional programming is that inference rules use reasoning which more closely resemble human reasoning.

        Thus, when a conclusion is drawn, it is possible to understand how this conclusion was reached. Furthermore, because the expert system uses knowledge in a form similar to the expert, it may be easier to retrieve this information from the expert.

        Procedure node interface

        The function of the procedure node interface is to receive information from the procedures coordinator and create the appropriate procedure call. The ability to call a procedure and receive information from that procedure can be viewed as simply a generalization of input from the external world. While in some earlier expert systems external information has been obtained, that information was obtained only in a predetermined manner so only certain information could actually be acquired. This expert system, disclosed in the cross-referenced application, through the knowledge base, is permitted to invoke any procedure allowed on its host system. This makes the expert system useful in a much wider class of knowledge domains than if it had no external access or only limited external access.

        In the area of machine diagnostics using expert systems, particularly self-diagnostic applications, it is not possible to conclude the current state of “health” of a machine without some information. The best source of information is the machine itself, for it contains much detailed information that could not reasonably be provided by the operator.

        The knowledge that is represented in the system appears in the rulebase. In the rulebase described in the cross-referenced applications, there are basically four different types of objects, with associated information present.

        1. Classes—these are questions asked to the user.
        2. Parameters—a parameter is a place holder for a character string which may be a variable that can be inserted into a class question at the point in the question where the parameter is positioned.
        3. Procedures—these are definitions of calls to external procedures.
        4. Rule Nodes—The inferencing in the system is done by a tree structure which indicates the rules or logic which mimics human reasoning. The nodes of these trees are called rule nodes. There are several different types of rule nodes.

        The rulebase comprises a forest of many trees. The top node of the tree is called the goal node, in that it contains the conclusion. Each tree in the forest has a different goal node. The leaves of the tree are also referred to as rule nodes, or one of the types of rule nodes. A leaf may be an evidence node, an external node, or a reference node.

        An evidence node functions to obtain information from the operator by asking a specific question. In responding to a question presented by an evidence node, the operator is generally instructed to answer “yes” or “no” represented by numeric values 1 and 0 or provide a value of between 0 and 1, represented by a “maybe.”

        Questions which require a response from the operator other than yes or no or a value between 0 and 1 are handled in a different manner.

        A leaf that is an external node indicates that data will be used which was obtained from a procedure call.

        A reference node functions to refer to another tree or subtree.

        A tree may also contain intermediate or minor nodes between the goal node and the leaf node. An intermediate node can represent logical operations like And or Or.

        The inference logic has two functions. It selects a tree to trace and then it traces that tree. Once a tree has been selected, that tree is traced, depth-first, left to right.

        The word “tracing” refers to the action the system takes as it traverses the tree, asking classes (questions), calling procedures, and calculating confidences as it proceeds.

        As explained in the cross-referenced applications, the selection of a tree depends on the ordering of the trees. The original ordering of the trees is the order in which they appear in the rulebase. This order can be changed, however, by assigning an evidence node an attribute “initial” which is described in detail in these applications. The first action taken is to obtain values for all evidence nodes which have been assigned an “initial” attribute. Using only the answers to these initial evidences, the rules are ordered so that the most likely to succeed is evaluated first. The trees can be further re-ordered since they are constantly being updated as a selected tree is being traced.

        It has been found that the type of information that is solicited by the system from the user by means of questions or classes should be tailored to the level of knowledge of the user. In many applications, the group of prospective uses is nicely defined and the knowledge level can be estimated so that the questions can be presented at a level which corresponds generally to the average user. However, in other applications, knowledge of the specific domain of the expert system might vary considerably among the group of prospective users.

        One application where this is particularly true involves the use of an expert system, operating in a self-diagnostic mode on a personal computer to assist the operator of the personal computer to diagnose the cause of a fault or error in either the hardware or software. In general, asking the operator for information is the most straightforward way for the expert system to gather information assuming, of course, that the information is or should be within the operator’s understanding. For example, in diagnosing a personal computer, the expert system must know the major functional components of the system. It could ask the operator, for instance, if the display is a monochrome or color display. The operator should, in all probability, be able to provide the correct answer 100% of the time. The expert system could, on the other hand, cause a test unit to be run to determine the type of display. The accuracy of the data collected by either approach in this instance probably would not be that different so the knowledge engineer could employ either approach without affecting the accuracy of the diagnosis. However, in many instances, because of the nature of the information being solicited, it is better to obtain the information from the system rather than asking the operator, because the accuracy of the data supplied by the operator is so low that the system could not effectively process it to a meaningful conclusion.

        In many situations the information is already in the system, in a form of which permits the correct answer to a question to be obtained through a process of inductive or deductive reasoning. The data previously collected by the system could be answers provided by the user to less complex questions that were asked for a different reason or results returned from test units that were previously run.

        User interface

        The function of the user interface is to present questions and information to the user and supply the user’s responses to the inference engine.

        Any values entered by the user must be received and interpreted by the user interface. Some responses are restricted to a set of possible legal answers, others are not. The user interface checks all responses to insure that they are of the correct data type. Any responses that are restricted to a legal set of answers are compared against these legal answers. Whenever the user enters an illegal answer, the user interface informs the user that his answer was invalid and prompts him to correct it.

        Application of expert systems

        Expert systems are designed and created to facilitate tasks in the fields of accounting, medicine, process control, financial service, production, human resources etc. Indeed, the foundation of a successful expert system depends on a series of technical procedures and development that may be designed by certain technicians and related experts.

        A good example of application of expert systems in banking area is expert systems for mortgages. Loan departments are interested in expert systems for mortgages because of the growing cost of labour which makes the handling and acceptance of relatively small loans less profitable. They also see in the application of expert systems a possibility for standardised, efficient handling of mortgage loan, and appreciate that for the acceptance of mortgages there are hard and fast rules which do not always exist with other types of loans.

        While expert systems have distinguished themselves in AI research in finding practical application, their application has been limited. Expert systems are notoriously narrow in their domain of knowledge—as an amusing example, a researcher used the “skin disease” expert system to diagnose his rustbucket car as likely to have developed measles—and the systems were thus prone to making errors that humans would easily spot. Additionally, once some of the mystique had worn off, most programmers realized that simple expert systems were essentially just slightly more elaborate versions of the decision logic they had already been using. Therefore, some of the techniques of expert systems can now be found in most complex programs without any fuss about them.

        An example, and a good demonstration of the limitations of, an expert system used by many people is the Microsoft Windows operating system troubleshooting software located in the “help” section in the taskbar menu. Obtaining expert/technical operating system support is often difficult for individuals not closely involved with the development of the operating system. Microsoft has designed their expert system to provide solutions, advice, and suggestions to common errors encountered throughout using the operating systems.

        Another 1970s and 1980s application of expert systems — which we today would simply call AI — was in computer games. For example, the computer baseball games Earl Weaver Baseball and Tony La Russa Baseball each had highly detailed simulations of the game strategies of those two baseball managers. When a human played the game against the computer, the computer queried the Earl Weaver or Tony La Russa Expert System for a decision on what strategy to follow. Even those choices where some randomness was part of the natural system (such as when to throw a surprise pitch-out to try to trick a runner trying to steal a base) were decided based on probabilities supplied by Weaver or La Russa. Today we would simply say that “the game’s AI provided the opposing manager’s strategy.”

        Advantages and disadvantages

        Advantages:

        • Provides consistent answers for repetitive decisions, processes and tasks
        • Holds and maintains significant levels of information
        • Encourages organizations to clarify the logic of their decision-making
        • Always asks a question, that a human might forget to ask
        • Can work continuously (no human needs)
        • Can be used by the user more frequently
        • A multi-user expert system can serve more users at a time

        Disadvantages:

        • Lacks common sense needed in some decision making
        • Cannot respond creatively like a human expert would in unusual circumstances
        • Domain experts not always able to explain their logic and reasoning
        • Errors may occur in the knowledge base, and lead to wrong decisions
        • Cannot adapt to changing environments, unless knowledge base is changed

        Types of problems solved by expert systems

        Expert systems are most valuable to organizations that have a high-level of know-how experience and expertise that cannot be easily transferred to other members. They are designed to carry the intelligence and information found in the intellect of experts and provide this knowledge to other members of the organization for problem-solving purposes.

        Typically, the problems to be solved are of the sort that would normally be tackled by a medical or other professional. Real experts in the problem domain (which will typically be very narrow, for instance “diagnosing skin conditions in human teenagers”) are asked to provide “rules of thumb” on how they evaluate the problems, either explicitly with the aid of experienced systems developers, or sometimes implicitly, by getting such experts to evaluate test cases and using computer programs to examine the test data and (in a strictly limited manner) derive rules from that. Generally, expert systems are used for problems for which there is no single “correct” solution which can be encoded in a conventional algorithm — one would not write an expert system to find shortest paths through graphs, or sort data, as there are simply easier ways to do these tasks.

        Simple systems use simple true/false logic to evaluate data. More sophisticated systems are capable of performing at least some evaluation, taking into account real-world uncertainties, using such methods as fuzzy logic. Such sophistication is difficult to develop and still highly imperfect.

        Expert Systems Shells or Inference Engine

        A shell is a complete development environment for building and maintaining knowledge-based applications. It provides a step-by-step methodology, and ideally a user-friendly interface such as a graphical interface, for a knowledge engineer that allows the domain experts themselves to be directly involved in structuring and encoding the knowledge. Many commercial shells are available, one example being eGanges which aims to remove the need for a knowledge engineer.

        Expert System

        “EASY MUSIC”

        Latar belakang.
        Seiring dengan berkembangnya industri musik baik di Indonesia maupun luar negeri, semakin banyak masyarakat khususnya dikalangan anak muda yang ingin mengekspresikan diri mereka dengan bermain musik. Namun, untuk pemula biasanya mereka dihadapkan pada sulitnya menentukan nada maupun chord yang ada pada sebuah lagu. Mulai menentukan letak Do hingga menentukan ketukan. Untuk itu, kami mencoba untuk membantu memecahkan masalah tersebut dengan expert system yang kami beri nama “Easy Music”. Dan diharapkan dengan adanya ini, tidak hanya anak muda yang dapat menikmatinya namun juga orang dewasa yang ingin belajar musik.

        Penjelasan.
        Easy Music ini dirancang sedemikian rupa untuk memudahkan user. Untuk menjalankan expert system ini, seorang user cukup menginput sebuah lagu yang mereka inginkan untuk diproses, tentunya dalam format tertentu (mp3). Kemudian expert system akan bekerja untuk menentukan nada-nada yang ada pada sebuah lagu tersebut. Pada output akan ditampilkan letak Do(yang merupakan dasar penentuan nada dalam sebuah lagu), jumlah ketukan dan chord-chord yang ada. Selain itu pada expert system ini juga menyediakan pilihan untuk memilih chord-chord tersebut ditampilkan dalam format alat musik tertentu. Misalnya, seorang user menginginkan output dalam bentuk chord gitar, bisa juga untuk menampilkan dalam bentuk chord piano, dll.

        Manfaat.
        Melihat semangat anak muda yg selalu ingin berkarya di bidang musik, kami mempersembahkan “Easy Music” sebagai salah satu media untuk membantu para generasi muda yg ingin berkarya. Dengan adanya “Easy Music” ini, mereka tidak perlu susah-susah untuk mencari chord, ketukan, atau informasi lainnya melalui searching di internet atau mencari di buku-buku musik. Cukup dengan membuka aplikasi ini,maka hal yg ingin diketahui dapat terjawab dengan cepat.

        OPERATORS AND ARITMETICS (Summary of Chapter 4)

        4. Operator dan Aritmatika.

        4.1. Operator

        Sering ditemui kesulitan untuk membaca penulisan standar prolog.  Oleh karena itu, ada cara lain untuk menuliskan predikat.Seperti pada binary predicate, yang dapat diubah menjadi infix operator.

        Contoh penulisan standar ada pada,

        likes(oppy,yellow).


        Selain itu bisa juga ditulis menurut binary predicate ,

        oppy likes yellow.

        Untuk predikate yang hanya mempunyai satu argumen atau yang disebut unary predicate dapat diubah menjadi postfix operator. Predikat dapat dituliskan sebelum argumen tanpa tanda kurung.

        notasi operator juga dapat digunakan untuk mempermudah membaca sebuah statement.

        likes(sasa,X):- is_male(X), owns(X,Y), is_taft(Y).


        akan lebih mudah untuk dibaca jika penulisannya sebagai berikut,

        sasa likes X:-X is male, X owns Y, Y is taft.

        Standar tanda kurung ‘functor dan argumen’ notasi, misalnya likes (sasa,X) dapat
        masih dapat digunakan dengan operator jika lebih disukai. ‘Mixed’ notasi juga diperbolehkan

        Setiap predikat yang ditetapkan pengguna dengan satu atau dua argumen dapat dikonversi ke
        operator dengan memasukkan tujuan menggunakan op predikat pada sistem prompt. Ini
        membutuhkan 3 argumen, misalnya
        ?-op(150,xfy,likes).
        Argumen pertama adalah ‘operator didahulukan’, yang merupakan integer dari 0 ke atas.
        Nilai didahulukan operator digunakan untuk menentukan urutan dari operator akan diterapkan bila lebih dari satu digunakan dalam istilah.
        Argumen kedua biasanya harus salah satu dari tiga bentuk berikut:
        xfy berarti bahwa binary predicates dan akan dikonversikan ke operator infiks
        fy berarti bahwa unary predicates dan akan dikonversikan ke operator prefix
        xf berarti bahwa predikat adalah unary dan akan dikonversi ke postfix operator
        Argumen ketiga menentukan nama predikat yang harus dikonversi ke
        operator.
        Sebuah predikat juga dapat dikonversi ke operator dengan menempatkan sebuah baris seperti
        ?-op (150, xfy, likes).
        4.2. Arithmetics.
        Tidak hanya dapat digunakan pada non numerik, prolog juga bisa melakukan hitungan aritmatik.
        Hal ini dicapai dengan menggunakan built-in predikat adalah / 2, yang telah ditetapkan sebagai infiks
        operator dan dengan demikian ditulis antara dua argumen.
        Cara yang paling umum adalah menggunakan / 2 adalah dimana argumen pertama adalah terikat
        variabel. Mengevaluasi tujuan X -6,5 akan menyebabkan X untuk terikat dengan jumlah -6,5
        dan tujuan untuk sukses.
        Argumen kedua dapat berupa nomor atau ekspresi aritmatika misalnya
        X adalah 6 * Y + Z-3.2 + P-Q / 4 (* menandakan perkalian).
        Setiap variabel yang muncul dalam sebuah ekspresi aritmatika sudah harus terikat (sebagai
        mengevaluasi hasil dari tujuan sebelumnya) dan nilai-nilai mereka harus numerik.
        tujuan akan selalu berhasil dan variabel yang membentuk pertama
        argumen akan terikat dengan nilai ekspresi aritmetik. Jika tidak, kesalahan
        pesan akan muncul.
        ? – X 10,5 4,7 * 2.
        X = 19,9
        ? – Y adalah 10, Z adalah Y 1.
        Y = 10,
        Z = 11
        Simbol seperti + – * / dalam ekspresi aritmatika adalah jenis khusus infiks
        operator yang dikenal sebagai operator aritmetika. Tidak seperti operator digunakan di tempat lain di Prolog
        mereka tidak predikat tetapi fungsi yang mengembalikan nilai numerik.
        Seperti halnya angka-angka, variabel dan operator, ekspresi aritmatika dapat mencakup
        fungsi aritmatika, ditulis dengan argumen mereka dalam tanda kurung (yaitu bukan sebagai
        operator). Seperti operator aritmetika ini kembali nilai-nilai numerik, misalnya menemukan
        akar kuadrat dari 36:
        ? – X adalah sqrt (36).
        X = 6
        Operator aritmetik – dapat digunakan tidak hanya sebagai operator infiks biner
        menunjukkan perbedaan dua nilai numerik, misalnya X-6, tetapi juga sebagai awalan unary
        operator untuk menunjukkan negatif dari sebuah nilai numerik, misalnya
        ? – X adalah 10, Y-X-2.
        X = 10,
        Y = -12
        Tabel di bawah menunjukkan beberapa operator dan aritmatika aritmetika
        fungsi yang tersedia dalam Prolog.
        X + Y       jumlah X dan Y
        X-Y          selisih dari X dan Y
        X * Y       hasil kali X dan Y
        X / Y       hasil bagi X dan Y
        X / / Y    ‘integer hasil bagi’ dari X dan Y (hasilnya adalah dipotong ke terdekat integer antara itu dan nol)
        X ^ Y       pangkat
        -X              negatif X
        abs (X)     nilai absolut X
        sin (X)      sinus X (untuk X diukur dalam derajat)
        cos (X)     kosinus X (untuk X diukur dalam derajat)
        max (X, Y) yang lebih besar dari X dan Y
        sqrt (X)    akar kuadrat X
        4.3.Equality Operator
        Kesetaraan Operator
        Ada tiga jenis operator relasional untuk pengujian kesetaraan dan ketidaksetaraan tersedia dalam Prolog.
        Satu untuk mengecek membandingkan nilai ekspresi aritmatika, dan dua lainnya digunakan untuk membandingkan istilah.
        Arithmetic Expression Equality =:=
        E1 =: = E2 berhasil jika ekspresi aritmetika mengevaluasi E1 dan E2 yang sama
        nilai.
        ? – 6 +4 =: = 6 * 3-8.
        yes
        ? – Sqrt (36) +4 =: = 5 * 11-45.
        yes
        Untuk memeriksa apakah suatu bilangan bulat ganjil atau bahkan kita dapat menggunakan checkeven / 1 predikat
        didefinisikan di bawah ini.
        checkeven (N):-M adalah N / / 2, N =: = 2 * M.
        ? – Checkeven (12).
        yes
        ? – Checkeven (23).
        no
        ? – Checkeven (-11).
        no
        ? – Checkeven (-30).
        yes
        Integer hasil bagi para operator / / membagi argumen pertama dengan kedua dan
        memotong hasilnya ke integer terdekat antara itu dan nol. Jadi 12 / / 2 adalah 6, 23 / / 2 adalah
        11, -11 / / 2 adalah -5 dan -30 / / 2 adalah -15. Membagi sebuah integer dengan 2 menggunakan / / dan mengalikan
        itu dengan 2 lagi akan memberikan bilangan asli jika bahkan, tetapi tidak sebaliknya.
        Ekspresi aritmatika Ketidaksetaraan = \ =
        E1 = \ = E2 berhasil jika ekspresi aritmetika E1 dan E2 tidak mengevaluasi ke
        nilai sama
        ? – 10 = \ = 8 3.
        yes
        Terms Identical ==
        Kedua argumen dari operator == infiks harus istilah. Tujuan Term1 == Term2
        berhasil jika dan hanya jika Term1 identik dengan Term2. Setiap variabel yang digunakan dalam istilah mungkin atau mungkin tidak sudah terikat, tetapi tidak ada variabel terikat sebagai akibat dari mengevaluasi tujuan.
        ? – likes (X, Prolog) == likes(X, Prolog).
        X = _
        ? – likes (X, Prolog) == likes (Y, Prolog).
        no
        (X dan Y adalah variabel yang berbeda)
        ? – X adalah 10, pred1 (X) == pred1 (10).
        X = 10
        ? – X == 0.
        tidak
        ? – 6 4 == 3 +7.
        no

        4.4 Logical Operator
        Bagian ini memberikan gambaran singkat dari dua operator yang mengambil argumen yang panggilan istilah, yaitu istilah yang dapat dianggap sebagai tujuan.
        Prefix operator bukan / 1 dapat ditempatkan sebelum tujuan untuk memberikan yang pengingkaran. Itu
        tujuan menegasikan berhasil jika tujuan asli gagal dan gagal jika tujuan asli
        berhasil.
        Contoh berikut menggambarkan penggunaan tidak / 1. Diasumsikan bahwa
        database berisi satu klausul
        dog (fido).
        ? – not dog (fido).
        no
        ? – dog (fred).
        yes
        ? -not dog (fred).
        yes
        ? – X = 0, X adalah 0.
        X = 0
        ? – X = 0, bukan X adalah 0.
        no
        The pemisahan Operator
        The pemisahan operator; / 2 (ditulis sebagai karakter titik koma) digunakan untuk mewakili
        ‘atau’. Ini adalah infiks operator yang membutuhkan dua argumen, yang keduanya adalah tujuan.
        Tujuan1; Tujuan2 berhasil jika salah Tujuan1 atau Tujuan2 berhasil.
        ? – 6 <3; 7 adalah 5 +2.
        yes

        ? – 6 * 6 =: = 36; 10 = 8 3.
        yes






        OPERATOR AND ARITHMETIC

        Practical Exercise 4.

        I. Pada soal nomor 1 kita diperintah untuk mengonvert predikat menggunakan operator form seperti yang ada pada contoh. Dan hasilnya harus sama dengan program yang ada pada contoh.

        Jadi yang kita lakukan adalah:

        1.Ubah program awal(yang ada pada soal) dengan standar operator form.

        Yang awalnya seperti ini:

        1

         

         

         

         

         

         

         

         

         

        Menjadi seperti ini:

        2

         

         

         

         

         

         

         

         

         

        2.Kemudian simpan hasil yang telah diubah dengan format .pl. Misalnya: prolog anjing.pl. Agar bisa di consult pada program prolog.

        Jangan lupa untuk mengganti save as type menjadi All files.

        3

         

         

         

         

         

        3. Setelah menyimpan file tersebut, maka buka program prolog. Klik file –> consult

        4

         

         

         

         

         

         

         

         

        4. Kemudian pilih file ‘prolog anjing.pl’.

        5

         

         

         

         

         

         

         

         

         

         

        5. Setelah itu akan keluar tampilan seperti ini.

        6

         

         

         

         

         

         

         

         

         

        6. Kemudian ketikan X chases Y. Seperti tampilan berikut ini:

        7

         

         

         

         

         

         

         

         

         

        7. Selanjutnya tekan “enter”.

        8

         

         

         

         

         

         

         

         

         

        8. Untuk menampilkan selanjutnya tekan “;”. Hingga muncul tulisan “no”.

        9

         

         

         

         

         

         

         

         

         

        9. Jika dibandingkan dengan program yang ada pada soal,hasil keluarannya akan sama yaitu seperti ini:

        a. Program seperti yang ada pada contoh soal.

        10

         

         

         

         

         

         

         

         

         

        b. Program yang telah diubah berdasarkan operator form.

        11

         

         

         

         

         

         

         

         

         

        10. Terbukti sama program yang seperti pada soal dengan yang telah diubah berdasarkan operator form.

        II. Pada soal nomor 2, kita diperintah untuk membuat operator hitungan.

        1. Melakukan hitungan rata-rata dari 2 buah bilangan.

        Misal: X=30

        Y=42

        Maka kita mencari Z dengan rumus rata-rata yaitu (X+Y)/2

        Dan hasilnya setelah ditekan enter adalah

        2.0

         

         

         

         

         

         

         

         

         

        2. Selanjutnya adalah menghitung akar dari hasil rata-rata tersebut.

        22

         

         

         

         

         

         

         

         

         

        3. Kemudian yang terakhir adalah menentukan hasil yang paling besar dari 2 perhitungan sebelumnya.

        23