QNLP  v1.0
QNLP::CorpusUtils Class Reference

#include <corpus_utils.hpp>

Collaboration diagram for QNLP::CorpusUtils:
Collaboration graph

Public Types

typedef std::unordered_map< std::string, std::unordered_map< std::string, unsigned int > > NTB
 
typedef std::unordered_map< std::string, std::unordered_map< unsigned int, std::string > > BTN
 

Public Member Functions

 CorpusUtils ()
 Construct a new Load Corpus object. Database name taken from the macro/compiler defined value. More...
 
 CorpusUtils (const std::string filename)
 Construct a new Load Corpus object. Database name given explicitly. More...
 
 ~CorpusUtils ()
 
NTBgetNameToBin ()
 Get the NTB object. This is a map of maps, wherein the first key represents the grammatical type to load. The second key accesses the name to binary string mapping data, wherein each unique entity has a mapping to a unique binary string, which will representation it's encoding in the quantum state-space. More...
 
BTNgetBinToName ()
 Get the BTN object. This is a map of maps, wherein the first key represents the grammatical type to load. The second key accesses binary mapping data, wherein each unique entity has a mapping to a unique string entity. This allows for determining a result upon measurement of the quantum state-space back to a specific meaning eneity. More...
 
void loadData (const std::string data_type, const std::string table="corpus")
 Loads from the database for a given data type (noun, verb, etc) More...
 
DBHelpergetDBHelper ()
 Return reference to database object. More...
 
void printData (const std::string type, const std::string table)
 Print the data with given type. More...
 
const std::string get_database_filename ()
 Get the database filename object. More...
 
void clearData ()
 Clear all loaded data. More...
 

Private Attributes

NTB name_to_bin
 
BTN bin_to_name
 
DBHelper db_helper
 
std::string database_filename
 

Detailed Description

Definition at line 19 of file corpus_utils.hpp.

Member Typedef Documentation

◆ BTN

typedef std::unordered_map<std::string, std::unordered_map<unsigned int, std::string> > QNLP::CorpusUtils::BTN

Definition at line 36 of file corpus_utils.hpp.

◆ NTB

typedef std::unordered_map<std::string, std::unordered_map<std::string, unsigned int> > QNLP::CorpusUtils::NTB

Definition at line 35 of file corpus_utils.hpp.

Constructor & Destructor Documentation

◆ CorpusUtils() [1/2]

CorpusUtils::CorpusUtils ( )

Construct a new Load Corpus object. Database name taken from the macro/compiler defined value.

Definition at line 15 of file corpus_utils.cpp.

15  :
#define QNLP_DB_FILE
std::string database_filename

◆ CorpusUtils() [2/2]

CorpusUtils::CorpusUtils ( const std::string  filename)

Construct a new Load Corpus object. Database name given explicitly.

Parameters
filenameDatabase filename

Definition at line 19 of file corpus_utils.cpp.

19  :
20  db_helper(filename), database_filename(filename) {}
std::string database_filename

◆ ~CorpusUtils()

CorpusUtils::~CorpusUtils ( )

Definition at line 22 of file corpus_utils.cpp.

22  {
24 }
void clearData()
Clear all loaded data.

References clearData().

Here is the call graph for this function:

Member Function Documentation

◆ clearData()

void CorpusUtils::clearData ( )

Clear all loaded data.

Definition at line 70 of file corpus_utils.cpp.

70  {
71  this->bin_to_name.clear();
72  this->name_to_bin.clear();
73 }

References bin_to_name, and name_to_bin.

Referenced by ~CorpusUtils().

Here is the caller graph for this function:

◆ get_database_filename()

const std::string CorpusUtils::get_database_filename ( )

Get the database filename object.

Returns
const std::string

Definition at line 66 of file corpus_utils.cpp.

66  {
67  return this->database_filename;
68 }
std::string database_filename

References database_filename.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ getBinToName()

CorpusUtils::BTN & CorpusUtils::getBinToName ( )

Get the BTN object. This is a map of maps, wherein the first key represents the grammatical type to load. The second key accesses binary mapping data, wherein each unique entity has a mapping to a unique string entity. This allows for determining a result upon measurement of the quantum state-space back to a specific meaning eneity.

Returns
BTN&

Definition at line 30 of file corpus_utils.cpp.

30  {
31  return this->bin_to_name;
32 }

References bin_to_name.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ getDBHelper()

DBHelper & CorpusUtils::getDBHelper ( )

