示例#1
0
def calculate_graph_prop(_params, _segment):
    
    kernel = core.Kernel.getSingleton()
    session = kernel.session()
    segment = kernel.segment()
        
    # check type
    question = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                                 keynodes.questions.initiated,
                                                                 sc.SC_A_CONST,
                                                                 sc.SC_N_CONST,
                                                                 sc.SC_A_CONST,
                                                                 _params), True, 5)
    
    assert question is not None
    question = question[2]
    
    global graph_prop_calculators
    for question_type, calculator, relation in graph_prop_calculators:   
        # check command type
        if sc_utils.checkIncToSets(session, question, [question_type], sc.SC_CONST):
  
            graph = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                                      question,
                                                                      sc.SC_A_CONST,
                                                                      sc.SC_N_CONST), True, 3)
            
            if graph is None:
                return
            
            graph = graph[2]
            
            if not sc_utils.checkIncToSets(session, graph, [graph_keynodes.Common.graph], sc.SC_CONST):
                return
            
            g = Graph(segment, graph)
            g.makeNxGraph()
                        
            result = calculator(g.graphNx)
            
            if result is None:
                raise RuntimeWarning("Calculator can't calculate value")
            
            value = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            bin_rel = sc_utils.createPairBinaryOrientFull(session, segment, graph, value, sc.SC_CONST)
            a = sc_utils.createPairPosPerm(session, segment, relation, bin_rel[0], sc.SC_CONST)
            
            elements = translate_value(session, segment, value, result)
            
            elements.extend([value, graph, a, relation])
            elements.extend(bin_rel)
            
            
            answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            for el in elements:
                sc_utils.createPairPosPerm(session, segment, answer, el, sc.SC_CONST)
                
            sc_utils.makeAnswer(session, segment, question, answer)
示例#2
0
def calculate_graph_element_prop(_params, _segment):

    kernel = core.Kernel.getSingleton()
    session = kernel.session()
    segment = kernel.segment()

    # check type
    question = session.search_one_shot(
        session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                  keynodes.questions.initiated, sc.SC_A_CONST,
                                  sc.SC_N_CONST, sc.SC_A_CONST, _params), True,
        5)

    assert question is not None
    question = question[2]

    global graph_prop_calculators
    for question_type, calculator, relation in graph_element_prop_calculators:
        # check command type
        if sc_utils.checkIncToSets(session, question, [question_type],
                                   sc.SC_CONST):

            element = session.search_one_shot(
                session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                          question, sc.SC_A_CONST,
                                          sc.SC_N_CONST), True, 3)

            if element is None:
                return

            element = element[2]
            graph = None
            arc = None
            it = session.create_iterator(
                session.sc_constraint_new(sc_constants.CONSTR_3_a_a_f,
                                          sc.SC_NODE,
                                          sc.SC_A_CONST | sc.SC_POS, element),
                True)
            while not it.is_over():
                if sc_utils.checkIncToSets(session, it.value(0),
                                           [graph_keynodes.Common.graph],
                                           sc.SC_CONST):
                    graph = it.value(0)
                    arc = it.value(1)
                    break
                it.next()

            if graph is None:
                continue

            # make graph and calculate property value
            g = Graph(segment, graph)
            sc2obj = g.makeNxGraph()
            result = calculator(g.graphNx, sc2obj[str(element.this)])

            #
            if result is None:
                raise RuntimeWarning("Calculator can't calculate value")

            value = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            bin_rel = sc_utils.createPairBinaryOrientFull(
                session, segment, arc, value, sc.SC_CONST)
            a = sc_utils.createPairPosPerm(session, segment, relation,
                                           bin_rel[0], sc.SC_CONST)

            elements = translate_value(session, segment, value, result)

            elements.extend([value, graph, a, relation])
            elements.extend(bin_rel)

            answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            for el in elements:
                sc_utils.createPairPosPerm(session, segment, answer, el,
                                           sc.SC_CONST)

            sc_utils.makeAnswer(session, segment, question, answer)
