@@ -120,7 +120,7 @@ impl TokenList {
120120pub struct TokenizerWrapper {
121121tokenizer : Tokenizer ,
122122#[ borrows( tokenizer) ]
123- #[ not_covariant ]
123+ #[ covariant ]
124124worker : Worker < ' this > ,
125125}
126126
@@ -242,45 +242,45 @@ impl Vibrato {
242242/// :type out: vibrato.TokenList
243243#[ pyo3( text_signature ="($self, text, /)" ) ]
244244fn tokenize ( & mut self , py : Python , text : & str ) ->TokenList {
245- self . wrapper . with_mut ( |fields|{
246- fields. worker . reset_sentence ( text) ;
247- fields. worker . tokenize ( ) ;
248- let surface_cache =& mut self . surface_cache . borrow_mut ( ) ;
249- let feature_cache =& mut self . feature_cache . borrow_mut ( ) ;
250- TokenList {
251- tokens : fields
252- . worker
253- . token_iter ( )
254- . map ( |token|{
255- let surface = surface_cache
256- . raw_entry_mut ( )
257- . from_key ( token. surface ( ) )
258- . or_insert_with ( ||{
259- (
260- token. surface ( ) . to_string ( ) ,
261- PyUnicode :: new ( py, token. surface ( ) ) . into ( ) ,
262- )
263- } )
264- . 1
265- . clone_ref ( py) ;
266- let feature = feature_cache
267- . raw_entry_mut ( )
268- . from_key ( token. feature ( ) )
269- . or_insert_with ( ||{
270- (
271- token. feature ( ) . to_string ( ) ,
272- PyUnicode :: new ( py, token. feature ( ) ) . into ( ) ,
273- )
274- } )
275- . 1
276- . clone_ref ( py) ;
277- let start = token. range_char ( ) . start ;
278- let end = token. range_char ( ) . end ;
279- ( surface, start, end, feature)
245+ self . wrapper . with_worker_mut ( |worker|{
246+ worker. reset_sentence ( text) ;
247+ worker. tokenize ( ) ;
248+ } ) ;
249+ let surface_cache =& mut self . surface_cache . borrow_mut ( ) ;
250+ let feature_cache =& mut self . feature_cache . borrow_mut ( ) ;
251+ let tokens =self
252+ . wrapper
253+ . borrow_worker ( )
254+ . token_iter ( )
255+ . map ( |token|{
256+ let surface = surface_cache
257+ . raw_entry_mut ( )
258+ . from_key ( token. surface ( ) )
259+ . or_insert_with ( ||{
260+ (
261+ token. surface ( ) . to_string ( ) ,
262+ PyUnicode :: new ( py, token. surface ( ) ) . into ( ) ,
263+ )
280264} )
281- . collect ( ) ,
282- }
283- } )
265+ . 1
266+ . clone_ref ( py) ;
267+ let feature = feature_cache
268+ . raw_entry_mut ( )
269+ . from_key ( token. feature ( ) )
270+ . or_insert_with ( ||{
271+ (
272+ token. feature ( ) . to_string ( ) ,
273+ PyUnicode :: new ( py, token. feature ( ) ) . into ( ) ,
274+ )
275+ } )
276+ . 1
277+ . clone_ref ( py) ;
278+ let start = token. range_char ( ) . start ;
279+ let end = token. range_char ( ) . end ;
280+ ( surface, start, end, feature)
281+ } )
282+ . collect ( ) ;
283+ TokenList { tokens}
284284}
285285
286286/// Tokenize a given text and return as a list of surfaces.
@@ -290,28 +290,28 @@ impl Vibrato {
290290/// :type out: list[str]
291291#[ pyo3( text_signature ="($self, text, /)" ) ]
292292fn tokenize_to_surfaces ( & mut self , py : Python , text : & str ) ->Vec < Py < PyUnicode > > {
293- self . wrapper . with_mut ( |fields |{
294- fields . worker . reset_sentence ( text) ;
295- fields . worker . tokenize ( ) ;
296- let surface_cache = & mut self . surface_cache . borrow_mut ( ) ;
297- fields
298- . worker
299- . token_iter ( )
300- . map ( |token| {
301- surface_cache
302- . raw_entry_mut ( )
303- . from_key ( token . surface ( ) )
304- . or_insert_with ( || {
305- (
306- token . surface ( ) . to_string ( ) ,
307- PyUnicode :: new ( py , token. surface ( ) ) . into ( ) ,
308- )
309- } )
310- . 1
311- . clone_ref ( py )
312- } )
313- . collect ( )
314- } )
293+ self . wrapper . with_worker_mut ( |worker |{
294+ worker. reset_sentence ( text) ;
295+ worker. tokenize ( ) ;
296+ } ) ;
297+ let surface_cache = & mut self . surface_cache . borrow_mut ( ) ;
298+ self . wrapper
299+ . borrow_worker ( )
300+ . token_iter ( )
301+ . map ( |token| {
302+ surface_cache
303+ . raw_entry_mut ( )
304+ . from_key ( token . surface ( ) )
305+ . or_insert_with ( || {
306+ (
307+ token. surface ( ) . to_string ( ) ,
308+ PyUnicode :: new ( py , token . surface ( ) ) . into ( ) ,
309+ )
310+ } )
311+ . 1
312+ . clone_ref ( py )
313+ } )
314+ . collect ( )
315315}
316316}
317317