Hi Maatary,
What output were you expecting?
Consider the graph consisting of the single triple:
ex:foo --ex:prop--> ex:bar
If you list all the subjects in the graph you would get:
ex:foo
because the subjects are the resources at the blunt end of the arrow.
If you list all the objects in this graph you would get:
ex:bar
because the objects are the nodes at the sharp end of the arrow.
Completely different lists. As you would expect, no?
Brian
On 23/08/2011 15:50, 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
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