Exemplo n.º 1
0
sc_result resolve_nrel_system_identifier(sc_memory_context const * ctx)
{
    sc_addr *results = 0;
    sc_uint32 results_count = 0;
    sc_stream *stream = sc_stream_memory_new(keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER],
                                             (sc_uint)(sizeof(sc_uchar) * strlen(keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER])),
                                             SC_STREAM_FLAG_READ, SC_FALSE);
    sc_uint32 i = 0;
    sc_iterator5 *it = 0;
    sc_bool found = SC_FALSE;
    sc_addr addr1, addr2;

    // try to find nrel_system_identifier strings
    if (sc_memory_find_links_with_content(ctx, stream, &results, &results_count) == SC_RESULT_OK)
    {
        for (i = 0; i < results_count; i++)
        {
            it = sc_iterator5_a_a_f_a_a_new(ctx,
                                            sc_type_node | sc_type_const | sc_type_node_norole,
                                            sc_type_arc_common | sc_type_const,
                                            results[i],
                                            sc_type_arc_pos_const_perm,
                                            sc_type_const | sc_type_node | sc_type_node_norole);

            while (sc_iterator5_next(it))
            {

                addr1 = sc_iterator5_value(it, 0);
                addr2 = sc_iterator5_value(it, 4);
                // comare begin sc-element and attribute, they must be equivalent
                if (SC_ADDR_IS_EQUAL(addr1, addr2))
                {
                    if (found == SC_FALSE)
                    {
                        sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER] = addr1;
                        found = SC_TRUE;
                    }else
                    {
                        sc_iterator5_free(it);
                        sc_stream_free(stream);
                        g_free(results);
                        g_error("There are more then one sc-elements with system identifier nrel_system_identifier ");
                        return SC_RESULT_ERROR;
                    }
                }
            }

            sc_iterator5_free(it);
        }

        g_free(results);
    }else
        return SC_RESULT_ERROR;

    sc_stream_free(stream);

    return found == SC_TRUE ? SC_RESULT_OK : SC_RESULT_ERROR;
}
//scp_result searchElStr5_f_f_f_a_a(scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5){}
//scp_result searchElStr5_f_f_a_f_a(scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5){}
//scp_result searchElStr5_f_f_a_a_f(scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5){}
//scp_result searchElStr5_f_a_f_f_a(scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5){}
scp_result searchElStr5_f_a_f_a_f(scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5)
{
    sc_iterator5 *it = sc_iterator5_f_a_f_a_f_new(param1->addr, param2->element_type, param3->addr, param4->element_type, param5->addr);
    if (SC_TRUE == sc_iterator5_next(it))
    {
        param2->addr = sc_iterator5_value(it, 1);
        param4->addr = sc_iterator5_value(it, 3);
        sc_iterator5_free(it);
        return SCP_RESULT_TRUE;
    }
    sc_iterator5_free(it);
    return SCP_RESULT_FALSE;
}
Exemplo n.º 3
0
sc_result sc_helper_find_element_by_system_identifier(sc_memory_context const * ctx, const sc_char* data, sc_uint32 len, sc_addr *result_addr)
{
    sc_addr *results = 0;
    sc_uint32 results_count = 0;
    sc_stream *stream = 0;
    sc_uint32 i = 0;
    sc_iterator5 *it = 0;
    sc_bool found = SC_FALSE;

    g_assert(sc_helper_is_initialized == SC_TRUE);
    g_assert(sc_keynodes != 0);

    // try to find sc-links with that contains system identifier value
    stream = sc_stream_memory_new(data, sizeof(sc_char) * len, SC_STREAM_FLAG_READ, SC_FALSE);
    if (sc_memory_find_links_with_content(ctx, stream, &results, &results_count) == SC_RESULT_OK)
    {
        for (i = 0; i < results_count; i++)
        {
            it = sc_iterator5_a_a_f_a_f_new(ctx,
                                            0,
                                            sc_type_arc_common | sc_type_const,
                                            results[i],
                                            sc_type_arc_pos_const_perm,
                                            sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER]);
            if (sc_iterator5_next(it))
            {
                if (found == SC_FALSE)
                {
                    found = SC_TRUE;
                    *result_addr = sc_iterator5_value(it, 0);
                }else
                {
                    // don't foget to free allocated memory before return error
                    sc_iterator5_free(it);
                    sc_stream_free(stream);
                    g_free(results);
                    return SC_RESULT_ERROR_INVALID_STATE;
                }
            }

            sc_iterator5_free(it);
        }

        g_free(results);
    }

    sc_stream_free(stream);

    return found == SC_TRUE ? SC_RESULT_OK : SC_RESULT_ERROR;
}
Exemplo n.º 4
0
sc_result sc_helper_get_system_identifier_link(sc_memory_context const * ctx, sc_addr el, sc_addr *sys_idtf_addr)
{
    sc_iterator5 *it = 0;
    sc_result res = SC_RESULT_ERROR;

    it = sc_iterator5_f_a_a_a_f_new(ctx,
                                    el,
                                    sc_type_arc_common | sc_type_const,
                                    sc_type_link,
                                    sc_type_arc_pos_const_perm,
                                    sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER]);
    g_assert(it != null_ptr);

    while (sc_iterator5_next(it) == SC_TRUE)
    {
        *sys_idtf_addr = sc_iterator5_value(it, 2);
        res = SC_RESULT_OK;
    }

    return res;
}
Exemplo n.º 5
0
	_SC_EXTERN ScAddr value(sc_uint8 idx) const
    {
        check_expr(idx < 5);
        check_expr(isValid());
		return ScAddr(sc_iterator5_value(mIterator, idx));
    }
