1 2 3 4 5 package net.nutch.ontology; 6 7 import net.nutch.protocol.ProtocolFactory; 8 import net.nutch.protocol.Protocol; 9 import net.nutch.protocol.Content; 10 import net.nutch.protocol.ProtocolException; 11 12 import net.nutch.parse.ParserFactory; 13 import net.nutch.parse.Parser; 14 import net.nutch.parse.Parse; 15 import net.nutch.parse.ParseException; 16 17 import junit.framework.TestCase; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.LinkedList ; 22 23 import java.lang.Exception ; 24 25 30 public class TestOntology extends TestCase { 31 32 private String fileSeparator = System.getProperty("file.separator"); 33 private String sampleDir = System.getProperty("test.data","."); 35 private String [] sampleFiles = {"time.owl"}; 39 40 private static Ontology ontology; 41 42 public TestOntology(String name) { 43 super(name); 44 } 45 46 protected void setUp() {} 47 48 protected void tearDown() {} 49 50 public void testIt() throws ProtocolException, ParseException, Exception { 51 String className = "Season"; 52 String [] subclassNames = 53 new String [] {"Spring", "Summer", "Fall", "Winter"}; 54 55 if (ontology==null) { 56 try { 57 ontology = OntologyFactory.getOntology(); 58 } catch (Exception e) { 59 throw new Exception ("Failed to instantiate ontology"); 60 } 61 } 62 63 for (int i=0; i<sampleFiles.length; i++) { 65 String urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i]; 67 68 ontology.load(new String [] {urlString}); 69 70 List subclassList = new LinkedList (); 71 72 Iterator iter = ontology.subclasses(className); 73 while (iter.hasNext()) { 74 String subclassLabel = (String ) iter.next(); 75 System.out.println(subclassLabel); 76 subclassList.add(subclassLabel); 77 } 78 79 for (int j=0; j<subclassNames.length; j++) { 80 assertTrue(subclassList.contains(subclassNames[j])); 81 } 82 } 83 84 } 85 86 } 87 | Popular Tags |