File size: 1,473 Bytes
0d84e21
 
 
aa61fae
 
0d84e21
 
 
 
 
 
 
 
 
 
 
aa61fae
0d84e21
 
 
 
 
 
aa61fae
0d84e21
 
 
 
 
 
 
aa61fae
0d84e21
 
aa61fae
0d84e21
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

# 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."