Ejemplo n.º 1
0
def populate(engine):
    This_rule_base = engine.get_create('fb_checkin_fc')

    fc_rule.fc_rule('prior', This_rule_base, prior, (('fb_checkin', 'prior', (
        contexts.variable('node'),
        contexts.variable('value'),
    ), False), ), (
        contexts.variable('node'),
        pattern.pattern_literal(0),
    ))

    fc_rule.fc_rule('inc_num_samples', This_rule_base, inc_num_samples,
                    (('fb_checkin', 'inc_num_samples', (
                        contexts.variable('node'),
                        contexts.variable('value'),
                        contexts.variable('prob'),
                    ), False), ), (
                        contexts.variable('node'),
                        contexts.variable('value'),
                        pattern.pattern_literal(0),
                    ))

    fc_rule.fc_rule('inc_num_features', This_rule_base, inc_num_features,
                    (('fb_checkin', 'inc_num_features', (
                        contexts.variable('node'),
                        contexts.variable('value'),
                        contexts.variable('prob'),
                    ), False), ), (
                        contexts.variable('node'),
                        contexts.variable('value'),
                        pattern.pattern_literal(0),
                    ))

    fc_rule.fc_rule('accuracy', This_rule_base, accuracy,
                    (('fb_checkin', 'accuracy',
                      (contexts.variable('new_value'), ), False), ),
                    (contexts.variable('new_value'), ))

    fc_rule.fc_rule('sample_size', This_rule_base, sample_size,
                    (('fb_checkin', 'sample_size', (
                        contexts.variable('node'),
                        contexts.variable('value'),
                    ), False), ), (
                        contexts.variable('node'),
                        contexts.variable('value'),
                    ))

    fc_rule.fc_rule('feature', This_rule_base, feature,
                    (('fb_checkin', 'feature', (
                        contexts.variable('node'),
                        contexts.variable('value'),
                    ), False), ), (
                        contexts.variable('node'),
                        contexts.variable('value'),
                    ))

    fc_rule.fc_rule('threshold', This_rule_base, threshold,
                    (('fb_checkin', 'threshold',
                      (contexts.variable('value'), ), False), ),
                    (contexts.variable('value'), ))
Ejemplo n.º 2
0
def populate(engine):
    This_rule_base = engine.get_create('key_rules')

    fc_rule.fc_rule('take', This_rule_base, take, (
        ('chest', 'closed', (pattern.pattern_literal(False), ), False),
        ('key', 'inChest', (pattern.pattern_literal(True), ), False),
    ), (pattern.pattern_literal(False), ))
def make_pattern(x):
    if isinstance(x, str):
        if x[0] == '$': return contexts.variable(x[1:])
        return pattern.pattern_literal(x)
    if isinstance(x, (tuple, list)):
        return pattern.pattern_tuple(
            tuple(make_pattern(element) for element in x))
    return pattern.pattern_literal(x)
Ejemplo n.º 4
0
def make_pattern(x):
    if isinstance(x, types.StringTypes):
        if x[0] == "$":
            return contexts.variable(x[1:])
        return pattern.pattern_literal(x)
    if isinstance(x, (tuple, list)):
        return pattern.pattern_tuple(tuple(make_pattern(element) for element in x))
    return pattern.pattern_literal(x)
Ejemplo n.º 5
0
def populate(engine):
  This_rule_base = engine.get_create('door_rules')
  
  fc_rule.fc_rule('open', This_rule_base, open,
    (('door', 'hasKey',
      (pattern.pattern_literal(True),),
      False),),
    (pattern.pattern_literal(False),))
Ejemplo n.º 6
0
def populate(engine):
  This_rule_base = engine.get_create('chest_rules')
  
  fc_rule.fc_rule('open', This_rule_base, open,
    (('chest', 'closed',
      (pattern.pattern_literal(True),),
      False),),
    (pattern.pattern_literal(False),))
Ejemplo n.º 7
0
def populate(engine):
  This_rule_base = engine.get_create('key_rules')
  
  fc_rule.fc_rule('take', This_rule_base, take,
    (('chest', 'closed',
      (pattern.pattern_literal(False),),
      False),
     ('key', 'inChest',
      (pattern.pattern_literal(True),),
      False),),
    (pattern.pattern_literal(False),))
Ejemplo n.º 8
0
def populate(engine):
  This_rule_base = engine.get_create('key')
  
  bc_rule.bc_rule('take', This_rule_base, 'take',
                  take, None,
                  (),
                  (),
                  (pattern.pattern_literal(True),))
  
  bc_rule.bc_rule('eat', This_rule_base, 'eat',
                  eat, None,
                  (),
                  (),
                  ())
  
  bc_rule.bc_rule('poop', This_rule_base, 'poop',
                  poop, None,
                  (),
                  (),
                  ())
  
  bc_rule.bc_rule('drop', This_rule_base, 'drop',
                  drop, None,
                  (),
                  (),
                  ())
Ejemplo n.º 9
0
def populate(engine):
    This_rule_base = engine.get_create('door')

    bc_rule.bc_rule('open', This_rule_base, 'open', open, None, (), (),
                    (pattern.pattern_literal(True), ))

    bc_rule.bc_rule('kick', This_rule_base, 'open', kick, None, (), (), ())
