Implement __new__ for PostProcessors

Allows PostProcessors to be instansiated through python class constructor.
This commit is contained in:
Bjarte Johansen
2020-02-07 11:18:41 +01:00
parent 03508826cb
commit f32e0c09fc
3 changed files with 30 additions and 31 deletions

View File

@ -8,31 +8,31 @@ pub struct PostProcessor {
pub processor: Container<dyn tk::tokenizer::PostProcessor + Sync>,
}
#[pyclass]
#[pyclass(extends=PostProcessor)]
pub struct BertProcessing {}
#[pymethods]
impl BertProcessing {
#[staticmethod]
fn new(sep: (String, u32), cls: (String, u32)) -> PyResult<PostProcessor> {
Ok(PostProcessor {
#[new]
fn new(obj: &PyRawObject, sep: (String, u32), cls: (String, u32)) -> PyResult<()> {
Ok(obj.init(PostProcessor {
processor: Container::Owned(Box::new(tk::processors::bert::BertProcessing::new(
sep, cls,
))),
})
}))
}
}
#[pyclass]
#[pyclass(extends=PostProcessor)]
pub struct RobertaProcessing {}
#[pymethods]
impl RobertaProcessing {
#[staticmethod]
fn new(sep: (String, u32), cls: (String, u32)) -> PyResult<PostProcessor> {
Ok(PostProcessor {
#[new]
fn new(obj: &PyRawObject, sep: (String, u32), cls: (String, u32)) -> PyResult<()> {
Ok(obj.init(PostProcessor {
processor: Container::Owned(Box::new(tk::processors::roberta::RobertaProcessing::new(
sep, cls,
))),
})
}))
}
}
}