-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core-clp): get_entry_matching_value should handle ignore-case properly. #690
base: main
Are you sure you want to change the base?
Changes from all commits
327c317
b4fdba2
8a515f8
aaac6a0
aecae49
8824757
df673c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,9 +82,9 @@ class DictionaryReader { | |||||
* Gets the entry exactly matching the given search string | ||||||
* @param search_string | ||||||
* @param ignore_case | ||||||
* @return nullptr if an exact match is not found, the entry otherwise | ||||||
* @return a (possibly empty) vector of entries | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kirkrodrigues how about
Suggested change
|
||||||
*/ | ||||||
EntryType const* | ||||||
std::vector<EntryType const*> | ||||||
get_entry_matching_value(std::string const& search_string, bool ignore_case) const; | ||||||
/** | ||||||
* Gets the entries that match a given wildcard string | ||||||
|
@@ -233,26 +233,30 @@ std::string const& DictionaryReader<DictionaryIdType, EntryType>::get_value(Dict | |||||
} | ||||||
|
||||||
template <typename DictionaryIdType, typename EntryType> | ||||||
EntryType const* DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value( | ||||||
std::vector<EntryType const*> | ||||||
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value( | ||||||
std::string const& search_string, | ||||||
bool ignore_case | ||||||
) const { | ||||||
std::vector<EntryType const*> entries; | ||||||
if (false == ignore_case) { | ||||||
for (auto const& entry : m_entries) { | ||||||
if (entry.get_value() == search_string) { | ||||||
return &entry; | ||||||
entries.push_back(&entry); | ||||||
aestriplex marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// early exit for case sensitive branch | ||||||
return entries; | ||||||
} | ||||||
} | ||||||
} else { | ||||||
auto const& search_string_uppercase = boost::algorithm::to_upper_copy(search_string); | ||||||
for (auto const& entry : m_entries) { | ||||||
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) { | ||||||
return &entry; | ||||||
entries.push_back(&entry); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return nullptr; | ||||||
return entries; | ||||||
} | ||||||
|
||||||
template <typename DictionaryIdType, typename EntryType> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -386,15 +386,30 @@ bool EncodedVariableInterpreter::encode_and_search_dictionary( | |
LogTypeDictionaryEntry::add_float_var(logtype); | ||
sub_query.add_non_dict_var(encoded_var); | ||
} else { | ||
auto entry = var_dict.get_entry_matching_value(var_str, ignore_case); | ||
if (nullptr == entry) { | ||
auto const entries = var_dict.get_entry_matching_value(var_str, ignore_case); | ||
if (entries.empty()) { | ||
// Not in dictionary | ||
return false; | ||
} | ||
encoded_var = encode_var_dict_id(entry->get_id()); | ||
|
||
LogTypeDictionaryEntry::add_dict_var(logtype); | ||
sub_query.add_dict_var(encoded_var, entry); | ||
|
||
if (entries.size() == 1) { | ||
auto const* entry = entries.at(0); | ||
encoded_var = encode_var_dict_id(entry->get_id()); | ||
sub_query.add_dict_var(encoded_var, entry); | ||
return true; | ||
} | ||
|
||
std::unordered_set<encoded_variable_t> encoded_vars; | ||
std::unordered_set<clp::VariableDictionaryEntry const*> const entries_set( | ||
entries.begin(), | ||
entries.end() | ||
); | ||
for (auto const entry : entries) { | ||
encoded_vars.insert(encode_var_dict_id(entry->get_id())); | ||
} | ||
sub_query.add_imprecise_dict_var(encoded_vars, entries_set); | ||
Comment on lines
+404
to
+412
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think about adding a new signature for sub_query.add_imprecise_dict_var that takes in a vector of entires as argument?. So we can replace this piece of code witha a single call to the new signature @LinZhihao-723 Note this won't solve the code duplication problem, because CLP-S duplicates the entire Query class |
||
} | ||
|
||
return true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gibber9809 The change in CLP-S looks reasonable to me, but can you take another look? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,9 +64,9 @@ class DictionaryReader { | |
* Gets the entry exactly matching the given search string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gibber9809 Can you take a look at the changes in clp-s part? |
||
* @param search_string | ||
* @param ignore_case | ||
* @return nullptr if an exact match is not found, the entry otherwise | ||
* @return a (possibly empty) vector of entries | ||
*/ | ||
EntryType const* | ||
std::vector<EntryType const*> | ||
get_entry_matching_value(std::string const& search_string, bool ignore_case) const; | ||
|
||
/** | ||
|
@@ -156,26 +156,30 @@ std::string const& DictionaryReader<DictionaryIdType, EntryType>::get_value(Dict | |
} | ||
|
||
template <typename DictionaryIdType, typename EntryType> | ||
EntryType const* DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value( | ||
std::vector<EntryType const*> | ||
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value( | ||
std::string const& search_string, | ||
bool ignore_case | ||
) const { | ||
std::vector<EntryType const*> entries; | ||
if (false == ignore_case) { | ||
for (auto const& entry : m_entries) { | ||
if (entry.get_value() == search_string) { | ||
return &entry; | ||
entries.push_back(&entry); | ||
// early exit for case sensitive branch | ||
return entries; | ||
} | ||
} | ||
} else { | ||
auto const& search_string_uppercase = boost::algorithm::to_upper_copy(search_string); | ||
for (auto const& entry : m_entries) { | ||
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) { | ||
return &entry; | ||
entries.push_back(&entry); | ||
} | ||
} | ||
} | ||
|
||
return nullptr; | ||
return entries; | ||
} | ||
|
||
template <typename DictionaryIdType, typename EntryType> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should update the docstring.
@kirkrodrigues any suggestions on how to account for multiple possible matching? "entry(entries)"?