Java Code Examples for weka.core.Attribute#RELATIONAL

The following examples show how to use weka.core.Attribute#RELATIONAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataTable.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * returns the cell editor for the given cell
 *
 * @param row the row index
 * @param column the column index
 * @return the cell editor
 */
@Override
public TableCellEditor getCellEditor(int row, int column) {
	TableCellEditor result;

	// relational attribute?
	if ((getModel() instanceof DataSortedTableModel)
		&& (((DataSortedTableModel) getModel()).getType(column) == Attribute.RELATIONAL)) {
		result = new RelationalCellEditor(row, column);
		// default
	} else {
		result = super.getCellEditor(row, column);
	}

	return result;
}
 
Example 2
Source File: MultiInstanceToPropositional.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the format of the input instances.
 *
 * @param instanceInfo an Instances object containing the input 
 * instance structure (any instances contained in the object are 
 * ignored - only the structure is required).
 * @return true if the outputFormat may be collected immediately
 * @throws Exception if the input format can't be set 
 * successfully
 */
public boolean setInputFormat(Instances instanceInfo) 
  throws Exception {

  if (instanceInfo.attribute(1).type()!=Attribute.RELATIONAL) {
    throw new Exception("Can only handle relational-valued attribute!");
  }  
  super.setInputFormat(instanceInfo);   

  m_NumBags = instanceInfo.numInstances();
  m_NumInstances = 0;
  for (int i=0; i<m_NumBags; i++)
    m_NumInstances += instanceInfo.instance(i).relationalValue(1).numInstances();

  Attribute classAttribute = (Attribute) instanceInfo.classAttribute().copy();
  Attribute bagIndex = (Attribute) instanceInfo.attribute(0).copy();

  /* create a new output format (propositional instance format) */
  Instances newData = instanceInfo.attribute(1).relation().stringFreeStructure();
  newData.insertAttributeAt(bagIndex, 0);
  newData.insertAttributeAt(classAttribute, newData.numAttributes());
  newData.setClassIndex(newData.numAttributes() - 1);

  super.setOutputFormat(newData.stringFreeStructure());

  m_BagStringAtts = new StringLocator(instanceInfo.attribute(1).relation().stringFreeStructure());
  m_BagRelAtts    = new RelationalLocator(instanceInfo.attribute(1).relation().stringFreeStructure());

  return true;
}
 
Example 3
Source File: RemoveType.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the attribute type to be deleted by the filter as a string.
 *
 * @return the attribute type as a String
 */
protected String getAttributeTypeString() {

  if (m_attTypeToDelete == Attribute.NOMINAL) return "nominal";
  else if (m_attTypeToDelete == Attribute.NUMERIC) return "numeric";
  else if (m_attTypeToDelete == Attribute.STRING) return "string";
  else if (m_attTypeToDelete == Attribute.DATE) return "date";
  else if (m_attTypeToDelete == Attribute.RELATIONAL) return "relational";
  else return "unknown";
}
 
Example 4
Source File: RemoveType.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the attribute type to be deleted by the filter.
 *
 * @param typeString a String representing the new type the filter should delete
 */
protected void setAttributeTypeString(String typeString) {

  typeString = typeString.toLowerCase();
  if (typeString.equals("nominal")) m_attTypeToDelete = Attribute.NOMINAL;
  else if (typeString.equals("numeric")) m_attTypeToDelete = Attribute.NUMERIC;
  else if (typeString.equals("string")) m_attTypeToDelete = Attribute.STRING;
  else if (typeString.equals("date")) m_attTypeToDelete = Attribute.DATE;
  else if (typeString.equals("relational")) m_attTypeToDelete = Attribute.RELATIONAL;
}
 
Example 5
Source File: CheckEstimator.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
AttrTypes (int type) {
  if (type == Attribute.NOMINAL) nominal = true;
  if (type == Attribute.NUMERIC) numeric = true;
  if (type == Attribute.STRING) string = true;
  if (type == Attribute.DATE) date = true;
  if (type == Attribute.RELATIONAL) relational = true;
}
 
Example 6
Source File: CheckEstimator.java    From tsml with GNU General Public License v3.0 5 votes vote down vote up
int getSetType() throws Exception {			
     int sum = 0;
     int type = -1;
     if (nominal) { sum ++; type = Attribute.NOMINAL; }
     if (numeric) { sum ++; type = Attribute.NUMERIC; }
     if (string) { sum ++; type = Attribute.STRING; }
     if (date) { sum ++; type = Attribute.DATE; }
     if (relational) { sum ++; type = Attribute.RELATIONAL; }
     if (sum > 1)
throw new Exception("Expected to have only one type set used wrongly.");
     if (type < 0)
throw new Exception("No type set.");
     return type;
   }
 
