示例#1
0
文件: money_new.py 项目: yuce/pyswip
def main():
    letters = "S E N D M O R Y".split()
    prolog = Prolog()
    sendmore = Functor("sendmore")
    prolog.consult("money.pl")
    
    X = Variable()
    call(sendmore(X))
    r = X.value
    for i, letter in enumerate(letters):
        print(letter, "=", r[i])
    print("That's all...")
示例#2
0
def main():
    letters = "S E N D M O R Y".split()
    prolog = Prolog()
    sendmore = Functor("sendmore")
    prolog.consult("money.pl")

    X = Variable()
    call(sendmore(X))
    r = X.value
    for i, letter in enumerate(letters):
        print(letter, "=", r[i])
    print("That's all...")
示例#3
0
def check_prolog_knowledge_base():
    global answers
    consult = Functor("consult", 1)
    call(consult(file_path))
    prolog = Prolog()
    arr = list(
        prolog.query(
            "run({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, X)".
            format(*answers)))
    if len(arr) > 0:
        v = arr[0]['X']
        return True, v
    else:
        v = "Такого героя нет. Добавьте его."
        return False, v
示例#4
0
文件: TP2.py 项目: Ydr/TP2Prolog
    def guardar_cont(self, ingredientes, pasos, nombre, autor, estilo):
        assertz = Functor("assertz", 1)
        receta = Functor("receta", 5)
        call(assertz(receta(self.ingredientes, self.pasos, self.nombre, self.autor, self.estilo)))
        try:  # Se lee el txt
            infousuario = ("receta(" + self.ingredientes, self.pasos, self.nombre, self.autor, self.estilo + ").")
            info = open("Base_Conocimiento.txt", "r")
            info = open("Base_Conocimiento.txt", "a")  # Abre la informacion guardada del txt
            info.write(",".join(infousuario) + "\n")
            info.close()

        except IOError:  # Creacion del archivo si no esta creado
            info = open("Base_Conocimiento.txt", "w")
            info.write(",".join(infousuario))
            self.guardar_cont(self.ingredientes, self.pasos, self.nombre, self.autor, self.estilo)
            info.close()
示例#5
0
 def get_n_ans_new(self,
                   instructions: str,
                   maxresults=-1,
                   solves=True) -> list:
     ' functors and items of predicates, variables'
     terms, vars, statements = self.parse_ins(instructions)
     vars_ans = [] if solves else {i[0]: []
                                   for i in vars
                                   }  # list/dict of variable values
     statements_ans = {}  # list of statements
     if terms:
         q = Query(*terms)  # make query
         while q.nextSolution() and maxresults:  # find solutions
             maxresults -= 1
             if solves:
                 # append values
                 vars_ans.append({k: v.value for k, v in vars})
             else:
                 for k, v in vars:
                     if v.value not in vars_ans[k]:
                         vars_ans[k].append(v.value)
         q.closeQuery()
     if statements:
         for statement in statements:
             statements_ans.update({statement[1]: call(statement[0])})
     return vars_ans, statements_ans
示例#6
0
from pyswip import Functor, Variable, Query, call
assertz = Functor("assertz", 1)
father = Functor("father", 2)

call(assertz(father("mi", "j")))
call(assertz(father("mi", "g")))

X = Variable()
q = Query(father("mi", X))
while q.nextSolution():
    print "Hello,", X.value
q.closeQuery()
示例#7
0
__author__ = 'btavares e fferreira'


from pyswip import Functor, Variable, Query, call,Prolog


assertz = Functor("assertz", 1)
father = Functor("father", 2)

call(assertz(father("michael","john")))
call(assertz(father("michael","gina")))

X = Variable()

q = Query(father("michael",X))
while q.nextSolution():
    print "Hello,", X.value
q.closeQuery()


prolog = Prolog()

#prolog.consult("e:/ia/testeXadrezBFa.pl")
prolog.consult("f:/temp/pee1.pl")
#prolog.assertz("posicao(2,3)")

for result in prolog.query("mover( 3/4, X/Y, C )"):
    print result['X'], result['Y'], result['C']


for result in prolog.query("aStar( 6/6, V, C)",maxresult=1):
示例#8
0
def insertar(raza, nombre, genero, edad, ecosistema, comida):
    call(assertz(Animal(raza, nombre, genero, edad, ecosistema, comida)))
    print "inserto", raza, nombre, genero, edad, ecosistema, comida
示例#9
0
 def delete_flight(self, origin, destination, cost):
     call(self.retract(self.edge(origin, destination, cost)))
示例#10
0
 def add_flight(self, origin, destination, cost):
     call(self.assertz(self.edge(origin, destination, cost)))