Exemplo n.º 1
0
def unit_quakersRepublicans():
    dick = scp.scp(epistemicStateType="dl")
    
    republican = basicLogic.atom('republican')
    quaker = basicLogic.atom('quaker')
    pacifist = basicLogic.atom('pacifist')
    
    factRepublican = basicLogic.operator_bitonic_implication(basicLogic.TRUE, republican)
    factQuaker = basicLogic.operator_bitonic_implication(basicLogic.TRUE, quaker)
    
    notPacifist = basicLogic.operator_monotonic_negation(pacifist)
    #republicans are usually not pacifists
    rule1 = basicLogic.operator_tritonic_defaultRule(republican,[notPacifist],notPacifist)
    #quakers are usually pacifists
    rule2 = basicLogic.operator_tritonic_defaultRule(quaker,[pacifist],pacifist)
    
    D = [rule1,rule2]
    W = [factRepublican,factQuaker]
    V = [republican,quaker,pacifist]
    
    dick.addDList(D)
    dick.addWList(W)
    dick.addVList(V)
    
    dick.addNext(comp_def_eval)
    
    print ("<<<<<<<<DICK>>>>>>>>>>")
    print (dick.evaluate())
Exemplo n.º 2
0
def unit_yuvalOnions():
    yuval = scp.scp(epistemicStateType="dl")
    eatonionSoup = basicLogic.atom("eatOnionSoup")
    loveEating= basicLogic.atom("loveEating")
    eatOnions=basicLogic.atom("eatOnions")
    brushTeeth=basicLogic.atom("brushTeeth")
    careForHygiene=basicLogic.atom("careForHygiene")
    
    dontEatOnions=basicLogic.operator_monotonic_negation(eatOnions)
    
    rule1=basicLogic.operator_tritonic_defaultRule(eatonionSoup,[eatOnions],eatOnions)
    rule2=basicLogic.operator_tritonic_defaultRule(eatonionSoup,[loveEating],loveEating)
    rule3=basicLogic.operator_tritonic_defaultRule(loveEating,[brushTeeth],brushTeeth)
    rule4=basicLogic.operator_tritonic_defaultRule(brushTeeth,[careForHygiene],careForHygiene)
    rule5=basicLogic.operator_tritonic_defaultRule(careForHygiene,[dontEatOnions],dontEatOnions)
    
    factEatsOnionSoup = basicLogic.operator_bitonic_implication(basicLogic.TRUE,eatonionSoup)
    
    D = [rule1,rule2,rule3,rule4,rule5]
    W = [factEatsOnionSoup]
    V =  [eatonionSoup, loveEating, eatOnions, brushTeeth, careForHygiene]
    
    yuval.addDList(D)
    yuval.addVList(V)
    yuval.addWList(W)
    
    yuval.addNext(comp_def_eval)
    
    print ("<<<<<<<<YUVAL>>>>>>>>>>")
    
    print (yuval.evaluate())    
Exemplo n.º 3
0
def example_nixon():
    DEFAULT = cop.m_default()
    W = no.stringListToBasicLogic(['( quaker <- T )', ' ( republican <- T ) '])
    #W = no.stringListToBasicLogic([' bird ', ' penguin '])

    V = no.stringListToBasicLogic(['quaker', 'republican', 'pacifist'])
    #dParts = no.stringListToBasicLogic(['( bird <- T )', '( penguin <- F ) ', '( flies <- T )'])
    dParts = no.stringListToBasicLogic(
        ['( quaker <- T )', '( pacifist <- T ) ', '( pacifist <- T )'])
    default1 = basicLogic.operator_tritonic_defaultRule(
        dParts[0], [dParts[1]], dParts[2])

    dParts2 = no.stringListToBasicLogic(
        ['( republican <- T )', '( pacifist <- F ) ', '( pacifist <- F )'])
    default2 = basicLogic.operator_tritonic_defaultRule(
        dParts2[0], [dParts2[1]], dParts2[2])
    D = [default1, default2]

    basePoint = epistemicState.epistemicState('Bird Example')
    basePoint['D'] = D
    basePoint['W'] = W
    basePoint['V'] = V

    ctm_flight = CTM.CTM()
    ctm_flight.si = [basePoint]
    ctm_flight.appendm(DEFAULT)

    print(ctm_flight)
    print(ctm_flight.evaluate())
Exemplo n.º 4
0
def example_birds():
    W = no.stringListToBasicLogic(['( bird <- T )'])

    V = no.stringListToBasicLogic(['bird', 'flies', 'penguin'])
    dParts = no.stringListToBasicLogic(
        ['( bird <- T )', '( flies <- T ) ', '( flies <- T )'])
    default1 = basicLogic.operator_tritonic_defaultRule(
        dParts[0], [dParts[1]], dParts[2])

    dParts2 = no.stringListToBasicLogic(
        ['( cold <- T )', '( flies <- F ) ', '( flies <- F )'])
    default2 = basicLogic.operator_tritonic_defaultRule(
        dParts2[0], [dParts2[1]], dParts2[2])
    D = [default1, default2]

    basePoint = epistemicState.epistemicState('Bird Example')
    basePoint['D'] = D
    basePoint['W'] = W
    basePoint['V'] = V

    ctm_flight = CTM.CTM()
    ctm_flight.si = [basePoint]
    #ctm_flight.appendm(TH)
    ctm_flight.appendm(DEFAULT)

    print(ctm_flight)
    print(ctm_flight.evaluate())
