LTP和THULAC的安装与分词工具的使用

LTP分词工具使用说明:

提前准备:
1. LTP项目文件 :ltp-3.4.0.tar.gz
2. LTP模型文件 :ltp_data_v3.4.0.zip

分别将上述文件进行解压:
执行命令:tar -zxv -f ltp-3.4.0.tar.gz ,解压后的文件为 ltp-3.4.0
执行命令:unzip ltp_data_v3.4.0.zip ,解压后的文件为 ltp_data_v3.4.0

使用步骤:

1. 直接在项目根目录下使用命令进行编译,即进入ltp-3.4.0文件目录后,执行
./configure
make
若编译成功,则会在项目根目录下生成bin目录,其目录下有ltp_test和ltp_server,以及./bin/example中有以下二进制程序:
cws_cmdline
ner_cmdline
par_cmdline
pos_cmdline
srl_cmdline

2.将解压后的文件ltp_data_v3.4.0移动到./bin下,并命名为ltp_data ;
将待处理文件(输入文件)移动到./bin 下,注意:要求输入文件的编码格式是utf-8!!!

3.由于只需要进行分词,我们只利用到cws_cmdline程序,因此,为了方便起见,将cws_cmdline文件移动到./bin下,

通过执行./cws_cmdline可查看其使用方法:
cws_cmdline in LTP 3.4.0 - (C) 2012-2017 HIT-SCIR
The console application for Chinese word segmentation.

usage: ./cws_cmdline

options:
  --threads arg                     The number of threads [default=1].(设置多线程数,默认为1)
  --input arg                         The path to the input file. Input data should contain one raw sentence each line.(输入文件)
  --segmentor-model arg     The path to the segment model [default=ltp_data/cws.model].(设置分词模型路径,默                                                                   认 ./ltp_data/cws.model)

  --segmentor-lexicon arg     The path to the external lexicon in segmentor  [optional].(设置外部的分词字典)
  -h [ --help ]                          Show help information

4.将输入文件(以tianya_part_utf8 为例)进行分词,执行命令:
./cws_cmdline --input ./tianya_part_utf8 --segmentor-model ./ltp_data/cws.model > output_file
或简化版:./cws_cmdline --input ./tianya_part_utf8  > output_file
若输入文件较大,可设置多线程,例如设置多线程数设置为24:
./cws_cmdline --threads 24 --input ./input_file  > output_file

 

THULAC分词工具使用说明:

提前准备:
1. THULAC项目文件 :THULAC_lite_c++_v1_2.zip
2. THULAC模型文件 :THULAC_pro_c++_v1.zip

分别将上述文件进行解压:
执行命令:unzip THULAC_lite_c++_v1_2.zip,解压后的文件为 THULAC_lite_c++_v1_2
执行命令:tar -zxv -f THULAC_pro_c++_v1.tar.gz ,解压后的出现4个文件(Makefile、models、README.md、src)

使用步骤:

1. 直接在项目根目录下使用命令进行编译,即在models文件所在目录后,执行
make
执行成功后,会出现可执行文件thulac

2.进入THULAC_lite_c++_v1_2目录后,查看该目录下是否存在文件thulac,
注意:此时执行make,会出现提示:make: Nothing to be done for `all'.这表明环境以及编译好了,
但是,由于编译者实在Mac下编译的,编译的thulac在Linux不可执行,而我们只需要分词功能,则有thulac文件即可,
因此,切记要用上一步编译出来的thulac文件替换当前目录下的thulac文件,
且thulac的执行需要依赖模型,因此需要将models文件移到当前目录下

3.文件thulac的使用方法:(注意输入输出文件的编码格式都是UTF-8!!!!!)

Command line usage:
./thulac [-t2s] [-seg_only] [-filter] [-deli delimeter] [-user userword.txt] [-model_dir dir]
or
./thulac [-t2s] [-seg_only] [-filter] [-deli delimeter] [-user userword.txt] outputfile
    -t2s                          transfer traditional Chinese text to Simplifed Chinese text(繁体转简体)
    -seg_only                segment text without Part-of-Speech  (仅分词)
    -filter                        use filter to remove the words that have no much sense, like "could" (过滤无意义的词,如:可以)
    -deli delimeter          agsign delimeter between words and POS tags. Default is _(设置词和词性之间的分隔符,默认'_')
    -user userword.txt    Use the words in the userword.txt as a dictionary and the words will labled as "uw"(设置用户词典,词典中每一个词一行,UTF8编码)
    -model_dir dir          dir is the directory that containts all the model file. Default is "models/"(设置模型路径,默认./models)

举个例子:输入文件以 tianya_part_utf8 为例,
./thulac -seg_only  < tianya_part_utf8 > output_tianya_part

你可能感兴趣的:(nlp)