gpt4 book ai didi

rdf - 如何在 JSON-LD 中表示备选方案的集合

转载 作者:行者123 更新时间:2023-12-04 22:31:12 25 4
gpt4 key购买 nike

我的模型中有一些属性,这些属性的值是替代数组(表示一组替代项,只能从中选择一个值)。早些时候,我使用 RDF/XML 来使用 rdf:Alt 执行此操作。看下面的例子

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://ns.example.com/example/">
<rdf:Description>
<ex:prop1>
<rdf:Alt>
<rdf:li>100</rdf:li>
<rdf:li>120</rdf:li>
<rdf:li>130</rdf:li>
</rdf:Alt>
</ex:prop1>
</rdf:Description>
</rdf:RDF>

但现在我想在 JSON-LD 中做同样的事情。我尝试通过在线转换器将上面的代码片段转换为 JSON-LD,并得到以下结果

{
"@context": {
"ex": "http://ns.example.com/example/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@graph": [
{
"@id": "_:g70327238021300",
"ex:prop1": {
"@id": "_:g70327280101680"
}
},
{
"@id": "_:g70327280101680",
"@type": "rdf:Alt",
"rdf:_1": "100",
"rdf:_2": "120",
"rdf:_3": "130"
}
]
}

实际上我发现 rdf:Alt/Seq/Bag 被标记为 archaic通过 w3c。 JSON-LD 中分别有@list 和@set 用于有序数组和无序数组。那么有没有其他方法可以在不使用“rdf:Alt”作为@type 的情况下在 JSON-LD 中执行此操作?

最佳答案

RDFS

在RDFS中,存在RDF Containers (RDF:Container) 和 RDF Collections (rdf:列表)。区别在于容器是开放,而集合是封闭,另见this question .

rdf:Container有3种:rdf:Bagrdf:Seqrdf:Alt.

这些容器之间没有形式上的(即语义上的)区别,而是实用上的。不同之处在于消费者打算如何处理数据,请参阅 this question .

严格来说,RDF 集合和 RDF 容器都不是 RDF 数据模型的一部分,而是特定 RDF 词汇表的元素(尽管这个词汇表很常见)。

JSON-LD

JSON-LD 数据模型与 RDF 不一致,参见例如 this article主要创作者之一。

  • JSON-LD 忽略了openclosed 之间的区别。
  • JSON-LD 忽略了上述实用差异。
  • JSON-LD 保留了有序无序之间的区别。
  • JSON-LD 保持(词汇上)非区别区别 之间的区别,
    识别这个与前一个的区别。

映射

来自 RDFS 1.1:

The same resource may appear in a container more than once.

The first member of the container, i.e. the value of the rdf:_1property, is the default choice.

因此,一般来说,rdf:Alt 的元素不是唯一的,而是有序的。因此,应该使用 @list。但是,如果您的替代方案是唯一且无序的,您可以使用@set

在其他情况下,请注意在没有订单的情况下声明订单没有任何危害。

另见 ISSUE-24用于讨论和激励。

更新

是的,不可能在 JSON-LD 数据模型中表达语用(即与语言语用相关)差异。例如,不可能表达 rdf:Seqrdf:Alt 之间的区别。如果你想表达这些差异,你需要一个词汇。

RDFS就是这样一种词汇表。使用 JSON-LD 作为 RDF 抽象语法的序列化格式,并像以前一样编写 "@type": "rdf:Alt" 等。

您可能对 JSON-LD 中大量的代理 @id 感到困惑。只是不要在 RDF 中使用空白节点,那么 JSON-LD 将如下所示:

{
"@context": {
"ex": "http://example.com/example/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@graph": [
{
"@id": "ex:object1",
"ex:availableOptions": {
"@id": "ex:optionsFor1"
}
},
{
"@id": "ex:optionsFor1",
"@type": "rdf:Alt",
"rdf:_1": "100",
"rdf:_2": "120",
"rdf:_3": "130"
}
]
}

另一种选择是使用其他词汇表,例如schema.org .我不确定这个例子是否正确:

{
"@context": {"schema": "http://schema.org/",
"adobe" : "http://ns.adobe.com/xap/1.0/smp/"},
"@type": "schema:ChooseAction",
"@id": "adobe:price",
"schema:option": ["100", "120", "130"]
}

关于rdf - 如何在 JSON-LD 中表示备选方案的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44959817/

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