Example 7
Source File: CheckAssociator.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Print out a short summary string for the dataset characteristics
 *
 * @param nominalPredictor true if nominal predictor attributes are present
 * @param numericPredictor true if numeric predictor attributes are present
 * @param stringPredictor true if string predictor attributes are present
 * @param datePredictor true if date predictor attributes are present
 * @param relationalPredictor true if relational predictor attributes are present
 * @param multiInstance whether multi-instance is needed
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 */
protected void printAttributeSummary(boolean nominalPredictor, 
                                     boolean numericPredictor, 
                                     boolean stringPredictor, 
                                     boolean datePredictor, 
                                     boolean relationalPredictor, 
                                     boolean multiInstance,
                                     int classType) {
  
  String str = "";

  if (numericPredictor)
    str += " numeric";
  
  if (nominalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " nominal";
  }
  
  if (stringPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " string";
  }
  
  if (datePredictor) {
    if (str.length() > 0)
      str += " &";
    str += " date";
  }
  
  if (relationalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " relational";
  }
  
  str += " predictors)";
  
  switch (classType) {
    case Attribute.NUMERIC:
      str = " (numeric class," + str;
      break;
    case Attribute.NOMINAL:
      str = " (nominal class," + str;
      break;
    case Attribute.STRING:
      str = " (string class," + str;
      break;
    case Attribute.DATE:
      str = " (date class," + str;
      break;
    case Attribute.RELATIONAL:
      str = " (relational class," + str;
      break;
    case NO_CLASS:
      str = " (no class," + str;
      break;
  }
  
  print(str);
}
 
Example 8
Source File: CheckAttributeSelection.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Print out a short summary string for the dataset characteristics
 *
 * @param nominalPredictor true if nominal predictor attributes are present
 * @param numericPredictor true if numeric predictor attributes are present
 * @param stringPredictor true if string predictor attributes are present
 * @param datePredictor true if date predictor attributes are present
 * @param relationalPredictor true if relational predictor attributes are present
 * @param multiInstance whether multi-instance is needed
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 */
protected void printAttributeSummary(boolean nominalPredictor, 
                                     boolean numericPredictor, 
                                     boolean stringPredictor, 
                                     boolean datePredictor, 
                                     boolean relationalPredictor, 
                                     boolean multiInstance,
                                     int classType) {
  
  String str = "";

  if (numericPredictor)
    str += " numeric";
  
  if (nominalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " nominal";
  }
  
  if (stringPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " string";
  }
  
  if (datePredictor) {
    if (str.length() > 0)
      str += " &";
    str += " date";
  }
  
  if (relationalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " relational";
  }
  
  str += " predictors)";
  
  switch (classType) {
    case Attribute.NUMERIC:
      str = " (numeric class," + str;
      break;
    case Attribute.NOMINAL:
      str = " (nominal class," + str;
      break;
    case Attribute.STRING:
      str = " (string class," + str;
      break;
    case Attribute.DATE:
      str = " (date class," + str;
      break;
    case Attribute.RELATIONAL:
      str = " (relational class," + str;
      break;
  }
  
  print(str);
}
 
Example 9
Source File: CheckClassifier.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Print out a short summary string for the dataset characteristics
 *
 * @param nominalPredictor true if nominal predictor attributes are present
 * @param numericPredictor true if numeric predictor attributes are present
 * @param stringPredictor true if string predictor attributes are present
 * @param datePredictor true if date predictor attributes are present
 * @param relationalPredictor true if relational predictor attributes are present
 * @param multiInstance whether multi-instance is needed
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 */
protected void printAttributeSummary(boolean nominalPredictor,
                                     boolean numericPredictor,
                                     boolean stringPredictor,
                                     boolean datePredictor,
                                     boolean relationalPredictor,
                                     boolean multiInstance,
                                     int classType) {

  String str = "";

  if (numericPredictor)
    str += " numeric";

  if (nominalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " nominal";
  }

  if (stringPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " string";
  }

  if (datePredictor) {
    if (str.length() > 0)
      str += " &";
    str += " date";
  }

  if (relationalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " relational";
  }

  str += " predictors)";

  switch (classType) {
    case Attribute.NUMERIC:
      str = " (numeric class," + str;
      break;
    case Attribute.NOMINAL:
      str = " (nominal class," + str;
      break;
    case Attribute.STRING:
      str = " (string class," + str;
      break;
    case Attribute.DATE:
      str = " (date class," + str;
      break;
    case Attribute.RELATIONAL:
      str = " (relational class," + str;
      break;
  }

  print(str);
}
 
