Ejemplo n.º 1
0
 def test_adapter_nodes(self):
     data = load_segs(fl='1535158393.0-revit-signal')
     system = SystemFactory.from_serialized_geom(data,
                                                 sys=System,
                                                 root=(-246, 45, 0))
     system = system.bake()
     rules = heursitics.EngineHeurFP()
     Eng = RuleEngine(term_rule=rules.root, mx=2500, debug=False, nlog=20)
     Kb = KB(rules.root)
     root = Eng.alg2(system.root, Kb)
     print('nodes ', len(root))
     renderer = RenderNodeSystem()
     root = renderer.render(root)
     self.vis.build(root)
Ejemplo n.º 2
0
def get_rendered():
    data = load_segs(fl='1535158393.0-revit-signal')
    system = SystemFactory.from_serialized_geom(data,
                                                sys=System,
                                                root=(-246, 45, 0))
    system = system.bake()
    rules = heursitics.EngineHeurFP()
    Eng = RuleEngine(term_rule=rules.root, mx=2500, debug=False, nlog=20)
    Kb = KB(rules.root)
    root = Eng.alg2(system.root, Kb)

    renderer = RenderNodeSystem()
    root = renderer.render(root)
    return root
Ejemplo n.º 3
0
def operations_reset() -> Dict[str, Any]:
    global state_engine, rule_engine
    state_engine = StateEngine()
    rule_engine = RuleEngine()
    result = {"success": True}
    log_result(result)
    return result
Ejemplo n.º 4
0
def getKnowledgeBase():
    statement = request.args.get('statement')
    mode = request.args.get('mode')
    if mode == 'expert':
       print('mode1')
       RuleWriter.createRules(statement)
       action = 'Success'
    else:
        print('mode2')
        action = RuleEngine.fetchRuleByStatement(statement)
    return '%s' %(action)
Ejemplo n.º 5
0
    def process(self,
                data,
                points=[(-246, 45, 0)],
                system_type='FP',
                **kwargs):
        """

        :param data:
        :param points:
        :param system_type:
        :param kwargs: arguments to render the system
        :return:
        """
        self._log_inputs(data, points)

        # build graph,  bake attributes
        system = SystemFactory.from_serialized_geom(data,
                                                    sys=viper.SystemV3,
                                                    root=tuple(points[0]))
        system.bake()

        syst_meta = SystemRequest(type=system_type, **kwargs)

        heuristic = self.get_system(system_type)()
        rl_engine = RuleEngine(term_rule=heuristic.root, mx=1e6, debug=False)
        fact_base = KB(heuristic.root)
        root_node = rl_engine.alg2(system.root, fact_base)

        # based on labels, finallize graph (adding new info)
        sysrender = RenderNodeSystem()
        root_node = sysrender.render(root_node)
        meta_data = rl_engine.annotate_type(root_node, heuristic.final_labels)

        # create build instructions
        geom, inds, syms = self.finalize(root_node)
        return {'geom': geom, 'indicies': inds, 'symbols': syms}
Ejemplo n.º 6
0
def test_initial_utterance() -> None:
    rule_engine = RuleEngine()
    state_engine = StateEngine()

    tokens = "function read file one argument file location".split()

    rule_engine.add_tokens(tokens)
    new_code = rule_engine.parse(Code())
    state_engine.set_code(new_code)
    assert state_engine.print_code() == "def read_file(file_location):"
    assert rule_engine.tokens == []

    tokens = "if call len file location less than twelve then".split()

    rule_engine.add_tokens(tokens)
    new_code = rule_engine.parse(state_engine.code)
    state_engine.set_code(new_code)
    assert (state_engine.print_code() ==
            "def read_file(file_location):\n\tif len(file_location) < 12:")
    assert rule_engine.tokens == []
Ejemplo n.º 7
0
def test_multiple_commands() -> None:
    state_engine = StateEngine()
    rule_engine = RuleEngine()

    tokens = ["function", "main", "zero", "argument"]
    rule_engine.add_tokens(tokens)
    assert rule_engine.tokens == tokens

    code_copy = state_engine.get_code_deepcopy()
    prev_num_lines = len(code_copy.lines)
    new_code = rule_engine.parse(code_copy)
    assert len(new_code.lines) == prev_num_lines + 1
    new_code_lines = new_code.print_lines()

    assert (
        new_code_lines ==
        "import os\nimport sys\n\n# Start talking to get started!\n#\n# If nothing comes to mind, here's a good example to get started...\n#	define a function main that takes no arguments\n#	print helloworld\n#	call main\n\ndef main():"
    )

    state_engine.set_code(new_code)
    tokens = ["call", "print", "twelve"]
    rule_engine.add_tokens(tokens)
    assert rule_engine.tokens == tokens

    code_copy = state_engine.get_code_deepcopy()

    prev_num_lines = len(code_copy.lines)
    new_code = rule_engine.parse(code_copy)
    assert len(new_code.lines) == prev_num_lines + 1

    new_code_lines = new_code.print_lines()

    assert (
        new_code_lines ==
        "import os\nimport sys\n\n# Start talking to get started!\n#\n# If nothing comes to mind, here's a good example to get started...\n#	define a function main that takes no arguments\n#	print helloworld\n#	call main\n\ndef main():\n\tprint(12)"
    )

    state_engine.set_code(new_code)
Ejemplo n.º 8
0
        "wsgi": {
            "class": "logging.StreamHandler",
            "stream": "ext://flask.logging.wsgi_errors_stream",
            "formatter": "default",
        }
    },
    "root": {
        "level": "INFO",
        "handlers": ["wsgi"]
    },
})

# Engine Setup
state_engine = StateEngine()
bart_engine = BartEngine()
rule_engine = RuleEngine()


# Logging
def log_input(message: Any) -> None:
    app.logger.info(f"Input - {pformat(message)}\n")


def log_result(message: Any) -> None:
    app.logger.info(f"Result - {pformat(message)}\n")


# Routes
@app.route("/", methods=["GET"])
def status() -> Dict[str, Any]:
    result = {"success": True}