-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
74 lines (59 loc) · 1.76 KB
/
Copy pathClient.java
File metadata and controls
74 lines (59 loc) · 1.76 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
package proj5;
import java.util.StringJoiner;
/**
* Driver for the index maker project
*
* Creates the index and dictionary for a given input file
*
* @author Nick DeBaise
* @version 11/14/22
*
* HC: I affirm I have carried out the Union College Honor Code
*/
public class Client
{
public static void main(String[] args)
{
makeIndex("GSTestInput.txt");
}
/**
* Makes an index out of fileName. Gradescope needs this function.
*
* @param fileName path to text file that you want to index
*/
public static void makeIndex(String fileName) {
FileReader reader = new FileReader(fileName);
LinkedList<String> words = reader.getWords();
Index index = new Index();
Dictionary dictionary = new Dictionary();
int currPageNum = 1;
int currIndex = 0;
while(words.getNode(currIndex) != null) {
ListNode word = words.getNode(currIndex++);
String w = (String) word.data;
if(w.equals("#")) {
currPageNum++;
continue;
}
if(w.length() <= 2) {
continue;
}
if(!dictionary.contains(w)) {
boolean wordWasAdded = index.handleWord(w, currPageNum);
if(!wordWasAdded) {
dictionary.addWord(w);
}
}
}
printIndex(index);
printDictionary(dictionary);
}
private static void printIndex(Index index) {
String s = index.toString().replaceAll(" ", "").trim();
System.out.println(s);
}
private static void printDictionary(Dictionary dict) {
String s = dict.toString().replaceAll(" ", "").trim();
System.out.println(s);
}
}