中文模糊匹配中文模糊匹配的小包
项目描述
模糊中文
近形词中文模糊匹配
一个简单的模糊匹配中文单词的工具,特别适用于正确的名称匹配和地址匹配。
一个可以模糊形状的小字词的工具匹配具体的细节,地址的特别近用处。
安装说明
pip install fuzzychinese
使用说明
首先使用想要的字典对模型进行训练匹配。
FuzzyChineseMatch.transform(raw_words, n)然后直接查找与raw_words的词最相近的前n个词。
训练训练时有结果分析方法可以选择,笔划分析(stroke),部首分析(radical),和单字分析(char)值。也可以通过调整ngram_range模型的性能来提高。
完成后返回相似度分数,匹配的相近的术语以及索引号。
import pandas as pd
from fuzzychinese import FuzzyChineseMatch
test_dict = pd.Series(['长白朝鲜族自治县','长阳土家族自治县','城步苗族自治县','达尔罕茂明安联合旗','汨罗市'])
raw_word = pd.Series(['达茂联合旗','长阳县','汩罗市'])
assert('汩罗市'!='汨罗市') # They are not the same!
fcm = FuzzyChineseMatch(ngram_range=(3, 3), analyzer='stroke')
fcm.fit(test_dict)
top2_similar = fcm.transform(raw_word, n=2)
res = pd.concat([
raw_word,
pd.DataFrame(top2_similar, columns=['top1', 'top2']),
pd.DataFrame(
fcm.get_similarity_score(),
columns=['top1_score', 'top2_score']),
pd.DataFrame(
fcm.get_index(),
columns=['top1_index', 'top2_index'])],
axis=1)
| 顶部1 | 前2名 | top1_score | top2_score | top1_index | top2_index | |
|---|---|---|---|---|---|---|
| 达茂联合旗 | 达尔罕茂明安联合旗 | 长白朝鲜族自治县 | 0.824751 | 0.287237 | 3 | 0 |
| 长阳县 | 长阳土家族自治县 | 长白朝鲜族自治县 | 0.610285 | 0.475000 | 1 | 0 |
| 汩罗市 | 汨罗市 | 长白朝鲜族自治县 | 1.000000 | 0.152093 | 4 | 0 |
其他功能
-
直接使用
Stroke,Radical进行汉字划分。stroke = Stroke() radical = Radical() print("像", stroke.get_stroke("像")) print("像", radical.get_radical("像"))
像 ㇒〡㇒㇇〡㇕一㇒㇁㇒㇒㇒㇏ 像 人象 -
使用
FuzzyChineseMatch.compare_two_columns(X, Y)对每一行的两个词进行比较,获得相似度分数。 -
详情请参阅说明文档。
致谢
安装
pip install fuzzychinese
快速开始
首先使用要匹配的目标单词列表训练模型。
然后使用FuzzyChineseMatch.transform(raw_words, n)在目标中查找前 n 个最相似的词raw_words。
训练模型时可以选择三种分析器:stroke、radical和char。您还可以更改ngram_range以微调模型。
匹配后,返回相似度得分、匹配词及其对应的索引。
from fuzzychinese import FuzzyChineseMatch
test_dict = pd.Series(['长白朝鲜族自治县','长阳土家族自治县','城步苗族自治县','达尔罕茂明安联合旗','汨罗市'])
raw_word = pd.Series(['达茂联合旗','长阳县','汩罗市'])
assert('汩罗市'!='汨罗市') # They are not the same!
fcm = FuzzyChineseMatch(ngram_range=(3, 3), analyzer='stroke')
fcm.fit(test_dict)
top2_similar = fcm.transform(raw_word, n=2)
res = pd.concat([
raw_word,
pd.DataFrame(top2_similar, columns=['top1', 'top2']),
pd.DataFrame(
fcm.get_similarity_score(),
columns=['top1_score', 'top2_score']),
pd.DataFrame(
fcm.get_index(),
columns=['top1_index', 'top2_index'])],
axis=1)
| 顶部1 | 前2名 | top1_score | top2_score | top1_index | top2_index | |
|---|---|---|---|---|---|---|
| 达茂联合旗 | 达尔罕茂明安联合旗 | 长白朝鲜族自治县 | 0.824751 | 0.287237 | 3 | 0 |
| 长阳县 | 长阳土家族自治县 | 长白朝鲜族自治县 | 0.610285 | 0.475000 | 1 | 0 |
| 汩罗市 | 汨罗市 | 长白朝鲜族自治县 | 1.000000 | 0.152093 | 4 | 0 |
其他用途
-
直接用
Stroke,Radical将汉字分解成笔画或部首。stroke = Stroke() radical = Radical() print("像", stroke.get_stroke("像")) print("像", radical.get_radical("像"))
像 ㇒〡㇒㇇〡㇕一㇒㇁㇒㇒㇒㇏ 像 人象 -
用于
FuzzyChineseMatch.compare_two_columns(X, Y)比较每行中的单词对以获得相似度分数。 -
有关详细信息,请参阅文档。
学分
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
Fuzzychinese-0.1.5.tar.gz
(287.5 kB
查看哈希)
内置分布
Fuzzychinese-0.1.5-py3-none-any.whl
(302.5 kB
查看哈希)
关
Fuzzychinese -0.1.5.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | a8640118865bda3b0317a3c04342e336a8cd92b085760388e1d9bb1c644cfac7 |
|
| MD5 | dbb684871d940e84326d22653587fc64 |
|
| 布莱克2-256 | f78c54db3f0384ce9050adbb320ccd6cc137b34d4940453c99dda629b9816a01 |
关
Fuzzychinese -0.1.5-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 59e62dab7eb3585e8d334fe867d97cbde6a7ecae5750c9e4e4041a42db2ff593 |
|
| MD5 | 153c83f22e6a615c9fbbf528f7dde97e |
|
| 布莱克2-256 | 48e7d5186b34c7919c31f5dd7e7b6a437ac97d0149d882c611009efad270aadf |