Closed kobeliuke closed 4 years ago
i want to convert the pmml to a java evalutor object directly
What do you mean by "directly"?
Please see the "Usage" section of the README file. What's wrong with the proposed transpilation (aka conversion) procedure - read PMML XML file, perform in-memory transpilation, and then use the resulting org.jpmml.evaluator.Evaluator
instance for evaluation?
i want to convert the pmml to a java evalutor object directly
What do you mean by "directly"?
Thanks for your reply, i mean:
if i want to use this transpiler,may be i need do something like this:
java -jar jpmml-transpiler-executable-1.0-SNAPSHOT.jar --xml-input LightGBMAudit.pmml --jar-output LightGBMAudit.pmml.jar
i wanna to transform pmml like this:
PMML xmlPmml;
try(InputStream is = ...){
xmlPmml = PMMLUtil.unmarshal(is);
}
JCodeModel codeModel = TranspilerUtil.transpile(xmlPmml, "com.mycompany.MyModel");
TranspilerUtil.compile(codeModel);
after this ,The README file tell me output the codeModel
as a jar, and in docker env, this is not easy,
so i wanna to This API: new ServiceLoadingModelEvaluatorBuilder().loadService(pmmlURL)
,
this just provide a pmml url, how can i load a JavaModelEvaluator with code , not url
The JPMML-CodeModel library (is a transitive dependency of the JPMML-Transpiler library) provides class org.jpmml.codemodel.JCodeModelClassLoader
, which defines an in-memory Java class loader object based on a JCodeModel
object:
JCodeModel codeModel = TranspilerUtil.transpile(..);
TranspilerUtil.compile(codeModel);
// THIS!
ClassLoader classLoader = new JCodeModelClassLoader(codeModel);
You can then use this JCodeModelClassLoader
in place of URLClassLoader
:
EvaluatorBuilder evaluatorBuilder = new ServiceLoadingModelEvaluatorBuilder()
.loadService(classLoader, null);
Evaluator evaluator = evaluatorBuilder.build();
Thanks you very much !!!!
However, when using JCodeModelClassLoader
, then there is a risk that the original JCodeModel
object will be staying in the RAM for as long as the Evaluator
object exists.
If you manage to dump the JCodeModel
object to a JAR file, then this breaks the "chain of reference", and JVM will be able to garbage-collect the original JCodeModel
object (can be huge, many times greater in size than the PMML class model object).
Thanks a lot, it have a great help,appreciate it.
as subject, sometimes i want to convert the pmml to a java evalutor object directly, any api can help, thanks a lot