2

我已经生成了这个 RDF/XML 数据

  <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>

使用此代码:

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");

我使用这个简单的代码写入文件

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

如您所见,在 RDF 生成的数据中,有j.0前缀:

我的问题:

如何替换该默认前缀j.0,但我的前缀喜欢vocabularyMarco

4

2 回答 2

3

要编写 RDF/XML,所有属性都必须有一个 qname。Jena 在需要但未提供时发明了“j.0”等。因此,在模型上设置您选择的前缀名称

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

您的代码和数据在“ http://william_student/ ”上不一致。

于 2015-03-06T20:50:51.633 回答
0
// Namespace declarations

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

Model model = ModelFactory.createDefaultModel();

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

它在上面的代码片段中创建前缀“citylsdi.org#”。

为了获得“vocabularyMarco”作为前缀只需使用

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+"'");
于 2015-03-08T06:12:52.397 回答