Beispiel #1
0
def close_sqrt(_xmlnode, tag, session, segment):
    """
    Postrprocess msqrt tag
    """

    while stack[-1] != "(":
        parse_result.append(stack.pop(-1))
        if len(stack) == 0:
            translation_errors.append(
                "Incorrect input string: can't find close bracket")
            return
    stack.pop(-1)
    variables.append(["0.5", []])

    findElement = sc_utils.getElementByIdtf("Num0.5", segment)
    if findElement == None:
        node = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                      "Num0.5")[1]
        sc_utils.createPair(session, core.Kernel.segment(), el, node,
                            sc.SC_CONST)
        variables_sc["0.5"] = node
    else:
        sc_utils.createPair(session, core.Kernel.segment(), el, findElement,
                            sc.SC_CONST)
        variables_sc["0.5"] = findElement

    parse_result.append("0.5")
    parse_result.append("^")
    return
Beispiel #2
0
def buildUserAtomQuestion(sc_qustions, sc_q_objects):
    # узел вопроса
    q_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    # добавляем во множество вопрос
    session.gen3_f_a_f(segment, sc_key.questions.question, q_node,
                       sc.SC_A_CONST | sc.SC_POS)
    # добавляем во множество атомарный вопрос
    session.gen3_f_a_f(segment, sc_key.questions.atom, q_node,
                       sc.SC_A_CONST | sc.SC_POS)
    # добавляем типы вопросов
    for sc_q in sc_qustions:
        session.gen3_f_a_f(segment, sc_q, q_node, sc.SC_A_CONST | sc.SC_POS)
    # добавляем объекты вопроса
    for sc_o in sc_q_objects:
        session.gen3_f_a_f(segment, q_node, sc_o, sc.SC_A_CONST | sc.SC_POS)
    # добавляем автора (пользователь)
    authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, authors_node,
                               sc_core.Kernel.getSingleton().getUserAddr(),
                               sc.SC_CONST)
    authors_pair_sheaf = sc_utils.createPairBinaryOrient(
        session, segment, q_node, authors_node, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, sc_key.common.nrel_authors,
                               authors_pair_sheaf, sc.SC_CONST)
    # добавляем окна для вывода
    output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)

    output_count = 0
    it = session.create_iterator(
        session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                  sc_key.ui.set_output_windows, sc.SC_ARC, 0),
        True)
    while not it.is_over():
        sc_utils.createPair(session, segment, output_node, it.value(2),
                            session.get_type(it.value(1)))
        output_count += 1
        it.next()

    if output_count == 0:
        sc_utils.createPairPosPerm(session, segment, output_node,
                                   kernel.getMainWindow()._getScAddr(),
                                   sc.SC_CONST)
    #sc_utils.copySet(session, sc_key.ui.set_output_windows, output_node, segment)
    # link output windows set to question
    output_sheaf = sc_utils.createPairBinaryOrient(session, segment,
                                                   output_node, q_node,
                                                   sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment,
                               sc_key.ui.nrel_set_of_output_windows,
                               output_sheaf, sc.SC_CONST)
    # initiate question
    sc_utils.createPairPosPerm(session, segment, sc_key.questions.initiated,
                               q_node, sc.SC_CONST)
    return q_node
Beispiel #3
0
def generate_variable(_xmlnode, tag, session, segment):
    """
    Process mi and mn tags. Generate variable or number and add it to result string
    @return:
    """
    #here should be generation of sc-node that represents variable
    global last, binoperands, lastop, el

    if session == None or segment == None:
        return

    nodename = _xmlnode.childNodes[0].nodeValue
    if not nodename in functions.keys():
        parse_result.append(nodename)

    if tag != "mi" and tag != "mn":
        translation_errors.append("Unknown tag")
        return
    #start generation
    if tag == "mi":
        if not nodename in functions.keys():
            findElement = sc_utils.getElementByIdtf(nodename, segment)
            if findElement == None:
                node = session.create_el_idtf(core.Kernel.segment(),
                                              sc.SC_NODE, nodename)[1]
                sc_utils.createPair(session, core.Kernel.segment(), el, node,
                                    sc.SC_CONST)
                variables_sc[nodename] = node
            else:
                sc_utils.createPair(session, core.Kernel.segment(), el,
                                    findElement, sc.SC_CONST)
                variables_sc[nodename] = findElement
        else:
            stack.append(nodename)
    if tag == "mn":
        findElement = sc_utils.getElementByIdtf("Num" + nodename, segment)
        if findElement == None:
            node = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                          "Num" + nodename)[1]
            #sc_utils.setContentInt(session, core.Kernel.segment(), node, int(nodename))
            sc_utils.createPair(session, core.Kernel.segment(), el, node,
                                sc.SC_CONST)
            variables_sc[nodename] = node
        else:
            sc_utils.createPair(session, core.Kernel.segment(), el,
                                findElement, sc.SC_CONST)
            variables_sc[nodename] = findElement

    variables.append([nodename, last])

    if (len(binoperands) == 1):
        binoperands.append(variables[-1][0])
        operations.append((lastop, binoperands))
        binoperands = []
    last = []
    lastop = ""
    return
