Final Project
Greetings 😀
This is our final project about Expert Systems. You can download by click the link below. Don’t worry, it’s spam free 😀
Prolog : Events Guide
/*******************************************************
Events Guide
* specialEvent(Name, Place, Month, Start-Date, *
*Â Â Â Â Â Â Â Â Â Â Â Â Â Â Finish-Date, Classification, Genre)Â Â Â Â Â *
*******************************************************/
specialEvent(scomdex-pameran-komputer, surabaya-expo, 11, 2, 7, family, computer).
specialEvent(surabaya-sale, tunjungan-plaza, 11, 9, 21, family, shopping).
specialEvent(surabaya-book-fair, surabaya-expo, 11, 16, 29, student, music).
specialEvent(kids-carnaval, tugu-pahlawan, 11, 29, 29, children, art).
specialEvent(music-concert, tunjungan-plaza, 12, 1, 3, adolescent, music).
specialEvent(food-festival, pakuwon-city, -1, -1, -1, family, restaurant).
specialEvent(music-by-request, surabaya-radio, -1, -1, -1, adolescent, music).
specialEvent(education-expo,surabaya-expo, 12, 7, 12, family ,education).
specialEvent(surabaya-real-estate-expo, pakuwon-city, 12, 1, 31, adult, property).
foodAvailableAt(kids-carnaval, cheap).
foodAvailableAt(surabaya-book-fair, medium).
foodAvailableAt(surabaya-real-estate-expo, expensive).
foodAvailableAt(education-expo, medium).
foodAvailableAt(food-festival, cheap).
foodAvailableAt(music-concert, medium).
foodAvailableAt(music-by-request, medium).
distance(surabaya-expo, tunjungan-plaza, 5).
distance(surabaya-expo, tugu-pahlawan, 7).
distance(surabaya-expo, pakuwon-city, 12).
distance(surabaya-expo, surabaya-radio, 8).
distance(tunjungan-plaza, tugu-pahlawan, 4).
distance(tunjungan-plaza, pakuwon-city, 12).
distance(tunjungan-plaza, surabaya-radio, 3).
distance(tugu-pahlawan,pakuwon-city,10).
distance(tugu-pahlawan, surabaya-radio, 5).
distance(pakuwon-city, surabaya-radio, 8).
/*************************************
* U T I L I T YÂ Â F U N C T I O N S *
*************************************/
near(X,Y) :- X = Y ;Â (distance(X,Y,D), D =< 5) ; (distance(Y,X,D), D =< 5).
getDates(E,M,Ds,De)Â :- specialEvent(E,_,M,Ds,De,_,_).
allYearEvent(E)Â Â Â Â Â :- specialEvent(E,_,-1,-1,-1,_,_).
suitableForKids(E)Â Â :- specialEvent(E,_,_,_,_,family,_).
/*************************************
* E N D U S E RÂ Â F U N C T I O N S *
*************************************/
getEvents(E,P,C,G)Â Â Â :- specialEvent(E,P,_,_,_,C,G).
partyEvents(E,M,D,P) :- getEvent(E,Ep,family,G),
near(P,Ep),
G \= shopping,
getDates(E,Em,Ds,De),
(allYearEvent(E) ; (Ds =< D, De >= D, Em =:= M)).
nearEvents(E,P)Â Â Â Â Â :- near(P,X), getEvent(E,X,_,_).
foodAvailable(E,T)Â Â :- foodAvailableAt(E,T) ;
(getEvent(E,_,T,G), G = restaurant).
/*************************************
* E X A M P L EÂ Â Q U E R I E S *
*************************************/
Here are some examples of how you would use the program:
* Is there anything suitable for a party for someone whose birthday is on the 1st October in or near Surabay Expo.
? partyEvents(X,11,1,surabaya-expo).
* Is there food available at the music-concert, if so how expensive is it?
? foodAvailable(music-concert, P).
* List all events in or near tunjungan-plaza.
? nearEvents(E, tunjungan-plaza).
* Get all adult events in pakuwon-city
?getEvents(E, pakuwon-city,adult,_).
*/
Loops (Exercise 3)
Greetings!
Now we meet again for the exercise 3. After exercise 2, we are really sure that you guys can solve this problem easily
So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy
Exercise 3
Using the person clauses given, find the professions of all those over 40..
The person clause is :
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).
Answer :
To find the profession is quite easy 😀 just look at the source code below :
find_prof:-person(_,_,Age,_,Prof),Age>40,
write(‘The proffesion above age 40 is ‘),write(Prof),nl,fail.
find_prof.
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). Read the rest of this entry »
Loops (Exercise 2)
Greetings!
Now we meet again for the exercise 2. After exercise 1, we are really sure that you guys can solve this problem easily
So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy
Exercise 2
Define and test a predicate to read in a series of characters input by the user and output all of those before the first new line or ? character.
Answer :
Well, first of all we have to make the rule for Prolog program. The source code will be like this :
go:-repeat,get0(X),stop(X).
stop(13):-nl.
stop(63):-nl,repeat,get0(X),X=:=13.
stop(X):-put(X),fail. Read the rest of this entry »
Loops (Exercise 1)
Greetings!
Now we meet again for the fifth tutorial now after you learned about Loops in our Literature Review, it is the time to implement your thoughts to Prolog Program
So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy
Excercise 1
Define a predicate to output the values of the squares of the integers from N1 to N2 inclusive and test it with N1 = 6 and N2 = 12.
Answer :
We can find a squared integer from the first input number until the last input number.
Here is the source code :
output_square(N1,N2):-N1>N2.
output_square(N1,N2):- write(N1),write(‘ square is ‘),Square is N1*N1,
write(Square),nl,M is N1+1,output_square(M,N2). Read the rest of this entry »
Loops
Greetings !
Now we have entered our third Literature Review. This time we will discuss about Loops in Prolog. So take your time and enjoy the review 😀
LOOPS
6.1 Lopping a Fixed Number of Times
Many programming languages provide ‘for loops’ which enable a set of instructions to be executed a fixed number of times. No such facility is available in Prolog (directly), but a similar effect can be obtained using recursion, as shown in the example programs below.
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
Input and Output in Prolog (Exercise 2)
Greetings!
Now we meet again for the exercise 2. After exercise 1, we are really sure that you guys can solve this problem easily 😀
So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy
Exercise 2
Define a predicate copyterms which reads all the terms in a text file and outputs them as terms to another text file one by one on separate lines. The output file should be in a format suitable for use as the input file in a subsequent call of copyterms. Thus for example if the input file contained
‘first term’. ‘second term’.
‘third term’.
fourth. ‘fifth term’.
sixth.
The output file would contain
‘first term’.
‘second term’.
‘third term’.
fourth.
‘fifth term’.
sixth. Read the rest of this entry »
Input and Output (Exercise 1)
Greetings!
Now we meet again for the fourth tutorial now after you learned about Input and Output in our Literature Review, it is the time to implement your thoughts to Prolog Program
So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy
Excercise 1
Define a predicate makelower/0 which reads in a line of characters from the keyboard and outputs it again as a single line with any upper case letters converted to lower case. (The ASCII values of the characters a, z, A and Z are 97, 122, 65 and 90, respectively.). Thus the following would be a typical use of makelower:
?- makelower.
: This is an Example 123 inCLUDing numbers and symbols +-*/@[] XYz
this is an example 123 including numbers and symbols +-*/@[] xyz Read the rest of this entry »
Input And Output in Prolog
Chapter 5 Input and Output
- Outputting Terms
The main built-in predicate provided for outputting terms is write/1, the write/1 predicate takes a single argument, which must be a valid Prolog term. The built-in predicate nl/0Â has also been used many times, evaluating a nl goal causes a new line to be output to the current output stream.
Examples :
?- write(26),nl.
26
yes
?- write(‘a string of characters’),nl.
a string of characters
yes
Note that atoms that have to be quoted on input (e.g. ‘Paul’, ‘hello world’) are not quoted when output using write. If it is important to output the quotes, the writeq/1 predicate can be used. It is identical to write/1 except that atoms that need quotes for input are output between quotes (other atoms are not).
Examples :
?- writeq(‘a string of characters’),nl.
‘a string of characters’
yes
?-writeq(dog),nl.
dog
yes
- Inputting Terms
The built-in predicate read/1 is provided to input terms. It takes a single argument, which must be a variable. In the input stream, the term must be followed by a dot (‘.’) and at least one white space character, such as space or newline.
Note that for input from the keyboard (only) a prompt character such as a colon will usually be displayed to indicate that user input is required. It may be necessary to press the ‘return’ key before Prolog will accept the input. Both of these do not apply to input from files. If the variable is unbound (which is usually the case) it is bound to the input value. Read the rest of this entry »
Expert System Design for Events Guide
Application of Expert System.
Background of the idea :
A program that helps to show some events that has been occured, is happening and will happend in the future in different locations.
Detail explanation of the idea :
First we should collect some events from the past, now and future and then write them in the facts of prolog. Example :
Events :
1. Computer Exhibition “Scomdex” in Surabaya Expo at November 2nd-7th 2009.
2. Surabaya Sale, discounts in some malls in Surabaya including Tunjungan Plaza for remembering the anniversary of Surabaya City at November 9th-21st 2009.
3. Surabaya Book Fair in Surabaya Expo at November 16th-29th 2009
4. Kindergarten and Elementary Carnaval in Tugu Pahlawan at November 29th 2009.
5. Music Concert in Tunjungan Plaza for teenagers at December 1st-3rd 2009.
6. Food Festival everyday in Pakuwon City in east Surabaya.
7. Music By Request, online in some Radio Stations in Surabaya everyday at 07.00 PM.
8. Education Expo, giving valuable experience for student in Surabaya Expo at December 7th-12nd.
9. Surabaya Real Estate Property Exhibition for executives in Pakuwon City at December 1st-31st 2009.
from the facts above then we create the rules that showing
1. How expensive the food available on each events;
2. How far between each event locations.
From the facts and rules created above we can make syntax to determine such as :
1. find some events at specific times, dates and locations.
2. find the cheaper prise of the food available in each events.
3. list all events with some classifications such as only for adults, family, teenagers, kids etc.
4. list the events that near with specific locations.
Benefit :
From the program we can make easy to get some information about events that have been occured, is happening and will happend in Surabaya area.