blob: a4569df262924f3e57f1cd0fca9bb53c6a1b2c49 (
plain) (
blame)
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.yst.libmlr.converter.entity;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.yahoo.yst.libmlr.converter.parser.DecisionTreeXmlException;
public class TreenetFunction extends MlrFunction {
private String ns; // namespace
private ArrayList<Tree> treeArylst;
private HashSet<String> featureSet;
private HashSet<String> labelSet;
protected ArrayList<EarlyExit> earlyExitArylst;
public TreenetFunction() {
treeArylst = new ArrayList<Tree>(500);
featureSet = new HashSet<String>();
labelSet = new HashSet<String>();
earlyExitArylst = new ArrayList<EarlyExit>(5);
}
public void setFunctionName(String id) {
funcId = id;
functionName = "mlr" + id;
/*
Pattern p = Pattern.compile("[^\\d]+(\\d+)\\w*");
Matcher m = p.matcher(functionName);
if (!m.matches())
throw new IllegalArgumentException("not a valid functionName");
funcId = m.group(1);
*/
ns = "mlr" + funcId + "ns";
}
public String getNameSpace() {
return ns;
}
public int getNumberOfTrees() {
return treeArylst.size();
}
public Tree getTree(int i) {
return treeArylst.get(i);
}
public void setTree(Tree t) {
treeArylst.add(t);
}
public HashSet<String> getFeatureSet() {
return featureSet;
}
public HashSet<String> getLabelSet() {
return labelSet;
}
public void addFeature(String f) {
featureSet.add(f);
}
public void addLabel(String lbl) {
if (labelSet.contains(lbl))
throw new DecisionTreeXmlException("Label " + lbl + " existed.");
labelSet.add(lbl);
}
public void removeLabelSet() {
labelSet = null;
}
public void getAllFeatures() {
for (String f: featureSet) {
System.out.println(f);
}
}
public void addEarlyExit(EarlyExit earx) {
earlyExitArylst.add(earx);
}
public int getNumEarlyExits() {
return earlyExitArylst.size();
}
public EarlyExit getEarlyExit(int i) {
return earlyExitArylst.get(i);
}
}
|