@Override public int numValues() { return tuple.getSchema().getColumnCount(); }
@Override public int numAttributes() { return tuple.getSchema().getColumnCount(); }
@Override public String toString() { StringBuffer text = new StringBuffer(); for (int i = 0; i < tuple.getSchema().getColumnCount(); i++) { if (i > 0) text.append(","); text.append(tuple.get(i)); } return text.toString(); }
@Override public double[] toDoubleArray() { for (int i = tuple.getSchema().getColumnCount() - 1; i >= 0; i--) { m_AttValues[i] = this.value(i); } return m_AttValues; }
/** * Constructor. * @param tuple an obvious tuple */ public ObviousWekaInstance(Tuple tuple, Instances instances) { this.tuple = tuple; this.instances = instances; this.m_Dataset = this.instances; this.m_Weight = 1.0; this.m_AttValues = new double[tuple.getSchema().getColumnCount()]; this.m_AttValues = toDoubleArray(); }
@Override public void replaceMissingValues(double[] arg0) { for (int i = 0; i < tuple.getSchema().getColumnCount(); i++) { if (isMissing(i)) { tuple.set(i, arg0[i]); } } }
@Override public double value(int attIndex) { Class<?> c = tuple.getSchema().getColumnType(attIndex); double value = -1; if (ObviousWekaUtils.isNumeric(c)) { return Double.valueOf(tuple.get(attIndex).toString()); } else if (ObviousWekaUtils.isString(c)) { return Double.valueOf(attribute(attIndex).indexOfValue( tuple.getString(attIndex))); } else if (ObviousWekaUtils.isDate(c)) { return tuple.getDate(attIndex).getTime(); } return value; }
@Override public void setValue(int attIndex, double value) { Class<?> c = tuple.getSchema().getColumnType(attIndex); if (ObviousWekaUtils.isNumeric(c)) { tuple.set(attIndex, value); } else if (ObviousWekaUtils.isString(c)) { return; } else if (ObviousWekaUtils.isDate(c)) { Date date = new Date((long) value); tuple.set(attIndex, date); } }
/** * Adds a row to the table (tuple). * @param tuple tuple to insert in the table. * @return row count */ public int addRow(Tuple tuple) { try { this.beginEdit(TableListener.ALL_COLUMN); int r = table.addRow(); for (int i = 0; i < tuple.getSchema().getColumnCount(); i++) { this.set(r, tuple.getSchema().getColumnName(i), tuple.get(i)); } this.endEdit(TableListener.ALL_COLUMN); this.fireTableEvent(r, r, TableListener.ALL_COLUMN, TableListener.INSERT); return r; } catch (Exception e) { throw new ObviousRuntimeException(e); } }
if (canAddRow()) { int rowId = table.addRow(); for (int i = 0; i < tuple.getSchema().getColumnCount(); i++) { String field = tuple.getSchema().getColumnName(i); if (schema.hasColumn(field)) { TypedFormat format = formatFactory.getFormat( tuple.getSchema().getColumnType(i).getSimpleName()); if (format instanceof FormatFactoryImpl.TypedDecimalFormat) { table.setValueAt(tuple.get(i).toString(), rowId,
@Override public int addRow(Tuple tuple) { if (tuple.getSchema().equals(getSchema())) { String colName = tuple.getString("name"); Class<?> c = (Class<?>) tuple.get("type"); Object value = tuple.get("default"); addColumn(colName, c, value); } this.fireTableEvent(getColumnCount(), getColumnCount(), TableListener.ALL_COLUMN, TableListener.INSERT); return getColumnCount(); }
@Override public int addRow(Tuple tuple) { Schema tupleSchema = tuple.getSchema(); for (int i = 0; i < tupleSchema.getColumnCount(); i++) { if (!tupleSchema.getColumnName(i).equals(schema.getColumnName(i)) || !tupleSchema.getColumnType(i).equals(schema.getColumnType(i))) { return -1; } } Instance inst = new Instance(schema.getColumnCount()); for (int i = 0; i < tuple.getSchema().getColumnCount(); i++) { Attribute att = instances.attribute(i); if (att.isNumeric()) { inst.setValue(att, Double.parseDouble(tuple.get(i).toString())); } else if (att.isString() || att.isNominal()) { inst.setValue(att, tuple.getString(i)); } else if (att.isDate()) { try { inst.setValue(att, att.parseDate(tuple.getDate(i).toString())); } catch (ParseException e) { e.printStackTrace(); } } } instances.add(inst); return getRowCount(); }
String[] schemaCol = new String[schemaSize + 1]; for (int i = schemaSize; i >= 0; i--) { schemaBoolean[i] = tuple.getSchema().hasColumn( visualTable.getColumnName(i)); schemaCol[i] = visualTable.getColumnName(i);