コード例 #1
0
KoSopranoTableModel::KoSopranoTableModel(KoDocumentRdf *rdf)
        : m_rdf(rdf)
{
    Soprano::StatementIterator siter = model()->listStatements();
    while (siter.next()) {
        m_statementIndex << *siter;
    }
}
コード例 #2
0
void BackupRestorationJob::slotRestRepo(const QString&, const QString& newPath)
{
    m_oldRepoPath = newPath;

    BackupFile bf = BackupFile::fromUrl( m_url );
    Soprano::StatementIterator it = bf.iterator();

    kDebug() << "Restore Statements:" << bf.numStatements();
    int numStatements = 0;
    while( it.next() ) {
        Soprano::Statement st = it.current();
        if( st.predicate() == NIE::url() ) {
            QUrl url = st.object().uri();
            if( url.scheme() == QLatin1String("file") ) {
                //
                // Check if the file exists
                //
                if( !QFile::exists( url.toLocalFile() ) ) {
                    url = translateHomeUri( url );

                    // REMOVING THIS CHANGE TO nepomuk-backup because one can have removablemedia
                    // files which are currently not mounted. This change sucks but the restore
                    // utility will have to manually check each file
                    // if( !QFile::exists( url.toLocalFile() ) ) {
                    //    url.setScheme("nepomuk-backup");
                    // }
                    if( QFile::exists( url.toLocalFile() ) )
                        st.setObject( url );
                }
            }
        }

        Soprano::Error::ErrorCode err = m_model->addStatement( st );
        if( err ) {
            kWarning() << m_model->lastError();
            setErrorText( m_model->lastError().message() );
            emitResult();
            return;
        }

        numStatements++;
        emitPercent( numStatements, bf.numStatements() );
    }

    QTimer::singleShot(0, m_storageService, SLOT(openPublicInterfaces()) );
    emitResult();
}
コード例 #3
0
ファイル: ontologyparser.cpp プロジェクト: vasi/kdelibs
bool OntologyParser::parse( const QString& filename, const QString& serializationMimeType )
{
    Soprano::RdfSerialization serialization = Soprano::SerializationUnknown;
    if( !serializationMimeType.isEmpty() ) {
        serialization = Soprano::mimeTypeToSerialization( serializationMimeType );
    }
    else if ( filename.endsWith( "trig" ) ) {
        serialization = Soprano::SerializationTrig;
    }
    else {
        serialization = Soprano::SerializationRdfXml;
    }

    if ( !( d->rdfParser = Soprano::PluginManager::instance()->discoverParserForSerialization( serialization, serializationMimeType ) ) ) {
        return false;
    }

    if ( !quiet )
        qDebug() << "(OntologyParser) Parsing " << filename << endl;

    Soprano::StatementIterator it = d->rdfParser->parseFile( filename,
                                    QUrl("http://org.kde.nepomuk/dummybaseuri"),
                                    serialization,
                                    serializationMimeType );
    bool success = true;

    while( it.next() ) {
        const Soprano::Statement& s = *it;

        if( s.predicate().uri() == Soprano::Vocabulary::RDFS::subClassOf() ) {
            ResourceClass* rc = d->getClass( s.subject().uri().toString() );
            rc->setParentResource( d->getClass( s.object().uri().toString() ) );
            rc->addParentResource( d->getClass( s.object().uri().toString() ) );
            rc->setGenerateClass( true );
        }
        else if( s.predicate().uri() == Soprano::Vocabulary::RDF::type() ) {
            if( s.object().uri().toString().endsWith( "#Class" ) )
                d->getClass( s.subject().uri().toString() )->setGenerateClass( true );
        }
        else if( s.predicate().uri() == Soprano::Vocabulary::RDFS::domain() ) {
            ResourceClass* rc = d->getClass( s.object().uri().toString() );
            Property* p = d->getProperty( s.subject().uri().toString() );
            p->setDomain( rc );
            if ( !rc->allProperties().contains( p ) )
                rc->addProperty( p );
            rc->setGenerateClass( true );
        }
        else if( s.predicate().uri() == Soprano::Vocabulary::RDFS::range() ) {
            Property* prop = d->getProperty(s.subject().uri().toString());
            QUrl type = s.object().uri();
            if( type.toString().contains( "XMLSchema" ) ) {
                prop->setLiteralRange( d->xmlSchemaTypes[type] );
            }
            else if( type == Soprano::Vocabulary::RDFS::Literal() ) {
                prop->setLiteralRange( "QString" );
            }
            else {
                prop->setRange( d->getClass(s.object().uri()) );
            }
        }
        else if( s.predicate().uri() == Soprano::Vocabulary::NRL::maxCardinality() ||
                 s.predicate().uri() == Soprano::Vocabulary::NRL::cardinality() ) {
            Property * p = d->getProperty(s.subject().uri());
            int cValue = s.object().literal().toInt();

            p->setIsList( cValue > 1 );
            if( s.predicate().uri() == Soprano::Vocabulary::NRL::maxCardinality() )
                p->setMaxCardinality( cValue );
            else
                p->setCardinality( cValue );
        }
        else if( s.predicate().uri() == Soprano::Vocabulary::RDFS::comment() ) {
            d->comments[s.subject().uri()] = s.object().literal().toString();
        }
        else if ( s.predicate().uri() == Soprano::Vocabulary::NRL::inverseProperty() ) {
            d->getProperty(s.subject().uri())->setInverseProperty( d->getProperty(s.object().uri()) );
            d->getProperty(s.object().uri())->setInverseProperty( d->getProperty(s.subject().uri()) );
        }
    }

    // determine the reverse properties
    for( QMap<QUrl, Property>::iterator propIt = d->properties.begin();
            propIt != d->properties.end(); ++propIt ) {
        Property& p = propIt.value();
        if( p.range() ) {
            if ( !quiet )
                qDebug() << "Setting reverse property " << p.uri() << " on type " << p.range()->uri() << endl;
            if ( !p.range()->allReverseProperties().contains( &p ) )
                p.range()->addReverseProperty( &p );
        }
        if ( !p.domain() ) {
            p.setDomain( d->getClass(Soprano::Vocabulary::RDFS::Resource()) );
        }

        Q_ASSERT( d->properties.count( propIt.key() ) == 1 );
    }

    // now assign the comments to resources and properties
    QMapIterator<QUrl, QString> commentsIt( d->comments );
    while( commentsIt.hasNext() ) {
        commentsIt.next();
        if( d->resources.contains( commentsIt.key() ) )
            d->resources[commentsIt.key()].setComment( commentsIt.value() );
        else if( d->properties.contains( commentsIt.key() ) )
            d->properties[commentsIt.key()].setComment( commentsIt.value() );
    }

    // testing stuff
    for( QMap<QUrl, ResourceClass>::iterator it = d->resources.begin();
            it != d->resources.end(); ++it ) {
        if( !it->parentClass(false) ) {
            it->setParentResource( d->getClass(Soprano::Vocabulary::RDFS::Resource()) );
        }
        if ( !quiet )
            qDebug() << "Resource: " << (*it).name()
                     << "[" << (*it).uri() << "]"
                     << " (->" << (*it).parentClass(false)->name() << ")"
                     << ( (*it).generateClass() ? " (will be generated)" : " (will not be generated)" )
                     << endl;

        Q_ASSERT( d->resources.count( it.key() ) == 1 );

        QListIterator<const Property*> propIt( (*it).allProperties() );
        while( propIt.hasNext() ) {
            const Property* p = propIt.next();
            if ( !quiet )
                qDebug() << "          " << p->uri() << " (->" << p->typeString() << ")" << ( p->isList() ? QString("+") : QString("1") ) << endl;
        }
    }

    return success;
}