Ejemplo n.º 1
0
sc_memory_context* sc_memory_initialize(const sc_memory_params *params)
{
    g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);

    sc_config_initialize(params->config_file);

    s_context_hash_table = g_hash_table_new(g_direct_hash, g_direct_equal);

    char *v_str = sc_version_string_new(&SC_VERSION);
    g_message("Version: %s", v_str);
    sc_version_string_free(v_str);

    g_message("Configuration:");
    g_message("\tmax_loaded_segments: %d", sc_config_get_max_loaded_segments());
    g_message("sc-element size: %zd", sizeof(sc_element));

    if (sc_storage_initialize(params->repo_path, params->clear) != SC_TRUE)
        return 0;

    s_memory_default_ctx = sc_memory_context_new(sc_access_lvl_make(SC_ACCESS_LVL_MAX_VALUE, SC_ACCESS_LVL_MAX_VALUE));
    sc_memory_context *helper_ctx = sc_memory_context_new(sc_access_lvl_make(SC_ACCESS_LVL_MIN_VALUE, SC_ACCESS_LVL_MAX_VALUE));
    if (sc_helper_init(helper_ctx) != SC_RESULT_OK)
        goto error;
    sc_memory_context_free(helper_ctx);

    if (sc_events_initialize() == SC_FALSE)
    {
        g_error("Error while initialize events module");
        goto error;
    }

    sc_result ext_res;
    ext_res = sc_ext_initialize(params->ext_path);

    switch (ext_res)
    {
    case SC_RESULT_OK:
        g_message("Modules initialization finished");
        return s_memory_default_ctx;

    case SC_RESULT_ERROR_INVALID_PARAMS:
        g_warning("Extensions directory '%s' doesn't exist", params->ext_path);
        break;

    default:
        g_warning("Unknown error while initialize extensions");
        break;
    }

    error:
    {
        if (helper_ctx)
            sc_memory_context_free(helper_ctx);
        sc_memory_context_free(s_memory_default_ctx);
    }
    return s_memory_default_ctx = 0;
}
Ejemplo n.º 2
0
_SC_EXT_EXTERN sc_result sc_module_shutdown()
{
  sc_result res = SC_RESULT_OK;

  if (utils_collect_identifiers_shutdown() != SC_RESULT_OK)
    res = SC_RESULT_ERROR;

  if (event_garbage_deletion)
    sc_event_destroy(event_garbage_deletion);

  sc_memory_context_free(s_garbage_ctx);
  sc_memory_context_free(s_default_ctx);

  return res;
}
Ejemplo n.º 3
0
_SC_EXT_EXTERN sc_result sc_module_shutdown()
{
  if (event_question_search_all_output_arcs)
    sc_event_destroy(event_question_search_all_output_arcs);
  if (event_question_search_all_input_arcs)
    sc_event_destroy(event_question_search_all_input_arcs);
  if (event_question_search_all_output_arcs_with_rel)
    sc_event_destroy(event_question_search_all_output_arcs_with_rel);
  if (event_question_search_all_input_arcs_with_rel)
    sc_event_destroy(event_question_search_all_input_arcs_with_rel);
  if (event_question_search_full_semantic_neighborhood)
    sc_event_destroy(event_question_search_full_semantic_neighborhood);
  if (event_question_search_all_identified_elements)
    sc_event_destroy(event_question_search_all_identified_elements);
  if (event_question_search_all_identifiers)
    sc_event_destroy(event_question_search_all_identifiers);
  if (event_question_search_decomposition)
    sc_event_destroy(event_question_search_decomposition);
  if (event_question_search_all_subclasses_in_quasybinary_relation)
    sc_event_destroy(event_question_search_all_subclasses_in_quasybinary_relation);
  if (event_question_search_all_superclasses_in_quasybinary_relation)
    sc_event_destroy(event_question_search_all_superclasses_in_quasybinary_relation);
  if (event_question_search_links_of_relation_connected_with_element)
    sc_event_destroy(event_question_search_links_of_relation_connected_with_element);

  sc_memory_context_free(s_default_ctx);

  return SC_RESULT_OK;
}
Ejemplo n.º 4
0
// simple arc creation test
gpointer create_arc_thread(gpointer data)
{
    sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8));
    int count = GPOINTER_TO_INT(data);
    int result = count;
    for (int i = 0; i < count; ++i)
    {
        sc_addr addr = sc_memory_node_new(ctx, 0);
        if (SC_ADDR_IS_EMPTY(addr))
            goto result;
        sc_addr addr2 = sc_memory_node_new(ctx, 0);
        if (SC_ADDR_IS_EMPTY(addr2))
            goto result;
        sc_addr arc = sc_memory_arc_new(ctx, sc_type_arc_access, addr, addr);
        if (SC_ADDR_IS_EMPTY(arc))
            goto result;

        continue;

        result = i + 1;
        break;
    }

    result:
    {
        sc_memory_context_free(ctx);
    }
    return GINT_TO_POINTER(result);
}
Ejemplo n.º 5
0
_SC_EXT_EXTERN sc_result sc_module_shutdown()
{

  ui_shutdown_translators();
  ui_shutdown_commands();

  sc_memory_context_free(s_default_ctx);

  return SC_RESULT_OK;
}
Ejemplo n.º 6
0
void ScMemoryContext::destroy()
{
    if (mContext)
    {
		ScMemory::unregisterContext(this);

        sc_memory_context_free(mContext);
        mContext = 0;
    }
}
Ejemplo n.º 7
0
_SC_EXT_EXTERN sc_result shutdown()
{
    sc_memory_context_free(s_default_ctx);
    if (SCP_RESULT_TRUE == scp_lib_shutdown() &&
        SCP_RESULT_TRUE == scp_process_destroyer_shutdown() &&
        SCP_RESULT_TRUE == scp_operator_interpreter_agents_shutdown() &&
        SCP_RESULT_TRUE == scp_procedure_preprocessor_shutdown() &&
        SCP_RESULT_TRUE == scp_program_verifier_shutdown() &&
        SCP_RESULT_TRUE == scp_operator_syncronizer_shutdown() &&
        SCP_RESULT_TRUE == scp_process_creator_shutdown())
        return SCP_RESULT_TRUE;
    else
        return SCP_RESULT_ERROR;
}
Ejemplo n.º 8
0
// simple sc-links creation
gpointer create_link_thread(gpointer data)
{
    sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8));
    int count = GPOINTER_TO_INT(data);
    int result = count;
    for (int i = 0; i < count; ++i)
    {
        sc_addr addr = sc_memory_link_new(ctx);
        if (SC_ADDR_IS_EMPTY(addr))
            result = i + 1;
    }

    sc_memory_context_free(ctx);

    return GINT_TO_POINTER(result);
}
Ejemplo n.º 9
0
void test_save()
{
    // create nodes
    s_default_ctx = sc_memory_initialize(&params);

    sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8));
    int const count = 1000000;
    for (int i = 0; i < count; ++i)
    {
        g_assert(SC_ADDR_IS_NOT_EMPTY(sc_memory_node_new(ctx, 0)));
    }

    sc_memory_context_free(ctx);

    GThread * thread = g_thread_try_new(0, start_save_threaded, 0, 0);
    test_creation(create_arc_thread, g_task_count, g_thread_count);

    g_thread_join(thread);

    sc_memory_shutdown(SC_FALSE);
}
Ejemplo n.º 10
0
void sc_memory_shutdown(sc_bool save_state)
{
    sc_events_stop_processing();

    sc_ext_shutdown();

    sc_events_shutdown();
    sc_config_shutdown();

    sc_helper_shutdown();

    sc_storage_shutdown(save_state);

    sc_memory_context_free(s_memory_default_ctx);
    s_memory_default_ctx = 0;

    /// todo: clear contexts
    g_hash_table_destroy(s_context_hash_table);
    s_context_hash_table = 0;
    s_context_id_last = 0;
    g_assert(s_context_id_count == 0);
}
Ejemplo n.º 11
0
bool Builder::run(const BuilderParams &params)
{

    mParams = params;

    collectFiles();

    // initialize sc-memory
    sc_memory_params p;
    sc_memory_params_clear(&p);
    p.clear = mParams.clearOutput ? SC_TRUE : SC_FALSE;
    p.config_file = mParams.configFile.empty() ? 0 : mParams.configFile.c_str();
    p.repo_path = mParams.outputPath.c_str();
    p.ext_path = mParams.extensionsPath.size() > 0 ? mParams.extensionsPath.c_str() : 0;

    sc_memory_initialize(&p);

    mContext = sc_memory_context_new(sc_access_lvl_make_min);

    std::cout << "Build knowledge base from sources... " << std::endl;

    // process founded files
    uint32 done = 0, last_progress = -1;
    tFileSet::iterator it, itEnd = mFileSet.end();
    for (it = mFileSet.begin(); it != itEnd; ++it)
    {
        uint32 progress = (uint32)(((float)++done / (float)mFileSet.size()) * 100);
        if (mParams.showFileNames)
        {
            std::cout << "[ " << progress << "% ] " << *it << std::endl;
        }
        else
        {
            if (last_progress != progress)
            {
                if (progress % 10 == 0)
                {
                    std::cout << "[" << progress << "%]";
                    std::cout.flush();
                }
                else
                {
                    std::cout << ".";
                    std::cout.flush();
                }
                last_progress = progress;
            }
        }

        try
        {
            processFile(*it);
        } catch(const Exception &e)
        {
            StringStream ss;
            ss << e.getDescription() << " in " << e.getFileName() << " at line " << e.getLineNumber();
            mErrors.push_back(ss.str());
        }
    }
    std::cout << std::endl << "done" << std::endl;

    // print errors
    std::cout << std::endl << "-------" << std::endl << "Errors:" << std::endl;
    int idx = 1;
    tStringList::iterator itErr, itErrEnd = mErrors.end();
    for (itErr = mErrors.begin(); itErr != itErrEnd; ++itErr)
        std::cout << "[" << idx++ << "]\t" << *itErr << std::endl;

    // print statistics
    sc_stat stat;
    sc_memory_stat(mContext, &stat);

    unsigned int all_count = stat.arc_count + stat.node_count + stat.link_count;

    std::cout << std::endl << "Statistics" << std::endl;
    std::cout << "Nodes: " << stat.node_count << "(" << ((float)stat.node_count / (float)all_count) * 100 << "%)" << std::endl;
    std::cout << "Arcs: " << stat.arc_count << "(" << ((float)stat.arc_count / (float)all_count) * 100 << "%)"  << std::endl;
    std::cout << "Links: " << stat.link_count << "(" << ((float)stat.link_count / (float)all_count) * 100 << "%)"  << std::endl;
    std::cout << "Total: " << all_count << std::endl;

    sc_memory_context_free(mContext);
    sc_memory_shutdown(SC_TRUE);

    return true;
}