@Test public void findChained() throws Exception { PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class); Visitor visitor = new AbstractVisitor(){ @Override public VisitorAction visit(Segment segment){ Model model = segment.getModel(); String id = segment.getId(); if("first".equals(id)){ checkFields(FieldNameUtil.create("x1_squared"), model); } else if("second".equals(id)){ checkFields(FieldNameUtil.create("x2", "x2_squared"), model); } else if("third".equals(id)){ checkFields(FieldNameUtil.create("x3"), model); } else if("sum".equals(id)){ checkFields(FieldNameUtil.create("first_output", "second_output", "third_output"), model); } else { throw new AssertionError(); } return super.visit(segment); } }; visitor.applyTo(pmml); }
@Test public void filterNestedSegmentation() throws Exception { ResourceUtil.unmarshal(NestedSegmentationTest.class, new DepthFilter("Segmentation", 3)); try { ResourceUtil.unmarshal(NestedSegmentationTest.class, new DepthFilter(Segmentation.class, 2)); fail(); } catch(UnmarshalException ue){ Throwable cause = ue.getCause(); assertTrue(cause instanceof SAXException); } ResourceUtil.unmarshal(NestedSegmentationTest.class, new DepthFilter("*", 15)); try { ResourceUtil.unmarshal(NestedSegmentationTest.class, new DepthFilter("*", 10)); fail(); } catch(UnmarshalException ue){ Throwable cause = ue.getCause(); assertTrue(cause instanceof SAXException); } } }
@Test public void filterNestedSegmentation() throws Exception { ResourceUtil.unmarshal(NestedSegmentationTest.class, new CountFilter("Segmentation", 3)); try { ResourceUtil.unmarshal(NestedSegmentationTest.class, new CountFilter(Segmentation.class, 2)); fail(); } catch(UnmarshalException se){ Throwable cause = se.getCause(); assertTrue(cause instanceof SAXException); } ResourceUtil.unmarshal(NestedSegmentationTest.class, new CountFilter("*", 100)); try { ResourceUtil.unmarshal(NestedSegmentationTest.class, new CountFilter("*", 10)); fail(); } catch(UnmarshalException ue){ Throwable cause = ue.getCause(); assertTrue(cause instanceof SAXException); } } }
@Test public void mixedContent() throws Exception { PMML pmml = ResourceUtil.unmarshal(getClass()); List<?> content = ExtensionUtil.getContent(pmml); assertEquals(5, content.size()); assertEquals("First text value", content.get(0)); assertEquals(Arrays.asList("First extension"), getDeepContent(content.get(1))); assertEquals("Second text value", content.get(2)); assertEquals(Arrays.asList("Second extension"), getDeepContent(content.get(3))); assertEquals("Third text value", content.get(4)); try { SerializationUtil.clone(pmml); fail(); } catch(NotSerializableException nse){ // Ignored } pmml.accept(new LocatorTransformer()); SerializationUtil.clone(pmml); }
@Test public void filterCustomExtension() throws Exception { PMML pmml = ResourceUtil.unmarshal(WildcardTest.class, new SkipFilter("http://localhost/test", "Extension")); assertTrue(pmml.hasExtensions()); List<?> content = ExtensionUtil.getContent(pmml); assertEquals("First textSecond text", content.get(0)); } }
@Test public void filter() throws Exception { PMML pmml = ResourceUtil.unmarshal(ExtensionFilterTest.class, new ImportFilter()); pmml = ResourceUtil.unmarshal(ExtensionFilterTest.class, new ImportFilter(false)); pmml = ResourceUtil.unmarshal(ExtensionFilterTest.class, new ImportFilter(), new ExtensionFilter());
@Test public void compressedSequence() throws Exception { PMML pmml = ResourceUtil.unmarshal(Version.PMML_4_3); pmml.accept(new LocatorNullifier()); DirectByteArrayOutputStream buffer = new DirectByteArrayOutputStream(3 * 1024); try(OutputStream os = new GZIPOutputStream(buffer)){ SerializationUtil.serializePMML(pmml, os); SerializationUtil.serializePMML(pmml, os); os.flush(); } try(InputStream is = new GZIPInputStream(buffer.getInputStream())){ PMML firstPmml = SerializationUtil.deserializePMML(is); PMML secondPmml = SerializationUtil.deserializePMML(is); assertNotSame(firstPmml, secondPmml); assertEquals(-1, is.read()); } } }
@Test public void unmarshal() throws Exception { PMML pmml = ResourceUtil.unmarshal(InlineTableTest.class); Row row = getRow(pmml); List<?> content = row.getContent(); assertEquals(9, content.size()); Visitor visitor = new RowCleaner(); visitor.applyTo(pmml); assertEquals(4, content.size()); Object first = content.get(0); Object second = content.get(1); Object third = content.get(2); Object fourth = content.get(3); assertTrue(first instanceof Element); assertTrue(second instanceof InputCell); assertTrue(third instanceof OutputCell); assertTrue(fourth instanceof Element); assertEquals("0", ((InputCell)second).getValue()); assertEquals("zero", ((OutputCell)third).getValue()); }
@Test public void resolveNested() throws Exception { PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class);
@Test public void cleanChained() throws Exception { PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class);
@Test public void resolveNested() throws Exception { PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class);
@Test public void cleanNested() throws Exception { PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class); DataDictionary dataDictionary = pmml.getDataDictionary(); checkFields(FieldNameUtil.create("y", "x1", "x2", "x3", "x4", "x5"), dataDictionary.getDataFields()); DataDictionaryCleaner cleaner = new DataDictionaryCleaner(); cleaner.applyTo(pmml); checkFields(FieldNameUtil.create("x1", "x2", "x3", "x4", "x5"), dataDictionary.getDataFields()); List<Model> models = pmml.getModels(); models.clear(); cleaner.applyTo(pmml); checkFields(Collections.emptySet(), dataDictionary.getDataFields()); }
@Test public void cleanChained() throws Exception { PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class); DataDictionary dataDictionary = pmml.getDataDictionary(); checkFields(FieldNameUtil.create("y", "x1", "x2", "x3", "x4"), dataDictionary.getDataFields()); DataDictionaryCleaner cleaner = new DataDictionaryCleaner(); cleaner.applyTo(pmml); checkFields(FieldNameUtil.create("y", "x1", "x2", "x3"), dataDictionary.getDataFields()); List<Model> models = pmml.getModels(); models.clear(); cleaner.applyTo(pmml); checkFields(Collections.emptySet(), dataDictionary.getDataFields()); }
@Test public void resolveChained() throws Exception { PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class);
@Test public void cleanNested() throws Exception { PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class);
@Test public void filterNestedSegmentation() throws Exception { PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class, new SkipFilter(Segmentation.class)); assertNotNull(pmml.getDataDictionary()); List<Model> models = pmml.getModels(); MiningModel miningModel = (MiningModel)models.get(0); assertNotNull(miningModel.getMiningSchema()); assertNotNull(miningModel.getLocalTransformations()); assertNotNull(miningModel.getOutput()); assertNull(miningModel.getSegmentation()); }
@Test public void filterChainedSegmentation() throws Exception { PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class, new SkipFilter("Segmentation")); assertNotNull(pmml.getDataDictionary()); assertNotNull(pmml.getTransformationDictionary()); List<Model> models = pmml.getModels(); MiningModel miningModel = (MiningModel)models.get(0); assertNotNull(miningModel.getMiningSchema()); assertNotNull(miningModel.getOutput()); assertNull(miningModel.getSegmentation()); }
@Test public void nullifyAndClone() throws Exception { PMML pmml = ResourceUtil.unmarshal(Version.PMML_4_3); assertNotNull(pmml.getLocator()); try { SerializationUtil.clone(pmml); fail(); } catch(NotSerializableException nse){ // Ignored } pmml.accept(new LocatorNullifier()); assertNull(pmml.getLocator()); SerializationUtil.clone(pmml); }
@Test public void transformAndClone() throws Exception { PMML pmml = ResourceUtil.unmarshal(Version.PMML_4_3); assertNotNull(pmml.getLocator()); try { SerializationUtil.clone(pmml); fail(); } catch(NotSerializableException nse){ // Ignored } pmml.accept(new LocatorTransformer()); assertNotNull(pmml.getLocator()); SerializationUtil.clone(pmml); }
@Test public void cleanNested() throws Exception { PMML pmml = ResourceUtil.unmarshal(NestedSegmentationTest.class);