Example #1
0
        public static Example exampleFromString(string data, DataSetSpecification dataSetSpec, string separator)
        {
            Hashtable attributes = new Hashtable();

            //ArrayList attributeValues = Arrays.asList(data.Split(separator.ToCharArray()[0]));
            string[]  splitData       = data.Split(separator.ToCharArray()[0]);
            ArrayList attributeValues = new ArrayList();

            foreach (string str in splitData)
            {
                attributeValues.Add(str);
            }
            if (dataSetSpec.isValid(attributeValues))
            {
                ArrayList   names     = dataSetSpec.getAttributeNames();
                IEnumerator nameiter  = names.GetEnumerator();
                IEnumerator valueiter = attributeValues.GetEnumerator();
                while (nameiter.MoveNext() && valueiter.MoveNext())
                {
                    string name = nameiter.Current.ToString();
                    AttributeSpecification attributeSpec = dataSetSpec.getAttributeSpecFor(name);
                    Attribute attribute = attributeSpec.createAttribute(valueiter.Current.ToString());
                    //attributes.put(name,attribute);
                    if (attributes.Contains(name))
                    {
                        attributes[name] = attribute;
                    }
                    else
                    {
                        attributes.Add(name, attribute);
                    }
                }
                string targetAttributeName = dataSetSpec.getTarget();
                //AttributeSpecification attributeSpec =dataSetSpec.getAttributeSpecFor(targetAttributeName );
                AttributeSpecification _attributeSpec = dataSetSpec.getAttributeSpecFor(targetAttributeName);
                return(new Example(attributes, (Attribute)attributes[targetAttributeName]));
            }
            else
            {
                throw new Exception("Unable to construct Example from " + data);
            }
        }
Example #2
0
		public static Example exampleFromString(string data,DataSetSpecification dataSetSpec,string separator)
		{
			Hashtable attributes = new Hashtable();
			//ArrayList attributeValues = Arrays.asList(data.Split(separator.ToCharArray()[0]));
			string[] splitData = data.Split(separator.ToCharArray()[0]);
			ArrayList attributeValues = new ArrayList();
			foreach (string str in splitData)
			{
				attributeValues.Add(str);
			}
			if (dataSetSpec.isValid(attributeValues))
			{
				ArrayList names = dataSetSpec.getAttributeNames();
				IEnumerator nameiter = names.GetEnumerator();
				IEnumerator valueiter = attributeValues.GetEnumerator();
				while(nameiter.MoveNext() && valueiter.MoveNext())
				{
					string name = nameiter.Current.ToString();
					AttributeSpecification attributeSpec = dataSetSpec.getAttributeSpecFor(name);
					Attribute attribute =  attributeSpec.createAttribute(valueiter.Current.ToString());
					//attributes.put(name,attribute);
					if (attributes.Contains(name))
						attributes[name] = attribute;
					else
						attributes.Add(name,attribute);
				}
				string targetAttributeName = dataSetSpec.getTarget();
				//AttributeSpecification attributeSpec =dataSetSpec.getAttributeSpecFor(targetAttributeName );
				AttributeSpecification _attributeSpec =dataSetSpec.getAttributeSpecFor(targetAttributeName );
				return new Example(attributes,(Attribute)attributes[targetAttributeName]);
			}
			else
			{
				throw new Exception("Unable to construct Example from " + data);
			}
		}
Example #3
0
 public ArrayList getAttributeNames()
 {
     return(specification.getAttributeNames());
 }