@Override public Pair<String,String> generate(int id, RandomGenerator random) { PMML pmml = RDFPMMLUtilsTest.buildDummyRegressionModel(); return new Pair<>("MODEL", PMMLUtils.toString(pmml)); }
modelUpdateTopic.send("MODEL", PMMLUtils.toString(bestModel)); } else { modelUpdateTopic.send("MODEL-REF", fs.makeQualified(bestModelPath).toString());
@Override public Pair<String,String> generate(int id, RandomGenerator random) { if (id == 0) { PMML pmml = RDFPMMLUtilsTest.buildDummyClassificationModel(); return new Pair<>("MODEL", PMMLUtils.toString(pmml)); } else { String nodeID = "r" + ((id % 2 == 0) ? '-' : '+'); Map<Integer,Integer> counts = new HashMap<>(); counts.put(0, 1); counts.put(1, 2); return new Pair<>("UP", TextUtils.joinJSON(Arrays.asList(0, nodeID, counts))); } }
@Override public Pair<String,String> generate(int id, RandomGenerator random) { if (id == 0) { PMML pmml = KMeansPMMLUtilsTest.buildDummyClusteringModel(); return new Pair<>("MODEL", PMMLUtils.toString(pmml)); } else { List<?> data = Arrays.asList(id % 3, Arrays.asList(id, id), id); return new Pair<>("UP", TextUtils.joinJSON(data)); } }
@Override public Pair<String,String> generate(int id, RandomGenerator random) { if (id % 10 == 0) { PMML pmml = PMMLUtils.buildSkeletonPMML(); AppPMMLUtils.addExtension(pmml, "features", 2); AppPMMLUtils.addExtension(pmml, "implicit", true); AppPMMLUtils.addExtensionContent(pmml, "XIDs", X.keySet()); AppPMMLUtils.addExtensionContent(pmml, "YIDs", Y.keySet()); return new Pair<>("MODEL", PMMLUtils.toString(pmml)); } else { int xOrYID = id % 10; String xOrYIDString = ALSUtilsTest.idToStringID(id); String message; boolean isX = xOrYID >= 6; if (isX) { message = TextUtils.joinJSON(Arrays.asList( "X", xOrYIDString, X.get(xOrYIDString), A.get(xOrYIDString))); } else { message = TextUtils.joinJSON(Arrays.asList( "Y", xOrYIDString, Y.get(xOrYIDString), At.get(xOrYIDString))); } return new Pair<>("UP", message); } }
@Test public void testReadPMMLFromMessage() throws Exception { PMML pmml = PMMLUtils.buildSkeletonPMML(); String pmmlString = PMMLUtils.toString(pmml); assertEquals(PMMLUtils.VERSION, AppPMMLUtils.readPMMLFromUpdateKeyMessage( "MODEL", pmmlString, null).getVersion()); Path pmmlPath = getTempDir().resolve("out.pmml"); Files.write(pmmlPath, Collections.singleton(pmmlString)); assertEquals(PMMLUtils.VERSION, AppPMMLUtils.readPMMLFromUpdateKeyMessage( "MODEL-REF", pmmlPath.toAbsolutePath().toString(), null).getVersion()); assertNull(AppPMMLUtils.readPMMLFromUpdateKeyMessage("MODEL-REF", "no-such-path", null)); }
@Test public void testExtensionContent() throws Exception { PMML model = buildDummyModel(); assertNull(AppPMMLUtils.getExtensionContent(model, "foo")); AppPMMLUtils.addExtensionContent(model, "foo1", Arrays.asList("bar", "baz")); AppPMMLUtils.addExtensionContent(model, "foo2", Collections.emptyList()); AppPMMLUtils.addExtensionContent(model, "foo3", Arrays.asList(" c\" d \"e ", " c\" d \"e ")); PMML reserializedModel = PMMLUtils.fromString(PMMLUtils.toString(model)); assertEquals(Arrays.asList("bar", "baz"), AppPMMLUtils.getExtensionContent(reserializedModel, "foo1")); assertNull(AppPMMLUtils.getExtensionContent(reserializedModel, "foo2")); assertEquals(Arrays.asList(" c\" d \"e ", " c\" d \"e "), AppPMMLUtils.getExtensionContent(reserializedModel, "foo3")); }
@Test public void testToString() throws Exception { PMML model = buildDummyModel(); model.getHeader().setTimestamp(null); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<PMML version=\"4.3\" xmlns=\"http://www.dmg.org/PMML-4_3\">" + "<Header>" + "<Application name=\"Oryx\"/>" + "</Header>" + "<TreeModel functionName=\"classification\">" + "<Node recordCount=\"123.0\"/>" + "</TreeModel>" + "</PMML>", PMMLUtils.toString(model)); }
@Test public void testFromString() throws Exception { PMML model = buildDummyModel(); PMML model2 = PMMLUtils.fromString(PMMLUtils.toString(model)); assertEquals(model.getHeader().getApplication().getName(), model2.getHeader().getApplication().getName()); assertEquals(model.getModels().get(0).getMiningFunction(), model2.getModels().get(0).getMiningFunction()); }
@Test public void testExtensionValue() throws Exception { PMML model = buildDummyModel(); assertNull(AppPMMLUtils.getExtensionValue(model, "foo")); AppPMMLUtils.addExtension(model, "foo", "bar"); PMML reserializedModel = PMMLUtils.fromString(PMMLUtils.toString(model)); assertEquals("bar", AppPMMLUtils.getExtensionValue(reserializedModel, "foo")); }
modelUpdateTopic.send("MODEL", PMMLUtils.toString(bestModel)); } else { modelUpdateTopic.send("MODEL-REF", fs.makeQualified(bestModelPath).toString());