Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 5b6c31d6428e1f6ea754ea6f7b1aed6e > files > 790

soprano-apidocs-2.6.0-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Soprano: Soprano Howto</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Soprano&#160;<span id="projectnumber">2.6.0</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="index.html">Soprano (aka QRDF) - A modular RDF storage framework</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<h1><a class="el" href="namespaceSoprano.html">Soprano</a> Howto </h1>  </div>
</div>
<div class="contents">
<div class="textblock"><h2><a class="anchor" id="includes"></a>
Soprano includes</h2>
<p>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</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;Soprano/Statement&gt;</span>
</pre></div><p>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.</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;Soprano/Soprano&gt;</span>
<span class="preprocessor"> #include &lt;QDebug&gt;</span>

 <span class="keywordtype">int</span> main( <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv )
 {
     <a class="code" href="classSoprano_1_1Model.html" title="A Model is the central class in Soprano. It is a queryable collection of RDF quadruples, i.e statements.">Soprano::Model</a>* model = <a class="code" href="namespaceSoprano.html#a66f765cf9fd9aae07f874fdb8867dd1c">Soprano::createModel</a>();
     model-&gt;<a class="code" href="classSoprano_1_1Model.html#aed5b923235288fbac997850cca8f6053">addStatement</a>( <a class="codeRef" href="qurl.html">QUrl</a>( <span class="stringliteral">&quot;http://mysite.org/data#A&quot;</span>),
                          <a class="code" href="namespaceSoprano_1_1Vocabulary_1_1RDFS.html#af4ad9f5ac62961046e7d8be3906a8010">Soprano::Vocabulary::RDFS::label</a>(),
                          <a class="code" href="classSoprano_1_1LiteralValue.html" title="Represents a literal value of an RDF Node.">Soprano::LiteralValue</a>( <span class="stringliteral">&quot;A test resource&quot;</span> ) );
     <a class="code" href="classSoprano_1_1StatementIterator.html" title="An iterator that provides a stream of Statements.">Soprano::StatementIterator</a> it = model-&gt;<a class="code" href="classSoprano_1_1Model.html#a7f50dc6483e0bed7830877182c7906ac">listStatements</a>();
     <span class="keywordflow">while</span>( it.<a class="code" href="classSoprano_1_1Iterator.html#a1ba632f6f015242ab9441da77d48415b">next</a>() )
         qDebug() &lt;&lt; *it;
 }
</pre></div><h2><a class="anchor" id="build_systems"></a>
Soprano in the Build System</h2>
<p>Integrating Soprano into your own build system is rather simple. Soprano provides a set of libraries and one include path. The libraries are: </p>
<ul>
<li>libsoprano - The core library providing storage, parsing, and all utility classes </li>
<li>libsopranoindex - The full text index based on CLucene (<a class="el" href="namespaceSoprano_1_1Index.html">Soprano::Index</a>) </li>
<li>libsopranoserver - The server library which provides a simple implementation of an RDF database server (<a class="el" href="namespaceSoprano_1_1Server.html">Soprano::Server</a>) </li>
<li>libsopranoclient - The counterpart to the server library (<a class="el" href="namespaceSoprano_1_1Client.html">Soprano::Client</a>)</li>
</ul>
<p>A PkgConfig description is provided for the core library and can be used as described in the following.</p>
<h3><a class="anchor" id="qmake"></a>
Using qmake with Soprano</h3>
<p>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.</p>
<div class="fragment"><pre class="fragment"> TEMPLATE = app
 SOURCES += main.cpp
 TARGET = sopranotest
 CONFIG += qt link_pkgconfig
 PKGCONFIG += soprano
</pre></div><h3><a class="anchor" id="cmake"></a>
Using CMake with Soprano</h3>
<p>Using cmake is simple. Find required packages <em>Qt4</em> and <em>PkgConfig</em>, look for Soprano via PkgConfig and link to both Soprano and QtCore:</p>
<div class="fragment"><pre class="fragment"> 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})
</pre></div><dl class="warning"><dt><b>Warning:</b></dt><dd>PkgConfig is not available on Windows. For platform independent development use a typical cmake module like KDE's <a href="http://websvn.kde.org:80/%2Acheckout%2A/trunk/KDE/kdelibs/cmake/modules/FindSoprano.cmake">FindSoprano.cmake</a>.</dd></dl>
<h4><a class="anchor" id="cmake_magic"></a>
Some CMake Magic</h4>
<p>Soprano provides the simple <a class="el" href="soprano_devel_tools.html#onto2vocabularyclass">onto2vocabularyclass</a> tool which can generate convenience namespaces such as <a class="el" href="namespaceSoprano_1_1Vocabulary_1_1RDF.html">Soprano::Vocabulary::RDF</a> 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:</p>
<div class="fragment"><pre class="fragment"> soprano_add_ontology(SOURCES
                      ONTOLOGY_FILE
                      ONTOLOGY_NAME
                      NAMESPACE
                      ENCODING
                      [VISIBLITY VISIBILITY_NAME])
</pre></div><p>Imagine one's code contains an ontology description in rdf+xml format named Foo (Foo Object Ontology) and you want to make its classes and properties accessible in the <em>MyStuff::Foo</em> namespace. One simply includes the cmake macro provided by <a class="el" href="namespaceSoprano.html">Soprano</a>:</p>
<div class="fragment"><pre class="fragment"> include(SopranoAddOntology)
</pre></div><p>And then uses it to add the generated files to the sources:</p>
<div class="fragment"><pre class="fragment"> soprano_add_ontology(foo_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/foo.rdfs <span class="stringliteral">&quot;FOO&quot;</span> <span class="stringliteral">&quot;Vocabulary&quot;</span> <span class="stringliteral">&quot;rdfxml&quot;</span>)
</pre></div><p>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:</p>
<div class="fragment"><pre class="fragment"> soprano_add_ontology(foo_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/foo.rdfs <span class="stringliteral">&quot;FOO&quot;</span> <span class="stringliteral">&quot;Vocabulary&quot;</span> <span class="stringliteral">&quot;rdfxml&quot;</span> VISIBILITY <span class="stringliteral">&quot;foo&quot;</span>)
</pre></div> </div></div>
<hr class="footer"/><address class="footer"><small>Generated on Fri Mar 11 2011 for Soprano by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>