Exemplo n.º 1
0
def logicBased():
    x = var()
    print(run(1, x, eq(x, 5)))
    z = var()
    print(run(1, x, eq(x, z), eq(z, 3)))

    print(run(1, x, eq((1, 2), (1, x))))

    print(run(2, x, membero(x, (1, 2, 3)), membero(x, (2, 3, 4))))

    z = var('test')
    print(z)

    a, b, c = vars(3)
    print(a)
    print(b)
    print(c)

    parent = Relation()
    facts(parent, ("Homer", "Bart"), ("Homer", "Lias"), ("Abe", "Homer"))
    print(run(2, x, parent("Homer", x)))

    y = var()
    print(run(1, x, parent(x, y), parent(y, 'Bart')))

    def grandparent(x, z):
        y = var()
        return conde((parent(x, y), parent(y, z)))

    print(run(1, x, grandparent(x, 'Bart')))
    menu()  #calls the menu function (a menu loop)
def star_wars_logic():

    x = var()

    parent = Relation()
    facts(parent, ("Darth Vader", "Luke Skywalker"),
          ("Darth Vader", "Leia Organa"), ("Han Solo", "Kylo Ren"),
          ("Leia Organa", "Kylo Ren"))
    print(run(0, x, parent(x, "Luke Skywalker")))
    print(run(0, x, parent("Darth Vader", x)))

    grandparent = Relation()
    facts(grandparent, ("Darth Vader", "Kylo Ren"))
    print(run(1, x, grandparent(x, "Kylo Ren")))
Exemplo n.º 3
0
def I():

    parent = Relation()
    facts(parent, ("Darth Vader", "Luke Skywalker"),
          ("Darth Vader", "Leia Organa"), ("Leia Organa", "Kylo Ren"),
          ("Han Solo", "Kylo Ren"))
    x = var()
    print(run(1, x, parent(x, "Luke Skywalker")))
    y = var()
    print(run(2, y, parent("Darth Vader", y)))

    grand_parents = Relation()
    facts(grand_parents, ("Darth Vader", "Kylo Ren"))
    z = var()
    print(run(1, z, grand_parents(z, "Kylo Ren")))
Exemplo n.º 4
0
    def start(self):
        self.parent = Relation()
        x = var()
        facts(self.parent,
              ("DarthVader", "LukeSkywalker"),
              ("DarthVader", "LeiaOrgana"),
              ("LeiaOrgana", "KyloRen"),
              ("HanSolo", "KyloRen")
              )

        lukesParent = run(1, x, self.parent(x, "LukeSkywalker"))
        darthsChildren =run(2, x, self.parent("DarthVader", x))
        print("Luke Skywalkers parent is: ", lukesParent)
        print("Darth Vaders children are: ", darthsChildren)
        kylosGrandparent = run(1, x,self.grandparent(x, "KyloRen"))
        print("Kylo Ren's grand parent is: ", kylosGrandparent)
        self.familyTreeDataStructures()
def main():
    parent = Relation()
    facts(parent, ("Darth Vader", "Luke Skywalker"),
          ("Darth Vader", "Leia Organa"), ("Leia Organa", "Kylo Ren"),
          ("Han Solo", "Kylo Ren"))
    # Darth Vader is Luke and Leia's Parent
    # Leia and Han are Kylo's Parents

    run(1, x, parent(x, "Luke Skywalker"))
    # What is x, such that x is the parent of Luke
    run(2, y, parent("Darth Vader", y))
    # What is y, such that y is the children of Vader

    grandparent = Relation()
    facts(grandparent, ("Darth Vader", "Kylo Ren"))
    # Darth Vader is Kylo Ren's Grandparent

    run(1, z, grandparent(z, "Kylo Ren"))
    # What is z, such that z is the grandparent of Kylo Ren
    #OR
    y = var()
    run(1, x, parent(x, y), parent(y, "Kylo Ren"))
Exemplo n.º 6
0
def gather_facts(doc):
    R = {'LEMMA': Relation('LEMMA'),
         'root': Relation('root'),
         'head': Relation('head')}
    for rel in DEPS:
        R[rel] = Relation(rel)
    for tok in doc:
        facts(R['LEMMA'], (tok.i, tok.lemma_))
        if not tok.pos_ in R:
            R[tok.pos_] = Relation(tok.pos_)
        fact(R[tok.pos_], (tok.i))

        facts(R[tok.dep_ if tok.head.i != tok.i else 'root'],
              (tok.head.i if tok.head.i != tok.i else -1, tok.i))
        facts(R['head'], (tok.head.i if tok.head.i != tok.i else -1, tok.i))

        if not tok.ent_type_ in R:
            R[tok.ent_type_] = Relation(tok.ent_type_)
        fact(R[tok.ent_type_], (tok.i))

    gather_inside_outside_quote_facts(R, doc)

    return R
