-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexMaker.java
More file actions
247 lines (228 loc) · 7.82 KB
/
Copy pathIndexMaker.java
File metadata and controls
247 lines (228 loc) · 7.82 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//IndexMaker
//main class for SermonIndexer project
//handles i/o
//Emily Stuckey
//1-10-16
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class IndexMaker {
public IndexMaker(){
Scanner input = new Scanner(System.in);
System.out.print("Enter 1 to create a new Sermon index, 2 to create a new ");
System.out.print("scriptural index, 3 to merge indices, 4 to merge Scriptural ");
System.out.print("indices, 5 to search a sermon for Scriptural indices ");
System.out.print("(and make a scriptural index), anything else to exit: ");
int whatWant = input.nextInt();
if (whatWant == 1){
boolean done = false;
notDone: while (!done){
//creating new index
System.out.print("Enter number/title of sermon or EXIT to exit: ");
String serm = input.next();
if (serm.equalsIgnoreCase("exit")){
done = true;
break notDone;
}
System.out.print("Enter name of file (remember extension): ");
String fName = input.next();
if (fName.equalsIgnoreCase("exit")){
done = true;
break notDone;
}
try {
//Open the given file
Index sermIndex = new Index(serm, fName);
//create a new DocumentIndex from the file
BufferedWriter sermWriter = new BufferedWriter(new FileWriter(serm + "-index.txt"));
//Create an output file for that sermon: e.g. "1-index.txt"
//write the DocumentIndex to the output file
sermWriter.write(sermIndex.toString());
sermWriter.flush();
sermWriter.close();
}
catch (IOException e){
System.out.println("Error in IndexMaker: " + e.getMessage());
}
}
}
else if (whatWant == 2){
boolean done = false;
notDone2: while (!done){
System.out.print("Enter number/title of sermon or EXIT to exit: ");
String serm = input.next();
if (serm.equalsIgnoreCase("exit")){
done = true;
break notDone2;
}
System.out.print("Enter name of file (remember extension): ");
String fName = input.next();
if (fName.equalsIgnoreCase("exit")){
done = true;
break notDone2;
}
try {
//Open the given file
ScriptureIndex scriptIndex = new ScriptureIndex(serm, fName);
//create a new DocumentIndex from the file
BufferedWriter scriptWriter = new BufferedWriter(new FileWriter(serm + "-scr-index.txt"));
//Create an output file for that sermon: e.g. "1-index.txt"
//write the DocumentIndex to the output file
scriptWriter.write(scriptIndex.toString());
scriptWriter.flush();
scriptWriter.close();
}
catch (IOException e){
System.out.println("Error in IndexMaker: " + e.getMessage());
}
}
}
else if (whatWant == 3){
//merging indices
boolean done = false;
ArrayList<String> filesToMerge = new ArrayList<String>();
boolean moreFiles = true;
notDone3: while (!done){
filesToGo: while (moreFiles){
System.out.print("Enter name of next file to merge (remember extension) or DONE: ");
String fName2 = input.next();
if (fName2.equalsIgnoreCase("exit")){
done = true;
break notDone3;
}
if (fName2.equalsIgnoreCase("done")){
moreFiles = false;
break filesToGo;
}
filesToMerge.add(fName2);
}
System.out.print("Enter name of destination (remember extension): ");
String fName3 = input.next();
if (fName3.equalsIgnoreCase("exit")){
done = true;
break notDone3;
}
if (filesToMerge.size() < 2){
System.out.println("Not enough files!");
done = true;
break notDone3;
}
try {
String file1 = filesToMerge.remove(0);
Index ind1 = new Index(new FileReader(file1));
Index compIndex = new Index();
while (filesToMerge.size() != 0){
//Open the given files
Index ind2 = new Index(new FileReader(filesToMerge.remove(0)));
compIndex = new Index(ind1, ind2);
//create a new DocumentIndex from the file
ind1 = compIndex;
}
BufferedWriter compWriter = new BufferedWriter(new FileWriter(fName3));
//Create an output file for that sermon: e.g. "1-index.txt"
//write the DocumentIndex to the output file
compWriter.write(compIndex.toString());
compWriter.flush();
compWriter.close();
}
catch (IOException e){
System.out.println("Error in IndexMaker: " + e.getMessage());
}
}
}
else if (whatWant == 4){
//merging indices
boolean done = false;
ArrayList<String> filesToMerge = new ArrayList<String>();
boolean moreFiles = true;
notDone4: while (!done){
filesToGo: while (moreFiles){
System.out.print("Enter name of next file to merge (remember extension) or DONE: ");
String fName2 = input.next();
if (fName2.equalsIgnoreCase("exit")){
done = true;
break notDone4;
}
if (fName2.equalsIgnoreCase("done")){
moreFiles = false;
break filesToGo;
}
filesToMerge.add(fName2);
}
System.out.print("Enter name of destination (remember extension): ");
String fName3 = input.next();
if (fName3.equalsIgnoreCase("exit")){
done = true;
break notDone4;
}
if (filesToMerge.size() < 2){
System.out.println("Not enough files!");
done = true;
break notDone4;
}
try {
String file1 = filesToMerge.remove(0);
ScriptureIndex ind1 = new ScriptureIndex(new FileReader(file1));
ScriptureIndex compIndex = new ScriptureIndex();
while (filesToMerge.size() != 0){
//Open the given files
ScriptureIndex ind2 = new ScriptureIndex(new FileReader(filesToMerge.remove(0)));
compIndex = new ScriptureIndex(ind1, ind2);
//create a new DocumentIndex from the file
ind1 = compIndex;
}
BufferedWriter compWriter = new BufferedWriter(new FileWriter(fName3));
//Create an output file for that sermon: e.g. "1-index.txt"
//write the DocumentIndex to the output file
compWriter.write(compIndex.toString());
compWriter.flush();
compWriter.close();
}
catch (IOException e){
System.out.println("Error in IndexMaker: " + e.getMessage());
}
}
}
else if (whatWant == 5){
boolean done = false;
notDone5: while (!done){
/* System.out.print("Enter number/title of sermon or EXIT to exit: ");
String serm = input.next();
if (serm.equalsIgnoreCase("exit")){
done = true;
break notDone5;
}*/ //probably not necessary for this
System.out.print("Enter name of file (remember extension): ");
String fName = input.next();
if (fName.equalsIgnoreCase("exit")){
done = true;
break notDone5;
}
try {
//Open the given file
//create an index by scanning for the scriptural references
ScriptureList scriptList = new ScriptureList(fName);
//create a new ScriptureList from the file
int extInd = fName.indexOf(".txt");
if (extInd != -1){
fName = fName.substring(0, extInd);
}
BufferedWriter listWriter = new BufferedWriter(new FileWriter(fName + "-scripture-list.txt"));
//Create an output file for that file: e.g. "1-scripture-list.txt"
//write the list to the output file
//note: thie will still need to be reviewed by hand!
listWriter.write(scriptList.toString());
listWriter.flush();
listWriter.close();
System.out.println("List made; see " + fName + "-scripture-list.txt");
}
catch (IOException e){
System.out.println("Error in IndexMaker: " + e.getMessage());
}
}
}
else {
System.out.println("Goodbye.");
}
}
}