-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartScan.java
94 lines (85 loc) · 2.82 KB
/
SmartScan.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.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.LinkedHashSet;
import java.util.Collections;
public class SmartScanning
{
private String txt1;
private String txt2;
private ArrayList<String> words1 = new ArrayList<String>();
private ArrayList<String> words2 = new ArrayList<String>();
private int minfreq;
private ArrayList<String> uwords1;
private ArrayList<String> uwords2;
private ArrayList<Integer> amtwords1 = new ArrayList<Integer>();
private ArrayList<Integer> amtwords2 = new ArrayList<Integer>();
public SmartScanning(String t1, String t2, int f)
{
txt1 = t1.toLowerCase();
txt2 = t2.toLowerCase();;
txt1 = txt1.replaceAll("\\p{Punct}", "");
txt2 = txt2.replaceAll("\\p{Punct}", "");
minfreq = f;
}
private void wordArrayMaker()
{
String[] word1 = txt1.split("[ ]+");
String[] word2 = txt2.split("[ ]+");
int num = 0;
for(String s : word1)
{
words1.add(s);
}
for(String s : word2)
{
words2.add(s);
}
uwords1 = new ArrayList<>(new LinkedHashSet<>(words1));
uwords2 = new ArrayList<>(new LinkedHashSet<>(words2));
num = 0;
for(String s : uwords1)
{
amtwords1.add(Collections.frequency(words1, s));
}
for(String s : uwords2)
{
amtwords2.add(Collections.frequency(words2, s));
}
}
public void removeAbvFreq()
{
this.wordArrayMaker();
int num = 0;
for(Integer i : amtwords1)
{
if(i>minfreq)
{
txt1 = txt1.replaceAll(" " + words1.get(num) + " ", " ");
txt1 = txt1.replaceAll(" " + words1.get(num) + ".", "");
txt1 = txt1.replaceAll(" " + words1.get(num) + ",", "");
txt1 = txt1.replaceAll(" " + words1.get(num) + "", "");
txt1 = txt1.replaceAll("" + words1.get(num) + " ", "");
txt1 = txt1.replaceAll("" + words1.get(num) + ",", "");
}
if(num<amtwords2.size() && amtwords2.get(num)>minfreq)
{
txt2 = txt2.replaceAll(" " + words2.get(num) + " ", " ");
txt2 = txt2.replaceAll(" " + words2.get(num) + ".", "");
txt2 = txt2.replaceAll(" " + words2.get(num) + ",", "");
txt2 = txt2.replaceAll(" " + words2.get(num) + "", "");
txt2 = txt2.replaceAll("" + words2.get(num) + " ", "");
txt2 = txt2.replaceAll("" + words2.get(num) + ",", "");
}
num++;
}
}
public String getText1()
{
return txt1;
}
public String getText2()
{
return txt2;
}
}