我有一个关于在另一个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>Main event有多个子事件,比如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嵌入到每个SubEvent中,如下所示:
<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>发布于 2016-01-14 04:11:33
可以通过为节点提供URI来标识该节点,该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属性的值:
<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。这将允许您和其他人识别/引用此子事件。)
发布于 2016-01-14 04:11:22
你正在寻找的一个节点标识符(参见http://www.w3.org/TR/json-ld/#node-identifiers)。以URL的形式为每个实体分配一个唯一的标识符,并在引用中使用它:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@id": "http://event.com/#mainEvent",
"@type": "Event",
"name": "MainEvent",
"startDate": "2016-04-21T12:00",
"location": {
...
}
}
</script>在上面你可以看到,我给了事件一个@id。我附加了一个片段(#mainEvent),因为http://event.com/通常会标识页面本身。然后,可以按如下方式引用该事件:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Event",
"name": "SubEvent",
"startDate": "2016-04-21T12:00",
"location": {
...
}
superEvent {
"@id": "http://event.com/#mainEvent"
}
}
</script>如您的示例中所示的嵌入也有效。在这种情况下,您将不需要标识符,因为很清楚什么引用了什么。
https://stackoverflow.com/questions/34761970
复制相似问题