|
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.1 2002/11/26 14:41:06 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 66 public String toString(){ 67 StringBuffer res = new StringBuffer(); 68 res.append("Instance type: " + instanceType + "\n"); 69 Iterator attrIter = attributes.iterator(); 70 while(attrIter.hasNext()){ 71 res.append("Attribute:" + attrIter.next().toString() + "\n"); 72 } 73 return res.toString(); 74 } 75 76 77 public java.util.List getAttributes() { 78 return attributes; 79 } 80 81 public Attribute getClassAttribute(){ 82 return classAttribute; 83 } 84 public String getInstanceType() { 85 return instanceType; 86 } 87 88 public int getClassIndex() { 89 return classIndex; 90 } 91 92 protected java.util.List attributes; 93 protected Attribute classAttribute = null; 94 protected String instanceType; 95 96 protected int classIndex; 97 }
|
DatasetDefintion |
|