ubuntu下文本標註工具BRAT全程離線安裝

1 Apache離線安裝

1.1 軟件下載

1.1.1 httpd文件

http://httpd.apache.org/download.cgi下載httpd文件
在這裏插入圖片描述

1.1.2 apr文件

可到官網http://apr.apache.org/下載apr。
在這裏插入圖片描述

1.1.3 apr-util文件

從官網http://apr.apache.org/下載apr-util。
在這裏插入圖片描述

1.1.4 pcre文件

從官網http://www.pcre.org/下載PCRE。

1.1.5 expat文件

由於系統缺失expat庫,需要另外下載expat源碼包並安裝,否則安裝apr-util環境會出錯。
下載地址:
https://sourceforge.net/projects/expat/files/expat/2.2.9/

1.2 安裝

下載完成後,分別解壓這些安裝包。

tar -zxvf apr-1.7.0.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf pcre-8.43.tar.gz 
tar -zxvf httpd-2.4.39.tar.gz
tar -zxvf expat-2.2.9.tar.gz

解壓完成後,會出現解壓的目錄。
然後分別進入四個目錄,執行以下命令

cd expat-2.2.9
./configure
make
make install

cd ../apr-1.7.0
./configure --prefix=/usr/local/apr (指定安裝目錄)
make
make install

cd ../apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

cd ../pcre
./configure --prefix=/usr/local/pcre
make
make install

cd …/httpd-2.4.39
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make
make install

默認安裝httpd後在/usr/local/httpd/modules下沒有cgi模塊,可以通過apxs命令進行離線編譯安裝cgi。

cd /usr/local/httpd/bin
./apxs -i -a -c /home/jcsa/httpd/modules/mod_cgi.c

在這裏插入圖片描述

將Apache加入系統服務中(待驗證):

cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/apache

1.3 文件配置

一切都按照流程安裝完成後,進入目錄 /usr/local/httpd/conf/
打開httpd.conf文件:

`vim httpd.conf`

找到文件中的 #ServerName www.example.com:80
修改爲:ServerName 192.168.190.156:80(自己的IP)
在本地瀏覽器訪問apache服務,顯示以下內容,表示Apache服務正常。
在這裏插入圖片描述
確保httpd.conf文件中mod_cgi模塊加載進來。
在這裏插入圖片描述

2 brat安裝

brat是一個文本標註工具,可以標註實體,事件、關係、屬性等,只支持在linux下安裝,其使用需要webserver,官方給出的教程使用的是Apache2。

2.1 下載brat軟件

建議下載brat的release版本地址:
https://github.com/nlplab/brat/releases/tag/v1.3p1
httpd安裝成功後,將下載的brat軟件解壓到/usr/local/httpd/htdocs/brat
使用如下命令對brat目錄授權:

sudo chmod 777 -R /usr/local/httpd/htdocs/brat

進入brat目錄

cd /usr/local/httpd/htdocs/brat 

執行以下命令,根據提示輸入用戶名、密碼、管理員郵箱

sudo ./install.sh

2.2 配置
打開httpd.conf文件:vim httpd.conf或者gedit httpd.conf
增加
<Directory /usr/local/httpd/htdocs/brat>
AllowOverride Options Indexes FileInfo Limit
Require all granted
AddType application/xhtml+xml .xhtml
AddType font/ttf .ttf
Options +ExecCGI
AddHandler cgi-script .cgi

重啓httpd後

cd /usr/local/httpd/bin
sudo ./apachectl restart

訪問以下網址http://127.0.0.1/brat/
在這裏插入圖片描述

3 brat使用

brat默認不支持中文標註,需要手動修改brat主目錄/server/src路徑下的projectconfig.py文件的第162行代碼,註釋源代碼,然後另起一行加入新代碼(修改之後記得重啓apache2服務):

# n  = re.sub(r'[^a-zA-Z0-9_-]', '_', n)
n = re.sub(u'[^a-zA-Z\u4e00-\u9fa5<>,0-9_-]', '_', n)

如果使用brat加載本地文件的時候報錯“unable to read text file xxx/xxx/xxx/xxx.txt ”,請確保你的txt文件已經授權給當前linux系統的登錄用戶,授權方式可以參考如下方式:

sudo chmod 777 xxx.txt

請確保python2環境存在,並且python軟連接指向的是python2,否則brat可能運行報錯(最新的release版本只支持python2),如果需要安裝python3可以建立新的軟連接,名字叫python3即可;當然這只是參考處理方案,也可以採用虛擬環境的方式在python2下運行brat。
最後,如何添加多個用戶:
找到config.py 對應的行,增加:

USER_PASSWORD = {
'admn': 'admin',
'test': 'test',
# (add USERNAME:PASSWORD pairs below this line.)
}

準備數據。把數據放進文件夾中,比如我把數據(即filename.txt文件,filename爲文件名)放在data/project/中。每一個句子獨立成一個.txt文件。然後按下列操作就可以給data文件夾中每一個.txt文件都產生一個.ann文件。

find data -name '*.txt' | sed -e 's|\.txt|.ann|g' | xargs touch

另外再對新添加的文件夾添加讀寫權限:

chmod –R 777 ./

4 參考

中標麒麟操作系統6.7版本下安裝Apache-2.4.39
Ubuntu 12.94 離線安裝(部署)Apache(Apache-2.4.7)
用深度學習做命名實體識別(二):文本標註工具brat
文本標註工具brat部署筆記

所有的離線安裝包地址:https://download.csdn.net/download/maoersong/12191533

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章