简体   繁体   English

如何通过Jena API生成rdf集合?

[英]How to generate rdf collection by Jena API?

I have RDF/XML data which looks like: 我有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>

It is not very strict, but I just want to know how to use Jena API to output the rdf:Collection like the above example. 它不是很严格,但是我只想知道如何使用Jena API来输出rdf:Collection,就像上面的示例一样。

Confusingly what parsetype="collection" creates is an rdf list , not a collection. 令人困惑的是parsetype="collection"创建的是rdf 列表 ,而不是集合。 This might have thwarted your searches. 这可能会阻碍您的搜索。

What you want is an RDFList which you can create using a number of methods in Model . 您需要一个RDFList ,您可以使用Model许多方法来创建它。 Let's assume you have most of what you need already in terms of resources and properties. 假设您已经在资源和属性方面拥有大部分需求。 The list can be created as follows: 可以如下创建该列表:

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

You could also create an empty list and add each item to it. 您也可以创建一个空列表并将每个项目添加到其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM