This title is actually a bit problematic, because the ontology/RDF itself does not have a namespace concept, they only care about the absolute URI; once the model is read into the memory in Jena, they all use absolute URIs to identify resources, and these XML concepts are introduced only when the XML format is used for storage.
Recently encountered a problem inProgramTo read multiple ontology files in XML format (*. OWL), there is an import Relationship between them. Before reading a file, I need to check whether the ontology corresponding to the namespace to be imported in this file (the default namespace of this ontology is the value of import) exists, so I must know each. the default namespace and import value of the owl file are not discussed here. One advantage of this is that Jena does not need to access the network when the local file cannot be found, delay.
Although the Jena API does not provide a method to get it directly. the method for obtaining the default namespace from the owl file is actually very simple, but COM. HP. hpl. jena. shared. the prefixmapping interface has a getnsprefixuri () method, which can be used to obtain the namespace corresponding to each prefix in the XML document.
What is prefix? Prefix is mainly used to simplify XML writing. For example, in the following statement, RDF is the prefix, so that "RDF: XXX "represents the long string of" http://www.w3.org/1999/02/22-rdf-syntax-ns#xxx.
Xmlns: RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns"
With this method, we can obtain the namespaces corresponding to the prefixes of RDF, Owl, XSD, and so on. The default namespaces correspond to null strings (""), so we use model. getnsprefixuri (""), while the ontmodel object implements the prefixmapping interface.
Of course, there are many ways to get the default namespace of an XML file. However, in an application that is oriented to the ontology rather than the XML file, the APIS at the ontology level may be more appropriate.