QueryParser Class Reference
from PyKDE4.nepomuk import *
Namespace: Nepomuk.Query
Detailed Description
\class QueryParser queryparser.h Nepomuk/Query/QueryParser
Parser for desktop user queries.
The QueryParser can be used to parse queries and convert them into Query instances.
The syntax is fairly simple: plain strings match to LiteralTerm terms, URIs need to be N3-encoded, when using white space parenthesis need to be put around properties and values, terms can be excluded via '-'.
Examples
%Query everything that contains the term "nepomuk":
nepomuk
%Query everything that contains both the terms "Hello" and "World":
Hello World
%Query everything that contains the term "Hello World":
"Hello World"
%Query everything that has a tag whose label matches "nepomuk" (actually this is where Query.resolveProperties would match "hastag" to nao:hasTag):
hastag:nepomuk
%Query everything that has a tag labeled "nepomuk" or a tag labeled "scribo:
hastag:nepomuk OR hastag:scribo
%Query everything that has a tag labeled "nepomuk" but not a tag labeled "scribo":
+hastag:nepomuk AND -hastag:scribo
The parser can handle one special case of nesting (TODO: implement a "real" parser) which matches all resources that are related to a resource which in turn has a certain property:
related:(hastag:nepomuk)
- Since:
- 4.4
Enumerations | |
ParserFlag | { NoParserFlags, QueryTermGlobbing } |
Methods | |
__init__ (self) | |
[Nepomuk.Types.Property] | matchProperty (self, QString fieldName) |
Nepomuk.Query.Query | parse (self, QString query) |
Nepomuk.Query.Query | parse (self, QString query, Nepomuk.Query.QueryParser.ParserFlags flags) |
Static Methods | |
Nepomuk.Query.Query | parseQuery (QString query) |
Method Documentation
__init__ | ( | self ) |
Create a new query parser.
[Nepomuk.Types.Property] matchProperty | ( | self, | ||
QString | fieldName | |||
) |
Try to match a field name as used in a query string to actual properties.
The matching is cached inside the Query instance for fast subsequent lookups.
Example:
hastag:nepomuk
- Returns:
- A list of properties that match fieldName or an empty list in case nothing was matched.
This method is used by parse() to match properties used in user queries.
Nepomuk.Query.Query parse | ( | self, | ||
QString | query | |||
) |
Parse a user query.
- Parameters:
-
query The query string to parse
- Parameters:
-
flags a set of flags influencing the parsing process.
- Returns:
- The parsed query or an invalid Query object in case the parsing failed.
- Since:
- 4.5
Nepomuk.Query.Query parse | ( | self, | ||
QString | query, | |||
Nepomuk.Query.QueryParser.ParserFlags | flags | |||
) |
Parse a user query.
- Parameters:
-
query The query string to parse
- Parameters:
-
flags a set of flags influencing the parsing process.
- Returns:
- The parsed query or an invalid Query object in case the parsing failed.
- Since:
- 4.5
Static Method Documentation
Nepomuk.Query.Query parseQuery | ( | QString | query | |
) |
Convenience method to quickly parse a query without creating an object.
- Returns:
- The parsed query or an invalid Query object in case the parsing failed.
Enumeration Documentation
ParserFlag |
Flags to change the behaviour of the parser.
- Since:
- 4.5
- Enumerator:
-
NoParserFlags = 0x0 QueryTermGlobbing = 0x1