def populate(engine):
  This_rule_base = engine.get_create('off_state_rules')
  
  fc_rule.fc_rule('init_rule', This_rule_base, init_rule,
    (('off_state_questions', 'beep_question',
      (contexts.variable('ans'),),
      False),),
    (contexts.variable('ans'),))
  
  fc_rule.fc_rule('ram_yes_rule', This_rule_base, ram_yes_rule,
    (('off_state_facts', 'beep_answer',
      (pattern.pattern_literal(True),),
      False),),
    ())
  
  fc_rule.fc_rule('ram_no_rule', This_rule_base, ram_no_rule,
    (('off_state_facts', 'beep_answer',
      (pattern.pattern_literal(False),),
      False),),
    (pattern.pattern_literal('speaker'),))
  
  fc_rule.fc_rule('speaker_rule', This_rule_base, speaker_rule,
    (('off_state_facts', 'problem_from',
      (pattern.pattern_literal('speaker'),),
      False),
     ('off_state_questions', 'speaker_question',
      (contexts.variable('ans'),),
      False),),
    (contexts.variable('ans'),))
  
  fc_rule.fc_rule('speaker_yes_rule', This_rule_base, speaker_yes_rule,
    (('off_state_facts', 'speaker_answer',
      (pattern.pattern_literal(True),),
      False),
     ('off_state_questions', 'monitor_check_question',
      (contexts.variable('ans'),),
      False),),
    (contexts.variable('ans'),))
  
  fc_rule.fc_rule('speaker_no_rule', This_rule_base, speaker_no_rule,
    (('off_state_facts', 'speaker_answer',
      (pattern.pattern_literal(False),),
      False),),
    ())
  
  fc_rule.fc_rule('monitor_yes_rule', This_rule_base, monitor_yes_rule,
    (('off_state_facts', 'monitor_answer',
      (pattern.pattern_literal(True),),
      False),),
    ())
  
  fc_rule.fc_rule('monitor_no_rule', This_rule_base, monitor_no_rule,
    (('off_state_facts', 'monitor_answer',
      (pattern.pattern_literal(False),),
      False),),
    ())
Ejemplo n.º 11
0
def populate(engine):
  This_rule_base = engine.get_create('krbparse_test')
  
  fc_rule.fc_rule('name1', This_rule_base, name1,
    (('a', 'b',
      (pattern.pattern_literal('x'),
       contexts.variable('b'),),
      False),),
    (contexts.variable('b'),))
Ejemplo n.º 12
0
def p_pattern_tuple2(p):
    ''' pattern_proper : LP_TOK data_list ',' '*' variable RP_TOK '''
    if goal_mode:
        p[0] = pattern.pattern_tuple(
            tuple(pattern.pattern_literal(x) for x in p[2]), p[5])
    else:
        p[0] = "pattern.pattern_tuple((%s), %s)" % \
                   (' '.join("pattern.pattern_literal(%s)," % str(x)
                             for x in p[2]),
                    p[5])
Ejemplo n.º 13
0
def p_pattern_tuple2(p):
    ''' pattern_proper : LP_TOK data_list ',' '*' variable RP_TOK '''
    if goal_mode:
        p[0] = pattern.pattern_tuple(
                 tuple(pattern.pattern_literal(x) for x in p[2]),
                 p[5])
    else:
        p[0] = "pattern.pattern_tuple((%s), %s)" % \
                   (' '.join("pattern.pattern_literal(%s)," % str(x)
                             for x in p[2]),
                    p[5])
Ejemplo n.º 14
0
def p_pattern_tuple3(p):
    ''' pattern_proper : LP_TOK data_list ',' patterns_proper rest_opt RP_TOK '''
    if goal_mode:
        p[0] = pattern.pattern_tuple(
            tuple(
                itertools.chain((pattern.pattern_literal(x) for x in p[2]),
                                p[4])), p[5])
    else:
        p[0] = "pattern.pattern_tuple((%s), %s)" % \
                   (' '.join(itertools.chain(
                               ("pattern.pattern_literal(%s)," % str(x)
                                 for x in p[2]),
                               (str(x) + ',' for x in p[4]))),
                    p[5])
Ejemplo n.º 15
0
def populate(engine):
  This_rule_base = engine.get_create('chest')
  
  bc_rule.bc_rule('open', This_rule_base, 'open',
                  open, None,
                  (),
                  (),
                  (pattern.pattern_literal(True),))
  
  bc_rule.bc_rule('kick', This_rule_base, 'kick',
                  kick, None,
                  (),
                  (),
                  ())
