gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 02:57:30 24 4
gpt4 key购买 nike

我有以下示例 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/Ex_WriteJsonLD.java

您需要咨询jsonld-java至于作者能不能如你所愿。

关于java - JSON-LD 空白节点到 Apache Jena 中的嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50588066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com