/** * Copy all the triples in srclist to be new rows in the model. * Note that the object value is modified to contain a unique * postfix so that the new triple copies can be inserted into * the Rdf model. It is a copy in a looser sense of the word. */ QModelIndexList KoSopranoTableModel::copyTriples(const QModelIndexList &srclist) { QModelIndexList ret; int FirstNewRowNumber = rowCount(); int LastNewRowNumber = FirstNewRowNumber + srclist.size() - 1; int currentNewRowNum = FirstNewRowNumber; beginInsertRows(QModelIndex(), FirstNewRowNumber, LastNewRowNumber); kDebug(30015) << " m_statementIndex.sz:" << m_statementIndex.size(); kDebug(30015) << " srclist.size():" << srclist.size(); kDebug(30015) << " first:" << FirstNewRowNumber; kDebug(30015) << " last:" << LastNewRowNumber; foreach (const QModelIndex &src, srclist) { int r = src.row(); kDebug(30015) << "r:" << r; Soprano::Statement st = m_statementIndex[ r ]; // // Append a bnode to the object to ensure the "copy" // is unique relative to the original. // Soprano::Node obj(QUrl(st.object().toString() + '-' + model()->createBlankNode().toString())); Soprano::Statement n(st.subject(), st.predicate(), obj, st.context()); model()->addStatement(n); m_statementIndex << n; QModelIndex newIdx = index(currentNewRowNum, ColSubj); ret << newIdx; ++currentNewRowNum; }
bool KoSopranoTableModel::setData(const QModelIndex &index, const QVariant &value, int role) { Q_UNUSED(role); if (!index.isValid()) { return false; } int r = index.row(); Soprano::Statement st = m_statementIndex[r]; QString uri = PrefexedLocalnameToURI(value.toString()); Soprano::Statement n(st.subject(), st.predicate(), st.object(), st.context()); switch (index.column()) { case ColSubj: n.setSubject(Soprano::Node(QUrl(uri))); return setDataUpdateTriple(index, st, n); case ColPred: n.setPredicate(Soprano::Node(QUrl(uri))); return setDataUpdateTriple(index, st, n); case ColObj: { if (st.object().isLiteral()) { n.setObject( Soprano::Node( Soprano::LiteralValue(value.toString()))); } else { n.setObject(Soprano::Node(QUrl(uri))); } return setDataUpdateTriple(index, st, n); } case ColObjType: { QString v = value.toString(); if (v == "URI") { n.setObject(Soprano::Node(QUrl(st.object().toString()))); } else if (v == "Literal") { n.setObject( Soprano::Node( Soprano::LiteralValue(st.object().toString()))); } else { n.setObject(Soprano::Node(QString(st.object().toString()))); } return setDataUpdateTriple(index, st, n); } case ColCtx: { QString v = value.toString(); if (v == "inline") { QString InternalContext = m_rdf->rdfInternalMetadataWithoutSubjectURI(); n.setContext(Soprano::Node(QUrl(InternalContext))); } else { if (!v.endsWith(".rdf")) v = v + ".rdf"; n.setContext(Soprano::Node(QUrl(m_rdf->rdfPathContextPrefix() + v))); } return setDataUpdateTriple(index, st, n); } } return false; }
void Soprano::ModelMonitor::slotStatementAdded( const Soprano::Statement& s ) { if ( s.matches( d->pattern ) ) { QTextStream outStream( stdout ); outStream << QString( "%1 | " ).arg( d->removedCnt + d->addedCnt++, 4, 10, QChar('0') ) << "Added: " << s << endl; } }
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(); }
void Soprano::ModelMonitor::slotStatementRemoved( const Soprano::Statement& s ) { // we do not use Statement::matches here since we want to match empty nodes on both sides. // not only in the pattern. This is because some backends do not emit the statementRemoved // signal on each single statement but on the pattern used. if ( ( d->pattern.subject().isEmpty() || s.subject().isEmpty() || d->pattern.subject() == s.subject() ) && ( d->pattern.predicate().isEmpty() || s.predicate().isEmpty() || d->pattern.predicate() == s.predicate() ) && ( d->pattern.object().isEmpty() || s.object().isEmpty() || d->pattern.object() == s.object() ) && ( d->pattern.context().isEmpty() || s.context().isEmpty() || d->pattern.context() == s.context() ) ) { QTextStream outStream( stdout ); outStream << QString( "%1 | " ).arg( d->addedCnt + d->removedCnt++, 4, 10, QChar('0') ) << "Removed: " << s << endl; } }
Soprano::Error::ErrorCode Soprano::Index::CLuceneIndex::removeStatement( const Soprano::Statement& statement ) { // qDebug() << "CLuceneIndex::removeStatement in thread " << QThread::currentThreadId(); QMutexLocker lock( &d->mutex ); clearError(); // just for speed if ( !d->indexPresent() ) { // qDebug() << "CLuceneIndex::removeStatement done in thread " << QThread::currentThreadId(); return Error::ErrorNone; } bool success = false; QString field = QString::fromLatin1( statement.predicate().uri().toEncoded() ); QString text = statement.object().isResource() ? QString::fromLatin1( statement.object().uri().toEncoded() ) : statement.object().toString(); if( text.isEmpty() ) { return Error::ErrorNone; } try { lucene::document::Document* document = d->getDocument( statement.subject() ); if ( document ) { CLuceneDocumentWrapper docWrapper( document ); docWrapper.removeProperty( field, text, statement.object().isResource() ); if ( d->transactionID == 0 ) { d->commit(); } success = true; } } catch( CLuceneError& err ) { qDebug() << "(Soprano::Index::CLuceneIndex::removeStatement) Exception occurred: " << err.what(); setError( exceptionToError( err ) ); success = false; } // qDebug() << "CLuceneIndex::removeStatement done in thread " << QThread::currentThreadId(); return success ? Error::ErrorNone : Error::ErrorUnknown; }
Soprano::Error::ErrorCode Soprano::Index::CLuceneIndex::addStatement( const Soprano::Statement& statement ) { // qDebug() << "CLuceneIndex::addStatement in thread " << QThread::currentThreadId(); QMutexLocker lock( &d->mutex ); clearError(); QString field = QString::fromLatin1( statement.predicate().uri().toEncoded() ); QString text = statement.object().isResource() ? QString::fromLatin1( statement.object().uri().toEncoded() ) : statement.object().toString(); if( text.isEmpty() ) { setError( "Cannot index object nodes that convert to an empty string." ); // qDebug() << "CLuceneIndex::addStatement done in thread " << QThread::currentThreadId(); return Error::ErrorUnknown; } bool success = true; try { lucene::document::Document* document = d->getDocument( statement.subject() ); if ( document ) { CLuceneDocumentWrapper docWrapper( document ); docWrapper.addProperty( field, text, statement.object().isResource() ); if ( d->transactionID == 0 ) { d->commit(); } success = true; } else { // error already set in documentForResource success = false; } } catch( CLuceneError& err ) { setError( exceptionToError( err ) ); success = false; } // qDebug() << "CLuceneIndex::addStatement done in thread " << QThread::currentThreadId(); return success ? Error::ErrorNone : Error::ErrorUnknown; }
QVariant KoSopranoTableModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } Soprano::Statement st = m_statementIndex[index.row()]; if (index.column() == ColIsValid && role == Qt::CheckStateRole) { return st.isValid(); } if (role == Qt::BackgroundRole) { if (!m_statementIndex[index.row()].isValid()) { return QColor("#BB0000"); } } if (role != Qt::DisplayRole && role != Qt::EditRole) { return QVariant(); } switch (index.column()) { case ColIsValid: return QVariant(); case ColSubj: return URItoPrefexedLocalname(st.subject().toString()); case ColPred: return URItoPrefexedLocalname(st.predicate().toString()); case ColObj: if (st.object().type() == Soprano::Node::ResourceNode) return URItoPrefexedLocalname(st.object().toString()); return st.object().toString(); case ColObjType: switch (st.object().type()) { case Soprano::Node::EmptyNode: return i18n("Empty"); case Soprano::Node::ResourceNode: return i18n("URI"); case Soprano::Node::LiteralNode: return i18n("Literal"); case Soprano::Node::BlankNode: return i18n("Blank"); } return QString(); case ColObjXsdType: return st.object().dataType().toString(); case ColCtx: { QString ctx = st.context().toString(); QString RdfPathContextPrefix = m_rdf->rdfPathContextPrefix(); QString InternalContext = m_rdf->inlineRdfContext().toString(); kDebug(30015) << "InternalContext:" << InternalContext; kDebug(30015) << "ctx:" << ctx; if (ctx.startsWith(RdfPathContextPrefix)) { ctx = ctx.mid(RdfPathContextPrefix.size()); } if (isInlineRdf(st)) { ctx = "inline"; } return ctx; } } return QVariant(); }
bool KoSopranoTableModel::isInlineRdf(Soprano::Statement st) const { return (st.context().toString() == m_rdf->inlineRdfContext().toString()); }
foreach (Soprano::Statement s, allStatements) { // RDEBUG << "HAVE:" << s; QVERIFY (s.object().toString() == "CDC474D4-1393-11D7-9A2C-000393914268"); QVERIFY (s.context().toString() == rdf->RDF_PATH_CONTEXT_PREFIX + "geo1.rdf"); }