diff --git a/web/src/validation/index.js b/web/src/validation/index.js index 26e27113..1465c29f 100644 --- a/web/src/validation/index.js +++ b/web/src/validation/index.js @@ -17,6 +17,7 @@ export function validateSentences(language, sentences) { run([ getSentencesWithCorrectLength(validator, sentences), getSentencesWithoutNumbers(validator, sentences), + getSentencesWithoutAbbreviations(validator, sentences), ], valid, filtered); return { @@ -82,6 +83,15 @@ function getSentencesWithoutNumbers(validator, sentences) { return { valid, filtered }; } +function getSentencesWithoutAbbreviations(validator, sentences) { + const { valid, filtered } = + typeof validator.filterAbbreviations !== 'function' ? + DEFAULT_VALIDATOR.filterAbbreviations(sentences) : + validator.filterAbbreviations(sentences); + + return { valid, filtered }; +} + function getValidatorFor(language) { return VALIDATORS[language] || DEFAULT_VALIDATOR; } \ No newline at end of file diff --git a/web/src/validation/languages/en.js b/web/src/validation/languages/en.js index 557d239b..aaa5680c 100644 --- a/web/src/validation/languages/en.js +++ b/web/src/validation/languages/en.js @@ -1,5 +1,10 @@ const MAX_WORDS = 14; const NUMBERS_REGEX = /[0-9]+/; +// Any words consisting of uppercase letters or uppercase letters with a period +// inbetween are considered abbreviations or acronyms. +// This currently also matches fooBAR but we most probably don't want that either +// as users wouldn't know how to pronounce the uppercase letters. +const ABBREVIATION_REGEX = /[A-Z]{2,}|[A-Z]+\.*[A-Z]+/; export function getMaxLength() { return MAX_WORDS; @@ -16,5 +21,19 @@ export function filterNumbers(sentences) { return true; }); + return { valid, filtered }; +} + +export function filterAbbreviations(sentences) { + const filtered = []; + const valid = sentences.filter(sentence => { + if (sentence.match(ABBREVIATION_REGEX)) { + filtered.push(sentence); + return false; + } + + return true; + }); + return { valid, filtered }; } \ No newline at end of file