-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
32 lines (28 loc) · 759 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from abc import ABCMeta, abstractmethod
from six import add_metaclass
@add_metaclass(ABCMeta)
class ArmTokenizerBase(object):
"""
A processing interface for tokenizing a string.
Subclasses must define ``tokenize()``.
"""
@abstractmethod
def tokenize(self, s):
"""
Return a tokenized copy of *s*.
:rtype: list of str
"""
pass
@abstractmethod
def segmentize(self,s):
"""
Return segmentized form of *s*
:rtype: list of str
"""
pass
def tokenize_sents(self, strings):
"""
Apply ``self.tokenize()`` to each element of ``strings``
:rtype: gen
"""
return [self.tokenize(s) for s in strings]