1 | /* |
---|
2 | * This program is free software; you can redistribute it and/or modify |
---|
3 | * it under the terms of the GNU General Public License as published by |
---|
4 | * the Free Software Foundation; either version 2 of the License, or |
---|
5 | * (at your option) any later version. |
---|
6 | * |
---|
7 | * This program is distributed in the hope that it will be useful, |
---|
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | * GNU General Public License for more details. |
---|
11 | * |
---|
12 | * You should have received a copy of the GNU General Public License |
---|
13 | * along with this program; if not, write to the Free Software |
---|
14 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
15 | */ |
---|
16 | |
---|
17 | /* |
---|
18 | * ExplorerDefaults.java |
---|
19 | * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand |
---|
20 | */ |
---|
21 | |
---|
22 | package weka.gui.explorer; |
---|
23 | |
---|
24 | import weka.core.Utils; |
---|
25 | |
---|
26 | import java.io.Serializable; |
---|
27 | import java.util.Collections; |
---|
28 | import java.util.Enumeration; |
---|
29 | import java.util.Properties; |
---|
30 | import java.util.Vector; |
---|
31 | |
---|
32 | /** |
---|
33 | * This class offers get methods for the default Explorer settings in |
---|
34 | * the props file <code>weka/gui/explorer/Explorer.props</code>. |
---|
35 | * |
---|
36 | * @author FracPete (fracpete at waikato dot ac dot nz) |
---|
37 | * @version $Revision: 6103 $ |
---|
38 | * @see #PROPERTY_FILE |
---|
39 | */ |
---|
40 | public class ExplorerDefaults |
---|
41 | implements Serializable { |
---|
42 | |
---|
43 | /** for serialization. */ |
---|
44 | private static final long serialVersionUID = 4954795757927524225L; |
---|
45 | |
---|
46 | /** The name of the properties file. */ |
---|
47 | public final static String PROPERTY_FILE = "weka/gui/explorer/Explorer.props"; |
---|
48 | |
---|
49 | /** Properties associated with the explorer options. */ |
---|
50 | protected static Properties PROPERTIES; |
---|
51 | static { |
---|
52 | try { |
---|
53 | PROPERTIES = Utils.readProperties(PROPERTY_FILE); |
---|
54 | } |
---|
55 | catch (Exception e) { |
---|
56 | System.err.println("Problem reading properties. Fix before continuing."); |
---|
57 | e.printStackTrace(); |
---|
58 | PROPERTIES = new Properties(); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * returns the value for the specified property, if non-existent then the |
---|
64 | * default value. |
---|
65 | * |
---|
66 | * @param property the property to retrieve the value for |
---|
67 | * @param defaultValue the default value for the property |
---|
68 | * @return the value of the specified property |
---|
69 | */ |
---|
70 | public static String get(String property, String defaultValue) { |
---|
71 | return PROPERTIES.getProperty(property, defaultValue); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * returns the associated properties file. |
---|
76 | * |
---|
77 | * @return the props file |
---|
78 | */ |
---|
79 | public final static Properties getProperties() { |
---|
80 | return PROPERTIES; |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * Tries to instantiate the class stored for this property, optional |
---|
85 | * options will be set as well. Returns null if unsuccessful. |
---|
86 | * |
---|
87 | * @param property the property to get the object for |
---|
88 | * @param defaultValue the default object spec string |
---|
89 | * @return if successful the fully configured object, null |
---|
90 | * otherwise |
---|
91 | */ |
---|
92 | protected static Object getObject(String property, String defaultValue) { |
---|
93 | return getObject(property, defaultValue, Object.class); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Tries to instantiate the class stored for this property, optional |
---|
98 | * options will be set as well. Returns null if unsuccessful. |
---|
99 | * |
---|
100 | * @param property the property to get the object for |
---|
101 | * @param defaultValue the default object spec string |
---|
102 | * @param cls the class the object must be derived from |
---|
103 | * @return if successful the fully configured object, null |
---|
104 | * otherwise |
---|
105 | */ |
---|
106 | protected static Object getObject(String property, String defaultValue, Class cls) { |
---|
107 | Object result; |
---|
108 | String tmpStr; |
---|
109 | String[] tmpOptions; |
---|
110 | |
---|
111 | result = null; |
---|
112 | |
---|
113 | try { |
---|
114 | tmpStr = get(property, defaultValue); |
---|
115 | tmpOptions = Utils.splitOptions(tmpStr); |
---|
116 | if (tmpOptions.length != 0) { |
---|
117 | tmpStr = tmpOptions[0]; |
---|
118 | tmpOptions[0] = ""; |
---|
119 | result = Utils.forName(cls, tmpStr, tmpOptions); |
---|
120 | } |
---|
121 | } |
---|
122 | catch (Exception e) { |
---|
123 | e.printStackTrace(); |
---|
124 | result = null; |
---|
125 | } |
---|
126 | |
---|
127 | return result; |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * returns if the GOEs in the Explorer will be initialized based on the |
---|
132 | * data that is loaded into the Explorer. |
---|
133 | * |
---|
134 | * @return true if the GOEs get initialized |
---|
135 | */ |
---|
136 | public static boolean getInitGenericObjectEditorFilter() { |
---|
137 | return Boolean.parseBoolean(get("InitGenericObjectEditorFilter", "false")); |
---|
138 | } |
---|
139 | |
---|
140 | /** |
---|
141 | * returns an array with the classnames of all the additional panels to |
---|
142 | * display as tabs in the Explorer. |
---|
143 | * |
---|
144 | * @return the classnames |
---|
145 | */ |
---|
146 | public static String[] getTabs() { |
---|
147 | String[] result; |
---|
148 | String tabs; |
---|
149 | |
---|
150 | // read and split on comma |
---|
151 | tabs = get("Tabs", "weka.gui.explorer.ClassifierPanel,weka.gui.explorer.ClustererPanel,weka.gui.explorer.AssociationsPanel,weka.gui.explorer.AttributeSelectionPanel,weka.gui.explorer.VisualizePanel"); |
---|
152 | result = tabs.split(","); |
---|
153 | |
---|
154 | return result; |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * Returns the initial directory for the file chooser used for opening |
---|
159 | * datasets. |
---|
160 | * <p/> |
---|
161 | * The following placeholders are recognized: |
---|
162 | * <pre> |
---|
163 | * %t - the temp directory |
---|
164 | * %h - the user's home directory |
---|
165 | * %c - the current directory |
---|
166 | * %% - gets replaced by a single percentage sign |
---|
167 | * </pre> |
---|
168 | * |
---|
169 | * @return the default directory |
---|
170 | */ |
---|
171 | public static String getInitialDirectory() { |
---|
172 | String result; |
---|
173 | |
---|
174 | result = get("InitialDirectory", "%c"); |
---|
175 | result = result.replaceAll("%t", System.getProperty("java.io.tmpdir")); |
---|
176 | result = result.replaceAll("%h", System.getProperty("user.home")); |
---|
177 | result = result.replaceAll("%c", System.getProperty("user.dir")); |
---|
178 | result = result.replaceAll("%%", System.getProperty("%")); |
---|
179 | |
---|
180 | return result; |
---|
181 | } |
---|
182 | |
---|
183 | /** |
---|
184 | * returns the default filter (fully configured) for the preprocess panel. |
---|
185 | * |
---|
186 | * @return the default filter, null if none |
---|
187 | */ |
---|
188 | public static Object getFilter() { |
---|
189 | return getObject("Filter", "", weka.filters.Filter.class); |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * returns the default classifier (fully configured) for the classify panel. |
---|
194 | * |
---|
195 | * @return the default classifier, ZeroR by default |
---|
196 | */ |
---|
197 | public static Object getClassifier() { |
---|
198 | Object result; |
---|
199 | |
---|
200 | result = getObject( |
---|
201 | "Classifier", |
---|
202 | weka.classifiers.rules.ZeroR.class.getName(), |
---|
203 | weka.classifiers.Classifier.class); |
---|
204 | if (result == null) |
---|
205 | result = new weka.classifiers.rules.ZeroR(); |
---|
206 | |
---|
207 | return result; |
---|
208 | } |
---|
209 | |
---|
210 | /** |
---|
211 | * returns the default classifier test mode for the classify panel. |
---|
212 | * |
---|
213 | * @return the default test mode |
---|
214 | */ |
---|
215 | public static int getClassifierTestMode() { |
---|
216 | return Integer.parseInt(get("ClassifierTestMode", "1")); |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * returns the default number of folds of the CV in the classify panel. |
---|
221 | * |
---|
222 | * @return the default number of folds |
---|
223 | */ |
---|
224 | public static int getClassifierCrossvalidationFolds() { |
---|
225 | return Integer.parseInt(get("ClassifierCrossvalidationFolds", "10")); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | * returns the default classifier test mode for the classify panel (0-99). |
---|
230 | * |
---|
231 | * @return the default precentage split |
---|
232 | */ |
---|
233 | public static int getClassifierPercentageSplit() { |
---|
234 | return Integer.parseInt(get("ClassifierPercentageSplit", "66")); |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * returns whether the built model is output. |
---|
239 | * |
---|
240 | * @return true if the built model is output |
---|
241 | */ |
---|
242 | public static boolean getClassifierOutputModel() { |
---|
243 | return Boolean.parseBoolean(get("ClassifierOutputModel", "true")); |
---|
244 | } |
---|
245 | |
---|
246 | /** |
---|
247 | * returns whether additional per-class stats of the classifier are output. |
---|
248 | * |
---|
249 | * @return true if stats are output |
---|
250 | */ |
---|
251 | public static boolean getClassifierOutputPerClassStats() { |
---|
252 | return Boolean.parseBoolean(get("ClassifierOutputPerClassStats", "true")); |
---|
253 | } |
---|
254 | |
---|
255 | /** |
---|
256 | * returns whether entropy-based evaluation meastures of the classifier |
---|
257 | * are output. |
---|
258 | * |
---|
259 | * @return true if output |
---|
260 | */ |
---|
261 | public static boolean getClassifierOutputEntropyEvalMeasures() { |
---|
262 | return Boolean.parseBoolean(get("ClassifierOutputEntropyEvalMeasures", "false")); |
---|
263 | } |
---|
264 | |
---|
265 | /** |
---|
266 | * returns whether the confusion matrix for the classifier is output. |
---|
267 | * |
---|
268 | * @return true if matrix is output |
---|
269 | */ |
---|
270 | public static boolean getClassifierOutputConfusionMatrix() { |
---|
271 | return Boolean.parseBoolean(get("ClassifierOutputConfusionMatrix", "true")); |
---|
272 | } |
---|
273 | |
---|
274 | /** |
---|
275 | * returns whether the predictions of the classifier are output as well. |
---|
276 | * |
---|
277 | * @return true if predictions are output as well |
---|
278 | */ |
---|
279 | public static boolean getClassifierOutputPredictions() { |
---|
280 | return Boolean.parseBoolean(get("ClassifierOutputPredictions", "false")); |
---|
281 | } |
---|
282 | |
---|
283 | /** |
---|
284 | * returns the string with the additional indices to output alongside the |
---|
285 | * predictions. |
---|
286 | * |
---|
287 | * @return the indices, 0 if none are output |
---|
288 | */ |
---|
289 | public static String getClassifierOutputAdditionalAttributes() { |
---|
290 | return get("ClassifierOutputAdditionalAttributes", ""); |
---|
291 | } |
---|
292 | |
---|
293 | /** |
---|
294 | * returns whether the predictions of the classifier are stored for |
---|
295 | * visualization. |
---|
296 | * |
---|
297 | * @return true if predictions are stored |
---|
298 | */ |
---|
299 | public static boolean getClassifierStorePredictionsForVis() { |
---|
300 | return Boolean.parseBoolean(get("ClassifierStorePredictionsForVis", "true")); |
---|
301 | } |
---|
302 | |
---|
303 | /** |
---|
304 | * returns whether the evaluation of the classifier is done cost-sensitively. |
---|
305 | * |
---|
306 | * @return true if cost-sensitively done |
---|
307 | */ |
---|
308 | public static boolean getClassifierCostSensitiveEval() { |
---|
309 | return Boolean.parseBoolean(get("ClassifierCostSensitiveEval", "false")); |
---|
310 | } |
---|
311 | |
---|
312 | /** |
---|
313 | * returns the default random seed value for the classifier for the |
---|
314 | * classify panel. |
---|
315 | * |
---|
316 | * @return the default random seed |
---|
317 | */ |
---|
318 | public static int getClassifierRandomSeed() { |
---|
319 | return Integer.parseInt(get("ClassifierRandomSeed", "1")); |
---|
320 | } |
---|
321 | |
---|
322 | /** |
---|
323 | * returns whether the order is preserved in case of the percentage split |
---|
324 | * in the classify tab. |
---|
325 | * |
---|
326 | * @return true if order is preserved |
---|
327 | */ |
---|
328 | public static boolean getClassifierPreserveOrder() { |
---|
329 | return Boolean.parseBoolean(get("ClassifierPreserveOrder", "false")); |
---|
330 | } |
---|
331 | |
---|
332 | /** |
---|
333 | * returns whether the source of a sourcable Classifier is output |
---|
334 | * in the classify tab. |
---|
335 | * |
---|
336 | * @return true if the source code is output |
---|
337 | */ |
---|
338 | public static boolean getClassifierOutputSourceCode() { |
---|
339 | return Boolean.parseBoolean(get("ClassifierOutputSourceCode", "false")); |
---|
340 | } |
---|
341 | |
---|
342 | /** |
---|
343 | * returns the default classname for a sourcable Classifier in the classify tab. |
---|
344 | * |
---|
345 | * @return the default classname |
---|
346 | */ |
---|
347 | public static String getClassifierSourceCodeClass() { |
---|
348 | return get("ClassifierSourceCodeClass", "Foobar"); |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | * Returns an instance of the class used for generating plot instances |
---|
353 | * for displaying the classifier errors. |
---|
354 | * |
---|
355 | * @return an instance of the class |
---|
356 | */ |
---|
357 | public static ClassifierErrorsPlotInstances getClassifierErrorsPlotInstances() { |
---|
358 | ClassifierErrorsPlotInstances result; |
---|
359 | String classname; |
---|
360 | String[] options; |
---|
361 | |
---|
362 | try { |
---|
363 | options = Utils.splitOptions(get("ClassifierErrorsPlotInstances", "weka.gui.explorer.ClassifierErrorsPlotInstances")); |
---|
364 | classname = options[0]; |
---|
365 | options[0] = ""; |
---|
366 | result = (ClassifierErrorsPlotInstances) Utils.forName(ClassifierErrorsPlotInstances.class, classname, options); |
---|
367 | } |
---|
368 | catch (Exception e) { |
---|
369 | e.printStackTrace(); |
---|
370 | result = new ClassifierErrorsPlotInstances(); |
---|
371 | } |
---|
372 | |
---|
373 | return result; |
---|
374 | } |
---|
375 | |
---|
376 | /** |
---|
377 | * Returns the minimum size in pixels for plots of plotting classifier errors |
---|
378 | * of numeric attributes. |
---|
379 | * |
---|
380 | * @return the size |
---|
381 | */ |
---|
382 | public static int getClassifierErrorsMinimumPlotSizeNumeric() { |
---|
383 | return Integer.parseInt(get("ClassifierErrorsMinimumPlotSizeNumeric", "1")); |
---|
384 | } |
---|
385 | |
---|
386 | /** |
---|
387 | * Returns the maximum size in pixels for plots of plotting classifier errors |
---|
388 | * of numeric attributes. |
---|
389 | * |
---|
390 | * @return the size |
---|
391 | */ |
---|
392 | public static int getClassifierErrorsMaximumPlotSizeNumeric() { |
---|
393 | return Integer.parseInt(get("ClassifierErrorsMaximumPlotSizeNumeric", "20")); |
---|
394 | } |
---|
395 | |
---|
396 | /** |
---|
397 | * returns the default clusterer (fully configured) for the clusterer panel. |
---|
398 | * |
---|
399 | * @return the default clusterer, EM by default |
---|
400 | */ |
---|
401 | public static Object getClusterer() { |
---|
402 | Object result; |
---|
403 | |
---|
404 | result = getObject( |
---|
405 | "Clusterer", |
---|
406 | weka.clusterers.EM.class.getName(), |
---|
407 | weka.clusterers.Clusterer.class); |
---|
408 | if (result == null) |
---|
409 | result = new weka.clusterers.EM(); |
---|
410 | |
---|
411 | return result; |
---|
412 | } |
---|
413 | |
---|
414 | /** |
---|
415 | * returns the default cluster test mode for the cluster panel. |
---|
416 | * |
---|
417 | * @return the default test mode |
---|
418 | */ |
---|
419 | public static int getClustererTestMode() { |
---|
420 | return Integer.parseInt(get("ClustererTestMode", "3")); |
---|
421 | } |
---|
422 | |
---|
423 | /** |
---|
424 | * returns whether the clusters are storeed for visualization purposes |
---|
425 | * in the cluster panel. |
---|
426 | * |
---|
427 | * @return true if clusters are stored |
---|
428 | */ |
---|
429 | public static boolean getClustererStoreClustersForVis() { |
---|
430 | return Boolean.parseBoolean(get("ClustererStoreClustersForVis", "true")); |
---|
431 | } |
---|
432 | |
---|
433 | /** |
---|
434 | * Returns an instance of the class used for generating plot instances |
---|
435 | * for displaying the cluster assignments. |
---|
436 | * |
---|
437 | * @return an instance of the class |
---|
438 | */ |
---|
439 | public static ClustererAssignmentsPlotInstances getClustererAssignmentsPlotInstances() { |
---|
440 | ClustererAssignmentsPlotInstances result; |
---|
441 | String classname; |
---|
442 | String[] options; |
---|
443 | |
---|
444 | try { |
---|
445 | options = Utils.splitOptions(get("ClustererAssignmentsPlotInstances", "weka.gui.explorer.ClustererAssignmentsPlotInstances")); |
---|
446 | classname = options[0]; |
---|
447 | options[0] = ""; |
---|
448 | result = (ClustererAssignmentsPlotInstances) Utils.forName(ClustererAssignmentsPlotInstances.class, classname, options); |
---|
449 | } |
---|
450 | catch (Exception e) { |
---|
451 | e.printStackTrace(); |
---|
452 | result = new ClustererAssignmentsPlotInstances(); |
---|
453 | } |
---|
454 | |
---|
455 | return result; |
---|
456 | } |
---|
457 | |
---|
458 | /** |
---|
459 | * returns the default associator (fully configured) for the associations panel. |
---|
460 | * |
---|
461 | * @return the default associator, Apriori by default |
---|
462 | */ |
---|
463 | public static Object getAssociator() { |
---|
464 | Object result; |
---|
465 | |
---|
466 | result = getObject( |
---|
467 | "Associator", |
---|
468 | weka.associations.Apriori.class.getName(), |
---|
469 | weka.associations.Associator.class); |
---|
470 | if (result == null) |
---|
471 | result = new weka.associations.Apriori(); |
---|
472 | |
---|
473 | return result; |
---|
474 | } |
---|
475 | |
---|
476 | /** |
---|
477 | * returns the default attribute evalautor (fully configured) for the |
---|
478 | * attribute selection panel. |
---|
479 | * |
---|
480 | * @return the default attribute evaluator, CfsSubsetEval by default |
---|
481 | */ |
---|
482 | public static Object getASEvaluator() { |
---|
483 | Object result; |
---|
484 | |
---|
485 | result = getObject( |
---|
486 | "ASEvaluation", |
---|
487 | weka.attributeSelection.CfsSubsetEval.class.getName(), |
---|
488 | weka.attributeSelection.ASEvaluation.class); |
---|
489 | if (result == null) |
---|
490 | result = new weka.attributeSelection.CfsSubsetEval(); |
---|
491 | |
---|
492 | return result; |
---|
493 | } |
---|
494 | |
---|
495 | /** |
---|
496 | * returns the default attribute selection search scheme (fully configured) |
---|
497 | * for the attribute selection panel. |
---|
498 | * |
---|
499 | * @return the default search scheme, BestFirst by default |
---|
500 | */ |
---|
501 | public static Object getASSearch() { |
---|
502 | Object result; |
---|
503 | |
---|
504 | result = getObject( |
---|
505 | "ASSearch", |
---|
506 | weka.attributeSelection.BestFirst.class.getName(), |
---|
507 | weka.attributeSelection.ASSearch.class); |
---|
508 | if (result == null) |
---|
509 | result = new weka.attributeSelection.BestFirst(); |
---|
510 | |
---|
511 | return result; |
---|
512 | } |
---|
513 | |
---|
514 | /** |
---|
515 | * returns the default attribute selection test mode for the attribute |
---|
516 | * selection panel. |
---|
517 | * |
---|
518 | * @return the default test mode |
---|
519 | */ |
---|
520 | public static int getASTestMode() { |
---|
521 | return Integer.parseInt(get("ASTestMode", "0")); |
---|
522 | } |
---|
523 | |
---|
524 | /** |
---|
525 | * returns the default number of folds of the CV in the attribute selection |
---|
526 | * panel. |
---|
527 | * |
---|
528 | * @return the default number of folds |
---|
529 | */ |
---|
530 | public static int getASCrossvalidationFolds() { |
---|
531 | return Integer.parseInt(get("ASCrossvalidationFolds", "10")); |
---|
532 | } |
---|
533 | |
---|
534 | /** |
---|
535 | * returns the default random seed value in the attribute selection panel. |
---|
536 | * |
---|
537 | * @return the default random seed |
---|
538 | */ |
---|
539 | public static int getASRandomSeed() { |
---|
540 | return Integer.parseInt(get("ASRandomSeed", "1")); |
---|
541 | } |
---|
542 | |
---|
543 | /** |
---|
544 | * only for testing - prints the content of the props file. |
---|
545 | * |
---|
546 | * @param args commandline parameters - ignored |
---|
547 | */ |
---|
548 | public static void main(String[] args) { |
---|
549 | Enumeration names; |
---|
550 | String name; |
---|
551 | Vector sorted; |
---|
552 | |
---|
553 | System.out.println("\nExplorer defaults:"); |
---|
554 | names = PROPERTIES.propertyNames(); |
---|
555 | |
---|
556 | // sort names |
---|
557 | sorted = new Vector(); |
---|
558 | while (names.hasMoreElements()) |
---|
559 | sorted.add(names.nextElement()); |
---|
560 | Collections.sort(sorted); |
---|
561 | names = sorted.elements(); |
---|
562 | |
---|
563 | // output |
---|
564 | while (names.hasMoreElements()) { |
---|
565 | name = names.nextElement().toString(); |
---|
566 | System.out.println("- " + name + ": " + PROPERTIES.getProperty(name, "")); |
---|
567 | } |
---|
568 | System.out.println(); |
---|
569 | } |
---|
570 | } |
---|