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

Confusion about "spellcheck" #76

Open
fankaiLiu opened this issue Sep 27, 2022 · 0 comments
Open

Confusion about "spellcheck" #76

fankaiLiu opened this issue Sep 27, 2022 · 0 comments
Labels
bug Something isn't working spellcheck

Comments

@fankaiLiu
Copy link

https://github.com/huacnlee/autocorrect/blob/main/autocorrect/src/spellcheck.rs

I encountered some confusion when using spellcheck。
The configuration file

spellcheck:
  # 0 - Disabled, 1 - Format and Lint, 2 - LintOnly
  mode: 1
  # Correct Words (Case insensitive) for by Spellcheck
  words:
    - 土豆=番茄

code

use autocorrect::{Config};

static DEFAULT_CONFIG_FILE: &str = "./.autocorrectrc";

fn main() {
	load_config(DEFAULT_CONFIG_FILE);
    println!("{}", spellcheck("土豆 土豆 土豆 土豆 土豆 土豆"));
}

pub fn load_config(config_file: &str) -> Config {
    return autocorrect::config::load_file(config_file).unwrap();
}

From my point of view, all potatoes should be replaced with tomatoes

But the output is ”番茄 土豆 番茄 土豆 番茄 土豆“

pub(crate) fn word_regexp(word: &str) -> Regex {
    let prefix = r#"([^\W]|[\p{Han}?!:,。;、]|$|^)"#;

    regexp!(
        r#"(?im){}([\s?!:,。;、]|^)+({})([\s?!:,。;、]|$)+{}"#,
        prefix,
        word.replace('-', r"\-").replace('.', r"\."),
        prefix
    )
}

I'm not sure what this rule does exactly, can a friend explain it?

@huacnlee huacnlee added bug Something isn't working spellcheck labels Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working spellcheck
Projects
None yet
Development

No branches or pull requests

2 participants