/** Creates a specialized AddExpression */ public Filter getFilter(String expr) { AddExpression af = new AddExpression(); af.setExpression(expr); return af; }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); options.add("-E"); options.add(getExpression()); options.add("-N"); options.add(getName()); if (getDebug()) { options.add("-D"); } return options.toArray(new String[0]); }
/** * Main method for testing this class. * * @param args should contain arguments to the filter: use -h for help */ public static void main(String[] args) { runFilter(new AddExpression(), args); } }
/** * Initializes the format for the dataset produced. Must be called before the * generateExample or generateExamples methods are used. Re-initializes the * random number generator with the given seed. * * @return the format for the dataset * @throws Exception if the generating of the format failed * @see #getSeed() */ @Override public Instances defineDataFormat() throws Exception { ArrayList<Attribute> atts; // initialize input format atts = new ArrayList<Attribute>(); atts.add(new Attribute("x")); m_RawData = new Instances(getRelationNameToUse(), atts, 0); m_Filter = new AddExpression(); m_Filter.setName("y"); m_Filter.setExpression(getExpression()); m_Filter.setInputFormat(m_RawData); return super.defineDataFormat(); }
public boolean input(Instance instance) throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); resetQueue(); m_NewBatch = false; copyValues(inst, false, instance.dataset(), outputFormatPeek()); push(inst); // No need to copy instance return true;
String expString = Utils.getOption('E', options); if (expString.length() != 0) { setExpression(expString); } else { setExpression("a1^2"); setName(name); setDebug(Utils.getFlag('D', options));
/** Creates a default AddExpression */ public Filter getFilter() { return new AddExpression(); }
inst = new DenseInstance(1.0, atts); inst.setDataset(m_RawData); m_Filter.input(inst); m_Filter.batchFinished(); inst = m_Filter.output();
public void testAddNamed() { m_Filter = getFilter("a3+a6"); String name = "BongoBongo"; ((AddExpression)m_Filter).setName(name); Instances result = useFilter(); assertEquals(name, result.attribute(result.numAttributes() - 1).name()); name = "BongoBongoSecond"; ((AddExpression)m_Filter).setName(name); result = useFilter(); assertEquals(name, result.attribute(result.numAttributes() - 1).name()); }
/** * Initializes the format for the dataset produced. Must be called before the * generateExample or generateExamples methods are used. Re-initializes the * random number generator with the given seed. * * @return the format for the dataset * @throws Exception if the generating of the format failed * @see #getSeed() */ @Override public Instances defineDataFormat() throws Exception { ArrayList<Attribute> atts; // initialize input format atts = new ArrayList<Attribute>(); atts.add(new Attribute("x")); m_RawData = new Instances(getRelationNameToUse(), atts, 0); m_Filter = new AddExpression(); m_Filter.setName("y"); m_Filter.setExpression(getExpression()); m_Filter.setInputFormat(m_RawData); return super.defineDataFormat(); }
public boolean input(Instance instance) throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); resetQueue(); m_NewBatch = false; copyValues(inst, false, instance.dataset(), outputFormatPeek()); push(inst); // No need to copy instance return true;
String expString = Utils.getOption('E', options); if (expString.length() != 0) { setExpression(expString); } else { setExpression("a1^2"); setName(name); setDebug(Utils.getFlag('D', options));
/** * Main method for testing this class. * * @param args should contain arguments to the filter: use -h for help */ public static void main(String[] args) { runFilter(new AddExpression(), args); } }
/** Creates a default AddExpression */ public Filter getFilter() { return new AddExpression(); }
inst = new DenseInstance(1.0, atts); inst.setDataset(m_RawData); m_Filter.input(inst); m_Filter.batchFinished(); inst = m_Filter.output();
public void testAddNamed() { m_Filter = getFilter("a3+a6"); String name = "BongoBongo"; ((AddExpression)m_Filter).setName(name); Instances result = useFilter(); assertEquals(name, result.attribute(result.numAttributes() - 1).name()); name = "BongoBongoSecond"; ((AddExpression)m_Filter).setName(name); result = useFilter(); assertEquals(name, result.attribute(result.numAttributes() - 1).name()); }
/** Creates a specialized AddExpression */ public Filter getFilter(String expr) { AddExpression af = new AddExpression(); af.setExpression(expr); return af; }
public static Expression parseString(String s) { if (s.length() == 0) return null; else { /*ADDITION*/ if (s.charAt(0) == '+') { Expression left = parseString(s.substring(1)); Expression right = parseString(s.substring(left.length() +1)); //where length should return expressions length return new AddExpression( left, right ); } /*LITERALS*/ else { int i=0; while (i < s.length() && s.charAt(i) != ' ') { // find the end of the number i++; } return new IntExpression(s.substring(0, i)); } } }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); options.add("-E"); options.add(getExpression()); options.add("-N"); options.add(getName()); if (getDebug()) { options.add("-D"); } return options.toArray(new String[0]); }
/** Creates a configured MultiFilter */ public Filter getConfiguredFilter() { MultiFilter result = new MultiFilter(); Filter[] filters = new Filter[2]; filters[0] = new Add(); ((Add) filters[0]).setAttributeIndex("last"); filters[1] = new AddExpression(); ((AddExpression) filters[1]).setExpression("a3+a6"); result.setFilters(filters); return result; }