internationalize word boundary checks#49
Open
aseifert wants to merge 27 commits into
Open
Conversation
added reference to flashtext paper
added citation
corrected citation
`charactes` | `characters` `explaination` | `explanation` `matche` | `match`
Fix issue with incomplete keyword at the end of the sentence
1 similar comment
|
Another way, based on https://stackoverflow.com/a/2998550: |
ioistired
suggested changes
Jun 8, 2019
| char = sentence[idx] | ||
| # when we reach a character that might denote word end | ||
| if char not in self.non_word_boundaries: | ||
| if KeywordProcessor.NON_WORD_CHAR_REGEX.match(char): |
There was a problem hiding this comment.
why the ugly direct reference to the class? just use self
|
Another way to do it: from functools import lru_cache
from flashtext import KeywordProcessor
class NonWordBoundaries:
def __init__(self, *predicates):
self.predicates = predicates
@lru_cache(maxsize=128)
def __contains__(self, ch):
for predicate in self.predicates:
if predicate(ch):
return True
return False
def main():
words_to_search = ["рок"]
keyword_processor = KeywordProcessor()
keyword_processor.set_non_word_boundaries(NonWordBoundaries(str.isalpha, str.isdigit))
keyword_processor.add_keywords_from_list(words_to_search)
keywords_found = keyword_processor.extract_keywords('рок порок роковой')
print(keywords_found)Not sure about performance though. But at least it is easy to modify the behaviour. |
|
Benchmarks vs. Regex are for the English only char set. Is increasing the word boundaries like this effecting flashtext performance in any significant way? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi there,
I think the only safe way to deal with issue #48 would be to test against the
\Wclass [1]. Judging from the benchmarks linked on https://github.com/vi3k6i5/flashtext#why-not-regex this seems to run slower by a factor of 1-2 though.Best,
Alex
[1] Quoting the Python docs: