22#include "../ui/error.hpp"
23#include "../utils/tools.hpp"
40 vector<string> vDBEntries;
46 fDB.open(sFile.c_str());
62 vDBEntries.push_back(sLine);
84 m_dataBase = vector<vector<string>>(vDBEntries.size(), vector<string>());
87 for (
unsigned int i = 0; i < vDBEntries.size(); i++)
90 if (vDBEntries[i].
find(
'~') == string::npos)
95 while (vDBEntries[i].
find(
'~') != string::npos)
98 if (vDBEntries[i].substr(0, vDBEntries[i].
find(
'~')).size())
99 m_dataBase[i].push_back(vDBEntries[i].substr(0, vDBEntries[i].
find(
'~')));
102 vDBEntries[i].erase(0, vDBEntries[i].
find(
'~') + 1);
106 if (vDBEntries[i].
size())
126 for (
size_t i = 0; i <
m_dataBase.size(); i++)
193 m_dataBase = vector<vector<string>>(vDataColumn.size(), vector<string>(1,
""));
195 for (
size_t i = 0; i < vDataColumn.size(); i++)
227 for (
size_t i = 0; i < data.
size(); i++)
267 vector<string> vColumn(
m_dataBase.size(),
"");
271 for (
size_t i = 0; i <
m_dataBase.size(); i++)
323 size_t nthRecord = (rand() %
m_dataBase.size());
343 for (
size_t i = 0; i <
m_dataBase.size(); i++)
368 map<size_t,vector<size_t>>
DataBase::find(
const string& _sSearchString,
bool findOnlyFirst)
const
370 map<size_t,vector<size_t>> mMatches;
375 if (lower.length() && lower !=
" ")
378 for (
size_t i = 0; i <
m_dataBase.size(); i++)
380 for (
size_t j = 0; j <
m_dataBase[i].size(); j++)
385 mMatches[i].push_back(j);
415 vector<string> vKeyWords;
416 string sTemp = _sSearchString;
417 map<double,vector<size_t>> mRelevance;
418 static std::string sIGNOREWORDS =
" " +
_lang.
get(
"COMMON_SEARCH_IGNOREWORDS") +
" ";
420 if (sTemp.back() !=
' ')
426 std::string sKeyWord = sTemp.substr(0, sTemp.find(
" "));
427 sTemp.erase(0, sTemp.find(
" ")+1);
431 if (sIGNOREWORDS.find(
" " + sKeyWord +
" ") == std::string::npos
432 || (!vKeyWords.size() && !sTemp.length()))
433 vKeyWords.push_back(sKeyWord);
435 while (sTemp.length());
439 map<size_t,vector<size_t>> mMatches =
find(vKeyWords.front());
443 for (
size_t i = 1; i < vKeyWords.size(); i++)
445 map<size_t,vector<size_t>> mCurMatches =
find(vKeyWords[i]);
447 for (
auto iter = mCurMatches.begin(); iter != mCurMatches.end(); ++iter)
451 mMatches[iter->first].insert(mMatches[iter->first].end(), iter->second.begin(), iter->second.end());
457 if (!vWeighting.size())
458 vWeighting.assign(
getCols(), 1.0);
459 else if (vWeighting.size() <
getCols())
460 vWeighting.insert(vWeighting.end(),
getCols()-vWeighting.size(), 0.0);
464 for (
auto iter = mMatches.begin(); iter != mMatches.end(); ++iter)
468 for (
size_t i = 0; i < iter->second.size(); i++)
470 weight += vWeighting[iter->second[i]];
473 mRelevance[weight].push_back(iter->first);
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
This class implements the basic input/ output file system and provides functionalities to work with f...
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class is an implementation of a database. It will handle the *.ndb data format an provides an in...
std::vector< std::string > getDBFileContent()
This member function reads the contents of a database file linewise to a vector.
std::map< double, std::vector< size_t > > findRecordsUsingRelevance(const std::string &_sSearchString, std::vector< double > vWeighting=std::vector< double >()) const
This member function will search multiple search strings in the database and returns a map,...
std::map< size_t, std::vector< size_t > > find(const std::string &_sSearchString, bool findOnlyFirst=false) const
This member function can be used to search a string in the managed database. The return value is a ma...
std::vector< std::string > & operator[](size_t i)
This is an overload of the array access operator, which can be used with read and write permissions....
std::string getElement(size_t i, size_t j) const
This member function will return the contents of the selected database field, or an empty string,...
size_t findOrCreateRecord(const std::string &sRecord)
This member function will return the id of the searched record (value in the first column of the matr...
void readDataBase()
This function opens up a NumeRe Data base file and reads its contents to the internal vector<vector> ...
size_t findRecord(const std::string &_sRecord) const
This member function finds a selected record in the first column of the database table and returns it...
std::vector< std::vector< std::string > > m_dataBase
size_t randomRecord() const
This member function can be used to select and random record.
std::vector< std::string > getColumn(size_t j) const
This member function will return the whole selected column of the database as a vector<string>....
std::string m_dataBaseFile
DataBase & operator=(const DataBase &data)
This is an overload of the assignment operator.
DataBase()
The default constructor will initialize the FileSystem base class using the information from the kern...
void addData(const std::string &sDataBaseFile)
This member function will use the passed database file name to update its internal contents (i....
Common exception class for all exceptions thrown in NumeRe.
static size_t invalid_position
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.