SharedCS152 LBA Group C.ipynbOpen in CoCalc
CS152 LBA project

CS152 LBA Group C

Authors: Antonio Stark, Jie Wen Lim, Royi Noiman

KB = """
% Enter your KB below this line:

resPrice(cheap,haciBaba).
resPrice(cheap,mustafaKebap).
resPrice(moderate,royalsVuoung).
resPrice(unkown,burgerMeister).
resPrice(cheap,mcDonalds).
resPrice(expensive,musashi).
resPrice(moderate,daJiaLe).
resPrice(expensive,shanghaiRestaurant).
resPrice(cheap,maroush).
resPrice(moderate,wonderWaffel).
resPrice(cheap,ronTeleskyPizza).
resPrice(moderate,birdBBQ).
resPrice(expensive,westinnHotel).
resPrice(expensive,angryAngryChicken).
resPrice(moderate,bonanza).
resPrice(moderate,milchUndZucker).
resPrice(cheap,kremanski).
resPrice(expensive,test).

resPrice(moderate,Name) :- resPrice(cheap,Name).
resPrice(expensive,Name) :- resPrice(moderate,Name).

resCuisine(turkish,haciBaba).
resCuisine(turkish,mustafaKebap).
resCuisine(vietnamese,royalsVuoung).
resCuisine(bbq,burgerMeister).
resCuisine(fastFood,mcDonalds).
resCuisine(japanese,musashi).
resCuisine(chinese,daJiaLe).
resCuisine(chinese,shanghaiRestaurant).
resCuisine(turkish,maroush).
resCuisine(dessert,wonderWaffel).
resCuisine(fastFood,ronTeleskyPizza).
resCuisine(bbq,birdBBQ).
resCuisine(fusion,westinnHotel).
resCuisine(chinese,angryAngryChicken).
resCuisine(cafe,bonanza).
resCuisine(cafe,milchUndZucker).
resCuisine(cafe,kremanski).

resCuisine(asian,Name) :- 
    resCuisine(japanese,Name);
    resCuisine(chinese,Name);
    resCuisine(vietnamese,Name).

resDistance(walkable,haciBaba).
resDistance(carable,mustafaKebap).
resDistance(walkable,royalsVuoung).
resDistance(walkable,burgerMeister).
resDistance(bikeable,mcDonalds).
resDistance(bikeable,musashi).
resDistance(walkable,daJiaLe).
resDistance(walkable,shanghaiRestaurant).
resDistance(carable,maroush).
resDistance(carable,wonderWaffel).
resDistance(carable,ronTeleskyPizza).
resDistance(carable,birdBBQ).
resDistance(fusion,westinnHotel).
resDistance(walkable,angryAngryChicken).
resDistance(walkable,bonanza).
resDistance(walkable,milchUndZucker).
resDistance(walkable,kremanski).

resDistance(bikeable,Name) :- resDistance(walkable,Name).
resDistance(carable,Name) :- resDistance(bikeable,Name).

resVeg(veg,haciBaba).
resVeg(nonveg,mustafaKebap).
resVeg(vegan,royalsVuoung).
resVeg(veg,burgerMeister).
resVeg(nonveg,mcDonalds).
resVeg(veg,musashi).
resVeg(nonveg,daJiaLe).
resVeg(veg,shanghaiRestaurant).
resVeg(veg,maroush).
resVeg(veg,wonderWaffel).
resVeg(veg,ronTeleskyPizza).
resVeg(nonveg,birdBBQ).
resVeg(vegan,westinnHotel).
resVeg(nonveg,angryAngryChicken).
resVeg(veg,bonanza).
resVeg(veg,milchUndZucker).
resVeg(veg,kremanski)
resVeg(nonveg,test).

resVeg(veg,Name) :- resVeg(vegan,Name).
resVeg(nonveg,Name) :- resVeg(veg,Name).

restaurant(P, D, C, V, Name) :- 
    resPrice(P,Name),
    resDistance(D,Name),
    resCuisine(C,Name), 
    resVeg(V, Name).


% The code below implements the prompting to ask the user:
multivalued(none).
"""

# This basically writes the above rules/goals into a text file
with open("KB.pl", "w") as text_file:
    text_file.write(KB)
print('welcome to the AJR Berlin Restaurant Database\nOperated under Antonio-JieWen-Roiman consulting group GmbH')

# mode interface
mode = input('What mode would you like to access today?\nEnter 1 for normal, 2 for pirate')

