While I create resources in the model and print the URI, I get the correct namespace. For instance, the URI is
http://www.somesite1.com/rdfdump/resources/resourceid-1
However, when I export the resources to an RDF file (link to the file) and I import it, I get the resource URI pointing to the physical location of the file in the disk such as
file:///D:/somefolder/resources/resourceid-1
I am using com.hp.hpl.jena.rdf.model.Model
in conjunction with com.hp.hpl.jena.ontology.OntModel
. The RDF model stores resources and I define an ontology using OntModel
. Initialize them in the following way.
com.hp.hpl.jena.rdf.model.Model model = ModelFactory.createDefaultModel();
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model);
NS = "http://www.somesite2.com/ontology"
BASE_URL = "http://www.somesite1.com/rdfdump/"
OntClass ocResource = ontModel.createClass(NS + "#RESOURCE");
//read an RDF file into the model
RDFDataMgr.read(model, file.toURI().toString());
This is the way I create a resource.
String uri = BASE_URL + "resources/resourceid-1";
com.hp.hpl.jena.rdf.model.Resource rdfResource = model.createResource(uri, ocResource );
Can you kindly point to me where is that I am going wrong and why is it that I do no get the correct URI when I import the file?
One thing I noted is, if I have the same base URL for both Jena RDF Model and OntModel, i.e., say http://www.somesite.com/...
, then I cannot retrieve resources in the model using
ocResource.listInstances()
It gives me 0 resources despite there being resources.