Operator (numerical_to_date) in White Paper doesn't work
nurman
New Altair Community Member
Hi folks,
I encountered a problem in RM while following the White Paper's tutorial.
I followed closely step-by-step the flow inside that tutorial on how to create numerical_to_date operator.
The operator was working fine but failed to show the attributes at the right part of the RM.
It's not the same like the tutorial want.
Is there any problems in my step or that is what the tutorial want? ???
I encountered a problem in RM while following the White Paper's tutorial.
I followed closely step-by-step the flow inside that tutorial on how to create numerical_to_date operator.
The operator was working fine but failed to show the attributes at the right part of the RM.
It's not the same like the tutorial want.
Is there any problems in my step or that is what the tutorial want? ???
Tagged:
0
Answers
-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.017">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.1.017" expanded="true" name="Process">
<process expanded="true" height="476" width="748">
<operator activated="true" class="retrieve" compatibility="5.1.017" expanded="true" height="60" name="Retrieve" width="90" x="112" y="165">
<parameter key="repository_entry" value="//Samples/data/Golf"/>
</operator>
<operator activated="true" class="tutorial:numerical_to_date" compatibility="5.0.000" expanded="true" height="60" name="numerical_to_date" width="90" x="313" y="165"/>
<operator activated="true" class="adjust_date" compatibility="5.1.017" expanded="true" height="76" name="Adjust Date" width="90" x="514" y="165">
<list key="adjustments"/>
</operator>
<connect from_op="Retrieve" from_port="output" to_op="numerical_to_date" to_port="example set"/>
<connect from_op="numerical_to_date" from_port="example set" to_op="Adjust Date" to_port="example set input"/>
<connect from_op="Adjust Date" from_port="example set output" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
[ /code]0 -
Hi, in this case we would need the code of your operator and not just the process xml.
Best, Marius0 -
Hi,
I followed the code in the White Paper, but seems no luck. No attributes in the RapidMiner. Is it I have messed-up somewhere?
/*
* RapidMiner
*
* Copyright (C) 2001-2009 by Rapid-I and the contributors
*
* Complete list of developers available at our web site:
*
* http://rapid-i.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.rapidminer.operator.preprocessing.transformation;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.Attributes;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.example.table.AttributeFactory;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorDescription;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.operator.ports.InputPort;
import com.rapidminer.operator.ports.OutputPort;
import com.rapidminer.operator.ports.metadata.AttributeMetaData;
import com.rapidminer.operator.ports.metadata.ExampleSetMetaData;
import com.rapidminer.operator.ports.metadata.ExampleSetPassThroughRule;
import com.rapidminer.operator.ports.metadata.ExampleSetPrecondition;
import com.rapidminer.operator.ports.metadata.SetRelation;
import com.rapidminer.parameter.UndefinedParameterError;
import com.rapidminer.tools.Ontology;
/**
* This is the Numerical2Date tutorial operator.
*
* @author Sebastian Land
*/
public class Numerical2DateOperator extends Operator {
private InputPort exampleSetInput = getInputPorts().createPort("example set");
private OutputPort exampleSetOutput = getOutputPorts().createPort("example set");
/**
* Constructor
*/
public Numerical2DateOperator(OperatorDescription description) {
super(description);
exampleSetInput.addPrecondition(new ExampleSetPrecondition(exampleSetInput, new String[] { "relative time" }, Ontology.ATTRIBUTE_VALUE));
getTransformer().addRule(new ExampleSetPassThroughRule(exampleSetInput, exampleSetOutput, SetRelation.EQUAL) {
@Override
public ExampleSetMetaData modifyExampleSet(ExampleSetMetaData metaData) throws UndefinedParameterError {
AttributeMetaData timeAMD = metaData.getAttributeByName("relative time");
if (timeAMD != null) {
timeAMD.setType(Ontology.DATE_TIME);
timeAMD.setName("date(" + timeAMD.getName() + ")");
timeAMD.setValueSetRelation(SetRelation.UNKNOWN);
}
return metaData;
}
});
}
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData();
Attributes attributes = exampleSet.getAttributes();
Attribute sourceAttribute = attributes.get("relative time");
String newName = "date(" + sourceAttribute.getName() + ")";
Attribute targetAttribute = AttributeFactory.createAttribute(newName, Ontology.DATE_TIME);
targetAttribute.setTableIndex(sourceAttribute.getTableIndex());
attributes.addRegular(targetAttribute);
attributes.remove(sourceAttribute);
for (Example example : exampleSet) {
double timeStampValue = example.getValue(targetAttribute);
example.setValue(targetAttribute, timeStampValue * 1000);
}
exampleSetOutput.deliver(exampleSet);
}
}0 -
In your process you are loading the Golf dataset, and with the line
Attribute sourceAttribute = attributes.get("relative time");
you are trying to get an attribute named "relative time", which is not present in Golf. Thus your operator can't do anything useful.0