Package weka.core

Examples of weka.core.Attribute

Typical usage (code from the main() method of this class):

...
// Create numeric attributes "length" and "weight"
Attribute length = new Attribute("length");
Attribute weight = new Attribute("weight");

// Create list to hold nominal values "first", "second", "third"
List my_nominal_values = new ArrayList(3);
my_nominal_values.add("first");
my_nominal_values.add("second");
my_nominal_values.add("third");

// Create nominal attribute "position"
Attribute position = new Attribute("position", my_nominal_values);
...

@author Eibe Frank (eibe@cs.waikato.ac.nz) @version $Revision: 6889 $


  private void checkSkipEnabledStatus() {
    boolean enable = false;
    if (m_instances != null) {
      if (m_timeStampCombo.getSelectedItem() != null) {
        String timeName = m_timeStampCombo.getSelectedItem().toString();
        Attribute timeAtt = m_instances.attribute(timeName);
        if (timeAtt != null) {
          if (m_periodicityCombo.getSelectedItem() != null) {
            String periodicity = m_periodicityCombo.getSelectedItem()
                .toString();
            enable = (timeAtt.isDate() && !periodicity.equals("<Unknown>") && !periodicity
                .equals("<Detect automatically>"));
          }
        }
      }
    }
View Full Code Here


    // update instances
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      values.addElement("Value" + (iValue + 1));
    }
    Attribute att = new Attribute(sName, values);
    m_Instances.insertAttributeAt(att, m_Instances.numAttributes());
    int nAtts = m_Instances.numAttributes();
    // update parentsets
    ParentSet[] parentSets = new ParentSet[nAtts];
    for (int iParentSet = 0; iParentSet < nAtts - 1; iParentSet++) {
View Full Code Here

      while (getNode2(sNodeName) >= 0) {
        sNodeName = "Copy (" + iAttempt + ") of " + sBaseName;
        iAttempt++;
      }

      Attribute att = new Attribute(sNodeName, nomStrings);
      instances.insertAttributeAt(att, instances.numAttributes());

      valueslist = selectElements(nodelist.item(iNode), "PROPERTY");
      nValues = valueslist.size();
      // generate value strings
View Full Code Here

  public void setNodeName(int nTargetNode, String sName) {
    // update undo stack
    if (m_bNeedsUndoAction) {
      addUndoAction(new RenameAction(nTargetNode, getNodeName(nTargetNode), sName));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      values.addElement(att.value(iValue));
    }
    replaceAtt(nTargetNode, sName, values);
  } // setNodeName
View Full Code Here

  public void renameNodeValue(int nTargetNode, String sValue, String sNewValue) {
    // update undo stack
    if (m_bNeedsUndoAction) {
      addUndoAction(new RenameValueAction(nTargetNode, sValue, sNewValue));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      if (att.value(iValue).equals(sValue)) {
        values.addElement(sNewValue);
      } else {
        values.addElement(att.value(iValue));
      }
    }
    replaceAtt(nTargetNode, att.name(), values);
  } // renameNodeValue
View Full Code Here

  public void addNodeValue(int nTargetNode, String sNewValue) {
    // update undo stack
    if (m_bNeedsUndoAction) {
      addUndoAction(new AddValueAction(nTargetNode, sNewValue));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      values.addElement(att.value(iValue));
    }
    values.addElement(sNewValue);
    replaceAtt(nTargetNode, att.name(), values);

    // update distributions of this node
    Estimator[] distributions = m_Distributions[nTargetNode];
    int nNewCard = values.size();
    for (int iParent = 0; iParent < distributions.length; iParent++) {
View Full Code Here

  public void delNodeValue(int nTargetNode, String sValue) throws Exception {
    // update undo stack
    if (m_bNeedsUndoAction) {
      addUndoAction(new DelValueAction(nTargetNode, sValue));
    }
    Attribute att = m_Instances.attribute(nTargetNode);
    int nCardinality = att.numValues();
    FastVector values = new FastVector(nCardinality);
    int nValue = -1;
    for (int iValue = 0; iValue < nCardinality; iValue++) {
      if (att.value(iValue).equals(sValue)) {
        nValue = iValue;
      } else {
        values.addElement(att.value(iValue));
      }
    }
    if (nValue < 0) {
      // could not find value
      throw new Exception("Node " + nTargetNode + " does not have value (" + sValue + ")");
    }
    replaceAtt(nTargetNode, att.name(), values);

    // update distributions
    Estimator[] distributions = m_Distributions[nTargetNode];
    int nCard = values.size();
    for (int iParent = 0; iParent < distributions.length; iParent++) {
View Full Code Here

   * @param nTargetNode index of node the replace specification for
   * @param sName new name of the node
   * @param values array of values of the node
   */
  void replaceAtt(int nTargetNode, String sName, FastVector values) {
    Attribute newAtt = new Attribute(sName, values);
    if (m_Instances.classIndex() == nTargetNode) {
      m_Instances.setClassIndex(-1);
      m_Instances.insertAttributeAt(newAtt, nTargetNode);
      m_Instances.deleteAttributeAt(nTargetNode + 1);
      m_Instances.setClassIndex(nTargetNode);
View Full Code Here

        }
    }

    private Instances initializeDataSet(int numFeatures, int neededCapacity) {
        FastVector fvAllAttributes = new FastVector(numFeatures + 1);
        Attribute tempAtt;
        for (int i = 0; i < numFeatures; i++) {
            tempAtt = new Attribute("att" + i);
            fvAllAttributes.addElement(tempAtt);
        }
        FastVector fvClassVal = new FastVector(2);
        fvClassVal.addElement("positive");
        fvClassVal.addElement("negative");
        Attribute ClassAttribute = new Attribute("theClass", fvClassVal);
        fvAllAttributes.addElement(ClassAttribute);
        // Create an empty training set
        Instances emptySet = new Instances("dataSet", fvAllAttributes, neededCapacity);
        emptySet.setClassIndex(numFeatures);
        return emptySet;
View Full Code Here

  public Instance getInstance(OWLOntology ontology, Query query){
    List<String> featureList = getFeatures(ontology, query);
    Instance instance = new Instance(featureList.size() + 1);
    instance.setDataset(dataSet);
    for(int i = 0; i < featureList.size(); i ++){
      Attribute attr = instance.attribute(i);
      if(attr.isNumeric()){
        instance.setValue(i, Double.valueOf(featureList.get(i)));
      }else{
        instance.setValue(i, featureList.get(i));
      }
    }
View Full Code Here

TOP

Related Classes of weka.core.Attribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.