Enumerate all possible tokenizations of a text. Args: text: A text. Returns: All possible tokenizations.
(text: str)
| 97 | |
| 98 | |
| 99 | def possible_tokenization(text: str) -> List[Tuple[str]]: |
| 100 | """Enumerate all possible tokenizations of a text. |
| 101 | |
| 102 | Args: |
| 103 | text: A text. |
| 104 | |
| 105 | Returns: All possible tokenizations. |
| 106 | |
| 107 | """ |
| 108 | states = [((), ())] |
| 109 | for c in text: |
| 110 | new_states = [] |
| 111 | for t, b in states: |
| 112 | # to split |
| 113 | new_states.append((t + (''.join(b + (c,)),), ())) |
| 114 | # not to split |
| 115 | new_states.append((t, b + (c,))) |
| 116 | states = new_states |
| 117 | return [t for t, b in states if not b] |
searching dependent graphs…