如何在 JPMML 中创建自定义标签?

数据挖掘 逻辑回归 爪哇
2022-02-18 20:20:49

我正在尝试在 jpmml 中创建逻辑回归模型,然后将 PMML 写入文件。我遇到的问题是我找不到任何方法来创建自定义标签,例如以下示例中的“shortForm”和“longForm”:

<MapValues outputColumn="longForm">
  <FieldColumnPair field="gender" column="shortForm"/>
  <InlineTable>
    <row><shortForm>m</shortForm><longForm>male</longForm>
    </row>
    <row><shortForm>f</shortForm><longForm>female</longForm>
    </row>
  </InlineTable>
</MapValues>

这是我到目前为止所拥有的:

MapValues mv = new MapValues("output")
  .withFieldColumnPairs(
        new FieldColumnPair( new FieldName("gender"), "shortForm" )
  ).withInlineTable(
        new InlineTable().withRows(
                new Row().with???( new ??? )
)))

简而言之,我要求一个 API 调用,我可以用它来实例化示例中的“shortForm”元素,并将其附加到“row”对象。我已经浏览了 API、示例和 Google/SO,但找不到任何东西。

谢谢你的帮助!

1个回答

您可以/应该使用通用的 XML 绑定 Java 架构 (JAXB) 方法。

简单地说,调用代表所需 XML 内容的Row#withContent(Object...)实例。org.w3c.dom.Element

例如:

Document document = documentBuilder.newDocument();
Element shortForm = document.createElement("shortForm");
shortForm.setTextContent("m");
Element longForm = document.createElement("longForm");
longForm.setTextContent("male");
row = row.withContent(shortForm, longForm);