@@ -2,6 +2,7 @@ import 'dart:convert';
22import 'package:arabic_learning/vars/config_structure.dart' ;
33import 'package:archive/archive.dart' ;
44import 'package:flutter_tts/flutter_tts.dart' ;
5+ import 'package:logging/logging.dart' ;
56import 'package:path_provider/path_provider.dart' as path_provider;
67import 'package:arabic_learning/package_replacement/fake_dart_io.dart' if (dart.library.io) 'dart:io' as io;
78import 'package:arabic_learning/package_replacement/fake_sherpa_onnx.dart' if (dart.library.io) 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx;
@@ -263,6 +264,7 @@ class _RootPattern {
263264 /// 该模式对应的词性
264265 final ArabicPOS pos;
265266
267+ // ignore: unused_element_parameter
266268 _RootPattern (this .name, String pattern, this .pos, {this .groups = const [1 , 2 , 3 ]})
267269 : regex = RegExp (pattern);
268270}
@@ -392,8 +394,11 @@ class ArabicStemmer {
392394 if (s.length > 3 && (s.startsWith ('و' ) || s.startsWith ('ف' ))) s = s.substring (1 );
393395
394396 if (s.length > 4 ) {
395- if (s.endsWith ('ات' ) || s.endsWith ('ون' ) || s.endsWith ('ين' )) s = s.substring (0 , s.length - 2 );
396- else if (s.endsWith ('ي' )) s = s.substring (0 , s.length - 1 );
397+ if (s.endsWith ('ات' ) || s.endsWith ('ون' ) || s.endsWith ('ين' )) {
398+ s = s.substring (0 , s.length - 2 );
399+ } else if (s.endsWith ('ي' )) {
400+ s = s.substring (0 , s.length - 1 );
401+ }
397402 // 注意:这里去掉了对 'ه' (Ha) 的移除,因为我们不再把 'ة' 转为 'ه'
398403 // 如果 'ه' 是原生字母或代词后缀,仍需小心
399404 }
@@ -520,26 +525,25 @@ class VocabularyOptimizer {
520525
521526/// 1. 初始化: BKSearch.init(['ktb', 'maktaba', ...] );
522527/// 2. 搜索: var results = BKSearch.search('kitab');
528+ @immutable
523529class BKSearch {
524530 // 私有构造函数,防止外部实例化
525- BKSearch ._();
531+ const BKSearch ._();
526532
527533 // 单例实例
528534 static final VocabularyOptimizer _optimizer = VocabularyOptimizer ();
529535 static bool _isInitialized = false ;
530536
537+ static final Logger logger = Logger ("BKTree" );
538+
531539 /// [必须调用] 初始化搜索引擎
532540 /// 通常在 App 启动或加载词库时调用
533541 static void init (List <String > allWords) {
534542 if (_isInitialized) return ; // 避免重复初始化
535- print ("正在构建 BK-Tree 搜索索引,词库大小: ${allWords .length }..." );
536- final stopwatch = Stopwatch ()..start ();
537-
543+ logger.info ("正在构建 BK-Tree 搜索索引,词库大小: ${allWords .length }..." );
538544 _optimizer.build (allWords);
539-
540- stopwatch.stop ();
541545 _isInitialized = true ;
542- print ("BK-Tree 索引构建完成,耗时: ${ stopwatch . elapsedMilliseconds }ms " );
546+ logger. info ("BK-Tree 索引构建完成" );
543547 }
544548
545549 /// 普通搜索: 返回所有相似词列表
0 commit comments