编程语言
首页 > 编程语言> > java-Apache Jena中嵌套对象的JSON-LD空白节点

java-Apache Jena中嵌套对象的JSON-LD空白节点

作者:互联网

我有以下示例Turtle文档:

@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:

{
  "@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"
    }
  ]
}

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

{
  "@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有可能吗?它在语义上是否等效?

解决方法:

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

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

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

您需要咨询jsonld-java关于编写者是否可以执行您想要的操作.

标签:json-ld,jena,blank-nodes,java
来源: https://codeday.me/bug/20191109/2010710.html