Files
SnowLuma/.pnpm-store/v11/files/37/f7e89407f2cf57d4a8708862297653a80dd870a9554d346a71a054aba4c387bd2291c2f3a5103a7a45ac1a0d5a104b2f116eb85ad667d99836041baeb20e97
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

92 lines
2.8 KiB
Plaintext

'use strict';
var feedback$8 = require('./matcher/bruteforce/feedback.cjs');
var feedback$7 = require('./matcher/date/feedback.cjs');
var feedback$6 = require('./matcher/dictionary/feedback.cjs');
var feedback$5 = require('./matcher/regex/feedback.cjs');
var feedback$4 = require('./matcher/repeat/feedback.cjs');
var feedback$3 = require('./matcher/sequence/feedback.cjs');
var feedback$2 = require('./matcher/spatial/feedback.cjs');
var feedback$1 = require('./matcher/separator/feedback.cjs');
var feedback = require('./matcher/wordSequence/feedback.cjs');
const defaultFeedback = {
warning: null,
suggestions: []
};
/*
* -------------------------------------------------------------------------------
* Generate feedback ---------------------------------------------------------------
* -------------------------------------------------------------------------------
*/
class Feedback {
constructor(options) {
this.options = options;
this.matchers = {};
this.defaultFeedback = {
warning: null,
suggestions: []
};
this.setDefaultSuggestions();
this.matchers = {
bruteforce: feedback$8,
date: feedback$7,
dictionary: feedback$6,
regex: feedback$5,
repeat: feedback$4,
sequence: feedback$3,
spatial: feedback$2,
separator: feedback$1,
wordSequence: feedback
};
Object.entries(this.options.matchers).forEach(([key, matcher]) => {
if (matcher.feedback) {
this.matchers[key] = matcher.feedback;
}
});
}
setDefaultSuggestions() {
this.defaultFeedback.suggestions.push(this.options.translations.suggestions.useWords, this.options.translations.suggestions.noNeed);
}
getFeedback(score, sequence) {
if (sequence.length === 0) {
return this.defaultFeedback;
}
if (score > 2) {
return defaultFeedback;
}
const extraFeedback = this.options.translations.suggestions.anotherWord;
const longestMatch = this.getLongestMatch(sequence);
let feedback = this.getMatchFeedback(longestMatch, sequence.length === 1);
if (feedback !== null && feedback !== undefined) {
feedback.suggestions.unshift(extraFeedback);
} else {
feedback = {
warning: null,
suggestions: [extraFeedback]
};
}
return feedback;
}
getLongestMatch(sequence) {
let longestMatch = sequence[0];
// ignore first entry
for (let i = 1; i < sequence.length; i += 1) {
const match = sequence[i];
if (match.token.length > longestMatch.token.length) {
longestMatch = match;
}
}
return longestMatch;
}
getMatchFeedback(match, isSoleMatch) {
if (this.matchers[match.pattern]) {
return this.matchers[match.pattern](this.options, match, isSoleMatch);
}
return defaultFeedback;
}
}
module.exports = Feedback;
//# sourceMappingURL=Feedback.cjs.map