2

Is there a way to get the base namespace from a OWL ontology file, without using DOM or similar, but just using Jena's API? E.g., from an OWL file:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
    xmlns="http://www.owl-ontologies.com/Ontology1254827934.owl#"
    xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:swrl="http://www.w3.org/2003/11/swrl#"
    xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xml:base="http://www.owl-ontologies.com/Ontology1254827934.owl">

how could I get http://www.owl-ontologies.com/Ontology1254827934.owl at runtime?

4

2 に答える 2

5

一方通行:

//Create the Ontology Model
OntModel model = ModelFactory.createOntologyModel();

//Read the ontology file
model.begin();
InputStream in = FileManager.get().open(FILENAME_HERE);
if (in == null) {
    throw new IllegalArgumentException("File: " + filename + " not found");
}        
model.read(in,"");
model.commit();

//Get the base namespace
model.getNsPrefixURI("");
于 2009-11-12T10:50:43.750 に答える