/** * Returns the header info for a relation-valued attribute, null if the * attribute is not relation-valued. * * @return the attribute's value as an Instances object */ public final/* @ non_null pure @ */Instances relation() { if (!isRelationValued()) { return null; } else { return ((RelationalAttributeInfo)m_AttributeInfo).m_Header; } }
/** * Returns the header info for a relation-valued attribute, null if the * attribute is not relation-valued. * * @return the attribute's value as an Instances object */ public final/* @ non_null pure @ */Instances relation() { if (!isRelationValued()) { return null; } else { return ((RelationalAttributeInfo)m_AttributeInfo).m_Header; } }
/** * Returns a value of a relation-valued attribute. Returns null if the * attribute is not relation-valued. * * @param valIndex the value's index * @return the attribute's value as an Instances object */ public final/* @ non_null pure @ */Instances relation(int valIndex) { if (!isRelationValued()) { return null; } else { return (Instances) ((RelationalAttributeInfo)m_AttributeInfo).m_Values.get(valIndex); } }
/** * Returns a value of a relation-valued attribute. Returns null if the * attribute is not relation-valued. * * @param valIndex the value's index * @return the attribute's value as an Instances object */ public final/* @ non_null pure @ */Instances relation(int valIndex) { if (!isRelationValued()) { return null; } else { return (Instances) ((RelationalAttributeInfo)m_AttributeInfo).m_Values.get(valIndex); } }
/** * Returns the number of attribute values. Returns 0 for attributes that are * not either nominal, string, or relation-valued. * * @return the number of attribute values */ public final/* @ pure @ */int numValues() { if (!isNominal() && !isString() && !isRelationValued()) { return 0; } else { return ((NominalAttributeInfo)m_AttributeInfo).m_Values.size(); } }
/** * Returns the number of attribute values. Returns 0 for attributes that are * not either nominal, string, or relation-valued. * * @return the number of attribute values */ public final/* @ pure @ */int numValues() { if (!isNominal() && !isString() && !isRelationValued()) { return 0; } else { return ((NominalAttributeInfo)m_AttributeInfo).m_Values.size(); } }
@Override public void validate(Instances data) throws InvalidInputDataException { if (!data.attribute(relationalAttributeIndex).isRelationValued()){ throw new InvalidInputDataException("The attribute at index <" + relationalAttributeIndex + " is not relational."); } }
/** * Adds a relation to a relation-valued attribute. * * @param value The value to add * @return the index assigned to the value, or -1 if the attribute is not of * type Attribute.RELATIONAL */ public int addRelation(Instances value) { if (!isRelationValued()) { return -1; } if (!((RelationalAttributeInfo)m_AttributeInfo).m_Header.equalHeaders(value)) { throw new IllegalArgumentException("Incompatible value for " + "relation-valued attribute.\n" + ((RelationalAttributeInfo)m_AttributeInfo).m_Header.equalHeadersMsg(value)); } Integer index = ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.get(value); if (index != null) { return index.intValue(); } else { int intIndex = ((NominalAttributeInfo)m_AttributeInfo).m_Values.size(); ((NominalAttributeInfo)m_AttributeInfo).m_Values.add(value); ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.put(value, new Integer(intIndex)); return intIndex; } }
/** * Adds a relation to a relation-valued attribute. * * @param value The value to add * @return the index assigned to the value, or -1 if the attribute is not of * type Attribute.RELATIONAL */ public int addRelation(Instances value) { if (!isRelationValued()) { return -1; } if (!((RelationalAttributeInfo)m_AttributeInfo).m_Header.equalHeaders(value)) { throw new IllegalArgumentException("Incompatible value for " + "relation-valued attribute.\n" + ((RelationalAttributeInfo)m_AttributeInfo).m_Header.equalHeadersMsg(value)); } Integer index = ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.get(value); if (index != null) { return index.intValue(); } else { int intIndex = ((NominalAttributeInfo)m_AttributeInfo).m_Values.size(); ((NominalAttributeInfo)m_AttributeInfo).m_Values.add(value); ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.put(value, new Integer(intIndex)); return intIndex; } }
/** * Sets a value of a relation-valued attribute. Creates a fresh list of * attribute values before it is set. * * @param index the value's index * @param data the value * @throws IllegalArgumentException if the attribute is not relation-valued. */ final void setValue(int index, Instances data) { if (isRelationValued()) { if (!data.equalHeaders(((RelationalAttributeInfo)m_AttributeInfo).m_Header)) { throw new IllegalArgumentException("Can't set relational value. " + "Headers not compatible.\n" + data.equalHeadersMsg(((RelationalAttributeInfo)m_AttributeInfo).m_Header)); } ((NominalAttributeInfo)m_AttributeInfo).m_Values = Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone()); ((NominalAttributeInfo)m_AttributeInfo).m_Values.set(index, data); } else { throw new IllegalArgumentException("Can only set value for" + " relation-valued attributes!"); } }
/** * Sets a value of a relation-valued attribute. Creates a fresh list of * attribute values before it is set. * * @param index the value's index * @param data the value * @throws IllegalArgumentException if the attribute is not relation-valued. */ final void setValue(int index, Instances data) { if (isRelationValued()) { if (!data.equalHeaders(((RelationalAttributeInfo)m_AttributeInfo).m_Header)) { throw new IllegalArgumentException("Can't set relational value. " + "Headers not compatible.\n" + data.equalHeadersMsg(((RelationalAttributeInfo)m_AttributeInfo).m_Header)); } ((NominalAttributeInfo)m_AttributeInfo).m_Values = Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone()); ((NominalAttributeInfo)m_AttributeInfo).m_Values.set(index, data); } else { throw new IllegalArgumentException("Can only set value for" + " relation-valued attributes!"); } }
/** * Returns the relational value of a relational attribute. * * @param att the attribute * @return the corresponding relation as an Instances object, null if missing * @throws IllegalArgumentException if the attribute is not a relation-valued * attribute * @throws UnassignedDatasetException if the instance doesn't belong to a * dataset. */ @Override public final/* @pure@ */Instances relationalValue(Attribute att) { int attIndex = att.index(); if (att.isRelationValued()) { if (isMissing(attIndex)) { return null; } return att.relation((int) value(attIndex)); } else { throw new IllegalArgumentException("Attribute isn't relation-valued!"); } }
/** * Returns the relational value of a relational attribute. * * @param att the attribute * @return the corresponding relation as an Instances object, null if missing * @throws IllegalArgumentException if the attribute is not a relation-valued * attribute * @throws UnassignedDatasetException if the instance doesn't belong to a * dataset. */ @Override public final/* @pure@ */Instances relationalValue(Attribute att) { int attIndex = att.index(); if (att.isRelationValued()) { if (isMissing(attIndex)) { return null; } return att.relation((int) value(attIndex)); } else { throw new IllegalArgumentException("Attribute isn't relation-valued!"); } }
public void insertInstance(int index, boolean notify) { if (!m_IgnoreChanges) { addUndoPoint(); } double[] vals = new double[m_Data.numAttributes()]; // set any string or relational attribute values to missing // in the new instance, just in case this is the very first // instance in the dataset. for (int i = 0; i < m_Data.numAttributes(); i++) { if (m_Data.attribute(i).isString() || m_Data.attribute(i).isRelationValued()) { vals[i] = Utils.missingValue(); } } Instance toAdd = new DenseInstance(1.0, vals); if (index < 0) { m_Data.add(toAdd); } else { m_Data.add(index, toAdd); } if (notify) { notifyListener(new TableModelEvent(this, m_Data.numInstances() - 1, m_Data.numInstances() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }
public void insertInstance(int index, boolean notify) { if (!m_IgnoreChanges) { addUndoPoint(); } double[] vals = new double[m_Data.numAttributes()]; // set any string or relational attribute values to missing // in the new instance, just in case this is the very first // instance in the dataset. for (int i = 0; i < m_Data.numAttributes(); i++) { if (m_Data.attribute(i).isString() || m_Data.attribute(i).isRelationValued()) { vals[i] = Utils.missingValue(); } } Instance toAdd = new DenseInstance(1.0, vals); if (index < 0) { m_Data.add(toAdd); } else { m_Data.add(index, toAdd); } if (notify) { notifyListener(new TableModelEvent(this, m_Data.numInstances() - 1, m_Data.numInstances() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }
public void insertInstance(int index, boolean notify) { if (!m_IgnoreChanges) { addUndoPoint(); } double[] vals = new double[m_Data.numAttributes()]; // set any string or relational attribute values to missing // in the new instance, just in case this is the very first // instance in the dataset. for (int i = 0; i < m_Data.numAttributes(); i++) { if (m_Data.attribute(i).isString() || m_Data.attribute(i).isRelationValued()) { vals[i] = Utils.missingValue(); } } Instance toAdd = new DenseInstance(1.0, vals); if (index < 0) { m_Data.add(toAdd); } else { m_Data.add(index, toAdd); } if (notify) { notifyListener(new TableModelEvent(this, m_Data.numInstances() - 1, m_Data.numInstances() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }
public void insertInstance(int index, boolean notify) { if (!m_IgnoreChanges) { addUndoPoint(); } double[] vals = new double[m_Data.numAttributes()]; // set any string or relational attribute values to missing // in the new instance, just in case this is the very first // instance in the dataset. for (int i = 0; i < m_Data.numAttributes(); i++) { if (m_Data.attribute(i).isString() || m_Data.attribute(i).isRelationValued()) { vals[i] = Utils.missingValue(); } } Instance toAdd = new DenseInstance(1.0, vals); if (index < 0) { m_Data.add(toAdd); } else { m_Data.add(index, toAdd); } if (notify) { notifyListener(new TableModelEvent(this, m_Data.numInstances() - 1, m_Data.numInstances() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }
/** * tests whether we can handle data that contains NO relational attribute * at all */ public void testNoRelationalAttribute() { m_Filter = getFilter(); // delete the rel. attributes int i = 0; while (i < m_Instances.numAttributes()) { if (m_Instances.attribute(i).isRelationValued()) m_Instances.deleteAttributeAt(i); else i++; } Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); }
private Instance makeOutputInstance(Instances output, Instance source) { double[] newVals = new double[output.numAttributes()]; for (int i = 0; i < newVals.length; i++) { newVals[i] = Utils.missingValue(); } for (int i = 0; i < source.numAttributes(); i++) { if (!source.isMissing(i)) { Attribute s = source.attribute(i); int outputIndex = output.attribute(s.name()).index(); if (s.isNumeric()) { newVals[outputIndex] = source.value(s); } else if (s.isString()) { String sVal = source.stringValue(s); newVals[outputIndex] = output.attribute(outputIndex).addStringValue( sVal); } else if (s.isRelationValued()) { Instances rVal = source.relationalValue(s); newVals[outputIndex] = output.attribute(outputIndex) .addRelation(rVal); } else if (s.isNominal()) { String nomVal = source.stringValue(s); newVals[outputIndex] = output.attribute(outputIndex).indexOfValue( nomVal); } } } Instance newInst = new DenseInstance(source.weight(), newVals); newInst.setDataset(output); return newInst; }
private Instance makeOutputInstance(Instances output, Instance source) { double[] newVals = new double[output.numAttributes()]; for (int i = 0; i < newVals.length; i++) { newVals[i] = Utils.missingValue(); } for (int i = 0; i < source.numAttributes(); i++) { if (!source.isMissing(i)) { Attribute s = source.attribute(i); int outputIndex = output.attribute(s.name()).index(); if (s.isNumeric()) { newVals[outputIndex] = source.value(s); } else if (s.isString()) { String sVal = source.stringValue(s); newVals[outputIndex] = output.attribute(outputIndex).addStringValue( sVal); } else if (s.isRelationValued()) { Instances rVal = source.relationalValue(s); newVals[outputIndex] = output.attribute(outputIndex) .addRelation(rVal); } else if (s.isNominal()) { String nomVal = source.stringValue(s); newVals[outputIndex] = output.attribute(outputIndex).indexOfValue( nomVal); } } } Instance newInst = new DenseInstance(source.weight(), newVals); newInst.setDataset(output); return newInst; }