Skip to content

Commit c3afd21

Browse files
author
Florian Treml
committed
Cleanup texts for calculating WER
1 parent 77a5ace commit c3afd21

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

frontend/src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ const enumValueToName = (obj, value) => {
2323
return Object.keys(obj)[Object.values(obj).findIndex(x => x === value)]
2424
}
2525

26+
const _cleanString = (str) => str.toLowerCase().replace(/[\W_]+/g, ' ').split(' ').filter(s => s && s.length > 0).join(' ')
27+
2628
const wer = async (text1, text2) => {
29+
const from = _cleanString(text1 || '')
30+
const to = _cleanString(text2 || '')
2731
return {
28-
distance: speechScorer.calculateEditDistance(text1 || '', text2 || ''),
29-
wer: speechScorer.wordErrorRate(text1 || '', text2 || '')
32+
distance: speechScorer.calculateEditDistance(from, to),
33+
wer: speechScorer.wordErrorRate(from, to)
3034
}
3135
}
3236

0 commit comments

Comments
 (0)