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

match uppercase non-english letters too #45

Merged
merged 2 commits into from
Nov 25, 2023
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
4 changes: 2 additions & 2 deletions src/parser/AbbrMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const isCapitalized = (text: string) => {
if (!text || text.length === 0) {
return false;
}
return /^[A-Z]/.test(text);
return /^\p{Uppercase_Letter}/u.test(text);
};

const compareNoCaseSensitive = (a: string, b: string): boolean => {
Expand Down Expand Up @@ -120,7 +120,7 @@ export class AbbrMarker implements AbstractMarker {
// Example: `I` as a sentence boundary and `I` as an abbreviation
// > We make a good team, you and I. Did you see Albert I. Jones yesterday?
// Related: https://github.com/azu/sentence-splitter/pull/31
if (isCapitalized(prevWord) && /^[A-Z]\./.test(currentWord) && isCapitalized(nextWord)) {
if (isCapitalized(prevWord) && /^\p{Uppercase_Letter}\./u.test(currentWord) && isCapitalized(nextWord)) {
sourceCode.markContextRange([sourceCode.offset, sourceCode.offset + currentWord.length]);
} else if (isMatched && !isCapitalized(nextWord)) {
// Exception. This allows to write Capitalized word at next word
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/1-sentence--nesting-pair-mark/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@
38
],
"raw": "He said \"I'm going to the 「無印」 store.\""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ők Cornel West és Robert F Kennedy Jr. Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól.
39 changes: 39 additions & 0 deletions test/fixtures/recognize-foreign-uppercase-characters/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"type": "Paragraph",
"children": [
{
"type": "Str",
"value": "Ők Cornel West és Robert F Kennedy Jr. Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól.",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 101
}
},
"range": [
0,
101
],
"raw": "Ők Cornel West és Robert F Kennedy Jr. Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól."
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 101
}
},
"range": [
0,
101
],
"raw": "Ők Cornel West és Robert F Kennedy Jr. Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól."
}
157 changes: 157 additions & 0 deletions test/fixtures/recognize-foreign-uppercase-characters/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"type": "Paragraph",
"children": [
{
"type": "Sentence",
"raw": "Ők Cornel West és Robert F Kennedy Jr.",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 38
}
},
"range": [
0,
38
],
"children": [
{
"type": "Str",
"raw": "Ők Cornel West és Robert F Kennedy Jr",
"value": "Ők Cornel West és Robert F Kennedy Jr",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 37
}
},
"range": [
0,
37
]
},
{
"type": "Punctuation",
"raw": ".",
"value": ".",
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 38
}
},
"range": [
37,
38
]
}
],
"contexts": []
},
{
"type": "WhiteSpace",
"raw": " ",
"value": " ",
"loc": {
"start": {
"line": 1,
"column": 38
},
"end": {
"line": 1,
"column": 39
}
},
"range": [
38,
39
]
},
{
"type": "Sentence",
"raw": "Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól.",
"loc": {
"start": {
"line": 1,
"column": 39
},
"end": {
"line": 1,
"column": 101
}
},
"range": [
39,
101
],
"children": [
{
"type": "Str",
"raw": "Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól",
"value": "Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól",
"loc": {
"start": {
"line": 1,
"column": 39
},
"end": {
"line": 1,
"column": 100
}
},
"range": [
39,
100
]
},
{
"type": "Punctuation",
"raw": ".",
"value": ".",
"loc": {
"start": {
"line": 1,
"column": 100
},
"end": {
"line": 1,
"column": 101
}
},
"range": [
100,
101
]
}
],
"contexts": []
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 101
}
},
"range": [
0,
101
],
"raw": "Ők Cornel West és Robert F Kennedy Jr. Ők elvehetik a szavazatokat Joe Biden-től és Donald Trump-tól."
}