Home Tutorials Rdf Controlling RDF Prefix in Java

Related Tutorials


 
 

Share on Google+Share on Google+

Controlling RDF Prefix in Java

Advertisement
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

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 27, 2008

Related Tutorials

Discuss: Controlling RDF Prefix in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com