void TestRdf::basicload() { RDEBUG; QString odt = QString(FILES_DATA_DIR) + "/weekend-hike.odt"; KoDocumentRdf *rdf = loadDocument(odt); QVERIFY(rdf); QSharedPointer<Soprano::Model> m = rdf->model(); QVERIFY(m); QCOMPARE (234, m->statementCount()); StatementIterator it; QList<Statement> allStatements; // check a triple it = m->listStatements( Node::createResourceNode(QUrl("uri:james")), Node::createResourceNode(QUrl("http://xmlns.com/foaf/0.1/name")), Node()); allStatements = it.allElements(); QCOMPARE (allStatements.size(), 1); foreach (Soprano::Statement s, allStatements) { // RDEBUG << "HAVE:" << s; QVERIFY (s.object().toString() == "James Smith"); }
void KoRdfSemanticItemViewSite::setProperty(const QString &prop, const QString &v) { QString fqprop = "http://koffice.org/rdf/site#" + prop; KoDocumentRdf *rdf = d->m_semItem->documentRdf(); Soprano::Model *m = rdf->model(); Soprano::Node ls = linkingSubject(); Soprano::Node pred = Node::createResourceNode(QUrl(fqprop)); m->removeAllStatements(Statement(ls, pred, Node())); m->addStatement(ls, pred,Node::createLiteralNode(v), rdf->manifestRdfNode()); }
QString RdfTest::insertTableWithSemItem(KoTextEditor &editor, KoDocumentRdf &rdfDoc, const QString name) { editor.insertTable(5,10); #define TABLESIZE (5*10) const QTextTable *table = editor.currentTable(); QTextCursor cur(editor.document()); cur.setPosition(table->firstPosition()); KoBookmark *bookmark = new KoBookmark(cur); bookmark->setPositionOnlyMode(false); // we want it to be several chars long KoTextInlineRdf *inlineRdf(new KoTextInlineRdf(editor.document(), bookmark)); QString newId = inlineRdf->createXmlId(); inlineRdf->setXmlId(newId); bookmark->setName(newId); bookmark->setInlineRdf(inlineRdf); KoTextDocument(editor.document()).textRangeManager()->insert(bookmark); editor.setPosition(table->firstPosition()); editor.movePosition(QTextCursor::PreviousCharacter); hTestSemanticItem testItem(new TestSemanticItem(0, &rdfDoc)); testItem->setName(name); Soprano::Statement st( testItem->linkingSubject(), // subject Soprano::Node::createResourceNode(QUrl("http://docs.oasis-open.org/ns/office/1.2/meta/pkg#idref")), // predicate Soprano::Node::createLiteralNode(newId), // object rdfDoc.manifestRdfNode()); // manifest datastore rdfDoc.model()->addStatement(st); rdfDoc.rememberNewInlineRdfObject(inlineRdf); Q_ASSERT(rdfDoc.model()->statementCount() > 0); bookmark->setRangeEnd(table->lastPosition()); return newId; }
QString KoRdfSemanticItemViewSite::getProperty(const QString &prop, const QString &defval) const { Soprano::Node ls = linkingSubject(); QString fqprop = "http://koffice.org/rdf/site#" + prop; KoDocumentRdf *rdf = d->m_semItem->documentRdf(); Soprano::Model *m = rdf->model(); StatementIterator it = m->listStatements(ls, Node::createResourceNode(QUrl(fqprop)), Node(), rdf->manifestRdfNode()); QList<Statement> allStatements = it.allElements(); foreach (Soprano::Statement s, allStatements) { return s.object().toString(); } return defval; }
Soprano::Node KoRdfSemanticItemViewSite::linkingSubject() const { KoDocumentRdf *rdf = d->m_semItem->documentRdf(); Soprano::Model *m = rdf->model(); Node pred(QUrl("http://koffice.org/rdf/site/package/common#idref")); Node obj = Node::createLiteralNode(d->m_xmlid); Node context = rdf->manifestRdfNode(); // try to find it if it already exists StatementIterator it = m->listStatements(Node(), pred, obj, context); QList<Statement> allStatements = it.allElements(); foreach (Soprano::Statement s, allStatements) { return s.subject(); } Node ret = m->createBlankNode(); m->addStatement(ret, pred, obj, context); return ret; }
void TestKoDocumentRdf::testCreate() { KoDocumentRdf *rdfDoc = new KoDocumentRdf(); Q_ASSERT(rdfDoc->model()); delete rdfDoc; }