Ejemplo n.º 16
0
def populate(engine):
  This_rule_base = engine.get_create('deseases')
  
  bc_rule.bc_rule('dengue_package', This_rule_base, 'desease',
                  dengue_package, None,
                  (pattern.pattern_literal('dengue'),
                   contexts.variable('u'),),
                  (),
                  ())
  
  bc_rule.bc_rule('dengue_not_chikungunha', This_rule_base, 'desease',
                  dengue_not_chikungunha, None,
                  (pattern.pattern_literal('dengue'),
                   contexts.variable('u'),),
                  (),
                  ())
  
  bc_rule.bc_rule('zika_package', This_rule_base, 'desease',
                  zika_package, None,
                  (pattern.pattern_literal('zika'),
                   contexts.variable('u'),),
                  (),
                  ())
  
  bc_rule.bc_rule('zika_not_chikungunha', This_rule_base, 'desease',
                  zika_not_chikungunha, None,
                  (pattern.pattern_literal('zika'),
                   contexts.variable('u'),),
                  (),
                  ())
  
  bc_rule.bc_rule('zika_itching', This_rule_base, 'desease',
                  zika_itching, None,
                  (pattern.pattern_literal('zika'),
                   contexts.variable('u'),),
                  (),
                  ())
  
  bc_rule.bc_rule('chikungunha_package', This_rule_base, 'desease',
                  chikungunha_package, None,
                  (pattern.pattern_literal('chikungunha'),
                   contexts.variable('u'),),
                  (),
                  ())
  
  bc_rule.bc_rule('chikungunha_not_dengue', This_rule_base, 'desease',
                  chikungunha_not_dengue, None,
                  (pattern.pattern_literal('chikungunha'),
                   contexts.variable('u'),),
                  (),
                  ())
Ejemplo n.º 17
0
def p_pattern_tuple3(p):
    ''' pattern_proper : LP_TOK data_list ',' patterns_proper rest_opt RP_TOK '''
    if goal_mode:
        p[0] = pattern.pattern_tuple(
                 tuple(itertools.chain(
                         (pattern.pattern_literal(x) for x in p[2]),
                         p[4])),
                 p[5])
    else:
        p[0] = "pattern.pattern_tuple((%s), %s)" % \
                   (' '.join(itertools.chain(
                               ("pattern.pattern_literal(%s)," % str(x)
                                 for x in p[2]),
                               (str(x) + ',' for x in p[4]))),
                    p[5])
Ejemplo n.º 18
0
 def gen():
     context = contexts.simple_context()
     vars = self._Variables[:num_returns]
     try:
         with self.prove(kb_name, entity_name, context,
                         tuple(pattern.pattern_literal(arg)
                               for arg in fixed_args) + vars) \
           as it:
             for plan in it:
                 final = {}
                 ans = tuple(context.lookup_data(var.name, final = final)
                             for var in vars)
                 if plan: plan = plan.create_plan(final)
                 yield ans, plan
     finally:
         context.done()
Ejemplo n.º 19
0
 def gen():
     context = contexts.simple_context()
     vars = self._Variables[:num_returns]
     try:
         with self.prove(kb_name, entity_name, context,
                         tuple(pattern.pattern_literal(arg)
                               for arg in fixed_args) + vars) \
           as it:
             for plan in it:
                 final = {}
                 ans = tuple(context.lookup_data(var.name, final = final)
                             for var in vars)
                 if plan: plan = plan.create_plan(final)
                 yield ans, plan
     finally:
         context.done()
Ejemplo n.º 20
0
def as_pattern(data):
    if isinstance(data, tuple) and is_pattern(data):
        if is_rest_var(data[-1]):
            name = data[-1][2:]
            if name[0] == '_':
                rest_var = contexts.anonymous(name)
            else:
                rest_var = contexts.variable(name)
            return pattern.pattern_tuple(
                tuple(as_pattern(element) for element in data[:-1]), rest_var)
        return pattern.pattern_tuple(
            tuple(as_pattern(element) for element in data))
    if isinstance(data, (str, )) and is_pattern(data):
        name = data[1:]
        if name[0] == '_': return contexts.anonymous(name)
        return contexts.variable(name)
    return pattern.pattern_literal(data)
Ejemplo n.º 21
0
def as_pattern(data):
    if isinstance(data, tuple) and is_pattern(data):
        if is_rest_var(data[-1]):
            name = data[-1][2:]
            if name[0] == '_':
                rest_var = contexts.anonymous(name)
            else:
                rest_var = contexts.variable(name)
            return pattern.pattern_tuple(tuple(as_pattern(element)
                                               for element in data[:-1]),
                                         rest_var)
        return pattern.pattern_tuple(tuple(as_pattern(element)
                                           for element in data))
    if isinstance(data, types.StringTypes) and is_pattern(data):
        name = data[1:]
        if name[0] == '_': return contexts.anonymous(name)
        return contexts.variable(name)
    return pattern.pattern_literal(data)
Ejemplo n.º 22
0
def p_pattern(p):
    ''' pattern : data '''
    if goal_mode:
        p[0] = pattern.pattern_literal(p[1])
    else:
        p[0] = "pattern.pattern_literal(%s)" % str(p[1])
