Difference between revisions of "Projects/Nepomuk/QueryLibrary"

Jump to: navigation, search
m (can be used)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
Nepomuk provides a Query Library which is a part of the nepomuk-core library. It can be user to dynamically create queries. This Query Library eventually compiles the queries into Sparql which is then run on our database - virtuoso.
+
<languages />
 +
<translate>
  
 +
== The Query Library == <!--T:1-->
 +
 +
<!--T:2-->
 +
'''Nepomuk''' provides a Query Library which is a part of the nepomuk-core library. It can be used to dynamically create queries. This Query Library eventually compiles the queries into Sparql which is then run on our database - virtuoso.
 +
 +
<!--T:3-->
 
It is recommended that you use the Query Library when you're searching for resources which have some direct properties. If the queries are too complex, maybe you should be directly using SPARQL. It all depends on your use case. The only advantage of using the QueryLibrary is that with improvements in the query library, your queries should get faster.
 
It is recommended that you use the Query Library when you're searching for resources which have some direct properties. If the queries are too complex, maybe you should be directly using SPARQL. It all depends on your use case. The only advantage of using the QueryLibrary is that with improvements in the query library, your queries should get faster.
  
= Creating Queries =
+
== Creating Queries == <!--T:4-->
  
The entire Query Library resides in the Nepomuk2::Query namespace. It consists of a number of terms which can be combined together to create larger terms. Eventually when you've have created the final term, you can pass it to <code>Nepomuk2::Query::Query</code> and [[Projects/Nepomuk/QueryingMethods| run the query]]
+
<!--T:5-->
 +
The entire Query Library resides in the Nepomuk2::Query namespace. It consists of a number of terms which can be combined together to create larger terms. Eventually when you've have created the final term, you can pass it to <tt>Nepomuk2::Query::Query</tt> and [[Projects/Nepomuk/QueryingMethods| run the query]]
  
 +
<!--T:6-->
 
The different kinds of terms are -
 
The different kinds of terms are -
  
 +
<!--T:7-->
 
* [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1AndTerm.html AndTerm]
 
* [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1AndTerm.html AndTerm]
 
* [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1OrTerm.html OrTerm]
 
* [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1OrTerm.html OrTerm]
Line 17: Line 27:
 
* [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1ResourceTypeTerm.html ResourceTypeTerm]
 
* [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1ResourceTypeTerm.html ResourceTypeTerm]
  
=== Examples ===
+
=== Examples === <!--T:8-->
  
 +
<!--T:9-->
 
Imagine we wanted to find all files that are tagged with a certain tag:
 
Imagine we wanted to find all files that are tagged with a certain tag:
  
 +
<!--T:10-->
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
 
Nepomuk::Tag myTag = someFancyMethod();
 
Nepomuk::Tag myTag = someFancyMethod();
  
 +
<!--T:11-->
 
// term matching the tag
 
// term matching the tag
 
Nepomuk::Query::ResourceTerm tagTerm( myTag );
 
Nepomuk::Query::ResourceTerm tagTerm( myTag );
  
 +
<!--T:12-->
 
// term matching tagged resource
 
// term matching tagged resource
 
Nepomuk::Query::ComparisonTerm term( Soprano::Vocabulary::NAO::hasTag(),  
 
Nepomuk::Query::ComparisonTerm term( Soprano::Vocabulary::NAO::hasTag(),  
Line 32: Line 46:
 
                                     Nepomuk::Query::ComparisonTerm::Equal );
 
                                     Nepomuk::Query::ComparisonTerm::Equal );
  
 +
<!--T:13-->
 
// build the query
 
// build the query
 
Nepomuk::Query::Query query( term );
 
Nepomuk::Query::Query query( term );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Introspecting Queries ==
+
=== Introspecting Queries === <!--T:14-->
  
The <code>Query</code> class provides convenient methods to convert the query into its relevant sparql query, which can then easily be read. Additionally, it also provides a <code>toSearchUrl</code> method.
+
<!--T:15-->
 +
The <tt>Query</tt> class provides convenient methods to convert the query into its relevant sparql query, which can then easily be read. Additionally, it also provides a <tt>toSearchUrl</tt> method.
  
 +
<!--T:16-->
 
* toSparqlQuery() - Creates a SPARQL query to be used in Soprano::Model::executeQuery
 
* toSparqlQuery() - Creates a SPARQL query to be used in Soprano::Model::executeQuery
 
* toSearchUrl() - Creates a URL that can be listed via KIO.
 
* toSearchUrl() - Creates a URL that can be listed via KIO.
 +
 +
<!--T:17-->
 +
[[Category:Documentation]]
 +
[[Category:Development]]
 +
[[Category:Tutorials]]
 +
</translate>

Latest revision as of 15:04, 1 September 2013

Other languages:English 100%

Contents

[edit] The Query Library

Nepomuk provides a Query Library which is a part of the nepomuk-core library. It can be used to dynamically create queries. This Query Library eventually compiles the queries into Sparql which is then run on our database - virtuoso.

It is recommended that you use the Query Library when you're searching for resources which have some direct properties. If the queries are too complex, maybe you should be directly using SPARQL. It all depends on your use case. The only advantage of using the QueryLibrary is that with improvements in the query library, your queries should get faster.

[edit] Creating Queries

The entire Query Library resides in the Nepomuk2::Query namespace. It consists of a number of terms which can be combined together to create larger terms. Eventually when you've have created the final term, you can pass it to Nepomuk2::Query::Query and run the query

The different kinds of terms are -

[edit] Examples

Imagine we wanted to find all files that are tagged with a certain tag:

Nepomuk::Tag myTag = someFancyMethod();
 
// term matching the tag
Nepomuk::Query::ResourceTerm tagTerm( myTag );
 
// term matching tagged resource
Nepomuk::Query::ComparisonTerm term( Soprano::Vocabulary::NAO::hasTag(), 
                                     tagTerm, 
                                     Nepomuk::Query::ComparisonTerm::Equal );
 
// build the query
Nepomuk::Query::Query query( term );

[edit] Introspecting Queries

The Query class provides convenient methods to convert the query into its relevant sparql query, which can then easily be read. Additionally, it also provides a toSearchUrl method.

  • toSparqlQuery() - Creates a SPARQL query to be used in Soprano::Model::executeQuery
  • toSearchUrl() - Creates a URL that can be listed via KIO.

This page was last modified on 1 September 2013, at 15:04. This page has been accessed 1,872 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal