|
DatasetDefintion |
|
1 /* 2 * Copyright (c) 1998-2001, The University of Sheffield. 3 * 4 * This file is part of GATE (see http://gate.ac.uk/), and is free 5 * software, licenced under the GNU Library General Public License, 6 * Version 2, June 1991 (in the distribution as file licence.html, 7 * and also available at http://gate.ac.uk/gate/licence.html). 8 * 9 * Valentin Tablan 19/11/2002 10 * 11 * $Id: DatasetDefintion.java,v 1.2 2003/02/20 18:40:13 valyt Exp $ 12 * 13 */ 14 package gate.creole.ml; 15 16 import java.util.*; 17 import java.io.*; 18 import java.net.URL; 19 20 import org.jdom.*; 21 import org.jdom.input.*; 22 23 import gate.util.*; 24 25 /** 26 * Stores data describing a dataset. 27 */ 28 29 public class DatasetDefintion implements Serializable{ 30 31 public DatasetDefintion(Element domElement) throws GateException{ 32 if(!domElement.getName().equals("DATASET")) throw new GateException( 33 "Dataset defintion element is \"" + domElement.getName() + 34 "\" instead of \"DATASET\"!"); 35 36 //find instance the type 37 Element anElement = domElement.getChild("INSTANCE-TYPE"); 38 if(anElement != null) instanceType = anElement.getTextTrim(); 39 else throw new GateException( 40 "Required element \"INSTANCE-TYPE\" not present!"); 41 42 //find the attributes 43 int attrIndex = 0; 44 attributes = new ArrayList(); 45 Iterator childrenIter = domElement.getChildren("ATTRIBUTE").iterator(); 46 while(childrenIter.hasNext()){ 47 Element child = (Element)childrenIter.next(); 48 Attribute attribute = new Attribute(child); 49 if(attribute.isClass()){ 50 if(classAttribute != null) throw new GateException( 51 "Attribute \""+ attribute.getName() + 52 "\" marked as class attribute but the class is already known to be\""+ 53 classAttribute.getName() + "\"!"); 54 classAttribute = attribute; 55 classIndex = attrIndex; 56 } 57 attributes.add(attribute); 58 attrIndex ++; 59 } 60 61 if(classAttribute == null) throw new GateException( 62 "No class attribute defined!"); 63 } 64 65 public DatasetDefintion(){ 66 attributes = new ArrayList(); 67 classAttribute = null; 68 classIndex = -1; 69 instanceType = null; 70 } 71 72 73 public String toString(){ 74 StringBuffer res = new StringBuffer(); 75 res.append("Instance type: " + instanceType + "\n"); 76 Iterator attrIter = attributes.iterator(); 77 while(attrIter.hasNext()){ 78 res.append("Attribute:" + attrIter.next().toString() + "\n"); 79 } 80 return res.toString(); 81 } 82 83 84 public java.util.List getAttributes() { 85 return attributes; 86 } 87 88 public Attribute getClassAttribute(){ 89 return classAttribute; 90 } 91 public String getInstanceType() { 92 return instanceType; 93 } 94 95 public int getClassIndex() { 96 return classIndex; 97 } 98 public void setClassAttribute(Attribute classAttribute) { 99 this.classAttribute = classAttribute; 100 } 101 public void setClassIndex(int classIndex) { 102 this.classIndex = classIndex; 103 } 104 public void setInstanceType(String instanceType) { 105 this.instanceType = instanceType; 106 } 107 108 protected java.util.List attributes; 109 protected Attribute classAttribute = null; 110 protected String instanceType; 111 112 protected int classIndex; 113 }
|
DatasetDefintion |
|