Ejemplo n.º 23
0
def populate(engine):
  This_rule_base = engine.get_create('krbparse_test')
  
  bc_rule.bc_rule('name2', This_rule_base, 'x',
                  name2, krbparse_test_plans.name2,
                  (pattern.pattern_literal(1),
                   contexts.variable('c'),
                   pattern.pattern_literal((1, 'b',)),
                   pattern.pattern_tuple((pattern.pattern_literal(1), pattern.pattern_literal('b'), contexts.variable('c'),), None),),
                  ('plan', 'd',),
                  (pattern.pattern_literal('x'),
                   contexts.variable('c'),
                   contexts.variable('plan#1'),
                   pattern.pattern_literal(1),
                   pattern.pattern_literal(2),
                   pattern.pattern_literal(3),
                   contexts.variable('plan#2'),))
  
  bc_rule.bc_rule('name3', This_rule_base, 'x',
                  name3, krbparse_test_plans.name3,
                  (pattern.pattern_literal(1),
                   contexts.variable('c'),
                   pattern.pattern_literal((1, 'b',)),
                   pattern.pattern_tuple((pattern.pattern_literal(1), pattern.pattern_literal('b'), contexts.variable('c'),), None),),
                  ('d',),
                  (pattern.pattern_literal('x'),
                   contexts.variable('c'),
                   contexts.variable('plan#1'),
                   pattern.pattern_literal(1),
                   pattern.pattern_literal(2),
                   pattern.pattern_literal(3),
                   contexts.variable('foo_fn'),))
Ejemplo n.º 24
0
def populate(engine):
    This_rule_base = engine.get_create('example')

    fc_rule.fc_rule('son_of', This_rule_base, son_of, (('family', 'son_of', (
        contexts.variable('child'),
        contexts.variable('father'),
        contexts.variable('mother'),
    ), False), ), (
        contexts.variable('child'),
        contexts.variable('father'),
        pattern.pattern_literal('father'),
        pattern.pattern_literal('son'),
        contexts.variable('mother'),
        pattern.pattern_literal('mother'),
    ))

    fc_rule.fc_rule('daughter_of', This_rule_base, daughter_of,
                    (('family', 'daughter_of', (
                        contexts.variable('child'),
                        contexts.variable('father'),
                        contexts.variable('mother'),
                    ), False), ), (
                        contexts.variable('child'),
                        contexts.variable('father'),
                        pattern.pattern_literal('father'),
                        pattern.pattern_literal('daughter'),
                        contexts.variable('mother'),
                        pattern.pattern_literal('mother'),
                    ))

    fc_rule.fc_rule('brothers', This_rule_base, brothers, (
        ('family', 'son_of', (
            contexts.variable('brother1'),
            contexts.variable('father'),
            contexts.variable('mother'),
        ), False),
        ('family', 'son_of', (
            contexts.variable('brother2'),
            contexts.variable('father'),
            contexts.variable('mother'),
        ), False),
    ), (
        contexts.variable('brother1'),
        contexts.variable('brother2'),
        pattern.pattern_literal('brother'),
    ))

    fc_rule.fc_rule('sisters', This_rule_base, sisters, (
        ('family', 'daughter_of', (
            contexts.variable('sister1'),
            contexts.variable('father'),
            contexts.variable('mother'),
        ), False),
        ('family', 'daughter_of', (
            contexts.variable('sister2'),
            contexts.variable('father'),
            contexts.variable('mother'),
        ), False),
    ), (
        contexts.variable('sister1'),
        contexts.variable('sister2'),
        pattern.pattern_literal('sister'),
    ))

    fc_rule.fc_rule('brother_and_sister', This_rule_base, brother_and_sister, (
        ('family', 'son_of', (
            contexts.variable('brother'),
            contexts.variable('father'),
            contexts.variable('mother'),
        ), False),
        ('family', 'daughter_of', (
            contexts.variable('sister'),
            contexts.variable('father'),
            contexts.variable('mother'),
        ), False),
    ), (
        contexts.variable('brother'),
        contexts.variable('sister'),
        pattern.pattern_literal('sister'),
        pattern.pattern_literal('brother'),
    ))

    fc_rule.fc_rule('facts_for_bc_rules', This_rule_base, facts_for_bc_rules,
                    (), (
                        pattern.pattern_literal('brother'),
                        pattern.pattern_literal('uncle'),
                        pattern.pattern_literal('sister'),
                        pattern.pattern_literal('aunt'),
                        pattern.pattern_literal('son'),
                        pattern.pattern_literal('nephew'),
                        pattern.pattern_literal('daughter'),
                        pattern.pattern_literal('niece'),
                    ))
