← Projects/Nepomuk/QueryLibrary You do not have permission to edit this page, for the following reason: The action you have requested is limited to users in one of the groups: Users, Administrators, trusted, KDEDevelopers. You can view and copy the source of this page. 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. 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 = 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]] The different kinds of terms are - * [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_1NegationTerm.html NegationTerm] * [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1ComparisonTerm.html ComparisionTerm] * [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1LiteralTerm.html LiteralTerm] * [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1ResourceTerm.html ResourceTerm] * [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Query_1_1ResourceTypeTerm.html ResourceTypeTerm] === Examples === Imagine we wanted to find all files that are tagged with a certain tag: <syntaxhighlight lang="cpp"> 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 ); </syntaxhighlight> == Introspecting Queries == 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. * toSparqlQuery() - Creates a SPARQL query to be used in Soprano::Model::executeQuery * toSearchUrl() - Creates a URL that can be listed via KIO. Return to Projects/Nepomuk/QueryLibrary. Retrieved from "https://techbase.kde.org/Projects/Nepomuk/QueryLibrary"