Example 10
Source File: CheckKernel.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Print out a short summary string for the dataset characteristics
 *
 * @param nominalPredictor true if nominal predictor attributes are present
 * @param numericPredictor true if numeric predictor attributes are present
 * @param stringPredictor true if string predictor attributes are present
 * @param datePredictor true if date predictor attributes are present
 * @param relationalPredictor true if relational predictor attributes are present
 * @param multiInstance whether multi-instance is needed
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 */
protected void printAttributeSummary(boolean nominalPredictor, 
                                     boolean numericPredictor, 
                                     boolean stringPredictor, 
                                     boolean datePredictor, 
                                     boolean relationalPredictor, 
                                     boolean multiInstance,
                                     int classType) {
  
  String str = "";

  if (numericPredictor)
    str += " numeric";
  
  if (nominalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " nominal";
  }
  
  if (stringPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " string";
  }
  
  if (datePredictor) {
    if (str.length() > 0)
      str += " &";
    str += " date";
  }
  
  if (relationalPredictor) {
    if (str.length() > 0)
      str += " &";
    str += " relational";
  }
  
  str += " predictors)";
  
  switch (classType) {
    case Attribute.NUMERIC:
      str = " (numeric class," + str;
      break;
    case Attribute.NOMINAL:
      str = " (nominal class," + str;
      break;
    case Attribute.STRING:
      str = " (string class," + str;
      break;
    case Attribute.DATE:
      str = " (date class," + str;
      break;
    case Attribute.RELATIONAL:
      str = " (relational class," + str;
      break;
  }
  
  print(str);
}
 
Example 11
Source File: XMLInstances.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
  * adds the attribute to the XML structure
  * 
  * @param parent	the parent node to add the attribute node as child
  * @param att		the attribute to add
  */
 protected void addAttribute(Element parent, Attribute att) {
   Element		node;
   Element		child;
   Element		property;
   Element		label;
   String		tmpStr;
   Enumeration		enm;
   int			i;
   
   node = m_Document.createElement(TAG_ATTRIBUTE);
   parent.appendChild(node);
   
   // XML attributes
   // name
   node.setAttribute(ATT_NAME, validContent(att.name()));
   
   // type
   switch (att.type()) {
     case Attribute.NUMERIC:
node.setAttribute(ATT_TYPE, VAL_NUMERIC);
break;

     case Attribute.DATE:
node.setAttribute(ATT_TYPE, VAL_DATE);
break;

     case Attribute.NOMINAL:
node.setAttribute(ATT_TYPE, VAL_NOMINAL);
break;

     case Attribute.STRING:
node.setAttribute(ATT_TYPE, VAL_STRING);
break;

     case Attribute.RELATIONAL:
node.setAttribute(ATT_TYPE, VAL_RELATIONAL);
break;

     default:
node.setAttribute(ATT_TYPE, "???");
   }
   
   // labels
   if (att.isNominal()) {
     child = m_Document.createElement(TAG_LABELS);
     node.appendChild(child);
     enm = att.enumerateValues();
     while (enm.hasMoreElements()) {
tmpStr = enm.nextElement().toString();
label = m_Document.createElement(TAG_LABEL);
child.appendChild(label);
label.appendChild(m_Document.createTextNode(validContent(tmpStr)));
     }
   }
   
   // format
   if (att.isDate())
     node.setAttribute(ATT_FORMAT, validContent(att.getDateFormat()));
   
   // class
   if (m_Instances.classIndex() > -1) {
     if (att == m_Instances.classAttribute())
node.setAttribute(ATT_CLASS, VAL_YES);
   }
   
   // add meta-data
   if ( (att.getMetadata() != null) && (att.getMetadata().size() > 0) ) {
     child = m_Document.createElement(TAG_METADATA);
     node.appendChild(child);
     enm = att.getMetadata().propertyNames();
     while (enm.hasMoreElements()) {
tmpStr = enm.nextElement().toString();
property = m_Document.createElement(TAG_PROPERTY);
child.appendChild(property);
property.setAttribute(ATT_NAME, validContent(tmpStr));
property.appendChild(m_Document.createTextNode(validContent(att.getMetadata().getProperty(tmpStr, ""))));
     }
   }
   
   // relational attribute?
   if (att.isRelationValued()) {
     child = m_Document.createElement(TAG_ATTRIBUTES);
     node.appendChild(child);
     for (i = 0; i < att.relation().numAttributes(); i++)
addAttribute(child, att.relation().attribute(i));
   }
 }
 