Beispiel #4
0
def buildUserAtomQuestion(sc_qustions, sc_q_objects):
    # узел вопроса
    q_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    # добавляем во множество вопрос
    session.gen3_f_a_f(segment, sc_key.questions.question, q_node, sc.SC_A_CONST | sc.SC_POS)
    # добавляем во множество атомарный вопрос
    session.gen3_f_a_f(segment, sc_key.questions.atom, q_node, sc.SC_A_CONST | sc.SC_POS)
    # добавляем типы вопросов
    for sc_q in sc_qustions:
        session.gen3_f_a_f(segment, sc_q, q_node, sc.SC_A_CONST | sc.SC_POS)
    # добавляем объекты вопроса
    for sc_o in sc_q_objects:
        session.gen3_f_a_f(segment, q_node, sc_o, sc.SC_A_CONST | sc.SC_POS)
    # добавляем автора (пользователь)
    authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, authors_node, 
                               sc_core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST)
    authors_pair_sheaf = sc_utils.createPairBinaryOrient(session, segment, 
                               q_node, authors_node, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, sc_key.common.nrel_authors, 
                               authors_pair_sheaf, sc.SC_CONST)
    # добавляем окна для вывода    
    output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    
    
    output_count = 0
    it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                       sc_key.ui.set_output_windows,
                                                       sc.SC_ARC,
                                                       0), True)
    while not it.is_over():
        sc_utils.createPair(session, segment, output_node, it.value(2), session.get_type(it.value(1)))
        output_count += 1
        it.next()
       
    if output_count == 0:
        sc_utils.createPairPosPerm(session, segment, output_node, kernel.getMainWindow()._getScAddr(), sc.SC_CONST )
    #sc_utils.copySet(session, sc_key.ui.set_output_windows, output_node, segment)
    # link output windows set to question
    output_sheaf = sc_utils.createPairBinaryOrient(session, segment, output_node, 
                                q_node, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, sc_key.ui.nrel_set_of_output_windows, 
                                output_sheaf, sc.SC_CONST) 
    # initiate question
    sc_utils.createPairPosPerm(session, segment, sc_key.questions.initiated, 
                               q_node, sc.SC_CONST)
    return q_node
def genSumRelation(session, segment, operation, _result):
    """

    @param session: session
    @param segment: list of segments to search objects in
    @param operation: sum operation and list of operands
    @param _result: a node which the result of translation
    @return: a node that represents the result of summ
    """
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    #gen set of sum components
    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, setNode,
                        sc.SC_CONST)

    arc1 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el1,
                               sc.SC_CONST)
    arc2 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el2,
                               sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc1,
                        sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc2,
                        sc.SC_CONST)

    #gen sum relations
    res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                 "")[1]  #add result node
    sc_utils.createPair(session, core.Kernel.segment(), _result, res,
                        sc.SC_CONST)

    relation = sc_utils.createPair(session, core.Kernel.segment(), setNode,
                                   res, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relation,
                        sc.SC_CONST)

    idtf = "сумма*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    sumNode = sc_utils.getElementByIdtf(idtf, segment)
    if sumNode == None:
        sumNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param,
                                       sumNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, sumNode,
                        sc.SC_CONST)

    relarc = sc_utils.createPair(session, core.Kernel.segment(), sumNode,
                                 relation, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relarc,
                        sc.SC_CONST)
    return res
def genPowerRelation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    #gen set of sum components
    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, setNode,
                        sc.SC_CONST)

    arc1 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el1,
                               sc.SC_CONST)
    arc2 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el2,
                               sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc1,
                        sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc2,
                        sc.SC_CONST)

    #gen sum relations
    res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                 "")[1]  #add result node
    sc_utils.createPair(session, core.Kernel.segment(), _result, res,
                        sc.SC_CONST)

    relation = sc_utils.createPair(session, core.Kernel.segment(), setNode,
                                   res, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relation,
                        sc.SC_CONST)

    idtf = "возведение в степень*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    powNode = sc_utils.getElementByIdtf(idtf, segment)
    if powNode == None:
        powNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param,
                                       powNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, powNode,
                        sc.SC_CONST)

    relarc = sc_utils.createPair(session, core.Kernel.segment(), powNode,
                                 setNode, sc.SC_CONST)

    baseIdtf = "основание_"
    baseIdtf = sc_utils.utf8ToCp1251(str(baseIdtf))
    baseNode = sc_utils.getElementByIdtf(baseIdtf, segment)
    if baseNode == None:
        baseNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                          baseIdtf)[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, baseNode,
                        sc.SC_CONST)
    a = sc_utils.createPair(session, core.Kernel.segment(), baseNode, arc1,
                            sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, a,
                        sc.SC_CONST)

    expIdtf = "показатель_"
    expIdtf = sc_utils.utf8ToCp1251(str(expIdtf))
    expNode = sc_utils.getElementByIdtf(expIdtf, segment)
    if expNode == None:
        expNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         expIdtf)[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, expNode,
                        sc.SC_CONST)
    a = sc_utils.createPair(session, core.Kernel.segment(), expNode, arc2,
                            sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, a,
                        sc.SC_CONST)

    powerIdtf = "результат_"
    powerIdtf = sc_utils.utf8ToCp1251(str(powerIdtf))
    powerNode = sc_utils.getElementByIdtf(powerIdtf, segment)
    if powerNode == None:
        powerNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                           powerIdtf)[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, powerNode,
                        sc.SC_CONST)
    a = sc_utils.createPair(session, core.Kernel.segment(), powerNode,
                            relation, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, a,
                        sc.SC_CONST)

    sc_utils.createPair(session, core.Kernel.segment(), _result, relarc,
                        sc.SC_CONST)
    return res
