views:

420

answers:

1

Hi, I'm new to Jena API's , I'm trying to figure out a way to get the base Namespace from a OWL ontology file, without using DOM or similar but just using the standard Jena's API. Is there such a way?? in an OWL file like

how do I get the base namespace "http://www.owl-ontologies.com/Ontology1254827934.owl" a runtime?? Many many thanks in advance!

+1  A: 

One way:

//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("");
sdsantos