#!/bin/bash # Overview # -------- # Little script to export in scheme format (readily dumpable into the # AtomSpace) the models and their scores, given to a CSV, following # Mike's format, 3 columns, the combo program, its recall (aka # sensitivity) and its precision (aka positive predictive value). # # Usage # ----- # Run it without argument to print the usage. # # Description # ----------- # The model will be labeled FILENAME:moses_model_INDEX # # where FILENAME is the basename of the filename provided in argument, # and INDEX is the row index of the model (starting by 0) # # The exported hypergraphs are # # 1. The model itself associated with its label (MODEL_PREDICATE_NAME) # # EquivalenceLink <1, 1> # PredicateNode MODEL_PREDICATE_NAME # MODEL # # 2. The label associated with its accuracy # # EvaluationLink # PredicateNode "accuracy" # ListLink # PredicateNode PREDICATE_MODEL_NAME # PredicateNode TARGET_FEATURE_NAME # # 3. The label associated with its balanced accuracy [REMOVED] # # EvaluationLink # PredicateNode "balancedAccuracy" # ListLink # PredicateNode PREDICATE_MODEL_NAME # PredicateNode TARGET_FEATURE_NAME # # 4. The label associated with its precision [REMOVED] # # ImplicationLink # PredicateNode MODEL_PREDICATE_NAME # PredicateNode TARGET_FEATURE_NAME # # 5. The label associated with its recall # # ImplicationLink # PredicateNode TARGET_FEATURE_NAME # PredicateNode MODEL_PREDICATE_NAME set -u # raise error on unknown variable read # set -x # debug trace #################### # Source common.sh # #################### PRG_PATH="$(readlink -f "$0")" PRG_DIR="$(dirname "$PRG_PATH")" . "$PRG_DIR/common.sh" #################### # Program argument # #################### if [[ $# == 0 || $# -gt 4 ]]; then echo "Usage: $0 MODEL_CSV_FILE PRED_NAME [-o OUTPUT_FILE]" echo "Example: $0 chr10_moses.5x10.csv \"aging\" -o chr10_moses.5x10.scm" exit 1 fi readonly MODEL_CSV_FILE="$1" readonly BASE_MODEL_CSV_FILE="$(basename "$MODEL_CSV_FILE")" readonly PRED_NAME="$2" shift OUTPUT_FILE="/dev/stdout" while getopts "o:" opt; do case $opt in o) OUTPUT_FILE="$OPTARG" ;; esac done ############# # Functions # ############# # Given # # 1. a model predicate name # # 2. a combo model # # return a scheme code defining the equivalence between the model name # and the model: # # EquivalenceLink <1, 1> # PredicateNode MODEL_PREDICATE_NAME # MODEL model_name_def() { local name="$1" local model="$2" cat < # PredicateNode "accuracy" # ListLink # PredicateNode PREDICATE_MODEL_NAME # PredicateNode TARGET_FEATURE_NAME model_accuracy_def() { local name="$1" local target="$2" local accuracy="$3" cat < # PredicateNode PREDICATE_MODEL_NAME # PredicateNode TARGET_FEATURE_NAME model_precision_def() { local name="$1" local target="$2" local precision="$3" cat < # PredicateNode TARGET_FEATURE_NAME # PredicateNode PREDICATE_MODEL_NAME model_recall_def() { local name="$1" local target="$2" local recall="$3" cat < "$OUTPUT_FILE" IFS="$OLDIFS"