Ejemplo n.º 1
0
Entity::Entity(const Nepomuk::Resource &resource)
  : d(new Entity::Private)
{
    kDebug();

    d->resource = resource;
    d->resourceUri = resource.resourceUri();
}
Ejemplo n.º 2
0
void Nepomuk::TagAnnotation::doCreate( Nepomuk::Resource resource )
{
    kDebug() << "tagging" << resource.resourceUri() << "with" << d->m_tag;
    Nepomuk::Tag tag;
    if( d->m_tagUri.isValid() )
        tag = d->m_tagUri;
    else
        tag = d->m_tag;
    if ( tag.label().isEmpty() &&
         !tag.identifiers().isEmpty() ) {
        tag.setLabel( d->m_tag );
    }
    resource.addTag( tag );
    emitFinished();
}
Ejemplo n.º 3
0
void Nepomuk::QueryClientWrapper::slotNewEntries(const QList<Nepomuk::Query::Result>& results)
{
    QList<Plasma::QueryMatch> matches;
    foreach(const Query::Result& result, results) {
        Plasma::QueryMatch match(m_runner);
        match.setType(Plasma::QueryMatch::PossibleMatch);
        match.setRelevance(normalizeScore(result.score()));

        Nepomuk::Resource res = result.resource();

        QString type;
        QString iconName;

        KMimeType::Ptr mimetype;
        if (res.hasProperty(Nepomuk::Vocabulary::NIE::mimeType())) {
            mimetype = KMimeType::mimeType(res.property(Nepomuk::Vocabulary::NIE::mimeType()).toString());
        }
        if (!mimetype && res.isFile() && res.toFile().url().isLocalFile()) {
            const KUrl url(res.toFile().url());
            mimetype = KMimeType::findByUrl(url);
        }

        if (mimetype) {
            type = mimetype->comment();
            iconName = mimetype->iconName();
        }

        if (type.isEmpty() ) {
            type = Nepomuk::Types::Class(res.resourceType()).label();
            iconName = res.genericIcon();
        }

        match.setText(res.genericLabel());
        match.setSubtext(type);
        match.setIcon(KIcon(iconName.isEmpty() ? QString::fromLatin1("nepomuk") : iconName));

        match.setData(qVariantFromValue(res));
        match.setId(KUrl(res.resourceUri()).url());
        matches << match;
    }
Ejemplo n.º 4
0
bool NW::Executive::canProcess( const Nepomuk::Resource & res) const
{
    // If no filter set up, then no filter is necessary
    if ( d->typeFilters.isEmpty() )
        return true;

    // Create a query
    /*
    for( int i = 0; i < d->typeFilters; i++)
    {
    }*/
    static QString unionString = QString( "UNION" );
    QStringList queryExactList;
    QStringList querySubclassList;
    bool currentType = d->typeFilters[0].allowed;

            
    /* General idea - unite consiquent records with same .allowed field into
     * one group, and  when prepare to switch to another group - create a query
     * from accumulated strings, ask it and determine the result. 
     * Reaching the end of filter list is treated as switching to another group
     */
    foreach( const FilterRecord & record, d->typeFilters)
    {
        if ( record.allowed != currentType ) {

            // After this function call, queryExactList will change!
            QString query = buildFilterQuery(res.resourceUri(), queryExactList, querySubclassList);


            Soprano::QueryResultIterator it = res.manager()->mainModel()->executeQuery(query, Soprano::Query::QueryLanguageSparql );
            if ( it.next() ) {
                // Has answer
                if ( it.boolValue() ) {
                    return currentType;
                }
            }
            else {
                // Wow. Ask query doesn't return an answer. May be it is incorrect ?
                qCritical() << "Filter query is incorrect. Report a BUG please";
                return false;
            }

            // Clear
            queryExactList.clear();
            querySubclassList.clear();

            // Switch current type
            currentType = record.allowed;
        }

        // Accumulate to the group
        if ( record.matchType == ExactMatch or record.matchType == SubclassOrExactMatch ) {
            queryExactList << FilterRecord::queryString(ExactMatch, record.typeUrl) << unionString;
        }

        if ( record.matchType == SubclassOrExactMatch or record.matchType == SubclassMatch ) {
            querySubclassList << FilterRecord::queryString(SubclassMatch, record.typeUrl) << unionString;
        }
    }
    // Build for the last group
    QString query = buildFilterQuery(res.resourceUri(), queryExactList, querySubclassList);


    Soprano::QueryResultIterator it = res.manager()->mainModel()->executeQuery(query, Soprano::Query::QueryLanguageSparql );
    if ( it.isBool() ) {
        // Has answer
        if ( it.boolValue() ) {
            return currentType;
        }
        else {
            // return default rule
            return d->defaultTypeRule;
        }
    }
    else {
        // Wow. Ask query doesn't return an answer. May be it is incorrect ?
        qCritical() << "Filter query is incorrect. Report a BUG please";
        return false;
    }


}