Repository navigation
Expand file tree
/
Copy pathTestingFile.java
More file actions
186 lines (117 loc) · 6.22 KB
/
Copy pathTestingFile.java
File metadata and controls
186 lines (117 loc) · 6.22 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
//eee
import java.util.Scanner;
import java.io.*;
import java.io.IOException;
public class TestingFile {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Choose an action from the menu:");
System.out.println("1. Load a knowledge base from a file");
System.out.println("2. Add a new statement to the knowledge base");
System.out.println("3. Search for a statement in the knowledge base by term");
System.out.println("4. Search for a statement in the knowledge base by term and sentence");
System.out.println("5. Quit");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
String st; //imortant variables
String[] arrayAll;
int count = 0;
arrayAll = new String[150000];
while (choice != 5) {
//System.out.println("hi");
if (choice == 1) {
Scanner scanner4 = new Scanner(System.in);
System.out.print("Enter file name: "); //path works
String txtName = scanner4.nextLine();
File file = new File(txtName);
String path = new File(FilePathExample.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath();
System.out.println("Current Java file location: " + path);
try(Scanner fScanner = new Scanner(file)) {
//BufferedReader bfri = new BufferedReader(
//new InputStreamReader(System.in));
//String path = bfri.readLine();
//BufferedReader bfro = new BufferedReader(
//new FileReader(path));
while (fScanner.hasNextLine()) {
//System.out.println("st: "+st);
st = fScanner.nextLine();
//separate line into the 3 parts using tab:
String[] array = st.split("\t");
//add them to a SINGLE array (instructions say use a single array)
for (int i = 0; i < 3; i++) {
//System.out.println("i: "+i);
arrayAll[count] = array[i];
//System.out.println(array[i] +"$$");
//System.out.println("ARRAYALL "+arrayAll[count]);
count++;
}
System.out.println();
//count++;
}
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println("WHAT");
//System.out.print(loadedText[0]+"*******");
System.out.println();
System.out.print("Knowledge base loaded successfully.");
choice = 0;
} else if (choice == 2) {
Scanner newS = new Scanner(System.in);
//System.out.println();
System.out.println("Enter the term: ");
String term = newS.nextLine();
System.out.print("Enter the statement: ");
String newStatement = newS.nextLine();
System.out.print("Enter the confidence score: ");
double confidenceScore = newS.nextDouble();
//pea crab Pea crabs are very small in size. 0.738231360912323
//Update sentance
int pos = 0;
for (int i = 0; i < arrayAll.length; i++) {
if (arrayAll[i].equals(term)) {
arrayAll[i + 1] = newStatement;
arrayAll[i + 2] = String.valueOf(confidenceScore);
pos = i;
}
}
System.out.println(arrayAll[pos + 1]);
//Statement for term maple syrup has been updated.
System.out.print("Statement for term " + term + " has been updated.");
choice = 0;
//System.out.println("he");
//3. Search for a statement in the knowledge base by term
} else if (choice == 3) {
Scanner sc3 = new Scanner(System.in);
System.out.println("Enter the term to search: ");
String searchTerm = sc3.nextLine();
/*for (String str : array) {
if (str.contains(wordToFind)) {
System.out.println("Found: " + str);
}
}*/
for (int i = 0; i < arrayAll.length; i = i + 3) {
if (arrayAll[i].contains(searchTerm)) {
System.out.println("Statement found: " + arrayAll[i + 1] +
" (Confidence score: " + arrayAll[i + 2] + ")");
//arrayAll[i+1] = newStatement;
//arrayAll[i+2] = String.valueOf(confidenceScore);
//pos = i;
}
}
choice = 0;
//4. Search for a statement in the knowledge base by term and sentence
} else if (choice == 4) {
System.out.println("Enter the term to search: ");
}
System.out.println("Choose an action from the menu:");
System.out.println("1. Load a knowledge base from a file");
System.out.println("2. Add a new statement to the knowledge base");
System.out.println("3. Search for a statement in the knowledge base by term");
System.out.println("4. Search for a statement in the knowledge base by term and sentence");
System.out.println("5. Quit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
}
}
}