1 Star 1 Fork 3

呆呆/MedicalInsuranceKG

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ExtLocation.py 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
AdiaLoveTrance 提交于 2018-05-30 09:03 . Add files via upload
import os
# from pyltp import Segmentor, Postagger, Parser, NamedEntityRecognizer
# LTP_DATA_DIR = 'E:\\ltp_data_v3.4.0' # ltp模型目录的路径
# cws_model_path = os.path.join(LTP_DATA_DIR, 'cws.model') # 分词模型路径,模型名称为`cws.model`
# pos_model_path = os.path.join(LTP_DATA_DIR, 'pos.model') # 词性标注模型路径,模型名称为`pos.model`
#
# segmenter = Segmentor()
# segmenter.load_with_lexicon(cws_model_path,'E:\\ltp_data_v3.4.0\\personal_seg.txt')
#
# postaggor = Postagger()
# postaggor.load_with_lexicon(pos_model_path,'E:\\ltp_data_v3.4.0\\personal_pos.txt')
def ExtbySentence(sentence, segmentor, postagger):
words = segmentor.segment(sentence)
postags = postagger.postag(words)
location = ''
for i in range(len(postags)):
if postags[i] == 'ns':
location = words[i]
# print(location)
return location
def ExtLocation(filename, segmentor, postagger):
"""提取语料所属地名"""
file = open(filename, 'r', encoding='utf-8')
loc = None
while loc == None:
sentence = next(file)
loc = ExtbySentence(sentence, segmentor, postagger)
return loc
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/smarteas/MedicalInsuranceKG.git
git@gitee.com:smarteas/MedicalInsuranceKG.git
smarteas
MedicalInsuranceKG
MedicalInsuranceKG
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385