Ejemplo n.º 25
0
def populate(engine):
    This_rule_base = engine.get_create('fc_rules')

    fc_rule.fc_rule('gender', This_rule_base, gender, (
        ('famous', 'knownFor', (
            contexts.variable('person'),
            contexts.variable('status'),
        ), False),
        ('famous', 'gender', (
            contexts.variable('person'),
            contexts.variable('gender'),
        ), True),
    ), (
        contexts.variable('person'),
        pattern.pattern_literal('male'),
    ))

    fc_rule.fc_rule('dictator', This_rule_base, dictator, (
        ('famous', 'rules', (
            contexts.variable('person'),
            contexts.variable('nation'),
        ), False),
        ('famous', 'free_elections', (contexts.variable('nation'), ), True),
    ), (contexts.variable('person'), ))

    fc_rule.fc_rule('freely_elected', This_rule_base, freely_elected, (
        ('famous', 'rules', (
            contexts.variable('person'),
            contexts.variable('nation'),
        ), False),
        ('famous', 'free_elections', (contexts.variable('nation'), ), False),
    ), (contexts.variable('person'), ))

    fc_rule.fc_rule('president', This_rule_base, president, (
        ('famous', 'rules', (
            contexts.variable('person'),
            contexts.variable('nation'),
        ), False),
        ('famous', 'title', (
            contexts.variable('person'),
            contexts.variable('title'),
        ), True),
    ), (
        contexts.variable('person'),
        pattern.pattern_literal('president'),
    ))

    fc_rule.fc_rule('allies', This_rule_base, allies, (
        ('famous', 'allies', (
            contexts.variable('nation1'),
            contexts.variable('nation2'),
        ), False),
        ('famous', 'rules', (
            contexts.variable('person1'),
            contexts.variable('nation1'),
        ), False),
        ('famous', 'rules', (
            contexts.variable('person2'),
            contexts.variable('nation2'),
        ), False),
    ), (
        contexts.variable('person1'),
        contexts.variable('nation2'),
        contexts.variable('person2'),
        contexts.variable('nation1'),
    ))

    fc_rule.fc_rule('children', This_rule_base, children, (
        ('famous', 'famousFor', (
            contexts.variable('person'),
            contexts.variable('skill'),
        ), False),
        ('famous', 'children', (
            contexts.variable('person'),
            contexts.variable('yesno'),
        ), True),
    ), (
        contexts.variable('person'),
        pattern.pattern_literal('No'),
    ))

    fc_rule.fc_rule('race', This_rule_base, race, (
        ('famous', 'famousFor', (
            contexts.variable('person'),
            contexts.variable('skill'),
        ), False),
        ('famous', 'race', (
            contexts.variable('person'),
            contexts.variable('race'),
        ), True),
    ), (
        contexts.variable('person'),
        pattern.pattern_literal('Caucasian'),
    ))

    fc_rule.fc_rule('princess', This_rule_base, princess,
                    (('famous', 'princess',
                      (contexts.variable('person'), ), False), ), (
                          contexts.variable('person'),
                          pattern.pattern_literal('female'),
                      ))
