soprano
Soprano Howto
Soprano includes
Using Soprano in your own project is pretty straight forward. Soprano provides includes for all classes and enumerations. Using a Soprano class like Statement is as simple as including
#include <Soprano/Statement>
For an easy start one can simply include the Soprano header which pulls in all classes. The following code shows a simple example of a Soprano application which creates a new Model, adds a Statement, and lists it.
#include <Soprano/Soprano> #include <QDebug> int main( int argc, char** argv ) { Soprano::Model* model = Soprano::createModel(); model->addStatement( QUrl( "http://mysite.org/data#A"), Soprano::Vocabulary::RDFS::label(), Soprano::LiteralValue( "A test resource" ) ); Soprano::StatementIterator it = model->listStatements(); while( it.next() ) qDebug() << *it; }
Soprano in the Build System
Integrating Soprano into your own build system is rather simple. Soprano provides a set of libraries and one include path. The libraries are:
- libsoprano - The core library providing storage, parsing, and all utility classes
- libsopranoindex - The full text index based on CLucene (Soprano::Index)
- libsopranoserver - The server library which provides a simple implementation of an RDF database server (Soprano::Server)
- libsopranoclient - The counterpart to the server library (Soprano::Client)
A PkgConfig description is provided for the core library and can be used as described in the following.
Using qmake with Soprano
Soprano provides pkg-config integration which allows to build the above example using qmake. The following pro file looks for Soprano includes and libs via pkg-config and builds the application sopranotest.
TEMPLATE = app SOURCES += main.cpp TARGET = sopranotest CONFIG += qt link_pkgconfig PKGCONFIG += soprano
Using CMake with Soprano
Using cmake is as simple. Find required packages Qt4 and PkgConfig, look for Soprano via PkgConfig and link to both Soprano and QtCore:
find_package(PkgConfig REQUIRED)
find_package(Qt4 REQUIRED)
pkg_search_module(Soprano REQUIRED soprano)
include_directories(${Soprano_INCLUDE_DIRS} ${QT_INCLUDE_DIR})
add_executable(sopranotest main.cpp)
target_link_libraries(sopranotest ${Soprano_LIBRARIES} ${QT_QTCORE_LIBRARY})
- Warning:
- PkgConfig is not available on Windows. For platform independant development use a typical cmake module like KDE's FindSoprano.cmake.
Some CMake Magic
Soprano provides the simple onto2vocabularyclass tool which can generate convinience namespaces such as Soprano::Vocabulary::RDF from ontology files. With CMake it is very simple to generate these namespaces on-the-fly instead of packaging the generated files by using the SopranoAddOntology macro provided by Soprano:
soprano_add_ontology(SOURCES
ONTOLOGY_FILE
ONTOLOGY_NAME
NAMESPACE
ENCODING
[VISIBLITY VISIBILITY_NAME])
Imagine ones code contains an ontology description in rdf+xml format named Foo (Foo Object Ontology) and you want to make it's classes and properties accessible in the MyStuff::Foo namespace. One simply includes the cmake macro provided by Soprano:
include(SopranoAddOntology)
And then uses it to add the generated files to the sources:
soprano_add_ontology(foo_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/foo.rdfs "FOO" "Vocabulary" "rdfxml")
This will add a command to generate files foo.h and foo.cpp at build time and add the latter to the sources foo_SOURCES. The generated namespace will be named Vocabulary::FOO. It is optionally possible to make the namespace public API and export it by adding the VISIBILITY keyword:
soprano_add_ontology(foo_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/foo.rdfs "FOO" "Vocabulary" "rdfxml" VISIBILITY "foo")
KDE 4.4 API Reference