示例#3
0
def calculate_graph_prop(_params, _segment):

    kernel = core.Kernel.getSingleton()
    session = kernel.session()
    segment = kernel.segment()

    # check type
    question = session.search_one_shot(
        session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                  keynodes.questions.initiated, sc.SC_A_CONST,
                                  sc.SC_N_CONST, sc.SC_A_CONST, _params), True,
        5)

    assert question is not None
    question = question[2]

    global graph_prop_calculators
    for question_type, calculator, relation in graph_prop_calculators:
        # check command type
        if sc_utils.checkIncToSets(session, question, [question_type],
                                   sc.SC_CONST):

            graph = session.search_one_shot(
                session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                          question, sc.SC_A_CONST,
                                          sc.SC_N_CONST), True, 3)

            if graph is None:
                return

            graph = graph[2]

            if not sc_utils.checkIncToSets(session, graph,
                                           [graph_keynodes.Common.graph],
                                           sc.SC_CONST):
                return

            g = Graph(segment, graph)
            g.makeNxGraph()

            result = calculator(g.graphNx)

            if result is None:
                raise RuntimeWarning("Calculator can't calculate value")

            value = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            bin_rel = sc_utils.createPairBinaryOrientFull(
                session, segment, graph, value, sc.SC_CONST)
            a = sc_utils.createPairPosPerm(session, segment, relation,
                                           bin_rel[0], sc.SC_CONST)

            elements = translate_value(session, segment, value, result)

            elements.extend([value, graph, a, relation])
            elements.extend(bin_rel)

            answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            for el in elements:
                sc_utils.createPairPosPerm(session, segment, answer, el,
                                           sc.SC_CONST)

            sc_utils.makeAnswer(session, segment, question, answer)
示例#4
0
def find_graph(_params, _segment):

    kernel = core.Kernel.getSingleton()
    session = kernel.session()
    segment = kernel.segment()

    # check type
    question = session.search_one_shot(
        session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                  keynodes.questions.initiated, sc.SC_A_CONST,
                                  sc.SC_N_CONST, sc.SC_A_CONST, _params), True,
        5)

    assert question is not None
    question = question[2]

    # check command type
    if sc_utils.checkIncToSets(session, question,
                               [graph_keynodes.Command.search_graph_full],
                               sc.SC_CONST):

        graph = session.search_one_shot(
            session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question,
                                      sc.SC_A_CONST, sc.SC_N_CONST), True, 5)

        if graph is None:
            return

        struct = sc_utils.createNodeElement(session, segment, sc.SC_CONST)

        graph = graph[2]

        sc_utils.createPairPosPerm(session, segment, struct, graph,
                                   sc.SC_CONST)
        sc_utils.createPairPosPerm(session, segment, struct,
                                   graph_keynodes.Common.rrel_edge,
                                   sc.SC_CONST)
        sc_utils.createPairPosPerm(session, segment, struct,
                                   graph_keynodes.Common.rrel_vertex,
                                   sc.SC_CONST)

        # collect verticies
        it = session.create_iterator(
            session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph,
                                      sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE,
                                      sc.SC_A_CONST | sc.SC_POS,
                                      graph_keynodes.Common.rrel_vertex), True)
        while not it.is_over():
            for i in xrange(1, 4):
                sc_utils.createPairPosPerm(session, segment, struct,
                                           it.value(i), sc.SC_CONST)
            it.next()

        it = session.create_iterator(
            session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph,
                                      sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE,
                                      sc.SC_A_CONST | sc.SC_POS,
                                      graph_keynodes.Common.rrel_edge), True)
        # collect edges
        while not it.is_over():
            for i in xrange(1, 4):
                sc_utils.createPairPosPerm(session, segment, struct,
                                           it.value(i), sc.SC_CONST)

            it1 = session.create_iterator(
                session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                          it.value(2),
                                          sc.SC_A_CONST | sc.SC_POS,
                                          sc.SC_NODE), True)
            while not it1.is_over():
                sc_utils.createPairPosPerm(session, segment, struct,
                                           it1.value(1), sc.SC_CONST)
                it1.next()

            it.next()

        sc_utils.makeAnswer(session, segment, question, struct)
