This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
generate_text.sh
68 lines (56 loc) · 2.05 KB
/
generate_text.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
#!/bin/sh
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
LDCDIR="" # Path to input LDC dataset directory (LDC2011T07)
OUTDIR="" # Path to output directory
HTML="LDC2011T07/gigaword_eng_5_d1/data/afp_eng/afp_eng_*"
DICT="afp_dict.txt"
MCAFPDIR="./data"
set -eu
if [ ! "${LDCDIR}" ]; then
echo "Please set the LDCDIR variable to point to the location of the LDC dataset top directory (contact LDC to obtain a copy)"
exit 1
fi
if [ ! "${MCAFPDIR}" ]; then
echo "Please set the MCAFPDIR variable to point to the location of the MCAFP dataset directory (where you downloaded the data)"
exit 1
fi
if [ ! "${OUTDIR}" ]; then
echo "Please set the OUTDIR variable to point to the desired output location"
exit 1
fi
DICTDIR="${OUTDIR}/tmp"
mkdir -p "${DICTDIR}"
if [ -e "${DICTDIR}/${DICT}" ]; then
echo "Using existing dict: ${DICTDIR}/${DICT}"
else
echo "Generate dict: ${DICTDIR}/${DICT}"
gunzip ${LDCDIR}/${HTML}
python html2word.py "${LDCDIR}/${HTML}" "${DICTDIR}/${DICT}"
fi
if [ ! -f "${MCAFPDIR}/train.mc5.kv" ]; then
echo "Concatenate all training files to train.mc5.kv"
cat ${MCAFPDIR}/train.mc5.kv-00?? > "${MCAFPDIR}/train.mc5.kv"
fi
for FNAME in "test" "dev" "train"; do
IDKV="${FNAME}.mc5.kv"
if [ ! -e "${MCAFPDIR}/${IDKV}" ]; then
echo "Missing MC-AFP ${MCAFPDIR}/${IDKV} input file"
exit 1
fi
TEXTKV="${FNAME}.mc5-text.kv"
echo "Generate ${TEXTKV}"
python id2text.py "${DICTDIR}/${DICT}" "${MCAFPDIR}/${IDKV}" "${OUTDIR}/${TEXTKV}"
done
echo "Done, see the .kv files in ${OUTDIR}"