Package org.integratedmodelling.riskwiz.learning.data

Examples of org.integratedmodelling.riskwiz.learning.data.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 vector to hold nominal values "first", "second", "third"
FastVector my_nominal_values = new FastVector(3);
my_nominal_values.addElement("first");
my_nominal_values.addElement("second");
my_nominal_values.addElement("third");

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

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


                                || m_Tokenizer.sval.equalsIgnoreCase(
                                        Attribute.ARFF_ATTRIBUTE_INTEGER)
                                        || m_Tokenizer.sval.equalsIgnoreCase(
                                                Attribute.ARFF_ATTRIBUTE_NUMERIC)) {
                    attributes.addElement(
                            new Attribute(attributeName, attributes.size()));
                    readTillEOL();
                } else if (m_Tokenizer.sval.equalsIgnoreCase(
                        Attribute.ARFF_ATTRIBUTE_STRING)) {
                    attributes.addElement(
                            new Attribute(attributeName, (FastVector) null,
                            attributes.size()));
                    readTillEOL();
                } else if (m_Tokenizer.sval.equalsIgnoreCase(
                        Attribute.ARFF_ATTRIBUTE_DATE)) {
                    String format = null;

                    if (m_Tokenizer.nextToken() != StreamTokenizer.TT_EOL) {
                        if ((m_Tokenizer.ttype != StreamTokenizer.TT_WORD)
                                && (m_Tokenizer.ttype != '\'')
                                && (m_Tokenizer.ttype != '\"')) {
                            errorMessage("not a valid date format");
                        }
                        format = m_Tokenizer.sval;
                        readTillEOL();
                    } else {
                        m_Tokenizer.pushBack();
                    }
                    attributes.addElement(
                            new Attribute(attributeName, format,
                            attributes.size()));
         
                } else if (m_Tokenizer.sval.equalsIgnoreCase(
                        Attribute.ARFF_ATTRIBUTE_RELATIONAL)) {
                    readTillEOL();
         
                    // Read attributes for subrelation
                    // First, save current set of attributes
                    FastVector atts = attributes;

                    attributes = new FastVector();
         
                    // Now, read attributes until we hit end of declaration of relational value
                    getFirstToken();
                    if (m_Tokenizer.ttype == StreamTokenizer.TT_EOF) {
                        errorMessage("premature end of file");
                    }
                    do {
                        if (Attribute.ARFF_ATTRIBUTE.equalsIgnoreCase(
                                m_Tokenizer.sval)) {
                            attributes = parseAttribute(attributes);
                        } else if (Attribute.ARFF_END_SUBRELATION.equalsIgnoreCase(
                                m_Tokenizer.sval)) {
                            getNextToken();
                            if (!attributeName.equalsIgnoreCase(m_Tokenizer.sval)) {
                                errorMessage(
                                        "declaration of subrelation "
                                                + attributeName
                                                + " must be terminated by "
                                                + "@end " + attributeName);
                            }
                            break;
                        } else {
                            errorMessage(
                                    "declaration of subrelation "
                                            + attributeName
                                            + " must be terminated by "
                                            + "@end " + attributeName);
                        }
                    } while (true);
         
                    // Make relation and restore original set of attributes
                    Instances relation = new Instances(attributeName, attributes,
                            0);

                    attributes = atts;
                    attributes.addElement(
                            new Attribute(attributeName, relation,
                            attributes.size()));
                } else {
                    errorMessage(
                            "no valid attribute type or invalid "
                                    + "enumeration");
                }
            } else {
       
                // Attribute is nominal.
                attributeValues = new FastVector();
                m_Tokenizer.pushBack();
       
                // Get values for nominal attribute.
                if (m_Tokenizer.nextToken() != '{') {
                    errorMessage("{ expected at beginning of enumeration");
                }
                while (m_Tokenizer.nextToken() != '}') {
                    if (m_Tokenizer.ttype == StreamTokenizer.TT_EOL) {
                        errorMessage("} expected at end of enumeration");
                    } else {
                        attributeValues.addElement(m_Tokenizer.sval);
                    }
                }
                attributes.addElement(
                        new Attribute(attributeName, attributeValues,
                        attributes.size()));
            }
            getLastToken(false);
            getFirstToken();
            if (m_Tokenizer.ttype == StreamTokenizer.TT_EOF) {
View Full Code Here


                    String attribName = md.getColumnName(i + 1);

                    switch (attributeTypes[i]) {
                    case Attribute.NOMINAL:
                        attribInfo.addElement(
                                new Attribute(attribName, m_nominalStrings[i]));
                        break;

                    case Attribute.NUMERIC:
                        attribInfo.addElement(new Attribute(attribName));
                        break;

                    case Attribute.STRING:
                        Attribute att = new Attribute(attribName,
                                (FastVector) null);

                        for (int n = 0; n < m_nominalStrings[i].size(); n++) {
                            att.addStringValue(
                                    (String) m_nominalStrings[i].elementAt(n));
                        }
                        attribInfo.addElement(att);
                        break;

                    case Attribute.DATE:
                        attribInfo.addElement(
                                new Attribute(attribName, (String) null));
                        break;

                    default:
                        throw new IOException("Unknown attribute type");
                    }
View Full Code Here

                String attribName = md.getColumnName(i + 1);

                switch (attributeTypes[i]) {
                case Attribute.NOMINAL:
                    attribInfo.addElement(
                            new Attribute(attribName, m_nominalStrings[i]));
                    break;

                case Attribute.NUMERIC:
                    attribInfo.addElement(new Attribute(attribName));
                    break;

                case Attribute.STRING:
                    Attribute att = new Attribute(attribName, (FastVector) null);

                    attribInfo.addElement(att);
                    for (int n = 0; n < m_nominalStrings[i].size(); n++) {
                        att.addStringValue(
                                (String) m_nominalStrings[i].elementAt(n));
                    }
                    break;

                case Attribute.DATE:
                    attribInfo.addElement(
                            new Attribute(attribName, (String) null));
                    break;

                default:
                    throw new IOException("Unknown attribute type");
                }
View Full Code Here

     */
    protected Attribute createAttribute(Element node) throws Exception {
        String    typeStr;
        String    name;
        int      type;
        Attribute    result;
        FastVector    values;
        ProtectedProperties  metadata;
        Vector    list;
        FastVector    atts;
   
        result = null;
   
        // name
        name = node.getAttribute(ATT_NAME);

        // type
        typeStr = node.getAttribute(ATT_TYPE);
        if (typeStr.equals(VAL_NUMERIC)) {
            type = Attribute.NUMERIC;
        } else if (typeStr.equals(VAL_DATE)) {
            type = Attribute.DATE;
        } else if (typeStr.equals(VAL_NOMINAL)) {
            type = Attribute.NOMINAL;
        } else if (typeStr.equals(VAL_STRING)) {
            type = Attribute.STRING;
        } else if (typeStr.equals(VAL_RELATIONAL)) {
            type = Attribute.RELATIONAL;
        } else {
            throw new Exception(
                    "Attribute type '" + typeStr + "' is not supported!");
        }

        // metadata
        metadata = createMetadata(node);
   
        switch (type) {
        case Attribute.NUMERIC:
            if (metadata == null) {
                result = new Attribute(name);
            } else {
                result = new Attribute(name, metadata);
            }
            break;

        case Attribute.DATE:
            if (metadata == null) {
                result = new Attribute(name, node.getAttribute(ATT_FORMAT));
            } else {
                result = new Attribute(name, node.getAttribute(ATT_FORMAT),
                        metadata);
            }
            break;
 
        case Attribute.NOMINAL:
            values = createLabels(node);
            if (metadata == null) {
                result = new Attribute(name, values);
            } else {
                result = new Attribute(name, values, metadata);
            }
            break;
 
        case Attribute.STRING:
            if (metadata == null) {
                result = new Attribute(name, (FastVector) null);
            } else {
                result = new Attribute(name, (FastVector) null, metadata);
            }
            break;
 
        case Attribute.RELATIONAL:
            list = getChildTags(node, TAG_ATTRIBUTES);
            node = (Element) list.get(0);
            atts = createAttributes(node, new int[1]);
            if (metadata == null) {
                result = new Attribute(name, new Instances(name, atts, 0));
            } else {
                result = new Attribute(name, new Instances(name, atts, 0),
                        metadata);
            }
            break;
        }
   
View Full Code Here

    protected FastVector createAttributes(Element parent, int[] classIndex) throws Exception {
        Vector  list;
        FastVector  result;
        int    i;
        Element  node;
        Attribute  att;

        result = new FastVector();
        classIndex[0] = -1;
   
        list = getChildTags(parent, TAG_ATTRIBUTE);
View Full Code Here

        for (int i = 0; i < m_structure.numAttributes(); i++) {
            String attname = m_structure.attribute(i).name();
            Hashtable tempHash = ((Hashtable) m_cumulativeStructure.elementAt(i));

            if (tempHash.size() == 0) {
                atts.addElement(new Attribute(attname));
            } else {
                FastVector values = new FastVector(tempHash.size());

                // add dummy objects in order to make the FastVector's size == capacity
                for (int z = 0; z < tempHash.size(); z++) {
                    values.addElement("dummy");
                }
                Enumeration e = tempHash.keys();

                while (e.hasMoreElements()) {
                    Object ob = e.nextElement();
                    // if (ob instanceof Double) {
                    int index = ((Integer) tempHash.get(ob)).intValue();

                    values.setElementAt(new String(ob.toString()), index);
                    // }
                }
                atts.addElement(new Attribute(attname, values));
            }
        }

        // make the instances
        String relationName;
View Full Code Here

        if (tokenizer.ttype == StreamTokenizer.TT_EOF) {
            ConverterUtils.errms(tokenizer, "premature end of file");
        }

        while (tokenizer.ttype != StreamTokenizer.TT_EOL) {
            attribNames.addElement(new Attribute(tokenizer.sval));
            ConverterUtils.getToken(tokenizer);
        }
        String relationName;

        if (m_sourceFile != null) {
View Full Code Here

TOP

Related Classes of org.integratedmodelling.riskwiz.learning.data.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.