java - 耶拿 - 如何将资源链接到属性?

标签 java properties resources jena

我正在开发一个框架,用于为特定数据结构实现欧洲数据模型(EDM),当我想添加属性时遇到问题。例如,考虑以下简单示例(使用 Apache Jena 3.9):

public static void main(String[] args) {
    String NS = "http://my.com/";
    Model model = ModelFactory.createDefaultModel();
    model.setNsPrefix("edm", EDM_TEST.getURI());
    model.setNsPrefix("skos", SKOS.getURI());

    Resource repository = model.createResource(NS + "testing_agent");
    repository.addProperty(RDF.type, EDM_TEST.Agent);
    repository.addProperty(SKOS.altLabel, model.createLiteral("Vasile Alecsandri Museum"));
    repository.addProperty(SKOS.prefLabel, model.createLiteral("Vasile Alecsandri National Museum"));

    Resource providedCHO = model.createResource(NS + "testing_cho");
    providedCHO.addProperty(RDF.type, EDM_TEST.ProvidedCHO);
    providedCHO.addProperty(EDM_TEST.currentLocation, repository);

    StringWriter out = new StringWriter();
    model.write(out, "RDF/XML");
    String result = out.toString();
    System.out.println(result);
}

结果似乎没问题:

<edm:ProvidedCHO rdf:about="http://my.com/testing_cho">
    <edm:currentLocation>
      <edm:Agent rdf:about="http://my.com/testing_agent">
        <skos:prefLabel>Vasile Alecsandri National Museum</skos:prefLabel>
        <skos:altLabel>Vasile Alecsandri Museum</skos:altLabel>
      </edm:Agent>
    </edm:currentLocation>
</edm:ProvidedCHO>

但这不行,因为 EDM 不允许 currentLocation 属性使用内部对象。因此,我需要为 currentLocation 属性生成以下输出:

<edm:ProvidedCHO rdf:about="http://my.com/testing_cho">
    <edm:currentLocation rdf:resource="http://my.com/testing_agent"/>
</edm:ProvidedCHO>
<edm:Agent rdf:about="http://my.com/testing_agent">
    <skos:prefLabel>Vasile Alecsandri National Museum</skos:prefLabel>
    <skos:altLabel>Vasile Alecsandri Museum</skos:altLabel>
</edm:Agent>

如何单独创建存储库资源(代理)并从提供的 CHO 资源链接到 currentLocation 属性,如我上面所解释的?

最佳答案

Jena 3.0.1 和 3.9.0 之间的区别在于 RDF/XMl 编写器的默认选择从简单变为漂亮。

可以通过

对格式详细信息的选择进行更多控制
RDFDataMgr.write(..,..,RDFFormat.RDFXML_ABBREV)

RDFDataMgr.write(..,..,RDFFormat.RDFXML_PLAIN)

可以通过以下方式进行更多控制:

http://jena.staging.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output

要创建非常特殊的 XML 架构,您可能需要取出数据,然后运行 ​​XSLT。

关于java - 耶拿 - 如何将资源链接到属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53471135/

相关文章:

java - 为什么我的 mac 不显示 java 版本?

Java Swing ComboBox 不可编辑 *使用 MCVE*

php - 在一行中声明多个属性

xml - Liquibase 替换 <property> 标签值?

Javascript 获取页面源(服务器端)

java - MySQL JDBC 驱动程序 5.1.33 - 时区问题

java - 如何在 Spring 3 中强制禁用 JSR-303 支持?

python - 使用 python 属性的奇怪结果

c# - 从代码设置应用程序资源

c# - System.Windows.Application.GetResourceStream 返回 null