def populate(engine):
  This_rule_base = engine.get_create('category_rules')
  
  bc_rule.bc_rule('ordered_rule0', This_rule_base, 'top2',
                  ordered_rule0, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(1),
                   pattern.pattern_literal('d'),
                   pattern.pattern_literal(2),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(4),
                   pattern.pattern_literal(11),))
  
  bc_rule.bc_rule('ordered_rule1', This_rule_base, 'top2',
                  ordered_rule1, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(1),
                   pattern.pattern_literal('d'),
                   pattern.pattern_literal(4),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(6),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule2', This_rule_base, 'top2',
                  ordered_rule2, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('dining'),),
                  (),
                  (pattern.pattern_literal(1),
                   pattern.pattern_literal('d'),
                   pattern.pattern_literal(5),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(9),
                   pattern.pattern_literal('a'),))
  
  bc_rule.bc_rule('ordered_rule3', This_rule_base, 'top2',
                  ordered_rule3, None,
                  (pattern.pattern_literal('relaxation'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(1),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(6),))
  
  bc_rule.bc_rule('ordered_rule4', This_rule_base, 'top2',
                  ordered_rule4, None,
                  (pattern.pattern_literal('outdoor'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(1),
                   contexts.variable('num'),
                   pattern.pattern_literal(8),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(13),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule5', This_rule_base, 'top2',
                  ordered_rule5, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('dining'),),
                  (),
                  (pattern.pattern_literal(1),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(4),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(11),))
  
  bc_rule.bc_rule('ordered_rule6', This_rule_base, 'top2',
                  ordered_rule6, None,
                  (pattern.pattern_literal('relaxation'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(1),
                   contexts.variable('num'),
                   pattern.pattern_literal(10),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule7', This_rule_base, 'top2',
                  ordered_rule7, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('dining'),),
                  (),
                  (pattern.pattern_literal(6),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(7),
                   pattern.pattern_literal(9),
                   pattern.pattern_literal('a'),))
  
  bc_rule.bc_rule('ordered_rule8', This_rule_base, 'top2',
                  ordered_rule8, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('cultural'),),
                  (),
                  (pattern.pattern_literal(1),
                   contexts.variable('num'),
                   pattern.pattern_literal(2),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(3),))
  
  bc_rule.bc_rule('ordered_rule9', This_rule_base, 'top2',
                  ordered_rule9, None,
                  (pattern.pattern_literal('outdoor'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(2),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(3),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(6),))
  
  bc_rule.bc_rule('ordered_rule10', This_rule_base, 'top2',
                  ordered_rule10, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(7),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(13),))
  
  bc_rule.bc_rule('ordered_rule11', This_rule_base, 'top2',
                  ordered_rule11, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('relaxation'),),
                  (),
                  (pattern.pattern_literal(4),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(6),
                   pattern.pattern_literal(12),))
  
  bc_rule.bc_rule('ordered_rule12', This_rule_base, 'top2',
                  ordered_rule12, None,
                  (pattern.pattern_literal('dining'),
                   pattern.pattern_literal('relaxation'),),
                  (),
                  (pattern.pattern_literal(5),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(10),))
  
  bc_rule.bc_rule('ordered_rule13', This_rule_base, 'top2',
                  ordered_rule13, None,
                  (pattern.pattern_literal('outdoor'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(6),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule14', This_rule_base, 'top2',
                  ordered_rule14, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(1),
                   contexts.variable('num'),
                   pattern.pattern_literal(3),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(7),
                   pattern.pattern_literal('a'),))
  
  bc_rule.bc_rule('ordered_rule15', This_rule_base, 'top2',
                  ordered_rule15, None,
                  (pattern.pattern_literal('dining'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(7),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(10),))
  
  bc_rule.bc_rule('ordered_rule16', This_rule_base, 'top2',
                  ordered_rule16, None,
                  (pattern.pattern_literal('relaxation'),
                   pattern.pattern_literal('nature'),),
                  (),
                  (pattern.pattern_literal(4),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(13),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule17', This_rule_base, 'top2',
                  ordered_rule17, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('relaxation'),),
                  (),
                  (pattern.pattern_literal(1),
                   contexts.variable('num'),
                   pattern.pattern_literal(7),
                   pattern.pattern_literal('b'),
                   pattern.pattern_literal(13),))
  
  bc_rule.bc_rule('ordered_rule18', This_rule_base, 'top2',
                  ordered_rule18, None,
                  (pattern.pattern_literal('dining'),
                   pattern.pattern_literal('relaxation'),),
                  (),
                  (pattern.pattern_literal(2),
                   pattern.pattern_literal('a'),
                   pattern.pattern_literal(9),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule19', This_rule_base, 'top2',
                  ordered_rule19, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('outdoor'),),
                  (),
                  (pattern.pattern_literal(2),
                   pattern.pattern_literal('b'),))
  
  bc_rule.bc_rule('ordered_rule20', This_rule_base, 'top2',
                  ordered_rule20, None,
                  (pattern.pattern_literal('dining'),
                   pattern.pattern_literal('relaxation'),),
                  (),
                  (pattern.pattern_literal(1),
                   pattern.pattern_literal('a'),))
  
  bc_rule.bc_rule('ordered_rule21', This_rule_base, 'top2',
                  ordered_rule21, None,
                  (pattern.pattern_literal('sights'),
                   pattern.pattern_literal('nature'),),
                  (),
                  ())
Ejemplo n.º 27
0
def populate(engine):
  This_rule_base = engine.get_create('fc_example')
  
  fc_rule.fc_rule('son_of', This_rule_base, son_of,
    (('family', 'son_of',
      (contexts.variable('child'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),),
    (contexts.variable('child'),
     contexts.variable('father'),
     pattern.pattern_literal('father'),
     pattern.pattern_literal('son'),
     contexts.variable('mother'),
     pattern.pattern_literal('mother'),))
  
  fc_rule.fc_rule('daughter_of', This_rule_base, daughter_of,
    (('family', 'daughter_of',
      (contexts.variable('child'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),),
    (contexts.variable('child'),
     contexts.variable('father'),
     pattern.pattern_literal('father'),
     pattern.pattern_literal('daughter'),
     contexts.variable('mother'),
     pattern.pattern_literal('mother'),))
  
  fc_rule.fc_rule('brothers', This_rule_base, brothers,
    (('family', 'son_of',
      (contexts.variable('brother1'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),
     ('family', 'son_of',
      (contexts.variable('brother2'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),),
    (contexts.variable('brother1'),
     contexts.variable('brother2'),
     pattern.pattern_literal('brother'),))
  
  fc_rule.fc_rule('sisters', This_rule_base, sisters,
    (('family', 'daughter_of',
      (contexts.variable('sister1'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),
     ('family', 'daughter_of',
      (contexts.variable('sister2'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),),
    (contexts.variable('sister1'),
     contexts.variable('sister2'),
     pattern.pattern_literal('sister'),))
  
  fc_rule.fc_rule('brother_and_sister', This_rule_base, brother_and_sister,
    (('family', 'son_of',
      (contexts.variable('brother'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),
     ('family', 'daughter_of',
      (contexts.variable('sister'),
       contexts.variable('father'),
       contexts.variable('mother'),),
      False),),
    (contexts.variable('brother'),
     contexts.variable('sister'),
     pattern.pattern_literal('sister'),
     pattern.pattern_literal('brother'),))
  
  fc_rule.fc_rule('facts_for_bc_rules', This_rule_base, facts_for_bc_rules,
    (),
    (pattern.pattern_literal('brother'),
     pattern.pattern_literal('uncle'),
     pattern.pattern_literal('sister'),
     pattern.pattern_literal('aunt'),
     pattern.pattern_literal('son'),
     pattern.pattern_literal('nephew'),
     pattern.pattern_literal('daughter'),
     pattern.pattern_literal('niece'),))
  
  fc_rule.fc_rule('niece_or_nephew_and_aunt_or_uncle', This_rule_base, niece_or_nephew_and_aunt_or_uncle,
    (('family', 'child_parent',
      (contexts.variable('nn'),
       contexts.variable('parent'),
       contexts.variable('depth'),
       contexts.anonymous('_'),
       contexts.variable('child_type'),),
      False),
     ('family', 'siblings',
      (contexts.variable('parent'),
       contexts.variable('au'),
       contexts.variable('sibling_type'),
       contexts.anonymous('_'),),
      False),
     ('family', 'as_au',
      (contexts.variable('sibling_type'),
       contexts.variable('au_type'),),
      False),
     ('family', 'as_nn',
      (contexts.variable('child_type'),
       contexts.variable('nn_type'),),
      False),),
    (contexts.variable('greats'),
     contexts.variable('nn'),
     contexts.variable('au'),
     contexts.variable('au_type'),
     contexts.variable('nn_type'),))
  
  fc_rule.fc_rule('parent_and_child', This_rule_base, parent_and_child,
    (('family', 'child_parent',
      (contexts.variable('child'),
       contexts.variable('parent'),
       contexts.variable('parent_type'),
       contexts.variable('child_type'),),
      False),),
    (contexts.variable('child'),
     contexts.variable('parent'),
     pattern.pattern_literal(()),
     contexts.variable('parent_type'),
     contexts.variable('child_type'),))
  
  fc_rule.fc_rule('grand_parent_and_child', This_rule_base, grand_parent_and_child,
    (('family', 'child_parent',
      (contexts.variable('child'),
       contexts.variable('parent'),
       contexts.anonymous('_'),
       contexts.variable('child_type'),),
      False),
     ('family', 'child_parent',
      (contexts.variable('parent'),
       contexts.variable('grand_parent'),
       contexts.variable('parent_type'),
       contexts.anonymous('_'),),
      False),),
    (contexts.variable('child'),
     contexts.variable('grand_parent'),
     pattern.pattern_literal(('grand',)),
     contexts.variable('parent_type'),
     contexts.variable('child_type'),))
  
  fc_rule.fc_rule('great_grand_parent_and_child', This_rule_base, great_grand_parent_and_child,
    (('family', 'child_parent',
      (contexts.variable('child'),
       contexts.variable('grand_child'),
       contexts.anonymous('_'),
       contexts.variable('child_type'),),
      False),
     ('family', 'child_parent',
      (contexts.variable('grand_child'),
       contexts.variable('grand_parent'),
       pattern.pattern_tuple((contexts.variable('a'),), contexts.variable('b')),
       contexts.variable('parent_type'),
       contexts.anonymous('_'),),
      False),),
    (contexts.variable('child'),
     contexts.variable('grand_parent'),
     pattern.pattern_tuple((pattern.pattern_literal('great'), contexts.variable('a'),), contexts.variable('b')),
     contexts.variable('parent_type'),
     contexts.variable('child_type'),))
  
  fc_rule.fc_rule('first_cousins', This_rule_base, first_cousins,
    (('family', 'child_parent',
      (contexts.variable('cousin1'),
       contexts.variable('sibling1'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),
     ('family', 'siblings',
      (contexts.variable('sibling1'),
       contexts.variable('sibling2'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),
     ('family', 'child_parent',
      (contexts.variable('cousin2'),
       contexts.variable('sibling2'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),),
    (contexts.variable('cousin1'),
     contexts.variable('cousin2'),
     pattern.pattern_literal(1),))
  
  fc_rule.fc_rule('nth_cousins', This_rule_base, nth_cousins,
    (('family', 'child_parent',
      (contexts.variable('next_cousin1'),
       contexts.variable('cousin1'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),
     ('family', 'cousins',
      (contexts.variable('cousin1'),
       contexts.variable('cousin2'),
       contexts.variable('n'),),
      False),
     ('family', 'child_parent',
      (contexts.variable('next_cousin2'),
       contexts.variable('cousin2'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),),
    (contexts.variable('next_n'),
     contexts.variable('next_cousin1'),
     contexts.variable('next_cousin2'),))
  
  fc_rule.fc_rule('how_related_child_parent', This_rule_base, how_related_child_parent,
    (('family', 'child_parent',
      (contexts.variable('person1'),
       contexts.variable('person2'),
       contexts.variable('prefix'),
       contexts.variable('p2_type'),
       contexts.variable('p1_type'),),
      False),),
    (contexts.variable('relationship'),
     contexts.variable('person1'),
     contexts.variable('person2'),))
  
  fc_rule.fc_rule('how_related_parent_child', This_rule_base, how_related_parent_child,
    (('family', 'child_parent',
      (contexts.variable('person2'),
       contexts.variable('person1'),
       contexts.variable('prefix'),
       contexts.variable('p1_type'),
       contexts.variable('p2_type'),),
      False),),
    (contexts.variable('relationship'),
     contexts.variable('person1'),
     contexts.variable('person2'),))
  
  fc_rule.fc_rule('how_related_siblings', This_rule_base, how_related_siblings,
    (('family', 'siblings',
      (contexts.variable('person1'),
       contexts.variable('person2'),
       contexts.variable('p2_type'),
       contexts.variable('p1_type'),),
      False),),
    (contexts.variable('person1'),
     contexts.variable('person2'),
     pattern.pattern_tuple((contexts.variable('p1_type'), contexts.variable('p2_type'),), None),))
  
  fc_rule.fc_rule('how_related_nn_au', This_rule_base, how_related_nn_au,
    (('family', 'nn_au',
      (contexts.variable('person1'),
       contexts.variable('person2'),
       contexts.variable('prefix'),
       contexts.variable('p2_type'),
       contexts.variable('p1_type'),),
      False),),
    (contexts.variable('relationship'),
     contexts.variable('person1'),
     contexts.variable('person2'),))
  
  fc_rule.fc_rule('how_related_au_nn', This_rule_base, how_related_au_nn,
    (('family', 'nn_au',
      (contexts.variable('person2'),
       contexts.variable('person1'),
       contexts.variable('prefix'),
       contexts.variable('p1_type'),
       contexts.variable('p2_type'),),
      False),),
    (contexts.variable('relationship'),
     contexts.variable('person1'),
     contexts.variable('person2'),))
  
  fc_rule.fc_rule('how_related_cousins', This_rule_base, how_related_cousins,
    (('family', 'cousins',
      (contexts.variable('cousin1'),
       contexts.variable('cousin2'),
       contexts.variable('n'),),
      False),),
    (contexts.variable('nth'),
     contexts.variable('cousin1'),
     contexts.variable('cousin2'),
     pattern.pattern_tuple((contexts.variable('nth'), pattern.pattern_literal('cousins'),), None),))
  
  fc_rule.fc_rule('how_related_removed_cousins', This_rule_base, how_related_removed_cousins,
    (('family', 'child_parent',
      (contexts.variable('removed_cousin1'),
       contexts.variable('cousin1'),
       contexts.variable('grand'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),
     ('family', 'cousins',
      (contexts.variable('cousin1'),
       contexts.variable('cousin2'),
       contexts.variable('n'),),
      False),),
    (contexts.variable('nth'),
     contexts.variable('r1'),
     contexts.variable('removed_cousin1'),
     contexts.variable('cousin2'),
     pattern.pattern_tuple((contexts.variable('nth'), pattern.pattern_literal('cousins'), contexts.variable('r1'), pattern.pattern_literal('removed'),), None),))
  
  fc_rule.fc_rule('how_related_cousins_removed', This_rule_base, how_related_cousins_removed,
    (('family', 'cousins',
      (contexts.variable('cousin1'),
       contexts.variable('cousin2'),
       contexts.variable('n'),),
      False),
     ('family', 'child_parent',
      (contexts.variable('removed_cousin2'),
       contexts.variable('cousin2'),
       contexts.variable('grand'),
       contexts.anonymous('_'),
       contexts.anonymous('_'),),
      False),),
    (contexts.variable('nth'),
     contexts.variable('r1'),
     contexts.variable('cousin1'),
     contexts.variable('removed_cousin2'),
     pattern.pattern_tuple((contexts.variable('nth'), pattern.pattern_literal('cousins'), contexts.variable('r1'), pattern.pattern_literal('removed'),), None),))
Ejemplo n.º 28
0
def populate(engine):
  This_rule_base = engine.get_create('animalia_fc')
  
  fc_rule.fc_rule('gives_milk', This_rule_base, gives_milk,
    (('animalia', 'gives_milk',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('mammal'),
     pattern.pattern_literal('gives_milk'),))
  
  fc_rule.fc_rule('have_feathers', This_rule_base, have_feathers,
    (('animalia', 'have_feathers',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('bird'),
     pattern.pattern_literal('have_feathers'),))
  
  fc_rule.fc_rule('eats_meat', This_rule_base, eats_meat,
    (('animalia', 'eats_meat',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('carnivore'),
     pattern.pattern_literal('eats_meat'),))
  
  fc_rule.fc_rule('can_swim', This_rule_base, can_swim,
    (('animalia', 'can_swim',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('aquatic'),
     pattern.pattern_literal('can_swim'),))
  
  fc_rule.fc_rule('lays_eggs', This_rule_base, lays_eggs,
    (('animalia', 'lays_eggs',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('bird'),
     pattern.pattern_literal('lays_eggs'),))
  
  fc_rule.fc_rule('has_hair', This_rule_base, has_hair,
    (('animalia', 'has_hair',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('mammal'),
     pattern.pattern_literal('has_hair'),))
  
  fc_rule.fc_rule('have_scales', This_rule_base, have_scales,
    (('animalia', 'have_scales',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('aquatic'),
     pattern.pattern_literal('have_scales'),))
  
  fc_rule.fc_rule('has_antenna', This_rule_base, has_antenna,
    (('animalia', 'has_antenna',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('insect'),
     pattern.pattern_literal('has_antenna'),))
  
  fc_rule.fc_rule('have_webbed_feet', This_rule_base, have_webbed_feet,
    (('animalia', 'have_webbed_feet',
      (contexts.variable('animal'),
       contexts.variable('type'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('type'),
     pattern.pattern_literal('amphibian'),
     pattern.pattern_literal('have_webbed_feet'),))
  
  fc_rule.fc_rule('find_animal_feature', This_rule_base, find_animal_feature,
    (('animalia', 'animal_kind',
      (contexts.variable('animal'),
       contexts.variable('type'),
       contexts.variable('kind'),
       contexts.variable('feature'),),
      False),),
    (contexts.variable('animal'),
     contexts.variable('feature'),
     contexts.variable('kind'),))
Ejemplo n.º 29
0
def p_pattern(p):
    ''' pattern : data '''
    if goal_mode:
        p[0] = pattern.pattern_literal(p[1])
    else:
        p[0] = "pattern.pattern_literal(%s)" % str(p[1])