Extracting URIs from RDF web page in Java using Jena Library

Posted by Prannoy Mittal on Stack Overflow See other posts from Stack Overflow or by Prannoy Mittal
Published on 2012-09-22T13:21:01Z Indexed on 2012/09/22 15:37 UTC
Read the original article Hit count: 510

Filed under:
|
|
|
|

I have written following code for extratcting URIs from a web page with content type application/rdf-xml for Linked Data application.

public static void test(String url)
{
    try
    {
        Model read = ModelFactory.createDefaultModel().read(url);
        System.out.println("to go");
        StmtIterator si;
        si = read.listStatements();
        System.out.println("to go");
        while(si.hasNext())
        {
            Statement s=si.nextStatement();
            Resource r=s.getSubject();
            Property p=s.getPredicate();
            RDFNode o=s.getObject();
            System.out.println(r.getURI());
            System.out.println(p.getURI());
            System.out.println(o.asResource().getURI());
        }
    }
    catch(JenaException | NoSuchElementException c)
    {    }
}

But above code is not extracting all URIs. It provides only few of the URIs. Please guide me where i Went wrong?? hey Rafeel For Eq:

for XML File :

          <?xml version="1.0"?>
           <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:ex="http://example.org/stuff/1.0/">
        <rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar"
       dc:title="RDF/XML Syntax Specification (Revised)">
            <ex:editor>
              <rdf:Description ex:fullName="Dave Beckett">
        <ex:homePage rdf:resource="http://purl.org/net/dajobe/" />
              </rdf:Description>
            </ex:editor>
             </rdf:Description>
         </rdf:RDF>

The output is :

        Subject URI is http://www.w3.org/TR/rdf-syntax-grammar
        Predicate  URI is http://example.org/stuff/1.0/editor
      Object URI is null
          Subject URI is http://www.w3.org/TR/rdf-syntax-grammar
         Predicate  URI is http://purl.org/dc/elements/1.1/title
       Website is read

© Stack Overflow or respective owner

Related posts about java

Related posts about xml-parsing