Home Tutorials Rdf Controlling RDF Prefix in Java



Controlling RDF Prefix in Java
Posted on: September 27, 2008 at 12:00 AM
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.

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();
 Resource root = model.createResource(
  
"http://amit/Kumar#"+"root");
 Property property = model.createProperty(
  
"http://amit/Kumar#"+"Property");
 Resource child = model.createResource(
  
"http://amit/Kumar#" +"child");


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.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.vocabulary.*;

public class RDFPrefix extends Object {
  public static void main (String args[]) {
 
 Model model = ModelFactory.createDefaultModel();
 Resource root = model.createResource(
  
"http://amit/Kumar#"+"root");
 Property property = model.createProperty(
  
"http://amit/Kumar#"+"Property");
 Resource child = model.createResource(
  
"http://amit/Kumar#" +"child");
 model.add(root,property,child);
 model.writeSystem.out );
  }
}

To run this example :

  • Create and save RDFPrefix.java
  • Compile RDFPrefix.java
  • Run RDFPrefix class file and you will get following output.

Output:


Download Source Code

     

Related Tags for Controlling RDF Prefix in Java:
capifilefilescontrolrdfforwithprefixrefeilitlscanliuseinjenanttrcajespisxesollprearrollingtwssrdthapdffixlsojeprprefixesonolo


More Tutorials from this section

Ask Questions?    Discuss: Controlling RDF Prefix in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.