forked from shangjingbo1226/AutoPhrase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phrasal_segmentation.sh
executable file
·77 lines (55 loc) · 2.22 KB
/
phrasal_segmentation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
MODEL=${MODEL:- "models/DBLP"}
TEXT_TO_SEG=${TEXT_TO_SEG:-data/EN/DBLP.5K.txt}
SEGMENTATION_MODEL=${MODEL}/segmentation.model
TOKEN_MAPPING=${MODEL}/token_mapping.txt
HIGHLIGHT_MULTI=0.5
HIGHLIGHT_SINGLE=0.8
ENABLE_POS_TAGGING=1
THREAD=10
green=`tput setaf 2`
reset=`tput sgr0`
echo ${green}===Compilation===${reset}
COMPILE=${COMPILE:- 1}
if [ $COMPILE -eq 1 ]; then
bash compile.sh
fi
mkdir -p tmp
mkdir -p ${MODEL}
### END Compilation###
echo ${green}===Tokenization===${reset}
TOKENIZER="-cp .:tools/tokenizer/lib/*:tools/tokenizer/resources/:tools/tokenizer/build/ Tokenizer"
TOKENIZED_TEXT_TO_SEG=tmp/tokenized_text_to_seg.txt
CASE=tmp/case_tokenized_text_to_seg.txt
echo -ne "Current step: Tokenizing input file...\033[0K\r"
time java $TOKENIZER -m direct_test -i $TEXT_TO_SEG -o $TOKENIZED_TEXT_TO_SEG -t $TOKEN_MAPPING -c N -thread $THREAD
LANGUAGE=`cat ${MODEL}/language.txt`
echo -ne "Detected Language: $LANGUAGE\033[0K\n"
### END Tokenization ###
echo ${green}===Part-Of-Speech Tagging===${reset}
if [ ! $LANGUAGE == "JA" ] && [ ! $LANGUAGE == "CN" ] && [ ! $LANGUAGE == "OTHER" ] && [ $ENABLE_POS_TAGGING -eq 1 ]; then
RAW=tmp/raw_tokenized_text_to_seg.txt # TOKENIZED_TEXT_TO_SEG is the suffix name after "raw_"
export THREAD LANGUAGE RAW
bash ./tools/treetagger/pos_tag.sh
mv tmp/pos_tags.txt tmp/pos_tags_tokenized_text_to_seg.txt
fi
POS_TAGS=tmp/pos_tags_tokenized_text_to_seg.txt
### END Part-Of-Speech Tagging ###
echo ${green}===Phrasal Segmentation===${reset}
if [ $ENABLE_POS_TAGGING -eq 1 ]; then
time ./bin/segphrase_segment \
--pos_tag \
--thread $THREAD \
--model $SEGMENTATION_MODEL \
--highlight-multi $HIGHLIGHT_MULTI \
--highlight-single $HIGHLIGHT_SINGLE
else
time ./bin/segphrase_segment \
--thread $THREAD \
--model $SEGMENTATION_MODEL \
--highlight-multi $HIGHLIGHT_MULTI \
--highlight-single $HIGHLIGHT_SINGLE
fi
### END Segphrasing ###
echo ${green}===Generating Output===${reset}
java $TOKENIZER -m segmentation -i $TEXT_TO_SEG -segmented tmp/tokenized_segmented_sentences.txt -o ${MODEL}/segmentation.txt -tokenized_raw tmp/raw_tokenized_text_to_seg.txt -tokenized_id tmp/tokenized_text_to_seg.txt -c N
### END Generating Output for Checking Quality ###