示例#5
0
def calculate_graph_element_prop(_params, _segment):
    
    kernel = core.Kernel.getSingleton()
    session = kernel.session()
    segment = kernel.segment()
        
    # check type
    question = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                                 keynodes.questions.initiated,
                                                                 sc.SC_A_CONST,
                                                                 sc.SC_N_CONST,
                                                                 sc.SC_A_CONST,
                                                                 _params), True, 5)
    
    assert question is not None
    question = question[2]
    
    global graph_prop_calculators
    for question_type, calculator, relation in graph_element_prop_calculators:
        # check command type
        if sc_utils.checkIncToSets(session, question, [question_type], sc.SC_CONST):
  
            element = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                                        question,
                                                                        sc.SC_A_CONST,
                                                                        sc.SC_N_CONST), True, 3)
            
            if element is None:
                return
            
            element = element[2]
            graph = None
            arc = None
            it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_a_a_f,
                                                                   sc.SC_NODE,
                                                                   sc.SC_A_CONST | sc.SC_POS,
                                                                   element), True)
            while not it.is_over():
                if sc_utils.checkIncToSets(session, it.value(0), [graph_keynodes.Common.graph], sc.SC_CONST):
                    graph = it.value(0)
                    arc = it.value(1)
                    break
                it.next()
                
            
            if graph is None:
                continue
            
            # make graph and calculate property value
            g = Graph(segment, graph)
            sc2obj = g.makeNxGraph()
            result = calculator(g.graphNx, sc2obj[str(element.this)])
            
            # 
            if result is None:
                raise RuntimeWarning("Calculator can't calculate value")
            
            
            value = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            bin_rel = sc_utils.createPairBinaryOrientFull(session, segment, arc, value, sc.SC_CONST)
            a = sc_utils.createPairPosPerm(session, segment, relation, bin_rel[0], sc.SC_CONST)
            
            elements = translate_value(session, segment, value, result)
            
            elements.extend([value, graph, a, relation])
            elements.extend(bin_rel)
            
            
            answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
            for el in elements:
                sc_utils.createPairPosPerm(session, segment, answer, el, sc.SC_CONST)
                
            sc_utils.makeAnswer(session, segment, question, answer)
示例#6
0
def find_graph(_params, _segment):

    kernel = core.Kernel.getSingleton()
    session = kernel.session()
    segment = kernel.segment()
        
    # check type
    question = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                                 keynodes.questions.initiated,
                                                                 sc.SC_A_CONST,
                                                                 sc.SC_N_CONST,
                                                                 sc.SC_A_CONST,
                                                                 _params), True, 5)
    
    assert question is not None
    question = question[2]
    
    # check command type
    if sc_utils.checkIncToSets(session, question, [graph_keynodes.Command.search_graph_full], sc.SC_CONST):
        
        graph = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                                  question,
                                                                  sc.SC_A_CONST,
                                                                  sc.SC_N_CONST), True, 5)
        
        if graph is None:
            return
        
        struct = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
        
        graph = graph[2]
        
        sc_utils.createPairPosPerm(session, segment, struct, graph, sc.SC_CONST)
        sc_utils.createPairPosPerm(session, segment, struct,  graph_keynodes.Common.rrel_edge, sc.SC_CONST)
        sc_utils.createPairPosPerm(session, segment, struct,  graph_keynodes.Common.rrel_vertex, sc.SC_CONST)
        
        # collect verticies
        it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                               graph,
                                                               sc.SC_A_CONST | sc.SC_POS,
                                                               sc.SC_NODE,
                                                               sc.SC_A_CONST | sc.SC_POS,
                                                               graph_keynodes.Common.rrel_vertex), True)
        while not it.is_over():
           for i in xrange(1, 4):
               sc_utils.createPairPosPerm(session, segment, struct, it.value(i), sc.SC_CONST)
           it.next()
           
        it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                               graph,
                                                               sc.SC_A_CONST | sc.SC_POS,
                                                               sc.SC_NODE,
                                                               sc.SC_A_CONST | sc.SC_POS,
                                                               graph_keynodes.Common.rrel_edge), True)
        # collect edges                                          
        while not it.is_over():
            for i in xrange(1, 4):
                sc_utils.createPairPosPerm(session, segment, struct, it.value(i), sc.SC_CONST)
               
            it1 = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                                    it.value(2),
                                                                    sc.SC_A_CONST | sc.SC_POS,
                                                                    sc.SC_NODE), True)
            while not it1.is_over():
                sc_utils.createPairPosPerm(session, segment, struct, it1.value(1), sc.SC_CONST)
                it1.next() 
                   
            it.next()
        
        sc_utils.makeAnswer(session, segment, question, struct)