Example 12
Source File: CheckEstimator.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Print out a short summary string for the dataset characteristics
 *
 * @param attrTypes the attribute types used (NUMERIC, NOMINAL, etc.)
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 */
protected void printAttributeSummary(AttrTypes attrTypes, int classType) {
  
  String str = "";
  
  if (attrTypes.numeric)
    str += " numeric";
  
  if (attrTypes.nominal) {
    if (str.length() > 0)
      str += " &";
    str += " nominal";
  }
  
  if (attrTypes.string) {
    if (str.length() > 0)
      str += " &";
    str += " string";
  }
  
  if (attrTypes.date) {
    if (str.length() > 0)
      str += " &";
    str += " date";
  }
  
  if (attrTypes.relational) {
    if (str.length() > 0)
      str += " &";
    str += " relational";
  }
  
  str += " attributes)";
  
  switch (classType) {
    case Attribute.NUMERIC:
      str = " (numeric class," + str;
      break;
    case Attribute.NOMINAL:
      str = " (nominal class," + str;
      break;
    case Attribute.STRING:
      str = " (string class," + str;
      break;
    case Attribute.DATE:
      str = " (date class," + str;
      break;
    case Attribute.RELATIONAL:
      str = " (relational class," + str;
      break;
  }
  
  print(str);
}
 
Example 13
Source File: CheckEstimator.java    From tsml with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Print out a short summary string for the dataset characteristics
 *
 * @param attrType the attribute type (NUMERIC, NOMINAL, etc.)
 * @param classType the class type (NUMERIC, NOMINAL, etc.)
 */
protected void printAttributeSummary(int attrType, int classType) {
  
  String str = "";
  
  switch (attrType) {
  case Attribute.NUMERIC:
    str = " numeric" + str;
    break;
  case Attribute.NOMINAL:
    str = " nominal" + str;
    break;
  case Attribute.STRING:
    str = " string" + str;
    break;
  case Attribute.DATE:
    str = " date" + str;
    break;
  case Attribute.RELATIONAL:
    str = " relational" + str;
    break;
  }
  str += " attribute(s))";
  
  switch (classType) {
  case Attribute.NUMERIC:
    str = " (numeric class," + str;
    break;
  case Attribute.NOMINAL:
    str = " (nominal class," + str;
    break;
  case Attribute.STRING:
    str = " (string class," + str;
    break;
  case Attribute.DATE:
    str = " (date class," + str;
    break;
  case Attribute.RELATIONAL:
    str = " (relational class," + str;
    break;
  }
  
  print(str);
}
 
Example 14
Source File: CollectiveClassifierPanel.java    From collective-classification-weka-package with GNU General Public License v3.0 4 votes vote down vote up
/**
  * Tells the panel to use a new set of instances.
  *
  * @param inst 	a set of Instances
  */
 public void setInstances(Instances inst) {
   m_Instances = inst;

   String[] attribNames = new String [m_Instances.numAttributes()];
   for (int i = 0; i < attribNames.length; i++) {
     String type = "";
     switch (m_Instances.attribute(i).type()) {
     case Attribute.NOMINAL:
type = "(Nom) ";
break;
     case Attribute.NUMERIC:
type = "(Num) ";
break;
     case Attribute.STRING:
type = "(Str) ";
break;
     case Attribute.DATE:
type = "(Dat) ";
break;
     case Attribute.RELATIONAL:
type = "(Rel) ";
break;
     default:
type = "(???) ";
     }
     attribNames[i] = type + m_Instances.attribute(i).name();
   }
   m_ClassCombo.setModel(new DefaultComboBoxModel(attribNames));
   if (attribNames.length > 0) {
     if (inst.classIndex() == -1)
m_ClassCombo.setSelectedIndex(attribNames.length - 1);
     else
m_ClassCombo.setSelectedIndex(inst.classIndex());
     m_EvalCombo.setEnabled(true);
     m_ClassCombo.setEnabled(true);
     m_CVPanel.setEnabled(true);
     m_SplitPanel.setEnabled(true);
     m_TestPanel.setEnabled(true);
     m_StartBut.setEnabled(m_RunThread == null);
     m_StopBut.setEnabled(m_RunThread != null);
   }
   else {
     m_StartBut.setEnabled(false);
     m_StopBut.setEnabled(false);
   }
 }
 
