Datasets:
File size: 1,778 Bytes
a97edac | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // Diagnostic only: do not import this into production evaluation.
// A loss-only experiment isolates false positives caused by the named bugs.
// Existing matches remain necessary: no synonyms or tolerances are added.
import {matchesAcceptedAnswer, stripResponseWrapperResidue} from './answer-normalization.mjs';
export const numericFormats=new Set([
'Positive integer','Signed integer','Integer','Bar number (digits)',
'Bar number (digits) or NA','Bar range (N-N)','Bar and beat',
'Beat number (digits)','Beat number (fraction)',
'Fractional beat number with optional beat prefix','Fraction written as N/N',
'Count in quarter notes','Count of eighth-note durations','Count and ornamentation',
'Count followed by note value','Count in number of beats (according to applicable meter)',
'Ratio','Section label followed by start-bar number','Bar number, yes-or-no',
]);
export function romanSignature(value){
return [...stripResponseWrapperResidue(value).normalize('NFKC').matchAll(/(?<![A-Za-z])[#b♯♭]?[IViv]+(?![A-Za-z])/gu)].map(m=>m[0]);
}
export function numberSignature(value){
return [...stripResponseWrapperResidue(value).normalize('NFKC').matchAll(/[+-]?\d+(?:\.\d+)?/gu)].map(m=>String(Number(m[0])));
}
export function diagnosticMatch(answer, reference, question, {roman=true,numeric=true}={}){
if(!matchesAcceptedAnswer(answer,reference,{fullQuestion:question.full_question}))return false;
if(roman&&question.answer_format==='Roman-numeral chord symbol'
&&JSON.stringify(romanSignature(answer))!==JSON.stringify(romanSignature(reference)))return false;
if(numeric&&numericFormats.has(question.answer_format)
&&JSON.stringify(numberSignature(answer))!==JSON.stringify(numberSignature(reference)))return false;
return true;
}
|