#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; }
TEMPLATE = app SOURCES += main.cpp TARGET = sopranotest CONFIG += qt link_pkgconfig PKGCONFIG += soprano
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})
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")