Пример #1
0
bool SCgMainWindow::isCommand(const ScUri &uri) const
{
    ScHelperInterface *helper = SCgPlugin::rootInterface()->scHelper();

    return helper->checkInclusion(uri, helper->keynode("/ui/command/class")) ||
            helper->checkInclusion(uri, helper->keynode("/ui/command/noatom"));
}
Пример #2
0
void suiKnowBase::initialize()
{
    registerAllKeynodes();
//    createMinimalBase();

    // first of all we need to find identification* and main_ nodes
    resolveMainIdentificationKeynodes();

    // resolve other keynodes
    ScHelperInterface *helper = suiRoot::getInstance()->scHelper();
    for (KeynodesMap::iterator it = mKeynodesMap.begin(); it != mKeynodesMap.end(); ++it)
    {
        ScUri uri = helper->findElementByMainIdentifier(it.key());
        if (!uri.isEmpty()) helper->appendKeynode(uri, it.value());
    }
}
Пример #3
0
void suiKnowBase::loadSources(const QStringList &sourceDirs)
{
    // load knowledge base from sources
    QString sDir;
    foreach(sDir, sourceDirs)
        loadSourceDirectory(sDir, true);

    // find all keynodes
    ScHelperInterface *helper = suiRoot::getInstance()->scHelper();
    KeynodesMap::iterator it;
    for (it = mKeynodesMap.begin(); it != mKeynodesMap.end(); ++it)
    {
        // skip keynodes, that already found
        if (helper->hasKeynode(it.value())) continue;
        // try to find keynodes by main identifier
        ScUri uri = helper->findElementByMainIdentifier(it.key());
        if (uri.isEmpty()) SuiExcept(SuiExceptionItemNotFound,
                                         QString("Can't find keynode '%1'").arg(it.key()),
                                         "void suiKnowBase::initialize(const QStringList &sourceDirs)");
    }

    ScUri content_keynode = helper->keynode("/etc/content*");

    // trying to search all loaded sources
    ScMemoryInterface *mem = suiRoot::getInstance()->scMemory();
    ScSafeIterator scIt(mem, ScTemplate() << helper->keynode("/etc/source")
                                          << ScElementType(ScArcMain)
                                          << ScElementType(ScNode | ScConst));
    while (!scIt.is_over())
    {
        ScUriVector res;
        // trying to find content of source
        if (helper->searchOneShot(ScTemplate() << scIt.value(2)
                                             << ScElementType(ScArcCommon | ScConst | ScPositive)
                                             << ScElementType(0) // fix to link
                                             << ScElementType(ScArcMain)
                                             << content_keynode, res))
        {
            suiRoot::getInstance()->translateDataToSc(res[2]);
        }else
            SuiExcept(SuiExceptionInternalError,
                      "Can't find knowledge base source content",
                      "void suiKnowBase::initialize(const QStringList &sourceDirs)");

        scIt.next();
    }
}
Пример #4
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();
            }
        }

}
Пример #5
0
// ----- Factory -----
SCgTranslateGWFToScFactory::SCgTranslateGWFToScFactory(QObject *parent) :
    QObject(parent)
{
    ScHelperInterface *helper = SCgPlugin::rootInterface()->scHelper();
    mFormats.push_back(helper->appendFormatKeynode("gwf"));
}