DeepDive安装及基础使用(上)
一、deepdive环境搭建及数据库安装
1、下载deepdive
在用虚拟机尝试未果后,借来了一台Mac电脑,利用桌面右上角的搜索图标,搜索terminal,打开终端,开始下载DeepDive
bash <(curl -fsSL git.io/getdeepdive) |
下载完成后选择1安装deepdive
### DeepDive installer for Mac + curl -fsSL https://github.com/HazyResearch/deepdive/raw/v0.8.x/util/install/install.Mac.sh 1) deepdive 5) postgres 2) deepdive_examples_tests 6) run_deepdive_tests 3) deepdive_from_release 7) spouse_example 4) deepdive_from_source # Select what to install (enter for all options, q to quit, or a number)? 1 |
安装完成后需要配置环境变量,deepdive的可执行文件一般安装在~/local/bin文件夹下。
2、添加deepdive的环境变量:export PATH="/Users/ds/local/bin:$PATH"
1、如果你是第一次配置环境变量,可以使用“touch ~/.bash_profile” 创建一个.bash_profile的隐藏配置文件(如果你是为编辑已存在的配置文件,则使用"open -e ~/.bash_profile"命令)
2、输入“open -e ~/.bash_profile”命令,打开配置编辑窗口
3、输入环境变量配置:export PATH="/Users/ds/local/bin:$PATH"
4、使用"source ~/.bash_profile"使配置生效
5、检查环境变量是否生效:echo $PATH
3、安装postgresql数据库(若安装错误则先安装Homebrew)
bash <(curl -fsSL git.io/getdeepdive) postgres |
附:下载实例
bash <(curl -fsSL git.io/getdeepdive) spouse_example |
二、搭建项目文件结构
1、创建数据库配置文件
DeepDive及postgresql数据库下载及环境搭建好后,手动新建项目文件transaction,并利用命令窗口访问,输入以下命令创建数据库配置文件:
echo "postgresql://[email protected]$HOSTNAME:5432/db_name" >db.url |
将会生成db.url数据库配置文件,其中db_name为数据库名,(在执行deepdive complie命令后)如果不存在该数据库,则会新建该数据库
2、创建input输入文件夹、udf用户自定义python脚本文件夹、deepdive.conf模型配置文件、app.ddlog用户配置文件
三、导入先验数据及待抽取文章
1、在input文件夹中导入先验数据
2、在app.ddlog中定义相应的数据表
@source transaction_dbdata( @key company1_name text, @key company2_name text ). |
3、在项目文件目录下,使用命令行生成postgresql数据库
deepdive compile && deepdive do transaction_dbdata |
- 在执⾏app.ddlog前,如果有改动,需要先执⾏deepdive compile编译才能⽣效
- 对于不依赖于其他表的表格,deepdive会⾃动去input⽂件夹下找到同名csv⽂件,在postgresql⾥建表导⼊
- 运⾏命令时,deepdive会在当前命令⾏⾥⽣成⼀个执⾏计划⽂件,和vi语法⼀样,审核后使⽤:wq保存并 执⾏。
4、检查先验数据导入是否成功:
⽤query语句或者deepdive sql "sql语句"进⾏数据库操作,进⾏查询id指令
deepdive query '?- transaction_dbdata(id, _).' |
或者登录postgresql数据库,查询db_name数据库下的transaction_dbdata表
psql -U ds -d db_name -h 127.0.0.1 select * from transaction_dbdata; |
查询结果如下:
5、待抽取文章导入(将文件放入input文件夹中)
6、在app.ddlog中建立对应的articles表
articles( id text, content text ). |
7、执行命令导入文章到postgresql数据库中(因为app.ddlog已更改,执行do命令前需要执行deepdive complie编译,否则出现错误:Unkonw target),并检查待抽取文章是否导入成功
deepdive do articles deepdive query '?- articles(id, _).' |
接下来为⽤nlp模块进⾏⽂本处理过程,首先要安装java8及nlp模块,详见我的文章:https://blog.****.net/qq_39591838/article/details/89458975
然后进行处理,由于篇幅较长,分见下篇