MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / split_indices

Function split_indices

test/general/lm_eval/decontamination/janitor.py:71–75  ·  view source on GitHub ↗

Splits a string on whitespaces and records the indices of each in the original string. @:return generator((word, (start_idx, end_idx)), ...)

(s)

Source from the content-addressed store, hash-verified

69
70# https://stackoverflow.com/questions/13734451/string-split-with-indices-in-python
71def split_indices(s):
72 """Splits a string on whitespaces and records the indices of each in the original string.
73 @:return generator((word, (start_idx, end_idx)), ...)
74 """
75 return ((m.group(0), (m.start(), m.end() - 1)) for m in re.finditer(r"\S+", s))
76
77
78def word_ngrams_indices(s, n):

Callers 1

word_ngrams_indicesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected