using namespace std;
-CommandFinder::CommandFinder(std::string text, std::list<std::shared_ptr<ClickableItem>>& commands) :
+CommandFinder::CommandFinder(std::string &text, std::list<std::shared_ptr<ClickableItem>>& commands) :
__WORD_MATCHING_RATE(0.3), __CHAR_MATCHING_RATE(0.25), __MIN_WORD_SIZE(3), __commands(commands)
{
_I("[CommandFinder] Initiate command searcher. text(%s)", text.c_str());
{
ClickableItem* result = nullptr;
if (__isLabel) {
- _I("[CommandFinder] Finde command by label text. text(%s)", __loweredText.c_str());
+ _I("[CommandFinder] Find command by label text. text(%s)", __loweredText.c_str());
result = findCommandByText();
if (result != nullptr) {
return result;
return result;
}
} else {
- _I("[CommandFinder] Finde command by index. index(%d)", __index);
+ _I("[CommandFinder] Find command by index. index(%d)", __index);
result = findCommandByIndex();
}
for (auto command : __commands) {
if (command->index == __index) {
+ _I("[CommandFinder] result command(%s)", command->label.c_str());
return command.get();
}
}
}
if (isValid) {
+ _I("[CommandFinder] result command(%s)", command->label.c_str());
return command.get();
}
}
ClickableItem* CommandFinder::findCommandByWord()
{
_I("[CommandFinder] Find command by word");
-
int maxNumber = __splitText.size() * __WORD_MATCHING_RATE;
ClickableItem* result = nullptr;
+ _I("[CommandFinder] Minimum matching word number (%d)", maxNumber);
for (auto command : __commands) {
string label = StringUtil::makeLowerCase(command->label);
}
}
+ if (result != nullptr) {
+ _I("[CommandFinder] result command(%s)", result->label.c_str());
+ }
+
return result;
}
ClickableItem* CommandFinder::findCommandByChar()
{
- _I("[CommandFinder] Find command by word");
+ _I("[CommandFinder] Find command by char");
ClickableItem* result = nullptr;
int resultScore = numeric_limits<int>::max();
for (auto command : __commands) {
string label = StringUtil::makeLowerCase(command->label);
vector<string> splitLabel = StringUtil::splitText(label, ' ');
+ _D("[CommandFinder] Command(%s), candidate(%s)", __loweredText.c_str(), label.c_str());
int score = 0;
for (auto& word : __splitText) {
// This is for calculating Levenshtein distance as similarity matric.
const int __MIN_THRESHOLD = word.size() * __CHAR_MATCHING_RATE;
- int minScore = __MIN_THRESHOLD;
+ int minScore = __MIN_THRESHOLD + 1;
+ _D("[CommandFinder] Minimum matching character number (%d)", __MIN_THRESHOLD);
for (auto& labelWord : splitLabel) {
if (labelWord.size() < __MIN_WORD_SIZE) {
continue;
int longSize = longString.size();
int shortSize = shortString.size();
- int* cost = new int[longSize] {0, };
- int* ncost = new int[longSize] {0, };
+ int* cost = new int[longSize + 1] {0, };
+ int* ncost = new int[longSize + 1] {0, };
for (int l = 0; l <= longSize; l++) {
cost[l] = l;
}
- score += (minScore < __MIN_THRESHOLD ? minScore : word.size());
+ _D("[CommandFinder] word(%s), labelword(%s), minscore(%d)", word.c_str(), label.c_str(), minScore);
+ score += (minScore <= __MIN_THRESHOLD ? minScore : word.size());
}
+ _D("[CommandFinder] result score(%d), score(%d)", resultScore, score);
if (resultScore > score) {
resultScore = score;
result = command.get();
}
if (threshold > resultScore) {
+ _I("[CommandFinder] result command(%s)", result->label.c_str());
return result;
}
using namespace std;
-void CommandManager::addCommand(ClickableItem item)
+void CommandManager::addCommand(ClickableItem &item)
{
try {
shared_ptr<ClickableItem> command = make_shared<ClickableItem>(item);
__commands.clear();
}
-ClickableItem* CommandManager::findCommand(std::string text, bool isIndex)
+ClickableItem* CommandManager::findCommand(std::string &text, bool isIndex)
{
int index = -1;
try {
_E("[CommandManager] Fail to convert. exception(%s)", e.what());
}
- if (isIndex) {
+ if (isIndex && index < 0) {
+ _E("[CommandManager] Index is not valid(%s)", text.c_str());
return nullptr;
}
}
auto command = finder->findCommand();
- _I("[CommandManager] Find command. text(%s). command(%s)", text.c_str(), command->label.c_str());
+ if (command != nullptr) {
+ _I("[CommandManager] Find command. text(%s). command(%s)", text.c_str(), command->label.c_str());
+ } else {
+ _E("[CommandManager] Fail to Find command. text(%s)", text.c_str());
+ }
return command;
}