Beispiel #7
0
def generate_exppressions(_xmlnode, tag, session, segment):
    """
    Process math tag. Generate relations between variables and numbers
    """
    global parse_result
    while len(stack) > 0:
        parse_result.append(stack.pop(-1))

    #generate unary expressions
    for var in variables:
        varname = var[0]
        while len(var[1]) > 0:
            op = var[1].pop(0)
            expr = op + var[0]
            key = var[0]
            var[0] = expr

            for operation in operations:
                for arg in operation[1]:
                    if arg == key:
                        operation[1][operation[1].index(key)] = expr

            for elem in parse_result:
                if elem == key:
                    parse_result[parse_result.index(key)] = expr

            if op == "-":
                #generate unary minus relation
                #find unary minus relation node, if not find create
                idtf = "обратное число*"
                idtf = sc_utils.utf8ToCp1251(str(idtf))
                unMinusNode = sc_utils.getElementByIdtf(idtf, segment)
                if unMinusNode == None:
                    unMinusNode = session.create_el_idtf(
                        core.Kernel.segment(), sc.SC_NODE, idtf)[1]
                    for param in [keynodes.info.stype_bin_orient_norole_rel]:
                        sc_utils.createPairPosPerm(session,
                                                   core.Kernel.segment(),
                                                   param, unMinusNode,
                                                   sc.SC_CONST)
                sc_utils.createPair(session, core.Kernel.segment(), el,
                                    unMinusNode, sc.SC_CONST)
                #gen node for result
                varSC = variables_sc[key]
                res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                             "")[1]  #node for result
                pair = sc_utils.createPair(
                    session, core.Kernel.segment(), varSC, res,
                    sc.SC_CONST)  #arc between processed node and result
                relBelong = sc_utils.createPair(session, core.Kernel.segment(),
                                                unMinusNode, pair, sc.SC_CONST)
                sc_utils.createPair(session, core.Kernel.segment(), el, res,
                                    sc.SC_CONST)
                sc_utils.createPair(session, core.Kernel.segment(), el, pair,
                                    sc.SC_CONST)
                sc_utils.createPair(session, core.Kernel.segment(), el,
                                    relBelong, sc.SC_CONST)

                variables_sc[expr] = res

    #generate operations
    expr = ""
    for elem in parse_result:
        if (not elem in operation_priority.keys()
                and not elem in functions.keys()):
            stack.append(elem)
        else:
            op = elem
            if (op not in functions.keys()):
                operand1 = stack.pop(-1)
                operand2 = stack.pop(-1)
                expr = operand2 + op + operand1
                stack.append(expr)

                if op in binary_expression_gen.keys():
                    gen_operation = binary_expression_gen[op]
                    res = gen_operation(session, segment, [operand2, operand1],
                                        el)
                    variables_sc[expr] = res
                else:
                    translation_errors.append("Unsupported operation")
            else:
                operands = []
                expr = op + "("
                for i in range(0, functions[op], 1):
                    operands.append(stack.pop(-1))
                    expr += operands[-1]
                    expr += ","
                expr += ")"
                stack.append(expr)

                res = f_generator.gen_function(op, operands, session, segment,
                                               el)
                variables_sc[expr] = res

    return
