Created
July 19, 2012 11:39
-
-
Save ijdickinson/3143188 to your computer and use it in GitHub Desktop.
Workaround for bug in Jena OntTools.namedHierarchyRoots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package usertests; | |
import java.io.StringReader; | |
import java.util.Iterator; | |
import com.hp.hpl.jena.ontology.*; | |
import com.hp.hpl.jena.rdf.model.ModelFactory; | |
import com.hp.hpl.jena.util.iterator.ExtendedIterator; | |
public class LHRTest | |
{ | |
public static final String SOURCE = "<?xml version=\"1.0\"?>\n" + | |
"<rdf:RDF\n" + | |
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" + | |
" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n" + | |
" xmlns:owl=\"http://www.w3.org/2002/07/owl#\" >\n" + | |
"<owl:Class rdf:about=\"http://dbpedia.org/class/yago/Album106591815\"/>\n" + | |
"<owl:Class rdf:about=\"http://dbpedia.org/class/yago/HostCitiesOfTheCommonwealthGames\"/>\n" + | |
"<owl:ObjectProperty rdf:about=\"http://dbpedia.org/property/after\"> \n" + | |
"<rdfs:domain>\n" + | |
"<owl:Class>\n" + | |
"<owl:unionOf rdf:parseType=\"Collection\">\n" + | |
"<owl:Class rdf:about=\"http://dbpedia.org/class/yago/Album106591815\"/>\n" + | |
"</owl:unionOf>\n" + | |
"</owl:Class>\n" + | |
"</rdfs:domain>\n" + | |
"</owl:ObjectProperty>\n" + | |
"</rdf:RDF>"; | |
public static void main( String[] args ) { | |
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF ); | |
m.read( new StringReader( SOURCE ), "RDF/XML" ); | |
for (ExtendedIterator<OntClass> i = m.listHierarchyRootClasses(); i.hasNext(); ) { | |
System.out.println( "LHRC -> " + i.next() ); | |
} | |
OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, m.getBaseModel() ); | |
for (Iterator<OntClass> i = OntTools.namedHierarchyRoots( base ).iterator(); i.hasNext(); ) { | |
System.out.println( "NHR -> " + i.next() ); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: