Java tutorial
/* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** * WekaRelationName.java * Copyright (C) 2010-2017 University of Waikato, Hamilton, New Zealand */ package adams.flow.transformer; import adams.flow.core.Token; import weka.core.Instance; import weka.core.Instances; /** <!-- globalinfo-start --> * Extracts the relation name of a weka.core.Instances or weka.core.Instance object. * <br><br> <!-- globalinfo-end --> * <!-- flow-summary-start --> * Input/output:<br> * - accepts:<br> * weka.core.Instance<br> * weka.core.Instances<br> * - generates:<br> * java.lang.String<br> * <br><br> <!-- flow-summary-end --> * <!-- options-start --> * Valid options are: <br><br> * * <pre>-D (property: debug) * If set to true, scheme may output additional info to the console. * </pre> * * <pre>-name <java.lang.String> (property: name) * The name of the actor. * default: RelationName * </pre> * * <pre>-annotation <adams.core.base.BaseText> (property: annotations) * The annotations to attach to this actor. * default: * </pre> * * <pre>-skip (property: skip) * If set to true, transformation is skipped and the input token is just forwarded * as it is. * </pre> * <!-- options-end --> * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision$ */ @Deprecated public class WekaRelationName extends AbstractTransformer { /** for serialization. */ private static final long serialVersionUID = 5428249514975625L; /** * Returns a string describing the object. * * @return a description suitable for displaying in the gui */ public String globalInfo() { return "DEPRECATED\n" + "Use " + WekaInstancesInfo.class.getName() + " instead.\n\n" + "Extracts the relation name of a weka.core.Instances or " + "weka.core.Instance object."; } /** * Returns the class that the consumer accepts. * * @return <!-- flow-accepts-start -->weka.core.Instance.class, weka.core.Instances.class<!-- flow-accepts-end --> */ public Class[] accepts() { return new Class[] { Instance.class, Instances.class }; } /** * Returns the class of objects that it generates. * * @return <!-- flow-generates-start -->java.lang.String.class<!-- flow-generates-end --> */ public Class[] generates() { return new Class[] { String.class }; } /** * Executes the flow item. * * @return null if everything is fine, otherwise error message */ protected String doExecute() { String result; Instance inst; Instances data; result = null; if (m_InputToken.getPayload() instanceof Instance) { inst = (Instance) m_InputToken.getPayload(); data = inst.dataset(); } else { inst = null; data = (Instances) m_InputToken.getPayload(); } m_OutputToken = new Token(data.relationName()); return result; } }