def clipsMatchPreference(data):
    # Preference
    preference = '(preference ' +\
                 '(cuisine "'+data['cuisine']+'") ' +\
                 '(is-vegetarian "'+data['isVegetarian']+'") ' +\
                 '(has-soup "'+data['hasSoup']+'") ' +\
                 '(fat-level "'+data['fatLevel']+'")' +\
                 '(calorie-level "'+data['calorieLevel']+'") ' +\
                 '(fiber-level "'+data['fiberLevel']+'") ' +\
                 '(carb-level "'+data['carbLevel']+'") ' +\
                 '(spicy-level "'+data['spicyLevel']+'") ' +\
                 '(sour-level "'+data['sourLevel']+'") ' +\
                 '(sweet-level "'+data['sweetLevel']+'") ' +\
                 '(salty-level "'+data['saltyLevel']+'"))'

    # CLIPS
    clips.Clear()
    clips.BatchStar(settings.CLIPS_DIR + "/templates.clp")
    if os.path.isfile(settings.CLIPS_DIR + "/dishes.clp"):
        clips.BatchStar(settings.CLIPS_DIR + "/dishes.clp")
    if os.path.isfile(settings.CLIPS_DIR + "/reviews.clp"):
        clips.BatchStar(settings.CLIPS_DIR + "/reviews.clp")
    if os.path.isfile(settings.CLIPS_DIR + "/suggestions.clp"):
        clips.BatchStar(settings.CLIPS_DIR + "/suggestions.clp")
    clips.BatchStar(settings.CLIPS_DIR + "/rules.clp")
    clips.Reset()
    clips.Assert(preference)
    clips.Run()
    return clips.StdoutStream.Read()
Beispiel #2
0
def match_preference(data):
    preference = '(preference ' + \
                 '(sex "' + data['sex'] + '") ' + \
                 '(price-level "' + data['priceLevel'] + '") ' + \
                 '(age-level "' + data['ageLevel'] + '") ' + \
                 '(cat-fashion "' + data['catFashion'] + '") ' + \
                 '(cat-music "' + data['catMusic'] + '") ' + \
                 '(cat-book "' + data['catBook'] + '") ' + \
                 '(cat-games "' + data['catGames'] + '") ' + \
                 '(cat-movies "' + data['catMovies'] + '") ' + \
                 '(cat-gadgets "' + data['catGadgets'] + '") ' + \
                 '(cat-sport "' + data['catSport'] + '") ' + \
                 '(cat-cosmetics "' + data['catCosmetics'] + '") ' + \
                 '(cat-toy "' + data['catToy'] + '"))'

    print(preference)
    clips.Clear()
    clips.BatchStar(settings.CLIPS_DIR + "/templates.clp")
    clips.BatchStar(settings.CLIPS_DIR + "/gifts.clp")
    clips.BatchStar(settings.CLIPS_DIR + "/suggestions.clp")
    clips.BatchStar(settings.CLIPS_DIR + "/rules.clp")
    clips.Reset()
    clips.Assert(preference)
    clips.Run()
    return clips.StdoutStream.Read()
Beispiel #3
0
def clipsMatchPreferencemaes(data):
    # Preference
    preference = '(preference ' +\
                 '(planta "'+data['planta']+'") ' +\
                 '(sintoma-aa "'+data['sintomaAA']+'") ' +\
                 '(sintoma-bb "'+data['sintomaBB']+'") ' +\
                 '(sintoma-cc "'+data['sintomaCC']+'"))'

    # CLIPS
    clips.Clear()
    clips.BatchStar(settings.CLIPS_DIR + "/templatesmaes.clp")
    if os.path.isfile(settings.CLIPS_DIR + "/dishesmaes.clp"):
        clips.BatchStar(settings.CLIPS_DIR + "/dishesmaes.clp")
    if os.path.isfile(settings.CLIPS_DIR + "/reviewsmaes.clp"):
        clips.BatchStar(settings.CLIPS_DIR + "/reviewsmaes.clp")
    if os.path.isfile(settings.CLIPS_DIR + "/suggestionsmaes.clp"):
        clips.BatchStar(settings.CLIPS_DIR + "/suggestionsmaes.clp")
    clips.BatchStar(settings.CLIPS_DIR + "/rulesmaes.clp")
    clips.Reset()
    clips.Assert(preference)
    clips.Run()
    return clips.StdoutStream.Read()
