-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector.java
93 lines (86 loc) · 4 KB
/
Vector.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
import java.io.*;
import java.util.*;
class Vector
{
public int[] getVectorArr(String FILENAME,HashMap<String,Integer> map) throws IOException
{
BufferedReader br=new BufferedReader(new FileReader(FILENAME));
BufferedReader br2=new BufferedReader(new FileReader(FILENAME));
WordPlay WP = new WordPlay();
int counter=WP.wordCount(br,map);
System.out.println(counter);
int arr[]=new int[counter];
createVector(br2,map,arr);
return arr;
}
public void printVector(int arr[])
{
for(int i=0;i<arr.length;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
public void createVector(BufferedReader br, HashMap<String,Integer> map,int arr[]) throws IOException
{
String line;
WordPlay WP = new WordPlay();
while((line=br.readLine())!=null)
{
String words[]=line.split(" ");
for(int i=0;i<words.length;i++)
{
String curWord = WP.formatWord(words[i]);
int pos = map.get(curWord);
arr[pos]++;
}
}
}
public double matchVectors(HashMap<String,Integer> map1,int vector1[],HashMap<String,Integer> map2,int vector2[], ArrayList<String> matchings)
{
int total=0;int match=0;
Iterator it = map1.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
//System.out.println(pair.getKey() + " = " + pair.getValue());
//it.remove(); // avoids a ConcurrentModificationException
String key = (String)pair.getKey();
UselessKeywords UK = new UselessKeywords();
if(UK.uselessWord(key)==true)
continue;
if(map2.get(key)!=null){
int count1 = vector1[(int)pair.getValue()];
int count2 = vector2[map2.get(key)];
matchings.add((String)pair.getKey());
//System.out.println("count1 = "+count1+" count2 = "+count2);
total+=count1+count2;
match+=2*(Math.min(count1,count2));
//System.out.println("total = "+total+" match = "+match);
}
else
{
total+=vector1[(int)pair.getValue()];
//System.out.println("total = "+total+" match = "+match);
}
}
//System.out.println("second file begins");
Iterator it2 = map2.entrySet().iterator();
while (it2.hasNext()) {
Map.Entry pair = (Map.Entry)it2.next();
//System.out.println(pair.getKey() + " = " + pair.getValue());
String key = (String)pair.getKey();
UselessKeywords UK = new UselessKeywords();
if(UK.uselessWord(key)==true)
continue;
if(map1.get(key)==null)
{
total+=vector2[(int)pair.getValue()];
//System.out.println("total = "+total+" match = "+match);
}
}
System.out.println("grand total = "+total);
System.out.println("grand match = "+match);
double score = ((double)match/total)*100;
return score;
}
}