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
// 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.º 3
0
_SC_EXT_EXTERN sc_result sc_module_initialize()
{
  s_default_ctx = sc_memory_context_new(sc_access_lvl_make_min);
  s_garbage_ctx = sc_memory_context_new(sc_access_lvl_make_max);

  if (utils_collect_keynodes_initialize() != SC_RESULT_OK)
    return SC_RESULT_ERROR;

  if (utils_collect_identifiers_initialize() != SC_RESULT_OK)
    return SC_RESULT_ERROR;

  if (utils_keynodes_initialize() != SC_RESULT_OK)
    return SC_RESULT_ERROR;

  event_garbage_deletion = sc_event_new(s_default_ctx, keynode_sc_garbage, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_garbage_delete, 0);
  if (event_garbage_deletion == null_ptr)
    return SC_RESULT_ERROR;

  return SC_RESULT_OK;
}
Ejemplo n.º 4
0
_SC_EXT_EXTERN sc_result sc_module_initialize()
{
  s_default_ctx = sc_memory_context_new(sc_access_lvl_make_min);

  if (search_keynodes_initialize() != SC_RESULT_OK)
    return SC_RESULT_ERROR;

  event_question_search_all_output_arcs = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_const_pos_output_arc, 0);
  if (event_question_search_all_output_arcs == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_input_arcs = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_const_pos_input_arc, 0);
  if (event_question_search_all_input_arcs == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_output_arcs_with_rel = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_const_pos_output_arc_with_rel, 0);
  if (event_question_search_all_input_arcs == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_input_arcs_with_rel = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_const_pos_input_arc_with_rel, 0);
  if (event_question_search_all_input_arcs == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_full_semantic_neighborhood = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_full_semantic_neighborhood, 0);
  if (event_question_search_full_semantic_neighborhood == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_decomposition = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_decomposition, 0);
  if (event_question_search_decomposition == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_identifiers = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_identifiers, 0);
  if (event_question_search_all_identifiers == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_identified_elements = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_identified_elements, 0);
  if (event_question_search_all_identified_elements == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_subclasses_in_quasybinary_relation = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_subclasses_in_quasybinary_relation, 0);
  if (event_question_search_all_subclasses_in_quasybinary_relation == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_all_superclasses_in_quasybinary_relation = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_all_superclasses_in_quasybinary_relation, 0);
  if (event_question_search_all_superclasses_in_quasybinary_relation == null_ptr)
    return SC_RESULT_ERROR;

  event_question_search_links_of_relation_connected_with_element = sc_event_new(s_default_ctx, keynode_question_initiated, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_search_links_of_relation_connected_with_element, 0);
  if (event_question_search_links_of_relation_connected_with_element == null_ptr)
    return SC_RESULT_ERROR;

  return SC_RESULT_OK;
}
Ejemplo n.º 5
0
// ------------------- Module ------------------------------
_SC_EXT_EXTERN sc_result sc_module_initialize()
{
  s_default_ctx = sc_memory_context_new(sc_access_lvl_make_min);

  if (!initialize_keynodes())
  {
    g_warning("Some errors, while initialize ui keynodes");
    return SC_RESULT_ERROR;
  }

  ui_initialize_commands();
  ui_initialize_translators();

  return SC_RESULT_OK;
}
Ejemplo n.º 6
0
ScMemoryContext::ScMemoryContext(sc_uint8 accessLevels /* = 0 */, std::string const & name /* = "" */)
    : mContext(0)
{
    mContext = sc_memory_context_new(accessLevels);
    if (name.empty())
    {
        std::stringstream ss;
        ss << "Context_" << gContextGounter;
        mName = ss.str();
    }
    else
        mName = name;

	ScMemory::registerContext(this);
}
Ejemplo n.º 7
0
_SC_EXT_EXTERN sc_result initialize()
{
    s_default_ctx = sc_memory_context_new(sc_access_lvl_make_min);
    if (SCP_RESULT_TRUE == scp_lib_init() &&
        SCP_RESULT_TRUE == scp_keynodes_init() &&
        SCP_RESULT_TRUE == scp_process_destroyer_init() &&
        SCP_RESULT_TRUE == scp_operator_interpreter_agents_init() &&
        SCP_RESULT_TRUE == scp_procedure_preprocessor_init() &&
        SCP_RESULT_TRUE == scp_program_verifier_init() &&
        SCP_RESULT_TRUE == scp_operator_syncronizer_init() &&
        SCP_RESULT_TRUE == scp_process_creator_init())
        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
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;
}