Implement synonym fetching

This commit is contained in:
Clément Renault 2020-01-16 11:38:23 +01:00
parent 5f9a3546e0
commit 9809ded23d
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -142,9 +142,19 @@ fn split_best_frequency<'a>(reader: &heed::RoTxn<MainT>, ctx: &Context, word: &'
} }
fn fetch_synonyms(reader: &heed::RoTxn<MainT>, ctx: &Context, words: &[&str]) -> MResult<Vec<Vec<String>>> { fn fetch_synonyms(reader: &heed::RoTxn<MainT>, ctx: &Context, words: &[&str]) -> MResult<Vec<Vec<String>>> {
let words = words.join(" "); // TODO ugly let words = words.join(" ");
// synonyms.synonyms(reader, words.as_bytes()).cloned().unwrap_or_default() let set = ctx.synonyms.synonyms(reader, words.as_bytes())?.unwrap_or_default();
Ok(vec![])
let mut strings = Vec::new();
let mut stream = set.stream();
while let Some(input) = stream.next() {
if let Ok(input) = std::str::from_utf8(input) {
let alts = input.split_ascii_whitespace().map(ToOwned::to_owned).collect();
strings.push(alts);
}
}
Ok(strings)
} }
fn is_last<I: IntoIterator>(iter: I) -> impl Iterator<Item=(bool, I::Item)> { fn is_last<I: IntoIterator>(iter: I) -> impl Iterator<Item=(bool, I::Item)> {