Beispiel #8
0
def init_cmd(session, segment, sheet, _menu_item_addr, _general_formul,
             _cmd_class_set, _init_set):
    """Initialize question/command from template
    @param session: Session to work with sc-memory
    @param segment: Segment to create sc-constructions  
    @param sheet: Current root sheet (command initiated from it) 
    @param _menu_item_addr: sc-element that designate command (question) menu item
    @type _menu_item_addr: sc_addr
    @param _general_formul: sc-element that designate general formulation relation (different for questions and commands)
    @type _general_formul: sc_addr
    @param _cmd_class_set: sc-element that designate class of commands (used to search command node in template)
    @type _cmd_class_set: sc_addr 
    @param _init_set: sc-element that designate initiated commands set (different for commands and questions)
    @type _init_set: sc_addr  
    """
    kernel = core.Kernel.getSingleton()

    # getting question template
    q_templ = sc_utils.searchOneShotBinPairAttrToNode(session, _menu_item_addr,
                                                      _general_formul,
                                                      sc.SC_CONST)
    if not q_templ:
        raise RuntimeWarning("Question '%s' haven't template" % _caption)
        return

    # getting question node
    it = session.create_iterator(
        session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                  _cmd_class_set, sc.SC_ARC, sc.SC_NODE,
                                  sc.SC_ARC, q_templ), True)
    question_node = None
    while not it.is_over():
        if sc_utils.checkIncToSets(session, it.value(2), [q_templ], 0):
            question_node = it.value(2)
            break

        it.next()

    if question_node is None:
        raise RuntimeError(
            "Can't get command (question) node for a '%s' command" %
            str(_menu_item_addr))

    # creating question using template:
    # * iterate through elements of template set
    # * making values of parameters cmd_desc_..., add that values to addit_elements map
    # * replace var elements to const elements
    # * replace meta elements to var elements
    # * link replaced arcs
    params = {}
    addit_elements = {
    }  # additional elements we need to add into question after params setup
    elements = []
    pairs = []

    it = session.create_iterator(
        session.sc_constraint_new(
            sc_constants.CONSTR_3_f_a_a,
            q_templ,
            sc.SC_A_CONST | sc.SC_POS,  # | sc.SC_PERMANENT,
            0),
        True)
    while not it.is_over():
        _el = it.value(2)
        elements.append(_el)
        # selected elements
        if _el.this == keynodes.ui.arg_set.this:
            params[str(_el.this)], elms = get_arguments_set(session, segment)
            addit_elements[str(_el.this)] = elms
        elif _el.this == keynodes.ui.arg_set_only.this:  # place just set node into question node
            params[str(_el.this)], elms = get_arguments_set(session, segment)
        elif _el.this == keynodes.ui.arg_cur_window.this:
            params[str(_el.this)] = sheet
        elif _el.this == keynodes.ui.arg_1.this:
            arguments = core.Kernel.getSingleton().getArguments()
            if len(arguments) > 0:
                params[str(_el.this)] = arguments[0]._getScAddr()
        elif _el.this == keynodes.ui.arg_2.this:
            arguments = core.Kernel.getSingleton().getArguments()
            if len(arguments) > 1:
                params[str(_el.this)] = arguments[1]._getScAddr()


#            elif _el.this == keynodes.ui.cmd_desc_curr_window.this:
#                params[str(_el.this)] = kernel.rootSheet._getScAddr()
        else:
            el_type = session.get_type(_el)
            idtf = session.get_idtf(_el)
            if not sc_utils.isSystemId(idtf) or (el_type & sc.SC_CONST):
                params[str(_el.this)] = _el
            else:
                # recreate var and meta elements using rules:
                # * var -> const
                # * meta -> var
                post_type = 0
                if el_type & sc.SC_VAR:
                    post_type = sc.SC_CONST
                elif el_type & sc.SC_META:
                    post_type = sc.SC_VAR
                else:
                    raise RuntimeWarning(
                        "Unknown const type for element '%s'" % str(_el))

                if el_type & sc.SC_ARC:
                    pairs.append(_el)
                    params[str(_el.this)] = session.create_el(
                        segment, sc.SC_ARC | post_type)
                elif el_type & sc.SC_NODE:
                    params[str(_el.this)] = session.create_el(
                        segment, sc.SC_NODE | post_type)
                    # TODO: copy structure types for elements

        it.next()

    # add selected set to question set
    q_node_new = params[str(question_node.this)]
    if sc_utils.checkIncToSets(
            session, keynodes.ui.arg_set,
        [question_node], sc.SC_POS | sc.SC_VAR) and sc_utils.checkIncToSets(
            session, keynodes.ui.arg_set, [q_templ], sc.SC_POS | sc.SC_CONST):
        # make pairs to additional elements
        for el in addit_elements[str(keynodes.ui.arg_set.this)]:
            assert sc_utils.createPairPosPerm(session, segment, q_node_new, el,
                                              sc.SC_CONST)

    # linking arcs
    for pair in pairs:
        # get begin and end elements
        _beg = session.get_beg(pair)
        _end = session.get_end(pair)

        if params.has_key(str(_beg.this)):
            _beg = params[str(_beg.this)]
        if params.has_key(str(_end.this)):
            _end = params[str(_end.this)]

        pair_new = params[str(pair.this)]

        session.set_beg(pair_new, _beg)
        session.set_end(pair_new, _end)

    # make authors set
    authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, authors_node,
                               core.Kernel.getSingleton().getUserAddr(),
                               sc.SC_CONST)
    assert authors_node is not None
    authors_pair_sheaf = sc_utils.createPairBinaryOrient(
        session, segment, params[str(question_node.this)], authors_node,
        sc.SC_CONST)
    assert authors_pair_sheaf is not None
    assert sc_utils.createPairPosPerm(session, segment,
                                      keynodes.common.nrel_authors,
                                      authors_pair_sheaf, sc.SC_CONST)

    # make output windows set
    output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    assert output_node is not None

    #        sc_utils.copySet(session, keynodes.ui.set_output_windows, output_node, segment)
    output_count = 0
    it = session.create_iterator(
        session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                  keynodes.ui.set_output_windows, sc.SC_ARC,
                                  0), True)
    while not it.is_over():
        sc_utils.createPair(session, segment, output_node, it.value(2),
                            session.get_type(it.value(1)))
        output_count += 1
        it.next()

    if output_count == 0:
        sc_utils.createPairPosPerm(session, segment, output_node,
                                   kernel.getMainWindow()._getScAddr(),
                                   sc.SC_CONST)

    # link output windows set to question
    output_sheaf = sc_utils.createPairBinaryOrient(
        session, segment, output_node, params[str(question_node.this)],
        sc.SC_CONST)
    assert output_sheaf is not None
    sc_utils.createPairPosPerm(session, segment,
                               keynodes.ui.nrel_set_of_output_windows,
                               output_sheaf, sc.SC_CONST)

    # initiate question
    assert sc_utils.createPairPosPerm(session, segment, _init_set,
                                      params[str(question_node.this)],
                                      sc.SC_CONST) is not None
