Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
feat: capitalize multi-word country and capital city names
hippietrailfc04b5ed704c
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rsindex fc901c3fe..1d77dd66f 100644--- a/harper-core/src/linting/lint_group.rs+++ b/harper-core/src/linting/lint_group.rs@@ -38,8 +38,9 @@ use super::plural_conjugate::PluralConjugate;use super::possessive_your::PossessiveYour;use super::pronoun_contraction::PronounContraction;use super::proper_noun_capitalization_linters::{- AmazonNames, Americas, AppleNames, Australia, AzureNames, ChineseCommunistParty, GoogleNames,- Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, UnitedOrganizations,+ AmazonNames, Americas, AppleNames, Australia, AzureNames, ChineseCommunistParty, Countries,+ GoogleNames, Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, NationalCapitals,+ UnitedOrganizations,};use super::repeated_words::RepeatedWords;use super::sentence_capitalization::SentenceCapitalization;@@ -286,7 +287,9 @@ create_lint_group_config!(SpecialAttention => true,Everywhere => true,ThanOthers => true,- SupposedTo => true+ SupposedTo => true,+ Countries => true,+ NationalCapitals => true);impl<T: Dictionary + Default> Default for LintGroup<T> {diff --git a/harper-core/src/linting/matcher.rs b/harper-core/src/linting/matcher.rsindex 3dca39187..d759673f5 100644--- a/harper-core/src/linting/matcher.rs+++ b/harper-core/src/linting/matcher.rs@@ -242,6 +242,111 @@ impl Matcher {"World","War","Ii" => "World War II"});+ // countries and capitals with special casing or punctuation+ triggers.extend(pt! {+ "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",+ "N'djamena" => "N'Djamena",+ "port","au","prince" => "Port-au-Prince",+ "Port","au","prince" => "Port-au-Prince",+ "Port","Au","Prince" => "Port-au-Prince",+ // port-au-prince won't work here because the left side has hyphens+ // Port-au-prince ditto+ // 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",+ // "st.","george's" => "St. George's",+ "St","georges" => "St. George's",+ // "St.","georges" => "St. George's",+ "St","george's" => "St. George's",+ // "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"+ });++ // countries and capitals with accents and diacritics+ triggers.extend(pt! {+ "asuncion" => "Asunción",+ "asunción" => "Asunción",+ "Asuncion" => "Asunción",+ "chisinau" => "Chișinău",+ "chișinău" => "Chișinău",+ "Chisinau" => "Chișinău",+ "bogota" => "Bogotá",+ "bogotá" => "Bogotá",+ "Bogota" => "Bogotá",+ "curacao" => "Curaçao",+ "curaçao" => "Curaçao",+ "curacao" => "Curaçao",+ "lome" => "Lomé",+ "lomé" => "Lomé",+ "Lome" => "Lomé",+ "male" => "Malé",+ "malé" => "Malé",+ "Male" => "Malé",+ "nukualofa" => "Nukuʻalofa",+ "Nukualofa" => "Nukuʻalofa",+ "nuku'alofa" => "Nukuʻalofa",+ "Nuku'alofa" => "Nukuʻalofa",+ "reykjavik" => "Reykjavík",+ "reykjavík" => "Reykjavík",+ "Reykjavik" => "Reykjavík",+ "san","jose" => "San José",+ "san","josé" => "San José",+ "San","jose" => "San José",+ "sao","tome" => "São Tomé",+ "são","tomé" => "São Tomé",+ "Sao","Tome" => "São Tomé",+ "sao","tome","and","principe" => "São Tomé and Príncipe",+ "são","tomé","and","príncipe" => "São Tomé and Príncipe",+ "Sao","Tome","and","Principe" => "São Tomé and Príncipe",+ "Sao","Tome","And","Principe" => "São Tomé and Príncipe",+ "torshavn" => "Tórshavn",+ "tórshavn" => "Tórshavn",+ "Torshavn" => "Tórshavn",+ "turkiye" => "Türkiye",+ "türkiye" => "Türkiye",+ "Turkiye" => "Türkiye",+ "yaounde" => "Yaoundé",+ "yaoundé" => "Yaoundé",+ "Yaounde" => "Yaoundé"+ });+triggers.push(Rule {pattern: vec![pt!("L"), pt!(Period), pt!("L"), pt!(Period), pt!("M")],replace_with: vecword!("large language model"),diff --git a/harper-core/src/linting/mod.rs b/harper-core/src/linting/mod.rsindex ce8bdc037..8390cd7ab 100644--- a/harper-core/src/linting/mod.rs+++ b/harper-core/src/linting/mod.rs@@ -94,8 +94,9 @@ pub use plural_conjugate::PluralConjugate;pub use possessive_your::PossessiveYour;pub use pronoun_contraction::PronounContraction;pub use proper_noun_capitalization_linters::{- AmazonNames, Americas, AppleNames, Australia, AzureNames, ChineseCommunistParty, GoogleNames,- Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, UnitedOrganizations,+ AmazonNames, Americas, AppleNames, Australia, AzureNames, ChineseCommunistParty, Countries,+ GoogleNames, Holidays, Koreas, Malaysia, MetaNames, MicrosoftNames, NationalCapitals,+ UnitedOrganizations,};pub use repeated_words::RepeatedWords;pub use sentence_capitalization::SentenceCapitalization;diff --git a/harper-core/src/linting/proper_noun_capitalization_linters.rs b/harper-core/src/linting/proper_noun_capitalization_linters.rsindex 57c0fe186..abe95f83b 100644--- a/harper-core/src/linting/proper_noun_capitalization_linters.rs+++ b/harper-core/src/linting/proper_noun_capitalization_linters.rs@@ -160,10 +160,7 @@ create_linter_for!(),Box::new(SequencePattern::default().then(Box::new(EitherPattern::new(vec![- Box::new(WordSet::all(&[- "Johor",- "Kota"- ])),+ Box::new(WordSet::all(&["Johor", "Kota"])),]))).then_whitespace().t_aco("Bahru")@@ -177,10 +174,7 @@ create_linter_for!(.t_aco("Kuala").then_whitespace().then(Box::new(EitherPattern::new(vec![- Box::new(WordSet::all(&[- "Lumpur",- "Terengganu"- ])),+ Box::new(WordSet::all(&["Lumpur", "Terengganu"])),])))),Box::new(SequencePattern::default()@@ -192,6 +186,273 @@ create_linter_for!("When referring to the states of Malaysia and their capitals, make sure to treat them as a proper noun.");+create_linter_for!(+ Countries,+ EitherPattern::new(vec![+ // Grouped country names+ // ... Islands+ Box::new(+ SequencePattern::default()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(WordSet::all(&["Cayman", "Falkland", "Marshall", "Solomon"])),+ Box::new(+ SequencePattern::default()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(SequencePattern::aco("British")),+ Box::new(+ SequencePattern::aco("United")+ .then_whitespace()+ .t_aco("States")+ ),+ ])))+ .then_whitespace()+ .t_aco("Virgin")+ ),+ Box::new(+ SequencePattern::aco("Northern")+ .then_whitespace()+ .t_aco("Mariana")+ )+ ])))+ .then_whitespace()+ .t_aco("Islands")+ ),+ // New ...+ Box::new(+ SequencePattern::aco("New")+ .then_whitespace()+ .then(Box::new(WordSet::all(&["Caledonia", "Zealand"])))+ ),+ // Northern ...+ Box::new(+ SequencePattern::aco("Northern")+ .then_whitespace()+ .then(Box::new(WordSet::all(&["Cyprus", "Ireland"])))+ ),+ // ... Republic+ Box::new(+ SequencePattern::default()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(+ SequencePattern::aco("Central")+ .then_whitespace()+ .t_aco("African")+ ),+ Box::new(WordSet::all(&["Czech", "Dominican"])),+ ])))+ .then_whitespace()+ .t_aco("Republic")+ ),+ // Saint ...+ Box::new(+ SequencePattern::aco("Saint")+ .then_whitespace()+ .then(Box::new(WordSet::all(&["Helena", "Lucia", "Martin"])))+ ),+ // South ...+ Box::new(+ SequencePattern::aco("South")+ .then_whitespace()+ .then(Box::new(WordSet::all(&["Africa", "Ossetia", "Sudan"])))+ ),+ // South Korea is under "Koreas"+ // One-off country names+ Box::new(+ SequencePattern::aco("American")+ .then_whitespace()+ .t_aco("Samoa")+ ),+ // United Arab Emirates is under "United Organizations"+ Box::new(+ SequencePattern::aco("Burkina")+ .then_whitespace()+ .t_aco("Faso")+ ),+ Box::new(+ SequencePattern::aco("Cape")+ .then_whitespace()+ .t_aco("Verde")+ ),+ Box::new(+ SequencePattern::aco("Costa")+ .then_whitespace()+ .t_aco("Rica")+ ),+ Box::new(+ SequencePattern::aco("East")+ .then_whitespace()+ .t_aco("Timor")+ ),+ Box::new(+ SequencePattern::aco("El")+ .then_whitespace()+ .t_aco("Salvador")+ ),+ Box::new(+ SequencePattern::aco("Equatorial")+ .then_whitespace()+ .t_aco("Guinea")+ ),+ // Box::new(SequencePattern::aco("Falkland").then_whitespace().t_aco("Islands")),+ Box::new(+ SequencePattern::aco("French")+ .then_whitespace()+ .t_aco("Polyynesia")+ ),+ 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")+ .then_whitespace()+ .t_aco("Guinea")+ ),+ Box::new(+ SequencePattern::aco("Puerto")+ .then_whitespace()+ .t_aco("Rico")+ ),+ // Saint Kitts and Nevis has lowercase "and"+ Box::new(+ SequencePattern::aco("Sierra")+ .then_whitespace()+ .t_aco("Leone")+ ),+ Box::new(+ SequencePattern::aco("Sint")+ .then_whitespace()+ .t_aco("Maarten")+ ),+ Box::new(SequencePattern::aco("Sri").then_whitespace().t_aco("Lanka")),+ Box::new(+ SequencePattern::aco("Saudi")+ .then_whitespace()+ .t_aco("Arabia")+ ),+ Box::new(+ SequencePattern::aco("Western")+ .then_whitespace()+ .t_aco("Sahara")+ )+ ]),+ "When referring to Countries, make sure to treat it as a proper noun."+);++create_linter_for!(+ NationalCapitals,+ EitherPattern::new(vec![+ // Grouped capital names+ // ... City+ Box::new(+ SequencePattern::default()+ .then(Box::new(EitherPattern::new(vec![+ Box::new(WordSet::all(&[+ "Belize",+ "Guatemala",+ "Kuwait",+ "Mexico",+ "Panama",+ "Vatican"+ ])),+ Box::new(+ SequencePattern::aco("Ho")+ .then_whitespace()+ .t_aco("Chi")+ .then_whitespace()+ .t_aco("Minh")+ )+ ])))+ .then_whitespace()+ .t_aco("City")+ ),+ // San ...+ Box::new(+ SequencePattern::aco("San")+ .then_whitespace()+ .then(Box::new(WordSet::all(&["Juan", "Marino", "Salvador"])))+ ),+ // St. ... TODO the period should be optional but this doesn't match even when it's not optional+ // Box::new(+ // SequencePattern::aco("St")+ // .then_period()+ // .then_whitespace()+ // .then(Box::new(WordSet::all(&["Helier", "John's", "Pierre"])))+ // ),+ // ... Town+ Box::new(+ SequencePattern::default()+ .then(Box::new(WordSet::all(&[+ "Cape", "George" // Cayman Islands+ ])))+ .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(+ SequencePattern::aco("Addis")+ .then_whitespace()+ .t_aco("Ababa")+ ),+ // Andorra la Vella has lowercase "la"+ Box::new(+ SequencePattern::aco("Bandar")+ .then_whitespace()+ .t_aco("Seri")+ .then_whitespace()+ .t_aco("Begawan")+ ),+ Box::new(+ SequencePattern::aco("Buenos")+ .then_whitespace()+ .t_aco("Aires")+ ),+ 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("New").then_whitespace().t_aco("Delhi")),+ Box::new(SequencePattern::aco("Pago").then_whitespace().t_aco("Pago")),+ Box::new(+ SequencePattern::aco("Phnom")+ .then_whitespace()+ .t_aco("Penh")+ ),+ 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"])))+ ),+ Box::new(SequencePattern::aco("Porto").then_hyphen().t_aco("Novo")),+ Box::new(SequencePattern::aco("Santo").then_hyphen().t_aco("Domingo")),+ Box::new(+ SequencePattern::aco("The")+ .then_whitespace()+ .then(Box::new(WordSet::all(&["Bahamas", "Hague"])))+ )+ ]),+ "When referring to national capitals, make sure to treat it as a proper noun."+);+create_linter_for!(ChineseCommunistParty,SequencePattern::aco("Chinese")