农业知识图谱项目安装
项目地址:
qq547276542/Agriculture_KnowledgeGraph: 农业知识图谱(AgriKG):农业领域的信息检索,命名实体识别,关系抽取,智能问答,辅助决策 (github.com)
1.安装Neo4j
docker run -d --name neo4j -p 7474:7474 -p 7687:7687 -v /home/neo4j/data:/data -v /home/neo4j/logs:/logs -v /home/neo4j/conf:/var/lib/neo4j/conf -v /home/neo4j/import:/var/lib/neo4j/import --env NEO4J_AUTH=neo4j/password neo4j
2.上传数据到Neo4j
[root@localhost ~]# docker cp /opt/neo4j/hudong_pedia.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/hudong_pedia2.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/new_node.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/wikidata_relation.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/wikidata_relation2.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/attributes.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/static_weather_list.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/weather_plant.csv neo4j:/var/lib/neo4j/import
[root@localhost ~]# docker cp /opt/neo4j/city_weather.csv neo4j:/var/lib/neo4j/import
3.导入数据到Neo4j
访问http://ip::7474/browser/ 使用neo4j/password 登录,并在执行命令框,执行如下命令
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/hudong_pedia.csv" AS line
CREATE (p:HudongItem{title:line.title,image:line.image,detail:line.detail,url:line.url,openTypeList:line.openTypeList,baseInfoKeyList:line.baseInfoKeyList,baseInfoValueList:line.baseInfoValueList})
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/hudong_pedia2.csv" AS line
CREATE (p:HudongItem{title:line.title,image:line.image,detail:line.detail,url:line.url,openTypeList:line.openTypeList,baseInfoKeyList:line.baseInfoKeyList,baseInfoValueList:line.baseInfoValueList})
// 导入新的节点
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/new_node.csv" AS line
CREATE (:NewNode { title: line.title })
//添加索引
CREATE CONSTRAINT ON (c:NewNode)
ASSERT c.title IS UNIQUE
//导入hudongItem和新加入节点之间的关系
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/wikidata_relation2.csv" AS line
MATCH (entity1:HudongItem{title:line.HudongItem}) , (entity2:NewNode{title:line.NewNode})
CREATE (entity1)-[:RELATION { type: line.relation }]->(entity2)
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/wikidata_relation.csv" AS line
MATCH (entity1:HudongItem{title:line.HudongItem1}) , (entity2:HudongItem{title:line.HudongItem2})
CREATE (entity1)-[:RELATION { type: line.relation }]->(entity2)
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/attributes.csv" AS line
MATCH (entity1:HudongItem{title:line.Entity}), (entity2:HudongItem{title:line.Attribute})
CREATE (entity1)-[:RELATION { type: line.AttributeName }]->(entity2);
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/attributes.csv" AS line
MATCH (entity1:HudongItem{title:line.Entity}), (entity2:NewNode{title:line.Attribute})
CREATE (entity1)-[:RELATION { type: line.AttributeName }]->(entity2);
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/attributes.csv" AS line
MATCH (entity1:NewNode{title:line.Entity}), (entity2:NewNode{title:line.Attribute})
CREATE (entity1)-[:RELATION { type: line.AttributeName }]->(entity2);
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/attributes.csv" AS line
MATCH (entity1:NewNode{title:line.Entity}), (entity2:HudongItem{title:line.Attribute})
CREATE (entity1)-[:RELATION { type: line.AttributeName }]->(entity2)
//我们建索引的时候带了label,因此只有使用label时才会使用索引,这里我们的实体有两个label,所以一共做2*2=4次。当然,可以建立全局索引,即对于不同的label使用同一个索引
//导入节点
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/static_weather_list.csv" AS line
MERGE (:Weather { title: line.title })
//添加索引
CREATE CONSTRAINT ON (c:Weather)
ASSERT c.title IS UNIQUE
将wikidataSpider/weatherData/weather_plant.csv放在指定的位置(import文件夹下)
//导入hudongItem和新加入节点之间的关系
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/weather_plant.csv" AS line
MATCH (entity1:Weather{title:line.Weather}) , (entity2:HudongItem{title:line.Plant})
CREATE (entity1)-[:Weather2Plant { type: line.relation }]->(entity2)
导入城市的气候
将city_weather.csv放在指定的位置(import 文件夹下)
(这步大约需要15分钟左右)
//导入城市对应的气候
LOAD CSV WITH HEADERS FROM "file:///var/lib/neo4j/import/city_weather.csv" AS line
MATCH (city{title:line.city}) , (weather{title:line.weather})
CREATE (city)-[:CityWeather { type: line.relation }]->(weather)
4.安装python包
django==3.1.8
py2neo==4.3.0
thulac安装最新
pinyin安装最新
-- pip install -r requirement.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
5.修改Neo4j用户
进入demo/Model/neo_models.py,修改第9行的neo4j账号密码,改成你自己的
6.启动服务
进入demo目录,然后运行如下命令
python manage.py runserver
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!