def genEqualityRelation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, setNode,
                        sc.SC_CONST)

    arc1 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el1,
                               sc.SC_CONST)
    arc2 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el2,
                               sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc1,
                        sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc2,
                        sc.SC_CONST)

    idtf = "равенство*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    eqNode = sc_utils.getElementByIdtf(idtf, segment)
    if eqNode == None:
        eqNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                        idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param,
                                       eqNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, eqNode,
                        sc.SC_CONST)

    relarc = sc_utils.createPair(session, core.Kernel.segment(), eqNode,
                                 setNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relarc,
                        sc.SC_CONST)
    return el1
def gen_fracture_relation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    #gen node that represents fracture
    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, setNode, sc.SC_CONST)

    arc1 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el1, sc.SC_CONST)
    arc2 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc2, sc.SC_CONST)

    #find or generate ordinal fracture node
    idtf = "обыкновенная дробь"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    powNode = sc_utils.getElementByIdtf(idtf, segment)
    if powNode == None:
        powNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, idtf)[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, powNode, sc.SC_CONST)
    relarc = sc_utils.createPair(session,core.Kernel.segment(), powNode, setNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relarc, sc.SC_CONST)

    #find or generate numerator
    numIdtf = "числитель_"
    numIdtf = sc_utils.utf8ToCp1251(str(numIdtf))
    numNode = sc_utils.getElementByIdtf(numIdtf, segment)
    if numNode == None:
        numNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, numIdtf)[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, numNode, sc.SC_CONST)
    a = sc_utils.createPair(session,core.Kernel.segment(), numNode, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, a, sc.SC_CONST)

    #find or generate denominator
    numIdtf = "знаменатель_"
    numIdtf = sc_utils.utf8ToCp1251(str(numIdtf))
    numNode = sc_utils.getElementByIdtf(numIdtf, segment)
    if numNode == None:
        numNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, numIdtf)[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, numNode, sc.SC_CONST)
    a = sc_utils.createPair(session,core.Kernel.segment(), numNode, arc2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, a, sc.SC_CONST)

    return setNode
def genDivideRelation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]] #divident
    el2 = math2sc.variables_sc[operation[1]] #divisor
    res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]  #difference result node
    sc_utils.createPair(session,core.Kernel.segment(), _result, res, sc.SC_CONST)

    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, setNode, sc.SC_CONST)

    #gen input sum parameters
    arc1 = sc_utils.createPair(session,core.Kernel.segment(), setNode, res, sc.SC_CONST)
    arc2 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc2, sc.SC_CONST)

    relation = sc_utils.createPair(session,core.Kernel.segment(), setNode, el1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relation, sc.SC_CONST)

    idtf = "произведение*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    sumNode = sc_utils.getElementByIdtf(idtf, segment)
    if sumNode == None:
        sumNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param, sumNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, sumNode, sc.SC_CONST)

    relarc = sc_utils.createPair(session,core.Kernel.segment(), sumNode, relation, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relarc, sc.SC_CONST)
    return res
def genSumRelation(session, segment, operation, _result):
    """

    @param session: session
    @param segment: list of segments to search objects in
    @param operation: sum operation and list of operands
    @param _result: a node which the result of translation
    @return: a node that represents the result of summ
    """
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    #gen set of sum components
    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, setNode, sc.SC_CONST)

    arc1 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el1, sc.SC_CONST)
    arc2 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc2, sc.SC_CONST)

    #gen sum relations
    res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]  #add result node
    sc_utils.createPair(session,core.Kernel.segment(), _result, res, sc.SC_CONST)

    relation = sc_utils.createPair(session,core.Kernel.segment(), setNode, res, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relation, sc.SC_CONST)

    idtf = "сумма*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    sumNode = sc_utils.getElementByIdtf(idtf, segment)
    if sumNode == None:
        sumNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param, sumNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, sumNode, sc.SC_CONST)

    relarc = sc_utils.createPair(session,core.Kernel.segment(), sumNode, relation, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relarc, sc.SC_CONST)
    return res
