presage  0.8.7
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
DatabaseConnector Class Reference

#include <databaseConnector.h>

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

List of all members.

Public Member Functions

 DatabaseConnector ()
 DatabaseConnector (const std::string &log_level)
virtual ~DatabaseConnector ()
void createNgramTable (const int n) const
void createUnigramTable () const
void createBigramTable () const
void createTrigramTable () const
int getUnigramCountsSum () const
int getNgramCount (const Ngram ngram) const
NgramTable getNgramLikeTable (const Ngram ngram, int limit=-1) const
NgramTable getNgramLikeTableFiltered (const Ngram ngram, const char **filter, int limit=-1) const
int incrementNgramCount (const Ngram ngram) const
void insertNgram (const Ngram ngram, const int count) const
void updateNgram (const Ngram ngram, const int count) const
void removeNgram (const Ngram ngram) const
virtual void beginTransaction () const
virtual void endTransaction () const
virtual void rollbackTransaction () const

Protected Member Functions

virtual void openDatabase ()=0
virtual void closeDatabase ()=0
virtual NgramTable executeSql (const std::string query) const =0

Protected Attributes

Logger< char > logger

Private Member Functions

std::string buildSelectLikeClause (const int cardinality) const
std::string buildWhereClause (const Ngram ngram) const
std::string buildWhereLikeClause (const Ngram ngram) const
std::string buildWhereLikeClauseFiltered (const Ngram ngram, const char **filter) const
std::string buildValuesClause (const Ngram ngram, const int count) const
std::string sanitizeString (const std::string) const
int extractFirstInteger (const NgramTable &) const

Detailed Description

Provides the interface to database creation, updating and querying operations.

Definition at line 44 of file databaseConnector.h.


Constructor & Destructor Documentation

Definition at line 31 of file databaseConnector.cpp.

DatabaseConnector::DatabaseConnector ( const std::string &  log_level)

Definition at line 35 of file databaseConnector.cpp.

Definition at line 39 of file databaseConnector.cpp.


Member Function Documentation

void DatabaseConnector::beginTransaction ( ) const [virtual]

Marks the beginning of an SQL transaction.

Definition at line 315 of file databaseConnector.cpp.

References executeSql().

Referenced by SmoothedNgramPredictor::learn(), main(), and SmoothedNgramPredictor::predict().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string DatabaseConnector::buildSelectLikeClause ( const int  cardinality) const [private]

Returns a string containing the column specifiers for the SQL SELECT clause built for an ngram of specified cardinality.

Definition at line 248 of file databaseConnector.cpp.

Referenced by getNgramLikeTable(), and getNgramLikeTableFiltered().

Here is the caller graph for this function:

std::string DatabaseConnector::buildValuesClause ( const Ngram  ngram,
const int  count 
) const [private]

Returns a string containing an SQL VALUES clause built for the ngram.

Definition at line 264 of file databaseConnector.cpp.

References sanitizeString().

Referenced by insertNgram().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string DatabaseConnector::buildWhereClause ( const Ngram  ngram) const [private]

Returns a string containing an SQL WHERE clause built for the ngram.

Definition at line 186 of file databaseConnector.cpp.

References sanitizeString().

Referenced by getNgramCount(), and updateNgram().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string DatabaseConnector::buildWhereLikeClause ( const Ngram  ngram) const [private]

Returns a string containing an SQL WHERE clause built for the ngram, where the last comparison is a LIKE clauses instead of = clause.

Definition at line 203 of file databaseConnector.cpp.

References sanitizeString().

Referenced by getNgramLikeTable().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string DatabaseConnector::buildWhereLikeClauseFiltered ( const Ngram  ngram,
const char **  filter 
) const [private]

Same as buildWhereLikeClause but considers also a filter on the subsequent letter

Definition at line 218 of file databaseConnector.cpp.

References sanitizeString().

Referenced by getNgramLikeTableFiltered().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void DatabaseConnector::closeDatabase ( ) [protected, pure virtual]

Implemented in SqliteDatabaseConnector.

void DatabaseConnector::createBigramTable ( ) const [inline]

Definition at line 54 of file databaseConnector.h.

References createNgramTable().

Here is the call graph for this function:

void DatabaseConnector::createNgramTable ( const int  n) const

Creates a table to store N-grams.

Definition at line 42 of file databaseConnector.cpp.

References executeSql().

