@@ -23,7 +23,6 @@ pub fn module_path() -> PyResult<PathBuf> {
23
23
}
24
24
25
25
/// Bindings to Python
26
- /// //TODO support returning both lang+score
27
26
/// //TODO support parallel identification
28
27
/// //TODO support loading relevant languages from text
29
28
#[ pymethods]
@@ -39,19 +38,24 @@ impl Identifier {
39
38
Ok ( identifier)
40
39
}
41
40
41
+ /// Identify the language of a string
42
42
#[ pyo3( name = "identify" ) ]
43
43
fn py_identify ( & mut self , text : & str ) -> String {
44
44
self . identify ( text) . 0 . to_string ( )
45
45
}
46
46
47
- #[ pyo3( name = "identify_with_confidence" ) ]
48
- fn py_identify_with_confidence ( & mut self , text : & str ) -> ( String , f32 ) {
47
+ /// Identify the top-k most probable languages of a string and return the prediction scores.
48
+ /// This score is the confidence score (difference with the 2nd best)
49
+ /// or the raw score if ignore_confidence is enabled.
50
+ #[ pyo3( name = "identify_with_score" ) ]
51
+ fn py_identify_with_score ( & mut self , text : & str ) -> ( String , f32 ) {
49
52
let pred = self . identify ( text) ;
50
53
( pred. 0 . to_string ( ) , pred. 1 )
51
54
}
52
55
53
- #[ pyo3( name = "identify_topk_with_confidence" ) ]
54
- fn py_identify_topk_with_confidence ( & mut self , text : & str , k : usize ) -> Vec < ( String , f32 ) > {
56
+ /// Identify the language of a string and return the raw prediction score.
57
+ #[ pyo3( name = "identify_topk_with_score" ) ]
58
+ fn py_identify_topk_with_score ( & mut self , text : & str , k : usize ) -> Vec < ( String , f32 ) > {
55
59
let preds = self . identify_topk ( text, k) ;
56
60
let mut out = Vec :: < _ > :: with_capacity ( preds. len ( ) ) ;
57
61
for ( pred, conf) in preds {
0 commit comments