ddc
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
CQueryCompiler Class Reference

#include <QueryCompiler.h>

Inheritance diagram for CQueryCompiler:
Inheritance graph
[legend]
Collaboration diagram for CQueryCompiler:
Collaboration graph
[legend]

Public Member Functions

 CQueryCompiler (const CConcHolder *pHolder=NULL)
 default constructor More...
 
virtual ~CQueryCompiler ()
 default destructor More...
 
void CleanParser ()
 
int yyqlex (void *valp)
 wrapper for yylex() as called from bison parser (valp is a YYSTYPE*) More...
 
string * newString (const string &s=string(""))
 wrapper to push a new string pointer onto the m_Labels stack (to be freed on CleanParser()) More...
 
string * newRegex (const string &pattern, const string &modifiers=string(""), bool isMatch=true)
 
const char * yytext () const
 flex convenience wrapper More...
 
int yyleng () const
 flex convenience wrapper More...
 
string yystring () const
 flex convenience wrapper More...
 
void yybegin (int new_state)
 wrapper for protected yyFlexLexer::yy_begin() More...
 
void DeleteTree ()
 delete parse tree (m_pQuery) if non-NULL; actually wipes all queries in m_Queries and m_qCountKeys More...
 
bool ParseQuery (const string &QueryStr)
 
bool CompileFilters ()
 
bool CheckSatisfiable (CQuery *query)
 
bool Compile (CQuery *query)
 
bool Evaluate (CQuery *query)
 
bool CheckSatisfiable ()
 
bool Compile ()
 
bool Evaluate ()
 evaluate parse tree bottom-up; wrapper for Evaluate(m_pQuery) More...
 
int GetNewNodeIndex ()
 return current node index to set CQueryTokenNode::m_NodeIndex More...
 
size_t GetNodeIndicesCount () const
 return m_CurrentNodeIndex More...
 
CQuerySetQuery (CQuery *qp)
 
CQueryPushQuery (CQuery *qp)
 
CQCountPushCountQuery (CQuery *qConditions)
 
CQKeysPushKeysQuery (CQCount *qCount)
 
CQFPrunenewPruneFilter (HitSortEnum ftype, const string &limitStr="-1")
 
void SetFilterBounds (const string &lb="", const string &ub="")
 set string bounds for current filter (called by bison parser) More...
 
void SetFilterKey (const string &field="", BYTE matchid=0, int offset=INT_MIN)
 set context-filter key More...
 
string QueryToString (void)
 debug: return a string form for the current query; wraps m_pQuery->toString() + m_pQuery->optionsToString() More...
 
string QueryToJson (void)
 return a json string form for the current query; wraps m_pQuery->toJson() + m_pQuery->optionsToJson() More...
 
void barf (const std::string &msg) const
 error reporting: throws a errParseError exception More...
 
void barf (const char *fmt,...) const
 error reporting: throws a errParseError exception with a printf() format More...
 
void yybarf (const char *yymsg) const
 
virtual ddcObjectList Children () const
 
virtual void DisownChildren ()
 
virtual string jsonClass ()
 
virtual string jsonData ()
 
- Public Member Functions inherited from ddcObject
 ddcObject ()
 Default constructor. More...
 
virtual ~ddcObject ()
 virtual destructor does nothing More...
 
template<typename Visit >
ddcObjectTraverse (Visit &visit)
 
template<typename Visit >
ddcObjectTraverse (Visit &visit) const
 
template<typename Visit >
ddcObjectTraverseR (Visit &visit)
 
template<typename Visit >
ddcObjectTraverseR (Visit &visit) const
 
virtual ddcObjectList Descendants () const
 
virtual string toString ()
 
virtual string toJson ()
 

Public Attributes

const CConcHolderm_pHolder
 a reference to the holder, for which this query is parsed More...
 
CQuerym_pQuery
 root of the abstract parse tree More...
 
CQueryOptions m_qOptions
 query options (adopted into top-level m_pQuery on SetQuery()) More...
 
