I would like to have a file like this:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://stackoverflow.com/q/24084473/1281433/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:j.0="http://stackoverflow.com/q/24084473/1281433/relations/">
<rdf:Property rdf:about="http://stackoverflow.com/q/24084473/1281433/Regione">
<rdfs:label>Regione</rdfs:label>
</rdf:Property>
<rdf:Property rdf:about="http://stackoverflow.com/q/24084473/1281433/Nome">
<rdfs:label>Nome</rdfs:label>
</rdf:Property>
<rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/soggetto">
<j.0:Nome>Vercelli</j.0:Nome>
<j.0:Regione>
<rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/Piemonte">
<rdfs:label>Piemonte</rdfs:label>
</rdf:Description>
</j.0:Regione>
</rdf:Description>
<rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/Vercelli">
<rdfs:label>Vercelli</rdfs:label>
</rdf:Description>
</rdf:RDF>
In particular, I would like to know how I can write, in Java code (using Jena library) the follow section:
<rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/soggetto">
<j.0:Nome>Vercelli</j.0:Nome>
<j.0:Regione>
<rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/Piemonte">
<rdfs:label>Piemonte</rdfs:label>
</rdf:Description>
</j.0:Regione>
</rdf:Description>
I have read in the literature, the <rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/Piemonte">
object (or resource?) is a blank node, but I don't know how to write it. I tried to use the follow code:
public Model BlankNodeCode (Model model){
Model model1 = model;
StmtIterator stmt = model.listStatements();
while (stmt.hasNext()){
Statement statement = stmt.next();
Resource subject = statement.getSubject();
Property pred = statement.getPredicate();
RDFNode object = statement.getObject();
Object res = null;
@SuppressWarnings("unchecked")
Resource resource = object.as((Class<Resource>) res);
model1.createResource(subject).addProperty(pred,model1.createResource(resource));
}
return model1;
}
But I get an exception:
Exception in thread "main" java.lang.NullPointerException
at com.hp.hpl.jena.enhanced.Polymorphic.findExistingView(Polymorphic.java:75)
at com.hp.hpl.jena.enhanced.Polymorphic.asInternal(Polymorphic.java:61)
at com.hp.hpl.jena.enhanced.EnhNode.as(EnhNode.java:107)
What am I doing wrong here?