Beispiel #13
0
def gen_function(name, params, session, segment, _result):
    """

    @param name: function name
    @param params: list of function params
    @param _result: an output node of the translator
    @return:
    """


    #gen function node
    idtf = name+"*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    funcNode = sc_utils.getElementByIdtf(idtf, segment)
    if funcNode == None:
        funcNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param, funcNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, funcNode, sc.SC_CONST)

    #gen args set
    argsSet = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, argsSet, sc.SC_CONST)

    for x in params:
        param = math2sc.variables_sc[x]
        arc = sc_utils.createPair(session, core.Kernel.segment(), argsSet, param, sc.SC_CONST)
        sc_utils.createPair(session,core.Kernel.segment(), _result, param, sc.SC_CONST)
        sc_utils.createPair(session,core.Kernel.segment(), _result, arc, sc.SC_CONST)
        pass

    #gen relation arc
    result = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    relation = sc_utils.createPair(session, core.Kernel.segment(), argsSet, result, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relation, sc.SC_CONST)
    arc = sc_utils.createPair(session,core.Kernel.segment(), funcNode, relation, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc, sc.SC_CONST)

    return result
def genDivideRelation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]  #divident
    el2 = math2sc.variables_sc[operation[1]]  #divisor
    res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                 "")[1]  #difference result node
    sc_utils.createPair(session, core.Kernel.segment(), _result, res,
                        sc.SC_CONST)

    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, setNode,
                        sc.SC_CONST)

    #gen input sum parameters
    arc1 = sc_utils.createPair(session, core.Kernel.segment(), setNode, res,
                               sc.SC_CONST)
    arc2 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el2,
                               sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc1,
                        sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc2,
                        sc.SC_CONST)

    relation = sc_utils.createPair(session, core.Kernel.segment(), setNode,
                                   el1, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relation,
                        sc.SC_CONST)

    idtf = "произведение*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    sumNode = sc_utils.getElementByIdtf(idtf, segment)
    if sumNode == None:
        sumNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param,
                                       sumNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, sumNode,
                        sc.SC_CONST)

    relarc = sc_utils.createPair(session, core.Kernel.segment(), sumNode,
                                 relation, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relarc,
                        sc.SC_CONST)
    return res
def genPowerRelation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    #gen set of sum components
    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, setNode, sc.SC_CONST)

    arc1 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el1, sc.SC_CONST)
    arc2 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc2, sc.SC_CONST)

    #gen sum relations
    res = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]  #add result node
    sc_utils.createPair(session,core.Kernel.segment(), _result, res, sc.SC_CONST)

    relation = sc_utils.createPair(session,core.Kernel.segment(), setNode, res, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relation, sc.SC_CONST)

    idtf = "возведение в степень*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    powNode = sc_utils.getElementByIdtf(idtf, segment)
    if powNode == None:
        powNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param, powNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, powNode, sc.SC_CONST)

    relarc = sc_utils.createPair(session,core.Kernel.segment(), powNode, setNode, sc.SC_CONST)

    baseIdtf = "основание_"
    baseIdtf = sc_utils.utf8ToCp1251(str(baseIdtf))
    baseNode = sc_utils.getElementByIdtf(baseIdtf, segment)
    if baseNode == None:
        baseNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, baseIdtf)[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, baseNode, sc.SC_CONST)
    a = sc_utils.createPair(session,core.Kernel.segment(), baseNode, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, a, sc.SC_CONST)


    expIdtf = "показатель_"
    expIdtf = sc_utils.utf8ToCp1251(str(expIdtf))
    expNode = sc_utils.getElementByIdtf(expIdtf, segment)
    if expNode == None:
        expNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, expIdtf)[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, expNode, sc.SC_CONST)
    a = sc_utils.createPair(session,core.Kernel.segment(), expNode, arc2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, a, sc.SC_CONST)


    powerIdtf = "результат_"
    powerIdtf = sc_utils.utf8ToCp1251(str(powerIdtf))
    powerNode = sc_utils.getElementByIdtf(powerIdtf, segment)
    if powerNode == None:
        powerNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, powerIdtf)[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, powerNode, sc.SC_CONST)
    a = sc_utils.createPair(session,core.Kernel.segment(), powerNode, relation, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, a, sc.SC_CONST)

    sc_utils.createPair(session,core.Kernel.segment(), _result, relarc, sc.SC_CONST)
    return res
def gen_fracture_relation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    #gen node that represents fracture
    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, setNode,
                        sc.SC_CONST)

    arc1 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el1,
                               sc.SC_CONST)
    arc2 = sc_utils.createPair(session, core.Kernel.segment(), setNode, el2,
                               sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc1,
                        sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc2,
                        sc.SC_CONST)

    #find or generate ordinal fracture node
    idtf = "обыкновенная дробь"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    powNode = sc_utils.getElementByIdtf(idtf, segment)
    if powNode == None:
        powNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         idtf)[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, powNode,
                        sc.SC_CONST)
    relarc = sc_utils.createPair(session, core.Kernel.segment(), powNode,
                                 setNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relarc,
                        sc.SC_CONST)

    #find or generate numerator
    numIdtf = "числитель_"
    numIdtf = sc_utils.utf8ToCp1251(str(numIdtf))
    numNode = sc_utils.getElementByIdtf(numIdtf, segment)
    if numNode == None:
        numNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         numIdtf)[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, numNode,
                        sc.SC_CONST)
    a = sc_utils.createPair(session, core.Kernel.segment(), numNode, arc1,
                            sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, a,
                        sc.SC_CONST)

    #find or generate denominator
    numIdtf = "знаменатель_"
    numIdtf = sc_utils.utf8ToCp1251(str(numIdtf))
    numNode = sc_utils.getElementByIdtf(numIdtf, segment)
    if numNode == None:
        numNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                         numIdtf)[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, numNode,
                        sc.SC_CONST)
    a = sc_utils.createPair(session, core.Kernel.segment(), numNode, arc2,
                            sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, a,
                        sc.SC_CONST)

    return setNode
