Ejemplo n.º 1
0
from logpy import run, var, conde, Relation, facts
parent = Relation()
facts(parent, ('Homer', 'Lisa'), ('Homer', 'Bart'), ('Abe', 'Homer'))

x = var()
y = var()
print(run(1, x, parent(x, 'Bart')))
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')))
Ejemplo n.º 2
0
    temp = var()
    return conde((father(temp, x), grandparent(temp, y)))

def grandmother(x, y):
    temp = var()
    return conde((mother(x, temp), parent(temp, y)))

if __name__ == '__main__':
    father = Relation()
    mother = Relation()

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

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

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

    x = var()

    # John's children
    '''name = 'John'
    output = run(0, x, father(name, x))
    print("\nList of " + name + "'s children:")
    for item in output:
        print(item)
    # William's mother
    name = 'William'
    output = run(0, x, mother(x, name))[0]
Ejemplo n.º 3
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 logpy 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)])
Ejemplo n.º 4
0
from logpy import run, var, conde, Relation, facts
parent = Relation()
facts(parent, ('Homer', 'Lisa'),
      ('Homer', 'Bart'),
      ('Abe', 'Homer'))

x = var()
y = var()
print(run(1, x, parent(x, 'Bart')))
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')))


Ejemplo n.º 5
0
def cal_relation():
    txt.delete(0.0, 'end')
    name = e1.get()
    name2 = e2.get()
    if __name__ == '__main__':
        Root = Relation()
    with open('project.json') as f:
        d = json.loads(f.read())

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

    x = var()

    # Depository
    if (name == 'Depository' or name2 == 'Depository'):
        if (name == 'Depository'):
            output = run(0, x, Root(name, x))
        else:
            output = run(0, x, Root(name2, x))

        ##print("\nList of " + name + "'s children:")
        for item in output:
            if ((name2 == "Stock Exchange" and name == "Depository")
                    or (name == "Stock Exchange" and name2 == "Depository")):
                txt.insert(
                    END,
                    "It is regulator of Shares where all the Share of Stock exchange are strored"
                )
                break
            if ((name2 == "Customer" and name == "Depository")
                    or (name == "Customer" and name2 == "Depository")):
                txt.insert(
                    END,
                    "Individual Shares of Each Person are Contained by depository"
                )
                break
            if ((name2 == "Broker" and name == "Depository")
                    or (name == "Broker" and name2 == "Depository")):
                txt.insert(
                    END,
                    "A stock broker connects the buyers and sellers of stocks,While a depository participant is described as an agent of the depository"
                )
                break
            if ((name2 == "Divident" and name == "Depository")
                    or (name == "Divident" and name2 == "Depository")):
                txt.insert(
                    END,
                    "Globally, distribution of dividends is by depositories")
                break
            else:
                txt.insert(
                    END,
                    "This relationship is Not Defined Directly or may be some Alphabeticall Error"
                )
                break

    #Customer
    elif (name == 'Customer' or name2 == 'Customer'):
        if (name == 'Customer'):
            output = run(0, x, Root(name, x))
        else:
            output = run(0, x, Root(name2, x))

        ##print("\nList of " + name + "'s children:")
        for item in output:
            if ((name2 == "Stock Exchange" and name == "Customer")
                    or (name == "Stock Exchange" and name2 == "Customer")):
                txt.insert(
                    END,
                    "Stock exchange is a place where the trading is executed and from here Customer get the idea to buy any share or not"
                )
                break
            if ((name2 == "Seller" and name == "Customer")
                    or (name == "Seller" and name2 == "Customer")):
                txt.insert(
                    END,
                    "Seller who sells and Customer who are ready to buy the shares"
                )
                break
            if ((name2 == "Divident" and name == "Customer")
                    or (name == "Divident" and name2 == "Customer")):
                txt.insert(
                    END,
                    "After Earning From the shares as a profit we get a divident as we get a interest in Banks"
                )
                break
            if ((name2 == "DEMAT ACC." and name == "Customer")
                    or (name == "DEMAT ACC." and name2 == "Customer")):
                txt.insert(
                    END,
                    "Where Customer Can go through the detail of the personal invested shares through Demat Account"
                )
                break
            if ((name2 == "Broker" and name == "Customer")
                    or (name == "Broker" and name2 == "Customer")):
                txt.insert(
                    END,
                    "Who acts as a intermediate between Customer and Stock market and helps him to invest in shares"
                )
                break
            if ((name2 == "Registrar" and name == "Customer")
                    or (name == "Registrar" and name2 == "Customer")):
                txt.insert(
                    END,
                    "A registrar is a bank or a similar company that is responsible for recordkeeping of bondholders and shareholders. "
                )
                break
            else:
                txt.insert(
                    END,
                    "This relationship is Not Defined Directly or may be some Alphabeticall Error"
                )
                break

    #Demat Acc.
    elif (name == "DEMAT ACC." or name2 == "DEMAT ACC."):
        if (name == "DEMAT ACC."):
            output = run(0, x, Root(name, x))
        else:
            output = run(0, x, Root(name2, x))

        ##print("\nList of " + name + "'s children:")
        for item in output:
            if ((name2 == "Seller" and name == "DEMAT ACC.")
                    or (name == "Seller" and name2 == "DEMAT ACC.")):
                txt.insert(
                    END,
                    "Seller sells their share after it collect the remaining shares informtion from DEMAT Account"
                )
                break
            if ((name2 == "Divident" and name == "DEMAT ACC.")
                    or (name == "Divident" and name2 == "DEMAT ACC.")):
                txt.insert(
                    END,
                    "Divident is Generated only u have Demat acc. becoz it contain all your information"
                )
                break
            if ((name2 == "Broker" and name == "DEMAT ACC.")
                    or (name == "Broker" and name2 == "DEMAT ACC.")):
                txt.insert(
                    END,
                    "Broker Provide you the Demat Account Where u get the information of all Shares"
                )
                break
            if ((name2 == "Stock Exchange" and name == "DEMAT ACC.")
                    or (name == "Stock Exchange" and name2 == "DEMAT ACC.")):
                txt.insert(
                    END,
                    "After invested in Shares with the help of Stock exchange we are ready to update our Demat Account"
                )
                break
            else:
                txt.insert(
                    END,
                    "This relationship is Not Defined Directly or may be some Alphabeticall Error"
                )
                break

    #Clearing House
    elif (name == "Clearing House" or name2 == "Clearing House"):
        if (name == "Clearing House"):
            output = run(0, x, Root(name, x))
        else:
            output = run(0, x, Root(name2, x))

        ##print("\nList of " + name + "'s children:")
        for item in output:
            if ((name2 == "Stock Exchange" and name == "Clearing House") or
                (name == "Stock Exchange" and name2 == "Clearing House")):
                txt.insert(
                    END,
                    "A clearing house acts as an intermediary between a buyer and seller and seeks to ensure that the process from trade inception to settlement is smooth."
                )
                break
            else:
                txt.insert(
                    END,
                    "This relationship is Not Defined Directly or may be some Alphabeticall Error"
                )
                break
    #Divident
    elif (name == "Divident" or name2 == "Divident"):
        if (name == "Divident"):
            output = run(0, x, Root(name, x))
        else:
            output = run(0, x, Root(name2, x))

        ##print("\nList of " + name + "'s children:")
        for item in output:
            if ((name2 == "Registrar" and name == "Divident")
                    or (name == "Registrar" and name2 == "Divident")):
                txt.insert(
                    END,
                    "The registrar determines which shareholders are paid a cash or stock dividend."
                )
                break
            else:
                txt.insert(
                    END,
                    "This relationship is Not Defined Directly or may be some Alphabeticall Error"
                )
                break
    else:
        txt.insert(
            END,
            "This relationship is Not Defined Directly or may be some Alphabeticall Error"
        )
Ejemplo n.º 6
0
def daughter(x, y):
    return ((parents(x, y), Female(y)))


Father = Relation()

Mother = Relation()

Male = Relation()

Female = Relation()

Couple = Relation()

facts(Couple, ('john', 'megan'), ('william', 'emma'), ('david', 'olivia'),
      ('adam', 'lily'))
facts(
    Father,
    ('john', 'william'),
    ('john', 'david'),
    ('john', 'adam'),
    ('william', 'rahul'),
    ('william', 'krish'),
    ('william', 'soni'),
    ('david', 'ben'),
    ('david', 'nisha'),
    ('david', 'julie'),
    ('david', 'neil'),
    ('david', 'peter'),
    ('adam', 'richa'),
)
Ejemplo n.º 7
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 logpy 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'))
Ejemplo n.º 8
0
from logpy import facts, Relation
computes = Relation('computes')
facts(computes, *patterns)
Ejemplo n.º 9
0
def start_main():
    def parents(x, y):
        return conde([Father(x, y)], [Mother(x, y)])

    def grandparents(x, y):
        z = var()
        return conde((parents(x, z), parents(z, y)))

    def grandfather(x, y):
        z = var()
        return conde((grandparents(x, y), Male(x)))

    def grandmother(x, y):
        z = var()
        return conde((grandparents(x, y), Female(x)))

    def uncle(m, y):
        z = var()
        x = var()
        return conde((Father(x, z), Father(x, m), Father(z, y), Male(m)))

    def sibling(x, y):
        z = var()
        return conde((parents(z, x), parents(z, y)))

    def brother(x, y):
        z = var()
        return conde((parents(z, x), parents(z, y), Male(x)))

    def sister(x, y):
        z = var()
        return conde((parents(z, x), parents(z, y), Female(x)))

    def aunty(x, y):
        z = var()
        return conde((uncle(z, y), Couple(z, x), Female(x)))

    def children(x, y):
        return ((parents(x, y)))

    def son(x, y):
        return ((parents(x, y), Male(y)))

    def daughter(x, y):
        return ((parents(x, y), Female(y)))

    global choice

    Father = Relation()

    Mother = Relation()

    Male = Relation()

    Female = Relation()

    Couple = Relation()

    facts(Couple, ('john', 'megan'),
          ('william', 'emma'),
          ('david', 'olivia'),
          ('adam', 'lily'))
    facts(Father, ('john', 'william'),
          ('john', 'david'),
          ('john', 'adam'),
          ('william', 'chris'),
          ('william', 'stephaine'),
          ('david', 'wayne'),
          ('david', 'tiffany'),
          ('david', 'julie'),
          ('david', 'neil'),
          ('david', 'peter'),
          ('adam', 'sophia'))

    facts(Mother, ('megan', 'william'),
          ('megan', 'david'),
          ('megan', 'adam'),
          ('emma', 'chris'),
          ('emma', 'stephaine'),
          ('olivia', 'wayne'),
          ('olivia', 'tiffany'),
          ('olivia', 'julie'),
          ('olivia', 'neil'),
          ('olivia', 'peter'),
          ('lily', 'sophia'))

    fact(Male, 'john')
    fact(Male, 'william')
    fact(Male, 'david')
    fact(Male, 'adam')
    fact(Male, 'chris')
    fact(Male, 'wayne')
    fact(Male, 'neil')
    fact(Male, 'peter')

    fact(Female, 'megan')
    fact(Female, 'emma')
    fact(Female, 'tiffany')
    fact(Female, 'julie')
    fact(Female, 'olivia')
    fact(Female, 'sophia')
    fact(Female, 'lily')
    fact(Female, 'stephaine')

    x = var()
    y = var()
    z = var()
    #
    # print(
    #     color.Bold + "---------------------------------Welcome to Relation Predicting Program------------------------------" + color.End + "\n\n")
    # print(
    #     color.Bold + "-----------------------------------------------------------------------------Created by:" + color.End,
    #     color.Darkcyan + color.Bold + "RUPESH YADAV" + color.End, "\n\n")
    # print("-----------------------------------------------------------------------------------------------------")
    # print(color.Bold + color.Blue + "Enter The Name Below From Above To Know There Realtives" + color.End)
    # print("-----------------------------------------------------------------------------------------------------")
    # print(color.Red + "1)JOHN\n2)WILLIAM\n3)DAVID\n4)ADAM\n5)CHRIS\n6)WAYNE\n7)NEIL\n8)PETER\n" + color.End)
    # print(
    #     color.Green + "9)MEGAN\n10)EMMA\n11)TIFFANY\n12)JULIE\n13)OLIVIA\n14)SOPHIA\n15)LILY\n16)STEPHAINE" + color.End)

    NameList = ['john', 'megan',
                'william', 'emma',
                'david', 'olivia',
                'adam', 'lily',
                'peter', 'neil',
                'sophia', 'julie',
                'tiffany', 'stephaine',
                'wayne', 'chris']

    name = input()
    FakeName = name.upper()
    name = name.lower()
    if name in NameList:
        print(color.Red + "Which Realtion Of" + color.End,
              color.Cyan + color.Bold + color.Underline + FakeName + color.End,
              color.Red + "You want to know?" + color.End)

        print(
            color.Blue + "1)PARENT\n2)SIBLING\n3)GRANDPARENT\n)4)UNCLE\n5)AUNTY\n6)CHILDREN\n7)COUPLE\n\n" + color.End)

        Relat = input()
        Relat = Relat.lower()
        if Relat == 'parent':
            print(
                color.Yellow + "Press 1 To Know The Name of Both Parent\nPress 2 To Know The Name Of Mother\nPress 3 To Know The Name Of Father" + color.End)
            option = int(input())
            if option == 1:
                out = (run(0, x, parents(x, name)))
            elif option == 2:
                out = (run(0, x, Mother(x, name)))
            else:
                out = (run(1, x, Father(x, name)))
            if len(out) == 0:
                print(color.Cyan + color.Bold + color.Underline + FakeName + color.End,
                      color.Green + "Parent Details Not In DataBase---SORRY" + color.End)
            else:
                print(out)
        elif Relat == 'sibling':
            print(
                color.Yellow + "Press 1 To Know The Name of Both Gender Sibling\nPress 2 To Know The Name Of Sisters\nPress 3 To Know The Name Of Brother" + color.End)
            option = int(input())
            if option == 1:
                out = (run(0, x, sibling(x, name)))
            elif option == 2:
                out = (run(1, x, sister(x, name)))
            else:
                out = (run(1, x, brother(x, name)))
            list1 = list(out)

            if name in list1:
                list1.remove(name)

            if len(list1) == 0:
                print(color.Cyan + color.Bold + color.Underline + FakeName + color.End,
                      color.Green + "Does not have Entered type sibling ---SORRY" + color.End)
            else:
                print(list1)
        elif Relat == 'grandparent':
            print(
                color.Yellow + "Press 1 To Know The Name of Both Grandmaa and Grandpaa\nPress 2 To Know The Name Of GrandFather\nPress 3 To Know The Name Of GrandMother" + color.End)
            option = int(input())
            if option == 1:
                out = (run(0, x, grandparents(x, name)))
            elif option == 2:
                out = (run(1, x, grandfather(x, name)))
            else:
                out = (run(1, x, grandmother(x, name)))
            list1 = list(out)

            if name in list1:
                list1.remove(name)

            if len(list1) == 0:
                print(color.Cyan + color.Bold + color.Underline + FakeName + color.End,
                      color.Green + "Does not have GrandParent data ---SORRY" + color.End)
            else:
                print(list1)
        elif Relat == 'uncle':
            out1 = run(1, x, Father(x, name))
            out = run(0, x, uncle(x, name))
            a = out1[0]
            list1 = list(out)
            if a in list1:
                list1.remove(a)
            print(list1)
        elif Relat == 'aunty':
            out = (run(0, x, aunty(x, name)))
            out1 = run(0, x, Mother(x, name))
            list1 = list(out)
            a = out1[0]
            if a in list1:
                list1.remove(a)
            print(list1)
        elif Relat == 'children':
            print(run(0, x, children(name, x)))
        elif Relat == 'couple':
            print(run(1, x, Couple(x, name)))
        else:
            print(color.Red + "The Relation You Is Wrong Or May Not Be In Database" + color.End)

    else:
        print(color.Blue + "The Name" + color.End, color.Red + color.Underline + FakeName + color.End,
              color.Blue + "You Have Entered Is Not In The DataBase" + color.End)