├── README.md ├── src ├── __pycache__ │ └── semantic.cpython-34.pyc └── semantic.py └── test.py /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## 语义理解/口语理解 3 | >>> 采用了深度学习等技术 4 | 5 | 主要功能: 6 | * 中文分词 7 | * 词性标注 8 | * 命名实体识别 9 | * 领域分类 10 | * 槽填充 11 | * 意图识别 12 | 13 | 自然语言处理使用的是作者开源的Jiagu项目:https://github.com/ownthink/Jiagu 14 | 15 | spoken举例: 16 | ``` 17 | 上海的天气 18 | 厦门明天会不会下雨 19 | 姚明真正的身高是多少 20 | ``` 21 | 22 | ### 使用方式 23 | ```shell 24 | python3 test.py 25 | ``` 26 | 27 | 解析结果 28 | ```shell 29 | { 30 | "input": "厦门明天会不会下雨", 31 | "semantics": [ 32 | { 33 | "score": "0.8", 34 | "domain": "天气", 35 | "intent": "雨", 36 | "slot": [ 37 | [ 38 | "城市", 39 | "厦门" 40 | ], 41 | [ 42 | "日期", 43 | "明天" 44 | ] 45 | ] 46 | } 47 | ], 48 | "词法分析": { 49 | "词性标注": [ 50 | "地名", 51 | "时间词", 52 | "动词", 53 | "动词", 54 | "动词" 55 | ], 56 | "实体识别": [ 57 | "B-地名", 58 | "O", 59 | "O", 60 | "O", 61 | "O" 62 | ], 63 | "中文分词": [ 64 | "厦门", 65 | "明天", 66 | "会", 67 | "不会", 68 | "下雨" 69 | ] 70 | } 71 | } 72 | ``` 73 | -------------------------------------------------------------------------------- /src/__pycache__/semantic.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ownthink/Semantic/df9870ad06ef91518654eb117ba7d966f4f76a4f/src/__pycache__/semantic.cpython-34.pyc -------------------------------------------------------------------------------- /src/semantic.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | class Analysis: 4 | def __init__(self, text): 5 | self.data = None 6 | if text=='' or type(text) != str: 7 | return None 8 | url = 'https://api.ownthink.com/slu?spoken=%s'%text 9 | sess = requests.get(url) 10 | text = sess.text 11 | slu = eval(text) 12 | 13 | self.data = slu['data'] 14 | 15 | def analysis(self): 16 | 17 | # 中文分词 18 | self.cws = self.data['词法分析']['中文分词'] 19 | 20 | # 词性标注 21 | self.pos = self.data['词法分析']['词性标注'] 22 | 23 | # 命名实体识别 24 | self.ner = self.data['词法分析']['实体识别'] 25 | 26 | # 领域分类 27 | self.domain = self.data['semantics'][0]['domain'] 28 | 29 | # 槽填充 30 | self.slot = self.data['semantics'][0]['slot'] 31 | 32 | # 意图识别 33 | self.intent = self.data['semantics'][0]['intent'] 34 | 35 | return self.data 36 | 37 | 38 | -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | from src.semantic import Analysis 2 | 3 | if __name__=='__main__': 4 | 5 | text = '厦门明天会不会下雨' 6 | 7 | slu = Analysis(text) 8 | 9 | data = slu.analysis() #解析 10 | print(data) #总的结果 11 | 12 | print('--------------------------') 13 | 14 | print(slu.cws) #分词 15 | 16 | print(slu.pos) #词性标注 17 | 18 | print(slu.ner) #命名实体识别 19 | 20 | print(slu.domain) #领域分类 21 | 22 | print(slu.intent) #意图识别 23 | 24 | print(slu.slot) #槽填充 25 | 26 | --------------------------------------------------------------------------------