|
a |
|
b/src/utils/RetreiveClassifiersFromWeka.java |
|
|
1 |
/* |
|
|
2 |
* Get all classifiers from weka libs |
|
|
3 |
*/ |
|
|
4 |
package utils; |
|
|
5 |
|
|
|
6 |
import java.io.File; |
|
|
7 |
import java.io.IOException; |
|
|
8 |
import java.util.ArrayList; |
|
|
9 |
import java.util.Collections; |
|
|
10 |
import java.util.Enumeration; |
|
|
11 |
import java.util.jar.JarEntry; |
|
|
12 |
import java.util.jar.JarFile; |
|
|
13 |
import weka.classifiers.*; |
|
|
14 |
import weka.core.Utils; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* |
|
|
18 |
* @author Administrator |
|
|
19 |
*/ |
|
|
20 |
public class RetreiveClassifiersFromWeka { |
|
|
21 |
|
|
|
22 |
public static void main(String[] args) { |
|
|
23 |
ArrayList<String> al = new ArrayList<>(); |
|
|
24 |
//get all possible models from lib folder |
|
|
25 |
File lib = new File("lib/weka/"); |
|
|
26 |
for (File jar : lib.listFiles()) { |
|
|
27 |
if (jar.getName().endsWith("jar")) { |
|
|
28 |
try { |
|
|
29 |
JarFile jarFile = new JarFile(jar); |
|
|
30 |
Enumeration<JarEntry> entries = jarFile.entries(); |
|
|
31 |
while (entries.hasMoreElements()) { |
|
|
32 |
JarEntry entry = entries.nextElement(); |
|
|
33 |
String n = entry.getName(); |
|
|
34 |
if (n.startsWith("weka/classifiers/") |
|
|
35 |
&& !n.contains("$") |
|
|
36 |
&& n.endsWith("class") |
|
|
37 |
&& n.split("/").length == 4 |
|
|
38 |
&& (n.contains("/bayes/") |
|
|
39 |
|| n.contains("/functions/") |
|
|
40 |
|| n.contains("/rules/") |
|
|
41 |
|| n.contains("/trees/") |
|
|
42 |
|| n.contains("/lazy") |
|
|
43 |
|| n.contains("/misc"))) { |
|
|
44 |
//System.out.println(jar.getName() + "\t" + n); |
|
|
45 |
al.add(n); |
|
|
46 |
} |
|
|
47 |
} |
|
|
48 |
} catch (IOException e) { |
|
|
49 |
e.printStackTrace(); |
|
|
50 |
} |
|
|
51 |
} |
|
|
52 |
} |
|
|
53 |
Collections.sort(al); |
|
|
54 |
|
|
|
55 |
for (String classifier : al) { |
|
|
56 |
try { |
|
|
57 |
classifier = classifier.replace(".class", "").replace("/", ".").replace("weka/classifiers/", ""); |
|
|
58 |
weka.classifiers.AbstractClassifier ac = (AbstractClassifier) Utils.forName(Classifier.class, classifier, args); |
|
|
59 |
String options = ""; |
|
|
60 |
for (String option : ac.getOptions()) { |
|
|
61 |
options += " " + option; |
|
|
62 |
} |
|
|
63 |
String cap = ac.getCapabilities().getClassCapabilities().toString(); |
|
|
64 |
System.out.println( |
|
|
65 |
classifier.replaceAll("^weka.classifiers.", "").replaceFirst("\\.", "\t") + "\t" |
|
|
66 |
+ ac.getCapabilities().getAttributeCapabilities().toString() |
|
|
67 |
.replaceAll("(Capabilities: \\[|attributes)", "") |
|
|
68 |
.replace("Empty nominal ,", "") |
|
|
69 |
.replace(" ,", ",").replace(" ", " ").replaceAll("\\].*", "").split("\n")[0] + "\t" |
|
|
70 |
+ ac.getCapabilities().getClassCapabilities().toString() |
|
|
71 |
.replaceAll("(Capabilities: \\[|class)", "") |
|
|
72 |
.replace("Missing values", "") |
|
|
73 |
.replace(" ,", ",").replace(" ", " ").replaceAll("\\].*", "").split("\n")[0].replaceAll(", $", " ")); |
|
|
74 |
//+ac.getCapabilities().getClassCapabilities().toString()); |
|
|
75 |
// if (cap.contains("Nominal class") && cap.contains("Numeric class")) { |
|
|
76 |
// System.out.println(classifier.replaceAll("^weka.classifiers.", "ccmd=") + options); |
|
|
77 |
// System.out.println(classifier.replaceAll("^weka.classifiers.", "rcmd=") + options); |
|
|
78 |
// } else if (cap.contains("Nominal class")) { |
|
|
79 |
// System.out.println(classifier.replaceAll("^weka.classifiers.", "ccmd=") + options); |
|
|
80 |
// } else { |
|
|
81 |
// System.out.println(classifier.replaceAll("^weka.classifiers.", "rcmd=") + options); |
|
|
82 |
// } |
|
|
83 |
// |
|
|
84 |
// ac.listOptions(); |
|
|
85 |
|
|
|
86 |
} catch (Exception e) { |
|
|
87 |
//e.printStackTrace(); |
|
|
88 |
} |
|
|
89 |
|
|
|
90 |
} |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
} |