如何在 JSON-LD 中用 Schema.org 表示文章的部分?

How to represent sections of an article with Schema.org in JSON-LD?

我是 JSON-LD 的新手,即使经过几个小时的搜索,我仍然找不到某些问题的明确答案。

我的网站类似于维基百科:它提供了关于特定主题的大量信息,有许多较小的部分、较长的页面等。 页面结构的简单示例:

<article id="animals">
  <header>
    <h1> 1. Animals </h1>
  </header>
  <section id="cats">
    <h2> 1.1 Cats </h2>
    <p> Some information about cats </p>
  </section>
  <section id="dogs">
    <h2> 1.2 Dogs </h2>
    <p> Some information about dogs </p>
  </section>
</article>

我想使用 JSON-LD 标记每个部分。 以下是我的做法(将不必要的属性放在一边):

<script type="application/ld+json">
            {
             "@context": "http://schema.org",
             "@graph": [
            {
              "@type": "CreativeWork",
              "@id": "http://www.example.com/example/#animals",
              "name": "Animals",
              "headline": "Animals",
              "genre": "http://vocab.getty.edu/aat/300048715",
              "url": "http://www.example.com/example/#animals"
            },
            {
              "@type": "CreativeWork",
              "@id": "http://www.example.com/example/#cats",
              "name": "Cats",
              "headline": "Cats",
              "genre": "http://vocab.getty.edu/aat/300048715",
              "url": "http://www.example.com/example/#cats",
              "isPartOf": {
                "@type": "CreativeWork",
                "@id": "http://www.example.com/example/#animals"
              }
            }
             ]
            }
        </script>

1) 经过几个小时的搜索,我还没有真正找到这些部分应该是什么类型。 CreativeWork 是正确的使用吗? genre 属性 使用正确吗?

2) 如何指定节所在的位置?是用url属性完成的吗?是否可以像本例中那样通过指示该部分的 id 来完成?

3) 我还注意到,如果标记这样一个长页面,脚本会变得非常大。应该是这样吗?

Schema.org 没有为 sections/chapters 提供类型。如果你想指定每个部分的数据,你应该使用 CreativeWork 类型,因为这是适用于这种情况的 most-specific 类型。

这些部分使用genre是有道理的,但我认为http://vocab.getty.edu/aat/300048715不合适。我不熟悉这个词汇,也找不到明确的定义,但至少这个词的标题 "articles" 表明它不适合 sections of an文章。

使用带有 url 属性 片段标识符的 URL 非常好,像文章的各个部分一样这样做是有意义的。

整个事情可能是 Article in your case (or one of its child types), and hasPart/isPartOf 可以用于 link ArticleCreativeWork 项。

{
  "@type": "Article",
  "@id": "http://www.example.com/example/#animals",
  "url": "http://www.example.com/example/#animals",
  "name": "Animals",
  "hasPart": [
    {
      "@type": "CreativeWork",
      "@id": "http://www.example.com/example/#cats",
      "url": "http://www.example.com/example/#cats",
      "name": "Cats"
    },
    {
      "@type": "CreativeWork",
      "@id": "http://www.example.com/example/#dogs",
      "url": "http://www.example.com/example/#dogs".
      "name": "Dogs"
    }
  ]
}

所有这些都会导致很长 script,特别是如果您还想使用 articleBody (for the whole article, including all of its sections) and text (for each section), as you have to duplicate/triple much of the content. This is one of the drawbacks of using JSON-LD. You can avoid this problem by using Microdata or RDFa instead. (See a short comparison.)