-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOperations.java
More file actions
138 lines (113 loc) · 4.1 KB
/
Operations.java
File metadata and controls
138 lines (113 loc) · 4.1 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
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
package spl1;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Operations {
public String[] words= new String[85000]; //to store the base words
public String[] stop= new String[85000]; //to remove stop word
public ArrayList<ArrayList<String>> aList = new ArrayList<ArrayList<String> >(85000);//to store all the words
public ArrayList<String> inList = new ArrayList<String>();//to store the input words
public static ArrayList<String> outList = new ArrayList<String>();
int i=0;
public Operations() {
}
public Operations(ArrayList<String> outList) {
this.outList = outList;
}
public ArrayList<String> getOutList() {
return outList;
}
//to search
public void search(){
Boolean found = false;
int outIt=0;
for(i=0; i < inList.size(); i++){
found = false;
NEW:
for (int j=0; j<aList.size(); j++){
for (int k=0; k<aList.get(j).size(); k++){
if(aList.get(j).get(k).equals(inList.get(i))){
// System.out.print(words[j]+" ");
outList.add(outIt,words[j]);
outIt++;
found = true;
break NEW;
}
}
}
if(!found){
// System.out.print(inList.get(i)+" ");
outList.add(outIt, inList.get(i));
outIt++;
}
}
}
//to split the input
public void splitInput(String inputString) throws FileNotFoundException{
String[] inArray = inputString.split("[ ,?/;>.*'|\"(){+></@#$%^&_=}]",0);
for(int j=0;j<inArray.length;j++){
//inArray[j].
char str[]=inArray[j].toCharArray();
for(i=0;i<str.length;i++)
{
if(str[i]>='A' && str[i]<='Z')
{
str[i]=(char)((int)str[i]+32);
}
}
for(i=0;i<str.length;i++) {
inArray[j]= "";
}
for(i=0;i<str.length;i++) {
inArray[j]+= Character.toString(str[i]);
}
// inArray[j] = inArray[j].toLowerCase();
inList.add(inArray[j]);
}
}
public void removeWord() throws FileNotFoundException
{
File files = new File("src/spl1/removablewords.txt");
Scanner sc = new Scanner(files);
while (sc.hasNextLine()){
stop[i++] = sc.nextLine();
}
ArrayList <String> stopWordList =new ArrayList<>();
stopWordList.addAll(Arrays.asList(stop));
inList.removeAll(stopWordList);
System.out.print("After removing stop words : ");
for(int i=0;i<inList.size();i++)
{
System.out.print(inList.get(i)+" ");
}
System.out.println("");
}
//to split the database
public void spliter() throws IOException {
//get the file
File file = new File("src/spl1/baseWords.txt");
//FileWriter newDb = new FileWriter("newDB.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
words[i] = sc.nextLine();
String[] firstSplit= words[i].split(" -> ",0);
char[] arr = firstSplit[0].toCharArray();
firstSplit[0] = "";
for(int j=0;j < arr.length ; j++){
if( arr[j] != '/')
firstSplit[0] += arr[j];
else break;
}
words[i] = firstSplit[0];
String[] secondSplit = firstSplit[1].split(",",0);
ArrayList<String> a1 = new ArrayList<String>();
for(int j=0;j<secondSplit.length;j++) {
a1.add(secondSplit[j]);
// newDb.write(secondSplit[j] + " -> " + words[i] + "\n");
}
aList.add(a1);
i++;
}
}
}