Beispiel #4
0
    def OnOpen(self, event):
        dlg = wx.FileDialog(self, "Selecciona archivo", self.dirname, "",
                            "*.clp", wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename = dlg.GetFilename()
        self.dirname = dlg.GetDirectory()
        if (self.filename != ""):
            os.chdir(self.dirname)
            self.clipsFile = os.path.join(self.dirname, self.filename)
            self.simClipsFile = os.path.join(self.dirname,
                                             'CicloControlado2.clp')
            self.timeClipsFile = os.path.join(self.dirname,
                                              'simulacionoficinaalumnos.clp')

            clips.Clear()
            clips.BatchStar(self.simClipsFile)
            clips.BatchStar(self.clipsFile)
            clips.BatchStar(self.timeClipsFile)

            clips.Reset()
            clips.Run()

            # Modo de ejecucion
            for f in clips.FactList():
                if "Preguntando" in f.PPForm():
                    self.nuevoCicloItem.Enable(True)
                    break

            self.SetStatusText(self.clipsFile)
            self.office.updatePeopleLocation()
            self.Refresh()

            self.OutputFrame.box.Clear()
            self.OutputFrame.appendText("-> Iniciar simulacion " +
                                        time.strftime("%c"))
        dlg.Destroy()
def load_expert_shell():
	clips.BatchStar("robot_planner.clp")
	clips.Reset()
Beispiel #6
0
def system_run(input_ set):
    if 'hazard' in input_set:
        clips.Clear()
        clips.Reset()

        eng_var[:]=[]

        eng_var.append(input_set['lat'])

        eng_var.append(input_set['long'])

        eng_var.append(clips.BuildTemplate("entity", """
        (slot aid (type STRING))
        (slot latitude (type NUMBER))
        (slot longitude (type NUMBER))
        (slot quantity (type NUMBER))
        """, "template for a entity"))

        eng_var.append(clips.BuildTemplate("allies", """
        (slot username (type STRING))
        (slot foraid (type STRING))
        (slot action (type STRING))
        (slot quantity (type NUMBER))
        """, "template for a allies"))

        eng_var.append(input_set['control'])

        eng_var.append(clips.BuildTemplate("disaster", """
        (slot hazard (type STRING))
        (slot latitude (type NUMBER))
        (slot longitude (type NUMBER))
        (slot span (type NUMBER))
        """, "template for a disaster"))

        d=clips.Fact(eng_var[5])
        d.Slots['hazard'] = input_set['hazard']
        d.Slots['latitude'] = input_set['lat']
        d.Slots['longitude'] = input_set['long']
        d.Slots['span'] = input_set['span']
        d.Assert()

        facts[:] = []
        fields[:] = []
        list_map[:] = []

        clips.RegisterPythonFunction(invoke_pronearea)
        clips.RegisterPythonFunction(display_disaster)
        clips.RegisterPythonFunction(invoke_entity)
        clips.RegisterPythonFunction(invoke_useralert)
        clips.RegisterPythonFunction(invoke_user_allocate )
        clips.RegisterPythonFunction(invoke_user_deallocate)
        clips.RegisterPythonFunction(invoke_message)
        clips.RegisterPythonFunction(invoke_alert_area)

        clips.BatchStar("/home/jishnu/PycharmProjects/dmis/controlunit/expertsystem/inference.clp")
        clips.Run()

    if 'refresh' in input_set:
        if len(eng_var)==0:
            return {'fact': facts, 'field': fields,'map_data':list_map}
        message_dealer(input_set['control'],eng_var[0],eng_var[1],eng_var[2])
        user_status_checking()
        clips.Run()

    if 'send' in input_set:
        if len(eng_var)==0:
            return {'fact': facts, 'field': fields,'map_data':list_map}
        message_handler(input_set['control'],input_set['selectaid'],input_set['parameter'])

    if 'deallocate' in input_set:
        try:
            clips.Assert("(DeallocateAll)")
        except clips.ClipsError:
            print("Error in Deallocation")
        clips.Run()
        facts[:] = []
        fields[:] = []
        list_map[:] = []

    clips.SendCommand("run")
    print (clips.PrintFacts())
    list_temp=list(facts)
    list_temp.reverse()
    return {'fact':list_temp,'field':list(set(fields)),'map_data':list_map}
# Function to convert user question into clips form
def parse_input_to_string():
	user_input = raw_input("Enter your question : ")
	words_list = user_input.lower().split()
	final_string = ""
	for word in words_list :
		final_string += '"' + word +'"' 
	return final_string 
# importing clips library
import clips
# get input from user and store it in a variable called user_input
user_input = parse_input_to_string();
# build a global variable using clips library called Final_answer to store final answer inside it
Final_answer = clips.BuildGlobal('Final_answer','sorry, i have no answers for you at this moment.')
# load clips file 
clips.BatchStar("algorithm.clp")
# reset clips environment 
clips.Reset()
# add new fact using assert with user inputs
clips.Assert('(User_input'+user_input+')')
# run the program
clips.Run()
# print out the final answer
print "Phronesis said : " + Final_answer.Value
# t = clips.StdoutStream.Read()
# print t