Schema.org JSON-LD 引用

标签 schema.org json-ld

我有一个关于在另一个 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>

最佳答案

您可以通过给它一个 URI 来标识一个节点,在 @id 中指定。关键词。此 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 的值。属性(property):

<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 。这将允许你和其他人识别/引用这个子事件。)

关于Schema.org JSON-LD 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34761970/

相关文章:

javascript - 如何使用 JSON-LD 标记面包屑列表中的最后一个非链接项

wordpress - 在 Yoast 生成的 JSON-LD 模式中更改作者 @id

seo - 谷歌附加链接搜索框

schema.org - 如何将面包屑添加到 Schema.org 中的产品?

php - JSON-LD 总是将单个对象构建为数组

gmail - 什么是有效日期时间/解析器是否损坏?

html - 多个 JSON-LD Schema.org 标签可以代表相同的 'object' 吗?

javascript - 如何在 Javascript 和 HTML 中格式化 JSON?

python - 在 rdflib 中批量编辑三元组的主题

java - 将 Json-Ld 对象数组读入 Apache Jena 中的模型。如何从模型中检索单个对象?