【问题标题】:How to match on non-existence of property and not output a default value in JSON-LD framing?如何匹配不存在的属性而不在 JSON-LD 框架中输出默认值?
【发布时间】:2023-12-26 12:55:01
【问题描述】:

我有一个schema:ProductGroupschema:ProductModel 节点的图表,我编写了一个框架以嵌套结构输出它,在概念上类似于图书馆书籍章节示例。一切正常,除了框架输出在*ProductGroup 上包含一个isVariantOf: null,我宁愿没有。

{
  "@context": {
    "@vocab": "http://schema.org/",
    "ex": "http://example.com/"
  },
  "@id": "ex:100",
  "@type": "ProductGroup",
  "hasVariant": [...],
  "isVariantOf": null,
  "name": "All The Things"
}

Full example in JSON-LD Playground(在 Flattened 和 Framed 之间切换以使其正确输出)。

*ProductGroup 没有isVariantOf 属性。在我的框架文件中,我匹配这个是空的。但是,我不知道如何在输出中省略空的 isVariantOf 属性。我想我必须设置 @omitDefault 标志,但我无法确定在哪里或如何设置。

{
  "@context": {
    "@vocab": "http://schema.org/",
    "ex": "http://example.com/"
  },
  "@graph": {
    "@type": "ProductGroup",
    "@requireAll": true,
    "isVariantOf": []
  }
}

【问题讨论】:

    标签: schema.org json-ld linked-data


    【解决方案1】:

    Framing Spec 中所述,使用在缺少属性时匹配 机制将带有null 的属性显式添加到输出中,以指示该属性不存在。要删除它,您可以使用框架作为上下文重新压缩结果,因为扩展算法会删除所有具有空值的属性。

    【讨论】:

      最近更新 更多