我有一个关于在另一个JSON-LD schema.org标记中引用JSON-LD schema.org标记的问题。我有一个包含主事件的页面,该页面位于http://event.com/,这是它的JSON-LD标记。

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
}
</script>


主事件有多个子事件,例如位于http://event.com/sub-event-1/,这是该事件的JSON-LD标记:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
}
</script>


我想做的是将子事件标记为主事件的一部分。是否可以创建从主事件到子事件的引用?像这样:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
  superEvent {
    "url": "http://event.com/"
  }
}
</script>


如果可能,什么是正确的标记以供参考。我找不到有关它的任何信息。

还是需要将MainEvent嵌入到每个子事件中,如下所示:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  },
  "superEvent": {
    "@type": "Event",
    "name": "MainEvent",
    "startDate": "2016-04-21T12:00",
    "location": {
    ...
    }
  }
}
</script>

最佳答案

您可以通过为节点指定@id关键字中指定的URI来标识该节点。该URI可用于引用该节点。

请参阅JSON-LD规范中的“ Node Identifiers”部分。

因此,您的主事件可以获取URI http://example.com/2016-04-21#main-event

<script type="application/ld+json">
{
  "@id": "http://example.com/2016-04-21#main-event",
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00"
}
</script>


您可以将此URI作为子事件的superEvent属性的值:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "superEvent": { "@id": "http://example.com/2016-04-21#main-event" }
}
</script>


(您当然也可以给您的子事件一个@id。这将使您和其他人可以识别/引用此子事件。)

07-24 09:54
查看更多