Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Add getSentencesWithoutAbbreviations
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler committed Dec 29, 2018
1 parent 930e364 commit 98056d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions web/src/validation/index.js
Expand Up @@ -17,6 +17,7 @@ export function validateSentences(language, sentences) {
run([
getSentencesWithCorrectLength(validator, sentences),
getSentencesWithoutNumbers(validator, sentences),
getSentencesWithoutAbbreviations(validator, sentences),
], valid, filtered);

return {
Expand Down Expand Up @@ -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;
}
19 changes: 19 additions & 0 deletions 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;
Expand All @@ -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 };
}

0 comments on commit 98056d5

Please sign in to comment.