summaryrefslogtreecommitdiff
path: root/generate-random-word-from-wikipedia.sh
blob: fbc720fda0c2b08c8ed93922a72ce4c445070b6c (plain)
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
#!/bin/bash

base_dir=$(readlink -f "$(dirname "$0")")

depth=$1
shift

if [ ! -s "${base_dir}/.words.${depth}" ]; then

  urls=()

  for i in $(seq "${depth}"); do
    urls=(
      $(
        "${base_dir}/dive-into-wikipedia.sh" "${urls[@]}" \
          | sort -u
      )
    )
    echo $i >&2
  done

  printf '%s\n' "${urls[@]}" \
    | parallel -j0 -n1 "${base_dir}/remove-tags.sh" \
    | sort -u \
    | grep -vxF '' \
    > "${base_dir}/.words.${depth}"

fi

"${base_dir}/markov" "${base_dir}/.words.${depth}" "$@"