refactor: enhance session management and room joining logic in WebSocket handling
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s
This commit is contained in:
@@ -28,6 +28,23 @@ function cleanTitleNoise(raw) {
|
||||
function normalizeTitle(s) { return normalizeCommon(cleanTitleNoise(s)); }
|
||||
function normalizeArtist(s) { return normalizeCommon(s).replace(/\bthe\b/g, ' ').replace(/\s+/g, ' ').trim(); }
|
||||
|
||||
// Produce a variant with anything inside parentheses (...) or double quotes "..." removed.
|
||||
function stripOptionalSegments(raw) {
|
||||
let s = String(raw);
|
||||
// Remove double-quoted segments first
|
||||
s = s.replace(/"[^"]*"/g, ' ');
|
||||
// Remove parenthetical segments (non-nested)
|
||||
s = s.replace(/\([^)]*\)/g, ' ');
|
||||
// Remove square-bracket segments [ ... ] (non-nested)
|
||||
s = s.replace(/\[[^\]]*\]/g, ' ');
|
||||
return s;
|
||||
}
|
||||
|
||||
function normalizeTitleBaseOptional(s) {
|
||||
// Clean general noise, then drop optional quoted/parenthetical parts, then normalize
|
||||
return normalizeCommon(stripOptionalSegments(cleanTitleNoise(s)));
|
||||
}
|
||||
|
||||
function tokenize(s) { return s ? String(s).split(' ').filter(Boolean) : []; }
|
||||
function tokenSet(s) { return new Set(tokenize(s)); }
|
||||
function jaccard(a, b) {
|
||||
@@ -79,12 +96,29 @@ const TITLE_JACCARD_THRESHOLD = 0.8;
|
||||
const ARTIST_SIM_THRESHOLD = 0.82;
|
||||
|
||||
export function scoreTitle(guessRaw, truthRaw) {
|
||||
const g = normalizeTitle(guessRaw);
|
||||
const t = normalizeTitle(truthRaw);
|
||||
const sim = simRatio(g, t);
|
||||
const jac = jaccard(g, t);
|
||||
const pass = sim >= TITLE_SIM_THRESHOLD || jac >= TITLE_JACCARD_THRESHOLD;
|
||||
return { pass, sim, jac, g, t };
|
||||
// Full normalized (keeps parentheses/quotes content after punctuation cleanup)
|
||||
const gFull = normalizeTitle(guessRaw);
|
||||
const tFull = normalizeTitle(truthRaw);
|
||||
// Base normalized (treat anything in () or "" as optional and remove it)
|
||||
const gBase = normalizeTitleBaseOptional(guessRaw);
|
||||
const tBase = normalizeTitleBaseOptional(truthRaw);
|
||||
|
||||
const pairs = [
|
||||
[gFull, tFull],
|
||||
[gFull, tBase],
|
||||
[gBase, tFull],
|
||||
[gBase, tBase],
|
||||
];
|
||||
|
||||
let bestSim = 0; let bestJac = 0; let pass = false; let bestPair = pairs[0];
|
||||
for (const [g, t] of pairs) {
|
||||
const sim = simRatio(g, t);
|
||||
const jac = jaccard(g, t);
|
||||
if (sim >= TITLE_SIM_THRESHOLD || jac >= TITLE_JACCARD_THRESHOLD) pass = true;
|
||||
if (sim > bestSim || (sim === bestSim && jac > bestJac)) { bestSim = sim; bestJac = jac; bestPair = [g, t]; }
|
||||
}
|
||||
|
||||
return { pass, sim: bestSim, jac: bestJac, g: bestPair[0], t: bestPair[1] };
|
||||
}
|
||||
|
||||
export function scoreArtist(guessRaw, truthArtistsRaw, primaryCount) {
|
||||
|
||||
Reference in New Issue
Block a user