def genEqualityRelation(session, segment, operation, _result):
    el1 = math2sc.variables_sc[operation[0]]
    el2 = math2sc.variables_sc[operation[1]]

    setNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session,core.Kernel.segment(), _result, setNode, sc.SC_CONST)

    arc1 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el1, sc.SC_CONST)
    arc2 = sc_utils.createPair(session,core.Kernel.segment(), setNode, el2, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc1, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, arc2, sc.SC_CONST)

    idtf = "равенство*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    eqNode = sc_utils.getElementByIdtf(idtf, segment)
    if eqNode == None:
        eqNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param, eqNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, eqNode, sc.SC_CONST)

    relarc = sc_utils.createPair(session,core.Kernel.segment(), eqNode, setNode, sc.SC_CONST)
    sc_utils.createPair(session,core.Kernel.segment(), _result, relarc, sc.SC_CONST)
    return el1
def gen_function(name, params, session, segment, _result):
    """

    @param name: function name
    @param params: list of function params
    @param _result: an output node of the translator
    @return:
    """

    #gen function node
    idtf = name + "*"
    idtf = sc_utils.utf8ToCp1251(str(idtf))
    funcNode = sc_utils.getElementByIdtf(idtf, segment)
    if funcNode == None:
        funcNode = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE,
                                          idtf)[1]
        for param in [keynodes.info.stype_bin_orient_norole_rel]:
            sc_utils.createPairPosPerm(session, core.Kernel.segment(), param,
                                       funcNode, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, funcNode,
                        sc.SC_CONST)

    #gen args set
    argsSet = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    sc_utils.createPair(session, core.Kernel.segment(), _result, argsSet,
                        sc.SC_CONST)

    for x in params:
        param = math2sc.variables_sc[x]
        arc = sc_utils.createPair(session, core.Kernel.segment(), argsSet,
                                  param, sc.SC_CONST)
        sc_utils.createPair(session, core.Kernel.segment(), _result, param,
                            sc.SC_CONST)
        sc_utils.createPair(session, core.Kernel.segment(), _result, arc,
                            sc.SC_CONST)
        pass

    #gen relation arc
    result = session.create_el_idtf(core.Kernel.segment(), sc.SC_NODE, "")[1]
    relation = sc_utils.createPair(session, core.Kernel.segment(), argsSet,
                                   result, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, relation,
                        sc.SC_CONST)
    arc = sc_utils.createPair(session, core.Kernel.segment(), funcNode,
                              relation, sc.SC_CONST)
    sc_utils.createPair(session, core.Kernel.segment(), _result, arc,
                        sc.SC_CONST)

    return result
Beispiel #19
0
def init_cmd(session, segment, sheet, _menu_item_addr, _general_formul, _cmd_class_set, _init_set):
    """Initialize question/command from template
    @param session: Session to work with sc-memory
    @param segment: Segment to create sc-constructions  
    @param sheet: Current root sheet (command initiated from it) 
    @param _menu_item_addr: sc-element that designate command (question) menu item
    @type _menu_item_addr: sc_addr
    @param _general_formul: sc-element that designate general formulation relation (different for questions and commands)
    @type _general_formul: sc_addr
    @param _cmd_class_set: sc-element that designate class of commands (used to search command node in template)
    @type _cmd_class_set: sc_addr 
    @param _init_set: sc-element that designate initiated commands set (different for commands and questions)
    @type _init_set: sc_addr  
    """
    kernel = core.Kernel.getSingleton()
    
    # getting question template
    q_templ = sc_utils.searchOneShotBinPairAttrToNode(session, _menu_item_addr, _general_formul, sc.SC_CONST)
    if not q_templ:
        raise RuntimeWarning("Question '%s' haven't template" % _caption)
        return

    # getting question node
    it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f,
                                                                            _cmd_class_set,
                                                                            sc.SC_ARC,
                                                                            sc.SC_NODE,
                                                                            sc.SC_ARC,
                                                                            q_templ), True)
    question_node = None
    while not it.is_over():
        if sc_utils.checkIncToSets(session, it.value(2), [q_templ], 0):
            question_node = it.value(2)
            break
        
        it.next()
    
    if question_node is None:
        raise RuntimeError("Can't get command (question) node for a '%s' command" % str(_menu_item_addr))

    # creating question using template:
    # * iterate through elements of template set
    # * making values of parameters cmd_desc_..., add that values to addit_elements map
    # * replace var elements to const elements
    # * replace meta elements to var elements
    # * link replaced arcs
    params = {}
    addit_elements = {} # additional elements we need to add into question after params setup
    elements = []
    pairs = []
    
    it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                          q_templ,
                                                          sc.SC_A_CONST | sc.SC_POS,# | sc.SC_PERMANENT,
                                                          0), True)
    while not it.is_over():
        _el = it.value(2)
        elements.append(_el)
        # selected elements
        if _el.this == keynodes.ui.arg_set.this:
            params[str(_el.this)], elms = get_arguments_set(session, segment)
            addit_elements[str(_el.this)] = elms
        elif _el.this == keynodes.ui.arg_set_only.this: # place just set node into question node
            params[str(_el.this)], elms = get_arguments_set(session, segment)
        elif _el.this == keynodes.ui.arg_all_el.this:
            params[str(_el.this)], elms = get_all_elements_set(session, segment)
        elif _el.this == keynodes.ui.arg_cur_window.this:
            params[str(_el.this)] = sheet
        elif _el.this == keynodes.ui.arg_1.this:
            arguments = core.Kernel.getSingleton().getArguments()
            if len(arguments) > 0:
                params[str(_el.this)] = arguments[0]._getScAddr()
        elif _el.this == keynodes.ui.arg_2.this:
            arguments = core.Kernel.getSingleton().getArguments()
            if len(arguments) > 1:
                params[str(_el.this)] = arguments[1]._getScAddr()
        elif _el.this == keynodes.ui.arg_3.this:
            arguments = core.Kernel.getSingleton().getArguments()
            if len(arguments) > 1:
                params[str(_el.this)] = arguments[2]._getScAddr()
