brat 的下载地址http://brat.nlplab.org/
Ubuntu16.04安装CGI环境
- 安装Apache2
sudo apt install apache2
- 配置CGI
1)打开文件/etc/apache2/sites-enabled/000-default.conf
sudo gedit /etc/apache2/sites-enabled/000-default.conf
找到以下的内容:
#Include conf-available/serve-cgi-bin.conf
修改为 Include conf-available/serve-cgi-bin.conf (去掉注释) 。
2)打开文件/etc/apache2/conf-available/serve-cgi-bin.conf
sudo gedit /etc/apache2/conf-available/serve-cgi-bin.conf
找到以下的内容:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory “/usr/lib/cgi-bin”>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
修改为:
ScriptAlias /cgi-bin/ /var/www/html/cgi-bin/
<Directory “/var/www/html/cgi-bin/”>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
AddHandler cgi-script cgi
3)打开文件/etc/apache2/mods-available/cgid.load
sudo gedit /etc/apache2/mods-available/cgid.load
在LoadModule cgid_module /usr/lib/apache2/modules/mod_cgid.so下加上:
AddHandler cgi-script .cgi .pl .py .sh
4)链接文件:
sudo ln -s /etc/apache2/mods-available/cgid.load /etc/apache2/mods-enabled/cgid.load
5)重启Apache2,终端输入:
sudo /etc/init.d/apache2 restart
6)新建/cgi-bin文件夹,终端输入:
sudo mkdir /var/www/html/cgi-bin/
7)创建一个CGI文件
在/var/www/html/cgi-bin/下新建helloworld.c文件
sudo touch /var/www/html/cgi-bin/helloworld.c
sudo vim /var/www/html/cgi-bin/helloworld.c
文件中的内容:
#include <stdio.h>
int main()
{
printf("Content-Type: text/html\n\n");
printf("Hello World!\n");
return 0;
}
插入模式:可以输入文本,在正常模式下,按i、a、o等都可以进入插入模式。
按Esc,输入:wq
–保存并退出。
编译源文件:
sudo gcc /var/www/html/cgi-bin/helloworld.c -o /var/www/html/cgi-bin/helloworld.cgi
修改CGI文件权限:
sudo chmod 755 /var/www/html/cgi-bin/helloworld.cgi
- 测试
浏览器键入:http://localhost/cgi-bin/helloworld.cgi,在页面可以看到 Hello World!
安装brat标注工具
- 下载好的brat安装包,解压
tar -zxvf brat-v1.3_Crunchy_Frog.tar.gz
- 由于已经配置过CGI保证系统服务器可用,则可以直接安装
cd /brat-v1.3_Crunchy_Frog/
./install.sh
\quad 安装的过程中要求设置用户名,密码,邮箱 出现 The installation has finished, you are almost done. 及后续的提示则安装成功
- 启动浏览器
#需要Python2
python2 standalone.py
\quad
出现浏览器的url是http://127.0.0.1:8001
- 访问url, 界面如下:
\quad 若出现错误UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe6 in position 10: ordinal not in range(128),打开/server/src/server.py文件,在开头添加如下代码:
import sys
reload(sys)
sys.setdefaultencoding('utf8')
- 支持中文
\quad brat本身是不支持中文的,如果在配置文件里定义中文会报错,解决办法是修改/server/src/projectconfig.py文件的第163行,加上中文支持即可: 将英文的这句话注释掉,并添加如下内容:
n = re.sub(u'[^a-zA-Z\u4e00-\u9fa5<>,0-9_-]', '_', n)
- brat自定义实体类型
\quad 首先,在brat项目的data目录下新建一个project目录,然后在brat项目的主目录下找到annotation.conf文件,复制到project目录。
# Simple text-based definitions of hierarchial ontologies of
# (physical) entity types, relation types, event types, and
# attributes.
# This is a minimal example configuration, based (loosely) on some
# ACE'05 entity, relation and event definitions
# (http://projects.ldc.upenn.edu/ace/annotation/2005Tasks.html).
# Please edit this according to the needs of your annotation.
[entities]
# Definition of entities.
# Format is a simple list with one type per line.
时间
地点
人名
组织名
产品名
[relations]
# Definition of (binary) relations.
# Format in brief: one relation per line, with first space-separated
# field giving the relation type and the rest of the line the
# comma-separated arguments in ROLE:TYPE format. The roles are
# typically "Arg1" and "Arg2".
夫妻 Arg1:人名, Arg2:人名
朋友 Arg1:人名, Arg2:人名
情侣 Arg1:人名, Arg2:人名
同事 Arg1:人名, Arg2:人名
父母 Arg1:人名, Arg2:人名
合作 Arg1:人名, Arg2:人名
兄弟姐妹 Arg1:人名, Arg2:人名
师生 Arg1:人名, Arg2:人名
属于 Arg1:人名, Arg2:机构
别名 Arg1:人名, Arg2:人名, <REL-TYPE>:symmetric-transitive
[events]
[attributes]
- 准备数据
\quad 把数据放进文件夹中,比如把数据(即filename.txt文件,filename为文件名)放在data/project/中。每一个句子独立成一个.txt文件。然后按下列操作就可以给data文件夹中每一个.txt文件都产生一个.ann文件。
find data -name '*.txt' | sed -e 's|\.txt|.ann|g' | xargs touch