Maatary Daniel OKOUYA wrote:

> Can anyone help me understand this different of output. I listing all  
> the subject in the RDF Graph then print their details. After what i  
> list all object of the graph and if they are a ressource convert them  
> in the  ressource they are and print
> 
> However, i get totaly different answer as you can see below

(a) You have different code for the two cases; of course the answers
    look different.

(b) In any case, the sets of subjects and objects in a graph need
    not be the same. Consider the trivial graph {(S P O)}; listSubjects
    will get you {S} (with one property P) and listObjects will get you 
    {O} (with no properties). Similarly {(S P X; X Q Y)} has subjects
    S and X, but objects X and Y.

(c) Don't use getLocalName(); you're setting yourself up for long-term
    trouble because different resources (different, as in having different
    URIs) can have the same local name. Like, eg, type.

    (Sometimes getLocalName is the right thing to do, but usually what
    it means is there's some design left to be done.)

Chris

> 
> 
> 
> static final String inputFileName = "data/promise.rdf";
>       
>       public static void main(String[] args) {
>               
>               // create an empty model
>          Model model = ModelFactory.createDefaultModel();
> 
>          // use the FileManager to find the input file
>          InputStream in = FileManager.get().open(inputFileName);
>          if (in == null) {
>              throw new IllegalArgumentException( "File: " +  
> inputFileName + " not found");
>          }
> 
>          // read the RDF/XML file
>          model.read(new InputStreamReader(in), "");
> 
>          ResIterator it      = model.listSubjects();
>          NodeIterator nodit  = model.listObjects();
>          Resource res        = null;
>          StmtIterator propIt = null;
> 
> 
>          while (it.hasNext()) {
>               
>               res = it.nextResource();
>               
>               System.out.println("res:" + res.toString());
>               
>               propIt = res.listProperties();
>               
>               while (propIt.hasNext())
>                               System.out.println("property: " +  
> propIt.nextStatement().getPredicate().getLocalName());
> 
>          }
> 
>          
> System 
> .out 
> .println 
> ("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Objects>>>>>>>>>>>>>>>>>>>>>>>\n");
>          res    = null;
>          propIt = null;
> 
>          while (nodit.hasNext()) {
>               RDFNode nod = nodit.nextNode();
>               
>               System.out.println("nod:" + nod.toString() + " : " +  
> nod.isResource());
> 
>                       if (nod.isResource()) {
>                               res = nod.asResource();
>                               
>                               System.out.println("res:" + res.toString() + " 
> : " +  
> res.getLocalName());
>                               
>                               //propIt = res.listProperties();
>                               
>                       }
>          }
>       
>               
> }
> 
> 
> res:http://www.people.lu.unisi.ch/fornaran/example/promise#JohnAction1
> property: hasAmount
> property: hasRecipient
> property: hasDuration
> property: hasActor
> property: type
> res:http://www.people.lu.unisi.ch/fornaran/example/promise#book1
> property: type
> res:http://www.people.lu.unisi.ch/fornaran/example/promise#MaryAction1
> property: hasObject
> property: hasRecipient
> property: hasActor
> property: type
> 
>  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Objects>>>>>>>>>>>>>>>>>>>>>>>
> 
> nod:http://www.people.lu.unisi.ch/fornaran/schemas/app-rdf0#Pay : true
> res:http://www.people.lu.unisi.ch/fornaran/schemas/app-rdf0#Pay : Pay
> nod:http://www.people.lu.unisi.ch/fornaran/schemas/app-rdf0#Deliver :  
> true
> res:http://www.people.lu.unisi.ch/fornaran/schemas/app-rdf0#Deliver :  
> Deliver
> nod:Mary : false
> nod:2 : false
> nod:http://www.people.lu.unisi.ch/fornaran/example/promise#book1 : true
> res:http://www.people.lu.unisi.ch/fornaran/example/promise#book1 : book1
> nod:John : false
> nod:http://www.people.lu.unisi.ch/fornaran/schemas/app-rdf0#book : true
> res:http://www.people.lu.unisi.ch/fornaran/schemas/app-rdf0#book : book
> nod:5 : false

-- 
"The wizard seemed quite willing when I talked to him."  /Howl's Moving Castle/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)

Reply via email to