Skip to content

Commit

Permalink
fix: use FullDictionary on the web until workers are an option
Browse files Browse the repository at this point in the history
  • Loading branch information
elijah-potter committed Nov 25, 2024
1 parent 5a3b88e commit 1d70ba5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions harper-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use std::sync::Mutex;
use harper_core::language_detection::is_doc_likely_english;
use harper_core::linting::{LintGroup, LintGroupConfig, Linter};
use harper_core::parsers::{IsolateEnglish, Markdown, PlainEnglish};
use harper_core::{remove_overlaps, Document, FstDictionary, Lrc};
use harper_core::{remove_overlaps, Document, FullDictionary, Lrc};
use once_cell::sync::Lazy;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;

static LINTER: Lazy<Mutex<LintGroup<Lrc<FstDictionary>>>> = Lazy::new(|| {
static LINTER: Lazy<Mutex<LintGroup<Lrc<FullDictionary>>>> = Lazy::new(|| {
Mutex::new(LintGroup::new(
LintGroupConfig::default(),
FstDictionary::curated(),
FullDictionary::curated(),
))
});

Expand All @@ -32,13 +32,13 @@ pub fn setup() {
#[wasm_bindgen]
pub fn is_likely_english(text: String) -> bool {
let document = Document::new_plain_english_curated(&text);
is_doc_likely_english(&document, &FstDictionary::curated())
is_doc_likely_english(&document, &FullDictionary::curated())
}

/// Helper method to remove non-English text from a plain English document.
#[wasm_bindgen]
pub fn isolate_english(text: String) -> String {
let dict = FstDictionary::curated();
let dict = FullDictionary::curated();

let document = Document::new_curated(
&text,
Expand Down Expand Up @@ -67,7 +67,8 @@ pub fn lint(text: String) -> Vec<Lint> {
let source: Vec<_> = text.chars().collect();
let source = Lrc::new(source);

let document = Document::new_from_vec(source.clone(), &mut Markdown, &FstDictionary::curated());
let document =
Document::new_from_vec(source.clone(), &mut Markdown, &FullDictionary::curated());

let mut lints = LINTER.lock().unwrap().lint(&document);

Expand Down

0 comments on commit 1d70ba5

Please sign in to comment.