使用示例
- 下载并部署服务
- 浏览器访问
http://127.0.0.1:8080/tag?statement=我有糖尿病,在吃格华止,可以同时吃奥利司他来减肥吗?
- 查看JSON返回结果
{
"code": 1,
"msg": "",
"result": {
"奥利司他": {
"keyword": "奥利司他",
"positions": [
{
"start": 17,
"end": 20
}
],
"dictwords": {
"medicine": [
{
"dict": "medicine",
"word": "奥利司他胶囊",
"index": [
"奥利司他",
"奥利司他胶囊"
],
"data": {
"category": "西药",
"categoryId": 0,
"isControl": true,
"isHighRisk": true,
"medicineType": 0
}
},
{
"dict": "medicine",
"word": "奥利司他片",
"index": [
"奥利司他",
"奥利司他片"
],
"data": {
"category": "西药",
"categoryId": 0,
"isControl": true,
"isHighRisk": true,
"medicineType": 0
}
}
]
}
},
"格华止": {
"keyword": "格华止",
"positions": [
{
"start": 8,
"end": 10
}
],
"dictwords": {
"brand": [
{
"dict": "brand",
"word": "格华止",
"index": [
"格华止"
],
"data": {
"category": "西药"
}
}
]
}
},
"糖尿": {
"keyword": "糖尿",
"positions": [
{
"start": 2,
"end": 3
}
],
"dictwords": {
"symptom": [
{
"dict": "symptom",
"word": "糖尿",
"index": [
"糖尿"
],
"data": {
"symptomId": 0
}
}
]
}
},
"糖尿病": {
"keyword": "糖尿病",
"positions": [
{
"start": 2,
"end": 4
}
],
"dictwords": {
"disease": [
{
"dict": "disease",
"word": "糖尿病",
"index": [
"糖尿病"
],
"data": {
"diseaseId": 0
}
}
]
}
}
},
"micros": 672
}
- 执行效率:一般办公电脑 500 ~ 1000微秒,一般服务器在100 ~ 200微秒
实现原理
定义字典和词条
- 一个json文件即一个字典,文件名称为字典名称,如:medicine.json,即为药品字典;
- 字典文件中每一行为一个词条,每个词条是一个json对象
- 词条结构如下
| 字段 | 数据类型 | 必须 | 说明 |
|---|---|---|---|
| word | 字符串 | 是 | 词条名称 |
| index | 字符串数组 | 是 | 该词条的索引词,语句中包含该索引词时才能搜索到本词条 |
| data | JSON对象 | 是 | 该词条的附属信息,比如id、分类等 |
构建索引树
将全部字典的全部词条,根据其索引词构建前缀索引树 例如以下索引词
糖尿病足
糖尿病皮肤感染
糖尿病性神经病
糖尿病性胃轻瘫
糖尿病性并结核病
糖尿病性周围神经病
糖原贮积病
糖原贮积病Ⅰ型
糖原贮积病Ⅱ型
可构建前缀树如下
按字切分输入语句
自然语句按字切分成搜索词,并记录其起始位置 例如:我有糖尿病,在吃格华止,可以同时吃奥利司他来减肥吗? 切分成以下搜索词
我有糖尿病,在吃格华止,可以同时吃奥利司他来减肥吗?
有糖尿病,在吃格华止,可以同时吃奥利司他来减肥吗?
糖尿病,在吃格华止,可以同时吃奥利司他来减肥吗?
尿病,在吃格华止,可以同时吃奥利司他来减肥吗?
...
格华止,可以同时吃奥利司他来减肥吗?
...
奥利司他来减肥吗?
...
并发搜捕索引树
- 用搜索词遍历索引树,收集走过的每个节点上附属的词条
- 按搜索词、字典名称合并词条并返回
用途
该服务可用于命令词提取、搜索意图识别、机器学习数据标注等领域