You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.3 KiB
33 lines
1.3 KiB
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.suggestIteration = exports.suggest = void 0; |
|
const helpers_1 = require("./helpers"); |
|
const defaultMinScore = 0.35; |
|
const wPrefix = '^'; |
|
const wSuffix = '$'; |
|
function* suggest(trie, word, minScore = defaultMinScore) { |
|
yield* suggestIteration(trie.iterate(), word, minScore); |
|
} |
|
exports.suggest = suggest; |
|
function* suggestIteration(i, word, minScore = defaultMinScore) { |
|
let goDeeper = true; |
|
const fA = helpers_1.wordToFeatures(wPrefix + word + wSuffix); |
|
for (let r = i.next(goDeeper); !r.done; r = i.next(goDeeper)) { |
|
const { text, node } = r.value; |
|
const fB = helpers_1.wordToFeatures(wPrefix + text); |
|
const rawScore = fA.intersectionScore(fB); |
|
const bestPossibleScore = fA.count / (fA.count + fB.count - rawScore); |
|
goDeeper = bestPossibleScore > minScore; |
|
if (goDeeper && node.f) { |
|
const fB = helpers_1.wordToFeatures(wPrefix + text + wSuffix); |
|
const rawScore = fA.intersectionScore(fB); |
|
const score = rawScore / (fA.count + fB.count - rawScore); |
|
if (score >= minScore) { |
|
const r = { word: text, score }; |
|
minScore = (yield r) || minScore; |
|
} |
|
} |
|
} |
|
} |
|
exports.suggestIteration = suggestIteration; |
|
//# sourceMappingURL=suggest.js.map
|