TaxonTools { public Set<OWLClass> getAncestors(OWLClass taxonClass, boolean reflexive) { if (taxonClass == null) { return Collections.emptySet(); } Set<OWLClass> result = new HashSet<OWLClass>(); Set<OWLClass> set = reasoner.getSuperClasses(taxonClass, false).getFlattened(); for (OWLClass cls : set) { if (cls.isBuiltIn() == false) { result.add(cls); } } if (reflexive) { result.add(taxonClass); } if (result.isEmpty()) { return Collections.emptySet(); } return result; } TaxonTools(OWLReasoner reasoner, boolean disposeReasoner); Set<OWLClass> getAncestors(OWLClass taxonClass, boolean reflexive); Set<OWLClass> getDescendents(Set<OWLClass> sources, boolean reflexive); void dispose(); static final String TAXON_PURL; final static String NCBI; static final String TAXON_PREFIX; }
@Test public void testSimpleTaxon() throws OWLOntologyCreationException, IOException{ TaxonTools taxo = new TaxonTools(g.getReasoner(), true); OWLClass taxonClass = g.getOWLClassByIdentifier(TaxonTools.NCBI + "33511"); assertTrue("Got the taxon class", taxonClass != null); String taxId = g.getIdentifier(taxonClass); assertEquals(TaxonTools.NCBI + "33511", taxId); String taxLabel = g.getLabel(taxonClass); assertEquals("Deuterostomia", taxLabel); Set<String> foo = new HashSet<String>(); foo.add("root"); foo.add("cellular organisms"); foo.add("Eukaryota"); foo.add("Fungi/Metazoa group"); foo.add("Metazoa"); foo.add("Eumetazoa"); foo.add("Bilateria"); foo.add("Coelomata"); foo.add(taxLabel); Set<OWLClass> taxonSuperClasses = taxo.getAncestors(taxonClass, true); for( OWLClass ec : taxonSuperClasses ){ String ec_str_label = g.getLabel(ec); assertTrue("Actual ancestor should have been in hash, not: " + ec_str_label, foo.contains(ec_str_label)); } assertEquals(9, taxonSuperClasses.size()); }