10
10
11
11
import java .io .File ;
12
12
import java .io .FileNotFoundException ;
13
- import java .io .IOException ;
14
13
import java .nio .file .Path ;
15
14
import java .util .Scanner ;
16
15
import java .util .concurrent .ExecutionException ;
@@ -30,7 +29,8 @@ public class Menu {
30
29
private Path dataPath ;
31
30
private Query query ;
32
31
33
- private static final String DEFAULT_DATA_PATH = "datasets/wili-2018-Large-117500-Edited.txt" ;
32
+ private static final String LARGE_DATASET = "datasets/wili-2018-Large-117500-Edited.txt" ;
33
+ private static final String SMALL_DATASET = "datasets/wili-2018-Small-11750-Edited.txt" ;
34
34
35
35
public Path getDataPath () {
36
36
return dataPath ;
@@ -65,38 +65,14 @@ public void display() {
65
65
System .out .println ("=============================================================================" );
66
66
67
67
try (var console = new Scanner (System .in )) {
68
- String input ;
69
-
70
68
while (true ) {
71
69
try {
72
70
if (dataPath == null ) {
73
- System .out .print ("$ Enter WiLi data location (or press enter to use the default): " );
74
- input = console .nextLine ().trim ();
75
-
76
- if (input .isEmpty ()) {
77
- input = DEFAULT_DATA_PATH ;
78
- }
79
-
80
- if (isFile (input )) {
81
- this .dataPath = Path .of (input );
82
- } else {
83
- throw new FileNotFoundException ("The dataset file could not be found" );
84
- }
71
+ getDatasetInput (console );
85
72
}
86
73
87
74
if (query == null ) {
88
- System .out .print ("$ Enter the query text/file: " );
89
- input = console .nextLine ().trim ();
90
-
91
- if (input .isEmpty ()) {
92
- continue ;
93
- }
94
-
95
- if (isFile (input )) {
96
- this .query = new QueryFile (Path .of (input ));
97
- } else {
98
- this .query = new QueryString (input );
99
- }
75
+ getQueryInput (console );
100
76
}
101
77
102
78
break ;
@@ -105,8 +81,53 @@ public void display() {
105
81
}
106
82
}
107
83
}
84
+ }
85
+
86
+ private void getDatasetInput (Scanner console ) throws FileNotFoundException {
87
+ while (true ) {
88
+ System .out .print ("$ Choose WiLi dataset ('L' for Large, 'S' for Small): " );
89
+ String input = console .nextLine ().toUpperCase ().trim ();
90
+
91
+ if (input .equals ("L" )) {
92
+ input = LARGE_DATASET ;
93
+ } else if (input .equals ("S" )) {
94
+ input = SMALL_DATASET ;
95
+ } else {
96
+ continue ;
97
+ }
98
+
99
+ if (isFile (input )) {
100
+ this .dataPath = Path .of (input );
101
+ break ;
102
+ } else {
103
+ throw new FileNotFoundException ("The dataset file could not be found" );
104
+ }
105
+ }
106
+ }
108
107
109
- detect ();
108
+ private void getQueryInput (Scanner console ) {
109
+ while (true ) {
110
+ System .out .print ("$ Enter the query text/file: " );
111
+ String input = console .nextLine ().trim ();
112
+
113
+ if (input .isEmpty ()) {
114
+ continue ;
115
+ }
116
+
117
+ if (input .equals ("-1" )) {
118
+ break ;
119
+ }
120
+
121
+ if (isFile (input )) {
122
+ this .query = new QueryFile (Path .of (input ));
123
+ System .out .println ("Query file entered." );
124
+ } else {
125
+ this .query = new QueryString (input );
126
+ System .out .println ("Query string entered." );
127
+ }
128
+
129
+ detect ();
130
+ }
110
131
}
111
132
112
133
private void detect () {
@@ -150,12 +171,12 @@ private void detect() {
150
171
151
172
try {
152
173
Language result = subParser .detect (qParser .getQueryMapping ());
153
- System .out .printf ("\n The text appears to be written in %s.\n " , result .toString ());
174
+ System .out .printf ("\n The text appears to be written in %s." , result .language ());
154
175
} catch (IllegalStateException e ) {
155
176
System .err .println ("\n [Error] Failed to detect the language: " + e .getMessage ());
156
177
}
157
178
158
- System .out .println ("\n Time: " + calcDuration (startTime ) + " (s)" );
179
+ System .out .println ("\n Time: " + calcDuration (startTime ) + " (s)\n " );
159
180
}
160
181
161
182
private static boolean isFile (String filename ) {
0 commit comments