#!/bin/bash

usage() {
  echo "usage: infer-wo METHOD DATADIR"
  echo "  METHOD:"
  echo "    baseline : the most common word order"
  echo "    count    : inferred from counting observed word orders"
  echo "    count2   : inferred from counting observed binary word orders"
  echo "    mln      : inferred from a markov logic network (alchemy)"
  echo "    position : just return the (SV-VS, OV-VO, SO-OS) 3D point"
  echo "  DATADIR:"
  echo "    the directory containing projected trees and IGT data"
  exit 1
}

test $# -eq 2 || usage
echo "$1" | grep -E '^(baseline|count2?|mln|position)$' -q || usage
test -d "$2" || usage

method="$1"
datadir="$2"

export PATH=scripts/:$PATH

case $method in
  baseline)
    # maybe do something more informed here. These are taken from the
    # most common features in WALS. Note that noun-determiner order is
    # used in the Matrix, but WALS does noun-demonstrative order
    echo "word-order=sov"
    echo "has-dets=yes"
    echo "noun-det-order=det-noun"
    echo "noun-adj-order=noun-adj";;
  count)
    extract-wo "$datadir/igt.all" | infer-wo-from-counts ;;
  count2)
    extract-wo "$datadir/igt.all" | infer-wo-from-counts2 ;;
  mln)
    lg=`basename "$datadir"`
    tgrep2 -m "$lg %s %p\n" -c "$datadir/igtprojtgm.tgc" scripts/wo.tgrep2 | scripts/wo.mln.sed | sort -u > "$datadir/mln.db"
    infer -i scripts/wo.mln -e "$datadir/mln.db" -r "$datadir/mln.results" -q IsWo&>/dev/null
    mln-select "$datadir/mln.results"
    ;;
  position)
    echo `basename "$datadir"` `extract-wo "$datadir/igt.all" | wo-position` ;;
esac
