| # Define base directory, Python script, and input directory | |
| BASE_DIR="$HOME/exp/myNLP/lang_detect" | |
| PYTHON_SCRIPT="$BASE_DIR/demo_usage.py" # Replace with the name of your Python script | |
| INPUT_DIR="$BASE_DIR/data/eg_input" | |
| WORD2VEC_DIR="$BASE_DIR/word2vec" | |
| FASTTEXT_DIR="$BASE_DIR/fasttext" | |
| # Function to run language detection | |
| run_detection() { | |
| model_type=$1 | |
| model_dir=$2 | |
| echo "Running language detection using $model_type models..." | |
| for file in "$INPUT_DIR"/*; do | |
| filename=$(basename -- "$file") | |
| detected_language=$(python3 "$PYTHON_SCRIPT" --mode detect --approach $model_type --input "$file" --profiles "$model_dir") | |
| echo "File: $filename - Detected Language with $model_type: $detected_language" | |
| # Run detection on random sentences from the file, 10 times | |
| for i in {1..10}; do | |
| random_sentence=$(shuf -n 1 "$file") | |
| echo "Attempt $i - Random sentence from $filename: $random_sentence" | |
| detected_language_sentence=$(python3 "$PYTHON_SCRIPT" --mode detect --approach $model_type --input "$random_sentence" --profiles "$model_dir") | |
| echo "Detected Language with $model_type: $detected_language_sentence" | |
| done | |
| echo "" | |
| done | |
| } | |
| # Run detection using Word2Vec models | |
| run_detection "word2vec" "$WORD2VEC_DIR" | |
| # Run detection using FastText models | |
| run_detection "fasttext" "$FASTTEXT_DIR" | |
| echo "Language detection completed for all files." | |