-
Notifications
You must be signed in to change notification settings - Fork 0
/
Processing.java
157 lines (125 loc) · 5.46 KB
/
Processing.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Map.Entry;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class Processing
{
static double falsePositiveProbability = 0.1;
static int expectedSize = 500000;
//GERMAN
static BloomFilter<String> de_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
//ENGLISH
static BloomFilter<String> eng_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
//FRENCH
static BloomFilter<String> fr_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
//SPANISH
static BloomFilter<String> es_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
//ITALIAN
static BloomFilter<String> it_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
//PORTUGESE
static BloomFilter<String> pt_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
//DUTCH
static BloomFilter<String> nl_bloomFilter = new BloomFilter<String>(falsePositiveProbability, expectedSize);
public static void process_input( List<String> input_text ) throws URISyntaxException, IOException
{
//THIS SEGMENT IS FOR DYNAMICALLY LOCATING THE DIRECTORY, SO THE PROGRAM WORKS "OUT OF THE BOX"
/*******************************************************************************************************************************************/
//this holds all the dictionary files, i.e. word lists garners from language folders
ArrayList<Path> dictionary_files = new ArrayList<Path>();
File currentDir = new File(".");
File targetDir = new File( currentDir, "ascii_word_lists" );
//File targetDir = new File( currentDir, "unicode_word_lists" );
if (targetDir.exists())
{
SearchDirectories.listDirectoryAndFiles( targetDir.toPath(), dictionary_files );
}
/*******************************************************************************************************************************************/
//this populates word presence data structs for each language
for(Path dir : dictionary_files)
{
String word_holding_directory_path = dir.toString().toLowerCase();
//BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream( dir.toString() ), "UTF-16LE") );
BufferedReader br = new BufferedReader( new FileReader( dir.toString() ) );
String line = null;
BloomFilter<String> bloomFilter;
if (word_holding_directory_path.toLowerCase().contains("/de/"))
{
bloomFilter = de_bloomFilter;
}
else if (word_holding_directory_path.toLowerCase().contains("/eng/"))
{
bloomFilter = eng_bloomFilter;
}
else if (word_holding_directory_path.toLowerCase().contains("/fr/"))
{
bloomFilter = fr_bloomFilter;
}
else if (word_holding_directory_path.toLowerCase().contains("/es/"))
{
bloomFilter = es_bloomFilter;
}
else if (word_holding_directory_path.toLowerCase().contains("/it/"))
{
bloomFilter = it_bloomFilter;
}
else if (word_holding_directory_path.toLowerCase().contains("/nl/"))
{
bloomFilter = nl_bloomFilter;
}
else if (word_holding_directory_path.toLowerCase().contains("/pt/"))
{
bloomFilter = pt_bloomFilter;
}
else
{
continue;
}
while ( ( line = br.readLine() ) != null )
{
bloomFilter.add( line.toLowerCase().trim() );
}
}
Map<String, BloomFilter<String>> langMaps = new HashMap<>();
langMaps.put( "Italiano, (Italian)", it_bloomFilter);
langMaps.put( "Français, (French)", fr_bloomFilter);
langMaps.put( "English, (English)", eng_bloomFilter);
langMaps.put( "Deutsch, (German)", de_bloomFilter);
langMaps.put( "Español, (Spanish)", es_bloomFilter);
langMaps.put( "Nederlandse, (Dutch)", nl_bloomFilter);
langMaps.put( "Português, (Portugese)", pt_bloomFilter);
int maxCount = 0;
String maxLang = null;
for (Map.Entry<String, BloomFilter<String>> entry : langMaps.entrySet())
{
int count = 0;
BloomFilter<String> words = entry.getValue();
for (String word : input_text)
{
String normalized = word.trim().toLowerCase();
if (words.contains(normalized))
{
++count;
}
}
if (count > maxCount)
{
maxLang = entry.getKey();
maxCount = count;
}
}
//System.out.println( "Language is: " + maxLang );
JOptionPane.showMessageDialog(null,"Language is: " + maxLang);
}
}