Use Jena to obtain the default namespace of the Ontology

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.