@Override public ExtendedIterator<OntClass> listHierarchyRootClasses() { return inner.listHierarchyRootClasses(); }
/** * Answer a list of the named hierarchy roots of a given {@link OntModel}. This * will be similar to the results of {@link OntModel#listHierarchyRootClasses()}, * with the added constraint that every member of the returned iterator will be a * named class, not an anonymous class expression. The named root classes are * calculated from the root classes, by recursively replacing every anonymous class * with its direct sub-classes. Thus it can be seen that the values in the list * consists of the shallowest fringe of named classes in the hierarchy. * @param m An ontology model * @return A list of classes whose members are the named root classes of the * class hierarchy in <code>m</code> */ public static List<OntClass> namedHierarchyRoots( OntModel m ) { List<OntClass> nhr = new ArrayList<>(); // named roots List<OntClass> ahr = new ArrayList<>(); // anon roots // do the initial partition of the root classes partitionByNamed( m.listHierarchyRootClasses(), nhr, ahr ); // now push the fringe down until we have only named classes while (!ahr.isEmpty()) { OntClass c = ahr.remove( 0 ); partitionByNamed( c.listSubClasses( true ), nhr, ahr ); } return nhr; }
/** * Answer a list of the named hierarchy roots of a given {@link OntModel}. This * will be similar to the results of {@link OntModel#listHierarchyRootClasses()}, * with the added constraint that every member of the returned iterator will be a * named class, not an anonymous class expression. The named root classes are * calculated from the root classes, by recursively replacing every anonymous class * with its direct sub-classes. Thus it can be seen that the values in the list * consists of the shallowest fringe of named classes in the hierarchy. * @param m An ontology model * @return A list of classes whose members are the named root classes of the * class hierarchy in <code>m</code> */ public static List<OntClass> namedHierarchyRoots( OntModel m ) { List<OntClass> nhr = new ArrayList<>(); // named roots List<OntClass> ahr = new ArrayList<>(); // anon roots // do the initial partition of the root classes partitionByNamed( m.listHierarchyRootClasses(), nhr, ahr ); // now push the fringe down until we have only named classes while (!ahr.isEmpty()) { OntClass c = ahr.remove( 0 ); partitionByNamed( c.listSubClasses( true ), nhr, ahr ); } return nhr; }
return ((OntModel) getModel()).listHierarchyRootClasses();
return ((OntModel) getModel()).listHierarchyRootClasses();
public void testListHierarchyRoots0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); assertFalse( m.listHierarchyRootClasses().hasNext() ); m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM ); assertFalse( m.listHierarchyRootClasses().hasNext() ); }
public void testListHierarchyRoots0() { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM ); assertFalse( m.listHierarchyRootClasses().hasNext() ); m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM ); assertFalse( m.listHierarchyRootClasses().hasNext() ); }
public void testListHierarchyRoots2() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a owl:Class. " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a} ); }
public void testListHierarchyRoots1() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a owl:Class. " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a} ); }
public void testListHierarchyRoots3() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a owl:Class. " + ":B a owl:Class ; rdfs:subClassOf :A . " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MINI_RULE_INF, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a} ); }
public void testListHierarchyRoots1() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a owl:Class. " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a} ); }
public void testListHierarchyRoots3() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a owl:Class. " + ":B a owl:Class ; rdfs:subClassOf :A . " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MINI_RULE_INF, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a} ); }
public void testListHierarchyRoots2() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a owl:Class. " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a} ); }
public void testListHierarchyRoots4() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a rdfs:Class. " + ":C a rdfs:Class. " + ":B a rdfs:Class ; rdfs:subClassOf :A . " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); OntClass c = m.getOntClass(NS+"C"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a,c} ); }
public void testListHierarchyRoots4() { String doc = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. " + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. " + "@prefix owl: <http://www.w3.org/2002/07/owl#>. " + "@prefix : <" + NS + ">. " + ":A a rdfs:Class. " + ":C a rdfs:Class. " + ":B a rdfs:Class ; rdfs:subClassOf :A . " ; OntModel m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, null); m.read( new StringReader(doc), NS, "N3" ); OntClass a = m.getOntClass(NS+"A"); OntClass c = m.getOntClass(NS+"C"); TestUtil.assertIteratorValues( this, m.listHierarchyRootClasses(), new Object[] {a,c} ); }