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

标签 java rdf jena

我有 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,如上面的示例。

最佳答案

令人困惑的是parsetype="collection"创建的是一个rdf列表,而不是一个集合。这可能会阻碍您的搜索。

你想要的是 RDFList您可以使用 number of methods in Model 创建。假设您已经拥有所需的大部分资源和属性(property)。该列表可以按如下方式创建:

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

您还可以创建一个空列表并将每个项目添加到其中。

关于java - 如何通过Jena API生成rdf集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998849/

相关文章:

sparql - 如何使用SPARQL查找图中的叶节点?

java - 耶拿自定义数据类型

在 Tomcat 8 上运行 Jena API 时出现 java.lang.UnsupportedClassVersionError

java - 编辑字段奇怪的高度

java - 编程初学者

java - RxJava 2 - 在另一个 Completable 之后调用 Completable

namespaces - OWL 处理具有命名空间的重复类名

java - 如何在 eclipse rcp 应用程序中启用上下文相关帮助?

file - 在 Turtle RDF 中交叉引用其他 .ttl

java - 一旦我编写了内置函数,我需要做什么才能让推理机意识到它?