I am using nltk tokenize library to split up english sentences.
Many sentences contain abbreviations such as e.g. or eg. thus I updated the tokenizer with these custom abbreviations.
I found a strange tokenization behaviour with a sentence though:
import nltk
nltk.download("punkt")
sentence_tokenizer = nltk.data.load("tokenizers/punkt/english.pickle")
extra_abbreviations = ['e.g', 'eg']
sentence_tokenizer._params.abbrev_types.update(extra_abbreviations)
line = 'Required experience with client frameworks (e.g. React, Vue.js) and testing (e.g. Karma, Tape)'
for s in sentence_tokenizer.tokenize(line):
print(s)
# OUTPUT
# Required experience with client frameworks (e.g. React, Vue.js) and testing (e.g.
# Karma, Tape)
So as you can see the tokenizer does not split on the first abbreviation (correct) but it does on the second (incorrect).
The weird thing is that if I change the word Karma in anything else, it works correctly.
import nltk
nltk.download("punkt")
sentence_tokenizer = nltk.data.load("tokenizers/punkt/english.pickle")
extra_abbreviations = ['e.g', 'eg']
sentence_tokenizer._params.abbrev_types.update(extra_abbreviations)
line = 'Required experience with client frameworks (e.g. React, Vue.js) and testing (e.g. SomethingElse, Tape)'
for s in sentence_tokenizer.tokenize(line):
print(s)
# OUTPUT
# Required experience with client frameworks (e.g. React, Vue.js) and testing (e.g. SomethingElse, Tape)
Any clue why is this happening?