Skip to content

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

fix(core): auto detect dialect for snapshots (#1433)

Steve Kurchcdb438f5dd27
diff --git a/harper-core/src/word_metadata.rs b/harper-core/src/word_metadata.rs
index bc44be9b5..014c75812 100644
--- a/harper-core/src/word_metadata.rs
+++ b/harper-core/src/word_metadata.rs
@@ -1,12 +1,14 @@
use harper_brill::UPOS;
use is_macro::Is;
+use itertools::Itertools;
use paste::paste;
use serde::{Deserialize, Serialize};
-use strum_macros::{Display, EnumString};
+use strum::{EnumCount, VariantArray};
+use strum_macros::{Display, EnumCount, EnumString, VariantArray};
use std::convert::TryFrom;
-use crate::WordId;
+use crate::{Document, TokenKind, TokenStringExt, WordId};
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Hash)]
pub struct WordMetadata {
@@ -77,8 +79,7 @@ macro_rules! generate_metadata_queries {
[< is_ $sub >]: Some(true),
..
})
- )
- }
+ ) }
#[doc = concat!("Checks if the word is definitely a ", stringify!($category), " and more specifically is labeled as __not__ (a) ", stringify!($sub), ".")]
pub fn [< is_non_ $sub _ $category >](&self) -> bool {
@@ -704,7 +705,19 @@ impl ConjunctionData {
/// A regional dialect.
#[derive(
- Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash, EnumString, Display,
+ Debug,
+ Clone,
+ Copy,
+ Serialize,
+ Deserialize,
+ PartialEq,
+ PartialOrd,
+ Eq,
+ Hash,
+ EnumCount,
+ EnumString,
+ Display,
+ VariantArray,
)]
pub enum Dialect {
// Note: these have bit-shifted values so that they can ergonomically integrate with
@@ -715,6 +728,41 @@ pub enum Dialect {
Australian = 1 << 2,
British = 1 << 3,
}
+impl Dialect {
+ /// Tries to guess the dialect used in the document by finding which dialect is used the most.
+ /// Returns `None` if it fails to find a single dialect that is used the most.
+ #[must_use]
+ pub fn try_guess_from_document(document: &Document) -> Option<Self> {
+ Self::try_from(DialectFlags::get_most_used_dialects_from_document(document)).ok()
+ }
+
+ /// Tries to get a dialect from its abbreviation. Returns `None` if the abbreviation is not
+ /// recognized.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use harper_core::Dialect;
+ ///
+ /// let abbrs = ["US", "CA", "AU", "GB"];
+ /// let mut dialects = abbrs.iter().map(|abbr| Dialect::try_from_abbr(abbr));
+ ///
+ /// assert_eq!(Some(Dialect::American), dialects.next().unwrap()); // US
+ /// assert_eq!(Some(Dialect::Canadian), dialects.next().unwrap()); // CA
+ /// assert_eq!(Some(Dialect::Australian), dialects.next().unwrap()); // AU
+ /// assert_eq!(Some(Dialect::British), dialects.next().unwrap()); // GB
+ /// ```
+ #[must_use]
+ pub fn try_from_abbr(abbr: &str) -> Option<Self> {
+ match abbr {
+ "US" => Some(Self::American),
+ "CA" => Some(Self::Canadian),
+ "AU" => Some(Self::Australian),
+ "GB" => Some(Self::British),
+ _ => None,
+ }
+ }
+}
impl TryFrom<DialectFlags> for Dialect {
type Error = ();
@@ -790,6 +838,49 @@ impl DialectFlags {
};
out
}
+
+ /// Gets the most commonly used dialect(s) in the document.
+ ///
+ /// If multiple dialects are used equally often, they will all be enabled in the returned
+ /// `DialectFlags`. On the other hand, if there is a single dialect that is used the most, it
+ /// will be the only one enabled.
+ #[must_use]
+ pub fn get_most_used_dialects_from_document(document: &Document) -> Self {
+ // Initialize counters.
+ let mut dialect_counters: [(Dialect, usize); Dialect::COUNT] = Dialect::VARIANTS
+ .iter()
+ .map(|d| (*d, 0))
+ .collect_array()
+ .unwrap();
+
+ // Count word dialects.
+ document.iter_words().for_each(|w| {
+ if let TokenKind::Word(Some(word_metadata)) = &w.kind {
+ // If the token is a word, iterate though the dialects in `dialect_counters` and
+ // increment those counters where the word has the respective dialect enabled.
+ dialect_counters.iter_mut().for_each(|(dialect, count)| {
+ if word_metadata.dialects.is_dialect_enabled(*dialect) {
+ *count += 1;
+ }
+ });
+ }
+ });
+
+ // Find max counter.
+ let max_counter = dialect_counters
+ .iter()
+ .map(|(_, count)| count)
+ .max()
+ .unwrap();
+ // Get and convert the collection of most used dialects into a `DialectFlags`.
+ dialect_counters
+ .into_iter()
+ .filter(|(_, count)| count == max_counter)
+ .fold(DialectFlags::empty(), |acc, dialect| {
+ // Fold most used dialects into `DialectFlags` via bitwise or.
+ acc | Self::from_dialect(dialect.0)
+ })
+ }
}
impl Default for DialectFlags {
/// A default value with no dialects explicitly enabled.
@@ -811,6 +902,31 @@ mod tests {
.clone()
}
+ mod dialect {
+ use super::super::{Dialect, DialectFlags};
+ use crate::Document;
+
+ #[test]
+ fn guess_british_dialect() {
+ let document = Document::new_plain_english_curated("Aluminium was used.");
+ let df = DialectFlags::get_most_used_dialects_from_document(&document);
+ assert!(
+ df.is_dialect_enabled_strict(Dialect::British)
+ && !df.is_dialect_enabled_strict(Dialect::American)
+ );
+ }
+
+ #[test]
+ fn guess_american_dialect() {
+ let document = Document::new_plain_english_curated("Aluminum was used.");
+ let df = DialectFlags::get_most_used_dialects_from_document(&document);
+ assert!(
+ df.is_dialect_enabled_strict(Dialect::American)
+ && !df.is_dialect_enabled_strict(Dialect::British)
+ );
+ }
+ }
+
mod noun {
use crate::word_metadata::tests::md;
diff --git a/harper-core/tests/linters.rs b/harper-core/tests/linters.rs
index 19090209f..7ec4a3e40 100644
--- a/harper-core/tests/linters.rs
+++ b/harper-core/tests/linters.rs
@@ -1,4 +1,4 @@
-//! This test creats snapshots of the reports of all linters.
+//! This test creates snapshots of the reports of all linters.
//!
//! # Usage
//!
@@ -189,11 +189,16 @@ fn print_error(lines: &Lines, start: usize, end: usize, message: &str) -> String
#[test]
fn test_most_lints() {
- snapshot::snapshot_all_text_files("linters", ".snap.yml", |source| {
+ snapshot::snapshot_all_text_files("linters", ".snap.yml", |source, dialect_override| {
let dict = FstDictionary::curated();
let document = Document::new_markdown_default(source, &dict);
- let mut linter = LintGroup::new_curated(dict, Dialect::American);
+ let mut linter = LintGroup::new_curated(
+ dict,
+ dialect_override.unwrap_or_else(|| {
+ Dialect::try_guess_from_document(&document).unwrap_or(Dialect::American)
+ }),
+ );
let mut lints = linter.lint(&document);
lints.sort_by(|a, b| {
diff --git a/harper-core/tests/pos_tags.rs b/harper-core/tests/pos_tags.rs
index 6a381cb3d..654fad2bf 100644
--- a/harper-core/tests/pos_tags.rs
+++ b/harper-core/tests/pos_tags.rs
@@ -271,7 +271,7 @@ impl Formatter {
#[test]
fn test_pos_tagger() {
- snapshot::snapshot_all_text_files("tagged", ".md", |source| {
+ snapshot::snapshot_all_text_files("tagged", ".md", |source, _| {
let dict = FstDictionary::curated();
let document = Document::new_markdown_default(source, &dict);
diff --git a/harper-core/tests/snapshot.rs b/harper-core/tests/snapshot.rs
index 9d9b356de..70aaf4d23 100644
--- a/harper-core/tests/snapshot.rs
+++ b/harper-core/tests/snapshot.rs
@@ -3,6 +3,7 @@ use std::{
path::{Path, PathBuf},
};
+use harper_core::Dialect;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
fn get_tests_dir() -> PathBuf {
@@ -12,6 +13,25 @@ fn get_text_dir() -> PathBuf {
get_tests_dir().join("text")
}
+/// Tries to find a dialect override from a given file path. Returns `None` if the number of
+/// dialect overrides found is not 1.
+#[must_use]
+fn try_get_dialect_override(path: &Path) -> Option<Dialect> {
+ let file_name = path.file_stem()?;
+ let mut dialect_overrides: Vec<_> = file_name
+ .to_string_lossy()
+ .split('.')
+ .map(Dialect::try_from_abbr)
+ .filter(Option::is_some)
+ .collect();
+ if dialect_overrides.len() == 1 {
+ dialect_overrides.pop().unwrap()
+ } else {
+ // If we find multiple overrides, it's unlikely that a dialect override is intended.
+ None
+ }
+}
+
pub fn get_text_files() -> Vec<PathBuf> {
let mut files = vec![];
for entry in std::fs::read_dir(get_text_dir())
@@ -34,10 +54,11 @@ pub fn get_text_files() -> Vec<PathBuf> {
fn tag_file(
text_file: &Path,
snapshot_file: &Path,
- create_snapshot: impl Fn(&str) -> String,
+ create_snapshot: impl Fn(&str, Option<Dialect>) -> String,
) -> Result<(), Box<dyn std::error::Error>> {
let source = std::fs::read_to_string(text_file)?.replace("\r\n", "\n");
- let tagged = create_snapshot(source.trim_end());
+ let dialect_override = try_get_dialect_override(text_file);
+ let tagged = create_snapshot(source.trim_end(), dialect_override);
// compare with snapshot
let has_snapshot = snapshot_file.exists();
@@ -65,7 +86,7 @@ fn get_snapshot_file(text_file: &Path, snapshot_dir: &Path, ext: &str) -> PathBu
pub fn snapshot_all_text_files(
out_dir: &str,
snapshot_ext: &str,
- create_snapshot: impl Copy + Fn(&str) -> String + 'static + Sync,
+ create_snapshot: impl Copy + Fn(&str, Option<Dialect>) -> String + 'static + Sync,
) {
let snapshot_dir = get_text_dir().join(out_dir);
std::fs::create_dir_all(&snapshot_dir).expect("Failed to create snapshot directory");
diff --git a/harper-core/tests/text/Spell.US.md b/harper-core/tests/text/Spell.US.md
new file mode 100644
index 000000000..ac7bcd29a
--- /dev/null
+++ b/harper-core/tests/text/Spell.US.md
@@ -0,0 +1,23 @@
+# Spell
+
+This document contains a list of words spelled correctly in some dialects of English, but not American English. This is designed to test the spelling suggestions we give for such mistakes.
+
+To achieve this, the filename of this file contains `.US.`, which will tell the snapshot generator to use the American dialect, rather than trying to use an automatically detected dialect.
+
+## Words
+
+- Afterwards.
+- Centre.
+- Labelled.
+- Flavour.
+- Favoured.
+- Honour.
+- Grey.
+- Quarrelled.
+- Quarrelling.
+- Recognised.
+- Neighbour.
+- Neighbouring.
+- Clamour.
+- Theatre.
+- Analyse.
diff --git a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
index 1d26da86f..946c211bf 100644
--- a/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
+++ b/harper-core/tests/text/linters/Alice's Adventures in Wonderland.snap.yml
@@ -45,18 +45,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 21 | be late!” (when she thought it over afterwards, it occurred to her that she
- | ^~~~~~~~~~ Did you mean to spell `afterwards` this way?
- 22 | ought to have wondered at this, but at the time it all seemed quite natural);
-Suggest:
- - Replace with: “afterward”
- - Replace with: “afterwords”
- - Replace with: “afterword's”
-
-
-
Lint: Readability (127 priority)
Message: |
39 | next. First, she tried to look down and make out what she was coming to, but it
@@ -85,29 +73,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 43 | shelves as she passed; it was labelled “ORANGE MARMALADE”, but to her great
- | ^~~~~~~~ Did you mean to spell `labelled` this way?
-Suggest:
- - Replace with: “labeled”
- - Replace with: “labeler”
- - Replace with: “labelless”
-
-
-
-Lint: Spelling (63 priority)
-Message: |
- 54 | I’ve fallen by this time?” she said aloud. “I must be getting somewhere near the
- 55 | centre of the earth. Let me see: that would be four thousand miles down, I
- | ^~~~~~ Did you mean to spell `centre` this way?
-Suggest:
- - Replace with: “center”
- - Replace with: “censure”
- - Replace with: “cent”
-
-
-
Lint: Readability (127 priority)
Message: |
55 | centre of the earth. Let me see: that would be four thousand miles down, I
@@ -309,18 +274,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 138 | finding it very nice, (it had, in fact, a sort of mixed flavour of cherry-tart,
- | ^~~~~~~ Did you mean to spell `flavour` this way?
- 139 | custard, pine-apple, roast turkey, toffee, and hot buttered toast,) she very
-Suggest:
- - Replace with: “flavor”
- - Replace with: “favor”
- - Replace with: “flour”
-
-
-
Lint: Readability (127 priority)
Message: |
146 | door into that lovely garden. First, however, she waited for a few minutes to
@@ -789,18 +742,6 @@ Suggest:
-Lint: Spelling (63 priority)
-Message: |
- 387 | driest thing I know. Silence all round, if you please! ‘William the Conqueror,
- 388 | whose cause was favoured by the pope, was soon submitted to by the English, who
- | ^~~~~~~~ Did you mean to spell `favoured` this way?
-Suggest:
- - Replace with: “favored”
- - Replace with: “flavored”
- - Replace with: “floured”
-
-
-
Lint: Spelling (63 priority)
Message: |
390 | Edwin and Morcar, the earls of Mercia and Northumbria—’”
@@ -1063,29 +1004,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 660 | voice she had never heard before, “Sure then I’m here! Digging for apples, yer
- 661 | honour!”
- | ^~~~~~ Did you mean to spell `honour` this way?
-Suggest:
- - Replace with: “honor”
- - Replace with: “hour”
- - Replace with: “honer”
-
-
-
-Lint: Spelling (63 priority)
-Message: |
- 668 | “Sure, it’s an arm, yer honour!” (He pronounced it “arrum.”)
- | ^~~~~~ Did you mean to spell `honour` this way?
-Suggest:
- - Replace with: “honor”
- - Replace with: “hour”
- - Replace with: “honer”
-
-
-
Lint: Spelling (63 priority)
Message: |
668 | “Sure, it’s an arm, yer honour!” (He pronounced it “arrum.”)
@@ -1097,28 +1015,6 @@ Suggest:
-Lint: Spelling (63 priority)
-Message: |
- 672 | “Sure, it does, yer honour: but it’s an arm for all that.”
- | ^~~~~~ Did you mean to spell `honour` this way?
-Suggest:
- - Replace with: “honor”
- - Replace with: “hour”
- - Replace with: “honer”
-
-
-
-Lint: Spelling (63 priority)
-Message: |
- 677 | then; such as, “Sure, I don’t like it, yer honour, at all, at all!” “Do as I
- | ^~~~~~ Did you mean to spell `honour` this way?
-Suggest:
- - Replace with: “honor”
- - Replace with: “hour”
- - Replace with: “honer”
-
-
-
Lint: Capitalization (31 priority)
Message: |
688 | one; Bill’s got the other—Bill! fetch it here, lad!—Here, put ’em up at this
@@ -1305,18 +1201,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 884 | > “In my youth,” said the sage, as he shook his grey locks, “I kept all my limbs
- | ^~~~ Did you mean to spell `grey` this way?
- 885 | > very supple By the use of this ointment—one shilling the box— Allow me to sell
-Suggest:
- - Replace with: “gray”
- - Replace with: “grew”
- - Replace with: “grep”
-
-
-
Lint: Miscellaneous (31 priority)
Message: |
929 | “It is a very good height indeed!” said the Caterpillar angrily, rearing itself
@@ -1708,17 +1592,6 @@ Suggest:
-Lint: Spelling (63 priority)
-Message: |
- 1497 | The Hatter shook his head mournfully. “Not I!” he replied. “We quarrelled last
- | ^~~~~~~~~~ Did you mean to spell `quarrelled` this way?
- 1498 | March—just before he went mad, you know—” (pointing with his tea spoon at the
-Suggest:
- - Replace with: “quarreled”
- - Replace with: “quarreler”
-
-
-
Lint: WordChoice (63 priority)
Message: |
1498 | March—just before he went mad, you know—” (pointing with his tea spoon at the
@@ -1845,18 +1718,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 1713 | they were all ornamented with hearts. Next came the guests, mostly Kings and
- 1714 | Queens, and among them Alice recognised the White Rabbit: it was talking in a
- | ^~~~~~~~~~ Did you mean to spell `recognised` this way?
-Suggest:
- - Replace with: “recognized”
- - Replace with: “recognize”
- - Replace with: “recognizer”
-
-
-
Lint: Readability (127 priority)
Message: |
1720 | Alice was rather doubtful whether she ought not to lie down on her face like the
@@ -1952,16 +1813,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 1832 | The players all played at once without waiting for turns, quarrelling all the
- | ^~~~~~~~~~~ Did you mean `quarreling`?
- 1833 | while, and fighting for the hedgehogs; and in a very short time the Queen was in
-Suggest:
- - Replace with: “quarreling”
-
-
-
Lint: Miscellaneous (31 priority)
Message: |
1840 | people here; the great wonder is, that there’s any one left alive!”
@@ -2221,17 +2072,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 2048 | But here, to Alice’s great surprise, the Duchess’s voice died away, even in the
- 2049 | middle of her favourite word ‘moral,’ and the arm that was linked into hers
- | ^~~~~~~~~ Did you mean to spell `favourite` this way?
-Suggest:
- - Replace with: “favorite”
- - Replace with: “favorites”
-
-
-
Lint: Readability (127 priority)
Message: |
2064 | The other guests had taken advantage of the Queen’s absence, and were resting in
@@ -2243,16 +2083,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 2068 | All the time they were playing the Queen never left off quarrelling with the
- | ^~~~~~~~~~~ Did you mean `quarreling`?
- 2069 | other players, and shouting “Off with his head!” or “Off with her head!” Those
-Suggest:
- - Replace with: “quarreling”
-
-
-
Lint: Readability (127 priority)
Message: |
2069 | other players, and shouting “Off with his head!” or “Off with her head!” Those
@@ -3293,17 +3123,6 @@ Suggest:
-Lint: Spelling (63 priority)
-Message: |
- 2547 | even make out that one of them didn’t know how to spell “stupid,” and that he
- 2548 | had to ask his neighbour to tell him. “A nice muddle their slates’ll be in
- | ^~~~~~~~~ Did you mean to spell `neighbour` this way?
-Suggest:
- - Replace with: “neighbor”
- - Replace with: “neighbors”
-
-
-
Lint: Spelling (63 priority)
Message: |
2548 | had to ask his neighbour to tell him. “A nice muddle their slates’ll be in
@@ -3474,17 +3293,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 2929 | “No, no!” said the Queen. “Sentence first—verdict afterwards.”
- | ^~~~~~~~~~ Did you mean to spell `afterwards` this way?
-Suggest:
- - Replace with: “afterward”
- - Replace with: “afterwords”
- - Replace with: “afterword's”
-
-
-
Lint: Readability (127 priority)
Message: |
2943 | At this the whole pack rose up into the air, and came flying down upon her: she
@@ -3584,17 +3392,6 @@ Message: |
-Lint: Spelling (63 priority)
-Message: |
- 2972 | The long grass rustled at her feet as the White Rabbit hurried by—the frightened
- 2973 | Mouse splashed his way through the neighbouring pool—she could hear the rattle
- | ^~~~~~~~~~~~ Did you mean `neighboring`?
- 2974 | of the teacups as the March Hare and his friends shared their never-ending meal,
-Suggest:
- - Replace with: “neighboring”
-
-
-
Lint: Spelling (63 priority)
Message: |
2977 | plates and dishes crashed around it—once more the shriek of the Gryphon, the
@@ -3638,18 +3435,6 @@ Suggest:
-Lint: Spelling (63 priority)
-Message: |
- 2988 | noises, would change (she knew) to the confused clamour of the busy
- | ^~~~~~~ Did you mean to spell `clamour` this way?
- 2989 | farm-yard—while the lowing of the cattle in the distance would take the place of
-Suggest:
- - Replace with: “clamor”
- - Replace with: “glamour”
- - Replace with: “clamber”
-
-
-
Lint: Readability (127 priority)
Message: |
2992 | Lastly, she pictured to herself how this same little sister of hers would, in
diff --git a/harper-core/tests/text/linters/Spell.US.snap.yml b/harper-core/tests/text/linters/Spell.US.snap.yml
new file mode 100644
index 000000000..226e97a78
--- /dev/null
+++ b/harper-core/tests/text/linters/Spell.US.snap.yml
@@ -0,0 +1,149 @@
+Lint: Spelling (63 priority)
+Message: |
+ 9 | - Afterwards.
+ | ^~~~~~~~~~ Did you mean to spell `Afterwards` this way?
+Suggest:
+ - Replace with: “Afterward”
+ - Replace with: “Afterwords”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 10 | - Centre.
+ | ^~~~~~ Did you mean to spell `Centre` this way?
+Suggest:
+ - Replace with: “Entire”
+ - Replace with: “Entry”
+ - Replace with: “Genre”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 11 | - Labelled.
+ | ^~~~~~~~ Did you mean to spell `Labelled` this way?
+Suggest:
+ - Replace with: “Labeled”
+ - Replace with: “Belled”
+ - Replace with: “Rebelled”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 12 | - Flavour.
+ | ^~~~~~~ Did you mean to spell `Flavour` this way?
+Suggest:
+ - Replace with: “Flavor”
+ - Replace with: “Cavour”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 13 | - Favoured.
+ | ^~~~~~~~ Did you mean to spell `Favoured` this way?
+Suggest:
+ - Replace with: “Favored”
+ - Replace with: “Devoured”
+ - Replace with: “Savored”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 14 | - Honour.
+ | ^~~~~~ Did you mean to spell `Honour` this way?
+Suggest:
+ - Replace with: “Honor”
+ - Replace with: “Concur”
+ - Replace with: “Contour”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 15 | - Grey.
+ | ^~~~ Did you mean to spell `Grey` this way?
+Suggest:
+ - Replace with: “Gorey”
+ - Replace with: “Greg”
+ - Replace with: “Trey”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 16 | - Quarrelled.
+ | ^~~~~~~~~~ Did you mean `Quarreled`?
+Suggest:
+ - Replace with: “Quarreled”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 17 | - Quarrelling.
+ | ^~~~~~~~~~~ Did you mean `Quarreling`?
+Suggest:
+ - Replace with: “Quarreling”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 18 | - Recognised.
+ | ^~~~~~~~~~ Did you mean `Recognized`?
+Suggest:
+ - Replace with: “Recognized”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 19 | - Neighbour.
+ | ^~~~~~~~~ Did you mean `Neighbor`?
+Suggest:
+ - Replace with: “Neighbor”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 20 | - Neighbouring.
+ | ^~~~~~~~~~~~ Did you mean `Neighboring`?
+Suggest:
+ - Replace with: “Neighboring”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 21 | - Clamour.
+ | ^~~~~~~ Did you mean to spell `Clamour` this way?
+Suggest:
+ - Replace with: “Clamor”
+ - Replace with: “Glamour”
+ - Replace with: “Cavour”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 22 | - Theatre.
+ | ^~~~~~~ Did you mean `Sheathe`?
+Suggest:
+ - Replace with: “Sheathe”
+
+
+
+Lint: Spelling (63 priority)
+Message: |
+ 23 | - Analyse.
+ | ^~~~~~~ Did you mean `Analyze`?
+Suggest:
+ - Replace with: “Analyze”
+
+
+
diff --git a/harper-core/tests/text/tagged/Spell.US.md b/harper-core/tests/text/tagged/Spell.US.md
new file mode 100644
index 000000000..0e312a7fd
--- /dev/null
+++ b/harper-core/tests/text/tagged/Spell.US.md
@@ -0,0 +1,78 @@
+> Spell
+# NSg/V
+>
+#
+> This document contains a list of words spelled correctly in some dialects of English , but not American English . This is designed to test the spelling suggestions we give for such mistakes .
+# I/Ddem+ NSg/V V D/P NSg/V P NPl/V+ V/J R NPr/J/P I/J/R NPl P NPr/V/J+ . NSg/C/P NSg/C NPr/J+ NPr/V/J+ . I/Ddem+ VL V/J P NSg/V D+ NSg/V+ NPl+ IPl+ NSg/V C/P NSg/I+ NPl/V+ .
+>
+#
+> To achieve this , the filename of this file contains `.US , which will tell the snapshot generator to use the American dialect , rather than trying to use an automatically detected dialect .
+# P V I/Ddem . D NSg P I/Ddem+ NSg/V+ V Unlintable . I/C+ NPr/VX NPr/V D+ NSg/V+ NSg P NSg/V D+ NPr/J+ NSg+ . NPr/V/J C/P NSg/V/J P NSg/V D/P W? V/J NSg+ .
+>
+#
+> Words
+# NPl/V
+>
+#
+>
+#
+>
+#
+> Afterwards .
+# R/Ca/Au/Br .
+>
+#
+> Centre .
+# NSg/V/Ca/Au/Br+ .
+>
+#
+> Labelled .
+# V/J/Ca/Au/Br+ .
+>
+#
+> Flavour .
+# NSg/V/Ca/Au/Br+ .
+>
+#
+> Favoured .
+# V/J/Ca/Au/Br+ .
+>
+#
+> Honour .
+# NSg/V/Ca/Au/Br+ .
+>
+#
+> Grey .
+# NPr/V/J/Ca/Au/Br+ .
+>
+#
+> Quarrelled .
+# V/Ca/Au/Br+ .
+>
+#
+> Quarrelling .
+# NSg/V/Ca/Au/Br+ .
+>
+#
+> Recognised .
+# V/J/Au/Br+ .
+>
+#
+> Neighbour .
+# NSg/V/J/Ca/Au/Br+ .
+>
+#
+> Neighbouring .
+# V/Ca/Au/Br+ .
+>
+#
+> Clamour .
+# NSg/V/Ca/Au/Br+ .
+>
+#
+> Theatre .
+# NSg/Ca/Au/Br+ .
+>
+#
+> Analyse .
+# V/Au/Br .