PMML with android support (without JAXB)

668 views
Skip to first unread message

Babak Shahid

unread,
Jun 24, 2020, 9:54:01 AM6/24/20
to Java PMML API
Hi,

We were trying to incorporate PMML in our project but since PMML requires JAXB, which is a java Native library but it is absent from android. Android only contains a subset of Java libraries, most of the subset of native libraries used by JAXB are also not available so there is a chain of dependencies that are raised on android. 

Is it possible that we can have a PMML version that uses an android friendly library that works similar to JAXB.

Thank you.

Villu Ruusmann

unread,
Jun 24, 2020, 3:21:27 PM6/24/20
to Java PMML API
Hi Babak,

> Is it possible that we can have a PMML version that
> uses an android friendly library that works similar to JAXB.
>

The PMML standard is distributed in the form of a XML Schema Document
(XSD), like this: http://dmg.org/pmml/v4-4/pmml-4-4.xsd

The JAXB technology allows me to generate Java class model classes
straight from the XSD file. I find it highly advantageous, as it gives
me a guarantee that all element and attribute names are correctly
spelled, plus their types and values are checked. Also, over the
years, I've customized/tweaked my XSD-to-Java conversion workflow
quite a lot, and I'd hate to lose that investment.

So, the short answer to your question is that the JPMML-Model library
(https://github.com/jpmml/jpmml-model) will never move off the JAXB
technology.

If that makes this library (partially-) hard to use on the Android
platform, then I can suggest the following workarounds.

1) If the Android Java/JVM does not provide built in JAXB runtime,
then perhaps it's possible to include an independent 3rd party JAXB
runtime into the project? The JPMML-Model project contains two modules
org.jpmml:pmml-model-metro and org.jpmml:pmml-model-moxy, which should
include a full runtime dependency of Glassfish Metro and EclipseLink
MOXy JAXB runtimes, respectively. I'd personally experiment with
depending on the org.jpmml:pmml-model-moxy module (instead of the
standard org.jpmml:pmml-model module), as EclipseLink as a third party
vendor might more flexible/less intrusive in their approach.

Also, it should be remembered that newer Java/JVM SE versions also do
not include JAXB runtime. However, using the suggested modules has got
things working for me on all Java SE 9, 10, 11 and 12 so far. Why not
on Android then?

2) The JPMML-Model library supports JSON and YAML data formats in
addition to the default XML data format. You can translate the
original PMML XML document to a PMML JSON document, and then load it
using some JSON unmarshalling library (instead of JAXB). The
JPMML-Model project is known to work well with FasterXML Jackson JSON
deserializer, as contained in the org.jpmml:pmml-model-jackson module.

For a quick start on translating PMML XML to PMML JSON, you can use
the org.jpmml.model.example.TranslationExample command-line
application (available in the JPMML-Model releases page at
https://github.com/jpmml/jpmml-model/releases):
$ java -cp pmml-model-example-executable-1.5.1.jar
org.jpmml.model.example.TranslationExample --input
DecisionTreeIris.pmml --output DecisionTreeIris.json

3) It's possible to translate+compile (aka transpile) PMML XML
documents into PMML Java Archives. Basically, it's a self-contained
Java ARchive (JAR), which contains an org.dmg.pmml.PMML subclass
representing the original PMML document. This class can be loaded and
instantiated as a regular Java class, and does not require any JAXB or
JSON runtime.

For example, transpiling a PMML XML to PMML Service JAR file using the
JPMML-Transpiler command-line application (available in the
JPMML-Transpiler releases page at
https://github.com/jpmml/jpmml-transpiler/releases):

$ java -jar jpmml-transpiler-executable-1.1.0.jar --input
DecisionTreeIris.pmml --output DecisionTreeIris.jar --class-name
com.mycompany.DecisionTreeIris

Then, add the DecisionTreeIris.jar to your Android application
classpath, and create a PMML class model object like this:
org.dmg.pmml.PMML pmml = new com.mycompany.DecisionTreeIris();

---

Should be plenty of options to choose from. I'd personally recommend
approach #2 for when you want to dynamically download/refresh/unload
models in your Android application, and #3 for when you want to
integrate more tightly. Approach #3 will be much speedier (can load
big models instantly - limited by the class loading speed of Android
JVM) and can possibly enjoy 10x performance improvement from replacing
XML interpretation with Java bytecode execution.


VR
Reply all
Reply to author
Forward
0 new messages