赞
踩
'''基于给定语料与模板的事件抽取,假定你选择的是Mongodb数据库'''
class TextMining:
def __init__(self):
mongo_host = 'localhost' # '127.0.0.1' 你数据库的ip
mongo_port = 27017 # 你数据库端口 原来是28017
mongo_db = 'news' # 数据库名称
mongo_col = 'news' # 数据表名称
username = urllib.parse.quote_plus("root") # 用户名
password = urllib.parse.quote_plus("12345678") # 密码
client = pymongo.MongoClient('mongodb://{}:{}@{}:{}'.format(username, password, mongo_host, mongo_port))
self.db = client[mongo_db]
self.col = self.db[mongo_col]
self.extractor = EventsExtraction()
``
导出的文件在event_extract中
https://www.w3cschool.cn/neo4j/neo4j_need_for_graph_databses.html
http://localhost:7474/browser/
在 Pycharm 中导入 py2neo 的安装包,版本选最新版即可。
参考项目:https://blog.csdn.net/RHJlife/article/details/108586578?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167425999916800213051757%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=167425999916800213051757&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-108586578-null-null.142v71one_line,201v4add_ask&utm_term=%E7%BA%A2%E6%A5%BC%E6%A2%A6%E7%9F%A5%E8%AF%86%E5%9B%BE%E8%B0%B1&spm=1018.2226.3001.4187
import csv import py2neo from py2neo import Graph,Node,Relationship,NodeMatcher #账号密码改为自己的即可 g=Graph('http://localhost:7474',user='neo4j',password='这里写自己的密码',name='neo4j') with open('C:/Users/dell/Desktop/data.csv','r',encoding='utf-8') as f: reader=csv.reader(f) for item in reader: if reader.line_num==1: continue print("当前行数:",reader.line_num,"当前内容:",item) start_node=Node("Person",name=item[4]) end_node=Node("Person",name=item[2]) relation=Relationship(start_node,item[5],end_node) g.merge(start_node,"Person","name") g.merge(end_node,"Person","name") g.merge(relation,"Person","name") #以下为neo4j代码,如需代码运行,请放入g.run(...)内运行,将...替换为下列代码 # MATCH (p: Person {name:"贾宝玉"})-[k:丫鬟]-(r) # return p,k,r # MATCH (p1:Person {name:"贾宝玉"}),(p2:Person{name:"香菱"}),p=shortestpath((p1)-[*..10]-(p2)) # RETURN p # 删除所有结点以及关系 # g.delete_all()
这是目前得到的效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。