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 1 commit
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"
}
}
27 changes: 19 additions & 8 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,29 @@ 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();
if(!Array.isArray(acronyms)){
if (isWordSatisfy(acronyms)) {
expandedAcronymList.push(acronyms);
}
}else{
Array.from(acronyms).forEach(acronym => {
azu marked this conversation as resolved.
Show resolved Hide resolved
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();

Array.from(acronyms).forEach(acronym => {
if (isWordSatisfy(acronym)) {
expandedAcronymList.push(acronym);
}
});
}
},
[Syntax.Document + ":exit"](node){
Expand Down
22 changes: 17 additions & 5 deletions src/word-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ export function expandOneWordToAcronym(CapitalWord) {
* @example World Health Organization -> WHO
*/
export function expandWordsToAcronym(words) {
if (words.length === 1) {
if (words.length == 1) {
azu marked this conversation as resolved.
Show resolved Hide resolved
return expandOneWordToAcronym(words[0]);
Copy link
Member

@azu azu Aug 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good interface that always return an array.

return [expandOneWordToAcronym(words[0]))

This change will remove unnessary Array.isArray code from https://github.com/textlint-rule/textlint-rule-unexpanded-acronym/pull/6/files#diff-8c133963a70d07eee0bd3b0a4e71f38eR72

                    var acronyms = acronymCreator.extractAcronym();
-                    //if the acronyms is a string i.e. only one acronym
-                    if(!Array.isArray(acronyms)){
-                        if (isWordSatisfy(acronyms)) {
-                            expandedAcronymList.push(acronyms);
-                        }
-                    //if the acronyms is an array of acronym, we need - to extract the satisfied ones
-                    }else{
                        acronyms.forEach(acronym => {
                            if (isWordSatisfy(acronym)) {
                                expandedAcronymList.push(acronym);
                            }
                        });
-                    }

}
else{
// World Health Organization -> WHO
return words.reduce((acronym, word) => {
acronym += word.charAt(0);
return acronym;
}, "");
let result = [];
azu marked this conversation as resolved.
Show resolved Hide resolved

let output = words.reverse().reduce((acronym, word, i) => {
azu marked this conversation as resolved.
Show resolved Hide resolved
acronym.unshift(word.charAt(0))
result.push(acronym.join(""))
return acronym;
}, []);

let output_1 = words.reverse().reduce((acronyms, word, i) => {
azu marked this conversation as resolved.
Show resolved Hide resolved
acronyms += word.charAt(0);
result.push(acronyms)
return acronyms;
}, []);
donganzh-zz marked this conversation as resolved.
Show resolved Hide resolved
return result;
}
}
3 changes: 2 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,7 @@ 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.
`
},
// options
Expand Down