Part I of Cartesia's "From Tokens to Bytes" shows that an H-Net splits an unfamiliar word into several chunks the first time it appears and into fewer chunks as the word recurs in the same text. The post shows this qualitatively. Turn it into a number.
data is a str (encode it as UTF-8) or bytes. boundaries holds one flag per byte, 1 where a chunk starts. pattern is a str or bytes. All positions are byte offsets.
find_occurrences(data, pattern)
pattern, scanning left to right: after a match at the search resumes at . Raise ValueError for an empty pattern.chunks_per_occurrence(boundaries, starts, length)
own_chunk(boundaries, start, length)
True if the span is exactly one chunk: a boundary at start, none inside, and either a boundary at start + length or the span ends the data.in_context_trend(data, boundaries, pattern)
ValueError if len(boundaries) differs from the number of bytes.(counts, flags, slope): the chunk counts and own_chunk flags of every occurrence in order, and the least-squares slope of the counts against occurrence index . Use None for the slope if there are fewer than 2 occurrences.bytes.find(sub, start) searches from an offset.