Esempio n. 1
0
// FIXME
ScUri suiScHelper::findElementByMainIdentifier(const QString &idtf) const
{
    ScUriList contents;

    // get all contents that same to our identifier
    mMemoryInterface->find_str_content(idtf, contents);

    if (contents.size() == 0)   return ScUri::empty();

    ScUri keynode_main_ = keynode("/etc/main_");
    ScUri keynode_idtf = keynode("/etc/identification*");

    ScUriList::iterator it;
    for (it = contents.begin(); it != contents.end(); ++it)
    {
        // find set where current sc-link is a main identifier
        ScUriVector res;
        if (searchOneShot(ScTemplate(ScElementType(ScNode | ScConst),
                                     ScElementType(ScArcMain),
                                     *it,
                                     ScElementType(ScArcMain),
                                     keynode_main_), res))
        {
            // get object by founded identifiers set
            if (searchOneShot(ScTemplate(res[0],
                                         ScElementType(ScArcCommon | ScConst),
                                         ScElementType(ScNode | ScConst),
                                         ScElementType(ScArcMain),
                                         keynode_idtf), res))
            {
                return res[2];
            }else
                SuiExcept(SuiExceptionInternalError,
                          QString("Invalid knowledge base"),
                          "ScUri suiScHelper::findElementByMainIdentifier(const QString &idtf) const");
        }

    }

    return ScUri::empty();
}
Esempio n. 2
0
void suiKnowBase::resolveMainIdentificationKeynodes()
{
    // get sc-links with identification* and main_ strings
    ScMemoryInterface *memory = suiRoot::getInstance()->scMemory();
    ScHelperInterface *helper = suiRoot::getInstance()->scHelper();

    QString idtf_alias = "identification*";
    QString main_alias = "main_";

    ScUriList idtf_candidates;
    if (!memory->find_str_content(idtf_alias, idtf_candidates))
        SuiExcept(SuiExceptionItemNotFound,
                  QString("Can't find sc-link with content: %1").arg(idtf_alias),
                  "void suiKnowBase::resolveMainIdentificationKeynodes()");

    ScUriList main_candidates;
    if (!memory->find_str_content(main_alias, main_candidates))
        SuiExcept(SuiExceptionFileNotFound,
                  QString("Can't find sc-link with content: %1").arg(main_alias),
                  "void suiKnowBase::resolveMainIdentificationKeynodes()");

    // all founded objects can be a candidates, so try them all
    for (ScUriList::iterator idtf_it = idtf_candidates.begin(); idtf_it != idtf_candidates.end(); ++idtf_it)
        for (ScUriList::iterator main_it = main_candidates.begin(); main_it != main_candidates.end(); ++main_it)
        {
            // iterate all possible identification sets for node identification*
            ScSafeIterator it_idtf_set(memory,
                                       ScTemplate() << ScElementType(ScNode | ScConst | ScTuple)
                                       << ScElementType(ScArcMain)
                                       << *idtf_it
                                       << ScElementType(ScArcMain)
                                       << ScElementType(ScNode | ScConst | ScRole));
            while (!it_idtf_set.is_over())
            {
                // now check if founded attribute (value with index 4) also
                // exist in any construction when we trying to find
                // identification set for main_ node
                ScSafeIterator it_main_set(memory,
                                           ScTemplate() << ScElementType(ScNode | ScConst)
                                           << ScElementType(ScArcMain)
                                           << *main_it
                                           << ScElementType(ScArcMain)
                                           << it_idtf_set.value(4));
                while (!it_main_set.is_over())
                {
                    // trying to find idetification* node
                    ScSafeIterator it1(memory,
                                       ScTemplate() << it_idtf_set.value(0)
                                       << ScElementType(ScArcCommon | ScConst)
                                       << ScElementType(ScNode | ScConst));

                    memory->_printEl(it_idtf_set.value(0));
                    while (!it1.is_over())
                    {
                        // check if it have output arc into common arc from identifiers set
                        // to identification* node
                        if (helper->checkExist(ScTemplate() << it1.value(2)
                                               << ScElementType(ScArcMain)
                                               << it1.value(1)))
                        {
                            // now we just have founded candidate to identification* (it1.value(2)) node
                            // to ensure we just need to check if it links to common arc
                            // from identification set for main_ node
                            if (helper->checkExist(ScTemplate() << it_main_set.value(0)
                                                   << ScElementType(ScArcCommon | ScConst)
                                                   << it_idtf_set.value(4)
                                                   << ScElementType(ScArcMain)
                                                   << it1.value(2)))
                            {
                                helper->appendKeynode(it_idtf_set.value(4), "/etc/main_");
                                helper->appendKeynode(it1.value(2), "/etc/identification*");
                                return;
                            }
                        }

                        it1.next();
                    }

                    it_main_set.next();
                }


                it_idtf_set.next();
            }
        }

}
Esempio n. 3
0
void suiKnowBase::loadSourceFile(const QString& filename)
{
    QFile file(filename);
    QFileInfo finfo(filename);

    ScMemoryInterface *sc_memory = suiRoot::getInstance()->scMemory();
    ScHelperInterface *sc_helper = suiRoot::getInstance()->scHelper();

    //get needed keynodes
    ScUri content_keynode = sc_helper->keynode("/etc/content*");
    ScUri path_keynode = sc_helper->keynode("/etc/path*");
    ScUri source_keynode = sc_helper->keynode("/etc/source");


    QString formatAlias = "/ui/format/" + finfo.suffix().toLower();

    ScUri format_keynode;
    if (!sc_helper->hasKeynode(formatAlias))
    {
        qDebug() << "format " << finfo.suffix() << " doesn't supported";
        return;
    }else
        format_keynode = sc_helper->keynode(formatAlias);

    ScUri source_node = sc_memory->gen_el(ScElementType(ScNode | ScConst));
    // Create link and write content to it.
    ScUri source_content = sc_memory->gen_el(ScElementType(ScLink | ScConst));
    sc_memory->set_content(source_content, file);

    // include sc-link into format set
    ScUriVector r;
    if (!sc_helper->genElStr(ScTemplate() << format_keynode << ScElementType(ScArcMain) << source_content, r))
        SuiExcept(SuiExceptionInternalError,
                  QString("Can't include sc-link into '%1' set").arg(formatAlias),
                  "void suiKnowBase::loadSourceFile(const QString& filename)");

    // Create node for storing file path.
    ScUri source_path_node = sc_memory->gen_el(ScElementType(ScLink | ScConst));
    QByteArray ba = filename.toUtf8();
    QBuffer buffer(&ba);
    sc_memory->set_content(source_path_node, buffer);


    ScUriVector v;
    sc_helper->genElStr(ScTemplate() << source_keynode
                        << ScElementType(ScArcMain)
                        << source_node, v);

    sc_helper->genElStr(ScTemplate() << source_node
                        << ScElementType(ScArcCommon | ScConst | ScPositive)
                        << source_content
                        << ScElementType(ScArcMain)
                        << content_keynode, v);

    sc_helper->genElStr(ScTemplate() << source_node
                        << ScElementType(ScArcCommon | ScConst | ScPositive)
                        << source_path_node
                        << ScElementType(ScArcMain)
                        << path_keynode, v);

}
Esempio n. 4
0
suiRoot::suiRoot(QMainWindow *mainWindow, QObject *parent) :
    QObject(parent),
    mMainWindow(mainWindow),
    mComponentsManager(0),
    mPluginManager(0),
    mMemoryInterface(0),
    mScHelper(0),
    mKnowBase(0),
    mKpm(0),
    mMainScWindow(0)
{
    Q_ASSERT(mInstance == 0);
    mInstance = this;

    mComponentsManager = new suiComponentsManager(this);
    mPluginManager = new suiPluginManager(this);

    // load plugins
    QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
    pluginsDir.cdUp();
    pluginsDir.cd("plugins");
#elif defined(Q_OS_LINUX)
    pluginsDir.cd("plugins");
#endif    
    // load sc plugins
    mPluginManager->loadPluginsFromDir(pluginsDir.absoluteFilePath("sc"), false);
    scMemory()->initialize("../kb");

    // create knowledge base control class
    mKnowBase = new suiKnowBase(this);
    mKnowBase->initialize();
    // load ui plugins
    mPluginManager->loadPluginsFromDir(pluginsDir.absoluteFilePath("ui"), true);
    // load sources
    //mKnowBase->loadSources(QStringList());// << "../repo/sources");

    // create main window
    UiComponentFactoryInterfaceList res;
    Q_ASSERT(mComponentsManager->factoriesList(UiComponentMainWindow, res));
    mMainScWindow = qobject_cast<UiMainWindowInterface*>(res.front()->createInstance());
    mMainScWindow->setUri(mScHelper->keynode("/ui/main_window"));

    mMainWindow->setCentralWidget(mMainScWindow->widget());

    // initialize knowledge processing machine
    mKpm = new suiKpm(this);
    mKpm->initialize();


    // >>>>> test
    // show main menu on main window
    ScUri main_menu = scHelper()->keynode("/ui/main_menu");
    ScUri decomp = scHelper()->keynode("/etc/decomposition*");

    // get set of child items for main menu
    ScUriVector v;
    if (scHelper()->searchOneShot(ScTemplate() << ScElementType(ScNode | ScConst)
                              << ScElementType(ScArcCommon | ScConst)
                              << main_menu
                              << ScElementType(ScArcMain)
                              << decomp, v))
    {
        ScUriList objects;
        ScTemplate templ;
        templ << v[0] << ScElementType(ScArcMain) << ScElementType(ScNode | ScConst);
        ScSafeIterator it(scMemory(), templ);
        while (!it.is_over())
        {
            objects << it.value(2);
            it.next();
        }

        mMainScWindow->showObjects(objects);
    }

    // <<<<<<< test
}
Esempio n. 5
0
bool SCgTranslateGWFToSc::translate(QIODevice &device, ScMemoryInterface *memory, const ScUri &set)
{
    mScMemory = memory;
    Q_ASSERT(mScMemory != 0);

    QScopedPointer<ScHelperInterface> helper(SCgPlugin::rootInterface()->scHelper(mScMemory));

    // read data from gwf
    GwfObjectInfoReader reader;
    if (!reader.read(&device))
    {
        qDebug() << "Error while translate to sc-code: " << reader.lastError();
        return false;
    }

    // iterate all objects and resolve them
    GwfObjectInfoReader::TypeToObjectsMap::const_iterator it;
    for (it = reader.objectsInfo().begin(); it != reader.objectsInfo().end(); ++it)
    {
        GwfObjectInfoReader::ObjectInfoList::const_iterator it_info;
        for (it_info = (*it).begin(); it_info != (*it).end(); ++it_info)
            resolveObject(*it_info);
    }

    // setup pair begin and end objects
    const GwfObjectInfoReader::ObjectInfoList &list = reader.objectsInfo()[SCgVisualObject::SCgPairType];
    GwfObjectInfoReader::ObjectInfoList::const_iterator it_info;
    for (it_info = list.begin(); it_info != list.end(); ++it_info)
    {
        SCgPairInfo *pairInfo = static_cast<SCgPairInfo*>(*it_info);
        ScUri pair_uri = mIdToScUri[pairInfo->id()];

        // get begin and end uri's
        ScUri b = mIdToScUri[pairInfo->beginObjectId()];
        ScUri e = mIdToScUri[pairInfo->endObjectId()];

        // setup begin and end
        mScMemory->set_beg(pair_uri, b);
        mScMemory->set_end(pair_uri, e);
    }

    // append objects into parent sets
    for (it = reader.objectsInfo().begin(); it != reader.objectsInfo().end(); ++it)
        for (it_info = (*it).begin(); it_info != (*it).end(); ++it_info)
        {
            SCgObjectInfo *info = *it_info;

            // check if object has a parent
            if (info->parentId() != "0" && !info->parentId().isEmpty())
            {
                ScUri uri = mIdToScUri[info->id()];
                ScUri parent = mIdToScUri[info->parentId()];

                // generate 5 elements construction to append new arc between parent and child into output set
                ScUriVector res;
                ScTemplate templ(parent,
                                 ScElementType(ScArcMain | ScConst | ScPos),
                                 uri,
                                 ScElementType(ScArcMain | ScConst | ScPos),
                                 set);

                if (!helper->genElStr(templ, res))
                    SuiExcept(SuiExceptionInternalError,
                              QString("Can't append '%1' into '%1'").arg(uri.value()).arg(parent.value()),
                              "bool SCgTranslateGWFToSc::translate(QIODevice &device, ScMemoryInterface *memory, const ScUri &set)");
            }
        }

    // append all translated objects into output set
    ScUriList::iterator it_list;
    ScUriVector res;
    for (it_list = mTranslatedObjects.begin(); it_list != mTranslatedObjects.end(); ++it_list)
        if (!helper->genElStr(ScTemplate() << set << ScElementType(ScArcMain | ScConst| ScPos) << *it_list, res))
            SuiExcept(SuiExceptionInternalError,
                      QString("Can't append '%1 into output set '%2").arg((*it_list).value()).arg(set.value()),
                      "bool SCgTranslateGWFToSc::translate(QIODevice &device, ScMemoryInterface *memory, const ScUri &set)");


    return true;
}
Esempio n. 6
0
SCgTranslateGWFToSc::SCgTranslateGWFToSc(QObject *parent) :
    QObject(parent),
    mScMemory(0)
{

    // create type conversion map
    mTypeAliasToScType["node/const/not_define"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/general_node"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/predmet"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/nopredmet"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/symmetry"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/asymmetry"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/attribute"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/relation"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/atom"] = ScElementType(ScNode | ScConst);
    mTypeAliasToScType["node/const/group"] = ScElementType(ScNode | ScConst);

    mTypeAliasToScType["node/var/not_define"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/general_node"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/predmet"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/nopredmet"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/symmetry"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/asymmetry"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/attribute"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/relation"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/atom"] = ScElementType(ScNode | ScVar);
    mTypeAliasToScType["node/var/group"] = ScElementType(ScNode | ScVar);

    mTypeAliasToScType["node/meta/not_define"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/general_node"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/predmet"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/nopredmet"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/symmetry"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/asymmetry"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/attribute"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/relation"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/atom"] = ScElementType(ScNode | ScMeta);
    mTypeAliasToScType["node/meta/group"] = ScElementType(ScNode | ScMeta);


    mTypeAliasToScType["pair/const/pos/-/orient"] = ScElementType(ScArcMain | ScConst | ScPos);
    mTypeAliasToScType["pair/const/neg/-/orient"] = ScElementType(ScArcMain | ScConst | ScNeg);
    mTypeAliasToScType["pair/const/fuz/-/orient"] = ScElementType(ScArcMain | ScConst);
    mTypeAliasToScType["pair/const/pos/temp/orient"] = ScElementType(ScArcMain | ScConst | ScPos | ScTemp);
    mTypeAliasToScType["pair/const/neg/temp/orient"] = ScElementType(ScArcMain | ScConst | ScNeg | ScTemp);
    mTypeAliasToScType["pair/const/fuz/temp/orient"] = ScElementType(ScArcMain | ScConst | ScTemp);
    mTypeAliasToScType["pair/const/-/-/-"] = ScElementType(ScEdgeCommon | ScConst);
    mTypeAliasToScType["pair/const/-/-/orient"] = ScElementType(ScArcCommon | ScConst);

    mTypeAliasToScType["pair/var/pos/-/orient"] = ScElementType(ScArcMain | ScVar | ScPos);
    mTypeAliasToScType["pair/var/neg/-/orient"] = ScElementType(ScArcMain | ScVar | ScNeg);
    mTypeAliasToScType["pair/var/fuz/-/orient"] = ScElementType(ScArcMain | ScVar);
    mTypeAliasToScType["pair/var/pos/temp/orient"] = ScElementType(ScArcMain | ScVar | ScPos | ScTemp);
    mTypeAliasToScType["pair/var/neg/temp/orient"] = ScElementType(ScArcMain | ScVar | ScNeg | ScTemp);
    mTypeAliasToScType["pair/var/fuz/temp/orient"] = ScElementType(ScArcMain | ScVar | ScTemp);
    mTypeAliasToScType["pair/var/-/-/-"] = ScElementType(ScEdgeCommon | ScVar);
    mTypeAliasToScType["pair/var/-/-/orient"] = ScElementType(ScArcCommon | ScVar);

    mTypeAliasToScType["pair/meta/pos/-/orient"] = ScElementType(ScArcMain | ScMeta | ScPos);
    mTypeAliasToScType["pair/meta/neg/-/orient"] = ScElementType(ScArcMain | ScMeta | ScNeg);
    mTypeAliasToScType["pair/meta/fuz/-/orient"] = ScElementType(ScArcMain | ScMeta);
    mTypeAliasToScType["pair/meta/pos/temp/orient"] = ScElementType(ScArcMain | ScMeta | ScPos | ScTemp);
    mTypeAliasToScType["pair/meta/neg/temp/orient"] = ScElementType(ScArcMain | ScMeta | ScNeg | ScTemp);
    mTypeAliasToScType["pair/meta/fuz/temp/orient"] = ScElementType(ScArcMain | ScMeta | ScTemp);
    mTypeAliasToScType["pair/meta/-/-/-"] = ScElementType(ScEdgeCommon | ScMeta);
    mTypeAliasToScType["pair/meta/-/-/orient"] = ScElementType(ScArcCommon | ScMeta);
}