Repository navigation
Load data files from embedded resources by default - #4
Merged
Merged
Conversation
The 9 dictionary/model files are embedded in JiebaNet.Segmenter.dll and loaded via manifest resource streams, so no file system layout is required (Android/iOS/WASM friendly, AOT safe). When a custom config directory is set (ConfigManager.ConfigFileBaseDir or the JIEBA_CONFIG_FILE_DIR env var), files are read from that directory instead, keeping the existing customization story. The test suite now runs in embedded mode, plus dedicated ConfigManager mode tests.
The embedded resources are the only default source now, so the loose copies are no longer needed; tests that relied on them either read the embedded resources directly or use hermetic temp directories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
按之前讨论的方案,将 9 个数据文件(dict.txt、HMM/POS 模型、idf.txt、stopwords.txt 等)改为默认从程序集内嵌资源加载,自定义目录机制保留为覆盖手段。桌面用户零感知,Avalonia mobile(Android/iOS)等无文件系统布局的场景开箱即用。
变更
ConfigManager新增OpenResource(fileName)/ReadResourceText(fileName),默认通过 manifest resource stream 读取(无反射、NativeAOT 安全);HasCustomConfigFileDir指示当前模式。ConfigManager.ConfigFileBaseDir或环境变量JIEBA_CONFIG_FILE_DIR时,全部数据文件改为从磁盘读取(即原有的自定义词典覆盖场景);ConfigFileBaseDirgetter 语义不变(始终返回解析后的绝对路径)。WordDictionary.LoadDict、FinalSeg/Viterbi、PosSeg/Viterbi、PosSegmenter.LoadWordTagTab、KeywordExtractor(新增SetDefaultStopWords)、IdfLoader(新增内嵌加载构造器)。用户显式传路径的 API(LoadUserDict、SetStopWords(path)、SetNewPath、SetIdfPath)保持不变。Segmenter.csproj增加EmbeddedResource(保留复制到输出目录,供自定义目录模式开箱使用)。TestConfigManager覆盖两种模式的资源解析。验证