1   package gate.creole.ontology;
2   
3   import java.net.MalformedURLException;
4   import java.net.URL;
5   import java.util.List;
6   import java.util.Set;
7   import gate.annotation.TestAnnotation;
8   import gate.creole.ResourceInstantiationException;
9   import gate.creole.ontology.jena.JenaOntologyImpl;
10  import junit.framework.Test;
11  import junit.framework.TestCase;
12  import junit.framework.TestSuite;
13  
14  /**
15   * Simple test class that load an ontology available online and 
16   * accesses its content via the ontology API 
17   **/
18  public class TestOntologyAPI extends TestCase {
19    public static void main(String[] args) {
20      junit.textui.TestRunner.run(TestOntologyAPI.class);
21    }
22  
23    public TestOntologyAPI(String arg0) {
24      super(arg0);
25    }
26  
27    protected void setUp() throws Exception {
28      super.setUp();
29    }
30  
31    protected void tearDown() throws Exception {
32      super.tearDown();
33    }
34  
35    // load a known ontology and access it
36    // through the API objects
37    public void testLoadingOWLOntology() throws MalformedURLException,
38            ResourceInstantiationException {
39      JenaOntologyImpl onto = new JenaOntologyImpl();
40      URL url = new URL("http://gate.ac.uk/tests/demo.owl");
41      onto.load(url, JenaOntologyImpl.OWL_LITE);
42      // the ontology is loaded let's access some of its values
43      Ontology ontology = (Ontology)onto;
44      int classNum = ontology.getClasses().size();
45      assertEquals(classNum, 18);
46      // get a specific class
47      TClass aClass = ontology.getClassByName(null);
48      assertNull(aClass);
49      // count the number of top classes
50      Set topclasses = ontology.getTopClasses();
51      assertEquals(topclasses.size(), 5);
52      // get the class Department
53      aClass = ontology.getClassByName("Department");
54      assertNotNull(aClass);
55      // and count the number of super classes
56      List supclassbydist = aClass.getSuperClassesVSDistance();
57      // the list contains 2 arrays of classes i-e 2 levels
58      assertEquals(supclassbydist.size(), 2);
59      // get the class Department
60      aClass = ontology.getClassByName("Organization");
61      assertNotNull(aClass);
62      assertTrue(aClass.isTopClass());
63      List subclasses = aClass.getSubClassesVSDistance();
64      assertEquals(subclasses.size(), 2);
65    }
66    /** Test suite routine for the test runner */
67    public static Test suite() {
68      return new TestSuite(TestOntologyAPI.class);
69    } // suite
70    
71  }
72