MCPcopy Create free account
hub / github.com/hankcs/HanLP / possible_tokenization

Function possible_tokenization

hanlp/utils/string_util.py:99–117  ·  view source on GitHub ↗

Enumerate all possible tokenizations of a text. Args: text: A text. Returns: All possible tokenizations.

(text: str)

Source from the content-addressed store, hash-verified

97
98
99def 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]

Callers 2

dict_combineMethod · 0.90

Calls 1

appendMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…