-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlanguageDetect.java
More file actions
55 lines (48 loc) · 1.43 KB
/
Copy pathlanguageDetect.java
File metadata and controls
55 lines (48 loc) · 1.43 KB
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
package lab5;
/*
* Put the text through your Huffman frequency code to get a frequency profile, and then compare it against these European languages to see
which one is the best match. Come up with some metric for quantifying how good the fit is.
* */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
public class languageDetect
{
public static void main(String[] args)
{
try
{
File fileDir = new File("H://mystery.txt");
BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(fileDir), "UTF-8"));//reading in the file as unicode
String str;
String ini=new String("");//enter file into this string
while ((str = in.readLine()) != null) //keep reading in until nothing left
{
//if(str!="")//not needed
//{
ini+=str;
System.out.println(str);
//}
}
double freq []=huffmanAdapt.main(ini);
String a=getDiff.main(freq);
System.out.println("the language seems to be "+a);
in.close();
}
catch (UnsupportedEncodingException e)
{
System.out.println(e.getMessage());
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
catch (Exception e)
{
System.out.println("end of string");
}
}
}