Controlling RDF Prefix in Java
We can also control prefixes of RDF files with the use
of Jena API for RDF. In RDF file there are two ways for Controlling RDF
prefixes.
First is explicit prefix controlling and second is
implicit prefix definition controlling. Here we have created prefix definitions
with the explicit prefix definitions.
We have created one resource "root" with one property. To create resources we have to use createResource() method of Model interface. To add property in this model we have used createProperty() method of Model interface.
Model model = ModelFactory.createDefaultModel();
|
Above lines of code creates an object of Model interface
and then we have created two resources first is root and second is child and
then we have added these with the Model interface method add().
model.add(root,property,child) adds resources to the graph model. Following is the full source code of RDFPrefix.java.
RDFPrefix.java
import java.io.*;
|
To run this example :
- Create and save RDFPrefix.java
- Compile RDFPrefix.java
- Run RDFPrefix class file and you will get following output.
Output: