|
2 | 2 | use pyo3::prelude::*; |
3 | 3 | use tokenizations::{get_alignments, get_charmap, Alignment, CharMap}; |
4 | 4 |
|
| 5 | +#[pyfunction] |
| 6 | +#[pyo3(name = "get_alignments")] |
| 7 | +pub fn get_alignments_py( |
| 8 | + a: Vec<String>, |
| 9 | + b: Vec<String>, |
| 10 | +) -> PyResult<(Alignment, Alignment)> { |
| 11 | + let a_refs: Vec<&str> = a.iter().map(|s| s.as_str()).collect(); |
| 12 | + let b_refs: Vec<&str> = b.iter().map(|s| s.as_str()).collect(); |
| 13 | + Ok(get_alignments(&a_refs, &b_refs)) |
| 14 | +} |
| 15 | + |
| 16 | +#[pyfunction] |
| 17 | +#[pyo3(name = "get_charmap")] |
| 18 | +pub fn get_charmap_py(a: String, b: String) -> PyResult<(CharMap, CharMap)> { |
| 19 | + Ok(get_charmap(&a, &b)) |
| 20 | +} |
| 21 | + |
5 | 22 | #[pymodule] |
6 | 23 | #[pyo3(name = "tokenizations")] |
7 | | -fn tokenizations_(_py: Python, m: &PyModule) -> PyResult<()> { |
| 24 | +fn tokenizations_(m: &Bound<'_, PyModule>) -> PyResult<()> { |
8 | 25 | m.add("__version__", "0.9.1")?; |
9 | | - |
10 | | - #[pyfn(m)] |
11 | | - #[pyo3(name = "get_alignments")] |
12 | | - pub fn get_alignments_py( |
13 | | - _py: Python, |
14 | | - a: Vec<&str>, |
15 | | - b: Vec<&str>, |
16 | | - ) -> PyResult<(Alignment, Alignment)> { |
17 | | - Ok(get_alignments(&a, &b)) |
18 | | - } |
19 | | - |
20 | | - #[pyfn(m)] |
21 | | - #[pyo3(name = "get_charmap")] |
22 | | - pub fn get_charmap_py(_py: Python, a: &str, b: &str) -> PyResult<(CharMap, CharMap)> { |
23 | | - Ok(get_charmap(a, b)) |
24 | | - } |
25 | | - |
| 26 | + m.add_function(wrap_pyfunction!(get_alignments_py, m)?)?; |
| 27 | + m.add_function(wrap_pyfunction!(get_charmap_py, m)?)?; |
26 | 28 | Ok(()) |
27 | 29 | } |
0 commit comments