JSON-LD空白节点到Apache Jena中的嵌套对象 [英] JSON-LD blank node to nested object in Apache Jena

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

问题描述

我有以下示例Turtle文档:

I have the following example Turtle document:

@prefix dct:   <http://purl.org/dc/terms/> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix example: <http://example.com/vocabulary/> .
@prefix dcat:  <http://www.w3.org/ns/dcat#> .

<http://example.com/datasets/1>
        a                     dcat:Distribution ;
        example:props         [ example:prop1  "hello" ;
                                example:prop2  "1" 
                              ] ;
        dct:description       "test data" .

我使用Apache Jena(RDFDataMgr和JSONLD_COMPACT_PRETTY)将其转换为JSON-LD:

I converted it into JSON-LD with the Apache Jena (RDFDataMgr with JSONLD_COMPACT_PRETTY) to JSON-LD:

{
  "@context": {
    "dct": "http://purl.org/dc/terms/",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "dcat": "http://www.w3.org/ns/dcat#",
    "example": "http://example.com/vocabulary/"
  },
  "@graph": [
    {
      "@id": "_:b0",
      "example:prop1": "hello",
      "example:prop2": "1"
    },
    {
      "@id": "http://example.com/datasets/1",
      "@type": "dcat:Distribution",
      "example:props": {
        "@id": "_:b0"
      },
      "dct:description": "test data"
    }
  ]
}

但是实际上我想拥有一个嵌套对象而不是一个空白节点:

But actually I want to have a nested object instead of a blank node:

{
  "@context": {
    "dct": "http://purl.org/dc/terms/",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "dcat": "http://www.w3.org/ns/dcat#",
    "example": "http://example.com/vocabulary/"
  },
  "@graph": [
    {
      "@id": "http://example.com/datasets/1",
      "@type": "dcat:Distribution",
      "example:props": {
         "example:prop1": "hello",
         "example:prop2": "1"
      },
      "dct:description": "test data"
    }
  ]
}

使用Apache Jena可以吗?它在语义上是否等效?

Is that possible with Apache Jena? And is it semantically equivalent?

推荐答案

Apache Jena使用jsonld-java进行JSON-LD输入和输出.

Apache Jena uses jsonld-java for JSON-LD input and output.

可以设置 jsonld-java 输出,如下所示:

It is possible to setup the jsonld-java output as shown with:

https://jena.apache.org/documentation/io/rdf-output.html#json-ld ==> https://github.com/apache/jena/blob/master/jena-arq/src-examples/arq/examples/riot/Ex_WriteJsonLD.java

关于作者是否可以咨询 jsonld-java 做你想做的事.

You'll need to consult jsonld-java as to whether the writer can do what you want.

这篇关于JSON-LD空白节点到Apache Jena中的嵌套对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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