@Override public Attributes filterAttributes(String localName, Attributes attributes){ if(("Apply").equals(localName) && compare(getSource(), Version.PMML_4_1) == 0){ return renameAttribute(attributes, "mapMissingTo", "defaultValue"); } else if(("PMML").equals(localName)){ Version target = getTarget(); if(getExtensions()){ attributes = renameAttribute(attributes, "version", "x-baseVersion"); } return setAttribute(attributes, "version", target.getVersion()); } else if(("TargetValue").equals(localName) && compare(getSource(), Version.PMML_3_1) <= 0){ return renameAttribute(attributes, "rawDataValue", "displayValue"); } return attributes; }
public PMML unmarshalPMML(File file) throws JAXBException, SAXException, IOException { Unmarshaller unmarshaller = createUnmarshaller(); try(InputStream is = new FileInputStream(file)){ Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return (PMML)unmarshaller.unmarshal(source); } }
@PostConstruct public void setUp() throws IOException, SAXException, JAXBException { try (InputStream is = properties.getModelLocation().getInputStream()) { Source transformedSource = ImportFilter.apply(new InputSource(is)); pmml = JAXBUtil.unmarshalPMML(transformedSource); Assert.state(!pmml.getModels().isEmpty(), "The provided PMML file at " + properties.getModelLocation() + " does not contain any model"); } }
/** * @see JAXBUtil#unmarshalPMML(Source) */ static public PMML unmarshal(InputStream is) throws SAXException, JAXBException { Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return JAXBUtil.unmarshalPMML(source); }
/** * @see JAXBUtil#unmarshalPMML(Source) */ static public PMML unmarshal(InputStream is) throws SAXException, JAXBException { Source source = SAXUtil.createFilteredSource(is, new ImportFilter()); return JAXBUtil.unmarshalPMML(source); }
@Override public Attributes filterAttributes(String localName, Attributes attributes){ if(("Apply").equals(localName) && compare(getSource(), Version.PMML_4_1) == 0){ return renameAttribute(attributes, "mapMissingTo", "defaultValue"); } else if(("PMML").equals(localName)){ Version target = getTarget(); if(getExtensions()){ attributes = renameAttribute(attributes, "version", "x-baseVersion"); } return setAttribute(attributes, "version", target.getVersion()); } else if(("TargetValue").equals(localName) && compare(getSource(), Version.PMML_3_1) <= 0){ return renameAttribute(attributes, "rawDataValue", "displayValue"); } return attributes; }
public LoadingModelEvaluatorBuilder load(InputStream is, String modelName) throws SAXException, JAXBException { Schema schema = getSchema(); ValidationEventHandler validationEventHandler = getValidationEventHandler(); List<? extends XMLFilter> filters = getFilters(); boolean locatable = getLocatable(); VisitorBattery visitors = getVisitors(); Unmarshaller unmarshaller = JAXBUtil.createUnmarshaller(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventHandler); if(filters == null){ filters = Collections.singletonList(new ImportFilter()); } Source source = SAXUtil.createFilteredSource(is, filters.toArray(new XMLFilter[filters.size()])); PMML pmml = (PMML)unmarshaller.unmarshal(source); Visitor locatorHandler = (locatable ? new LocatorTransformer() : new LocatorNullifier()); locatorHandler.applyTo(pmml); if(visitors != null && visitors.size() > 0){ visitors.applyTo(pmml); } Model model = PMMLUtil.findModel(pmml, modelName); setPMML(pmml); setModel(model); return this; }
@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());