예제 #1
0
def main():
    builder = OntoBuilder()
    builder.build_knowledge_base('data/knowledge_base.txt')
    builder.build_facts('data/fact_base.txt')
    # builder.store('data/knowledge_base.json')

    onto_container = OntoContainer()
    onto_container.load("data/knowledge_base.json")
    onto_container.build_secondary_connections()

    algo1 = Algorithm(onto_container=onto_container,
                      filename='algo/patterns/simple_connection.json')

    algo_container = AlgoContainer()
    algo_container.add_algorithm(algo1)

    brain = Brain(onto_container=onto_container, algo_container=algo_container)
    estimator = Estimator(brain)
    algo_composer = AlgoComposer(brain=brain, estimator=estimator)

    input = 'do people in Russia speak english?'
    # input = 'does USA have people?'

    graph_walker = GraphWalker(brain=brain)
    graph_walker.train_mode = True
    result = graph_walker.resolve(input)
    print(result)
    exit()

    algorithm = algo_composer.compose(input, 'right')
    if algorithm:
        algorithm.save('algo/patterns/composed.json')
def main():
    builder = OntoBuilder2()
    builder.build_facts('data/fact_base.txt')
    builder.store('data/knowledge_base.json')

    onto_container = OntoContainer()
    onto_container.load("data/knowledge_base.json")
    onto_container.build_secondary_connections()

    algo_container = AlgoContainer()

    brain = Brain(onto_container=onto_container, algo_container=algo_container)
    estimator = Estimator(brain)

    algo_builder = AlgoBuilder(brain)
    algo_builder.build_from('data/algo_base.txt', './algo/patterns')

    algo_container.add_algorithm(
        Algorithm(onto_container=onto_container,
                  filename='algo/patterns/closed_q_reply.json'))
    algo_container.add_algorithm(
        Algorithm(onto_container=onto_container,
                  filename='algo/patterns/what_question_reply.json'))
    algo_container.add_algorithm(
        Algorithm(onto_container=onto_container,
                  filename='algo/patterns/switch_context.json'))
    algo_container.add_algorithm(
        Algorithm(onto_container=onto_container,
                  filename='algo/patterns/get_closest.json'))
    algo_container.attach_to_brain(brain)

    # input = 'do people in a slavic speaking country speak english?'
    input = 'do people in a USA speak english?'
    # input = 'does USA have people?'

    algo_runner = AlgoRunner(brain=brain)
    result = algo_runner.run(input)
    print(result)