Example 15
Source File: DataTableModel.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * returns the name of the column at columnIndex
 *
 * @param columnIndex the index of the column
 * @return the name of the column
 */
@Override
public String getColumnName(int columnIndex) {
	String result;

	result = "";

	if ((columnIndex >= 0) && (columnIndex < getColumnCount())) {
		if (columnIndex == 0) {
			result =
				"<html><center>No.<br><font size=\"-2\">&nbsp;</font></center></html>";
		} else {
			if (m_Data != null) {
				if ((columnIndex - 1 < m_Data.numAttributes())) {
					result = "<html><center>";

					// index
					if (m_ShowAttributeIndex) {
						result += columnIndex + ": ";
					}

					// name
					if (isClassIndex(columnIndex)) {
						result +=
							"<b>" + m_Data.attribute(columnIndex - 1).name() + "</b>";
					} else {
						result += m_Data.attribute(columnIndex - 1).name();
					}

					// attribute type
					switch (getType(columnIndex)) {
						case Attribute.DATE:
							result += "<br><font size=\"-2\">Date</font>";
							break;
						case Attribute.NOMINAL:
							result += "<br><font size=\"-2\">Nominal</font>";
							break;
						case Attribute.STRING:
							result += "<br><font size=\"-2\">String</font>";
							break;
						case Attribute.NUMERIC:
							result += "<br><font size=\"-2\">Numeric</font>";
							break;
						case Attribute.RELATIONAL:
							result += "<br><font size=\"-2\">Relational</font>";
							break;
						default:
							result += "<br><font size=\"-2\">???</font>";
					}

					result += "</center></html>";
				}
			}
		}
	}

	return result;
}
 
Example 16
Source File: DataTableModel.java    From meka with GNU General Public License v3.0 4 votes vote down vote up
/**
 * returns the value for the cell at columnindex and rowIndex
 *
 * @param rowIndex the row index
 * @param columnIndex the column index
 * @return the value at the position
 */
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
	Object result;
	String tmp;
	String key;
	boolean modified;

	result = null;
	key = rowIndex + "-" + columnIndex;

	if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex >= 0)
		&& (columnIndex < getColumnCount())) {
		if (columnIndex == 0) {
			result = new Integer(rowIndex + 1);
		} else {
			if (isMissingAt(rowIndex, columnIndex)) {
				result = null;
			} else {
				if (m_Cache.containsKey(key)) {
					result = m_Cache.get(key);
				} else {
					switch (getType(columnIndex)) {
						case Attribute.DATE:
						case Attribute.NOMINAL:
						case Attribute.STRING:
						case Attribute.RELATIONAL:
							result = m_Data.instance(rowIndex).stringValue(columnIndex - 1);
							break;
						case Attribute.NUMERIC:
							result =
								new Double(m_Data.instance(rowIndex).value(columnIndex - 1));
							break;
						default:
							result = "-can't display-";
					}

					if (getType(columnIndex) != Attribute.NUMERIC) {
						if (result != null) {
							tmp = result.toString();
							modified = false;
							// fix html tags, otherwise Java parser hangs
							if ((tmp.indexOf('<') > -1) || (tmp.indexOf('>') > -1)) {
								tmp = tmp.replace("<", "(");
								tmp = tmp.replace(">", ")");
								modified = true;
							}
							// does it contain "\n" or "\r"? -> replace with red html tag
							if ((tmp.indexOf("\n") > -1) || (tmp.indexOf("\r") > -1)) {
								tmp =
									tmp.replaceAll("\\r\\n",
										"<font color=\"red\"><b>\\\\r\\\\n</b></font>");
								tmp =
									tmp.replaceAll("\\r",
										"<font color=\"red\"><b>\\\\r</b></font>");
								tmp =
									tmp.replaceAll("\\n",
										"<font color=\"red\"><b>\\\\n</b></font>");
								tmp = "<html>" + tmp + "</html>";
								modified = true;
							}
							result = tmp;
							if (modified) {
								m_Cache.put(key, tmp);
							}
						}
					}
				}
			}
		}
	}

	return result;
}