-
Notifications
You must be signed in to change notification settings - Fork 1
/
PythonOntologyCreator.java
117 lines (76 loc) · 2.68 KB
/
PythonOntologyCreator.java
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
package org.vikamine.kernel._examples;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.vikamine.kernel.data.Attribute;
import org.vikamine.kernel.data.AttributeBuilder;
import org.vikamine.kernel.data.DataRecordSet;
import org.vikamine.kernel.data.FullDataRecord;
import org.vikamine.kernel.data.NominalAttribute;
import org.vikamine.kernel.data.Ontology;
import org.vikamine.kernel.data.creators.DataFactory;
public class PythonOntologyCreator {
public Ontology ontology;
private static List<String> unique(String arr[]) {
HashSet<String> set = new HashSet<>();
for (int i=0; i<arr.length; i++)
{
if (!set.contains(arr[i]))
{
set.add(arr[i]);
}
}
List<String> mainList = new ArrayList<String>();
mainList.addAll(set);
return mainList;
}
public PythonOntologyCreator(String[] columnNames, String[] columnTypes, double[][] numericArrays, String[][] nominalArrays) throws Exception {
List<Attribute> attributes = new ArrayList<Attribute>();
AttributeBuilder basicBuilder = new AttributeBuilder();
int colI = 0;
int nomI = 0;
int numI = 0;
for (String colType : columnTypes) {
if (colType.equals("numeric")) {
basicBuilder.buildNumericAttribute(columnNames[colI]);
attributes.add(basicBuilder.getAttribute());
}
if (colType.equals("nominal")) {
basicBuilder.buildNominalAttribute(columnNames[colI], unique(nominalArrays[nomI]));
basicBuilder.buildNominalValues();
attributes.add(basicBuilder.getAttribute());
nomI++;
}
colI++;
}
int numberRecords = 0;
if (numericArrays.length != 0) {
numberRecords = numericArrays[0].length;
}
else {
numberRecords = nominalArrays[0].length;
}
DataRecordSet dataset = new DataRecordSet("dataset", attributes, numberRecords);
for (int rowI = 0; rowI < numberRecords; rowI++) {
colI = 0;
nomI = 0;
numI = 0;
double[] record = new double[columnNames.length];
for (colI = 0; colI < columnNames.length; colI++) {
if(columnTypes[colI].equals("numeric")) {
record[colI] = Double.valueOf(numericArrays[numI][rowI]).doubleValue();
numI++;
}
if(columnTypes[colI].equals("nominal")) {
record[colI] = ((NominalAttribute) dataset
.getAttribute(columnNames[colI]))
.getIndexOfValue(nominalArrays[nomI][rowI]);
nomI++;
}
}
dataset.add(new FullDataRecord(1, record));
}
dataset.compactify();
ontology = DataFactory.createOntology(dataset);
}
}