Giter VIP home page Giter VIP logo

Comments (6)

vruusmann avatar vruusmann commented on August 18, 2024 2

With the exported pmml file, I want to use jpmml to import it, and form a model with Java.

If you simply want to extract the contents of InlineTable elements, then you can use the JPMML-Model library for that.

I cast the Object into XercesImpl

You should implement a safe type check using the instanceof operator. If the object is an instance of org.w3c.dom.Element, then perform the type cast, and invoke the Element#getTextContent() method on the resulting object.

You can see how it's done in the JPMML-Evaluator library:
https://github.com/jpmml/jpmml-evaluator/blob/master/pmml-evaluator/src/main/java/org/jpmml/evaluator/InlineTableUtil.java#L77

from jpmml-evaluator.

vruusmann avatar vruusmann commented on August 18, 2024

JPMML-Evaluator provides full support for the TransformationDictionary element.

I believe that this issue is related to the following StackOverflow thread:
https://stackoverflow.com/questions/42499423/java-to-implement-transformationdictionary-pmml-model

KNIME uses the MapValues element to represent its Category2Number transformation:

<MapValues outputColumn="out" dataType="integer">
	<FieldColumnPair field="LIVE_STS" column="in"/>
	<InlineTable>
	<row>
		<pmml:in>N</pmml:in>
		<pmml:out>0</pmml:out>
	</row>
	<row>
		<pmml:in>L</pmml:in>
		<pmml:out>1</pmml:out>
	</row>
	</InlineTable>
</MapValues>

I'm afraid that this is not a valid XML/PMML markup, as the pmml:in and pmml:out elements do not specify a namespace declaration. The JPMML-Evaluator gets confused because the input value is supposed to be contained in the in column, but the InlineTable element does not contain such column (but there's a pmml:in column instead).

Can you test if one of the following changes makes JPMML-Evaluator work properly:

  1. Change the value of MapValues@outputColumn attribute to pmml:out, and the value of FieldColumnPair@column to pmml:in.

or

  1. Change the names of pmml:in and pmml:out elements to in and out, respectively.

Also, what are your KNIME and JPMML-Evaluator versions? Would hate to waste time on troubleshooting legacy/outdated versions.

from jpmml-evaluator.

cinqs avatar cinqs commented on August 18, 2024

For your infos:

I am using:

Knime: 3.2.2

Jpmml-eval: 1.3.4

I saw that knime has released the newer version 3.3.1, and I will try that before I post again, and of course I will try to delete the pmml namespace for a trial.

Merci bien

from jpmml-evaluator.

cinqs avatar cinqs commented on August 18, 2024

I tried the Knime 3.3.1, it behaves exactly the same with version 3.2.2 regarding the node Category2Number.

What I expected:

With the exported pmml file, I want to use jpmml to import it, and form a model with Java. Then I would be able to feed the model with a input category, after processing, the model would return a number, the number should be exactly the same as I did get from Knime Category2Number node.

What I did

  1. I removed the namespace xmlns:pmml="http://www.dmg.org/PMML-4_2"
  2. I removed all the pmml: ns before the in and out Elements.

Within Java:

PMML pmml = PMMLUtil.unmarshal(new FileInputStream(pmmlPath));
		
TransformationDictionary td = pmml.getTransformationDictionary();
		
if(td.hasDerivedFields()) {
    List<DerivedField> dfs = td.getDerivedFields();
			
     for(DerivedField df : dfs) {
         MapValues mv = (MapValues) df.getExpression();
         InlineTable it = mv.getInlineTable();
         List<Row> rs = it.getRows();
         for(Row r : rs) {
             List<Object> os = r.getContent();
             for(Object o : os) {
		  System.out.println(o.toString());
	     }
         }
     }
}

Then I checked console output, I got

[in: null]

            
[out: null]

I cast the Object into XercesImpl, (I forgot how I got the idea.), and its toString() method is:

public String toString(){
    return "[" + element.getTagName() + " : " + element.getNodeValue + "]";
}

But what I need here is element.getTextValue() instead of element.getNodeValue

what I want

I want to manually get the in, out text value to form a map to be used for mapping the input category. But I can't get the value. any idea?

Or these above are wrong direction on implement TransformationDictionary, do you have any other idea?

from jpmml-evaluator.

vruusmann avatar vruusmann commented on August 18, 2024

I removed the namespace xmlns:pmml="http://www.dmg.org/PMML-4_2"

The PMML specification does not define in and out elements. So, this KNIME generated PMML document is invalid (because it does not validate against PMML 4.2 XML schema).

You cannot blame valid PMML consumer implementations for not accepting invalid PMML documents.

Let's keep this issue open, and find and document a viable workaround. However, you should definitely file a bug report with KNIME.com, and ask them to fix their software.

from jpmml-evaluator.

cinqs avatar cinqs commented on August 18, 2024

I fetched the complete content from InlineTable with

Table<Integer, String, String> t = InlineTableUtil.getContent(it);

thanks, and I will leave this issue open.

As you suggested, I will also try to file a bug report to Knime.

Merci bcp.

from jpmml-evaluator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.