多个 JSON-LD Schema.org 标签能够表示相同的 ‘object’ 吗?

huangapple go评论65阅读模式
英文:

Can multiple JSON-LD Schema.org tags represent the same 'object'?

问题

我有一个网站,客户要求使用JSON-LD(而不是微数据)schema.org标记。其中一个他们想要的是在每个页面上都有一个基本的'WebPage'标记,包含有关我们在每个页面上拥有的内容的一些信息。另一个是'FAQPage',只会在特定的FAQ页面上添加。这两个标记都将直接添加到页面上作为内联脚本标记。

'FAQPage'继承自'WebPage',因此包含了'WebPage'的所有属性。

如果我只让页脚代码生成一个'WebPage'标记,而FAQ组件生成一个'FAQPage'标记,它们都会以单独的JSON-LD脚本标记的形式出现在页面上 - 我认为这会被解释为两个独立的'网页' - 这不是我们想要的。

是否有可能标记schema标记,以使这两个JSON-LD标记表示彼此的'扩展',而不是独立的标记?由于FAQPage继承自WebPage,我希望有一种方法可以设置一个标识符,显示这两个标记表示相同的页面正在被记录。

(是的,我可以在后端使用逻辑来将有关FAQPage的信息'传递'到页脚,并使页脚组件动态输出FAQPage或WebPage,但这不是我在这里寻求的解决方案。)

英文:

I have a site where the client is requesting JSON-LD (not microdata) schema.org tags. One of the ones they want is a base 'WebPage' tag on every page, with some information about the things we have on every page. Another is a 'FAQPage' that will be added only on the specific FAQ page. Both will be being added directly onto the page as inline script tags.

FAQPage inherits from WebPage, so it contains all the properties of WebPage.

If I just let the Footer code generate a 'WebPage' tag, and the FAQ component generate the 'FAQPage' tag, both will end up on the page as separate JSON-LD script tags - which I believe would be interpreted as two separate 'web pages' - not what we're looking for.

Is it possible to mark up the schema tag so that the two JSON-LD tags represent an 'extending' of eachother, instead? Since FAQPage inherits WebPage, I'm hoping there's a way to set an identifier that shows both are the same Page being documented.

(Yes, I could use logic on the backend to 'pass' information about the FAQPage to the footer, and have the footer component output FAQPage or WebPage dynamically, but that's not what I'm looking for here.)

答案1

得分: 3

@id关键字可用于此目的。它为节点对象提供了一个IRI(或空白节点标识符)形式的标识符。

具有相同@id值的节点对象相同的东西,无论这些东西的类型是否处于继承关系中。

这些IRI不必解析为Web上的文档。如果它们这样做,您应确保保持有关该事物和关于该事物的文档之间的区分。

但是,在您的特定情况下,该事物和关于该事物的文档实际上表示相同的事物。因此,您可以将页面的规范IRI用作@id

<!-- 语言:lang-html -->

&lt;!-- 在页面/faq上 --&gt;

&lt;script type=&quot;application/ld+json&quot;&gt;
{
    &quot;@context&quot;: &quot;https://schema.org&quot;,
    &quot;@type&quot;: &quot;FAQPage&quot;,
    &quot;@id&quot;: &quot;/faq&quot;
}
&lt;/script&gt;

&lt;script type=&quot;application/ld+json&quot;&gt;
{
    &quot;@context&quot;: &quot;https://schema.org&quot;,
    &quot;@type&quot;: &quot;WebPage&quot;,
    &quot;@id&quot;: &quot;/faq&quot;
}
&lt;/script&gt;

在对象表示相同事物但具有不同的@id值的情况下,您可以使用属性owl:sameAs来明确表示关系。但仅支持Schema.org的消费者将不会识别这一点。(Schema.org还有一个sameAs属性,但它有不同的含义。)

英文:

The @id keyword can get used for this. It gives a node object an identifier in the form of an IRI (or a blank node identifier).

Node objects with the same @id value are the same thing, no matter if the types these things have are in an inheritance relationship or not.

These IRIs don’t have to resolve to a document on the Web. If they do, you should make sure to keep the differentiation between the thing and the document about that thing.

However, in your specific case, the thing and the document about that thing represent actually the same. So you could use your page’s canonical IRI as @id:

<!-- language: lang-html -->

&lt;!-- on the page /faq --&gt;

&lt;script type=&quot;application/ld+json&quot;&gt;
{
    &quot;@context&quot;: &quot;https://schema.org&quot;,
    &quot;@type&quot;: &quot;FAQPage&quot;,
    &quot;@id&quot;: &quot;/faq&quot;
}
&lt;/script&gt;

&lt;script type=&quot;application/ld+json&quot;&gt;
{
    &quot;@context&quot;: &quot;https://schema.org&quot;,
    &quot;@type&quot;: &quot;WebPage&quot;,
    &quot;@id&quot;: &quot;/faq&quot;
}
&lt;/script&gt;

In cases where objects represent the same thing, but have different @id values, you can make the relationship explicit by using the property owl:sameAs. But consumers that only support Schema.org won’t recognize this. (Schema.org also has a sameAs property, but it has a different meaning.)

huangapple
  • 本文由 发表于 2023年2月24日 00:11:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547418.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定