if mode == 1:
    transport = input("What mode of transportation do you have?\nEnter 1 for walking, 2 for bike, and 3 for Uber")
    money = input("How much money are you willing to spend?\nEnter 1 for a little, 2 for some amount, 3 if you just won the lottery")
    vegOptions = input("Are you vegetarian?\n 1 if vegan, 2 if vegetarian, 3 if you are flexible")
    cuiType = input("Which cuisine are you feeling?\n Available options are: 1. Fast Food, 2. BBQ, 3. Fusion, 4. Cafe, 5. Dessert, 6. Turkish, 7. Asian, 8. Chinese, 9. Japanese, 10. Vietnamese")
elif mode == 2:
    transport = input("Ayyyyy!!! Wat shyp do yee pirate bring with ya todai?\nEnter 1 for shipwrecked, 2 for dingie, and 3 for a four-mast")
    money = input("All gut! And how ya treasah chest fillin?\nEnter 1 if yer got a bag of gold, 2 if ye got a chest of goodies, 3 if youre back from Aldorado")
    vegOptions = input("Ye schillin a sparklin! What meat ya pitchfork readi to skewer?\n 1 if only greens, 2 if greens an whites, 3 if you are meat-a-hungry!")
    cuiType = input("Ahoi! Well set ya sails to bloom and the plates to full! What gales a blowin today for ye lad?\n Available options are: 1. Fast Food, 2. BBQ, 3. Fusion, 4. Cafe, 5. Dessert, 6. Turkish, 7. Asian, 8. Chinese, 9. Japanese, 10. Vietnamese")

#print money, transport, vegOptions, cuiType

price = ''
if money == 1: price = 'cheap'
elif money == 2: price = 'moderate'
elif money == 3: price ='expensive'

distance = ''
if transport == 1: distance = 'walkable'
elif transport == 2: distance = 'bikeable'
elif transport == 3: distance = 'carable'

howveg = ''
if vegOptions == 1: howveg = 'vegan'
elif vegOptions == 2: howveg = 'veg'
elif vegOptions == 3: howveg = 'nonveg'
    
cuisine = ''
if cuiType == 1: cuisine = 'fastFood'
elif cuiType == 2: cuisine = 'bbq'
elif cuiType == 3: cuisine = 'fusion'
elif cuiType == 4: cuisine = 'cafe'
elif cuiType == 5: cuisine = 'dessert'
elif cuiType == 6: cuisine = 'turkish'
elif cuiType == 7: cuisine = 'asian'
elif cuiType == 8: cuisine = 'chinese'
elif cuiType == 9: cuisine = 'japanese'
elif cuiType == 10: cuisine = 'vietnamese'
    
#print price, distance, howveg, cuisine
welcome to the AJR Berlin Restaurant Database Operated under Antonio-JieWen-Roiman consulting group GmbH
What mode would you like to access today? Enter 1 for normal, 2 for pirate
What mode of transportation do you have? Enter 1 for walking, 2 for bike, and 3 for Uber
How much money are you willing to spend? Enter 1 for a little, 2 for some amount, 3 if you just won the lottery
Are you vegetarian? 1 if vegan, 2 if vegetarian, 3 if you are flexible
Which cuisine are you feeling? Available options are: 1. Fast Food, 2. BBQ, 3. Fusion, 4. Cafe, 5. Dessert, 6. Turkish, 7. Asian, 8. Chinese, 9. Japanese, 10. Vietnamese
#print price, distance, cuisine, howveg

from pyswip.prolog import Prolog
from pyswip.easy import *

prolog = Prolog() # Global handle to interpreter

retractall = Functor("retractall")
known = Functor("known",3)

prolog.consult("KB.pl") # open the KB
call(retractall(known))

soln = list(prolog.query('restaurant(%s, %s, %s, %s, Name)' %(price, distance, cuisine, howveg)))

#print soln

if len(soln) == 0:
    if mode == 1:
        print 'Sorry there does not seem to be a restaurant that meets your standards. Please search again'
    elif mode == 2:
        print 'Argh ye sorry ass pirate! Get a hold of yeself and try again!\nEverything that shines is gold, eh? Be less picky this time'
else:
    if mode == 1:
        print 'We recommend that you try out:\n'
        for i in range(len(soln)):
            print soln[i].values()[0]
        print '\nHappy munching!'
    if mode == 2:
        print 'Ya tummy can be filled at the islands of:\n'
        for i in range(len(soln)):
            print soln[i].values()[0]
        print '\nAghhhh go fill ya empty hulls!'
Sorry there does not seem to be a restaurant that meets your standards. Please search again