gpt4 book ai didi

json-ld - 这是 JSON-LD 索引映射的正确使用吗?

转载 作者:行者123 更新时间:2023-12-03 21:44:10 27 4
gpt4 key购买 nike

我想以 json-ld 格式创建一组人,但我需要保留一些键而不是使用数组,所以我首先尝试了这个:

{
"@context" : {
"@base" : "http://www.example.com/data/",
"@vocab" : "http://www.example.com/vocab#",
"name" : "schema:name",
"people" : {
"@container" : "@index",
"@id" : "people"
},
"schema" : "http://schema.org/"
},
"@id" : "http://www.example.com",
"people" : {
"person1" : {
"@id" : "people/person1",
"name" : "Person 1"
},
"person2" : {
"@id" : "people/person2",
"name" : "Person 2"
},
"person3" : {
"@id" : "people/person3",
"name" : "Person 3"
},
"person4" : {
"@id" : "people/person4",
"name" : "Person 4"
}
}
}

在 JSON-LD Playground 中测试它,一切看起来都很好,N-Quads 结果显示如下:
<http://www.example.com/data/people/person1> <http://schema.org/name> "Person 1" .
<http://www.example.com/data/people/person2> <http://schema.org/name> "Person 2" .
<http://www.example.com/data/people/person3> <http://schema.org/name> "Person 3" .
<http://www.example.com/data/people/person4> <http://schema.org/name> "Person 4" .
<http://www.example.com> <http://www.example.com/vocab#people> <http://www.example.com/data/people/person1> .
<http://www.example.com> <http://www.example.com/vocab#people> <http://www.example.com/data/people/person2> .
<http://www.example.com> <http://www.example.com/vocab#people> <http://www.example.com/data/people/person3> .
<http://www.example.com> <http://www.example.com/vocab#people> <http://www.example.com/data/people/person4> .

然后我想添加一个 schema:knows 属性也保留键而不使用这样的数组:
{
"@context" : {
"@base" : "http://www.example.com/data/",
"@vocab" : "http://www.example.com/vocab#",
"knows" : {
"@container" : "@index",
"@id" : "schema:knows",
"@type" : "@id"
},
"name" : "schema:name",
"people" : {
"@container" : "@index",
"@id" : "people"
},
"schema" : "http://schema.org/"
},
"@id" : "http://www.example.com",
"people" : {
"person1" : {
"@id" : "people/person1",
"knows" : {
"person2" : "people/person2",
"person3" : "people/person3"
},
"name" : "Person 1"
},
"person2" : {
"@id" : "people/person2",
"name" : "Person 2"
},
"person3" : {
"@id" : "people/person3",
"name" : "Person 3"
},
"person4" : {
"@id" : "people/person4",
"name" : "Person 4"
}
}
}

这次当我在操场上测试时,它返回以下错误:

{ "name": "jsonld.SyntaxError", "message": "Invalid JSON-LD syntax; conflicting @index property detected.", "details": { "code": "conflicting indexes", "subject": { "@id": "http://www.example.com/data/people/person2", "@index": "person2" } } }



那么什么是保留键而不使用数组或使用索引映射的正确方法的替代方法?

问候

最佳答案

这是对的。您在 jsonld.js ( which I already reported ) 中发现了一个错误。您可以尝试运行示例 in my playground或使用 Gregg Kellogg's RDF distiller service .两者都返回您期望的三元组。

关于json-ld - 这是 JSON-LD 索引映射的正确使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28836484/

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