Skip to content

Instantly share code, notes, and snippets.

@harschware
Created April 13, 2011 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harschware/916880 to your computer and use it in GitHub Desktop.
Save harschware/916880 to your computer and use it in GitHub Desktop.
Code is response to answers.semanticweb.com question at http://answers.semanticweb.com/questions/8497
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns="http://example.org/unnamed0#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://example.org/unnamed0">
<owl:Ontology rdf:about="">
<owl:versionInfo rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Created with TopBraid Composer</owl:versionInfo>
</owl:Ontology>
<owl:Class rdf:ID="Uncle">
<owl:intersectionOf rdf:parseType="Collection">
<owl:Class rdf:ID="Brother"/>
<owl:Class rdf:ID="Parent"/>
</owl:intersectionOf>
<rdfs:subClassOf>
<owl:Class rdf:ID="Person"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="#Parent">
<rdfs:subClassOf>
<owl:Class rdf:about="#Person"/>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:about="#Person">
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:Class>
<owl:Class rdf:about="#Brother">
<rdfs:subClassOf rdf:resource="#Person"/>
</owl:Class>
<owl:DatatypeProperty rdf:ID="age">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
<rdfs:domain rdf:resource="#Person"/>
</owl:DatatypeProperty>
<owl:TransitiveProperty rdf:ID="knows">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>knows</rdfs:label>
<rdfs:domain rdf:resource="#Person"/>
<rdfs:range rdf:resource="#Person"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#SymmetricProperty"/>
</owl:TransitiveProperty>
<Uncle rdf:ID="UncleBob">
<owl:sameAs>
<Uncle rdf:ID="UncleRobert"/>
</owl:sameAs>
<knows>
<Uncle rdf:ID="UncleSam">
<knows>
<Uncle rdf:ID="UncleTom"/>
</knows>
</Uncle>
</knows>
</Uncle>
</rdf:RDF>
<!-- Created with TopBraid -->
package testejena;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import java.io.InputStream;
import java.util.Iterator;
public class TesteProp {
static final String inputFileName = "schema.owl";
public static void main(String args[]) {
try {
//create the reasoning model using the base
OntModel inf = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
inf.read(in, "");
String URI = "http://example.org/unnamed0#";
ExtendedIterator classes = inf.listClasses();
while (classes.hasNext()) {
OntClass essaClasse = (OntClass) classes.next();
String vClasse = essaClasse.getLocalName().toString();
if (essaClasse.hasSubClass()) {
System.out.println("Classe: " + vClasse);
OntClass cla = inf.getOntClass(URI + vClasse);
if( cla != null ) {
for (Iterator i = cla.listSubClasses(); i.hasNext();) {
OntClass c = (OntClass) i.next();
System.out.print(" " + c.getLocalName() + " " + "\n");
} // end for
} // end if
}
}
} catch (Exception e) {
System.out.println(e);
}
}
}
@harschware
Copy link
Author

Code is response to answers.semanticweb.com question at http://answers.semanticweb.com/questions/8497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment