Marco Dinatsoli
Marco Dinatsoli

Reputation: 10580

jena how to change the default prefix name to my prefix name

I have generated this RDF/XML data

  <rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://marco_student/" > 
  <rdf:Description rdf:nodeID="A0">
    <j.0:description>Departamento de Engenharia Civil</j.0:description>
    <j.0:abbreviation>DEC</j.0:abbreviation>
    <rdf:type rdf:resource="http://marco_student/Department"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A1">
    <j.0:description>Departamento de Engenharia Informática</j.0:description>
    <j.0:abbreviation>DEI</j.0:abbreviation>
    <rdf:type rdf:resource="http://marco_student/Department"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A2">
    <j.0:description>Departamento de Engenharia Electrotécnica</j.0:description>
    <j.0:abbreviation>DEE</j.0:abbreviation>
    <rdf:type rdf:resource="http://marco_student/Department"/>
  </rdf:Description>
</rdf:RDF>

using this code:

String myNameSpace = "http://william_student/";
            Resource departmentClass = ResourceFactory.createResource(myNameSpace+"Department");
            Property abbreviationProperty = ResourceFactory.createProperty(myNameSpace, "abbreviation");
            Property descriptionProperty = ResourceFactory.createProperty(myNameSpace, "description");
            Model departmentModel = ModelFactory.createDefaultModel();
            Resource departmentInstance1 = departmentModel.createResource();
            departmentInstance1.addProperty(RDF.type, departmentClass);
            departmentInstance1.addProperty(abbreviationProperty, "DEI");

and I write to file using this simple code

File file = new File("D:/departments.rdf");
            fos = new FileOutputStream(file);
            departmentModel.write(fos);

as you see, in the RDF generated data, there is j.0 prefix:

My question:

How can I replace that default prefix j.0, but my prefix like vocabularyMarco

Upvotes: 2

Views: 1079

Answers (2)

AndyS
AndyS

Reputation: 16700

To write RDF/XML, all properties must have a qname. Jena invents "j.0" etc when one is needed but not supplied. So set a prefix name of your choice on the model

model.setNsPrefix("vocabularyMarco", "http://marco_student/")

Your code and the data don't agree on "http://william_student/".

Upvotes: 3

Janga Reddy
Janga Reddy

Reputation: 1

// Namespace declarations

static final String companyUri = "citylsdi.org#";

Model model = ModelFactory.createDefaultModel();

model.setNsPrefix( "Indicator", "citylsdi.org#" );

It creates prefix "citylsdi.org#" In the above code snippet.

In order to get "vocabularyMarco" as prefix Just use

Model model = ModelFactory.createDefaultModel();
model.setNsPrefix( "Indicator", "vocabularyMarco" );

// Create the types of Property we need to describe relationships in the model

Property cu_role = model.createProperty(companyUri,domain);

// Create resources representing the people in our model

Resource rs2 = model.createResource(companyUri+name);

rs2.addProperty(cu_role,"'"+role+"'");

Upvotes: 0

Related Questions