sc_result sc_graph_find_min_path(sc_addr graph, sc_addr beg_vertex, sc_addr end_vertex, sc_addr_list **path) { sc_addr curr_vertex, cur_wave; sc_addr_list *not_checked_vertices = nullptr, *wave_list_head = nullptr, *path_head = nullptr; sc_iterator3 *wave_it; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex); if (sc_helper_check_arc(sc_graph_keynode_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; while (sc_iterator5_next(it5) == SC_TRUE) { if (SC_ADDR_IS_EQUAL(beg_vertex, it5->results[2]) == SC_FALSE) { not_checked_vertices = sc_addr_list_append(not_checked_vertices); not_checked_vertices->value = it5->results[2]; } } cur_wave = sc_memory_node_new(sc_type_node | sc_type_const); sc_memory_arc_new(sc_type_arc_pos_const_perm, cur_wave, beg_vertex); wave_list_head = sc_addr_list_append(wave_list_head); wave_list_head->value = cur_wave; do { cur_wave = create_wave(cur_wave, graph, ¬_checked_vertices); wave_it = sc_iterator3_f_a_a_new(cur_wave, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const); if (sc_iterator3_next(wave_it) == SC_FALSE) //TODO clear memory return SC_RESULT_ERROR; wave_list_head = sc_addr_list_append(wave_list_head); wave_list_head->value = cur_wave; } while(sc_helper_check_arc(cur_wave, end_vertex, sc_type_arc_pos_const_perm) == SC_FALSE); path_head = sc_addr_list_append(path_head); path_head->value = end_vertex; curr_vertex = end_vertex; wave_list_head = sc_addr_list_next(wave_list_head); do { curr_vertex = find_adjacent_from_wave(graph, wave_list_head->value, curr_vertex); path_head = sc_addr_list_append(path_head); path_head->value = curr_vertex; } while((wave_list_head = sc_addr_list_next(wave_list_head)) != nullptr); *path = path_head; return SC_RESULT_OK; }
/*! Deep first search to build a connective component * \param curr_vertex * start vertex for the search * \param not_checked_vertices * set of not checked vertices * \param curr_conn_comp * connective component that is being built by this search * \param graph * sc-addr of graph structure to search connective components */ void deep_first_search_for_find_conn_comp(sc_addr curr_vertex, sc_addr not_checked_vertices, sc_addr curr_conn_comp, sc_addr graph) { sc_iterator3 *it3 = sc_iterator3_f_a_f_new(not_checked_vertices, sc_type_arc_pos_const_perm, curr_vertex); if (sc_iterator3_next(it3) == SC_TRUE) sc_memory_element_free(it3->results[1]); sc_iterator3_free(it3); sc_memory_arc_new(sc_type_arc_pos_const_perm, curr_conn_comp, curr_vertex); sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(curr_vertex, sc_type_edge_common | sc_type_const, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, graph); while(sc_iterator5_next(it5) == SC_TRUE) { if (sc_helper_check_arc(not_checked_vertices, it5->results[2], sc_type_arc_pos_const_perm) == SC_TRUE) deep_first_search_for_find_conn_comp(it5->results[2], not_checked_vertices, curr_conn_comp, graph); } sc_iterator5_free(it5); }
sc_result sc_graph_find_conn_comp(sc_addr graph, sc_addr *conn_comp_set) { if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; sc_addr not_checked_vertices, curr_vertex; sc_iterator3 *it3; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex); not_checked_vertices = sc_memory_node_new(sc_type_node | sc_type_const); *conn_comp_set = sc_memory_node_new(sc_type_node | sc_type_const); while(sc_iterator5_next(it5) == SC_TRUE) { curr_vertex = it5->results[2]; sc_memory_arc_new(sc_type_arc_pos_const_perm, not_checked_vertices, curr_vertex); } sc_iterator5_free(it5); it3 = sc_iterator3_f_a_a_new(not_checked_vertices, sc_type_arc_pos_const_perm, sc_type_node); while(sc_iterator3_next(it3) == SC_TRUE) { sc_addr curr_conn_comp = sc_memory_node_new(sc_type_node | sc_type_const); curr_vertex = it3->results[2]; if(sc_helper_check_arc(not_checked_vertices, curr_vertex, sc_type_arc_pos_const_perm) == SC_FALSE) continue; deep_first_search_for_find_conn_comp(curr_vertex, not_checked_vertices, curr_conn_comp, graph); sc_memory_arc_new(sc_type_arc_pos_const_perm, *conn_comp_set, curr_conn_comp); } sc_iterator3_free(it3); sc_memory_element_free(not_checked_vertices); return SC_RESULT_OK; }
/*! Calculates vertex degree * \param graph * graph that contains vertex for degree calculation * \param vertex * vertex for deegree calculation * \param result * vertex degree */ sc_result sc_graph_vertex_degree(sc_addr graph, sc_addr vertex, int *result) { int degree = 0; sc_type arc_type = 0; sc_iterator3 *it3; if (sc_helper_check_arc(sc_graph_keynode_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; //Check if vertex belongs to this garph if (sc_graph_check_vertex(graph, vertex) != SC_RESULT_OK) return SC_RESULT_ERROR_INVALID_PARAMS; if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) { arc_type = sc_type_edge_common; } else if (sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) { arc_type = sc_type_arc_common; } else return SC_RESULT_ERROR_INVALID_PARAMS; it3 = sc_iterator3_f_a_a_new(vertex, arc_type, sc_type_node); while (sc_iterator3_next(it3) == SC_TRUE) // The arc must belong to the current graph if (sc_graph_check_arc(graph,it3->results[1]) == SC_RESULT_OK) degree++; if (arc_type == sc_type_edge_common) { *result = degree; return SC_RESULT_OK; } it3 = sc_iterator3_a_a_f_new(sc_type_node, arc_type, vertex); while (sc_iterator3_next(it3) == SC_TRUE) if (sc_graph_check_arc(graph,it3->results[1]) == SC_RESULT_OK) degree++; *result = degree; return SC_RESULT_OK; }
sc_result search_incident_vertex_arc(sc_addr graph, sc_addr vertex, sc_addr_list **listArc) { sc_iterator3 *it3; sc_iterator5 *it5; sc_type arc_type; sc_addr sc_graph_keynode_rrel; if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm)) { arc_type = sc_type_edge_common; sc_graph_keynode_rrel = sc_graph_keynode_rrel_edge; } else if (sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm)) { arc_type = sc_type_arc_common; sc_graph_keynode_rrel = sc_graph_keynode_rrel_arc; } it3 = sc_iterator3_f_a_a_new(vertex, arc_type, sc_type_node); while(sc_iterator3_next(it3) == SC_TRUE) { it5 = sc_iterator5_f_a_f_a_f_new(graph, sc_type_arc_pos, it3->results[1], sc_type_arc_pos, sc_graph_keynode_rrel); while(sc_iterator5_next(it5) == SC_TRUE) { *listArc = sc_addr_list_append(*listArc); (*listArc)->value = it5->results[2]; } } sc_iterator5_free(it5); sc_iterator3_free(it3); return SC_RESULT_OK; }
void search_nonbinary_relation(sc_addr elem, sc_addr answer, sc_bool sys_off) { sc_iterator3 *it1, *it2, *it3; sc_type el_type; // iterate input arcs for elem it1 = sc_iterator3_a_a_f_new(sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, elem); while (sc_iterator3_next(it1) == SC_TRUE) { // if elem is a link of non-binary relation if (SC_TRUE == sc_helper_check_arc(keynode_nonbinary_relation, sc_iterator3_value(it1, 0), sc_type_arc_pos_const_perm)) { if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 0)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it1, 1)))) continue; // iterate other elements of link it2 = sc_iterator3_f_a_a_new(elem, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const); 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 attributes of link it3 = sc_iterator3_a_a_f_new(sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_iterator3_value(it2, 1)); while (sc_iterator3_next(it3) == SC_TRUE) { if (sys_off == SC_TRUE && (IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 0)) || IS_SYSTEM_ELEMENT(sc_iterator3_value(it3, 1)))) continue; sc_memory_get_element_type(sc_iterator3_value(it3, 0), &el_type); if (!(el_type & (sc_type_node_norole | sc_type_node_role))) continue; appendIntoAnswer(answer, sc_iterator3_value(it3, 0)); appendIntoAnswer(answer, sc_iterator3_value(it3, 1)); } sc_iterator3_free(it3); } sc_iterator3_free(it2); appendIntoAnswer(answer, sc_iterator3_value(it1, 0)); appendIntoAnswer(answer, sc_iterator3_value(it1, 1)); } } sc_iterator3_free(it1); }
void appendIntoAnswer(sc_addr answer, sc_addr el) { sc_addr arc; if (sc_helper_check_arc(answer, el, sc_type_arc_pos_const_perm) == SC_TRUE) return; arc = sc_memory_arc_new(sc_type_arc_pos_const_perm, answer, el); SYSTEM_ELEMENT(arc); }
sc_result sc_graph_find_conn_comp(sc_addr graph, sc_addr_list **conn_comp_set) { sc_addr curr_vertex, graph_keynode; sc_addr_list *not_checked_vertices = nullptr; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex); if (sc_helper_check_arc(sc_graph_keynode_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) graph_keynode = sc_graph_keynode_not_oriented_graph; else if (sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) graph_keynode = sc_graph_keynode_oriented_graph; else return SC_RESULT_ERROR_INVALID_PARAMS; *conn_comp_set = nullptr; while(sc_iterator5_next(it5) == SC_TRUE) { curr_vertex = it5->results[2]; not_checked_vertices = sc_addr_list_append(not_checked_vertices); not_checked_vertices->value = curr_vertex; } sc_iterator5_free(it5); while (not_checked_vertices != nullptr) { sc_addr curr_conn_comp = sc_memory_node_new(sc_type_node | sc_type_const); sc_memory_arc_new(sc_type_arc_pos_const_perm, sc_graph_keynode_graph, curr_conn_comp); sc_memory_arc_new(sc_type_arc_pos_const_perm, graph_keynode, curr_conn_comp); curr_vertex = not_checked_vertices->value; deep_first_search_for_find_conn_comp(curr_vertex, ¬_checked_vertices, &curr_conn_comp, graph); *conn_comp_set = sc_addr_list_append(*conn_comp_set); (*conn_comp_set)->value = curr_conn_comp; } return SC_RESULT_OK; }
sc_result search_incident_vertexes(sc_addr graph, sc_addr arc, sc_addr_list **listVertex) { sc_iterator3 *it3; sc_iterator5 *it5; sc_type arc_type; // sc_addr sc_graph_keynode_rrel; if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm)) arc_type = sc_type_edge_common; else if (sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm)) arc_type = sc_type_arc_common; it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos, sc_type_node, sc_type_arc_pos, sc_graph_keynode_rrel_vertex); while(sc_iterator5_next(it5) == SC_TRUE) { it3 = sc_iterator3_f_a_a_new(it5->results[2], arc_type, sc_type_node); while(sc_iterator3_next(it3) == SC_TRUE) { if(SC_ADDR_IS_EQUAL(it3->results[1],arc)) { *listVertex = sc_addr_list_append(*listVertex); (*listVertex)->value = it3->results[0]; *listVertex = sc_addr_list_append(*listVertex); (*listVertex)->value = it3->results[2]; } } } sc_iterator5_free(it5); sc_iterator3_free(it3); return SC_RESULT_OK; }
sc_addr create_wave(sc_addr cur_wave, sc_addr graph, sc_addr_list **not_checked_vertices) { sc_addr_list *cur_item; sc_addr new_wave; sc_iterator3 *it3 = sc_iterator3_f_a_a_new(cur_wave, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const); sc_type arc_type; new_wave = sc_memory_node_new(sc_type_node | sc_type_const); if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) arc_type = sc_type_edge_common; else if(sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) arc_type = sc_type_arc_common; while (sc_iterator3_next(it3) == SC_TRUE) { sc_addr cur_vertex = it3->results[2]; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(cur_vertex, arc_type | sc_type_const, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, graph); while (sc_iterator5_next(it5) == SC_TRUE) { cur_item = *not_checked_vertices; do { if (SC_ADDR_IS_EQUAL(cur_item->value, it5->results[2]) == SC_TRUE) { if (cur_item == *not_checked_vertices) *not_checked_vertices = sc_addr_list_remove(*not_checked_vertices); else cur_item = sc_addr_list_remove(cur_item); sc_memory_arc_new(sc_type_arc_pos_const_perm, new_wave, it5->results[2]); break; } } while((cur_item = sc_addr_list_next(cur_item)) != nullptr); } } return new_wave; }
/*! Deep first search to build a connective component * \param curr_vertex * start vertex for the search * \param not_checked_vertices * set of not checked vertices * \param curr_conn_comp * connective component that is being built by this search * \param graph * sc-addr of graph structure to search connective components */ void deep_first_search_for_find_conn_comp(sc_addr curr_vertex, sc_addr_list **not_checked_vertices, sc_addr *curr_conn_comp, sc_addr graph) { sc_addr arc, rrel_keynode; sc_type arc_type; sc_iterator5 *it5; *not_checked_vertices = sc_addr_list_remove(*not_checked_vertices); arc = sc_memory_arc_new(sc_type_arc_pos_const_perm, *curr_conn_comp, curr_vertex); sc_memory_arc_new(sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex, arc); if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) { arc_type = sc_type_edge_common; rrel_keynode = sc_graph_keynode_rrel_edge; } else if (sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) { arc_type = sc_type_arc_common; rrel_keynode = sc_graph_keynode_rrel_arc; } it5 = sc_iterator5_f_a_a_a_f_new(curr_vertex, arc_type | sc_type_const, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, graph); while(sc_iterator5_next(it5) == SC_TRUE) { if (sc_addr_list_is_included(*not_checked_vertices, it5->results[2]) == SC_TRUE) { arc = sc_memory_arc_new(sc_type_arc_pos_const_perm, *curr_conn_comp, it5->results[1]); sc_memory_arc_new(sc_type_arc_pos_const_perm, rrel_keynode, arc); deep_first_search_for_find_conn_comp(it5->results[2], not_checked_vertices, curr_conn_comp, graph); } } sc_iterator5_free(it5); }
sc_result agent_search_all_superclasses_in_quasybinary_relation(const sc_event *event, sc_addr arg) { sc_addr question, answer; sc_iterator3 *it1; sc_bool sys_off = SC_TRUE; 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_search_all_superclasses_in_quasybinary_relation, 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)); search_superclasses_rec(sc_iterator3_value(it1, 2), answer, sys_off); } sc_iterator3_free(it1); connect_answer_to_question(question, answer); finish_question(question); return SC_RESULT_OK; }
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; }
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; }
// -------------------------------------------------- sc_result agent_append_idtf(const sc_event *event, sc_addr arg) { sc_addr arc, el, link, n; sc_stream *content = 0; sc_uint8 *data = 0; sc_uint32 data_len = 0, read_bytes = 0; redisReply * reply = null_ptr; if (sc_memory_get_arc_end(s_default_ctx, arg, &arc) != SC_RESULT_OK) return SC_RESULT_ERROR; if (sc_memory_get_arc_begin(s_default_ctx, arg, &n) != SC_RESULT_OK) return SC_RESULT_ERROR; // get element if (sc_memory_get_arc_begin(s_default_ctx, arc, &el) != SC_RESULT_OK) return SC_RESULT_ERROR; if (sc_helper_check_arc(s_default_ctx, keynode_system_element, el, sc_type_arc_pos_const_perm) == SC_TRUE) return SC_RESULT_OK; // get sc-link if (sc_memory_get_arc_end(s_default_ctx, arc, &link) != SC_RESULT_OK) return SC_RESULT_ERROR; // get content of sc-link if (sc_memory_get_link_content(s_default_ctx, link, &content) != SC_RESULT_OK) return SC_RESULT_ERROR; // get length of data if (sc_stream_get_length(content, &data_len) != SC_RESULT_OK) { sc_stream_free(content); return SC_RESULT_ERROR; } data = g_malloc0(data_len + 1); if (sc_stream_read_data(content, data, data_len, &read_bytes) != SC_RESULT_OK || read_bytes != data_len) { sc_stream_free(content); g_free(data); return SC_RESULT_ERROR; } sc_result res = SC_RESULT_OK; sc_addr el_addr = el; if (SC_ADDR_IS_EQUAL(n, keynode_nrel_idtf)) el_addr = link; reply = do_sync_redis_command(redisCtx, "SET idtf:%s:%s %b", SC_ADDR_IS_EQUAL(n, keynode_nrel_main_idtf) ? str_main_idtf_postfix : (SC_ADDR_IS_EQUAL(n, keynode_nrel_idtf) ? str_idtf_postfix : str_sys_idtf_postfix), data, &el_addr, sizeof(el_addr)); if (reply == 0 || reply->type == REDIS_REPLY_ERROR) res = SC_RESULT_ERROR; if (reply) freeReplyObject(reply); sc_stream_free(content); g_free(data); return res; }
bool ScMemoryContext::helperCheckArc(ScAddr const & begin, ScAddr end, sc_type arcType) { check_expr(isValid()); return (sc_helper_check_arc(mContext, *begin, *end, arcType) == SC_RESULT_OK); }
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); }
sc_bool check_coherence(sc_memory_context *context, sc_addr element, sc_addr sc_pattern, sc_addr checked_arc, sc_bool output, sc_type_result *result, sc_type_result *inp_result) { sc_addr addr1, addr2, temp; sc_iterator3 *it_pattern_arc = sc_iterator3_f_a_a_new(context, element, 0, 0); if (it_pattern_arc == null_ptr) {return SC_FALSE;} while (SC_TRUE == sc_iterator3_next(it_pattern_arc)) { addr2 = sc_iterator3_value(it_pattern_arc, 1); if (SC_TRUE == sc_helper_check_arc(context, sc_pattern, addr2, sc_type_arc_pos_const_perm)) { if (SC_TRUE == output && SC_ADDR_IS_EQUAL(checked_arc, addr2)) { continue; } if (SC_TRUE == find_result_pair_for_var(result, addr2, &temp) && SC_FALSE == find_result_pair_for_var(inp_result, addr2, &temp)) { sc_iterator3_free(it_pattern_arc); return SC_FALSE; } } } sc_iterator3_free(it_pattern_arc); it_pattern_arc = sc_iterator3_a_a_f_new(context, 0, 0, element); if (it_pattern_arc == null_ptr) {return SC_FALSE;} while (SC_TRUE == sc_iterator3_next(it_pattern_arc)) { addr1 = sc_iterator3_value(it_pattern_arc, 0); if (SC_ADDR_IS_EQUAL(addr1, sc_pattern)) continue; addr2 = sc_iterator3_value(it_pattern_arc, 1); if (SC_TRUE == sc_helper_check_arc(context, sc_pattern, addr2, sc_type_arc_pos_const_perm)) { if (SC_FALSE == output && SC_ADDR_IS_EQUAL(checked_arc, addr2)) { continue; } if (SC_TRUE == find_result_pair_for_var(result, addr2, &temp) && SC_FALSE == find_result_pair_for_var(inp_result, addr2, &temp)) { sc_iterator3_free(it_pattern_arc); return SC_FALSE; } } } sc_iterator3_free(it_pattern_arc); sc_type element_type; if (SC_RESULT_OK != sc_memory_get_element_type(context, element, &element_type)) {return SC_FALSE;} if ((sc_type_node & element_type) != sc_type_node) { sc_addr end, begin; if (SC_RESULT_OK != sc_memory_get_arc_begin(context, element, &begin)) {return SC_FALSE;} if (SC_RESULT_OK != sc_memory_get_arc_end(context, element, &end)) {return SC_FALSE;} if (SC_TRUE == check_coherence(context, begin, sc_pattern, element, SC_TRUE, result, inp_result) && SC_TRUE == check_coherence(context, end, sc_pattern, element, SC_FALSE, result, inp_result)) return SC_TRUE; else return SC_FALSE; } return SC_TRUE; }
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); }