Referenced by createBigramTable(), createTrigramTable(), createUnigramTable(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

void DatabaseConnector::createTrigramTable ( ) const [inline]

Definition at line 55 of file databaseConnector.h.

References createNgramTable().

Here is the call graph for this function:

void DatabaseConnector::createUnigramTable ( ) const [inline]

Definition at line 53 of file databaseConnector.h.

References createNgramTable().

Here is the call graph for this function:

void DatabaseConnector::endTransaction ( ) const [virtual]

Marks the end of an SQL transaction.

Definition at line 320 of file databaseConnector.cpp.

References executeSql().

Referenced by SmoothedNgramPredictor::learn(), main(), and SmoothedNgramPredictor::predict().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual NgramTable DatabaseConnector::executeSql ( const std::string  query) const [protected, pure virtual]
int DatabaseConnector::extractFirstInteger ( const NgramTable table) const [private]

Returns the first element of the ngramtable as an integer.

Definition at line 288 of file databaseConnector.cpp.

References endl(), and logger.

Referenced by getNgramCount(), and getUnigramCountsSum().

Here is the call graph for this function:

Here is the caller graph for this function:

int DatabaseConnector::getNgramCount ( const Ngram  ngram) const

Returns an integer equal to the specified ngram count.

Definition at line 88 of file databaseConnector.cpp.

References buildWhereClause(), endl(), executeSql(), extractFirstInteger(), and logger.

Referenced by SmoothedNgramPredictor::count(), incrementNgramCount(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

NgramTable DatabaseConnector::getNgramLikeTable ( const Ngram  ngram,
int  limit = -1 
) const

Returns a table of ngrams matching the specified ngram-like query.

Definition at line 108 of file databaseConnector.cpp.

References buildSelectLikeClause(), buildWhereLikeClause(), and executeSql().

Referenced by SmoothedNgramPredictor::predict().

Here is the call graph for this function:

Here is the caller graph for this function:

NgramTable DatabaseConnector::getNgramLikeTableFiltered ( const Ngram  ngram,
const char **  filter,
int  limit = -1 
) const

Returns a table of ngrams matching the specified ngram-like query and satisfying the given filter.

Definition at line 124 of file databaseConnector.cpp.

References buildSelectLikeClause(), buildWhereLikeClauseFiltered(), and executeSql().

Referenced by SmoothedNgramPredictor::predict().

Here is the call graph for this function:

Here is the caller graph for this function:

Returns an integer equal to the sum of the counts of all unigrams.

Definition at line 71 of file databaseConnector.cpp.

References endl(), executeSql(), extractFirstInteger(), and logger.

Referenced by SmoothedNgramPredictor::count(), and SmoothedNgramPredictor::predict().

Here is the call graph for this function:

Here is the caller graph for this function:

int DatabaseConnector::incrementNgramCount ( const Ngram  ngram) const

Increments the specified ngram count and returns the updated count.

If the ngram does not yet exit in the database, it is created and its count is set to one.

Definition at line 140 of file databaseConnector.cpp.

References endl(), getNgramCount(), insertNgram(), logger, and updateNgram().

Referenced by SmoothedNgramPredictor::check_learn_consistency(), and SmoothedNgramPredictor::learn().

Here is the call graph for this function:

Here is the caller graph for this function:

void DatabaseConnector::insertNgram ( const Ngram  ngram,
const int  count 
) const

Insert ngram into database and sets its count.

Definition at line 164 of file databaseConnector.cpp.

References buildValuesClause(), and executeSql().

Referenced by incrementNgramCount(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void DatabaseConnector::openDatabase ( ) [protected, pure virtual]

Implemented in SqliteDatabaseConnector.

void DatabaseConnector::removeNgram ( const Ngram  ngram) const

Removes the ngram from the database

Definition at line 161 of file databaseConnector.cpp.

void DatabaseConnector::rollbackTransaction ( ) const [virtual]

Rolls back an SQL transaction.

Definition at line 325 of file databaseConnector.cpp.

References executeSql().

Referenced by SmoothedNgramPredictor::learn().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string DatabaseConnector::sanitizeString ( const std::string  str) const [private]

Sanitizes ngram, guards against SQL code injection.

Definition at line 278 of file databaseConnector.cpp.

Referenced by buildValuesClause(), buildWhereClause(), buildWhereLikeClause(), and buildWhereLikeClauseFiltered().

Here is the caller graph for this function:

void DatabaseConnector::updateNgram ( const Ngram  ngram,
const int  count 
) const

Updates ngram count.

Definition at line 175 of file databaseConnector.cpp.

References buildWhereClause(), and executeSql().

Referenced by incrementNgramCount(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Logger<char> DatabaseConnector::logger [protected]

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