Exemplo n.º 7
0
z = var()

from kanren import Relation,facts,conde
parent = Relation()

facts(parent,
('isidro','daniel'),
('isidro','hilda'),
('ana','daniel'),
('ana','hilda'),
('elena','betza'),
('elena','severo'),
('elena','julia'),
('daniel','tahere'),
('daniel','didar'),
('betza','tahere'),
('betza','didar'),
('severo','elisa'),
('jazmin','elisa'),
('julia','marifer'),
('julia','jose'),
('hilda','maria'),
('julio','maria'),
('maria','guadalupe'),
('nelson','guadalupe')
)

def abuelos(x, z):
    y = var()
    return conde((parent(x,y), parent(y,z) ))
Exemplo n.º 8
0
from kanren import Relation, facts, run, conde, var

print("Using logic programming:")
parent = Relation()

facts(parent, ('Darth Vader', 'Luke Skywalker'),
              ('Darth Vader', 'Leia Organa'),
              ('Leia Organa', 'Kylo Ren'),
              ('Han Solo', 'Kylo Ren'))

q = var()
# Who is the parent of Luke Skywalker?
print((run(0, q, parent(q, 'Luke Skywalker'))))

# Who  are the children of Darth Vader?
print((run(0, q, parent('Darth Vader', q))))

def grandparent(gp, child):
    p = var()
    return conde((parent(gp, p), parent(p, child)))

# Who is the grandparent of Kylo Ren?
print((run(0, q, grandparent(q, 'Kylo Ren'))))

#Question 4
print("Using standard python:")
class Member(object):
    def __init__(self, name):
        self.parents = []
        self.children = []
        self.name = name
Exemplo n.º 9
0
"""
Name: Kangnan Dong
Date: 3/8/2020
Assignment2 Goal: use kanren package to build a family tree
"""

import json
from kanren import Relation, facts, run, conde, var, eq

with open('relationships.json') as f:
    d = json.loads(f.read())
father = Relation()
mother = Relation()

for item in d['father']:
    facts(mother, (list(item.keys())[0], list(item.values())[0]))
for item in d['mother']:
    facts(father, (list(item.keys())[0], list(item.values())[0]))

def parent(x, y):
    return conde((father(x, y),), (mother(x,y),))
def grandparent(x, y):
    temp = var()
    return conde((parent(x, temp), parent(temp, y)))
def sibling(x, y):
    temp = var()
    return conde((parent(temp, x), parent(temp, y)))
def uncle(x, y):
    temp = var()
    return conde((father(temp, x), grandparent(temp, y)))
Exemplo n.º 10
0
expr = (mul, 2, (add, 3, 1))  # 2 * (3 + 1)
print(run(0, (x, y), eq(pattern, expr)))  # prints ((3, 2),) meaning
#   x matches to 3
#   y matches to 2

pattern = (add, (mul, 2, r), s)  # (2 * r) + s
expr = (add, 5, (mul, 6, 2))  # 5 + (6  * 2)
print(run(0, (r, s), eq(pattern, expr)))  # prints ((6, 5),) meaning
#   r matches to 6
#   s matches to 5

results()
pizza()
pizza = Relation()
pizza2 = Relation()
facts(pizza, ('Pepperoni', 'Sausage'), ('Pepperoni', 'Bacon'), ('Ham', 'Pepperoni'))
facts(pizza2, ('Pineapple', 'Ham'), ('Pineapple', 'Sardines'), ('Anchovies', 'Pineapple'))

print(run(1, x, pizza(x, 'Sausage')))
print(run(2, x, pizza('Pepperoni', x)))
print(run(3, x, pizza2(x, 'Ham')))
print(run(4, x, pizza2('Pineapple', x)))


def mypizza(x, z):
    y = var()
    return conde((pizza(x, y), pizza(y, z)))


