<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://techbase.kde.org/skins/common/feed.css?0.2"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://techbase.kde.org/index.php?title=Projects/Nepomuk/SparqlQueries/en&amp;feed=atom&amp;action=history</id>
		<title>Projects/Nepomuk/SparqlQueries/en - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://techbase.kde.org/index.php?title=Projects/Nepomuk/SparqlQueries/en&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Projects/Nepomuk/SparqlQueries/en&amp;action=history"/>
		<updated>2013-05-25T22:51:13Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.2</generator>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Projects/Nepomuk/SparqlQueries/en&amp;diff=77230&amp;oldid=prev</id>
		<title>FuzzyBot: Updating to match new version of source page</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Projects/Nepomuk/SparqlQueries/en&amp;diff=77230&amp;oldid=prev"/>
				<updated>2012-12-12T14:00:02Z</updated>
		
		<summary type="html">&lt;p&gt;Updating to match new version of source page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;languages /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
== Running Sparql Queries ==&lt;br /&gt;
&lt;br /&gt;
Depending on the needs of your application you may need to directly run sparql queries.&lt;br /&gt;
&lt;br /&gt;
'''Nepomuk''' uses one main [http://soprano.sourceforge.net/apidox/stable/classSoprano_1_1Model.html Soprano model] which is accessed through the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk_1_1ResourceManager.html ResourceManager]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
    Soprano::Model* model = Nepomuk::ResourceManager::instance()-&amp;gt;mainModel();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The queries can be run via this model -&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
    QString query = QString::fromLatin1(&amp;quot;select ?r where { ?r a nco:Contact . }&amp;quot;);&lt;br /&gt;
    Soprano::Model* model = Nepomuk2::ResourceManager::instance()-&amp;gt;mainModel();&lt;br /&gt;
    Soprano::QueryResultIterator it = model-&amp;gt;executeQuery( query, Soprano::Query::QueryLanguageSparql );&lt;br /&gt;
&lt;br /&gt;
    while( it.next() ) {&lt;br /&gt;
        kDebug() &amp;lt;&amp;lt; it[&amp;quot;r&amp;quot;].uri();&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sparql Prefixes ===&lt;br /&gt;
&lt;br /&gt;
When writing SPARQL queries, according to the standard one needs to prepend the queries with the prefixes that have been used. For example - &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
PREFIX nco: &amp;lt;http://www.semanticdesktop.org/ontologies/2007/03/22/nco#&amp;gt; .&lt;br /&gt;
select ?r ?name where { ?r a nco:Contact . ?r nco:fullname ?name . }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When running queries in Nepomuk, you do not need to explicitly add the prefix. The prefix will automatically be added by the storage service. In the future we will try to make virtuoso automatically understand all prefixes.&lt;br /&gt;
&lt;br /&gt;
=== Full Text Indexing ===&lt;br /&gt;
&lt;br /&gt;
'''Nepomuk''' depends on [http://soprano.sourceforge.net/apidox/trunk/soprano_backend_virtuoso.html Virtuoso] for data storage. '''Virtuoso''' brings a lot of nice [http://docs.openlinksw.com/virtuoso/rdfsparql.html#sparqlextensions extensions to SPARQL]. Most importantly the full text search which is used through the artificial ''bif:contains'' property. &lt;br /&gt;
&lt;br /&gt;
This allows to combine graph queries with full text queries in a nice way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
select ?r where { ?r nao:prefLabel ?label .&lt;br /&gt;
                  ?label bif:contains 'nepomuk' . }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query above will find any resources that contain ''nepomuk'' in their label.&lt;br /&gt;
&lt;br /&gt;
Of course wildcards are supported, too. However, be aware that when using wildcards the expression itself needs to be enclosed in quotes as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
select ?r where { ?r nao:prefLabel ?label .&lt;br /&gt;
                  ?label bif:contains &amp;quot;'nepomuk*'&amp;quot; . }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note the virtuoso '''requires a minimum of 4 leading characters''' in order to use wildcards.&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>FuzzyBot</name></author>	</entry>

	</feed>