Return reference to database object.

Returns
DB& reference to database object

Definition at line 75 of file corpus_utils.cpp.

75  {
76  return this->db_helper;
77 }

References db_helper.

Referenced by loadData(), and TEST_CASE().

Here is the caller graph for this function:

◆ getNameToBin()

CorpusUtils::NTB & CorpusUtils::getNameToBin ( )

Get the NTB object. This is a map of maps, wherein the first key represents the grammatical type to load. The second key accesses the name to binary string mapping data, wherein each unique entity has a mapping to a unique binary string, which will representation it's encoding in the quantum state-space.

Returns
NTB&

Definition at line 26 of file corpus_utils.cpp.

26  {
27  return this->name_to_bin;
28 }

References name_to_bin.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ loadData()

void CorpusUtils::loadData ( const std::string  data_type,
const std::string  table = "corpus" 
)

Loads from the database for a given data type (noun, verb, etc)

Parameters
data_typeString of the data type to load
tableDatabase table to load data from

Definition at line 34 of file corpus_utils.cpp.

34  {
35  int rc;
36  sqlite3_stmt *select_stmt = NULL;
38 
39  std::string query = "select name, bin_id from " + table + " where type=?";
40  SQL_RETURN_CHECK ( sqlite3_prepare_v2( getDBHelper().getDBRef(), query.c_str(), -1, &select_stmt, NULL ), SQLITE_OK );
41 
42  //Arg 2 is the 1-based index of the variable to replace
43  //Arg 4 is used to give the number of bytes, where -1 takes the length of string
44  //Arg 5 specifies the destructor type, where SQLITE_STATIC causes it to ignore.
45  SQL_RETURN_CHECK( sqlite3_bind_text( select_stmt, 1, data_type.c_str(), -1, SQLITE_STATIC ), SQLITE_OK );
46 
47  //Iterate through the rows of returned values
48  while ( (rc = sqlite3_step(select_stmt)) == SQLITE_ROW) {
49  std::string k( reinterpret_cast<const char*> ( sqlite3_column_text(select_stmt, 0) ) );
50  unsigned int v = (unsigned int) sqlite3_column_int(select_stmt, 1);
51  name_to_bin[data_type][k] = v;
52  bin_to_name[data_type][v] = k;
53  }
54  SQL_RETURN_CHECK( sqlite3_finalize(select_stmt), SQLITE_OK );
55 }
std::string database_filename
#define SQL_RETURN_CHECK(x, y)
Definition: db_helper.hpp:19
int openDB(const std::string filename)
Opens the requested database, and gives the return code of the operation. If the DB pointer has alrea...
Definition: db_helper.cpp:32
DBHelper & getDBHelper()
Return reference to database object.

References bin_to_name, database_filename, db_helper, getDBHelper(), name_to_bin, QNLP::DBHelper::openDB(), and SQL_RETURN_CHECK.

Referenced by printData(), and TEST_CASE().

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

◆ printData()

void CorpusUtils::printData ( const std::string  type,
const std::string  table = "corpus" 
)

Print the data with given type.

Parameters
typeGrammatical type
tableDatabase table to print data from

Definition at line 57 of file corpus_utils.cpp.

57  {
58  if(! this->name_to_bin.size()){
59  loadData(type, table);
60  }
61  for(auto& dat : this->name_to_bin[type]){
62  std::cout << dat.first << " : " << dat.second << std::endl;
63  }
64 }
void loadData(const std::string data_type, const std::string table="corpus")
Loads from the database for a given data type (noun, verb, etc)

References loadData(), and name_to_bin.

Here is the call graph for this function:

Field Documentation

◆ bin_to_name

BTN QNLP::CorpusUtils::bin_to_name
private

Definition at line 90 of file corpus_utils.hpp.

Referenced by clearData(), getBinToName(), and loadData().

◆ database_filename

std::string QNLP::CorpusUtils::database_filename
private

Definition at line 94 of file corpus_utils.hpp.

Referenced by get_database_filename(), and loadData().

◆ db_helper

DBHelper QNLP::CorpusUtils::db_helper
private

Definition at line 93 of file corpus_utils.hpp.

Referenced by getDBHelper(), and loadData().

◆ name_to_bin

NTB QNLP::CorpusUtils::name_to_bin
private

Definition at line 89 of file corpus_utils.hpp.

Referenced by clearData(), getNameToBin(), loadData(), and printData().


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