print(run(1, x, mypizza(x, 'Sausage')))
print("Making the perfect pizza...")
Exemplo n.º 11
0
 def kanren(self, vrs):
     edge = kr.Relation()
     kr.facts(edge, *self._kanren(vrs))
     return edge
Exemplo n.º 12
0
http://objectcommando.com/blog/2011/11/04/the-magical-island-of-kanren-core-logic-intro-part-1/
"""
import toolz

from kanren import Relation, conde, facts, run, var

father = Relation()
mother = Relation()

facts(
    father,
    ("Vito", "Michael"),
    ("Vito", "Sonny"),
    ("Vito", "Fredo"),
    ("Michael", "Anthony"),
    ("Michael", "Mary"),
    ("Sonny", "Vicent"),
    ("Sonny", "Francesca"),
    ("Sonny", "Kathryn"),
    ("Sonny", "Frank"),
    ("Sonny", "Santino"),
)

facts(
    mother,
    ("Carmela", "Michael"),
    ("Carmela", "Sonny"),
    ("Carmela", "Fredo"),
    ("Kay", "Mary"),
    ("Kay", "Anthony"),
    ("Sandra", "Francesca"),
Exemplo n.º 13
0
from kanren import var, facts, Relation, run

# Declaring a relation, maze_path
maze_path = Relation()

# Defining a path on a maze
# Relation object from Kanren library is used to define different paths
# Maze starts at 1, and the finish line is 9
# Path to finish is 1->2->5->6->9
facts(maze_path, (1, 2), (1, 3), (2, 8), (2, 5), (3, 1), (3, 4), (5, 6),
      (5, 1), (1, 4), (3, 7), (7, 4), (4, 8), (2, 7), (5, 7), (6, 9), (8, 1))


# Function will work its way back from the finish (9) to the start (1) by using the run function
# Run function recursively finds the parent of current_position until we reach base case
# Once base case is reached, we reverse our string since we traveled from finish to start
# String is then printed to user
def finish_maze(current_position, path):
    x = var()
    if current_position == 1:
        path = path[::-1]
        print(path)
    else:
        current_position = run(1, x, maze_path(x, current_position))[0]
        path += ">-%d" % current_position
        finish_maze(current_position, path)


# Function displays start menu for user
def start_menu():
    print("*** Welcome to the Maze ***")
Exemplo n.º 14
0
# Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
# Family relationships from The Godfather
# Translated from the core.logic example found in
# "The Magical Island of Kanren - core.logic Intro Part 1"
# http://objectcommando.com/blog/2011/11/04/the-magical-island-of-kanren-core-logic-intro-part-1/
from kanren import Relation, facts, run, conde, var, eq
from treelib import Node, Tree
import re

father = Relation()
mother = Relation()

facts(father, ('John', 'Jesse'), ('John', 'Calli'), ('Jim', 'Mindy'),
      ('Jim', 'Jimmy'), ('Hector', 'Michael'), ('Hector', 'Rachael'),
      ('Hector', 'Daniel'), ('Bruce', 'John'), ('Bruce', 'Terry'),
      ('Bruce', 'Lynda'), ('Bruce', 'Lorie'), ('Bruce', 'Barbara'),
      ('Bruce', 'Leslie'))

facts(mother, ('Mindy', 'Jesse'), ('Mindy', 'Calli'), ('Margie', 'Mindy'),
      ('Margie', 'Jimmy'), ('Leslie', 'Michael'), ('Leslie', 'Rachael'),
      ('Leslie', 'Daniel'), ('Berniece', 'John'), ('Berniece', 'Terry'),
      ('Berniece', 'Lynda'), ('Berniece', 'Lorie'), ('Berniece', 'Barbara'),
      ('Berniece', 'Leslie'), ('Lorie', 'Cassie'))

q = var()

print('Practicing Commands...')

print((run(0, q, father('John', q))))  # John is the father of who?
Exemplo n.º 15
0
#Emanuel Ordonez
#Assignment 2
#CS 351

import kanren
from kanren import run, var, conde, Relation, facts

cor = 'CS 351'
prof = 'Cary Jardin'

#assigning professor to a course
course = Relation()
facts(course, (cor, prof))

#assigning professor to all students
professor = Relation()


#value to help use run
def studies(c, student):
    return conde((course(c, prof), professor(prof, student)))


#Menu for app
print('\n\nCourse Menu')
print('_____________________________')
print('1: Course Name')
print('2: Professor Name')
print('3: Add a student')
print('4: Students in course')
print('5: Quit')
Exemplo n.º 16
0
from kanren import Relation, facts, run, var
x = var()  #declaring x variable with var
parent = Relation()
#presenting the fact in the system
facts(parent, ("Nathan", "Mexican"), ("Tina", "Thai"), ("Tim", "Vegetarian"),
      ("Sally", "Italian"), ("John", "Thai"))

#setting the parameter and the output
Thai_food = run(2, x, parent(x, "Thai"))
print(Thai_food)

mexican_food = run(1, x, parent(x, "Mexican"))
print(mexican_food)

veg_food = run(1, x, parent(x, "Vegetarian"))
print(veg_food)

Italian_food = run(1, x, parent(x, "Italian"))
print(Italian_food)
Exemplo n.º 17
0
# Family relationships from The Godfather
# Translated from the core.logic example found in
# "The Magical Island of Kanren - core.logic Intro Part 1"
# http://objectcommando.com/blog/2011/11/04/the-magical-island-of-kanren-core-logic-intro-part-1/

from kanren import Relation, facts, run, conde, var, eq

father = Relation()
mother = Relation()

facts(father, ('Vito', 'Michael'), ('Vito', 'Sonny'), ('Vito', 'Fredo'),
      ('Michael', 'Anthony'), ('Michael', 'Mary'), ('Sonny', 'Vicent'),
      ('Sonny', 'Francesca'), ('Sonny', 'Kathryn'), ('Sonny', 'Frank'),
      ('Sonny', 'Santino'))

facts(mother, ('Carmela', 'Michael'), ('Carmela', 'Sonny'),
      ('Carmela', 'Fredo'), ('Kay', 'Mary'), ('Kay', 'Anthony'),
      ('Sandra', 'Francesca'), ('Sandra', 'Kathryn'), ('Sandra', 'Frank'),
      ('Sandra', 'Santino'))

q = var()

print((run(0, q, father('Vito', q))))  # Vito is the father of who?
# ('Sonny', 'Michael', 'Fredo')

print((run(0, q, father(q, 'Michael'))))  # Who is the father of Michael?
# ('Vito',)


def parent(p, child):
    return conde([father(p, child)], [mother(p, child)])
Exemplo n.º 18
0
# Family relationships from The Godfather
# Translated from the core.logic example found in
# "The Magical Island of Kanren - core.logic Intro Part 1"
# http://objectcommando.com/blog/2011/11/04/the-magical-island-of-kanren-core-logic-intro-part-1/

from kanren import Relation, facts, run, conde, var, eq

father = Relation()
mother = Relation()

facts(father, ('Vito', 'Michael'),
              ('Vito', 'Sonny'),
              ('Vito', 'Fredo'),
              ('Michael', 'Anthony'),
              ('Michael', 'Mary'),
              ('Sonny', 'Vicent'),
              ('Sonny', 'Francesca'),
              ('Sonny', 'Kathryn'),
              ('Sonny', 'Frank'),
              ('Sonny', 'Santino'))

facts(mother, ('Carmela', 'Michael'),
              ('Carmela', 'Sonny'),
              ('Carmela', 'Fredo'),
              ('Kay', 'Mary'),
              ('Kay', 'Anthony'),
              ('Sandra', 'Francesca'),
              ('Sandra', 'Kathryn'),
              ('Sandra', 'Frank'),
              ('Sandra', 'Santino'))
Exemplo n.º 19
0
x = kanren.var()
z = kanren.var()
y = kanren.var()
a, b, c = kanren.vars(3)
print(run(1, x, eq(x, 5)))

print(run(1, x, eq(x, z), eq(z, 3)))

print(run(1, x, eq((1, 2), (1, x))))

print(run(2, x, membero(x, (1, 2, 3)), membero(x, (2, 3, 4))))
print(a, b, c)

parent = Relation()
facts(parent, ("Homer", "Bart"), ("Homer", "Lisa"), ("Abe", "Homer"))

print(run(1, x, parent(x, "Bart")))

print(run(2, x, parent("Homer", x)))

print(run(1, x, parent(x, y), parent(y, 'Bart')))


def grandparent(x, z):
    return conde((parent(x, y), parent(y, z)))


print(run(1, x, grandparent(x, 'Bart')))

pokemon = Relation()
Exemplo n.º 20
0
# coding: utf-8

# In[15]:


from kanren import Relation, facts, run, conde, var, eq

x = var()
y = var()

father = Relation()
mother = Relation()

facts(father, ('The Force', 'Anakin Skywalker'),
 ('Cliegg Lars', 'Owen Lars'),
 ('Anakin Skywalker', 'Leia Organa'),
 ('Anakin Skywalker', 'Luke Skywalker'),
 ('Han Solo', 'Ben Solo'))

facts(mother, ('Shmi Skywalker', 'Anakin Skywalker'),
 ('Shmi Skywalker', 'Owen Lars'),
 ('Padme Amidala', 'Leia Organa'),
 ('Padme Amidala', 'Luke Skywalker'),
 ('Leia Organa', 'Ben Solo'))

resultF = run(1, x, father(x, 'Anakin Skywalker'))
resultM = run(1, x, mother(x, 'Anakin Skywalker'))
print(resultF + resultM)

resultF = run(1, x, father(x, 'Owen Lars'))
resultM = run(1, x, mother(x, 'Owen Lars'))
Exemplo n.º 21
0
          membero(x, (2, 3, 4))))  # x is a member of (2, 3, 4)

# Logic variable
z = var('test')
print (z)

# Multiple variable at one
a, b, c = var('a'), var('b'), var('c')
print(a)
print(b)
print(c)

# Data store and relationship
parent = Relation()
facts(parent, ("Homer", "Bart"),
      ("Homer", "Lisa"),
      ("Abe", "Homer"))

print(run(1, x, parent(x, "Bart")))

print(run(2, x, parent("Homer", x)))

# Intermediate variables for more complex queries
y = var()
print(run(1, x, parent(x, y),
          parent(y, 'Bart')))


# Separate relationship. conde() is a goal constructor for logic AND and OR
def grandparent(x, z):
    y = var()
Exemplo n.º 22
0
from kanren import run, eq, membero, var, conde, vars, Relation, facts

price = Relation()
userRatings = Relation()
screenSize = Relation()
pixelDensity = Relation()
numOfCores = Relation()
weight = Relation()

print("Apple Iphone 11 Pro VS Samsung Galaxy S20 Ultra")
print()

facts(price, ('1000', 'Iphone 11'), ('1200', 'S20'))
facts(userRatings, ('4.7', 'Iphone 11'), ('4.6', 'S20'))
facts(screenSize, ('5.8 inches', 'Iphone 11'), ('6.9 inches', 'S20'))
facts(pixelDensity, ('358 PPI', 'Iphone 11'), ('511 PPI', 'S20'))
facts(numOfCores, ('6 Core', 'Iphone 11'), ('8 Core', 'S20'))

print("If answer Iphone then enter 1, if S20 then enter 2")
answer = input("Which do you think has a better price? ")

applePrice = (run(1, x, price(x, "Iphone 11")))[0]
samsungPrice = (run(1, x, price(x, "S20")))[0]
if answer == "1":
    print("You are right! The Iphone only costs $", applePrice)
elif answer == "2":
    print("You are wrong! The Samsung costs $", samsungPrice,
          " which is more than ", (int(samsungPrice) - int(applePrice)),
          " dollars")
else:
    print("Wrong input!")
Exemplo n.º 23
0
from kanren import Relation, facts, run, eq, membero, var, conde
x = var()
y = var()
z = var()

# Question 1: Modeling Star Wars family relations
parent = Relation()
facts(parent, ("Darth Vader", "Luke Skywalker"),
      ("Darth Vader", "Leia Organa"), ("Leia Organa", "Kylo Ren"),
      ("Han Solo", "Kylo Ren"))

# Question 2: Queries about the family
# Who is parent of Luke Skywalker
print('Question 2:', run(1, x, parent(x, "Luke Skywalker")))
# Who are the children of Darth Vader
print('Question 2:', run(2, x, parent("Darth Vader", x)))


# Question 3: Define the grandparent relation
def grandparent(x, z):
    y = var()
    return conde((parent(x, y), parent(y, z)))


print('Question 3:', run(1, x, grandparent(x, "Kylo Ren")))

# Question 4: Answers questions 1, 2 and 3 using default python
print('Question 4:')


def create_person(name, parent, children):
Exemplo n.º 24
0
employee = Relation()
Trainee = Relation()
traineenb = 0
managernb = 0
managednb = 0


username = input(" Hello, I'am doing the listing of the employees and they're managers\n What is your name ?\n")
print(" Welcome " + username + "!\n")

Employees = input(" You have to add your manager, the people you are managing and your trainee if you have one\n Enter the keyword you need to enter ?\n Manager, Managed, Trainee\n")

while (1):
    if (Employees == "Trainee" or Employees == "trainee"):
        trainee = input(" Enter the name of your trainee\n")
        facts(Trainee,   (username, trainee))
        traineenb += 1
    if (Employees == "Managed" or Employees == "managed"):
        sidekick = input(" Enter the name of the person managed by you\n")
        facts(employee,   (username, sidekick))
        managednb += 1
    if (Employees == "Manager" or Employees == "manager"):
        manager = input(" Enter the name of your manager\n")
        facts(employee,   (manager, username))
        managernb += 1
    if (Employees == "stop" or Employees == "STOP" or Employees == "Stop"):
        break
    Employees = input(" Who do you wan't to add now ?\n Trainee, Manager, Managed or STOP\n")
                    
listing = input(" What do you want to know ?\n Who is your Trainee, Manager or Managed ?\n")
x = var()
Exemplo n.º 25
0
'''
Name: Leouel Guanzon
Professor: Cary Jardin
Course: CS351 Programming Languages
Description: Logical Programming (Simple Family Tree) 
'''

from kanren import run, var, Relation, facts

parent = Relation()
member = var()

dad = input("Enter your father's name: ")
child1 = input("Enter your brother's/sister's name: ")
child2 = input("Enter your name: ")

facts(parent, (dad, child1), (dad, child2))

print("The father of ", child1, " is ")
print(run(1, member, parent(member, child1)))
print("The children of ", dad, " is ")
print(run(2, member, parent(dad, member)))
Exemplo n.º 26
0
print(run(1, x, eq(x, z), eq(z, 3)))
#asks for a number x such that 1,2 equals 1,x
print(run(1, x, eq((1, 2), (1, x))))
#uses membero twice to ask for 2 values of x such that x is a member of 1,2,3 and that x is a member of 2,3.4
print(run(2, x, membero(x, (1, 2, 3)), membero(x, (2, 3, 4))))
#creates a logic variable
z = kanren.var('test')
print(z)
#creates multiple logic variables at once
a, b, c = var('a'), var('b'), var('c')
print(a)
print(b)
print(c)
#creates a parent relationship and uses it to state facts about who is related to who
parent = Relation()
facts(parent, ("Homer", "Bart"), ("Homer", "Lisa"), ("Abe", "Homer"))
print(run(1, x, parent(x, "Bart")))
print(run(2, x, parent("Homer", x)))
#uses intermediate variables for complex queries
y = var()
print(run(1, x, parent(x, y), parent(y, 'Bart')))


#express the grandfather relationship seperatly using conde
def grandparent(x, z):
    y = var()
    return conde((parent(x, y), parent(y, z)))


print(run(1, x, grandparent(x, 'Bart')))
Exemplo n.º 27
0
# -*- coding: utf-8 -*-

from kanren import facts, Relation, run, var, conde, lall, lany, eq
from kanren.core import success

edges = Relation()
right = Relation()
down = Relation()
left = Relation()

facts(edges, (1, 'U', 1), (2, 'U', 2), (3, 'U', 3), (4, 'U', 1), (5, 'U', 2),
      (6, 'U', 3), (7, 'U', 4), (8, 'U', 5), (9, 'U', 6), (1, 'D', 4),
      (2, 'D', 5), (3, 'D', 6), (4, 'D', 7), (5, 'D', 8), (6, 'D', 9),
      (7, 'D', 7), (8, 'D', 8), (9, 'D', 9), (1, 'R', 2), (2, 'R', 3),
      (3, 'R', 3), (4, 'R', 5), (5, 'R', 6), (6, 'R', 6), (7, 'R', 8),
      (8, 'R', 9), (9, 'R', 9), (1, 'L', 1), (2, 'L', 1), (3, 'L', 2),
      (4, 'L', 4), (5, 'L', 4), (6, 'L', 5), (7, 'L', 7), (8, 'L', 7),
      (9, 'L', 8))

# def walk(pos, path, end_pos):
#     x = var()
#     lany(lall(eq(path, []), eq(pos, end_pos)),
#          lall(
#               edges(pos, path[0], x),
#               walk(x, path[1:], end_pos)))


def walk(pos, path, end_pos):
    if eq(path, []):
        eq(pos, end_pos)
        return success
Exemplo n.º 28
0
#asignacion de valores
from kanren import Relation, facts
parent = Relation()
grandparent=Relation()
tios = Relation()
primos=Relation()
hijos=Relation()

#relacion de padre

facts(parent, ("miguelina", "amilkar"),
             ("miguelina", "belen"),
              ("ernesto", "amilkar"),
              ("ernesto", "belen"),
              ("remi","shana"),
              ("remi","israel"),
              ("willy", "shana"),
              ("willly","israel"),
              ("barbara",  "miguelina"),
              ("barbara",  "remi"),
              ("clemente",  "miguelina"),
              ("clemente",  "remi"))
#relacion abuelos
facts(grandparent,("clemente","amilkar"),
                  ("clemente","belen"),
                  ("clemente","shana"),
                  ("clemente","israel"),
                  ("barbara","amilkar"),
                  ("barbara","belen"),
                  ("barbara","shana"),
                  ("barbara","israel")
                  )
Exemplo n.º 29
0
from kanren import run, var
from kanren import Relation, facts

I = var()  # Ingrediente
P = var()  # Plato
T = var()  # Tipo de plato
M = var()  # Malestar

es_ingred_de = Relation()
facts(es_ingred_de, ("tomate", "ensalada"), ("limon", "ensalada"),
      ("pollo", "aguadito"), ("arvejas", "aguadito"), ("zapallo", "picante"),
      ("cebolla", "picante"), ("maracuya", "helado"),
      ("saborizante", "helado"), ("aguardiente", "calientito"),
      ("te", "calientito"))

##TIPO DE ALIMENTOS
es_un_tipoalimento_de = Relation()
facts(es_un_tipoalimento_de, ("ensalada", "entrada"), ("aguadito", "sopa"),
      ("picante", "platofondo"), ("helado", "postre"),
      ("calientito", "bebida"))

##RECOMENDADO PARA
bueno_contra = Relation()
facts(bueno_contra, ("tomate", "caries"), ("limon", "gripe"),
      ("cebolla", "gripe"), ("zanahoria", "ceguera"), ("te", "stress"),
      ("maracuya", "stress"))
##EXCESO
#en_exceso_provoca(huevo, colesterol)
#en_exceso_provoca(platano, diabetes)
#en_exceso_provoca(carne, artritis)
#en_exceso_provoca(aceite, colesterol)
Exemplo n.º 30
0
    print(index, data[i - 1]["id"], data[i - 1]["firstName"],
          data[i - 1]["lastName"], data[i - 1]["jobType"])
'''
Initialize the relations and variables
'''

# Initialize the relations:
jobType = Relation()
x = var()
y = var()
z = var()
'''
store the employee data into the facts to build our relationship and constraints using the Kanren libraries
'''
for index, i in enumerate(result_id):
    facts(jobType, (data[i - 1]["jobType"], data[i - 1]["firstName"],
                    data[i - 1]["lastName"], str(data[i - 1]["id"])))
'''
print the solutions and find out how many jobtype they do correspond for each question
'''
findType = ['Engineer', 'Architect', 'Consultant', 'Producer', 'Manager']
for i in findType:
    '''
    the x,y,z are empty variables and are going to fillout as output solution and find the correlation and
    print the names of the employees that belong in that specific profession.
    '''
    output = run(0, (x, y, z), jobType(i, x, y, z))
    attributesResults = ['firstname', 'lastname', 'prime']
    print('\nList the names of the ' + i + ':')
    print('\n' + '\t'.join(attributesResults))
    print('=' * 57)
    # Extract the output
Exemplo n.º 31
0
from kanren import run, eq, membero, vars, conde, Relation, facts, var

#Austin Bradstreet, 004880497
#CS-351, 1st attempt at using Python

care = 'Austin'
shel = 'Valley of Animal Friends'

caretaker = Relation()

shelter = Relation()
facts(shelter, (shel, care))

animal_name = Relation()


def contains(s, animal):

    return conde((shelter(s, care), caretaker(care, animal)))


print('\nAnimal Shelter menu')
print('______________________')
print('1: Animal Shelter Name')
print('2: Caretaker Name')
print('3: Animals in shelter')
print('4: Add animals')
print('5: Add name to animal')
print('6: exit')
print('_______________________\n')