#            elif _el.this == keynodes.ui.cmd_desc_curr_window.this:
#                params[str(_el.this)] = kernel.rootSheet._getScAddr()
        else:
            el_type = session.get_type(_el)
            idtf = session.get_idtf(_el)
            if not sc_utils.isSystemId(idtf) or (el_type & sc.SC_CONST):
                params[str(_el.this)] = _el
            else:
                # recreate var and meta elements using rules:
                # * var -> const
                # * meta -> var
                post_type = 0
                if el_type & sc.SC_VAR:
                    post_type = sc.SC_CONST
                elif el_type & sc.SC_META:
                    post_type = sc.SC_VAR
                else:
                    raise RuntimeWarning("Unknown const type for element '%s'" % str(_el))
                
                if el_type & sc.SC_ARC:
                    pairs.append(_el)
                    params[str(_el.this)] = session.create_el(segment, sc.SC_ARC | post_type)
                elif el_type & sc.SC_NODE:
                    params[str(_el.this)] = session.create_el(segment, sc.SC_NODE | post_type)
                    # TODO: copy structure types for elements
                
        it.next()
    
    # add selected set to question set    
    q_node_new = params[str(question_node.this)]
    if sc_utils.checkIncToSets(session, keynodes.ui.arg_set, [question_node], sc.SC_POS | sc.SC_VAR) and sc_utils.checkIncToSets(session, keynodes.ui.arg_set, [q_templ], sc.SC_POS | sc.SC_CONST):
        # make pairs to additional elements
        for el in addit_elements[str(keynodes.ui.arg_set.this)]:
             assert sc_utils.createPairPosPerm(session, segment, q_node_new, el, sc.SC_CONST)
    
    
    # linking arcs
    for pair in pairs:
        # get begin and end elements
        _beg = session.get_beg(pair)
        _end = session.get_end(pair)
        
        if params.has_key(str(_beg.this)):
            _beg = params[str(_beg.this)]
        if params.has_key(str(_end.this)):
            _end = params[str(_end.this)]
            
        pair_new = params[str(pair.this)]
            
        session.set_beg(pair_new, _beg)
        session.set_end(pair_new, _end)
    
    
    # make authors set
    authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, segment, authors_node, core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST)
    assert authors_node is not None
    authors_pair_sheaf = sc_utils.createPairBinaryOrient(session, segment, params[str(question_node.this)], authors_node, sc.SC_CONST)
    assert authors_pair_sheaf is not None
    assert sc_utils.createPairPosPerm(session, segment, keynodes.common.nrel_authors, authors_pair_sheaf, sc.SC_CONST)
    
    
    # make output windows set
    output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST)
    assert output_node is not None
    
#        sc_utils.copySet(session, keynodes.ui.set_output_windows, output_node, segment)
    output_count = 0
    it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a,
                                                       keynodes.ui.set_output_windows,
                                                       sc.SC_ARC,
                                                       0), True)
    while not it.is_over():
       sc_utils.createPair(session, segment, output_node, it.value(2), session.get_type(it.value(1)))
       output_count += 1
       it.next()
       
    if output_count == 0:
       sc_utils.createPairPosPerm(session, segment, output_node, kernel.getMainWindow()._getScAddr(), sc.SC_CONST )
    
    # link output windows set to question
    output_sheaf = sc_utils.createPairBinaryOrient(session, segment, output_node, params[str(question_node.this)], sc.SC_CONST)
    assert output_sheaf is not None
    sc_utils.createPairPosPerm(session, segment, keynodes.ui.nrel_set_of_output_windows, output_sheaf, sc.SC_CONST) 
    
    # initiate question
    assert sc_utils.createPairPosPerm(session, segment, _init_set, params[str(question_node.this)], sc.SC_CONST) is not None