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

Add abstract base class syntax to tokenize/api.py #1223

Merged
merged 2 commits into from
Jan 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nltk/tokenize/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
Tokenizer Interface
"""

from abc import ABCMeta, abstractmethod
from six import add_metaclass

from nltk.internals import overridden
from nltk.tokenize.util import string_span_tokenize

@add_metaclass(ABCMeta)
class TokenizerI(object):
"""
A processing interface for tokenizing a string.
Subclasses must define ``tokenize()`` or ``tokenize_sents()`` (or both).
"""
@abstractmethod
def tokenize(self, s):
"""
Return a tokenized copy of *s*.
Expand All @@ -26,8 +31,6 @@ def tokenize(self, s):
"""
if overridden(self.tokenize_sents):
return self.tokenize_sents([s])[0]
else:
raise NotImplementedError()

def span_tokenize(self, s):
"""
Expand Down