{"id":19096993,"url":"https://github.com/lionsoul2014/friso","last_synced_at":"2025-04-05T07:01:22.249Z","repository":{"id":15546207,"uuid":"18281156","full_name":"lionsoul2014/friso","owner":"lionsoul2014","description":"High performance Chinese tokenizer with both GBK and UTF-8 charset support based on MMSEG algorithm developed by ANSI C.  Completely based on modular implementation and can be easily embedded in other programs, like: MySQL, PostgreSQL, PHP, etc.","archived":false,"fork":false,"pushed_at":"2023-10-29T19:35:45.000Z","size":3220,"stargazers_count":496,"open_issues_count":7,"forks_count":91,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-03-29T06:01:33.190Z","etag":null,"topics":["c","chinese-tokenizer","chinese-word-segmentation","cjk-tokenizer","full-text-search","japanese-tokenizer","korean-tokenizer","php-tokenizer","tokenizer"],"latest_commit_sha":null,"homepage":"http://gitee.com/lionsoul/friso","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lionsoul2014.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-31T03:54:16.000Z","updated_at":"2025-03-23T08:53:39.000Z","dependencies_parsed_at":"2022-08-31T15:41:32.432Z","dependency_job_id":"c95b715f-9ca8-4810-9c25-0e9d48f1d181","html_url":"https://github.com/lionsoul2014/friso","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionsoul2014%2Ffriso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionsoul2014%2Ffriso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionsoul2014%2Ffriso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionsoul2014%2Ffriso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lionsoul2014","download_url":"https://codeload.github.com/lionsoul2014/friso/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299828,"owners_count":20916190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","chinese-tokenizer","chinese-word-segmentation","cjk-tokenizer","full-text-search","japanese-tokenizer","korean-tokenizer","php-tokenizer","tokenizer"],"created_at":"2024-11-09T03:38:24.546Z","updated_at":"2025-04-05T07:01:22.194Z","avatar_url":"https://github.com/lionsoul2014.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# **Friso**是什么？\n\nFriso 是使用 c 语言开发的一款开源的高性能中文分词器，使用流行的mmseg算法实现。完全基于模块化设计和实现，可以很方便的植入其他程序中，\n例如：MySQL，PHP，并且提供了php5, php7, ocaml, lua的插件实现。源码无需修改就能在各种平台下编译使用，加载完 20 万的词条，内存占用稳定为 14.5M.\n\n\n# **Friso**核心功能：\n\n- [x] 中文分词：mmseg算法 + **Friso** 独创的优化算法，四种切分模式。\n- [ ] 关键字提取：基于textRank算法。\n- [ ] 关键短语提取：基于textRank算法。\n- [ ] 关键句子提取：基于textRank算法。\n\n\n# **Friso**中文分词：\n\n### 四种切分模式：\n\n- [x] 简易模式：FMM 算法，适合速度要求场合。\n- [x] 复杂模式- MMSEG 四种过滤算法，具有较高的岐义去除，分词准确率达到了98.41%。\n- [x] 检测模式：只返回词库中已有的词条，很适合某些应用场合。(1.6.1版本开始)。\n- [ ] 最多模式：细粒度切分，专为检索而生，除了中文处理外（不具备中文的人名，数字识别等智能功能）其他与复杂模式一致（英文，组合词等）。\n\n### 分词功能特性：\n- [x] 同时支持对 UTF-8/GBK 编码的切分，支持 php5 和 php7 扩展和 sphinx token 插件。\n- [x] 支持自定义词库。在 dict 文件夹下，可以随便添加/删除/更改词库和词库词条，并且对词库进行了分类。\n- [x] 简体/繁体/简体混合支持, 可以方便的针对简体，繁体或者简繁体切分。同时还可以以此实现简繁体的相互检索。\n- [x] 支持中英/英中混合词的识别(维护词库可以识别任何一种组合)。例如：卡拉ok, 漂亮mm, c语言，IC卡，哆啦a梦。\n- [x] 很好的英文支持，英文标点组合词识别, 例如c++, c#, 电子邮件，网址，小数，百分数。\n- [x] 自定义保留标点：你可以自定义保留在切分结果中的标点，这样可以识别出一些复杂的组合，例如：c++, k\u0026r，code.google.com。\n- [x] 复杂英文切分的二次切分：默认 Friso 会保留数字和字母的原组合，开启此功能，可以进行二次切分提高检索的命中率。例如：qq2013会被切分成：qq/ 2013/ qq2013。\n- [x] 支持阿拉伯数字/小数基本单字单位的识别，例如2012年，1.75米，5吨，120斤，38.6℃。\n- [x] 自动英文圆角/半角，大写/小写转换。\n- [x] 同义词匹配：自动中文/英文同义词追加. (需要在 friso.ini 中开启 friso.add_syn 选项)。\n- [x] 自动中英文停止词过滤。(需要在 friso.ini 中开启 friso.clr_stw 选项)。\n- [x] 多配置支持, 安全的应用于多进程/多线程环境。\n\n\n# **Friso**快速体验：\n\n#### 终端测试：\n\n1. cd到 **Friso**根目录。\n2. make\n3. 运行：./src/friso -init ./friso.ini\n4. 你将看到类似如下的终端界面\n5. 在光标处输入文本开始测试\n\n```\nInitialized in 0.088911sec\nMode: Complex\n+-Version: 1.6.2 (UTF-8)\n+---------------------------------------------------------------+\n| Friso - a Chinese word segmentation writen by c.              |\n| bug report email - chenxin619315@gmail.com.                   |\n| or: visit https://github.com/lionsoul2014/friso.              |\n|     java edition for https://github.com/lionsoul2014/jcseg    |\n| type 'quit' to exit the program.                              |\n+---------------------------------------------------------------+\nfriso\u003e\u003e \n```\n\n#### 测试样板：\n\n##### 分词文本\n\n~~~text\n歧义和同义词:研究生命起源，混合词: 做B超检查身体，x射线本质是什么，今天去奇都ktv唱卡拉ok去，哆啦a梦是一个动漫中的主角，单位和全角: 2009年８月６日开始大学之旅，岳阳今天的气温为38.6℃, 也就是101.48℉, 英文数字: bug report example@gmail.com or visit http://code.google.com/p/jcseg, we all admire the hacker spirit!特殊数字: ① ⑩ ⑽ ㈩.\n~~~\n\n##### 分词结果：\n\n~~~text\n歧义 和 同义词 : 研究 琢磨 研讨 钻研 生命 起源 ， 混合词 : 做 b超 检查 身体 ， x射线 本质 是 什么 ， 今天 去 奇都ktv 唱 卡拉ok 去 ， 哆啦a梦 是 一个 动漫 中 的 主角 ， 单位 和 全角 : 2009年 8月 6日 开始 大学 之旅 ， 岳阳 今天 的 气温 为 38.6℃ , 也就是 101.48℉ , 英文 英语 数字 : bug report example gmail com example@gmail.com or visit http : / / code google com code.google.com / p / jcseg , we all admire appreciate like love enjoy the hacker spirit mind ! 特殊 数字 : .\n~~~\n\n\n\n# Friso安装\n\n### Linux:\ncd到friso的根目录，运行：\n```shell\nmake\nsudo make install\n\n# for testing\nmake testing\n```\n备注：如果是 64 位的系统，请将/usr/lib/libfriso.so 拷贝一份到/usr/lib64 中\n\n### Winnt:\n1. 使用 VS 编译得到 dll 和 lib 文件，具体可以参考 Friso 讨论：http://www.oschina.net/question/853816_135216\n2. 使用 cygwin 从源码编译； 删除原有的 Makefile, 更改 Makefile.cygwin 为 Makefile, 打开 cygwin 的终端，cd 到 Friso 的 src 目录，运行:\n```shell\nmake\n```\n备注：在Friso的src目录下即可得到friso.exe和friso.dll文件。\n\n\n\n\n# Friso配置\nFriso 要做的配置工作很简单，找到 friso.ini 配置文件, 使用文本编辑器打开即可\n\n### 配置说明：\n\n```\n# friso configuration file.\n#\tdo not change the name of the left key.\n# @email\tchenxin619315@gmail.com\n# @date\t\t2012-12-20\n#\n\n# charset, only UTF8 and GBK support.\n# set it with UTF8(0) or GBK(1)\nfriso.charset = 0\n\n# lexicon directory absolute path.\n#\tthe value must end with '/'\n# this will tell friso how to find friso.lex.ini configuration file and all the lexicon files.\n#\n# if it is not start with '/' for linux, or matches no ':' for winnt in its value \n#\tfriso will search the friso.lex.ini relative to friso.ini\n# absolute path search:\n# linux:\tfriso.lex_dir = /c/products/friso/dict/UTF-8/\n# Winnt:\tfriso.lex_dir = D:/products/friso/dict/UTF-8/\n# relative path search (All system)\nfriso.lex_dir = ./vendors/dict/UTF-8/\n\n# the maximum matching length.\nfriso.max_len = 5 \n\n# 1 for recognition chinese name.\n#\tand 0 for closed it.\nfriso.r_name = 1\n\n# the maximum length for the cjk words in a\n#\tchinese and english mixed word.\nfriso.mix_len = 2\n\n# the maxinum length for the chinese last name adron.\nfriso.lna_len = 1\n\n# append the synonyms words\nfriso.add_syn = 1\n\n# clear the stopwords or not (1 to open it and 0 to close it)\n# @date 2013-06-13\nfriso.clr_stw = 0\n\n# keep the unrecongized words or not (1 to open it and 0 to close it)\n# @date 2013-06-13\nfriso.keep_urec = 0\n\n# use sphinx output style like 'admire|love|enjoy einsten'\n# @date 2013-10-25\nfriso.spx_out = 0\n\n# start the secondary segmentation for complex english token.\nfriso.en_sseg = 1\n\n# min length of the secondary segmentation token. (better larger than 1)\nfriso.st_minl = 2\n\n# default keep punctuations for english token.\nfriso.kpuncs = @%.#\u0026+\n\n# the threshold value for a char not a part of a chinese name.\nfriso.nthreshold = 2000000\n\n# default mode for friso.\n# 1 : simple mode - simply maxmum matching algorithm.\n# 2 : complex mode - four rules of mmseg alogrithm.\n# 3 : detect mode - only return the words that the do exists in the lexicon\nfriso.mode = 2\n```\n\n### 词库的配置：\n\n1. friso.ini中 friso.lex_dir 指向friso依赖的词库目录, 修改其值为词库目录绝对地址, 并且必须以”/”结尾。例如：friso.lex_dir = /usr/lib/friso/dict/\n2. 词库分为UTF-8和GBK编码的，根据你使用的编码需要选择加载对应编码的词库。\n\n\n\n\n# Friso插件\n\nFriso目前提供了对php5, php7, ocaml, lua的分词插件：\n\n语言 | binding | 作者 | 状态\n:-: | :-: | :-: | :-:\nphp | [php5-binding](binding/php5) | dongyado\u0026lt;dongyado@gmail.com\u0026gt; | 已完成\nphp | [php7-binding](binding/php7) | dongyado\u0026lt;dongyado@gmail.com\u0026gt; | 已完成\nocaml | [ocaml-binding](binding/ocaml) | https://github.com/kandu | 已完成\nsphinx | [sphinx-binding](binding/sphinx) | lionsoul\u0026lt;chenxin619315@gmail.com\u0026gt; | 开发中\nlua | [lua-binding](binding/lua) | lionsoul\u0026lt;chenxin619315@gmail.com\u0026gt; | 开发中\n\n\n\n# Friso分词接口\n\n### 一个完整的demo: \n```c\n/* 第一步：申明三个对象 */\nfriso_t friso;          /* Friso 分词对象 */\nfriso_config_t config;  /* Friso 配置对象 */\nfriso_task_t task;      /* Friso 任务对象 */\n\n/* 第二步：初始化相应的对象 */\nfriso  = friso_new();\nconfig = friso_new_config();\ntask   = friso_new_task();\n\n/* 从friso.ini配置文件中初始化 friso */\nif (friso_init_from_ifile(friso, config, \"friso.ini文件地址\") != 1) {\n    /* friso 初始化失败 */\n}\n\n/*\n * 切分模式默认来自friso.ini中的设置\n * 可以通过friso_set_mode函数自定义切分模式(简易，复杂，检测模式)\n * 简易模式：__FRISO_SIMPLE_MODE__\n * 复杂模式：__FRISO_COMPLEX_MODE__\n * 检测模式：__FRISO_DETECT_MODE__\n * 例如，这里设置为使用复杂模式分词：\n*/\nfriso_set_mode(config, __FRISO_COMPLEX_MODE__);\n\n\n/* 第三步：设置分词内容 */\nfriso_set_text(task, \"分词的文本\");\n\n/* 第四步：获取分词内容 */\nwhile (config-\u003enext_token(friso, config, task) != NULL) {\n    /* \n      task存储了分词的结果，\n      task-\u003etoken-\u003eword: 词条内容\n      task-\u003etoken-\u003eoffset: 词条在原始文本的offset\n      task-\u003etoken-\u003elength: 词条的长度(字节数)\n      task-\u003etoken-\u003erlen: 词条的真正字节数(Friso转换后的长度-字节数)\n    */\n    printf(\"%s \", task-\u003etoken-\u003eword);\n}\n\n\n/* 第五步：释放对象 */\nfriso_free_task(task);\nfriso_free_config(config);\nfriso_free(friso);\n```\n\n### 备注：\n1. 第三步和第四步可以反复调用，使用friso_set_setx重置分词内容即可。\n2. 对于多线程环境，不同线程共享friso和config对象，需要分别初始化task使用对象。\n\n\n\n\n\n# Friso词库管理\n\n### 词库分类定义\n\nFriso 内部对词库进行了分类, 在管理词库前你需要先了解Friso的词库类别，分类整型值以及含义如下：\n\n```\ntypedef enum {\n __LEX_CJK_WORDS__ = 0,     // 普通 CJK 词库\n __LEX_CJK_UNITS__ = 1,     // CJK 单位词库\n __LEX_ECM_WORDS__ = 2,     // 英中混合词(例如: b 超)\n __LEX_CEM_WORDS__ = 3,     // 中英混合词(例如: 卡拉 ok).\n __LEX_CN_LNAME__  = 4,     // 中文姓氏\n __LEX_CN_SNAME__  = 5,     // 中文单姓名词库\n __LEX_CN_DNAME1__ = 6,     // 中文双姓名首字词库\n __LEX_CN_DNAME2__ = 7,     // 中文双姓名尾字词库\n __LEX_CN_LNA__ = 8,        // 中文姓氏修饰词词库\n __LEX_STOPWORDS__ = 9,     // 停止词词库\n __LEX_ENPUN_WORDS__ = 10,  // 英文和标点混合词库(例如: c++)\n __LEX_OTHER_WORDS__ = 15,  // 无用\n __LEX_NCSYN_WORDS__ = 16   // 无用\n} friso_lex_t;\n```\n\n### 词库配置文件\n\n词库目录下的 friso.lex.ini 配置文件存储了词库类别以及对应类别下的词库文件名称，是一对多的关系，默认的配置如下：\n```\n# main lexion\n__LEX_CJK_WORDS__ :[\n    lex-main.lex;\n    lex-admin.lex;\n    lex-chars.lex;\n    lex-cn-mz.lex;\n    lex-cn-place.lex;\n    lex-company.lex;\n    lex-festival.lex;\n    lex-flname.lex;\n    lex-food.lex;\n    lex-lang.lex;\n    lex-nation.lex;\n    lex-net.lex;\n    lex-org.lex;\n    lex-touris.lex;\n# add more here\n]\n# single chinese unit lexicon\n__LEX_CJK_UNITS__ :[\n    lex-units.lex;\n]\n# chinese and english mixed word lexicon like \"b超\".\n__LEX_ECM_WORDS__:[\n    lex-ecmixed.lex;\n]\n# english and chinese mixed word lexicon like \"卡拉ok\".\n__LEX_CEM_WORDS__:[\n    lex-cemixed.lex;\n]\n# chinese last name lexicon.\n__LEX_CN_LNAME__:[\n    lex-lname.lex;\n]\n# single name words lexicon.\n__LEX_CN_SNAME__:[\n    lex-sname.lex;\n]\n# first word of a double chinese name.\n__LEX_CN_DNAME1__:[\n    lex-dname-1.lex;\n]\n# second word of a double chinese name.\n__LEX_CN_DNAME2__:[\n    lex-dname-2.lex;\n]\n# chinese last name decorate word.\n__LEX_CN_LNA__:[\n    lex-ln-adorn.lex;\n]\n# stopwords lexicon\n__LEX_STOPWORDS__:[\n    lex-stopword.lex;\n]\n# english and punctuation mixed words lexicon.\n__LEX_ENPUN_WORDS__:[\n    lex-en-pun.lex;\n]\n# english words(for synonyms words)\n__LEX_EN_WORDS__:[\n    lex-en.lex;\n]\n```\n\n### 新增词库文件\n\n1. 确认类别：首先确认你要加入的词库文件的类别. \n2. 新建词库：例如: 我想添加一个词库文件专门用来存储植物的名字, 在dict/下新建 lex-plants.lex文件, 然后按照一个词条一行的规则加入词条到该文件中.\n3. 启用词库：接下来还有一个重要的步骤就是将该词库归类到 friso.lex.ini 中去, 通常的词库都是 CJK 词库, 也就是将lex-plants.lex 作为一行加入到 __LEX_CJK_WORDS__ 类别下即可。\n\n```\n# main lexion\n__LEX_CJK_WORDS__ :[\n    lex-main.lex;\n    lex-admin.lex;\n    lex-chars.lex;\n    lex-cn-mz.lex;\n    lex-cn-place.lex;\n    lex-company.lex;\n    lex-festival.lex;\n    lex-flname.lex;\n    lex-food.lex;\n    lex-lang.lex;\n    lex-nation.lex;\n    lex-net.lex;\n    lex-org.lex;\n    lex-touris.lex;\n# 新增的植物名称词库\n    lex-plants.lex;\n# add more here\n]\n```\n\n### 给词库新增词条\n\n找到对应的词库文件, 使用文本编辑器打开, 将要加入的词条按照下面的格式作为一行加入即可(备注：加入前建议先确认下相同的词条不存在)。\n\nFriso 词库词条格式:\n\n```\n词条/同义词集合\n```\n\n同义词没有使用 null 代替, 多个同义词使用英文逗号隔开，例如：\n\n```\n你好/null\n研究/琢磨,研讨,钻研\n```\n\n\n\n\n# 相关附录\n\n\n### 参考文献\n\n1. MMSEG算法原著：http://technology.chtsai.org/mmseg/\n\n### 技术交流分享\n\n1. 旧版的参考pdf参考文献：请参考项目下的 friso-help-doc.pdf\n2. 使用案例典范：[RediSearch~信息检索](https://github.com/RediSearch/RediSearch)\n3. NLP博客分享：微信公众号：lionsoul-org(狮子的魂)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flionsoul2014%2Ffriso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flionsoul2014%2Ffriso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flionsoul2014%2Ffriso/lists"}