加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
淡然.坏笑1 提交于 2019-11-07 16:45 . 修改neo4j地址
from py2neo import Graph,Node
class test:
def __init__(self):
self.g = Graph(host="127.0.0.1", # neo4j 搭载服务器的ip地址,ifconfig可获取到
http_port=7474, # neo4j 服务器监听的端口号
user="neo4j", # 数据库user name,如果没有更改过,应该是neo4j
password="806393858")
def findNER(self,input):
sql_name = 'match (n) where not n:question_type and "{}" contains n.name return n.name as name,n.label as label'.format(input)
sql_label = 'match (m:question_type) where "{}" contains m.name return m.label as label'.format(input)
data_name = self.g.run(sql_name).data()
data_label = self.g.run(sql_label).data()
dict_type = {i['name']:i['label'] for i in data_name}
stop_wds = []
for wd1 in dict_type.keys():
for wd2 in dict_type.keys():
if wd1 in wd2 and wd1 != wd2:
stop_wds.append(wd1)
final_wds = [i for i in dict_type.keys() if i not in stop_wds]
final_dict = {i: dict_type.get(i) for i in final_wds}
return final_dict,data_label
if __name__ == '__main__':
test = test()
while 1:
text = input()
print(test.findNER(text))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化