<commit_before>#!/bin/bash
#
#   Copyright 2012 <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# Usage:
#
#   justify.sh 
#
#   justify.sh http://ieeevis.tw.rpi.edu/lam-2012-evaluations-2-categories source/lodspeakr-basic-menu.svg svg-crowbar
#   ==> source/lodspeakr-basic-menu.svg was derived from http://ieeevis.tw.rpi.edu/lam-2012-evaluations-2-categories

if [ $# -lt 3 -o $# -gt 4 ]; then
   echo "usage:   `basename $0` path/to/source/a.xls path/to/destination/a.xls.csv <engine-name>" 
   echo "or" 
   echo "usage: . `basename $0` path/to/source/a.xls path/to/destination/a.xls.csv <engine-name> [-h | --history]" 
   echo ""
   echo "   source      file: a file used to create 'destination file'."
   echo "   destination file: a file derived from 'source file'."
   echo ""
   echo "   engine-name     : URI-friendly local name of method used to create destination from source:"
   echo "      xls2csv,   tab2comma,     redelimit,            file_rename,   escaping_commas_redelimit"
   echo "      duplicate, google_refine, serialization_change, parse_field,   tabulating_fixed_width"
   echo "      html_tidy, pretty_print,  xsl_html_scrape,      manual_csvify, uncompress"
   echo "      select_subset, etc."
   echo ""
   echo "   --history: search command history for the command that created 'destination-file' "
   echo "              from 'source-file' and include it in the provenance."
   echo "              NOTE: a period (.) must precede the `basename $0` command to access history."
   echo "              This option only works in interactive shells."
else

see='https://github.com/timrdf/csv2rdf4lod-automation/wiki/CSV2RDF4LOD-not-set'
CSV2RDF4LOD_HOME=${CSV2RDF4LOD_HOME:?"not set; source csv2rdf4lod/source-me.sh or see $see"}

if [ $0 == "bash" ]; then
   # In case of --history's . invocation
   myMD5=`md5.sh $CSV2RDF4LOD_HOME/bin/util/justify.sh` 
else
   # In case of no --history
   myMD5=`md5.sh $0`
fi

logID=`resource-name.sh`

antecedent="$1"
consequent="$2"

if [[ "$3" == "-h" || "$3" == "--history" ]]; then
   echo "ERROR: Requested -h --history, but did not specify <engine-name>."
else
   method="`echo $3 | awk '{print tolower($0)}'`"                                                           # e.g., 'serialization_change'
   method_name="conv:${method}_Method"                                                                      # e.g., 'serialization_change_Method'
   engine_type="conv:`echo $method | awk '{print toupper(substr($0,0,1)) substr($0,2,length($0))}'`_Engine" # e.g.  'Serialization_change_Engine

   #echo "my MD5     : $myMD5"
   #echo "antecedent : $antecedent"
   #echo "consequent : $consequent"
   #echo "method     : $method"
   #echo "method name: $method_name"
   #echo "engine type: $engine_type"

   commandUsed=""
   if [ $# -ge 4 ]; then
      if [ ${4:-"."} == "-h" -o ${4:-"."} == "--history" ]; then
         if [ `history | wc -l` -gt 0 ]; then
            commandUsed=`history | grep -v "justify.sh" | grep "$antecedent" | grep "$consequent" | tail -1`

            if [ ${#commandUsed} -lt 1 ]; then
               # If we didn't find one for both, find one with just the consequent.
               commandUsed=`history | grep -v "justify.sh" | grep "$consequent" | tail -1`<commit_msg>fixed parse error when given a full URI<commit_after>#!/bin/bash
#
#   Copyright 2012 <NAME>
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# Usage:
#
#   justify.sh 
#
#   justify.sh http://ieeevis.tw.rpi.edu/lam-2012-evaluations-2-categories source/lodspeakr-basic-menu.svg svg-crowbar
#   ==> source/lodspeakr-basic-menu.svg was derived from http://ieeevis.tw.rpi.edu/lam-2012-evaluations-2-categories

if [ $# -lt 3 -o $# -gt 4 ]; then
   echo "usage:   `basename $0` path/to/source/a.xls path/to/destination/a.xls.csv <engine-name>" 
   echo "or" 
   echo "usage: . `basename $0` path/to/source/a.xls path/to/destination/a.xls.csv <engine-name> [-h | --history]" 
   echo ""
   echo "   source      file: a file used to create 'destination file'."
   echo "   destination file: a file derived from 'source file'."
   echo ""
   echo "   engine-name     : URI-friendly local name of method used to create destination from source:"
   echo "      xls2csv,   tab2comma,     redelimit,            file_rename,   escaping_commas_redelimit"
   echo "      duplicate, google_refine, serialization_change, parse_field,   tabulating_fixed_width"
   echo "      html_tidy, pretty_print,  xsl_html_scrape,      manual_csvify, uncompress"
   echo "      select_subset, etc."
   echo ""
   echo "   --history: search command history for the command that created 'destination-file' "
   echo "              from 'source-file' and include it in the provenance."
   echo "              NOTE: a period (.) must precede the `basename $0` command to access history."
   echo "              This option only works in interactive shells."
else

see='https://github.com/timrdf/csv2rdf4lod-automation/wiki/CSV2RDF4LOD-not-set'
CSV2RDF4LOD_HOME=${CSV2RDF4LOD_HOME:?"not set; source csv2rdf4lod/source-me.sh or see $see"}

if [ $0 == "bash" ]; then
   # In case of --history's . invocation
   myMD5=`md5.sh $CSV2RDF4LOD_HOME/bin/util/justify.sh` 
else
   # In case of no --history
   myMD5=`md5.sh $0`
fi

logID=`resource-name.sh`

antecedent="$1"
consequent="$2"

if [[ "$3" == "-h" || "$3" == "--history" ]]; then
   echo "ERROR: Requested -h --history, but did not specify <engine-name>."
else
   method="`echo $3 | awk '{print tolower($0)}'`"                                                           # e.g., 'serialization_change'
   method_name="conv:${method}_Method"                                                                      # e.g., 'serialization_change_Method'
   if [[ "$method" =~ http* ]]; then
      method_name="<${method}>"
   fi
   method_name="conv:${method}_Method"                                                                      # e.g., 'serialization_change_Method'
   engine_type="conv:`echo $method | awk '{print toupper(substr($0,0,1)) substr($0,2,length($0))}'`_Engine" # e.g.  'Serialization_change_Engine

   #echo "my MD5     : $myMD5"
   #echo "antecedent : $antecedent"
   #echo "consequent : $consequent"
   #echo "method     : $method"
   #echo "method name: $method_name"
   #echo "engine type: $engine_type"

   commandUsed=""
   if [ $# -ge 4 ]; then
      if [ ${4:-"."} == "-h" -o ${4:-"."} == "--history" ]; then
         if [ `history | wc -l` -gt 0 ]; then
            commandUsed=`history | grep -v "justify.sh" | grep "$antecedent" | grep "$consequent" | tail -1`

            if [ ${#commandUsed} -lt 1 ]; then
               # If we didn't find one for both, find one with just the consequent.
               commandUsed=`history | grep -v "justify.sh" | grep "$consequent" | tail -1`
{'fraction_non_alphanumeric': 0.13420079091720882, 'fraction_numerical': 0.016328613343538717, 'mean_word_length': 2.588100686498856, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1026213', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2505, 'n_words': 731}