Simple Query on RDF file in Java
As you have already learned about controlling prefix, generating RDF files and about RDF Iterators in the previous examples, so in this section we are going to describe how to run simple query on the RDF graph model. Now lets see the example that can fires a simple query. The example is going to list the subject with property name "VCARD.FN".
To do this we have taken an object of Model interface. By the use of listSubjectsWithProperty() method we have queried about VCARD.FN . It returns an object of ResIterator (i.e ResourceIterator).
"Resource res = iter.nextResource();"
Above line of code gets all the resources of that particular Subject. Now we can get property and other information's of that resource.
getProperty() gets property of that resource.
getURI() will gets URI of that resource.
RDFQuery.java
import java.io.*;
|
To run this example follow these steps:
- Create and Save RDFQuery.java
- Compile RDFQuery.java
- Run RDFQuery.class file and you will get the following output:
Output: