Skip to content
Snippets Groups Projects
Select Git revision
  • 0a29cc3d6544adff5c4eb33e1e1022aed71197d1
  • master default protected
2 results

evaluate.sh

Blame
  • evaluate.sh 1.83 KiB
    #! /usr/bin/env bash
    
    function has_space {
      [[ "$1" != "${1%[[:space:]]*}" ]] && return 0 || return 1
    }
    
    function print_usage_and_exit {
      >&2 echo "USAGE : (tsv | txt) expPath [arguments]"
      exit 1
    }
    
    MODE=$1
    EXPPATH=$2
    
    if [ -z "$MODE" ];
    then
      >&2 echo "ERROR : missing argument 1 (mode)"
      print_usage_and_exit
    fi
    
    if [ -z "$EXPPATH" ];
    then
      >&2 echo "ERROR : missing argument 2 (expPath)"
      print_usage_and_exit
    fi
    
    shift
    shift
    
    if [ ! -d "$EXPPATH" ]; then
      >&2 echo "ERROR : directory $EXPPATH doesn't exist"
      print_usage_and_exit
    fi
    
    source $EXPPATH"/config"
    
    TRAIN=$(find $CORPUS -type f -name '*train*.conllu')
    TRAINRAW=$(find $CORPUS -type f -name '*train*.txt')
    DEV=$(find $CORPUS -type f -name '*dev*.conllu')
    DEVRAW=$(find $CORPUS -type f -name '*dev*.txt')
    TEST=$(find $CORPUS -type f -name '*test*.conllu')
    TESTRAW=$(find $CORPUS -type f -name '*test*.txt')
    MCD=$(find $CORPUS -type f -name '*.mcd')
    
    REF=$TEST
    REFRAW=$TESTRAW
    
    if has_space "$REF" || has_space "$REFRAW" || has_space "$MCD";
    then
      >&2 echo "ERROR : more than 1 match"
      >&2 echo "REF : " $REF
      >&2 echo "REFRAW : " $REFRAW
      >&2 echo "MCD : " $MCD
      print_usage_and_exit
    fi
    
    if test ! -f $REF;
    then
      >&2 echo "ERROR : no ref file found in" $CORPUS
      >&2 echo "$REF"
      print_usage_and_exit
    fi
    if test ! -f $REFRAW;
    then
      >&2 echo "ERROR : no ref file found in" $CORPUS
      >&2 echo "$REFRAW"
      print_usage_and_exit
    fi
    
    if test -z $MCD;
    then
    	MCD=$EXPPATH"/data/*\.mcd"
    fi
    
    EVALCONLL="../scripts/conll18_ud_eval.py"
    OUTPUT=$EXPPATH"/predicted_eval.tsv"
    
    if [ "$MODE" = "tsv" ]; then
    macaon decode --model $EXPPATH --mcd $MCD --inputTSV $REF $@ > $OUTPUT && $EVALCONLL $REF $OUTPUT -v || exit 1
    exit 0
    fi
    
    if [ "$MODE" = "txt" ]; then
    macaon decode --model $EXPPATH --mcd $MCD --inputTXT $REFRAW $@ > $OUTPUT && $EVALCONLL $REF $OUTPUT -v || exit 1
    exit 0
    fi
    
    print_usage_and_exit