def text_to_word_sequence(text,
filters='!"#$%&()*+,-./:;<=>[email protected][\\]^_`{|}~\t\n',
lower=True, split=" "):
"""Converts a text to a sequence of words (or tokens).
# Arguments
text: Input text (string).
filters: Sequence of characters to filter out.
lower: Whether to convert the input to lowercase.
split: Sentence split marker (string).
# Returns
A list of words (or tokens).
"""
if lower:
text = text.lower()
if sys.version_info < (3,) and isinstance(text, unicode):
translate_map = dict((ord(c), unicode(split)) for c in filters)
else:
translate_map = maketrans(filters, split * len(filters))
text = text.translate(translate_map)
seq = text.split(split)
return [i for i in seq if i]
unicode
文字の代わりにバイト(str
)の文字列を指す2.xでタイプです。 3.xの等価はとは対照的にstr
です。
2.xのコードパスを削除するだけで、そのコードは問題ありません(もちろん、バグは例外です)。