| 30 | return self |
| 31 | |
| 32 | class Sentence(list): |
| 33 | |
| 34 | def __init__(self, string="", token=["word"]): |
| 35 | """ A list of words, where punctuation marks are split from words. |
| 36 | """ |
| 37 | for ch in PUNCTUATION: # Naive tokenization. |
| 38 | string = string.replace(ch, " %s " % ch) |
| 39 | string = re.sub(r"\s+", " ", string) |
| 40 | string = string.split(" ") |
| 41 | list.__init__(self, (Word(self, w, index=i) for i, w in enumerate(string))) |
| 42 | |
| 43 | @property |
| 44 | def words(self): |
| 45 | return self |
| 46 | |
| 47 | @property |
| 48 | def chunks(self): |
| 49 | return [] |
| 50 | |
| 51 | class Word(object): |
| 52 | |