byte[] data = IoUtils.readBytesFromInputStream(processResource.getInputStream()); String processAsString = new String(data, "UTF-8");
public InputStream getInputStream() throws IOException { return delegate.getInputStream(); }
public String compile(String resource, ClassLoader classLoader) { String theory = null; Resource cpr = new ClassPathResource(resource); try { theory = compile(cpr.getInputStream(), classLoader); } catch (IOException e) { results.add(new PMMLError(e.toString())); e.printStackTrace(); } return theory; }
public Resource[] transform(Resource resource, ClassLoader classLoader) { String theory = null; try { theory = compile(resource.getInputStream(), classLoader); } catch (IOException e) { results.add(new PMMLError(e.toString())); e.printStackTrace(); return new Resource[0]; } return new Resource[]{buildOutputResource(resource, theory)}; }
private InputStream getInputStreamByFileName(String fileName) { InputStream is = null; Resource res = ResourceFactory.newClassPathResource(fileName); try { is = res.getInputStream(); } catch (Exception e) { } if (is == null) { res = ResourceFactory.newFileResource(fileName); } try { is = res.getInputStream(); } catch (Exception e) { this.results.add(new PMMLError("Unable to retrieve file based resource: " + fileName)); } return is; }
/** * This method calls the PMML compiler to get PMMLResource objects which are used to * create one or more PackageDescr objects * @param resource * @return * @throws DroolsParserException * @throws IOException */ private List<PackageDescr> getPackageDescrs(Resource resource) throws DroolsParserException, IOException { List<PMMLResource> resources = pmmlCompiler.precompile(resource.getInputStream(), null, null); if (resources != null && !resources.isEmpty()) { return generatedResourcesToPackageDescr(resource, resources); } return null; }
private static void prepareTemplate(String ntempl) { try { String path = TEMPLATE_PATH + ntempl; Resource res = ResourceFactory.newClassPathResource(path, org.kie.pmml.pmml_4_2.PMML4Compiler.class); if (res != null) { InputStream stream = res.getInputStream(); if (stream != null) { registry.addNamedTemplate(path.substring(path.lastIndexOf('/') + 1), TemplateCompiler.compileTemplate(stream)); } } } catch (IOException e) { e.printStackTrace(); } }
private void loadTemplates(MULTIPLEMODELMETHOD mmm) { if (!templates.contains(mmm.name())) { Resource res = ResourceFactory.newClassPathResource(templateNameToFile.get(mmm.name()), MiningSegmentation.class); if (res != null) { try { InputStream strm = res.getInputStream(); templates.addNamedTemplate(mmm.name(), TemplateCompiler.compileTemplate(strm)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
Map<String, String> modelSources = null; try { modelSources = compiler.getJavaClasses(resource.getInputStream()); } catch (IOException e) { kbuilder.addBuilderResult(new SrcError(resource, e.getMessage()));
byte[] data = IoUtils.readBytesFromInputStream(processResource.getInputStream()); String processAsString = new String(data, "UTF-8");
@Test public void testMissingTreeNull() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() );
@Test public void testMissingTreeAllMissingDefault() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() );
@Test public void testMissingTreeLastChoice() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() );
@Test public void testMissingAggregate() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() );
@Test public void testMissingTreeDefault() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() ); for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) { if ( o instanceof TreeModel ) { TreeModel tree = (TreeModel) o; tree.setMissingValueStrategy( MISSINGVALUESTRATEGY.DEFAULT_CHILD ); } } KieSession kSession = getSession( compiler.generateTheory( pmml ) ); setKSession( kSession ); setKbase( getKSession().getKieBase() ); kSession.fireAllRules(); //init model FactType tgt = kSession.getKieBase().getFactType( packageName, "Fld9" ); FactType tok = kSession.getKieBase().getFactType( PMML4Helper.pmmlDefaultPackageName(), "TreeToken" ); kSession.getEntryPoint( "in_Fld1" ).insert( 70.0 ); kSession.getEntryPoint( "in_Fld2" ).insert( 40.0 ); kSession.getEntryPoint( "in_Fld3" ).insert( "miss" ); kSession.fireAllRules(); Object token = getToken( kSession ); assertEquals( 0.72, (Double) tok.get( token, "confidence" ), 1e-6 ); assertEquals( "null", tok.get( token, "current" ) ); assertEquals( 40.0, tok.get( token, "totalCount" ) ); checkFirstDataFieldOfTypeStatus(tgt, true, false, "Missing", "tgtX" ); checkGeneratedRules(); }
@Test public void testMissingTreeNone() throws Exception { PMML4Compiler compiler = new PMML4Compiler(); PMML pmml = compiler.loadModel( PMML, ResourceFactory.newClassPathResource( source2 ).getInputStream() );