sc_result agent_search_links_of_relation_connected_with_element(const sc_event *event, sc_addr arg)
{
    sc_addr question, answer, param_elem, param_rel;
    sc_iterator3 *it1, *it2, *it3, *it4;
    sc_iterator5 *it5, *it_order;
    sc_type el_type;
    sc_bool sys_off = SC_TRUE;
    sc_bool param_elem_found = SC_FALSE, param_rel_found = SC_FALSE, found = SC_FALSE;

    if (!sc_memory_get_arc_end(arg, &question))
        return SC_RESULT_ERROR_INVALID_PARAMS;

    // check question type
    if (sc_helper_check_arc(keynode_question_search_links_of_relation_connected_with_element, question, sc_type_arc_pos_const_perm) == SC_FALSE)
        return SC_RESULT_ERROR_INVALID_TYPE;

    answer = create_answer_node();

    // get question arguments
    it5 = sc_iterator5_f_a_a_a_a_new(question,
                                     sc_type_arc_pos_const_perm,
                                     0,
                                     sc_type_arc_pos_const_perm,
                                     sc_type_node | sc_type_const);
    while (sc_iterator5_next(it5) == SC_TRUE)
    {
        if (SC_ADDR_IS_EQUAL(sc_iterator5_value(it5, 4), keynode_rrel_1))
        {
            param_elem = sc_iterator5_value(it5, 2);
            param_elem_found = SC_TRUE;
            continue;
        }
        if (SC_ADDR_IS_EQUAL(sc_iterator5_value(it5, 4), keynode_rrel_2))
        {
            param_rel = sc_iterator5_value(it5, 2);
            param_rel_found = SC_TRUE;
            continue;
        }
    }
    sc_iterator5_free(it5);
    if (param_elem_found == SC_FALSE || param_rel_found == SC_FALSE)
    {
        return SC_RESULT_ERROR;
    }

    appendIntoAnswer(answer, param_elem);

    if (IS_SYSTEM_ELEMENT(param_elem) || IS_SYSTEM_ELEMENT(param_rel))
        sys_off = SC_FALSE;

    if (SC_TRUE == sc_helper_check_arc(keynode_quasybinary_relation, param_rel, sc_type_arc_pos_const_perm))
    {
        // Search subclasses in quasybinary relation
        // Iterate input arcs of quasybinary relation
        it5 = sc_iterator5_a_a_f_a_f_new(sc_type_const,
                                         sc_type_const | sc_type_arc_common,
                                         param_elem,
                                         sc_type_arc_pos_const_perm,
                                         param_rel);
        while (sc_iterator5_next(it5) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 0))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))))
                continue;

            found = SC_TRUE;

            appendIntoAnswer(answer, sc_iterator5_value(it5, 0));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 3));

            search_arc_components(sc_iterator5_value(it5, 0), answer, sys_off);

            // Iterate subclasses in quasybinary relation
            it1 = sc_iterator3_f_a_a_new(sc_iterator5_value(it5, 0),
                                         sc_type_arc_pos_const_perm,
                                         sc_type_const | sc_type_node);
            while (sc_iterator3_next(it1) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 1))
                                           || IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 2))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it1, 1));
                appendIntoAnswer(answer, sc_iterator3_value(it1, 2));

                search_arc_components(sc_iterator3_value(it1, 2), answer, sys_off);

                // iterate order relations between elements
                it_order = sc_iterator5_f_a_a_a_a_new(sc_iterator3_value(it1, 2),
                                                      sc_type_arc_common | sc_type_const,
                                                      sc_type_node | sc_type_const,
                                                      sc_type_arc_pos_const_perm,
                                                      sc_type_node | sc_type_const);
                while (sc_iterator5_next(it_order) == SC_TRUE)
                {
                    if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 1)) || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 2))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 3)) || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 4))))
                        continue;

                    if (SC_FALSE == sc_helper_check_arc(keynode_order_relation, sc_iterator5_value(it_order, 4), sc_type_arc_pos_const_perm))
                        continue;
                    if (SC_FALSE == sc_helper_check_arc(sc_iterator5_value(it5, 0), sc_iterator5_value(it_order, 2), sc_type_arc_pos_const_perm))
                        continue;

                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 1));
                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 2));
                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 3));
                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 4));
                }
                sc_iterator5_free(it_order);

                // iterate roles of element in link
                it2 = sc_iterator3_a_a_f_new(sc_type_node | sc_type_const,
                                             sc_type_arc_pos_const_perm,
                                             sc_iterator3_value(it1, 1));
                while (sc_iterator3_next(it2) == SC_TRUE)
                {
                    sc_memory_get_element_type(sc_iterator3_value(it2, 0), &el_type);
                    if (!(el_type & sc_type_node_role))
                        continue;

                    if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 0))
                                               || IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 1))))
                        continue;

                    appendIntoAnswer(answer, sc_iterator3_value(it2, 0));
                    appendIntoAnswer(answer, sc_iterator3_value(it2, 1));
                }
                sc_iterator3_free(it2);
            }
            sc_iterator3_free(it1);
        }
        sc_iterator5_free(it5);

        // Iterate input arcs of quasybinary relation
        it1 = sc_iterator3_a_a_f_new(sc_type_const | sc_type_node,
                                     sc_type_arc_pos_const_perm,
                                     param_elem);
        while (sc_iterator3_next(it1) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 0))
                                       || IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 1))))
                continue;

            // search all parents in quasybinary relation
            it5 = sc_iterator5_f_a_a_a_f_new(sc_iterator3_value(it1, 0),
                                             sc_type_arc_common | sc_type_const,
                                             sc_type_node | sc_type_const,
                                             sc_type_arc_pos_const_perm,
                                             param_rel);
            if (sc_iterator5_next(it5) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 2))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))))
                    continue;

                appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
                appendIntoAnswer(answer, sc_iterator5_value(it5, 2));
                appendIntoAnswer(answer, sc_iterator5_value(it5, 3));

                search_arc_components(sc_iterator5_value(it5, 2), answer, sys_off);

                appendIntoAnswer(answer, sc_iterator3_value(it1, 0));
                appendIntoAnswer(answer, sc_iterator3_value(it1, 1));

                search_arc_components(sc_iterator3_value(it1, 0), answer, sys_off);
            }
            sc_iterator5_free(it5);
        }
        sc_iterator3_free(it1);
    }
    else
    {
        // Iterate output arcs of given relation
        it5 = sc_iterator5_f_a_a_a_f_new(param_elem,
                                         sc_type_const,
                                         sc_type_const,
                                         sc_type_arc_pos_const_perm,
                                         param_rel);
        while (sc_iterator5_next(it5) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 2))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))))
                continue;

            found = SC_TRUE;

            appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 2));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 3));

            search_arc_components(sc_iterator5_value(it5, 2), answer, sys_off);
        }
        sc_iterator5_free(it5);

        // Iterate input arcs of given relation
        it5 = sc_iterator5_a_a_f_a_f_new(sc_type_const,
                                         sc_type_const,
                                         param_elem,
                                         sc_type_arc_pos_const_perm,
                                         param_rel);
        while (sc_iterator5_next(it5) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 0))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))))
                continue;

            appendIntoAnswer(answer, sc_iterator5_value(it5, 0));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 3));

            search_arc_components(sc_iterator5_value(it5, 0), answer, sys_off);
        }
        sc_iterator5_free(it5);

        // Iterate input arcs for input element
        it1 = sc_iterator3_a_a_f_new(sc_type_const,
                                     sc_type_arc_pos_const_perm,
                                     param_elem);
        while (sc_iterator3_next(it1) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 0))
                                       || IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 1))))
                continue;

            // Iterate input arcs for input element
            it2 = sc_iterator3_f_a_f_new(param_rel,
                                         sc_type_arc_pos_const_perm,
                                         sc_iterator3_value(it1, 0));
            if (sc_iterator3_next(it2) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 1))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it2, 1));
                appendIntoAnswer(answer, sc_iterator3_value(it1, 0));

                // Iterate elements of fonnd link of given relation
                it3 = sc_iterator3_f_a_a_new(sc_iterator3_value(it1, 0),
                                             sc_type_arc_pos_const_perm,
                                             sc_type_const);
                while (sc_iterator3_next(it3) == SC_TRUE)
                {
                    if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1))
                                               || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 2))))
                        continue;

                    appendIntoAnswer(answer, sc_iterator3_value(it3, 1));
                    appendIntoAnswer(answer, sc_iterator3_value(it3, 2));

                    search_arc_components(sc_iterator3_value(it3, 2), answer, sys_off);

                    // Iterate role relations
                    it4 = sc_iterator3_a_a_f_new(sc_type_const | sc_type_node,
                                                 sc_type_arc_pos_const_perm,
                                                 sc_iterator3_value(it3, 1));
                    while (sc_iterator3_next(it4) == SC_TRUE)
                    {
                        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 0))
                                                   || IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 1))))
                            continue;

                        appendIntoAnswer(answer, sc_iterator3_value(it4, 0));
                        appendIntoAnswer(answer, sc_iterator3_value(it4, 1));

                        search_arc_components(sc_iterator3_value(it4, 0), answer, sys_off);
                    }
                    sc_iterator3_free(it4);
                }
                sc_iterator3_free(it3);
            }
            sc_iterator3_free(it2);
        }
        sc_iterator3_free(it1);
    }

    if (found == SC_TRUE)
    {
        appendIntoAnswer(answer, param_rel);
    }

    connect_answer_to_question(question, answer);
    finish_question(question);

    return SC_RESULT_OK;
}
void search_translation(sc_addr elem, sc_addr answer, sc_bool sys_off)
{
    sc_iterator5 *it5;
    sc_iterator3 *it3, *it4;
    sc_bool found = SC_FALSE;

    // iterate translations of sc-element
    it5 = sc_iterator5_a_a_f_a_f_new(sc_type_node | sc_type_const,
                                     sc_type_arc_common | sc_type_const,
                                     elem,
                                     sc_type_arc_pos_const_perm,
                                     keynode_nrel_translation);
    while (sc_iterator5_next(it5) == SC_TRUE)
    {
        found = SC_TRUE;

        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 0))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))))
            continue;

        appendIntoAnswer(answer, sc_iterator5_value(it5, 0));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 3));

        // iterate translation sc-links
        it3 = sc_iterator3_f_a_a_new(sc_iterator5_value(it5, 0),
                                     sc_type_arc_pos_const_perm,
                                     0);
        while (sc_iterator3_next(it3) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 2))))
                continue;

            // iterate input arcs for link
            it4 = sc_iterator3_a_a_f_new(sc_type_node,
                                         sc_type_arc_pos_const_perm,
                                         sc_iterator3_value(it3, 2));
            while (sc_iterator3_next(it4) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 0))))
                    continue;
                if (sc_helper_check_arc(keynode_languages, sc_iterator3_value(it4, 0), sc_type_arc_pos_const_perm) == SC_TRUE)
                {
                    appendIntoAnswer(answer, sc_iterator3_value(it4, 0));
                    appendIntoAnswer(answer, sc_iterator3_value(it4, 1));
                }
            }
            sc_iterator3_free(it4);

            // iterate input arcs for arc
            it4 = sc_iterator3_a_a_f_new(sc_type_node,
                                         sc_type_arc_pos_const_perm,
                                         sc_iterator3_value(it3, 1));
            while (sc_iterator3_next(it4) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 0)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 1))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it4, 0));
                appendIntoAnswer(answer, sc_iterator3_value(it4, 1));
            }
            sc_iterator3_free(it4);

            appendIntoAnswer(answer, sc_iterator3_value(it3, 1));
            appendIntoAnswer(answer, sc_iterator3_value(it3, 2));
        }
        sc_iterator3_free(it3);

    }
    sc_iterator5_free(it5);

    if (found == SC_TRUE)
    {
        appendIntoAnswer(answer, keynode_nrel_translation);
    }
}
sc_result agent_search_full_semantic_neighborhood(const sc_event *event, sc_addr arg)
{
    sc_addr question, answer;
    sc_iterator3 *it1, *it2, *it3, *it4, *it6;
    sc_iterator5 *it5, *it_order, *it_order2;
    sc_type el_type;
    sc_bool sys_off = SC_TRUE;
    sc_bool key_order_found = SC_FALSE;

    if (!sc_memory_get_arc_end(arg, &question))
        return SC_RESULT_ERROR_INVALID_PARAMS;

    // check question type
    if (sc_helper_check_arc(keynode_question_full_semantic_neighborhood, question, sc_type_arc_pos_const_perm) == SC_FALSE)
        return SC_RESULT_ERROR_INVALID_TYPE;

    answer = create_answer_node();

    // get question argument
    it1 = sc_iterator3_f_a_a_new(question, sc_type_arc_pos_const_perm, 0);
    if (sc_iterator3_next(it1) == SC_TRUE)
    {
        if (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 2)))
            sys_off = SC_FALSE;

        appendIntoAnswer(answer, sc_iterator3_value(it1, 2));

        search_translation(sc_iterator3_value(it1, 2), answer, sys_off);
        search_arc_components(sc_iterator3_value(it1, 2), answer, sys_off);

        // iterate input arcs
        it2 = sc_iterator3_a_a_f_new(0,
                                     0,
                                     sc_iterator3_value(it1, 2));
        while (sc_iterator3_next(it2) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 0)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 1))))
                continue;

            appendIntoAnswer(answer, sc_iterator3_value(it2, 0));
            appendIntoAnswer(answer, sc_iterator3_value(it2, 1));

            search_arc_components(sc_iterator3_value(it2, 0), answer, sys_off);

            // iterate input arcs into found arc, to find relations
            it3 = sc_iterator3_a_a_f_new(sc_type_node,
                                         sc_type_arc_pos_const_perm,
                                         sc_iterator3_value(it2, 1));
            while (sc_iterator3_next(it3) == SC_TRUE)
            {
                sc_memory_get_element_type(sc_iterator3_value(it3, 0), &el_type);
                if (!(el_type & (sc_type_node_norole | sc_type_node_role)))
                    continue;

                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 0))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it3, 0));
                appendIntoAnswer(answer, sc_iterator3_value(it3, 1));

                search_arc_components(sc_iterator3_value(it3, 0), answer, sys_off);

                // search typical sc-neighborhood if necessary
                if (SC_ADDR_IS_EQUAL(keynode_rrel_key_sc_element, sc_iterator3_value(it3, 0)))
                {
                    search_typical_sc_neighborhood(sc_iterator3_value(it2, 0), answer, sys_off);
                }

                // check if it's a quasy binary relation
                if (sc_helper_check_arc(keynode_quasybinary_relation, sc_iterator3_value(it3, 0), sc_type_arc_pos_const_perm) == SC_TRUE)
                {
                    // iterate elements of relation
                    it4 = sc_iterator3_f_a_a_new(sc_iterator3_value(it2, 0), sc_type_arc_pos_const_perm, 0);
                    while (sc_iterator3_next(it4) == SC_TRUE)
                    {
                        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it4, 2))))
                            continue;

                        appendIntoAnswer(answer, sc_iterator3_value(it4, 1));
                        appendIntoAnswer(answer, sc_iterator3_value(it4, 2));

                        search_arc_components(sc_iterator3_value(it4, 2), answer, sys_off);

                        // iterate order relations between elements
                        it_order = sc_iterator5_f_a_a_a_a_new(sc_iterator3_value(it4, 2),
                                                              sc_type_arc_common | sc_type_const,
                                                              sc_type_node | sc_type_const,
                                                              sc_type_arc_pos_const_perm,
                                                              sc_type_node | sc_type_const);
                        while (sc_iterator5_next(it_order) == SC_TRUE)
                        {
                            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 1)) || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 2))
                                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 3)) || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 4))))
                                continue;

                            if (SC_FALSE == sc_helper_check_arc(keynode_order_relation, sc_iterator5_value(it_order, 4), sc_type_arc_pos_const_perm))
                                continue;
                            if (SC_FALSE == sc_helper_check_arc(sc_iterator3_value(it2, 0), sc_iterator5_value(it_order, 2), sc_type_arc_pos_const_perm))
                                continue;

                            appendIntoAnswer(answer, sc_iterator5_value(it_order, 1));
                            appendIntoAnswer(answer, sc_iterator5_value(it_order, 2));
                            appendIntoAnswer(answer, sc_iterator5_value(it_order, 3));
                            appendIntoAnswer(answer, sc_iterator5_value(it_order, 4));

                        }
                        sc_iterator5_free(it_order);

                        // iterate roles of element in link
                        it6 = sc_iterator3_a_a_f_new(sc_type_node | sc_type_const,
                                                     sc_type_arc_pos_const_perm,
                                                     sc_iterator3_value(it4, 1));
                        while (sc_iterator3_next(it6) == SC_TRUE)
                        {
                            sc_memory_get_element_type(sc_iterator3_value(it6, 0), &el_type);
                            if (!(el_type & sc_type_node_role))
                                continue;

                            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it6, 0))
                                                       || IS_SYSTEM_ELEMENT(sc_iterator3_value(it6, 1))))
                                continue;

                            appendIntoAnswer(answer, sc_iterator3_value(it6, 0));
                            appendIntoAnswer(answer, sc_iterator3_value(it6, 1));

                            search_arc_components(sc_iterator3_value(it6, 0), answer, sys_off);
                        }
                        sc_iterator3_free(it6);

                    }
                    sc_iterator3_free(it4);
                }
            }
            sc_iterator3_free(it3);

            // search all parents in quasybinary relation
            it5 = sc_iterator5_f_a_a_a_a_new(sc_iterator3_value(it2, 0),
                                             sc_type_arc_common | sc_type_const,
                                             sc_type_node | sc_type_const,
                                             sc_type_arc_pos_const_perm,
                                             sc_type_node | sc_type_const);
            while (sc_iterator5_next(it5) == SC_TRUE)
            {
                // check if it's a quasy binary relation
                if (sc_helper_check_arc(keynode_quasybinary_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm) == SC_TRUE)
                {
                    if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 2))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 4))))
                        continue;

                    appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
                    appendIntoAnswer(answer, sc_iterator5_value(it5, 2));
                    appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
                    appendIntoAnswer(answer, sc_iterator5_value(it5, 4));

                    search_arc_components(sc_iterator5_value(it5, 2), answer, sys_off);
                }
            }
            sc_iterator5_free(it5);

            // search translation for element
            search_translation(sc_iterator3_value(it2, 0), answer, sys_off);

            // search non-binary relation link
            search_nonbinary_relation(sc_iterator3_value(it2, 0), answer, sys_off);
        }
        sc_iterator3_free(it2);

        // iterate output arcs
        it2 = sc_iterator3_f_a_a_new(sc_iterator3_value(it1, 2),
                                     0,
                                     0);
        while (sc_iterator3_next(it2) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 2))))
                continue;

            appendIntoAnswer(answer, sc_iterator3_value(it2, 1));
            appendIntoAnswer(answer, sc_iterator3_value(it2, 2));

            search_arc_components(sc_iterator3_value(it2, 2), answer, sys_off);

            // iterate input arcs into found arc, to find relations
            it3 = sc_iterator3_a_a_f_new(sc_type_node,
                                         sc_type_arc_pos_const_perm,
                                         sc_iterator3_value(it2, 1));
            while (sc_iterator3_next(it3) == SC_TRUE)
            {
                sc_memory_get_element_type(sc_iterator3_value(it3, 0), &el_type);
                if (!(el_type & (sc_type_node_norole | sc_type_node_role)))
                    continue;

                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 0))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it3, 0));
                appendIntoAnswer(answer, sc_iterator3_value(it3, 1));

                // search of key sc-elements order
                if (SC_ADDR_IS_EQUAL(sc_iterator3_value(it3, 0), keynode_rrel_key_sc_element))
                {
                    it_order2 = sc_iterator5_f_a_a_a_f_new(sc_iterator3_value(it2, 1),
                                                           sc_type_arc_common | sc_type_const,
                                                           sc_type_arc_pos_const_perm,
                                                           sc_type_arc_pos_const_perm,
                                                           keynode_nrel_key_sc_element_base_order);
                    while (sc_iterator5_next(it_order2) == SC_TRUE)
                    {
                        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order2, 1)) || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order2, 3))))
                            continue;

                        appendIntoAnswer(answer, sc_iterator5_value(it_order2, 1));
                        appendIntoAnswer(answer, sc_iterator5_value(it_order2, 3));
                        if (SC_FALSE == key_order_found)
                        {
                            key_order_found = SC_TRUE;
                            appendIntoAnswer(answer, keynode_nrel_key_sc_element_base_order);
                        }
                    }
                    sc_iterator5_free(it_order2);
                }

                // search translation for element
                search_translation(sc_iterator3_value(it3, 0), answer, sys_off);
            }
            sc_iterator3_free(it3);

            // search translation for element
            search_translation(sc_iterator3_value(it2, 2), answer, sys_off);

            // check if element is an sc-link
            if (SC_RESULT_OK == sc_memory_get_element_type(sc_iterator3_value(it2, 2), &el_type) &&
                (el_type | sc_type_link))
            {
                // iterate input arcs for link
                it3 = sc_iterator3_a_a_f_new(sc_type_node | sc_type_const,
                                             sc_type_arc_pos_const_perm,
                                             sc_iterator3_value(it2, 2));
                while (sc_iterator3_next(it3) == SC_TRUE)
                {
                    if (sc_helper_check_arc(keynode_languages, sc_iterator3_value(it3, 0), sc_type_arc_pos_const_perm) == SC_TRUE)
                    {
                        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 0))))
                            continue;

                        appendIntoAnswer(answer, sc_iterator3_value(it3, 0));
                        appendIntoAnswer(answer, sc_iterator3_value(it3, 1));

                        search_arc_components(sc_iterator3_value(it3, 0), answer, sys_off);
                    }
                }
                sc_iterator3_free(it3);
            }
        }
        sc_iterator3_free(it2);

    }
    sc_iterator3_free(it1);

    connect_answer_to_question(question, answer);
    finish_question(question);

    return SC_RESULT_OK;
}
void search_typical_sc_neighborhood(sc_addr elem, sc_addr answer, sc_bool sys_off)
{
    sc_iterator3 *it1, *it0;
    sc_iterator5 *it5;
    sc_bool found = SC_FALSE;

    // search for keynode_typical_sc_neighborhood
    it0 = sc_iterator3_a_a_f_new(sc_type_node | sc_type_const,
                                 sc_type_arc_pos_const_perm,
                                 elem);
    while (sc_iterator3_next(it0) == SC_TRUE)
    {
        if (SC_ADDR_IS_EQUAL(sc_iterator3_value(it0, 0), keynode_typical_sc_neighborhood))
        {
            found = SC_TRUE;
            // iterate input arcs for elem
            it1 = sc_iterator3_f_a_a_new(elem,
                                         sc_type_arc_pos_const_perm,
                                         0);
            while (sc_iterator3_next(it1) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 1)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 2))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it1, 1));
                appendIntoAnswer(answer, sc_iterator3_value(it1, 2));
            }
            sc_iterator3_free(it1);

            appendIntoAnswer(answer, sc_iterator3_value(it0, 1));
            appendIntoAnswer(answer, sc_iterator3_value(it0, 0));
            continue;
        }

        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it0, 0)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it0, 1))))
            continue;

        it5 = sc_iterator5_f_a_f_a_f_new(keynode_sc_neighborhood,
                                         sc_type_arc_common | sc_type_const,
                                         sc_iterator3_value(it0, 0),
                                         sc_type_arc_pos_const_perm,
                                         keynode_nrel_inclusion);
        if (sc_iterator5_next(it5) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1)) || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))))
                continue;

            appendIntoAnswer(answer, sc_iterator3_value(it0, 0));
            appendIntoAnswer(answer, sc_iterator3_value(it0, 1));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
        }
        sc_iterator5_free(it5);

    }
    sc_iterator3_free(it0);
    if (found == SC_TRUE)
    {
        appendIntoAnswer(answer, keynode_typical_sc_neighborhood);
    }
}
Exemplo n.º 10
0
scp_result scp_iterator5_next(sc_memory_context *context, scp_iterator5 *iter, scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *param4, scp_operand *param5)
{
    sc_uint32 fixed1 = 0;
    sc_uint32 fixed3 = 0;
    sc_uint32 fixed5 = 0;
    sc_uint32 fixed = 0;
    if (param2->param_type == SCP_FIXED)
    {
        return print_error("SCP ITERATOR 5 NEW", "Parameter 2 must have ASSIGN modifier");
    }
    if (param4->param_type == SCP_FIXED)
    {
        return print_error("SCP ITERATOR 5 NEW", "Parameter 4 must have ASSIGN modifier");              ;
    }
    if (param1->param_type == SCP_FIXED)
    {
        if (SC_FALSE == sc_memory_is_element(context, param1->addr))
        {
            return print_error("SCP ITERATOR 5 NEW", "Parameter 1 has modifier FIXED, but has not value");
        }
        fixed1 = 0x1;
    }
    if (param3->param_type == SCP_FIXED)
    {
        if (SC_FALSE == sc_memory_is_element(context, param3->addr))
        {
            return print_error("SCP ITERATOR 5 NEW", "Parameter 3 has modifier FIXED, but has not value");
        }
        fixed3 = 0x100;
    }
    if (param5->param_type == SCP_FIXED)
    {
        if (SC_FALSE == sc_memory_is_element(context, param5->addr))
        {
            return print_error("SCP ITERATOR 5 NEW", "Parameter 5 has modifier FIXED, but has not value");
        }
        fixed5 = 0x10000;
    }
    fixed = (fixed1 | fixed3 | fixed5);
    switch (fixed)
    {
        case 0x00001:
            if (iter->type != sc_iterator5_f_a_a_a_a)
            {
                return print_error("SCP ITERATOR 5 NEXT", "Iterator type and parameter type combination doesn't match");
            }
            else
            {
                if (SC_TRUE == sc_iterator5_next(iter))
                {
                    param2->addr = sc_iterator5_value(iter, 1);
                    param3->addr = sc_iterator5_value(iter, 2);
                    param4->addr = sc_iterator5_value(iter, 3);
                    param5->addr = sc_iterator5_value(iter, 4);
                    return SCP_RESULT_TRUE;
                }
                else
                {
                    return SCP_RESULT_FALSE;
                }
            }
        case 0x00100:
            if (iter->type != sc_iterator5_a_a_f_a_a)
            {
                return print_error("SCP ITERATOR 5 NEXT", "Iterator type and parameter type combination doesn't match");
            }
            else
            {
                if (SC_TRUE == sc_iterator5_next(iter))
                {
                    param1->addr = sc_iterator5_value(iter, 0);
                    param2->addr = sc_iterator5_value(iter, 1);
                    param4->addr = sc_iterator5_value(iter, 3);
                    param5->addr = sc_iterator5_value(iter, 4);
                    return SCP_RESULT_TRUE;
                }
                else
                {
                    return SCP_RESULT_FALSE;
                }
            }
        case 0x10100:
            if (iter->type != sc_iterator5_a_a_f_a_f)
            {
                return print_error("SCP ITERATOR 5 NEXT", "Iterator type and parameter type combination doesn't match");
            }
            else
            {
                if (SC_TRUE == sc_iterator5_next(iter))
                {
                    param1->addr = sc_iterator5_value(iter, 0);
                    param2->addr = sc_iterator5_value(iter, 1);
                    param4->addr = sc_iterator5_value(iter, 3);
                    return SCP_RESULT_TRUE;
                }
                else
                {
                    return SCP_RESULT_FALSE;
                }
            }
        case 0x00101:
            if (iter->type != sc_iterator5_f_a_f_a_a)
            {
                return print_error("SCP ITERATOR 5 NEXT", "Iterator type and parameter type combination doesn't match");
            }
            else
            {
                if (SC_TRUE == sc_iterator5_next(iter))
                {
                    param2->addr = sc_iterator5_value(iter, 1);
                    param4->addr = sc_iterator5_value(iter, 3);
                    param5->addr = sc_iterator5_value(iter, 4);
                    return SCP_RESULT_TRUE;
                }
                else
                {
                    return SCP_RESULT_FALSE;
                }
            }
        case 0x10001:
            if (iter->type != sc_iterator5_f_a_a_a_f)
            {
                return print_error("SCP ITERATOR 5 NEXT", "Iterator type and parameter type combination doesn't match");
            }
            else
            {
                if (SC_TRUE == sc_iterator5_next(iter))
                {
                    param2->addr = sc_iterator5_value(iter, 1);
                    param3->addr = sc_iterator5_value(iter, 2);
                    param4->addr = sc_iterator5_value(iter, 3);
                    return SCP_RESULT_TRUE;
                }
                else
                {
                    return SCP_RESULT_FALSE;
                }
            }
        case 0x10101:
            if (iter->type != sc_iterator5_f_a_f_a_f)
            {
                return print_error("SCP ITERATOR 5 NEXT", "Iterator type and parameter type combination doesn't match");
            }
            else
            {
                if (SC_TRUE == sc_iterator5_next(iter))
                {
                    param2->addr = sc_iterator5_value(iter, 1);
                    param4->addr = sc_iterator5_value(iter, 3);
                    return SCP_RESULT_TRUE;
                }
                else
                {
                    return SCP_RESULT_FALSE;
                }
            }
        default:
            return print_error("SCP ITERATOR 3 NEXT", "Unsupported parameter type combination");
    }
    return SCP_RESULT_ERROR;
}
Exemplo n.º 11
0
void search_superclasses_rec(sc_addr elem, sc_addr answer, sc_bool sys_off)
{
    sc_iterator3 *it3;
    sc_iterator5 *it5;

    // search taxonomy
    it5 = sc_iterator5_a_a_f_a_a_new(s_default_ctx,
                                     sc_type_node | sc_type_const,
                                     sc_type_arc_common | sc_type_const,
                                     elem,
                                     sc_type_arc_pos_const_perm,
                                     sc_type_node | sc_type_const);
    while (sc_iterator5_next(it5) == SC_TRUE)
    {
        if (SC_FALSE == sc_helper_check_arc(s_default_ctx, keynode_taxonomy_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm))
            continue;
        if (SC_TRUE == sys_off && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 0))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 4))))
            continue;

        appendIntoAnswer(answer, sc_iterator5_value(it5, 0));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 4));

        search_superclasses_rec(sc_iterator5_value(it5, 0), answer, sys_off);
    }
    sc_iterator5_free(it5);

    // iterate input arcs
    it3 = sc_iterator3_a_a_f_new(s_default_ctx,
                                 sc_type_node | sc_type_const,
                                 sc_type_arc_pos_const_perm,
                                 elem);
    while (sc_iterator3_next(it3) == SC_TRUE)
    {
        // search all parents in quasybinary relation
        it5 = sc_iterator5_f_a_a_a_a_new(s_default_ctx,
                                         sc_iterator3_value(it3, 0),
                                         sc_type_arc_common | sc_type_const,
                                         sc_type_node | sc_type_const,
                                         sc_type_arc_pos_const_perm,
                                         sc_type_node | sc_type_const);
        while (sc_iterator5_next(it5) == SC_TRUE)
        {
            // check if it's a quasybinary relation
            if (sc_helper_check_arc(s_default_ctx, keynode_quasybinary_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm) == SC_TRUE)
            {
                if (!(sc_helper_check_arc(s_default_ctx, keynode_taxonomy_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm) == SC_TRUE
                      || sc_helper_check_arc(s_default_ctx, keynode_decomposition_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm) == SC_TRUE))
                    continue;


                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 2))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 4))
                                           || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 0))
                                           || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1))))
                    continue;


                appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
                appendIntoAnswer(answer, sc_iterator5_value(it5, 2));
                appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
                appendIntoAnswer(answer, sc_iterator5_value(it5, 4));

                appendIntoAnswer(answer, sc_iterator3_value(it3, 0));
                appendIntoAnswer(answer, sc_iterator3_value(it3, 1));

                search_superclasses_rec(sc_iterator5_value(it5, 2), answer, sys_off);
            }
        }
        sc_iterator5_free(it5);

    }
    sc_iterator3_free(it3);
}
Exemplo n.º 12
0
sc_result agent_search_decomposition(const sc_event *event, sc_addr arg)
{
    sc_addr question, answer;
    sc_iterator3 *it1, *it2, *it3;
    sc_iterator5 *it5, *it_order;
    sc_bool sys_off = SC_TRUE;
    sc_type el_type;

    if (!sc_memory_get_arc_end(s_default_ctx, arg, &question))
        return SC_RESULT_ERROR_INVALID_PARAMS;

    // check question type
    if (sc_helper_check_arc(s_default_ctx, keynode_question_decomposition, question, sc_type_arc_pos_const_perm) == SC_FALSE)
        return SC_RESULT_ERROR_INVALID_TYPE;

    answer = create_answer_node();

    // get operation argument
    it1 = sc_iterator3_f_a_a_new(s_default_ctx,
                                 question,
                                 sc_type_arc_pos_const_perm,
                                 0);
    if (sc_iterator3_next(it1) == SC_TRUE)
    {
        if (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 2)))
            sys_off = SC_FALSE;

        appendIntoAnswer(answer, sc_iterator3_value(it1, 2));

        // iterate decomposition
        it5 = sc_iterator5_a_a_f_a_a_new(s_default_ctx,
                                         sc_type_node | sc_type_const,
                                         sc_type_arc_common | sc_type_const,
                                         sc_iterator3_value(it1, 2),
                                         sc_type_arc_pos_const_perm,
                                         sc_type_node | sc_type_const);
        while (sc_iterator5_next(it5) == SC_TRUE)
        {
            if (SC_FALSE == sc_helper_check_arc(s_default_ctx, keynode_decomposition_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm))
                continue;
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 0))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))
                                       || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 4))))
                continue;

            appendIntoAnswer(answer, sc_iterator5_value(it5, 0));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
            appendIntoAnswer(answer, sc_iterator5_value(it5, 4));

            // iterate decomposition set elements
            it2 = sc_iterator3_f_a_a_new(s_default_ctx,
                                         sc_iterator5_value(it5, 0),
                                         sc_type_arc_pos_const_perm,
                                         0);
            while (sc_iterator3_next(it2) == SC_TRUE)
            {
                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 1))
                                           || IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 2))))
                    continue;

                // iterate order relations between elements
                it_order = sc_iterator5_f_a_a_a_a_new(s_default_ctx,
                                                      sc_iterator3_value(it2, 2),
                                                      sc_type_arc_common | sc_type_const,
                                                      sc_type_node | sc_type_const,
                                                      sc_type_arc_pos_const_perm,
                                                      sc_type_node | sc_type_const);
                while (sc_iterator5_next(it_order) == SC_TRUE)
                {
                    if (SC_FALSE == sc_helper_check_arc(s_default_ctx, keynode_order_relation, sc_iterator5_value(it_order, 4), sc_type_arc_pos_const_perm))
                        continue;
                    if (SC_FALSE == sc_helper_check_arc(s_default_ctx, sc_iterator5_value(it5, 0), sc_iterator5_value(it_order, 2), sc_type_arc_pos_const_perm))
                        continue;

                    if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 1))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 2))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 3))
                                               || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 4))))
                        continue;

                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 1));
                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 2));
                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 3));
                    appendIntoAnswer(answer, sc_iterator5_value(it_order, 4));

                }
                sc_iterator5_free(it_order);

                // iterate roles of element in link
                it3 = sc_iterator3_a_a_f_new(s_default_ctx,
                                             sc_type_node | sc_type_const,
                                             sc_type_arc_pos_const_perm,
                                             sc_iterator3_value(it2, 1));
                while (sc_iterator3_next(it3) == SC_TRUE)
                {
                    sc_memory_get_element_type(s_default_ctx, sc_iterator3_value(it3, 0), &el_type);
                    if (!(el_type & sc_type_node_role))
                        continue;

                    if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 0))
                                               || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1))))
                        continue;

                    appendIntoAnswer(answer, sc_iterator3_value(it3, 0));
                    appendIntoAnswer(answer, sc_iterator3_value(it3, 1));
                }
                sc_iterator3_free(it3);

                appendIntoAnswer(answer, sc_iterator3_value(it2, 1));
                appendIntoAnswer(answer, sc_iterator3_value(it2, 2));
            }
            sc_iterator3_free(it2);
        }
        sc_iterator5_free(it5);
    }
    sc_iterator3_free(it1);

    connect_answer_to_question(question, answer);
    finish_question(question);

    return SC_RESULT_OK;
}
Exemplo n.º 13
0
void search_subclasses_rec(sc_addr elem, sc_addr answer, sc_bool sys_off)
{
    sc_iterator3 *it2, *it6;
    sc_iterator5 *it5, *it_order;
    sc_type el_type;

    // iterate taxonomy
    it5 = sc_iterator5_f_a_a_a_a_new(s_default_ctx,
                                     elem,
                                     sc_type_arc_common | sc_type_const,
                                     sc_type_node | sc_type_const,
                                     sc_type_arc_pos_const_perm,
                                     sc_type_node | sc_type_const);
    while (sc_iterator5_next(it5) == SC_TRUE)
    {
        if (SC_FALSE == sc_helper_check_arc(s_default_ctx, keynode_taxonomy_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm))
            continue;
        if (SC_TRUE == sys_off && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 2))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 4))))
            continue;

        appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 2));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 4));

        search_subclasses_rec(sc_iterator5_value(it5, 2), answer, sys_off);
    }
    sc_iterator5_free(it5);

    // iterate decomposition
    it5 = sc_iterator5_a_a_f_a_a_new(s_default_ctx,
                                     sc_type_node | sc_type_const,
                                     sc_type_arc_common | sc_type_const,
                                     elem,
                                     sc_type_arc_pos_const_perm,
                                     sc_type_node | sc_type_const);
    while (sc_iterator5_next(it5) == SC_TRUE)
    {
        if (SC_FALSE == sc_helper_check_arc(s_default_ctx, keynode_decomposition_relation, sc_iterator5_value(it5, 4), sc_type_arc_pos_const_perm))
            continue;

        if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 0))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 1))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 3))
                                   || IS_SYSTEM_ELEMENT(sc_iterator5_value(it5, 4))))
            continue;

        appendIntoAnswer(answer, sc_iterator5_value(it5, 0));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 1));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 3));
        appendIntoAnswer(answer, sc_iterator5_value(it5, 4));

        // iterate decomposition set elements
        it2 = sc_iterator3_f_a_a_new(s_default_ctx,
                                     sc_iterator5_value(it5, 0),
                                     sc_type_arc_pos_const_perm,
                                     0);
        while (sc_iterator3_next(it2) == SC_TRUE)
        {
            if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 1))
                                       || IS_SYSTEM_ELEMENT(sc_iterator3_value(it2, 2))))
                continue;

            // iterate order relations between elements
            it_order = sc_iterator5_f_a_a_a_a_new(s_default_ctx,
                                                  sc_iterator3_value(it2, 2),
                                                  sc_type_arc_common | sc_type_const,
                                                  sc_type_node | sc_type_const,
                                                  sc_type_arc_pos_const_perm,
                                                  sc_type_node | sc_type_const);
            while (sc_iterator5_next(it_order) == SC_TRUE)
            {
                if (SC_FALSE == sc_helper_check_arc(s_default_ctx, keynode_order_relation, sc_iterator5_value(it_order, 4), sc_type_arc_pos_const_perm))
                    continue;
                if (SC_FALSE == sc_helper_check_arc(s_default_ctx, sc_iterator5_value(it5, 0), sc_iterator5_value(it_order, 2), sc_type_arc_pos_const_perm))
                    continue;

                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 1))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 2))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 3))
                                           || IS_SYSTEM_ELEMENT(sc_iterator5_value(it_order, 4))))
                    continue;

                appendIntoAnswer(answer, sc_iterator5_value(it_order, 1));
                appendIntoAnswer(answer, sc_iterator5_value(it_order, 2));
                appendIntoAnswer(answer, sc_iterator5_value(it_order, 3));
                appendIntoAnswer(answer, sc_iterator5_value(it_order, 4));

            }
            sc_iterator5_free(it_order);

            // iterate roles of element in link
            it6 = sc_iterator3_a_a_f_new(s_default_ctx,
                                         sc_type_node | sc_type_const,
                                         sc_type_arc_pos_const_perm,
                                         sc_iterator3_value(it2, 1));
            while (sc_iterator3_next(it6) == SC_TRUE)
            {
                sc_memory_get_element_type(s_default_ctx, sc_iterator3_value(it6, 0), &el_type);
                if (!(el_type & sc_type_node_role))
                    continue;

                if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it6, 0))
                                           || IS_SYSTEM_ELEMENT(sc_iterator3_value(it6, 1))))
                    continue;

                appendIntoAnswer(answer, sc_iterator3_value(it6, 0));
                appendIntoAnswer(answer, sc_iterator3_value(it6, 1));
            }
            sc_iterator3_free(it6);

            appendIntoAnswer(answer, sc_iterator3_value(it2, 1));
            appendIntoAnswer(answer, sc_iterator3_value(it2, 2));

            search_subclasses_rec(sc_iterator3_value(it2, 2), answer, sys_off);
        }
        sc_iterator3_free(it2);
    }
    sc_iterator5_free(it5);
}