Exemplo n.º 5
0
def createRarelyRule(rule):
    rarelyIsRule = False
    rarelyIsHead = False
    isImplication = isinstance(rule, basicLogic.operator_bitonic_implication)
    rarelyIsRule = isinstance(rule, basicLogic.operator_monotonic_rarely)

    if isImplication:
        rarelyIsHead = isinstance(rule.clause2,
                                  basicLogic.operator_monotonic_rarely)

    rarelyInRightPlace = rarelyIsRule or rarelyIsHead
    if rarelyIsHead:
        c1 = rule.clause1
        c2 = basicLogic.operator_monotonic_negation(rule.clause1)
        #known to be mostly
        c3 = basicLogic.operator_monotonic_negation(rule.clause2.clause)
        r = basicLogic.operator_tritonic_defaultRule(c1, c2, c3)

        return r
    elif rarelyIsRule:
        c1 = basicLogic.TRUE
        c2 = rule.clause
        c3 = basicLogic.operator_monotonic_negation(rule.clause)
        r = basicLogic.operator_tritonic_defaultRule(c1, c2, c3)
        return r
    else:
        print("Requirement that 'mostly' is the second clause in a->m(b)")
        raise Exception()
Exemplo n.º 6
0
def example_suppression():
    W = no.stringListToBasicLogic(['( e <- T )'])
    #W = no.stringListToBasicLogic([' bird ', ' penguin '])

    V = no.stringListToBasicLogic(['e', 'l', 'o'])
    #dParts = no.stringListToBasicLogic(['( bird <- T )', '( penguin <- F ) ', '( flies <- T )'])
    dParts1 = no.stringListToBasicLogic(
        ['( e <- T )', '( ab1 <- F ) ', '( l <- T )'])
    default1 = basicLogic.operator_tritonic_defaultRule(
        dParts1[0], [dParts1[1]], dParts1[2])

    dParts2 = no.stringListToBasicLogic(
        ['( o <- T )', '( ab2 <- F ) ', '( l <- T )'])
    default2 = basicLogic.operator_tritonic_defaultRule(
        dParts2[0], [dParts2[1]], dParts2[2])

    dParts3 = no.stringListToBasicLogic(
        ['( o <- F )', '( ab1 <- T ) ', '( ab1 <- T )'])
    default3 = basicLogic.operator_tritonic_defaultRule(
        dParts3[0], [dParts3[1]], dParts3[2])

    dParts4 = no.stringListToBasicLogic(
        ['( e <- F )', '( ab2 <- T ) ', '( ab2 <- T )'])
    default4 = basicLogic.operator_tritonic_defaultRule(
        dParts4[0], [dParts4[1]], dParts4[2])

    D = [default1, default2, default3, default4]

    basePoint = epistemicState.epistemicState('Bird Example')
    basePoint['D'] = D
    basePoint['W'] = W
    basePoint['V'] = V

    ctm_flight = CTM.CTM()
    ctm_flight.si = [basePoint]
    #ctm_flight.appendm(TH)
    ctm_flight.appendm(DEFAULT)

    print(ctm_flight)
    print(ctm_flight.evaluate())
Exemplo n.º 7
0
def unit_tweetyAndChilly ():
    #create the two birds as individual scps
    tweety = scp.scp(epistemicStateType="dl")
    chilly = scp.scp(epistemicStateType="dl")
    
    #variables
    flies = basicLogic.atom('flies')
    bird = basicLogic.atom('bird')  
    
    notflies = basicLogic.operator_monotonic_negation(flies)
    #the only inference rule
    rule1 = basicLogic.operator_tritonic_defaultRule(bird,[flies],flies)
    
    fact_bird = basicLogic.operator_bitonic_implication(basicLogic.TRUE, bird)
    factNotFlies = basicLogic.operator_bitonic_implication(basicLogic.TRUE, notflies)
    #the set of concrete rules
    W_tweety=[fact_bird]
    W_chilly=[fact_bird,factNotFlies]
    #in this case both tweety and chilly share the same inference rules
    D = [rule1]
    V = [flies,bird]
    #create wteety
    tweety.addDList(D)
    tweety.addVList(V)
    tweety.addWList(W_tweety)
    #create chilly
    chilly.addDList(D)
    chilly.addVList(V)
    chilly.addWList(W_chilly)
    #add the complex operator for evaluating default rules
    tweety.addNext(comp_def_eval)
    chilly.addNext(comp_def_eval)
    print ("<<<<<<<<TWEETY>>>>>>>>>>")
    print (tweety.evaluate())
    
    
    print (chilly.evaluate())