MCPcopy Create free account
hub / github.com/ddf-project/DDF / deserializeFromDDF

Method deserializeFromDDF

core/src/main/java/io/ddf/ml/Model.java:162–187  ·  view source on GitHub ↗
(BasicDDF ddf)

Source from the content-addressed store, hash-verified

160 }
161
162 public static Model deserializeFromDDF(BasicDDF ddf) throws DDFException {
163 List<String> data = ddf.getList(String.class);
164 List<String> metaData = new ArrayList<String>();
165 List<Schema.Column> columns = ddf.getSchema().getColumns();
166
167 for (Schema.Column col : columns) {
168 metaData.add(col.getName());
169 }
170 if (metaData.size() != data.size()) {
171 throw new DDFException("");
172 }
173
174 List<String> listJson = new ArrayList<String>();
175
176 for (int i = 0; i < metaData.size(); i++) {
177 String key = metaData.get(i);
178 String value = data.get(i);
179 listJson.add(String.format("\"%s\":%s", key, value));
180 }
181
182 String json = StringUtils.join(listJson, ",");
183 Model model = Model.fromJson(String.format("{%s}", json));
184
185 ddf.getManager().addModel(model);
186 return model;
187 }
188
189 static class ModelDeserializer implements JsonDeserializer<Model> {
190 private Gson _gson = new Gson();

Callers 1

Calls 11

fromJsonMethod · 0.95
sizeMethod · 0.80
addModelMethod · 0.80
getColumnsMethod · 0.65
getSchemaMethod · 0.65
addMethod · 0.65
getNameMethod · 0.65
getMethod · 0.65
joinMethod · 0.65
getListMethod · 0.45
getManagerMethod · 0.45

Tested by 1