review changes

This commit is contained in:
mpostma 2022-01-25 10:06:27 +01:00 committed by ad hoc
parent d0aabde502
commit 7541ab99cd
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643
3 changed files with 6 additions and 17 deletions

View File

@ -18,6 +18,3 @@ opt-level = 3
opt-level = 3 opt-level = 3
[profile.test.build-override] [profile.test.build-override]
opt-level = 3 opt-level = 3
[patch.crates-io]
fst = { path = "/Users/mpostma/Documents/code/rust/fst/" }

View File

@ -294,24 +294,18 @@ pub fn word_derivations<'c>(
let word = std::str::from_utf8(word)?; let word = std::str::from_utf8(word)?;
derived_words.push((word.to_string(), 0)); derived_words.push((word.to_string(), 0));
} }
} else { } else if fst.contains(word) {
let automaton = Str::new(word); derived_words.push((word.to_string(), 0));
let mut stream = fst.search(automaton).into_stream();
while let Some(word) = stream.next() {
let word = std::str::from_utf8(word)?;
derived_words.push((word.to_string(), 0));
}
} }
} else { } else {
if max_typo == 1 { if max_typo == 1 {
let dfa = build_dfa(word, 1, is_prefix); let dfa = build_dfa(word, 1, is_prefix);
let starts = Str::new(get_first(word)).starts_with(); let starts = Str::new(get_first(word)).starts_with();
let mut stream = fst.search_with_state(starts.intersection(&dfa)).into_stream(); let mut stream = fst.search(starts.intersection(&dfa)).into_stream();
while let Some((word, state)) = stream.next() { while let Some(word) = stream.next() {
let word = std::str::from_utf8(word)?; let word = std::str::from_utf8(word)?;
let distance = dfa.distance(state.1); derived_words.push((word.to_string(), 1));
derived_words.push((word.to_string(), distance.to_u8()));
} }
} else { } else {
let starts = Str::new(get_first(word)).starts_with(); let starts = Str::new(get_first(word)).starts_with();
@ -335,7 +329,7 @@ pub fn word_derivations<'c>(
fn get_first(s: &str) -> &str { fn get_first(s: &str) -> &str {
match s.chars().next() { match s.chars().next() {
Some(c) => &s[..c.len_utf8()], Some(c) => &s[..c.len_utf8()],
None => s, None => panic!("unexpected empty query"),
} }
} }

View File

@ -366,8 +366,6 @@ fn create_query_tree(
let mut operations = synonyms(ctx, &words)?.unwrap_or_default(); let mut operations = synonyms(ctx, &words)?.unwrap_or_default();
let concat = words.concat(); let concat = words.concat();
let query = Query { prefix: is_prefix, kind: typos(concat, true, 1) }; let query = Query { prefix: is_prefix, kind: typos(concat, true, 1) };
// let query =
// Query { prefix: is_prefix, kind: typos(concat, authorize_typos) };
operations.push(Operation::Query(query)); operations.push(Operation::Query(query));
and_op_children.push(Operation::or(false, operations)); and_op_children.push(Operation::or(false, operations));
} }