当前位置: 首页>>代码示例>>Java>>正文


Java JAXBUtil类代码示例

本文整理汇总了Java中org.jpmml.model.JAXBUtil的典型用法代码示例。如果您正苦于以下问题:Java JAXBUtil类的具体用法?Java JAXBUtil怎么用?Java JAXBUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JAXBUtil类属于org.jpmml.model包,在下文中一共展示了JAXBUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:26,代码来源:ApplyModel.java

示例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();
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:19,代码来源:RandomForestPMMLProducerConsumerTest.java

示例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();
}
 
开发者ID:feedzai,项目名称:fos-r,代码行数:21,代码来源:RandomForestPMMLProducerConsumerTest.java

示例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);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:20,代码来源:SerMojo.java

示例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;
}
 
开发者ID:jpmml,项目名称:jpmml-cascading,代码行数:18,代码来源:PMMLPlannerUtil.java

示例6: toString

import org.jpmml.model.JAXBUtil; //导入依赖的package包/类
/**
 * @param pmml model
 * @return model serialized as an XML document as a string
 */
public static String toString(PMML pmml) {
  try (StringWriter out = new StringWriter()) {
    // v JAXBUtil.marshalPMML but need to set compact, non-pretty output
    Marshaller marshaller = JAXBUtil.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
    marshaller.marshal(pmml, new StreamResult(out));
    return out.toString();
  } catch (JAXBException | IOException e) {
    // IOException should not be possible; JAXBException would only happen with XML
    // config problems.
    throw new IllegalStateException(e);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:18,代码来源:PMMLUtils.java

示例7: 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);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:15,代码来源:PMMLUtils.java

示例8: 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

示例9: 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);
	}
}
 
开发者ID:vruusmann,项目名称:jpmml-toolkit,代码行数:10,代码来源:Aggregator.java

示例10: convertPMMLToString

import org.jpmml.model.JAXBUtil; //导入依赖的package包/类
public static String convertPMMLToString(PMML pmml) throws JAXBException, UnsupportedEncodingException {
    ByteArrayOutputStream baor = new ByteArrayOutputStream();
    StreamResult streamResult = new StreamResult();
    streamResult.setOutputStream(baor);
    JAXBUtil.marshal(pmml, streamResult);
    return baor.toString(Charset.defaultCharset().toString());
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:8,代码来源:PMMLGenerator.java

示例11: testModelLibrary

import org.jpmml.model.JAXBUtil; //导入依赖的package包/类
/**
 * Test model library with sample training and test data
 */
@TestWith({"testMetaDataAll"})
public void testModelLibrary(TestMetaData testMetaData) throws Exception {
  Driver driver = new com.cloudera.framework.example.three.Driver(dfsServer.getConf());
  assertEquals(SUCCESS, driver.runner(dfsServer.getPath(DATASET_DIR).toString()));
  assertTrue(dfsServer.getFileSystem().exists(dfsServer.getPath(DATASET_DIR + "/" + ModelDir() + "/" + ModelFile())));
  assertTrue(Double.parseDouble(((PMML) JAXBUtil.unmarshal(new StreamSource(new StringReader((String) driver.getResults().get(0))))).
    getHeader().getExtensions().get(0).getContent().get(0).toString()) > ModelPmml.MinimumAccuracy());
  assertTrue(Double.parseDouble(((PMML) JAXBUtil.unmarshal(new StreamSource(dfsServer.getFileSystem().open(
    dfsServer.getPath(DATASET_DIR + "/" + ModelDir() + "/" + ModelFile()))))).
    getHeader().getExtensions().get(0).getContent().get(0).toString()) > ModelPmml.MinimumAccuracy());
}
 
开发者ID:ggear,项目名称:cloudera-framework,代码行数:15,代码来源:Model.java

示例12: testModelScript

import org.jpmml.model.JAXBUtil; //导入依赖的package包/类
/**
 * Test model script with sample training and test data
 */
@Test
public void testModelScript() throws Exception {
  assertEquals(0, scalaServer.execute(new File(DIR_SOURCE_SCRIPT, SCRIPT_SCALA)));
  assertTrue(dfsServer.getFileSystem().exists(dfsServer.getPath(DATASET_DIR + "/" + ModelDir() + "/" + ModelFile())));
  assertTrue(Double.parseDouble(((PMML) JAXBUtil.unmarshal(new StreamSource(dfsServer.getFileSystem().open(
    dfsServer.getPath(DATASET_DIR + "/" + ModelDir() + "/" + ModelFile()))))).
    getHeader().getExtensions().get(0).getContent().get(0).toString()) > ModelPmml.MinimumAccuracy());
}
 
开发者ID:ggear,项目名称:cloudera-framework,代码行数:12,代码来源:Model.java

示例13: 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);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:11,代码来源:FastRandomForestPMMLConsumer.java

示例14: produce

import org.jpmml.model.JAXBUtil; //导入依赖的package包/类
@Override
public void produce(FastRandomForest randomForestClassifier, File targetFile) throws PMMLConversionException {
    PMML pmml = produce(randomForestClassifier);
    try (FileOutputStream fis = new FileOutputStream(targetFile)){
        JAXBUtil.marshalPMML(pmml, new StreamResult(fis));
    } catch (Exception e) {
        throw new PMMLConversionException("Failed to marshal the PMML to the given file.", e);
    }
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:10,代码来源:FastRandomForestPMMLProducer.java

示例15: 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);
}
 
开发者ID:feedzai,项目名称:fos-weka,代码行数:11,代码来源:RandomForestPMMLConsumer.java


注:本文中的org.jpmml.model.JAXBUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。