【问题标题】:How to add object property with Jena? Special format如何使用 Jena 添加对象属性?特殊格式
【发布时间】:2013-12-08 17:56:45
【问题描述】:

您好,我正在尝试在这两个人之间添加一个对象属性。我在代码中也有对象属性,并且个体在本体中。只需要使用一个属性来连接它们。个人在代码中看起来像这样,我的问题是我从来没有使用这个“描述”标签来处理那个本体。

<!-- http://vivo.iu.edu/individual/n6356 -->

<owl:Thing rdf:about="http://vivo.iu.edu/individual/n6356">
    <rdf:type rdf:resource="&bibo;Article"/>
    <rdf:type rdf:resource="&bibo;Document"/>
    <rdf:type rdf:resource="&vivo;ConferencePaper"/>
    <rdf:type rdf:resource="&vivo;InformationResource"/>
    <rdf:type rdf:resource="&owl;NamedIndividual"/>
    <rdfs:label xml:lang="en-us">Indiana University Digital Music Library Project</rdfs:label>
    <vitro:modTime rdf:datatype="&xsd;dateTime">2010-07-28T15:36:03</vitro:modTime>
    <vitro:moniker rdf:datatype="&xsd;string">conference paper</vitro:moniker>
    <bibo:doi rdf:datatype="&xsd;string">http://doi.acm.org/10.1145/379437.379774</bibo:doi>
    <title>Indiana University Digital Music Library Project</title>
    <dateTimeValue rdf:resource="http://vivo.iu.edu/individual/n4086167"/>
    <bibo:presentedAt rdf:resource="http://vivo.iu.edu/individual/n5092"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n6257"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n6300"/>
    <vitro:mostSpecificType rdf:resource="&vivo;ConferencePaper"/>
</owl:Thing>

<!-- http://vivo.iu.edu/individual/n6399 -->

<owl:Thing rdf:about="http://vivo.iu.edu/individual/n6399">
    <rdf:type rdf:resource="&bibo;Article"/>
    <rdf:type rdf:resource="&bibo;Document"/>
    <rdf:type rdf:resource="&vivo;ConferencePaper"/>
    <rdf:type rdf:resource="&vivo;InformationResource"/>
    <rdf:type rdf:resource="&owl;NamedIndividual"/>
    <rdfs:label xml:lang="en-us">Assessing Future Ecosystem Services: a Case Study of the Northern Highlands Lake District  Wisconsin</rdfs:label>
    <vitro:modTime rdf:datatype="&xsd;dateTime">2010-07-28T15:36:03</vitro:modTime>
    <vitro:moniker rdf:datatype="&xsd;string">conference paper</vitro:moniker>
    <bibo:doi rdf:datatype="&xsd;string">http://doi.acm.org/10.1145/379437.99999</bibo:doi>
    <title>Assessing Future Ecosystem Services: a Case Study of the Northern Highlands Lake District  Wisconsin</title>
    <dateTimeValue rdf:resource="http://vivo.iu.edu/individual/n111111"/>
    <bibo:presentedAt rdf:resource="http://vivo.iu.edu/individual/n2222"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n3333"/>
    <informationResourceInAuthorship rdf:resource="http://vivo.iu.edu/individual/n4444"/>
    <vitro:mostSpecificType rdf:resource="&vivo;ConferencePaper"/>
</owl:Thing>

我已尝试使用此代码,但 getter 给了我空值。通过名称获取两个个体,获取对象属性并将它们添加到模型中。

Individual doc = model.getIndividual("n6356");
Individual ref = model.getIndividual("n6399");
ObjectProperty cites = model.getObjectProperty("http://purl.org/ontology/bibo/cites");
model.add(doc,cites,ref);

【问题讨论】:

  • 你在这方面有什么进展吗?

标签: java rdf jena owl object-property


【解决方案1】:

RDF 中的资源要么是空白节点,要么是 URI 节点。您的个人恰好是 IRI 节点,因此您需要通过以下方式检索它们:

Individual doc = model.getIndividual("http://vivo.iu.edu/individual/n6356");
Individual ref = model.getIndividual("http://vivo.iu.edu/individual/n6399");

如果你要做很多这样的事情,这样做可能是有意义的:

final String NS = "http://vivo.iu.edu/individual/";
Individual doc = model.getIndividual(NS+"n6356");
Individual ref = model.getIndividual(NS+"n6399");

【讨论】:

    【解决方案2】:

    如果您没有将模型保存在内存中,请不要忘记将其写出来。

    final String NS = "http://vivo.iu.edu/individual/";
    Individual doc = model.getIndividual(NS+"n6356");
    Individual ref = model.getIndividual(NS+"n6399");
    ObjectProperty cites = model.getObjectProperty("http://purl.org/ontology/bibo/cites");
    model.add(doc,cites,ref).write(new FileOutputStream(new File("rdf/myRDFFile.owl"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 2015-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      相关资源
      最近更新 更多