从此

🏠 » 📄文章 » 内容

 欢迎来访!

Quarkus 原生构建(native) houbb:segment 中文分词库并修复 heaven 库的读取资源类 StreamUtil

🕗2025-09-15👁️0

quarkus jvm 模式只要引入 com.github.houbb:segment 分词库即可,而 native 模式则要修改为:

    implementation("com.github.houbb:segment:0.3.1")
    implementation("com.github.houbb:segment-data-phrase-api:0.1.0")
    implementation("com.github.houbb:log-integration:1.1.8")


  并从jar包里解压出词库 segment_chinese_ts_char.txt, segment_emit_prob.txt, segment_phrase_dict_define.txt, segment_phrase_dict_system.txt,放置到 src\main\resources 下。

  quarkus.native.resources.includes=*.txt

【或】修改 native 构建时读取资源文件 StreamUtil 类源码

    public static List<String> readAllLines(final String path) {
        InputStream inputStream = StreamUtil.class.getResourceAsStream(path); // 非 src\main\resources 目录,则改动此处 path。
        return readAllLines(inputStream, CharsetConst.UTF8, true);
    }


reflection.json:

[
    {
        "name": "com.github.houbb.segment.support.segment.impl.Segment",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.impl.FastSegment",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.impl.PreciseSegment",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.mode.impl.precise.SearchSegmentMode",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.mode.impl.SingleSegmentMode",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.data.phrase.core.data.SegmentMixedPhraseData",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.data.pos.core.data.SegmentPosDataMixed",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.data.pos.core.model.SegmentPos",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.format.impl.HalfWidthSegmentFormat",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.format.impl.LowerCaseSegmentFormat",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },

    {
        "name": "com.github.houbb.segment.support.trie.impl.SegmentTrieTree",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.viterbi.Viterbi",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.format.impl.ChineseTsSegmentFormat",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.format.impl.NoneSegmentFormat",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.result.impl.SegmentResultHandlerWord",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.result.impl.SegmentResultHandler",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.tagging.pos.tag.impl.NoneSegmentPosTagging",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.tagging.pos.tag.impl.SimpleSegmentPosTagging",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.strategy.impl.SimpleSegmentStrategy",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.strategy.impl.TireTreeSegmentStrategy",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    },
    {
        "name": "com.github.houbb.segment.support.segment.strategy.impl.hmm.HmmSegmentStrategy",
        "queryAllPublicConstructors": true,
        "queryAllPublicMethods": true,
        "allPublicConstructors": true,
        "allPublicMethods": true
    }
]