本文整理汇总了Java中org.jpmml.model.JAXBUtil.unmarshalPMML方法的典型用法代码示例。如果您正苦于以下问题:Java JAXBUtil.unmarshalPMML方法的具体用法?Java JAXBUtil.unmarshalPMML怎么用?Java JAXBUtil.unmarshalPMML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jpmml.model.JAXBUtil
的用法示例。
在下文中一共展示了JAXBUtil.unmarshalPMML方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
@Override
public void init(ProcessContext processContext) throws Exception {
//load model and marshal it into pmml version > 4.0
log.info("Loading .pmml model");
try (InputStream is = url.openStream()) {
Source transformedSource = ImportFilter.apply(new InputSource(is));
pmml = JAXBUtil.unmarshalPMML(transformedSource);
} catch (SAXException ex) {
log.error("Could not load model from file provided at" + url);
}
//build a modelevaluator from the loaded pmml file
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
modelEvaluator = modelEvaluatorFactory.newModelEvaluator(pmml);
log.info("Loaded model requires the following fields: " + modelEvaluator.getActiveFields().toString());
log.info("Loaded model has targets: " + modelEvaluator.getTargetFields().toString());
if (modelEvaluator.getTargetFields().size() > 1) {
log.error("Only models with one target variable are supported for now");
}
targetName = modelEvaluator.getTargetFieldName();
activeFields = modelEvaluator.getActiveFields();
}
示例2: testUncompressed
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
@Test
public void testUncompressed() throws Exception {
ModelConfig modelConfig = setupConfig();
RManager rManager = setupManager();
UUID uuid = rManager.trainAndAdd(modelConfig, RIntegrationTest.getTrainingInstances());
File targetFile = Files.createTempFile("targetPMML", ".xml").toFile();
// Save the model as PMML and load it.
rManager.saveAsPMML(uuid, targetFile.getAbsolutePath(), false);
try (FileInputStream fis = new FileInputStream(targetFile)) {
JAXBUtil.unmarshalPMML(new StreamSource(fis));
}
targetFile.delete();
}
示例3: testCompressed
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
@Test
public void testCompressed() throws Exception {
ModelConfig modelConfig = setupConfig();
RManager rManager = setupManager();
UUID uuid = rManager.trainAndAdd(modelConfig, RIntegrationTest.getTrainingInstances());
File targetFile = Files.createTempFile("targetPMML", ".xml").toFile();
// Save the model as PMML and load it.
rManager.saveAsPMML(uuid, targetFile.getAbsolutePath(), true);
try (FileInputStream fis = new FileInputStream(targetFile);
GZIPInputStream gis = new GZIPInputStream(fis)) {
JAXBUtil.unmarshalPMML(new StreamSource(gis));
}
targetFile.delete();
}
示例4: transform
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
private void transform(File pmmlFile, File serFile, List<Class<? extends Visitor>> visitorClazzes) throws Exception {
PMML pmml;
try(InputStream is = new FileInputStream(pmmlFile)){
Source source = ImportFilter.apply(new InputSource(is));
pmml = JAXBUtil.unmarshalPMML(source);
}
for(Class<? extends Visitor> visitorClazz : visitorClazzes){
Visitor visitor = visitorClazz.newInstance();
visitor.applyTo(pmml);
}
try(OutputStream os = new FileOutputStream(serFile)){
SerializationUtil.serializePMML(pmml, os);
}
}
示例5: createEvaluator
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
static
public Evaluator createEvaluator(InputStream is) throws SAXException, JAXBException {
Source source = ImportFilter.apply(new InputSource(is));
PMML pmml = JAXBUtil.unmarshalPMML(source);
// If the SAX Locator information is available, then transform it to java.io.Serializable representation
LocatorTransformer locatorTransformer = new LocatorTransformer();
locatorTransformer.applyTo(pmml);
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelManager(pmml);
modelEvaluator.verify();
return modelEvaluator;
}
示例6: fromString
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
/**
* @param pmmlString PMML model encoded as an XML doc in a string
* @return {@link PMML} object representing the model
* @throws IOException if XML can't be unserialized
*/
public static PMML fromString(String pmmlString) throws IOException {
// Emulate PMMLUtil.unmarshal here, but need to accept a Reader
InputSource source = new InputSource(new StringReader(pmmlString));
try {
return JAXBUtil.unmarshalPMML(ImportFilter.apply(source));
} catch (JAXBException | SAXException e) {
throw new IOException(e);
}
}
示例7: setUp
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
@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");
}
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:10,代码来源:PmmlProcessorConfiguration.java
示例8: unmarshal
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
static
private PMML unmarshal(File file) throws Exception {
try(InputStream is = new FileInputStream(file)){
Source source = ImportFilter.apply(new InputSource(is));
return JAXBUtil.unmarshalPMML(source);
}
}
示例9: consume
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
@Override
public FastRandomForest consume(String pmmlString) throws PMMLConversionException {
PMML pmml = null;
try (ByteArrayInputStream bais = new ByteArrayInputStream(pmmlString.getBytes())){
pmml = JAXBUtil.unmarshalPMML(new StreamSource(bais));
} catch (Exception e) {
throw new PMMLConversionException("Failed to unmarshal PMML from string. Make sure it is a valid PMML.", e);
}
return consume(pmml);
}
示例10: consume
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
@Override
public RandomForest consume(String pmmlString) throws PMMLConversionException {
PMML pmml = null;
try (ByteArrayInputStream bais = new ByteArrayInputStream(pmmlString.getBytes())){
pmml = JAXBUtil.unmarshalPMML(new StreamSource(bais));
} catch (Exception e) {
throw new PMMLConversionException("Failed to unmarshal PMML from string. Make sure it is a valid PMML.", e);
}
return consume(pmml);
}
示例11: consume
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
/**
* Consumes the PMML in the given file and converts it to a Weka {@link Classifier}.
*
* @param file The file with the PMML representation of the classifier.
* @return A Weka {@link Classifier}.
* @throws PMMLConversionException If if fails to consume the PMML file.
*/
public static Classifier consume(File file) throws PMMLConversionException {
PMML pmml = null;
try {
if (isGzipped(file)) {
logger.debug("Consuming GZipped PMML file '{}'.", file.getAbsolutePath());
try (FileInputStream fis = new FileInputStream(file);
GZIPInputStream gzipInputStream = new GZIPInputStream(fis))
{
pmml = JAXBUtil.unmarshalPMML(new StreamSource(gzipInputStream));
}
} else {
logger.debug("Consuming PMML file '{}'.", file.getAbsolutePath());
try (FileInputStream fis = new FileInputStream(file)) {
pmml = JAXBUtil.unmarshalPMML(new StreamSource(fis));
}
}
} catch (Exception e) {
throw new PMMLConversionException("Failed to unmarshal PMML file '" + file + "'. Make sure the file is a valid PMML.", e);
}
Algorithm algorithm = getAlgorithm(pmml);
logger.debug("Consumed PMML file using algorithm {}.", algorithm);
return algorithm.getPMMLConsumer().consume(pmml);
}
示例12: createEvaluator
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
private static Evaluator createEvaluator(String filePath) throws SAXException, JAXBException, IOException{
InputStream is = new FileInputStream(new File(filePath));
PMML pmml;
try {
Source source = ImportFilter.apply(new InputSource(is));
pmml = JAXBUtil.unmarshalPMML(source);
} finally {
is.close();
}
PMMLManager pmmlManager = new PMMLManager(pmml);
return (Evaluator)pmmlManager.getModelManager(ModelEvaluatorFactory.getInstance());
}
示例13: createEvaluator
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
static
public Evaluator createEvaluator(InputStream is) throws SAXException, JAXBException {
Source source = ImportFilter.apply(new InputSource(is));
PMML pmml = JAXBUtil.unmarshalPMML(source);
// If the SAX Locator information is available, then transform it to java.io.Serializable representation
LocatorTransformer locatorTransformer = new LocatorTransformer();
locatorTransformer.applyTo(pmml);
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
Evaluator evaluator = modelEvaluatorFactory.newModelEvaluator(pmml);
// Perform self-testing
evaluator.verify();
return evaluator;
}
示例14: createEvaluator
import org.jpmml.model.JAXBUtil; //导入方法依赖的package包/类
static
public Evaluator createEvaluator(InputStream is) throws SAXException, JAXBException {
Source source = ImportFilter.apply(new InputSource(is));
PMML pmml = JAXBUtil.unmarshalPMML(source);
// If the SAX Locator information is available, then transform it to java.io.Serializable representation
LocatorTransformer locatorTransformer = new LocatorTransformer();
pmml.accept(locatorTransformer);
ModelEvaluatorFactory modelEvaluatorFactory = ModelEvaluatorFactory.newInstance();
ModelEvaluator<?> modelEvaluator = modelEvaluatorFactory.newModelManager(pmml);
return modelEvaluator;
}