Skip to content

Commit fd74d7a

Browse files
danieldkDaniël de Kok
authored andcommitted
Add the static read_fasttext method
1 parent 3f76024 commit fd74d7a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/embeddings.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ impl PyEmbeddings {
5959
Ok(())
6060
}
6161

62+
/// read_fasttext(path,/)
63+
/// --
64+
///
65+
/// Read embeddings in the fasttext format.
66+
#[staticmethod]
67+
fn read_fasttext(path: &str) -> PyResult<PyEmbeddings> {
68+
read_non_fifu_embeddings(path, |r| Embeddings::read_fasttext(r))
69+
}
70+
6271
/// read_text(path,/)
6372
/// --
6473
///
@@ -338,9 +347,11 @@ where
338347
Ok(embeddings)
339348
}
340349

341-
fn read_non_fifu_embeddings<R>(path: &str, read_embeddings: R) -> PyResult<PyEmbeddings>
350+
fn read_non_fifu_embeddings<R, V>(path: &str, read_embeddings: R) -> PyResult<PyEmbeddings>
342351
where
343-
R: FnOnce(&mut BufReader<File>) -> ffio::Result<Embeddings<SimpleVocab, NdArray>>,
352+
R: FnOnce(&mut BufReader<File>) -> ffio::Result<Embeddings<V, NdArray>>,
353+
V: Vocab,
354+
Embeddings<VocabWrap, StorageViewWrap>: From<Embeddings<V, NdArray>>,
344355
{
345356
let f = File::open(path).map_err(|err| {
346357
exceptions::IOError::py_err(format!(

0 commit comments

Comments
 (0)