import java.util.*; /** A class the represents a simple OWL class. The class can have multiple superclasses and multiple property restrictions. From an implementation perspective, the class has multiple "slots" (OwlProperty objects) where each "slot" represents a specific property the class could have. Each of these slots can have one or more "facets" that restrict the slot. Each OWL restriction is one of these facets. Note, to ensure compatibility with older versions of Java, the various data structures are not parameterized. */ public class OwlClass { protected String id; /** A data structure that contains all of the properties directly associated with the class. The hashtable allows for efficient access to properties by ID. Each property will contain all of the restrictions on that property. */ protected Hashtable properties; /** A data structure that contains all of the direct superclasses of the class. */ protected Vector superClasses; /** The ontology that contains the class. */ protected OwlOnt ont; /** Given a URI, create a class. */ public OwlClass(String id) { this.id = id; properties = new Hashtable(); superClasses = new Vector(); } /** Add a set of property restrictions for a specific property to the class. * * @param prop - An OwlProperty object that contains the restriction information. */ public void addProperty(OwlProperty prop) { String propId; propId = prop.getId(); properties.put(propId, prop); } /** Add a superclass to the class. * * @param parentId - The URI of the new parent class. */ public void addSuperClass(String parentId) { superClasses.addElement(parentId); } /** Return the URI of the class. */ public String getId() { return id; } /** Return an array of properties that the class can have. Each OwlProperty * is similar to a "slot", and has information about all of the restrictions * on that property. */ public OwlProperty[] getProperties() { OwlProperty[] propArray; OwlProperty nextProp; int i = 0; propArray = new OwlProperty[properties.size()]; Enumeration propEnum = properties.elements(); while (propEnum.hasMoreElements()) { nextProp = (OwlProperty)propEnum.nextElement(); propArray[i] = nextProp; i = i +1; } return propArray; } /** Given the URI of a property, returns the OwlProperty object which contains the restrictions * the class has with respect to the property. If there are no such restriction, then * returns null. * @param propId - URI of the property * @return an OwlProperty object or null if the class has no restrictions involving the property */ public OwlProperty getProperty(String propId) { Object lookup; lookup = properties.get(propId); if (lookup == null) return null; else return (OwlProperty)lookup; } /** Returns the direct superclasses of the classes (as an array of string URIs of OWL classes. */ public String[] getSuperClasses() { String[] classArray; OwlClass nextClass; int i = 0; classArray = new String[superClasses.size()]; superClasses.copyInto(classArray); return classArray; } /** Returns true if the current class is a subclass of the specified class, whether directly or by transitivity of subClassOf. */ public boolean isSubClassOf(String parentId) { // ***** YOU NEED TO WRITE THIS METHOD!!! ***** return false; // temporary return value so that the class compiles } /** Sets the ontology for the class. This should only be called by OwlOnt, and only after the class has been added to the ontology. */ public void setOntology(OwlOnt ont) { this.ont = ont; } /** Provides a raw description of the class and its contents. Useful for debugging. */ public String toString() { String str = id + "\n"; OwlProperty[] props = getProperties(); for (int i=0; i < props.length; i++) str = str + "\t" + props[i].toString() + "\n"; return str; } }