将空白节点添加到Jena模型 [英] Adding blank nodes to a Jena model

查看:109
本文介绍了将空白节点添加到Jena模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一组现有的三元组填充Jena本体模型,其中某些三元组包含空白节点.我想忠实地在新模型中维护这些空白节点,但无法找到将它们添加到Jena模型中的方法.

I'm trying to populate a Jena ontology model with an existing set of triples, some of which contain blank nodes. I want to maintain these blank nodes inside this new model faithfully but I can't work out a way of adding them into a Jena model.

我一直在使用:

Statement s = ResourceFactory.createStatement(subject, predicate, object);

要向模型添加新语句:

private OntModel model = ModelFactory.createOntologyModel();
model.add(s);

,但这仅允许某些类型作为主语,谓语和宾语;资源主题,属性谓词,RDFNode对象.这些类型均不允许通过以下方式添加空白节点作为主题或对象:

but this only allows for certain types as subject, predicate, and object; Resource subject, Property predicate, RDFNode object. None of these types allow for the adding of a blanknode as subject or object such as through:

Node subject =  NodeFactory.createBlankNode(subjectValue);

有什么建议吗?我尝试仅使用blanknodes作为资源并创建Resource对象,但这会破坏它们成为类而不是空白节点时的所有内容.

Any suggestions? I've tried just using the blanknodes as resources and creating a Resource object but that breaks everything as they become classes then and not blank nodes.

任何帮助,将帮助我将头发拔掉,将不胜感激.

Any help would be much appreciated, been pulling my hair out with this.

推荐答案

好吧,如果您已经拥有一组三元组,则可以使用以下命令轻松地从文件中读取它们:

well, if you already have an existing set of triples you can easily read them from file by using:

OntModel model = ModelFactory.createOntologyModel();
model.read(new FileInputStream("data.ttl"), null, "TTL");

这将处理空白节点,请参见 jena文档

this will take care of blank nodes, see the jena documentation

您可以像这样手动创建一个空白节点:

you can create a blank node by hand like this:

Resource subject = model.createResource("s");
Property predicate = model.createProperty("p");
Resource object = model.createResource();
model.add(subject, predicate, object);

这将导致类似以下内容:

which will result in something like:

[s,p,aad22737-ce84-4564-a9c5-9bdfd49b55de]

[s, p, aad22737-ce84-4564-a9c5-9bdfd49b55de]

这篇关于将空白节点添加到Jena模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