Ejemplo n.º 1
0
def take(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('key_facts', 'inChest', context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "key.take: got unexpected plan from when clause 1"
            from Scenes import demoScene
            demoScene.DemoScene.demo_player.textComp.output_string = "You cannot take the key"
            if demoScene.DemoScene.has_key is True:
                demoScene.DemoScene.demo_player.textComp.output_string = "You already have the key"
            elif demoScene.DemoScene.has_key is False and demoScene.DemoScene.key_present is True:
                demoScene.DemoScene.demo_player.textComp.output_string = "You take the key"
                demoScene.DemoScene.has_key = True
            rule.rule_base.num_bc_rule_successes += 1
            yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
def febre(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove(rule.rule_base.root_name, 'get_celsius', context,
                                  (rule.pattern(0),
                                   rule.pattern(1),
                                   rule.pattern(2),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "regras.febre: got unexpected plan from when clause 1"
                        with engine.prove(rule.rule_base.root_name, 'get_celsius', context,
                                          (rule.pattern(0),
                                           rule.pattern(1),
                                           rule.pattern(2),)) \
                          as gen_2:
                            for x_2 in gen_2:
                                assert x_2 is None, \
                                  "regras.febre: got unexpected plan from when clause 2"
                                rule.rule_base.num_bc_rule_successes += 1
                                yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 3
0
def open(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    itertools.imap(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove('door_facts', 'closed', context,
                                  (rule.pattern(0),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "door.open: got unexpected plan from when clause 1"
                        from Scenes import demoScene
                        if demoScene.DemoScene.door_open is True:
                            demoScene.DemoScene.demo_player.textComp.output_string = "The door is already open"
                        elif demoScene.DemoScene.door_open is False and demoScene.DemoScene.has_key is False:
                            demoScene.DemoScene.demo_player.textComp.output_string = "The door is locked"
                        elif demoScene.DemoScene.door_open is False and demoScene.DemoScene.has_key is True:
                            demoScene.DemoScene.demo_player.textComp.output_string = "You open the door"
                        rule.rule_base.num_bc_rule_successes += 1
                        yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 4
0
def open(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('door_facts', 'closed', context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "door.open: got unexpected plan from when clause 1"
            from Scenes import demoScene
            if demoScene.DemoScene.door_open is True:
                demoScene.DemoScene.demo_player.textComp.output_string = "The door is already open"
            elif demoScene.DemoScene.door_open is False and demoScene.DemoScene.has_key is False:
                demoScene.DemoScene.demo_player.textComp.output_string = "The door is locked"
            elif demoScene.DemoScene.door_open is False and demoScene.DemoScene.has_key is True:
                demoScene.DemoScene.demo_player.textComp.output_string = "You open the door"
            rule.rule_base.num_bc_rule_successes += 1
            yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 5
0
def arr(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                ft = tuple(context.lookup_data('fault'))
                mark2 = context.mark(True)
                if rule.pattern(0).match_data(context, context, ft[0]):
                    context.end_save_all_undo()
                    with engine.prove('Remedy', 'responsekind', context,
                                      (rule.pattern(0),
                                       rule.pattern(1),)) \
                      as gen_3:
                        for x_3 in gen_3:
                            assert x_3 is None, \
                              "Remedyrule.arr: got unexpected plan from when clause 3"
                            rule.rule_base.num_bc_rule_successes += 1
                            yield
                else:
                    context.end_save_all_undo()
                context.undo_to_mark(mark2)
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
def ordered_rule18(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('answer', 'question', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "category_rules.ordered_rule18: got unexpected plan from when clause 1"
            with engine.prove('answer', 'question', context,
                              (rule.pattern(2),
                               rule.pattern(3),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "category_rules.ordered_rule18: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 7
0
def open(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('chest_facts', 'closed', context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "chest.open: got unexpected plan from when clause 1"
            from Scenes import demoScene
            if demoScene.DemoScene.chest_open is True and demoScene.DemoScene.has_key is False:
                demoScene.DemoScene.demo_player.textComp.output_string = "The chest is already open. It contains a key"
            elif demoScene.DemoScene.chest_open is True and demoScene.DemoScene.has_key is True:
                demoScene.DemoScene.demo_player.textComp.output_string = "The chest is already open. It is empty"
            else:
                demoScene.DemoScene.demo_player.textComp.output_string = "You open the chest. Inside, you find a key"
                demoScene.DemoScene.add_entities(demoScene.DemoScene.demo_key)
                demoScene.DemoScene.key_present = True
                demoScene.DemoScene.chest_open = True
            rule.rule_base.num_bc_rule_successes += 1
            yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 8
0
def int_discrasiahemorragica(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove('questions', 'discrasiaHemorragica', context,
                                  (rule.pattern(0),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "rules.int_discrasiahemorragica: got unexpected plan from when clause 1"
                        mark2 = context.mark(True)
                        if rule.pattern(1).match_data(
                                context, context,
                                Fdiscrasiahemorragica(
                                    context.lookup_data(
                                        'ans_discrasiahemorragica'))):
                            context.end_save_all_undo()
                            rule.rule_base.num_bc_rule_successes += 1
                            yield
                        else:
                            context.end_save_all_undo()
                        context.undo_to_mark(mark2)
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 9
0
def get(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove(rule.rule_base.root_name, 'ar', context,
                                  (rule.pattern(0),
                                   rule.pattern(1),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "Remedyrule.get: got unexpected plan from when clause 1"
                        with engine.prove(rule.rule_base.root_name, 'VM', context,
                                          (rule.pattern(2),
                                           rule.pattern(1),)) \
                          as gen_2:
                            for x_2 in gen_2:
                                assert x_2 is None, \
                                  "Remedyrule.get: got unexpected plan from when clause 2"
                                with engine.prove(rule.rule_base.root_name, 'PM', context,
                                                  (rule.pattern(3),
                                                   rule.pattern(1),)) \
                                  as gen_3:
                                    for x_3 in gen_3:
                                        assert x_3 is None, \
                                          "Remedyrule.get: got unexpected plan from when clause 3"
                                        mark4 = context.mark(True)
                                        if rule.pattern(4).match_data(
                                                context, context,
                                            (context.lookup_data(
                                                'responsefault'),
                                             context.lookup_data('VMfault'),
                                             context.lookup_data('PMfault'))):
                                            context.end_save_all_undo()
                                            with engine.prove('Remedy', 'remedy_of', context,
                                                              (rule.pattern(4),
                                                               rule.pattern(5),
                                                               rule.pattern(6),)) \
                                              as gen_5:
                                                for x_5 in gen_5:
                                                    assert x_5 is None, \
                                                      "Remedyrule.get: got unexpected plan from when clause 5"
                                                    rule.rule_base.num_bc_rule_successes += 1
                                                    yield
                                        else:
                                            context.end_save_all_undo()
                                        context.undo_to_mark(mark4)
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 10
0
def diagnostico(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove(rule.rule_base.root_name, 'diagnostico1', context,
                                  (rule.pattern(0),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "rules.diagnostico: got unexpected plan from when clause 1"
                        with engine.prove(rule.rule_base.root_name, 'int_hipertrofiaganglionar', context,
                                          (rule.pattern(1),)) \
                          as gen_2:
                            for x_2 in gen_2:
                                assert x_2 is None, \
                                  "rules.diagnostico: got unexpected plan from when clause 2"
                                with engine.prove(rule.rule_base.root_name, 'int_discrasiahemorragica', context,
                                                  (rule.pattern(2),)) \
                                  as gen_3:
                                    for x_3 in gen_3:
                                        assert x_3 is None, \
                                          "rules.diagnostico: got unexpected plan from when clause 3"
                                        mark4 = context.mark(True)
                                        if rule.pattern(3).match_data(
                                                context, context,
                                                list(
                                                    sum(
                                                        context.lookup_data(
                                                            'result1'),
                                                        sum(
                                                            context.
                                                            lookup_data(
                                                                'hipertrofiaganglionar'
                                                            ),
                                                            context.
                                                            lookup_data(
                                                                'discrasia'))))
                                        ):
                                            context.end_save_all_undo()
                                            rule.rule_base.num_bc_rule_successes += 1
                                            yield
                                        else:
                                            context.end_save_all_undo()
                                        context.undo_to_mark(mark4)
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 11
0
def diagnostico_4(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('doenca', 'hipertrofia', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "bc_regras.diagnostico_4: got unexpected plan from when clause 1"
            with engine.prove('doenca', 'discrasia', context,
                              (rule.pattern(2),
                               rule.pattern(3),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "bc_regras.diagnostico_4: got unexpected plan from when clause 2"
                with engine.prove('doenca', 'acometimento', context,
                                  (rule.pattern(4),
                                   rule.pattern(5),
                                   rule.pattern(6),
                                   rule.pattern(7),)) \
                  as gen_3:
                  for x_3 in gen_3:
                    assert x_3 is None, \
                      "bc_regras.diagnostico_4: got unexpected plan from when clause 3"
                    mark4 = context.mark(True)
                    if rule.pattern(8).match_data(context, context,
                            def_doenca(context.lookup_data('doenca10'), context.lookup_data('doenca11'), context.lookup_data('doenca12'))):
                      context.end_save_all_undo()
                      rule.rule_base.num_bc_rule_successes += 1
                      yield
                    else: context.end_save_all_undo()
                    context.undo_to_mark(mark4)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
def ordered_rule21(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        rule.rule_base.num_bc_rule_successes += 1
        yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
def ordered_rule17(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('answer', 'question', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "category_rules.ordered_rule17: got unexpected plan from when clause 1"
            for python_ans in \
                 ('a', 'b', 'c'):
              mark2 = context.mark(True)
              if rule.pattern(1).match_data(context, context, python_ans):
                context.end_save_all_undo()
                with engine.prove('answer', 'question', context,
                                  (rule.pattern(2),
                                   rule.pattern(3),)) \
                  as gen_3:
                  for x_3 in gen_3:
                    assert x_3 is None, \
                      "category_rules.ordered_rule17: got unexpected plan from when clause 3"
                    with engine.prove('answer', 'question', context,
                                      (rule.pattern(4),
                                       rule.pattern(3),)) \
                      as gen_4:
                      for x_4 in gen_4:
                        assert x_4 is None, \
                          "category_rules.ordered_rule17: got unexpected plan from when clause 4"
                        rule.rule_base.num_bc_rule_successes += 1
                        yield
              else: context.end_save_all_undo()
              context.undo_to_mark(mark2)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 14
0
def zika_itching(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                if context.lookup_data('u')['itching'] >= 2:
                    rule.rule_base.num_bc_rule_successes += 1
                    yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 15
0
def dengue_not_chikungunha(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                if context.lookup_data('u')['dycrasy'] == True:
                    if context.lookup_data('u')['musclepain'] == True:
                        rule.rule_base.num_bc_rule_successes += 1
                        yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 16
0
def name3(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('a', 'b', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is not None, \
              "krbparse_test.name3: expected plan from when clause 1"
            mark1 = context.mark(True)
            if not rule.pattern(2).match_data(context, context, x_1):
              raise AssertionError("krbparse_test.name3: plan match to $plan#1 failed in when clause 1")
            context.end_save_all_undo()
            with engine.prove(rule.rule_base.root_name, 'x', context,
                              (rule.pattern(3),
                               rule.pattern(4),
                               rule.pattern(5),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is not None, \
                  "krbparse_test.name3: expected plan from when clause 2"
                mark2 = context.mark(True)
                if not rule.pattern(6).match_data(context, context, x_2):
                  raise AssertionError("krbparse_test.name3: plan match to $foo_fn failed in when clause 2")
                context.end_save_all_undo()
                rule.rule_base.num_bc_rule_successes += 1
                yield context
                context.undo_to_mark(mark2)
            context.undo_to_mark(mark1)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 17
0
def at_station(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('subway_rules', 'take_line', context,
                          (rule.pattern(0),
                           rule.pattern(1),
                           rule.pattern(2),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "subway_rules.at_station: got unexpected plan from when clause 1"
            with engine.prove('subway', 'at_station', context,
                              (rule.pattern(0),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "subway_rules.at_station: got unexpected plan from when clause 2"
                with engine.prove('subway', 'station', context,
                                  (rule.pattern(0),
                                   rule.pattern(3),
                                   rule.pattern(4),
                                   rule.pattern(4),)) \
                  as gen_3:
                  for x_3 in gen_3:
                    assert x_3 is None, \
                      "subway_rules.at_station: got unexpected plan from when clause 3"
                    rule.rule_base.num_bc_rule_successes += 1
                    yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 18
0
def dengue_package(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        if context.lookup_data('u')['fever'] >= 38:
          if context.lookup_data('u')['feverstart'] > 3:
            if context.lookup_data('u')['feverstart'] < 8:
              if context.lookup_data('u')['musclepain'] == True:
                if context.lookup_data('u')['headache'] == True:
                  rule.rule_base.num_bc_rule_successes += 1
                  yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 19
0
def zika_package(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        if context.lookup_data('u')['skinspots'] == True:
          if context.lookup_data('u')['edemafreq'] == True:
            if context.lookup_data('u')['conj'] == True:
              if context.lookup_data('u')['hypertrofy'] == True:
                if context.lookup_data('u')['dycrasy'] == False:
                  rule.rule_base.num_bc_rule_successes += 1
                  yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 20
0
def chikungunha_package(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        if context.lookup_data('u')['fever'] >= 38:
          if context.lookup_data('u')['feverstart'] <= 3:
            if context.lookup_data('u')['artpainfreq'] == True:
              if context.lookup_data('u')['artpainint'] >= 2:
                if context.lookup_data('u')['edemafreq'] == True:
                  rule.rule_base.num_bc_rule_successes += 1
                  yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 21
0
def kick(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    itertools.imap(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                from Scenes import demoScene
                if demoScene.DemoScene.door_open is True:
                    demoScene.DemoScene.demo_player.textComp.output_string = "You kick the door closed"
                    demoScene.DemoScene.door_open = False
                elif demoScene.DemoScene.door_open is False and demoScene.DemoScene.has_key is False:
                    demoScene.DemoScene.demo_player.textComp.output_string = "You kick the door. It's locked shut"
                rule.rule_base.num_bc_rule_successes += 1
                yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 22
0
def poop(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        from Scenes import demoScene
        if demoScene.DemoScene.key_eaten and demoScene.DemoScene.key_eaten is True:
            demoScene.DemoScene.demo_player.textComp.output_string = "You poop out the key"
            demoScene.DemoScene.has_key = False
            demoScene.DemoScene.key_present = True
            demoScene.DemoScene.key_eaten = False
        rule.rule_base.num_bc_rule_successes += 1
        yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 23
0
def kick(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        from Scenes import demoScene
        if demoScene.DemoScene.door_open is True:
            demoScene.DemoScene.demo_player.textComp.output_string = "You kick the door closed"
            demoScene.DemoScene.door_open = False
        elif demoScene.DemoScene.door_open is False and demoScene.DemoScene.has_key is False:
            demoScene.DemoScene.demo_player.textComp.output_string = "You kick the door. It's locked shut"
        rule.rule_base.num_bc_rule_successes += 1
        yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 24
0
def drop(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        from Scenes import demoScene
        if demoScene.DemoScene.has_key is True:
            demoScene.DemoScene.demo_player.textComp.output_string = "You drop the key on the floor"
            demoScene.DemoScene.has_key = False
        else:
            demoScene.DemoScene.demo_player.textComp.output_string = "You don't have the key"
        rule.rule_base.num_bc_rule_successes += 1
        yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 25
0
def travel_on_same_line(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('subway', 'station', context,
                          (rule.pattern(0),
                           rule.pattern(1),
                           rule.pattern(2),
                           rule.pattern(2),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "subway_rules.travel_on_same_line: got unexpected plan from when clause 1"
            with engine.prove('subway', 'station', context,
                              (rule.pattern(3),
                               rule.pattern(1),
                               rule.pattern(2),
                               rule.pattern(2),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "subway_rules.travel_on_same_line: got unexpected plan from when clause 2"
                if context.lookup_data('from') != context.lookup_data('to'):
                  rule.rule_base.num_bc_rule_successes += 1
                  yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 26
0
def half_siblings_same_father(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove('family', 'son_of', context,
                                  (rule.pattern(0),
                                   rule.pattern(1),
                                   rule.pattern(2),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "example.half_siblings_same_father: got unexpected plan from when clause 1"
                        with engine.prove('family', 'son_of', context,
                                          (rule.pattern(3),
                                           rule.pattern(1),
                                           rule.pattern(4),)) \
                          as gen_2:
                            for x_2 in gen_2:
                                assert x_2 is None, \
                                  "example.half_siblings_same_father: got unexpected plan from when clause 2"
                                if context.lookup_data(
                                        'mother1') != context.lookup_data(
                                            'mother2'):
                                    rule.rule_base.num_bc_rule_successes += 1
                                    yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
def get(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove('remedies', 'remedy_of', context,
                                  (rule.pattern(0),
                                   rule.pattern(1),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "remedyget.get: got unexpected plan from when clause 1"
                        rule.rule_base.num_bc_rule_successes += 1
                        yield
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()
Ejemplo n.º 28
0
def kick(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        from Scenes import demoScene
        if demoScene.DemoScene.chest_open is True and demoScene.DemoScene.has_key is False:
            demoScene.DemoScene.demo_player.textComp.output_string = "You kick the chest. The key rattles around inside"
        elif demoScene.DemoScene.chest_open is True and demoScene.DemoScene.has_key is True:
                demoScene.DemoScene.demo_player.textComp.output_string = "You kick the empty chest"
        else:
                demoScene.DemoScene.demo_player.textComp.output_string = "You kick the chest. Something rattles around inside it"
        rule.rule_base.num_bc_rule_successes += 1
        yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 29
0
def resulta_diagnostico(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(map(lambda pat, arg:
                   pat.match_pattern(context, context,
                                     arg, arg_context),
                 patterns,
                 arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'diagnostico_1', context,
                          (rule.pattern(0),
                           rule.pattern(1),
                           rule.pattern(2),
                           rule.pattern(3),
                           rule.pattern(4),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "bc_regras.resulta_diagnostico: got unexpected plan from when clause 1"
            with engine.prove(rule.rule_base.root_name, 'diagnostico_2', context,
                              (rule.pattern(5),
                               rule.pattern(6),
                               rule.pattern(7),
                               rule.pattern(8),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "bc_regras.resulta_diagnostico: got unexpected plan from when clause 2"
                with engine.prove(rule.rule_base.root_name, 'diagnostico_3', context,
                                  (rule.pattern(9),
                                   rule.pattern(10),
                                   rule.pattern(11),
                                   rule.pattern(12),)) \
                  as gen_3:
                  for x_3 in gen_3:
                    assert x_3 is None, \
                      "bc_regras.resulta_diagnostico: got unexpected plan from when clause 3"
                    with engine.prove(rule.rule_base.root_name, 'diagnostico_4', context,
                                      (rule.pattern(13),
                                       rule.pattern(14),
                                       rule.pattern(15),
                                       rule.pattern(16),
                                       rule.pattern(17),)) \
                      as gen_4:
                      for x_4 in gen_4:
                        assert x_4 is None, \
                          "bc_regras.resulta_diagnostico: got unexpected plan from when clause 4"
                        mark5 = context.mark(True)
                        if rule.pattern(18).match_data(context, context,
                                def_doenca2(context.lookup_data('doenca51'), context.lookup_data('doenca52'), context.lookup_data('doenca53'), context.lookup_data('doenca54'))):
                          context.end_save_all_undo()
                          rule.rule_base.num_bc_rule_successes += 1
                          yield
                        else: context.end_save_all_undo()
                        context.undo_to_mark(mark5)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()
Ejemplo n.º 30
0
def diagnostico1(rule, arg_patterns, arg_context):
    engine = rule.rule_base.engine
    patterns = rule.goal_arg_patterns()
    if len(arg_patterns) == len(patterns):
        context = contexts.bc_context(rule)
        try:
            if all(
                    map(
                        lambda pat, arg: pat.match_pattern(
                            context, context, arg, arg_context), patterns,
                        arg_patterns)):
                rule.rule_base.num_bc_rules_matched += 1
                with engine.prove(rule.rule_base.root_name, 'int_febre', context,
                                  (rule.pattern(0),)) \
                  as gen_1:
                    for x_1 in gen_1:
                        assert x_1 is None, \
                          "rules.diagnostico1: got unexpected plan from when clause 1"
                        with engine.prove(rule.rule_base.root_name, 'int_mancha', context,
                                          (rule.pattern(1),)) \
                          as gen_2:
                            for x_2 in gen_2:
                                assert x_2 is None, \
                                  "rules.diagnostico1: got unexpected plan from when clause 2"
                                with engine.prove(rule.rule_base.root_name, 'int_dormuscular', context,
                                                  (rule.pattern(2),)) \
                                  as gen_3:
                                    for x_3 in gen_3:
                                        assert x_3 is None, \
                                          "rules.diagnostico1: got unexpected plan from when clause 3"
                                        with engine.prove(rule.rule_base.root_name, 'freq_dorarticular', context,
                                                          (rule.pattern(3),)) \
                                          as gen_4:
                                            for x_4 in gen_4:
                                                assert x_4 is None, \
                                                  "rules.diagnostico1: got unexpected plan from when clause 4"
                                                with engine.prove(rule.rule_base.root_name, 'tem_conjuntivite', context,
                                                                  (rule.pattern(4),)) \
                                                  as gen_5:
                                                    for x_5 in gen_5:
                                                        assert x_5 is None, \
                                                          "rules.diagnostico1: got unexpected plan from when clause 5"
                                                        with engine.prove(rule.rule_base.root_name, 'int_edemaart', context,
                                                                          (rule.pattern(5),)) \
                                                          as gen_6:
                                                            for x_6 in gen_6:
                                                                assert x_6 is None, \
                                                                  "rules.diagnostico1: got unexpected plan from when clause 6"
                                                                with engine.prove(rule.rule_base.root_name, 'int_dorcabeca', context,
                                                                                  (rule.pattern(6),)) \
                                                                  as gen_7:
                                                                    for x_7 in gen_7:
                                                                        assert x_7 is None, \
                                                                          "rules.diagnostico1: got unexpected plan from when clause 7"
                                                                        with engine.prove(rule.rule_base.root_name, 'int_acrometimentoNeurologico', context,
                                                                                          (rule.pattern(7),)) \
                                                                          as gen_8:
                                                                            for x_8 in gen_8:
                                                                                assert x_8 is None, \
                                                                                  "rules.diagnostico1: got unexpected plan from when clause 8"
                                                                                with engine.prove(rule.rule_base.root_name, 'int_coceira', context,
                                                                                                  (rule.pattern(8),)) \
                                                                                  as gen_9:
                                                                                    for x_9 in gen_9:
                                                                                        assert x_9 is None, \
                                                                                          "rules.diagnostico1: got unexpected plan from when clause 9"
                                                                                        mark10 = context.mark(
                                                                                            True
                                                                                        )
                                                                                        if rule.pattern(
                                                                                                9
                                                                                        ).match_data(
                                                                                                context,
                                                                                                context,
                                                                                                sum(
                                                                                                    context
                                                                                                    .
                                                                                                    lookup_data(
                                                                                                        'febre2'
                                                                                                    ),
                                                                                                    sum(
                                                                                                        context
                                                                                                        .
                                                                                                        lookup_data(
                                                                                                            'mancha2'
                                                                                                        ),
                                                                                                        sum(
                                                                                                            context
                                                                                                            .
                                                                                                            lookup_data(
                                                                                                                'dormuscular'
                                                                                                            ),
                                                                                                            sum(
                                                                                                                context
                                                                                                                .
                                                                                                                lookup_data(
                                                                                                                    'articular2'
                                                                                                                ),
                                                                                                                sum(
                                                                                                                    context
                                                                                                                    .
                                                                                                                    lookup_data(
                                                                                                                        'conjuntivite'
                                                                                                                    ),
                                                                                                                    sum(
                                                                                                                        context
                                                                                                                        .
                                                                                                                        lookup_data(
                                                                                                                            'edemartic'
                                                                                                                        ),
                                                                                                                        sum(
                                                                                                                            context
                                                                                                                            .
                                                                                                                            lookup_data(
                                                                                                                                'acometimentoneurologico'
                                                                                                                            ),
                                                                                                                            sum(
                                                                                                                                context
                                                                                                                                .
                                                                                                                                lookup_data(
                                                                                                                                    'dordecabeca'
                                                                                                                                ),
                                                                                                                                context
                                                                                                                                .
                                                                                                                                lookup_data(
                                                                                                                                    'coceiraa'
                                                                                                                                )
                                                                                                                            )
                                                                                                                        )
                                                                                                                    )
                                                                                                                )
                                                                                                            )
                                                                                                        )
                                                                                                    )
                                                                                                )
                                                                                        ):
                                                                                            context.end_save_all_undo(
                                                                                            )
                                                                                            rule.rule_base.num_bc_rule_successes += 1
                                                                                            yield
                                                                                        else:
                                                                                            context.end_save_all_undo(
                                                                                            )
                                                                                        context.undo_to_mark(
                                                                                            mark10
                                                                                        )
                rule.rule_base.num_bc_rule_failures += 1
        finally:
            context.done()