Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix: proper noun caps linter doesn't capitalize minor words

hippietrail402649f02a9e
diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rs
index d759673f5..442339b11 100644
--- a/harper-core/src/linting/matcher.rs
+++ b/harper-core/src/linting/matcher.rs
@@ -247,21 +247,9 @@ impl Matcher {
"andorra","la","vella" => "Andorra la Vella",
"Andorra","La","vella" => "Andorra la Vella",
"Andorra","La","Vella" => "Andorra la Vella",
- "antigua","and","barbuda" => "Antigua and Barbuda",
- "Antigua","and","barbuda" => "Antigua and Barbuda",
- "Antigua","And","Barbuda" => "Antigua and Barbuda",
- "bosnia and herzegovina" => "Bosnia and Herzegovina",
- "Bosnia","and","herzegovina" => "Bosnia and Herzegovina",
- "Bosnia","And","herzegovina" => "Bosnia and Herzegovina",
- "democratic","republic","of","the","congo" => "Democratic Republic of the Congo",
- "Democratic","republic","of","the","congo" => "Democratic Republic of the Congo",
- "Democratic","Republic","Of","The","Congo" => "Democratic Republic of the Congo",
"guinea","bissau" => "Guinea-Bissau",
"Guinea","bissau" => "Guinea-Bissau",
"Guinea","Bissau" => "Guinea-Bissau",
- "isle","of","man" => "Isle of Man",
- "Isle","of","man" => "Isle of Man",
- "Isle","Of","Man" => "Isle of Man",
"ndjamena" => "N'Djamena",
"Ndjamena" => "N'Djamena",
"n'djamena" => "N'Djamena",
@@ -274,15 +262,6 @@ impl Matcher {
// Port-Au-Prince ditto
"porto","novovo" => "Porto-Novo",
"Porto","novovo" => "Porto-Novo",
- "saint","kitts","and","nevis" => "Saint Kitts and Nevis",
- "Saint","kitts","and","nevis" => "Saint Kitts and Nevis",
- "Saint","Kitts","And","Nevis" => "Saint Kitts and Nevis",
- "saint","pierre","and","miqueleon" => "Saint Pierre and Miquelon",
- "Saint","pierre","and","miquelon" => "Saint Pierre and Miquelon",
- "Saint","Pierre","And","Miquelon" => "Saint Pierre and Miquelon",
- "saint","vincent","and","the","grenadines" => "Saint Vincent and the Grenadines",
- "Saint","vincent","and","the","grenadines" => "Saint Vincent and the Grenadines",
- "Saint","Vincent","And","The","Grenadines" => "Saint Vincent and the Grenadines",
"st","georges" => "St. George's",
// "st.","georges" => "St. George's",
"st","george's" => "St. George's",
@@ -293,10 +272,7 @@ impl Matcher {
// "St.","george's" => "St. George's",
"St","Georges" => "St. George's",
// "St.","Georges" => "St. George's",
- "St","George's" => "St. George's",
- "trinidad","and","tobago" => "Trinidad and Tobago",
- "Trinidad","and","tobago" => "Trinidad and Tobago",
- "Trinidad","And","Tobago" => "Trinidad and Tobago"
+ "St","George's" => "St. George's"
});
// countries and capitals with accents and diacritics
@@ -319,6 +295,9 @@ impl Matcher {
"male" => "Malé",
"malé" => "Malé",
"Male" => "Malé",
+ "noumea" => "Nouméa",
+ "nouméa" => "Nouméa",
+ "Noumea" => "Nouméa",
"nukualofa" => "Nukuʻalofa",
"Nukualofa" => "Nukuʻalofa",
"nuku'alofa" => "Nukuʻalofa",
diff --git a/harper-core/src/linting/proper_noun_capitalization_linters.rs b/harper-core/src/linting/proper_noun_capitalization_linters.rs
index abe95f83b..09c30f4db 100644
--- a/harper-core/src/linting/proper_noun_capitalization_linters.rs
+++ b/harper-core/src/linting/proper_noun_capitalization_linters.rs
@@ -190,6 +190,16 @@ create_linter_for!(
Countries,
EitherPattern::new(vec![
// Grouped country names
+ // ... Guinea
+ Box::new(
+ SequencePattern::default()
+ .then(Box::new(EitherPattern::new(vec![
+ Box::new(SequencePattern::aco("Equatorial")),
+ Box::new(SequencePattern::aco("Papua").then_whitespace().t_aco("New")),
+ ])))
+ .then_whitespace()
+ .t_aco("Guinea")
+ ),
// ... Islands
Box::new(
SequencePattern::default()
@@ -262,7 +272,21 @@ create_linter_for!(
.then_whitespace()
.t_aco("Samoa")
),
+ Box::new(
+ SequencePattern::aco("Antigua")
+ .then_whitespace()
+ .t_aco("and")
+ .then_whitespace()
+ .t_aco("Barbuda")
+ ),
// United Arab Emirates is under "United Organizations"
+ Box::new(
+ SequencePattern::aco("Bosnia")
+ .then_whitespace()
+ .t_aco("and")
+ .then_whitespace()
+ .t_aco("herzegovina")
+ ),
Box::new(
SequencePattern::aco("Burkina")
.then_whitespace()
@@ -278,6 +302,17 @@ create_linter_for!(
.then_whitespace()
.t_aco("Rica")
),
+ Box::new(
+ SequencePattern::aco("Democratic")
+ .then_whitespace()
+ .t_aco("republic")
+ .then_whitespace()
+ .t_aco("of")
+ .then_whitespace()
+ .t_aco("the")
+ .then_whitespace()
+ .t_aco("congo")
+ ),
Box::new(
SequencePattern::aco("East")
.then_whitespace()
@@ -288,42 +323,40 @@ create_linter_for!(
.then_whitespace()
.t_aco("Salvador")
),
+ // Box::new(SequencePattern::aco("Equatorial").then_whitespace().t_aco("Guinea")),
Box::new(
- SequencePattern::aco("Equatorial")
+ SequencePattern::aco("French")
.then_whitespace()
- .t_aco("Guinea")
+ .t_aco("Polynesia")
),
- // Box::new(SequencePattern::aco("Falkland").then_whitespace().t_aco("Islands")),
+ Box::new(SequencePattern::aco("Guinea").then_hyphen().t_aco("Bissau")),
Box::new(
- SequencePattern::aco("French")
+ SequencePattern::aco("Isle")
.then_whitespace()
- .t_aco("Polyynesia")
+ .t_aco("of")
+ .then_whitespace()
+ .t_aco("Man")
),
- Box::new(SequencePattern::aco("Guinea").then_hyphen().t_aco("Bissau")),
Box::new(
SequencePattern::aco("Ivory")
.then_whitespace()
.t_aco("Coast")
),
- Box::new(SequencePattern::aco("La").then_whitespace().t_aco("Paz")),
Box::new(
SequencePattern::aco("North")
.then_whitespace()
.t_aco("Macedonia")
),
Box::new(
- SequencePattern::aco("Papua")
- .then_whitespace()
- .t_aco("New")
+ SequencePattern::aco("Puerto")
.then_whitespace()
- .t_aco("Guinea")
+ .t_aco("Rico")
),
Box::new(
- SequencePattern::aco("Puerto")
+ SequencePattern::aco("Saudi")
.then_whitespace()
- .t_aco("Rico")
+ .t_aco("Arabia")
),
- // Saint Kitts and Nevis has lowercase "and"
Box::new(
SequencePattern::aco("Sierra")
.then_whitespace()
@@ -336,9 +369,11 @@ create_linter_for!(
),
Box::new(SequencePattern::aco("Sri").then_whitespace().t_aco("Lanka")),
Box::new(
- SequencePattern::aco("Saudi")
+ SequencePattern::aco("Trinidad")
.then_whitespace()
- .t_aco("Arabia")
+ .t_aco("and")
+ .then_whitespace()
+ .t_aco("Tobago")
),
Box::new(
SequencePattern::aco("Western")
@@ -376,6 +411,36 @@ create_linter_for!(
.then_whitespace()
.t_aco("City")
),
+ // Saint ...
+ Box::new(
+ SequencePattern::aco("Saint")
+ .then_whitespace()
+ .then(Box::new(EitherPattern::new(vec![
+ Box::new(
+ SequencePattern::aco("Kitts")
+ .then_whitespace()
+ .t_aco("and")
+ .then_whitespace()
+ .t_aco("Nevis")
+ ),
+ Box::new(
+ SequencePattern::aco("Pierre")
+ .then_whitespace()
+ .t_aco("and")
+ .then_whitespace()
+ .t_aco("Miquelon")
+ ),
+ Box::new(
+ SequencePattern::aco("Vincent")
+ .then_whitespace()
+ .t_aco("and")
+ .then_whitespace()
+ .t_aco("the")
+ .then_whitespace()
+ .t_aco("Grenadines")
+ )
+ ])))
+ ),
// San ...
Box::new(
SequencePattern::aco("San")
@@ -398,7 +463,6 @@ create_linter_for!(
.then_whitespace()
.t_aco("Town")
),
- // George Town is with "Cape Town"
// One-off capital names
Box::new(SequencePattern::aco("Abu").then_whitespace().t_aco("Dhabi")),
Box::new(
@@ -406,7 +470,7 @@ create_linter_for!(
.then_whitespace()
.t_aco("Ababa")
),
- // Andorra la Vella has lowercase "la"
+ // Andorra la Vella can't be done here because "la" must not be capitalized
Box::new(
SequencePattern::aco("Bandar")
.then_whitespace()
@@ -419,15 +483,14 @@ create_linter_for!(
.then_whitespace()
.t_aco("Aires")
),
+ // Dar es Salaam can't be done here because "es" must not be capitalized
Box::new(
SequencePattern::aco("Diego")
.then_whitespace()
.t_aco("Garcia")
),
- // Guatemala City is with "Belize City"
- // Ho Chi Minh City is with "Belize City"
// Kuala Lumpur is under "Malaysia"
- // Mexico City is with "Belize City"
+ Box::new(SequencePattern::aco("La").then_whitespace().t_aco("Paz")),
Box::new(SequencePattern::aco("New").then_whitespace().t_aco("Delhi")),
Box::new(SequencePattern::aco("Pago").then_whitespace().t_aco("Pago")),
Box::new(
@@ -435,15 +498,21 @@ create_linter_for!(
.then_whitespace()
.t_aco("Penh")
),
+ // Port-au-Prince can't be done here because "au" must not be capitalized
Box::new(
- // Port-au-Prince can't be done here because "au" must not be capitalized
- // Port of Spain can't be done here because "of" must not be capitalized
SequencePattern::aco("Port")
.then_whitespace()
- .then(Box::new(WordSet::all(&["Louis", "Moresby", "Vila"])))
+ .then(Box::new(EitherPattern::new(vec![
+ Box::new(WordSet::all(&["Louis", "Moresby", "Vila"])),
+ Box::new(SequencePattern::aco("of").then_whitespace().t_aco("Spain"))
+ ])))
),
Box::new(SequencePattern::aco("Porto").then_hyphen().t_aco("Novo")),
- Box::new(SequencePattern::aco("Santo").then_hyphen().t_aco("Domingo")),
+ Box::new(
+ SequencePattern::aco("Santo")
+ .then_whitespace()
+ .t_aco("Domingo")
+ ),
Box::new(
SequencePattern::aco("The")
.then_whitespace()