Lumiera  0.pre.03
»edit your freedom«
query-util.cpp File Reference

Go to the source code of this file.

Description

Implementation of helpers for working with predicate queries.

Definition in file query-util.cpp.

#include "lib/error.hpp"
#include "lib/query-util.hpp"
#include "lib/util.hpp"
#include <boost/algorithm/string.hpp>
#include <functional>
#include <regex>
#include <map>

Typedefs

using ChPredicate = std::function< bool(string::value_type)>
 

Functions

string appendTerms (string const &pred1, string const &pred2)
 
uint countPred (const string &)
 count the top-level predicates in the query string. More...
 
string extractID (Symbol sym, const string &termString)
 (preliminary) helper: instead of really parsing and evaluating the terms, just do a regular expression match to extract the literal argument behind the given predicate symbol. More...
 
regex & getTermRegex (Symbol sym)
 
bool hasTerm (Symbol sym, string const &queryString)
 
void normaliseID (string &id)
 ensure standard format for a given id string. More...
 
string removeTerm (Symbol sym, string &queryString)
 (preliminary) helper: cut a term with the given symbol. More...
 

Variables

const regex FIND_PREDICATE {string{"(\\w+)"} + MATCH_ARGUMENT}
 
ChPredicate is_alpha = boost::algorithm::is_alpha()
 
ChPredicate is_upper = boost::algorithm::is_upper()
 
Literal MATCH_ARGUMENT = R"~(\(\s*([\w_\.\-]+)\s*\),?\s*)~"
 
map< Symbol, regex > regexTable
 

Namespaces

 lib
 Implementation namespace for support and library code.
 

Function Documentation

◆ normaliseID()

void normaliseID ( string &  id)

ensure standard format for a given id string.

Trim, sanitise and ensure the first letter is lower case.

Note
modifies the given string ref in place

Definition at line 61 of file query-util.cpp.

References lib::query::normaliseID().

Referenced by QueryUtils_test::check_normaliseID(), and lib::query::normaliseID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extractID()

string extractID ( Symbol  sym,
const string &  termString 
)

(preliminary) helper: instead of really parsing and evaluating the terms, just do a regular expression match to extract the literal argument behind the given predicate symbol.

e.g calling extractID ("stream", "id(abc), stream(mpeg)") yields "mpeg"

Definition at line 101 of file query-util.cpp.

References lib::query::extractID().

Referenced by QueryUtils_test::check_extractID(), and lib::query::extractID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeTerm()

string removeTerm ( Symbol  sym,
string &  queryString 
)

(preliminary) helper: cut a term with the given symbol.

The term is matched, removed from the original string and returned

Note
parameter termString will be modified!
Todo:
as it seems we're not using the extracted term anymore, we could save the effort of rebuilding that term.

Definition at line 118 of file query-util.cpp.

References lib::query::removeTerm().

Referenced by QueryUtils_test::check_removeTerm(), and lib::query::removeTerm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countPred()

uint countPred ( const string &  q)

count the top-level predicates in the query string.

Note
this is a very hackish preliminary implementation. The regex used will flounder when applied to nested terms. We need a real parser for predicate logic terms (which we probably get for free when we embed a prolog system)...

usable for ordering queries, as more predicates usually mean more conditions, i.e. more constriction

Definition at line 146 of file query-util.cpp.

References lib::query::countPred().

Referenced by QueryUtils_test::check_countPred(), and lib::query::countPred().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendTerms()

string appendTerms ( string const &  pred1,
string const &  pred2 
)
Note
preliminary implementation without any syntax checks
Returns
a conjunction of the predicates

Definition at line 161 of file query-util.cpp.

References lib::query::appendTerms().

Referenced by lib::query::appendTerms().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: