[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    RDF in KOffice: the need for context support in the soprano memory
From:       Jos van den Oever <jos.van.den.oever () kogmbh ! com>
Date:       2010-08-20 18:44:23
Message-ID: 201008202044.23798.jos.van.den.oever () kogmbh ! com
[Download RAW message or body]

Hi all,

These last days, I've been struggling with a problem in the KOffice RDF code. I 
wanted to fix the failing unit test and found that this was not so easy.

I went to look for the cause of the problem and found that a query (run from 
the KWord SPARQL query form ;-) like this one:
  SELECT ?g ?s ?p ?o WHERE { GRAPH ?g { ?s ?p ?o } }
would give no results, even though a query without GRAPH, like this:
  SELECT ?s ?p ?o WHERE { ?s ?p ?o }
would work.

Now these things used to work, so what has changed? The packages on my machine 
changed. KOffice uses Soprano for RDF support and Soprano uses Redland as the 
memory only backend.
Testing a number of calls with the Redland command-line tools led me to this 
test:
  # create a graph with one statement in context 'c'
  rdfproc -c -n -s sqlite test add s p o c
  # query the graph
  rdfproc -c -s sqlite test query sparql - 'select ?g ?s ?p ?o where {graph ?g 
{?s ?p ?o}}'
This should give one result line, but gives no result lines on some versions 
of Redland.
Redland uses two other libraries: Raptor and Rasqal. The latter is responsible 
for doing the querying. Since verion 0.9.17 of Rasqal, a new query engine is 
in use. Starting from this version, the above commands give no results.

The ChangeLog gives the option to compile Rasqal with
  --with-query-engine-version=1
to get the old query engine. This gives the desired behavior in Rasqal version 
0.9.17, 0.9.18 and 0.9.19, but is not what e.g. Fedora Core 13 uses.
I have reported the issue in the Redland bug database.
http://bugs.librdf.org/mantis/view.php?id=382

Without support for GRAPH in queries, RDF in KOffice is dysfunctional. The 
Soprano backends are loaded dynamically, so I wrote a test to detect at 
runtime if Soprano can deliver the implementation we need.

Best regards,
Jos

-- 
Jos van den Oever, software architect
+49 391 25 19 15 53
http://kogmbh.com/legal/

["rasqaltest.cpp" (text/x-c++src)]

#include <Soprano/Global>
#include <Soprano/StorageModel>
#include <Soprano/QueryResultIterator>
#include <Soprano/Statement>
#include <QtCore/QDebug>

int
main() {
    /* Test whether a model is present that supports:
       - context / graphs
       - querying on graphs
       - storage in memory.
    */

    const Soprano::Backend *backend = Soprano::discoverBackendByFeatures(
            Soprano::BackendFeatureContext |
            Soprano::BackendFeatureQuery |
            Soprano::BackendFeatureStorageMemory);
    if (backend == NULL) {
        // without a backend with the desired features, this test fails
        qDebug() << "No suitable backend found.";
        return 1;
    }
    qDebug() << "Found a backend: " << backend->pluginName();

    Soprano::setUsedBackend(backend);
    Soprano::BackendSettings backendSettings;
    backendSettings << Soprano::BackendOptionStorageMemory;
    Soprano::StorageModel* model = backend->createModel(backendSettings);
    if (model == NULL) {
        // if model creation failed, this test fails
        qDebug() << "No model could be created.";
        return 1;
    }

    model->addStatement(Soprano::Statement(
            QUrl("subject"), QUrl("predicate"), QUrl("object"),
            QUrl("context")));

    Soprano::QueryResultIterator it = model->executeQuery(
            "SELECT ?g ?s ?p ?o WHERE { GRAPH ?g { ?s ?p ?o } }",
            Soprano::Query::QueryLanguageSparql);

    if (!it.next()) {
        // there should be exactly one result statement
        qDebug() << "Query returned too few results.";
        delete model;
        return 1;
    }
    if (it.next()) {
        // there should be exactly one result statement
        qDebug() << "Query returned too many results.";
        delete model;
        return 1;
    } 

    delete model;
    return 0;
}


_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic