Skip to content
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

remove_partial_matches only consider alpha, the digial may not match? #16

Open
yqynju opened this issue Mar 16, 2021 · 0 comments
Open

Comments

@yqynju
Copy link

yqynju commented Mar 16, 2021

[code ]

aho_corasick::trie trie;
trie.remove_overlaps()
    .only_whole_words()
    .case_insensitive();
trie.insert("great question");
trie.insert("forty-two");
trie.insert("deep thought");
auto tokens = trie.tokenise("123great question");
std::stringstream html;
html << "<html><body><p>";
for (const auto& token : tokens) {
        if (token.is_match()) html << "<i>";
        html << token.get_fragment();
        if (token.is_match()) html << "</i>";
}
html << "</p></body></html>";
std::cout << html.str();

[output]

<html><body><p>great question</p></body></html>

that's not the whole words.

if change remove_partial_matches as below, it works ok (isalpha ---> isalnum)

void remove_partial_matches(string_ref_type search_text, emit_collection &collected_emits) const
    {
        size_t size = search_text.size();
        emit_collection remove_emits;
        for (const auto &e : collected_emits) {
            if ((e.get_start() == 0 || !std::isalnum(search_text.at(e.get_start() - 1))) &&
                (e.get_end() + 1 == size || !std::isalnum(search_text.at(e.get_end() + 1)))
               ) {
                continue;
            }
            remove_emits.push_back(e);
        }
        for (auto &e : remove_emits) {
            collected_emits.erase(
                std::find(collected_emits.begin(), collected_emits.end(), e)
            );
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant