在 JSON-LD 中表示重复属性

Representing repeating attributes in JSON-LD

我想知道如何使用 JSON-LD (recommended by Google) and Schema.org specifications. For example, how should we represent an Article with N Comments (N > 1)?

表示重复属性

允许数组作为 comment 值,如下面的示例。似乎是 Google testing tool 喜欢它。

但是可以使用 flat @graph 表示吗?如何?我必须发展一个网站,这种表示可能更容易实现。

我想两者都可以吗?那怎么选择呢?

我的例子:

<script type="application/ld+json">
{
  "@context" : "http:\/\/schema.org",
  "@type" : "Article",
  "url" : "https:\/\/exemple.com/article?id=1234",
  "author" :{"@type" : "Person","name" : "Didier"},
  "image" : "https:\/\/exemple.com/article.jpg",
  "mainEntityOfPage" : "https:\/\/exemple.com",
  "dateModified" : "2018-06-14T19:50:02+02:00",
  "datePublished" : "2018-06-14T19:50:02+02:00",
  "publisher" : {"@type" : "Organization","name" : "exemple.com", "logo" : {"@type" : "ImageObject", "url" : "https:\/\/exemple.com\/logo.png"}},
  "headline" : "my article",
  "text" : "blah blah",
  "commentCount" : 2,
  "comment" : [{
      "author" : {"@type" : "Person", "name" : "Didier"},
      "text" : "comment first!!",
      "dateCreated" : "2018-06-14T21:40:00+02:00"
},{
      "author" : {"@type" : "Person", "name" : "Robert"},
      "text" : "second comment",
      "dateCreated" : "2018-06-14T23:23:00+02:00"
}]
}
</script>

最简单(也是最受支持)的方法是提供一个数组作为值,就像您的代码片段中那样:

"comment": [
  {"@type": "Comment"},
  {"@type": "Comment"}
]

如果您想使用多个顶级项目 (),您需要一种方式来表明这些顶级 Comment 项目是对 Article 的评论。

With @id,您可以为每个项目提供一个 URI,并将此 URI 引用为 属性 值,而不是嵌套项目:

{
  "@context": "http://schema.org",
  "@graph": [
    {
      "@type": "Article",
      "@id": "/articles/foobar",
      "comment": [
        {"@id": "/articles/foobar#comment-1"},
        {"@id": "/articles/foobar#comment-2"}
      ]
    },
    {
      "@type": "Comment",
      "@id": "/articles/foobar#comment-1"
    },
    {
      "@type": "Comment",
      "@id": "/articles/foobar#comment-2"
    }
  ]
}

除了在 Article 下列出评论 URI,您还可以在每个 Comment:

中引用 Article
{
  "@context": "http://schema.org",
  "@graph": [
    {
      "@type": "Article",
      "@id": "/articles/foobar"
    },
    {
      "@type": "Comment",
      "@id": "/articles/foobar#comment-1",
      "@reverse": {"comment": {"@id": "/articles/foobar"}}
    },
    {
      "@type": "Comment",
      "@id": "/articles/foobar#comment-2",
      "@reverse": {"comment": {"@id": "/articles/foobar"}}
    }
  ]
}