gpt4 book ai didi

java - 从 JSON 转换为 JSON-LD

转载 作者:行者123 更新时间:2023-11-29 10:12:28 27 4
gpt4 key购买 nike

<分区>

我正在做一个项目,它要求我们使用一个现有的 json-ld 服务。我们说 json。我仍在研究 http://www.w3.org/TR/json-ld/文档以及如何转换 json > json-ld(和返回)。

一些问题.. 如果我提供 2 个这样的上下文..

"@context": [
"http://example/test1/core.jsonld",
"http://example2/test2/core.jsonld"
],

key 如何知道要应用哪个前缀?例如

(test1 or test2)name : ..
(test1 or test2)date : ..
(test1 or test2)address : ..

到目前为止,我对它的工作原理的理解是,任何 json 都可以转换为 json ld。我们需要为其提供上下文,以便它知道“iri”或 namespace 。

此外,我正在使用的当前示例 json-ld 也有一些没有定义前缀的键,所以我想有一个默认值,但没有任何东西告诉我默认值是什么(没有@vocab,字面上只是定义的两个上下文)。我想默认值是一个上下文,但在这种情况下我有 2 个。

如果我错了请纠正我,但所有 json 都可以转换为 json-ld,反之亦然?我正在寻找 Java 解决方案 ATM。

我想要的一个非常基本的例子

{
"id": 1,
"name": "A green door",
"price": 12.50,
}

成为

{
@context{
test : www.example.com/test/core.json-ld
test2 : www.example.com/test2/core.json-ld
}
"id": 1,
"test:name": "A green door",
"test2:price": 12.50,
}

编辑:所以这是服务对我的期望的示例

{
"@context": [
"http://test.net/abcd/contexts/core.jsonld",
"http://test.net/abcd/contexts/def/4.0/core.jsonld"
],

"startDate": { "@value": "2009-11-21T22:17:10Z", "@type": "xsd:dateTime" },
"endDate": { "@value": "2005-13-24T22:01:01Z", "@type": "xsd:dateTime" },
"comment": "my comment",
"example": [{
"properties": {
"name": "test name",
"description": "test description",
"geometry": { "objVal": "POINT (127.25 3.243)", "confidence": "abcd-c:MED" },
"def:width": { "decimalVal" : 50, "units": "abcd-u:meters" },
"def:length": { "decimalVal" : 75, "units": "abcd-u:meters" },
"def:height": { "decimalVal" : 200, "units": "abcd-u:meters" },
"def:status": "operational",
"def:typeCode": "building"
},
"metadata": {
"@id": "object/123-32132-12321f",
"type": [ "def:Building" ],
"def:confidence": { "@id": "abcd-c:HIGH" },
"def:typeCode": "building"
}
}],
"def:classification": "classified",
"def:confidence": { "@id": "abcd-c:HIGH" },
"def:indicator": { "@value": "true", "@type": "xsd:boolean" },
"def:levelCode": { "@id": "def-cl:FULL" },
"source": {
"@id": "remote-store/12321fd-cdsf143221",
"mediaType": "image/jpeg",
"startDate": { "@value": "2001-11-11T12:02:02Z", "@type": "xsd:dateTime" },
"def:classification": "classified",
"def:producer": "ABC",
"name": "another name",
"describedby": "source/123123123-f21321f"
}
}

当然,我当前的 json 看起来不是这样的,我可以构建类似的结构,但我觉得如果我只需将 @context 添加到我当前的 json 并将其传递给服务,那就太简单了,因为它向我展示了它的期望。听起来我也许可以做到这一点,并且让现有的服务读取带有注释的 json 与我提供的示例 json-ld 相同

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