Java Code Examples for weka.core.Attribute#STRING
The following examples show how to use
weka.core.Attribute#STRING .
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: StringKernel.java From tsml with GNU General Public License v3.0 | 6 votes |
/** * initializes variables etc. * * @param data the data to use */ protected void initVars(Instances data) { super.initVars(data); m_kernelEvals = 0; // take the first string attribute m_strAttr = -1; for (int i = 0; i < data.numAttributes(); i++) { if (i == data.classIndex()) continue; if (data.attribute(i).type() == Attribute.STRING) { m_strAttr = i; break; } } m_numInsts = m_data.numInstances(); m_storage = new double[m_cacheSize]; m_keys = new long[m_cacheSize]; m_powersOflambda = calculatePowersOfLambda(); }
Example 2
Source File: RemoveType.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * 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 3
Source File: RemoveType.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * 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 4
Source File: CheckEstimator.java From tsml with GNU General Public License v3.0 | 5 votes |
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 5
Source File: CheckEstimator.java From tsml with GNU General Public License v3.0 | 5 votes |
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 6
Source File: DataTableModel.java From meka with GNU General Public License v3.0 | 5 votes |
/** * returns the TYPE of the attribute at the given position * * @param rowIndex the index of the row * @param columnIndex the index of the column * @return the attribute type */ public int getType(int rowIndex, int columnIndex) { int result; result = Attribute.STRING; if ((rowIndex < 0) && columnIndex > 0 && columnIndex < getColumnCount()) { result = m_Data.attribute(columnIndex - 1).type(); } else if ((rowIndex >= 0) && (rowIndex < getRowCount()) && (columnIndex > 0) && (columnIndex < getColumnCount())) { result = m_Data.instance(rowIndex).attribute(columnIndex - 1).type(); } return result; }
Example 7
Source File: CheckAssociator.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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\"> </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 |
/** * 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; }