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

时间:2018-03-12 20:19:13

标签: schema.org 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)我也注意到,如果标记这样的长页面,脚本会变得非常大。它应该是这样的吗?

1 个答案:

答案 0 :(得分:0)

Schema.org没有提供章节/章节的类型。如果您想以任何方式指定有关每个部分的数据,您应该使用CreativeWork类型,因为这是这种情况下最具体的类型。

对这些部分使用genre可能有意义,但我不认为http://vocab.getty.edu/aat/300048715是合适的。我不熟悉这个词汇,也找不到明确的定义,但至少术语的标题“文章”表明它不适合文章的部分

url属性使用带有片段标识符的URL非常合适,对于文章的各个部分来说,这样做是有意义的。

您的案例(或其中一种子类型)可能是Article,而hasPart / isPartOf可用于关联Article使用CreativeWork项。

{
  "@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(对于整篇文章,包括其所有部分)和text(对于每个部分) ),因为你必须复制/三倍的内容。这是使用JSON-LD的缺点之一。您可以使用Microdata或RDFa来避免此问题。 (See a short comparison.