size_t m_Limit
 query limit (anything but 0 (default) overrides CConcHolder arguments) More...
 
bool m_bSatisfiable
 is query satisfiable? (default is true, may be set to false by CheckSatisfiable()) More...
 
CQCountKeyExprList m_qCountKeys
 count()-query keys More...
 
size_t m_qCountSample
 count()-query sample size (overrides count-query m_dtr->m_Options->m_Limit if set) More...
 
size_t m_qCountLimit
 count()-query result-set size (for keys()-queries) More...
 
HitSortEnum m_qCountSort
 count()-query sort order More...
 
string m_qCountLo
 count()-query lower bound More...
 
string m_qCountHi
 count()-query upper bound More...
 
vector< string > m_IndexTuple
 keys()-query tuple More...
 
set< string > m_WordSet
 temporary for $i={w1,w2,...,wN} word-set queries More...
 
vector< string > m_Expanders
 temporary for "% X1 % X2 ..." expansion queries More...
 
vector< string > m_MorphItems
 temporary for [m1,m2,...,mN] morph-pattern queries More...
 
string m_FilterField
 temporary for filter field (#less_by_xyz, #greater_by_xyz) More...
 
string m_FilterLB
 temporary for filter lower bound (#less_by_xyz, #greater_by_xyz) More...
 
string m_FilterUB
 temporary for filter upper bound (#less_by_xyz, #greater_by_xyz) More...
 
BYTE m_FilterMatchId
 temporary for filter reference match-id (#left, #right, #mid; default=0:any) More...
 
int m_FilterOffset
 temporary for filter offsets (#left, #right, #mid; default=0:any) More...
 
string m_RegexPattern
 temporary for regex patterns More...
 
string m_RegexReplacement
 temporary for regex replacement strings (used by count-keys) More...
 
string m_RegexModifiers
 temporary for regex modifiers More...
 
int m_CurrentNodeIndex
 current node index to set CQueryTokenNode::m_NodeIndex More...
 
vector< CQuery * > m_Queries
 set of all query nodes allocated during current parse More...
 
list< string > m_Labels
 a special slot for YACC (which contains all string leaves of the parse tree) More...
 
bool m_KeepLexerComments
 enable collection of lexer comments in m_pQuery->m_Options->m_LexerComments (default=false) More...
 
- Public Attributes inherited from ddcObject
void * m_User
 user data associated with this object (for use e.g. by perl wrappers) More...
 

Static Public Attributes

static const size_t m_MaxContextSentencesCount = 5
 maximum context size for #cntxt operator More...
 

Detailed Description

CQueryCompiler is a class for the parse tree of the input query and its general properties.

Descended from FlexLexer (abstract class of flex tool), so it should implement also flex parser's functionality (DDC uses YACC in thread-safe mode).

moo: renamed CQueryParser to CQueryCompiler to reflect actual functionality.

Constructor & Destructor Documentation

◆ CQueryCompiler()

CQueryCompiler::CQueryCompiler ( const CConcHolder pHolder = NULL)

◆ ~CQueryCompiler()

CQueryCompiler::~CQueryCompiler ( )
virtual

default destructor

References CleanParser().

Here is the call graph for this function:

Member Function Documentation

◆ CleanParser()

void CQueryCompiler::CleanParser ( )

◆ yyqlex()

int CQueryCompiler::yyqlex ( void *  valp)

wrapper for yylex() as called from bison parser (valp is a YYSTYPE*)

References BLOCK_COMMENT, DATE, DDC_STATIC_BUFLEN, errParseError, EXPANDER, INDEX, INFIX, INTEGER, KW_DATE, KW_FILEID, KW_FILENAME, LINE_COMMENT, m_KeepLexerComments, CQueryOptions::m_LexerComments, m_qOptions, m_RegexModifiers, m_RegexPattern, m_RegexReplacement, NEG_REGEX, newString(), PREFIX, REGEX, REGEX_REPLACE, REGEX_SEARCH, REGOPT, SUFFIX, SYMBOL, yyleng(), yylex, and yytext().

Referenced by yyqlex().

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

◆ newString()

string * CQueryCompiler::newString ( const string &  s = string(""))

wrapper to push a new string pointer onto the m_Labels stack (to be freed on CleanParser())

References m_Labels.

Referenced by newRegex(), and yyqlex().

Here is the caller graph for this function:

◆ newRegex()

string * CQueryCompiler::newRegex ( const string &  pattern,
const string &  modifiers = string(""),
bool  isMatch = true 
)

wrapper for regexes, similar to "(?" + modifers + ":" + pattern + ")"

Parameters
isMatchif true (default), /g modifier will cause regex to be wrapped in '^' and '$' anchors (match whole string)

References newString().

Here is the call graph for this function:

◆ yytext()

const char* CQueryCompiler::yytext ( ) const
inline

flex convenience wrapper

Referenced by yyqlex().

Here is the caller graph for this function:

◆ yyleng()

int CQueryCompiler::yyleng ( ) const
inline

flex convenience wrapper

Referenced by yyqlex().

Here is the caller graph for this function:

◆ yystring()

string CQueryCompiler::yystring ( ) const
inline

flex convenience wrapper

References CheckSatisfiable(), Compile(), CompileFilters(), DeleteTree(), Evaluate(), ParseQuery(), and yybegin().

Here is the call graph for this function:

◆ yybegin()

void CQueryCompiler::yybegin ( int  new_state)

wrapper for protected yyFlexLexer::yy_begin()

Referenced by ParseQuery(), and yystring().

Here is the caller graph for this function:

◆ DeleteTree()

void CQueryCompiler::DeleteTree ( )

delete parse tree (m_pQuery) if non-NULL; actually wipes all queries in m_Queries and m_qCountKeys

References CQCountKeyExprList::Clear(), DDCDefaultCountSampleSize, m_Limit, m_pQuery, m_qCountHi, m_qCountKeys, m_qCountLimit, m_qCountLo, m_qCountSample, m_qCountSort, m_Queries, and NoSort.

Referenced by CleanParser(), and yystring().

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

◆ ParseQuery()

bool CQueryCompiler::ParseQuery ( const string &  QueryStr)

parse QueryStr and build a parse tree for it in m_pQuery

  • moo: this method should be safe to call even if (m_pHolder==NULL).
    Returns
    false on failure (and may throw an exception)

References CleanParser(), m_pQuery, QueryToString(), yybegin(), yyqdebug, and yyqparse().

Referenced by CRunQueryData::Init(), and yystring().

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

◆ CompileFilters()

bool CQueryCompiler::CompileFilters ( )

moo: compile and apply filters in m_pQuery->m_Options->m_QFilters OBSOLETE : now just a wrapper for m_pQuery->CompileOptions(this)

References CQuery::CompileOptions(), and m_pQuery.

Referenced by yystring().

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

◆ CheckSatisfiable() [1/2]

bool CQueryCompiler::CheckSatisfiable ( CQuery query)

moo: check the current parsed query (m_pQuery) for unsatisfiability with respect to the current index (m_pHolder) and compiler options (m_HitTypeStr etc.)

  • sets m_bSatisfiable to false if any trivially unsatisfiable global constraints (e.g subcorpus match, etc) are found
  • call this and act on its return value (if at all) before calling Compile()
  • really just a wrapper for m_pQuery->CheckSatisfiable(this)
    Returns
    new value of m_bSatisfiable

References CQuery::CheckSatisfiable(), and m_bSatisfiable.

Here is the call graph for this function:

◆ Compile() [1/2]

bool CQueryCompiler::Compile ( CQuery query)

moo: compile the given query (query) with respect to the current index (m_pHolder) and compiler options (m_HitTypeStr etc.)

  • really just a wrapper for query->CompileOptions(this) && query->Compile(this)
    Returns
    false on failure (and may throw an exception)

References CQuery::Compile(), CQuery::CompileOptions(), errParseError, CQuery::RootOK(), and CQuery::toString().

Here is the call graph for this function:

◆ Evaluate() [1/2]

bool CQueryCompiler::Evaluate ( CQuery query)

evaluate parse tree bottom-up

  • query defaults to m_pQuery

References Compile(), CQuery::Evaluate(), and CQuery::m_Compiler.

Here is the call graph for this function:

◆ CheckSatisfiable() [2/2]

bool CQueryCompiler::CheckSatisfiable ( )
inline

wrapper for CheckSatisfiable(m_pQuery)

Returns
false on failure (and may throw an exception)

Referenced by yystring().

Here is the caller graph for this function:

◆ Compile() [2/2]

bool CQueryCompiler::Compile ( )
inline

wrapper for Compile(m_pQuery)

Returns
false on failure (and may throw an exception)

Referenced by Evaluate(), and yystring().

Here is the caller graph for this function:

◆ Evaluate() [2/2]

bool CQueryCompiler::Evaluate ( )
inline

evaluate parse tree bottom-up; wrapper for Evaluate(m_pQuery)

References GetNewNodeIndex(), GetNodeIndicesCount(), and SetQuery().

Referenced by yystring().

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

◆ GetNewNodeIndex()

int CQueryCompiler::GetNewNodeIndex ( )

return current node index to set CQueryTokenNode::m_NodeIndex

References m_CurrentNodeIndex.

Referenced by CQToken::Compile(), and Evaluate().

Here is the caller graph for this function:

◆ GetNodeIndicesCount()

size_t CQueryCompiler::GetNodeIndicesCount ( ) const

return m_CurrentNodeIndex

References m_CurrentNodeIndex.

Referenced by Evaluate().

Here is the caller graph for this function:

◆ SetQuery()

CQuery * CQueryCompiler::SetQuery ( CQuery qp)

set current top-level query, adopting filters and flags; sets this->m_pQuery=qp Called by bison during the parse.

References CQueryOptions::Clear(), m_pQuery, m_qOptions, CQuery::SetOptions(), and CQueryOptions::swap().

Referenced by Evaluate(), and PushCountQuery().

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

◆ PushQuery()

CQuery* CQueryCompiler::PushQuery ( CQuery qp)
inline

push a newly allocated CQuery* onto the stack. Called by bison during the parse.

References barf(), Children(), DisownChildren(), newPruneFilter(), PushCountQuery(), PushKeysQuery(), QueryToJson(), QueryToString(), SetFilterBounds(), SetFilterKey(), and yybarf().

Referenced by PushCountQuery(), and PushKeysQuery().

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

◆ PushCountQuery()

CQCount * CQueryCompiler::PushCountQuery ( CQuery qConditions)

push a newly allocated CQCount* count-query onto the stack, setting m_CountBy Called by bison during the parse.

References DDCDefaultCountSampleSize, CQCountKeyExprList::m_Exprs, m_qCountHi, m_qCountKeys, m_qCountLo, m_qCountSample, m_qCountSort, NoSort, PushQuery(), and SetQuery().

Referenced by PushQuery().

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

◆ PushKeysQuery()

CQKeys * CQueryCompiler::PushKeysQuery ( CQCount qCount)

push a newly allocated CQKeys* query onto the stack. called by bison during the parse.

References m_IndexTuple, m_Limit, m_qCountLimit, and PushQuery().

Referenced by PushQuery().

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

◆ newPruneFilter()

CQFPrune * CQueryCompiler::newPruneFilter ( HitSortEnum  ftype,
const string &  limitStr = "-1" 
)

allocated CQFPrune* filter onto Called by bison during the parse.

References CQCountKeyExprList::m_Exprs, and m_qCountKeys.

Referenced by PushQuery().

Here is the caller graph for this function:

◆ SetFilterBounds()

void CQueryCompiler::SetFilterBounds ( const string &  lb = "",
const string &  ub = "" 
)

set string bounds for current filter (called by bison parser)

References m_FilterLB, and m_FilterUB.

Referenced by PushQuery(), and SetFilterKey().

Here is the caller graph for this function:

◆ SetFilterKey()

void CQueryCompiler::SetFilterKey ( const string &  field = "",
BYTE  matchid = 0,
int  offset = INT_MIN 
)

set context-filter key

References m_FilterField, m_FilterMatchId, m_FilterOffset, and SetFilterBounds().

Referenced by PushQuery().

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

◆ QueryToString()

string CQueryCompiler::QueryToString ( void  )

debug: return a string form for the current query; wraps m_pQuery->toString() + m_pQuery->optionsToString()

References m_pQuery, CQuery::optionsToString(), and CQuery::toString().

Referenced by ParseQuery(), and PushQuery().

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

◆ QueryToJson()

string CQueryCompiler::QueryToJson ( void  )

return a json string form for the current query; wraps m_pQuery->toJson() + m_pQuery->optionsToJson()

References m_pQuery, CQuery::optionsToJson(), and CQuery::toJson().

Referenced by PushQuery().

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

◆ barf() [1/2]

void CQueryCompiler::barf ( const std::string &  msg) const

error reporting: throws a errParseError exception

References errParseError.

Referenced by PushQuery(), and yybarf().

Here is the caller graph for this function:

◆ barf() [2/2]

void CQueryCompiler::barf ( const char *  fmt,
  ... 
) const

error reporting: throws a errParseError exception with a printf() format

References BARFSIZE, and errParseError.

◆ yybarf()

void CQueryCompiler::yybarf ( const char *  yymsg) const

error reporting: throw a verbose errParseError exception using current lexer+parser context

  • this is called by underlying bison parser's yyerror() routine

References barf().

Referenced by PushQuery().

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

◆ Children()

ddcObjectList CQueryCompiler::Children ( ) const
virtual

get a list of direct ddcObject daughters of this node

  • default just returns an empty list
  • useful for external wrappers (e.g. perl reference-counting)

Reimplemented from ddcObject.

References m_pQuery.

Referenced by PushQuery().

Here is the caller graph for this function:

◆ DisownChildren()

void CQueryCompiler::DisownChildren ( )
virtual

"disown" any direct child objects, preventing their destruction if the current object is deleted

  • default implementation does nothing

Reimplemented from ddcObject.

References m_pQuery, and m_Queries.

Referenced by PushQuery().

Here is the caller graph for this function:

◆ jsonClass()

virtual string CQueryCompiler::jsonClass ( void  )
inlinevirtual

class-name for json strinfication

  • default implementation returns C++ class name

Reimplemented from ddcObject.

◆ jsonData()

virtual string CQueryCompiler::jsonData ( void  )
inlinevirtual

instance data for json stringification

  • default implementation returns "NODATA":1, for strict syntax compliance

Reimplemented from ddcObject.

References jsonStr().

Here is the call graph for this function:

Member Data Documentation

◆ m_MaxContextSentencesCount

const size_t CQueryCompiler::m_MaxContextSentencesCount = 5
static

maximum context size for #cntxt operator

Referenced by CQueryOptions::Compile().

◆ m_pHolder

const CConcHolder* CQueryCompiler::m_pHolder

◆ m_pQuery

CQuery* CQueryCompiler::m_pQuery

◆ m_qOptions

CQueryOptions CQueryCompiler::m_qOptions

query options (adopted into top-level m_pQuery on SetQuery())

Referenced by CleanParser(), SetQuery(), and yyqlex().

◆ m_Limit

size_t CQueryCompiler::m_Limit

query limit (anything but 0 (default) overrides CConcHolder arguments)

Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushKeysQuery().

◆ m_bSatisfiable

bool CQueryCompiler::m_bSatisfiable

◆ m_qCountKeys

CQCountKeyExprList CQueryCompiler::m_qCountKeys

count()-query keys

Referenced by CleanParser(), DeleteTree(), newPruneFilter(), and PushCountQuery().

◆ m_qCountSample

size_t CQueryCompiler::m_qCountSample

count()-query sample size (overrides count-query m_dtr->m_Options->m_Limit if set)

Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushCountQuery().

◆ m_qCountLimit

size_t CQueryCompiler::m_qCountLimit

count()-query result-set size (for keys()-queries)

Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushKeysQuery().

◆ m_qCountSort

HitSortEnum CQueryCompiler::m_qCountSort

count()-query sort order

Referenced by CleanParser(), CQueryCompiler(), DeleteTree(), and PushCountQuery().

◆ m_qCountLo

string CQueryCompiler::m_qCountLo

count()-query lower bound

Referenced by CleanParser(), DeleteTree(), and PushCountQuery().

◆ m_qCountHi

string CQueryCompiler::m_qCountHi

count()-query upper bound

Referenced by CleanParser(), DeleteTree(), and PushCountQuery().

◆ m_IndexTuple

vector<string> CQueryCompiler::m_IndexTuple

keys()-query tuple

Referenced by CleanParser(), and PushKeysQuery().

◆ m_WordSet

set<string> CQueryCompiler::m_WordSet

temporary for $i={w1,w2,...,wN} word-set queries

Referenced by CleanParser().

◆ m_Expanders

vector<string> CQueryCompiler::m_Expanders

temporary for "% X1 % X2 ..." expansion queries

Referenced by CleanParser().

◆ m_MorphItems

vector<string> CQueryCompiler::m_MorphItems

temporary for [m1,m2,...,mN] morph-pattern queries

Referenced by CleanParser().

◆ m_FilterField

string CQueryCompiler::m_FilterField

temporary for filter field (#less_by_xyz, #greater_by_xyz)

Referenced by CleanParser(), and SetFilterKey().

◆ m_FilterLB

string CQueryCompiler::m_FilterLB

temporary for filter lower bound (#less_by_xyz, #greater_by_xyz)

Referenced by CleanParser(), and SetFilterBounds().

◆ m_FilterUB

string CQueryCompiler::m_FilterUB

temporary for filter upper bound (#less_by_xyz, #greater_by_xyz)

Referenced by CleanParser(), and SetFilterBounds().

◆ m_FilterMatchId

BYTE CQueryCompiler::m_FilterMatchId

temporary for filter reference match-id (#left, #right, #mid; default=0:any)

Referenced by CleanParser(), and SetFilterKey().

◆ m_FilterOffset

int CQueryCompiler::m_FilterOffset

temporary for filter offsets (#left, #right, #mid; default=0:any)

Referenced by CleanParser(), and SetFilterKey().

◆ m_RegexPattern

string CQueryCompiler::m_RegexPattern

temporary for regex patterns

Referenced by CleanParser(), and yyqlex().

◆ m_RegexReplacement

string CQueryCompiler::m_RegexReplacement

temporary for regex replacement strings (used by count-keys)

Referenced by CleanParser(), and yyqlex().

◆ m_RegexModifiers

string CQueryCompiler::m_RegexModifiers

temporary for regex modifiers

Referenced by CleanParser(), and yyqlex().

◆ m_CurrentNodeIndex

int CQueryCompiler::m_CurrentNodeIndex

◆ m_Queries

vector<CQuery*> CQueryCompiler::m_Queries

set of all query nodes allocated during current parse

Referenced by DeleteTree(), and DisownChildren().

◆ m_Labels

list<string> CQueryCompiler::m_Labels

a special slot for YACC (which contains all string leaves of the parse tree)

Referenced by CleanParser(), and newString().

◆ m_KeepLexerComments

bool CQueryCompiler::m_KeepLexerComments

enable collection of lexer comments in m_pQuery->m_Options->m_LexerComments (default=false)

Referenced by CQueryCompiler(), and yyqlex().


The documentation for this class was generated from the following files: