~zorba-coders/zorba/feature-cloudant

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
78
79
80
81
82
83
84
85
86
87
#! /bin/bash
##
#   Copyright 2006-2008 The FLWOR Foundation.
#   
#   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.
##

THESAURUS_URL="http://wordnetcode.princeton.edu/3.0/WNdb-3.0.tar.gz"

die() {
  echo
  echo 'Arguments: [--workdir <workdir>] [--builddir <builddir>]'
  echo '           [--thesaurusurl <thesaurusurl>]'
  echo '           <zorba_repository>'
  echo '<zorba_repository> is the top-level BZR working copy.'
  echo '<workdir> is a temp directory to download and unzip XQTS (default: /tmp).'
  echo '<builddir> is the directory Zorba has been built in'
  echo '           (default: <zorba_repository>/build)'
  echo '<thesaurusurl> is the URL where a WordNet thesaurus can be found'
  echo "               (default: $THESAURUS_URL)"
  exit 1
}

WORK=/tmp

while [ $# -gt 1 ]
do
  # --workdir to specify a working directory to download/unzip XQTS
  test "$1" = "--workdir" && { WORK="$2"; shift; shift; }

  # --builddir to specify Zorba build directory (default: srcdir/build)
  test "$1" = "--builddir" && { BUILD="$2"; shift; shift; }

  # thesaurusurl to specify the URL where thesaurus can be found
  test "$" = "--thesaurusurl" && { THESAURUS_URL="$2"; shift; shift; }
done

SRC="$1"
if [ -z "$BUILD" ]; then
  BUILD="$SRC/build"
fi

if test ! -d "$SRC/test/zorbatest"; then
  echo "Invalid zorba repository $SRC"
  die
fi

if test ! -d "$BUILD"; then
  echo "Invalid build directory $BUILD"
  die
fi

THESAURUS_TAR="$WORK/thesaurus.tar.gz"
echo Downloading thesaurus ...
wget -c -O $THESAURUS_TAR $THESAURUS_URL

# Canonicalize SRC and BUILD
SRC=$(cd "$SRC" && pwd)
echo Repository is at $SRC
BUILD=$(cd "$BUILD" && pwd)
echo Build dir is at $BUILD

# Compile thesaurus to binary format
mkdir -p $BUILD/LIB_PATH/edu/princeton/wordnet
THESAURUS_DEST="$BUILD/LIB_PATH/edu/princeton/wordnet/wordnet-en.zth"
echo "Compiling thesaurus to $THESAURUS_DEST..."
untar_dir=`mktemp -d "$WORK/thesaurus.XXXXXX"`
cd "$untar_dir"
gzip -dc "$THESAURUS_TAR" | tar x
$SRC/scripts/zt-wn-compile "$untar_dir/dict" "$THESAURUS_DEST"

echo "Cleaning up work directory... $untar_dir"
rm -rf "$untar_dir"

echo Done.

# vim:set et sw=2 ts=2: