Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs to ignore Capital letter at the beginning of the Sentence #6

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"textlint-scripts": "^2.1.0"
},
"dependencies": {
"array-includes": "^3.0.1",
"array-includes": "^3.0.3",
"is-capitalized": "^1.0.0"
}
}
22 changes: 13 additions & 9 deletions src/textlint-rule-unexpanded-acronym.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Step
3. expandedAcronymList.includes(acronymList)
- Not found Acronym and throw error
*/
export default function (context, options = {}) {
module.exports = function (context, options = {}) {
const minAcronymLength = options.min_acronym_len || defaultOptions.min_acronym_len;
const maxAcronymLength = options.max_acronym_len || defaultOptions.max_acronym_len;
const ignoreAcronymList = options.ignore_acronyms || defaultOptions.ignore_acronyms;
Expand Down Expand Up @@ -67,18 +67,22 @@ export default function (context, options = {}) {
} else if (!includes(acronymJoiningWords, word) // ignore of and...
&& acronymCreator.canExtractAcronym()) {
// Create Acronym
var acronym = acronymCreator.extractAcronym();
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
var acronyms = acronymCreator.extractAcronym();
acronyms.forEach(acronym => {
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
});
}
});
if (acronymCreator.canExtractAcronym()) {
// Create Acronym
var acronym = acronymCreator.extractAcronym();
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
var acronyms = acronymCreator.extractAcronym();
acronyms.forEach(acronym => {
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
});
}
},
[Syntax.Document + ":exit"](node){
Expand Down
31 changes: 21 additions & 10 deletions src/word-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@ export function expandOneWordToAcronym(CapitalWord) {
}
/*
* create Acronym from words.
* @param words
* @returns {string}
* @example XMLHttpRequest -> XHR
* @example World Health Organization -> WHO
* @param {string[]} words
* @returns (1)string if only one word (2) array if multiple words
*/
export function expandWordsToAcronym(words) {
//XMLHttpRequest -> XHR
if (words.length === 1) {
return expandOneWordToAcronym(words[0]);
return [expandOneWordToAcronym(words[0])];
}
else{
const result = [];
//In American Broadcast Company -> ["C", "BC", "ABC", "IABC"]
words.reverse().reduce((acronym, word, i) => {
acronym.unshift(word.charAt(0))
result.push(acronym.join(""))
return acronym;
}, []);

//In American Broadcast Company -> ["I", "IA", "IAB", "IABC"]
words.reverse().reduce((acronym, word, i) => {
acronym.push(word.charAt(0));
result.push(acronym.join(""))
return acronym;
}, []);
donganzh-zz marked this conversation as resolved.
Show resolved Hide resolved
return result;
}
// World Health Organization -> WHO
return words.reduce((acronym, word) => {
acronym += word.charAt(0);
return acronym;
}, "");
}
4 changes: 3 additions & 1 deletion test/textlint-rule-unexpanded-acronym-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ always remember (or at least consider).this foodstuff's effect on one's ever-exp
Now we know what SOC stands for`,
// capitalized word
"ABC can stand form the Australian Broadcasting Commission",
"XHR is XMLHttpRequest",
"XHR is known as XMLHttpRequest.",
{
text: `
VHSIC stands for "Very High Speed Integrated Circuit".
Expand All @@ -23,6 +23,8 @@ SQL: ([siːkwəl] or ess-cue-el) Structured Query Language.
IEEE: (I triple E) Institute of Electrical and Electronics Engineers
NAACP: (N double A C P) National Association for the Advancement of Colored People
NCAA: (N C double A or N C two A or N C A A) National Collegiate Athletic Association
In the Amazon Web Service, it can be short as AWS.
Enter the Amazon Resource Names(ARN) for the Lambda you created in the setting
`
},
// options
Expand Down