一、Brat標注工具安裝
1.安裝條件:
(1)運行於Linux系統(window系統下虛擬機內linux系統安裝也可以)
(2)目前brat最新版本(v1.3p1)僅支持python2版本運行使用(我用的是python2.7版本)
2.建議到github網站下載最新release版本:https://github.com/nlplab/brat/tags
3.下載方式
(1)windows系統點擊zip文件下載解壓
(2)在linux系統的/var/www/html/目錄下wget下載解壓
wget https://github.com/nlplab/brat/archive/refs/tags/v1.3p1.zip unzip brat-1.3p1.zip # 下載后zip文件名為brat-1.3p1.zip mv brat-1.3p1.zip brat # 修改文件名為brat
4.安裝
(1)在/var/www/html/brat目錄下執行
./install.sh
(2)啟動apache2
service apache2 start
(3)運行服務
python2.7 standalone.py
如果出現了以下錯誤:
File "standalone.py", line 257 except SystemExit, sts: ^ SyntaxError: invalid syntax
說明需要將python3版本改為python2.7版本
(4)原始brat配置文件沒有針對中文文本的標注,需要安裝后自行修改/var/www/html/brat/server/src/projectconfig.py配置文件162行,將其注釋更改為如下所示:
# n = re.sub(r'[^a-zA-Z0-9_-]', '_', n) n = re.sub(u'[^a-zA-Z\u4e00-\u9fa5<>\u2014-\uff1b,0-9_-]', '_', n)
(5)打開瀏覽器,輸入http://127.0.0.0:brat即可見到歡迎頁面!
點擊ok開始進入使用。
5.使用
(1)/var/www/html/brat/目錄下的data目錄是供我們自己做標注時存放項目的文件夾,可以在data內mkdir一個project目錄,再根據具體項目創建對應目錄。
例如我現在需要標注10份txt文件,那么我需要在project內創建項目目錄后label-test將這10份txt文件放進去,但是需要注意的是,brat並不會在標注的同時幫助我們創建每個txt對應的標注結果文件,
所以在標注之前,我們需要先一一對應創建這10份txt對應的ann文件(空的)。下面這條命令意思是找到當前目錄下的txt文件並復制其名稱創建一個空白的ann文件。
find ./ -name '*.txt' | sed -e 's|\.txt|.ann|g' | xargs touch
利用上述的命令后,我們目錄下將會有10個txt文件,10個ann文件。
(2)標注需要配置文件,因此我們要到/var/www/html/brat/目錄下找到annotation.conf以及visual.conf,復制到/var/www/html/brat/data/project/label-test/目錄下
annotation.conf是可以對標注的實體、關系、事件、屬性等內容。
visual.conf可以修改標注的顏色等。
示例:
annotation.conf內容:
[entities] # Definition of entities. # Format is a simple list with one type per line. 時間 地點 人名 組織名 公司名 產品名 [relations] [events] [attributes]
注意:即使沒有relations、events、attributes等內容,也不能把這幾個去掉,去掉會一直報錯!!
visual.conf內容:
[labels] [drawing] 時間 bgColor:yellow 地點 bgColor:blue, fgColor:white 人名 bgColor:deepskyblue 組織名 bgColor:green, fgColor:white 公司名 bgColor:purple, fgColor:white 產品名 bgColor:pink
注意:同理,即使沒有labels內容,也不要去掉[labels]。
mayun.txt內容:
1964年9月10日,馬雲出生在杭州。 幼年的馬雲在人們的眼中是典型的壞孩子:叛逆、倔強、愛打架、逞強、頑皮淘氣。 馬雲的父親雖然是典型的江南人,但脾氣卻很火暴,馬雲從小在父親拳腳下長大。 馬雲是看金庸的武俠小說長大的,行俠仗義、打抱不平的“俠義”情結在少年馬雲的內心深處早已生根、萌芽。
mayun.ann內容為空,現在可以開始標注了,打開瀏覽器http://127.0.0.0:8001,登錄后才可以進行標注。打開我們創建的目錄,鼠標選中需要標注的實體,馬上就會自動顯示讓我們標注該內容對應的類別:
接着打開mayun.ann,可以看到標注的內容已經記錄好了。
若無apache2,則對其進行安裝並修改配置文件
sudo apt-get install apache2 # 安裝apache2 sudo vim /etc/apache2/apache2.conf # 修改apache2配置
將下列內容添加至配置文件中:
<Directory /home/*/public_html> AllowOverride Options Indexes FileInfo Limit AddType application/xhtml+xml .xhtml AddType font/ttf .ttf # For CGI support AddHandler cgi-script .cgi # Comment out the line above and uncomment the line below for FastCGI #AddHandler fastcgi-script fcgi </Directory>
對userdir賦權:
sudo a2enmod userdir
繼續執行:
sudo apt-get install libapache2-mod-fastcgi sudo a2enmod fastcgi sudo a2enmod rewrite
重新加載apache2配置:
sudo /etc/init.d/apache2 reload
可能會遇到如下問題:
[....] Reloading apache2 configuration (via systemctl): apache2.serviceapache2.service is not active, cannot reload.
failed!
解決方法:
sudo apachectl stop /etc/init.d/apache2 start
此時操作無誤后,打開http://127.0.0.1即可看到apache默認頁面。
備注:此處針對apache2的安裝配置可能有欠缺,僅供參考。
參考鏈接:
https://www.moshangxingzou.com/index.php/2019/11/27/%E6%96%87%E6%9C%AC%E6%A0%87%E6%B3%A8%E5%B7%A5%E5%85%B7brat%E9%83%A8%E7%BD%B2%E7%AC%94%E8%AE%B0/
https://www.cnblogs.com/anai/p/11474460.html