Skip to content

Allow word tokenization override#27

Open
freecraver wants to merge 2 commits into
cdimascio:masterfrom
freecraver:feature/word_tokenizer
Open

Allow word tokenization override#27
freecraver wants to merge 2 commits into
cdimascio:masterfrom
freecraver:feature/word_tokenizer

Conversation

@freecraver

Copy link
Copy Markdown

See #26 (comment)

Introduces a non-breaking change which allows to override custom word-level tokenization.

The new f_tokenize_words argument accepts a function which maps a text to its words.

example:

from nltk import word_tokenize
r = Readability(text, f_tokenize_words=word_tokenize)

Tests run ✔️
Tests added ✔️
Added section 'What makes a word' to Readme ✔️

Additional remarks:

  • The main difference between nltks TweetTokenizer and the TreebankWordTokenizer I observed is the handling of clitics and abbreviations:
Text Tweet Treebank
"We've got two different solutions" ["We've", 'got', 'two', 'different', 'solutions'] ['We', "'ve", 'got', 'two', 'different', 'solutions']
'How common are abbreviations in the U.S.?' ['How', 'common', 'are', 'abbreviations', 'in', 'the', 'U', '.', 'S', '.', '?'] ['How', 'common', 'are', 'abbreviations', 'in', 'the', 'U.S.', '?']

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

Successfully merging this pull request may close these issues.

1 participant