--!native --!optimize 2 -- Compiled with roblox-ts v3.0.0 local TS = _G[script] local SubString = TS.import(script, script.Parent.Parent, "Utils", "SubString") --[[ * * Generates a Map of n-grams with their frequencies. * @example "apple" → {"app":1, "ppl":1, "ple":1} (n=3) ]] local function NGramCountsTokenization(str, n) local counts = {} do local i = 0 local _shouldIncrement = false while true do if _shouldIncrement then i += 1 else _shouldIncrement = true end if not (i <= #str - n) then break end local gram = SubString(str, i, i + n) local _condition = counts[gram] if _condition == nil then _condition = 0 end counts[gram] = _condition + 1 end end return counts end return { NGramCountsTokenization = NGramCountsTokenization, }