use of org.apache.xmlbeans.SchemaType in project knime-core by knime.
the class RuleEngine2PortsNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
BufferedDataTable data = (BufferedDataTable) inData[DATA_PORT];
m_rowCount = data.size();
try {
Pair<ColumnRearranger, PortObject> rearrangerPair = createColumnRearranger((DataTableSpec) inData[DATA_PORT].getSpec(), new DataTableRowInput((DataTable) inData[RULE_PORT]));
BufferedDataTable predictedTable = exec.createColumnRearrangeTable(data, rearrangerPair.getFirst(), exec);
PortObject second = rearrangerPair.getSecond();
if (m_settings.isPMMLRuleSet()) {
if (m_settings.isProvideStatistics()) {
PMMLPortObject po = (PMMLPortObject) rearrangerPair.getSecond();
PMMLPortObject pmmlPortObject = new PMMLPortObject(m_copy.getSpec(), po);
// Remove extra model.
pmmlPortObject.addModelTranslater(new PMMLTranslator() {
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
}
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
return null;
}
});
second = pmmlPortObject;
} else {
second = m_copy;
}
}
return new PortObject[] { predictedTable, second };
} finally {
m_rowCount = -1;
}
}
use of org.apache.xmlbeans.SchemaType in project knime-core by knime.
the class AbstractTreeModelPMMLTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
PMML pmml = pmmlDoc.getPMML();
TreeModelDocument.TreeModel treeModel = pmml.addNewTreeModel();
AbstractTreeModelExporter<N> exporter = createExporter(new DerivedFieldMapper(pmmlDoc));
SchemaType st = exporter.writeModelToPMML(treeModel, spec);
if (exporter.hasWarning()) {
addWarning(exporter.getWarning());
}
return st;
}
use of org.apache.xmlbeans.SchemaType in project knime-core by knime.
the class PMMLPortObject method addModelTranslater.
/**
* Adds the model of the content translater to the PMML document.
* @param modelTranslator the model translator containing the model to be
* added
*/
public void addModelTranslater(final PMMLTranslator modelTranslator) {
SchemaType type = modelTranslator.exportTo(m_pmmlDoc, m_spec);
LocalTransformations localTransformations = moveDerivedFields(type);
/* Remove mining fields from mining schema that where created as a
* derived field. In KNIME the origin of columns is not distinguished
* and all columns are added to the mining schema. But in PMML this
* results in duplicate entries. Those columns should only appear once
* as derived field in the transformation dictionary or local
* transformations. */
Set<String> derivedFields = new HashSet<String>();
for (DerivedField derivedField : getDerivedFields()) {
derivedFields.add(derivedField.getName());
}
MiningSchema miningSchema = PMMLUtils.getFirstMiningSchema(m_pmmlDoc, type);
if (miningSchema == null) {
LOGGER.info("No mining schema found.");
return;
}
MiningField[] miningFieldArray = miningSchema.getMiningFieldArray();
List<MiningField> miningFields = new ArrayList<MiningField>(Arrays.asList(miningFieldArray));
Set<String> miningFieldNames = new HashSet<String>();
for (MiningField miningField : miningFieldArray) {
String miningFieldName = miningField.getName();
if (derivedFields.contains(miningFieldName)) {
LOGGER.debug("Removing field \"" + miningFieldName + "\" from MiningFields as it is a DerivedField.");
miningFields.remove(miningField);
} else {
miningFieldNames.add(miningFieldName);
}
}
/* According to the PMML Spec DerivedFields must ultimately refer back
* to active MiningFields of the model's MiningSchema. Therefore we
* have to add all referred DataFields to the MiningSchema. */
String fullPath = NAMESPACE_DECLARATION + "$this/pmml:DerivedField/*/@field" + "| $this/pmml:DerivedField//pmml:FieldColumnPair/@field";
XmlObject[] xmlDescendants = localTransformations.selectPath(fullPath);
Set<String> referencedFields = new LinkedHashSet<String>();
// collect all referred field names
for (XmlObject xo : xmlDescendants) {
XmlCursor xmlCursor = xo.newCursor();
referencedFields.add(xmlCursor.getTextValue());
xmlCursor.dispose();
}
for (String referencedField : referencedFields) {
if (!derivedFields.contains(referencedField) && !miningFieldNames.contains(referencedField)) {
/* Add them to the mining schema if they are not already
* contained there and if they don't refer to derived fields. */
MiningField miningField = MiningField.Factory.newInstance();
miningField.setName(referencedField);
miningField.setInvalidValueTreatment(INVALIDVALUETREATMENTMETHOD.AS_IS);
LOGGER.debug("Adding field \"" + referencedField + "\" to MiningSchema because it is referenced in " + "LocalTransformations.");
miningFields.add(miningField);
}
}
miningSchema.setMiningFieldArray(miningFields.toArray(new MiningField[0]));
}
use of org.apache.xmlbeans.SchemaType in project knime-core by knime.
the class AbstractGBTModelPMMLTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
PMML pmml = pmmlDoc.getPMML();
AbstractGBTModelExporter<M> exporter = createExporter(new DerivedFieldMapper(pmmlDoc));
SchemaType st = exporter.writeModelToPMML(pmml.addNewMiningModel(), spec);
if (exporter.hasWarning()) {
addWarning(exporter.getWarning());
}
return st;
}
use of org.apache.xmlbeans.SchemaType in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createComponents.
/**
* Creates the components section of the SensorML description.
*
* @param sosComponents
* SOS SWE representation.
*
* @return encoded sml:components
*
* @throws EncodingException
* if the encoding fails
*/
private Components createComponents(List<SmlComponent> sosComponents) throws EncodingException {
Components components = Components.Factory.newInstance(getXmlOptions());
ComponentList componentList = components.addNewComponentList();
for (SmlComponent sosSMLComponent : sosComponents) {
Component component = componentList.addNewComponent();
if (sosSMLComponent.getName() != null) {
component.setName(sosSMLComponent.getName());
}
if (sosSMLComponent.getHref() != null) {
component.setHref(sosSMLComponent.getHref());
if (sosSMLComponent.getTitle() != null) {
component.setTitle(sosSMLComponent.getTitle());
}
} else if (sosSMLComponent.getProcess() != null) {
XmlObject xmlObject = null;
if (sosSMLComponent.getProcess().isSetXml()) {
try {
xmlObject = XmlObject.Factory.parse(sosSMLComponent.getProcess().getXml());
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding SensorML child procedure description " + "from stored SensorML encoded sensor description with XMLBeans", xmle);
}
} else {
if (sosSMLComponent.getProcess() instanceof SensorML) {
xmlObject = createSensorDescriptionFromObject(((SensorML) sosSMLComponent.getProcess()).getMembers().iterator().next());
} else if (sosSMLComponent.getProcess() instanceof AbstractProcess) {
xmlObject = createSensorDescriptionFromObject(sosSMLComponent.getProcess());
}
}
if (xmlObject != null) {
AbstractProcessType xbProcess = null;
if (xmlObject instanceof SensorMLDocument) {
final SensorMLDocument smlDoc = (SensorMLDocument) xmlObject;
for (final Member member : smlDoc.getSensorML().getMemberArray()) {
xbProcess = member.getProcess();
break;
}
} else if (xmlObject instanceof AbstractProcessType) {
xbProcess = (AbstractProcessType) xmlObject;
}
if (xbProcess == null) {
throw new EncodingException("The sensor type is not supported by this SOS");
}
// TODO add feature/parentProcs/childProcs to component - is
// this already done?
SchemaType schemaType = xbProcess.schemaType();
component.addNewProcess().substitute(getQnameForType(schemaType), schemaType).set(xbProcess);
}
}
}
return components;
}
Aggregations