#!/bin/bash

## trying to implement emily's case-matrix algorithm
## 
## what i realized is that the original step-by-step doesn't
## correspond well to the practical steps for implementation.
##
## after consideration, i think that the first step is to
## build up a survey of relevant objects that are queryable 
## for the properties we want to reason about.
##
## then, we go reasoning over those objects.  
##
## to this end, i created the class Verb and Arg in scripts
## 
dir=$1
outdir=$2
if [ ! -d $outdir ]; then 
  mkdir "$outdir"
fi

## do for each lang
for l in `ls $dir`; do
  echo "============="
  echo "processing $l"
  echo "============="
  lpath="$dir/$l"
  if [ ! -d "$outdir/$l" ]; then 
    mkdir "$outdir/$l"
  fi


#Here is a first version of a "case matrix", or set of info on what
#to look for in the IGT to choose the different case options.
#
#I'm going to start first from the choices on this page:
#http://www.delph-in.net/matrix/customize/matrix.cgi?subpage=case
#
#1. Find a sample of two argument verbs, where both arguments
#are nouny (NPs or PPs) and overt.  (We may make a list of verbs
#to avoid, via English glosses, if possible, as they may be 
#misleading, e.g.: "be", "have", "like", "please".)


  ## read igt all file into python module and use that
  # ./scripts/sample_verbs.py "$outdir/$l" $lpath/igt.all 2
  # output is in outdir/2verbs and outdir/2trees 

#2. Find a sample of one argument verbs, where the argument
#is nouny (NP or PP) and overt.  (The projection from the translation
#line should help with detecting predicate arity and covert arguments.)
  ## read igt all file into python module and use that
  # ./scripts/sample_verbs.py "$outdir/$l" $lpath/igt.all 1
  # output is in outdir/1verbs and outdir/1trees 

#
#3. Look for grams in the NP, which maybe be on the head noun, an
#adposition, or on its dependents (determiners, adjectives).  Exclude
#grams for person (1st, 2nd, 3rd) and number (sg, pl, du, non-sg, etc).
#Case grams may include: nom, acc, abs, erg, dat, gen, obl, subj, obj
#and others. 
  # so we want to find examples of NPs and then check the gloss line
  # for those examples
  # ./scripts/sample_nps.py "$outdir/$l" $lspath/igt.all
  # output in outdir/nps.grams and outdir/nps.log

#4. For the two argument verbs, determine which argument is
#the subject.  The best way to do this for now is probably via
#a projection from English.  Call the subject "A" and the other
#argument "O".  Call the sole argument of one argument verbs "S".
#
#5. Discard any grams which appear on both A and O (with the same
#tense on the verb and the same person value for the arguments).
#
#6. Compare the remaining grams on A and O to those on S. Note
#that only one or two of these may have any grams.  If there is more
#than one gram for each, there is likely some noise in the data.
#
#I. No such grams: Choose option "no case".
#
#II. A=S, O is different: Choose option Nominative-Accusative.
#
#III. S=O, A is different: Chose option Ergative-Absolutive. 
#
#IV. S, A, and O all different: Choose option Tripartite. 
#
#V. Single argument verbs appear with two different cases on the
#S, one same as A, one same as O, but always consistent for a given
#verb: Choose split-S
#
#VI. Single argument verbs appear with two different cases on the
#S, one same as A, one same as O, but not always consistent for a given
#verb: Choose fluid-S
#
#VII. The case grams are different for some nouns than others (e.g.,
#pronouns v. other nouns or 1st and 2nd person vs. 3rd person): Choose
#Split-N
#
#==> Case page says can enter more info on Lexicon page, but I can't
#find that.  What is it?  Need to ref Scott's thesis and possibly to
#fix this.
#
#VIII. S=A for verbs with some values for certain features (typically
#tense/aspect/mood) but S=O for verbs with different values for those
#features: Choose Split-V
#
#==> Again there might be something to fix on the lexicon page
#
#IX. Focus case.  I think we can ignore this one for now --- and
#maybe only trigger it if we know we have an austronesian language.
#
#Some further notes:
#
#We can probably add some a priori biases based on the typological
#frequency of the various choices.  WALS might have this info.
#
#For some languages, WALS might have the answer directly.
#
#For all languages with anything other than "none", we allow for the
#definition of additional cases and of additional verb types with different
#case frames.
#
#Just answering this question doesn't make a complete analysis of case.
#We also have to figure out where the case is marked within the NP, and
#define the appropriate lexical types (e.g., of determiners, pronouns,
#case-marking adpositions) or lexical rules (e.g., for nouns).  In addition,
#the questionnaire asks for names for each of the cases.  This could
#be drawn from the grams.
#
#
done
