#!/bin/bash
# Teste si une expression fait parti des dictionnaires.
# Les paramètres doivent être passés dans le fichier (command cat)
# erg-test-conf avec séparé par une tabulation :
# - le nom du fichier original
# - le nom du fichier total
# l'argument $1 indique l'expression à rechercher.
# ou bien personnalisé ci-dessous avec un echo et un if éventuel.
# ou bien il faut éditer le fichier bash erg-test pour indiquer quels sont les dictionnaires à vérifier.

if [ "$1" = "" ]
then
	echo " erg-test teste la solidite d'un vocabulaire.
 Les paramètres doivent être passés dans le fichier
 erg-test-conf avec séparé par une tabulation :
 - le nom du fichier original
 - le nom du fichier total
 l'argument $1 indique l'expression à rechercher"
fi

#cat erg-test-conf | while read i
#echo "total_des_fichiers_total
#../code-fr-sans_section.txt
#../dic/dic-manuel-suppr.txt
#../dic/dic-manuel-lemmatisation.txt
#../dic/dic-frq
#../dic/dic-auto-lemmatisation.csv"
find $2  | while read i
do
	if [ -f "$i" ]
	then
		# Bold
		echo -e "\n\033[1m$i\033[0m"
		# retour à la normale
		tput sgr0
		# Test pour savoir si les mots doivent être comptés.
		if [ "$(echo "$i" | sed -e "s/^.*\///g")" = "total_des_fichiers_total" ]
		then
			if [ "$3" = "w" ]
			then
				cat "$i" | grep -w "$1"
			else
				cat "$i" | grep "$1"
			fi

		elif [ "$(echo "$i" | sed -e "s/^.*\///g")" = "dic-auto-lemmatisation.csv" ]
		then
			if [ "$3" = "w" ]
			then
				cat "$i" | erg-mots | erg-suppr_num | grep -w "$1" | uniq -ic 
			else
				cat "$i" | erg-mots | erg-suppr_num | grep "^$1" | uniq -ic 
			fi
		else
			if [ "$3" = "w" ]
			then
				cat "$i" | erg-mots | uniq -ic | grep -w "$1"
			else
				cat "$i" | erg-mots | uniq -ic | grep "$1"
			fi
		fi

	fi
done
