我有RDF / XML数据,如下所示:
<rdf:RDF>
<rdf:Description rdf:about="https://localhost/process/members/test">
<process:user rdf:resource="https://localhost/users/test"/>
<process:roleAssignments rdf:parseType="Collection">
<rdf:Description rdf:about="https://localhost/process/role/ProductOwner">
<process:roleUrl rdf:resource="https://localhost/role/ProductOwner"/>
</rdf:Description>
<rdf:Description rdf:about="https://localhost/process/role/TeamMember">
<process:roleUrl rdf:resource="https://localhost/role/TeamMember"/>
</rdf:Description>
</process:roleAssignments>
</rdf:Description>
</rdf:RDF>
它不是很严格,但我只是想知道如何使用Jena API输出rdf:Collection,如上例所示。
答案 0 :(得分:2)
令人困惑的是parsetype="collection"
创建的是一个rdf 列表,而不是一个集合。这可能会妨碍您的搜索。
您想要的是使用RDFList
创建的number of methods in Model
。假设您在资源和属性方面拥有大部分已经需要的东西。可以按如下方式创建列表:
// ... create model, resources, and properties as usual ...
// create the role assignments as you normally would
model.add(productOwner, roleUrl, productOwner);
model.add(teamMember, roleUrl, teamMember);
// Create a list containing the subjects of the role assignments in one go
RDFList list = model.createList(new RDFNode[] {productOwner, teamMember}));
// Add the list to the model
model.add(test, roleAssignments, list);
// ... now write the model out as rdf/xml or whatever you like ...
您还可以创建一个空列表并将每个项目添加到其中。