build_adjacency = function (n, offset = 0) {
const coded = lengths[n].map((d) => d.split("").map((e) => codes[e]));
const dists = coded.map((d) => []);
for (let i = 0; i < coded.length; i++) {
const word1 = coded[i];
const words = [[0, word1]];
for (let k = 1; k < word1.length; k++) {
words.push([
Math.min(k, word1.length - k),
[...word1.slice(k, word1.length), ...word1.slice(0, k)]
]);
}
for (let j = i + 1; j < coded.length; j++) {
if (coded[j].length != word1.length) {
continue;
}
for (let [cost, word] of words) {
const d = dist(word, coded[j], cost);
if (d <= max_thresh) {
dists[i].push([j + offset, d]);
dists[j].push([i + offset, d]);
}
}
}
for (let drop = 0; drop < word1.length; drop++) {
const word = [
...word1.slice(0, drop),
...word1.slice(drop + 1, word1.length)
];
if (total_vocab[word1.join("-")] !== undefined) {
dists[i].push([total_vocab[word1.join("-")], 3]);
}
}
}
return dists;
}