微数据与 RDFa

发布于 2024-12-28 04:51:41 字数 144 浏览 0 评论 0原文

我有一个关于 RDFa 和 Microdata 的简单问题。

我目前的理解是,RDFa 是将 RDF 实现为 HTML,但对于像我这样的新开发人员来说很复杂,Microdata 似乎非常容易且快速实现。

这两种语义格式还有哪些其他优点和缺点?

I have a quick question about RDFa and Microdata.

My current understanding is that RDFa is RDF implemented into HTML but is complicated for new developers like myself, Microdata seems really easy and quick to implement.

What are the other advantages and disadvantages around these two semantic formats ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剩余の解释 2025-01-04 04:51:41

Microdata 和 RDFa 之间的差异

虽然存在许多(技术上的、较小的)差异,但以下是我认为重要的一些差异(使用我的答案以网站管理员为基础)。

规范

适用性

  • 微数据只能在 (X)HTML5(分别为 WHATWG 定义的 HTML)中使用。

  • RDFa 可用于各种宿主语言,即多种 (X)HTML 变体和 XML(因此也可用于 SVG、MathML、Atom 等)。

    并且可以支持新的主机语言,如 RDFa Core “是用任何标记语言表达结构化数据的属性规范”。

使用多个词汇表

  • 在 Microdata 中,对同一内容使用多个词汇表更加困难,有时甚至是不可能。

  • 由于使用了前缀,RDFa 允许混合词汇表。

使用反向属性

  • Microdata 不提供使用反向属性的方法。对于未定义逆属性的词汇表(例如,它们仅定义 parent 而不是 parentchild),您需要这个。流行的 Schema.org 就是这样一个词汇表(只有一些较旧的例外)。

    虽然 W3C 注释Microdata to RDF定义了实验性的itemprop-reverse,此属性不属于 W3C 或 WHATWG 的一部分Microdata。

  • RDFa 支持使用反向属性(使用 rev 属性)。

语义网

  • 通过使用微数据,您并没有直接参与语义网(并且据我所知微数据并不打算这样做),主要是因为它没有定义为 RDF 序列化(尽管有一些方法从 Microdata 中提取 RDF)。

  • RDFa 是一个 RDF 序列化,而 RDF 是 W3C 语义网


规范RDFa CoreHTML+RDFa 可能比 HTML 微数据,但它是这不是一个“公平”的比较,因为它们提供了更多功能。

与 Microdata 类似的是 RDFa Lite (它“确实可以满足大多数日常需求”),而且这个规范,至少在我看来,比 Microdata 简单得多。

该怎么办?

如果您想支持特定的使用者(例如,搜索引擎和浏览器插件),您应该检查他们有关支持语法的文档。

如果您只想学习一种语法并且没有特定的消费者,(注意,主观意见!)请选择 RDFa。 为什么?

  • RDFa 已经成熟多年,是 W3C Rec,而 Microdata 是一个相对较新的发明,尚未由 W3C 标准化。
  • RDFa 可以在多种语言中使用,而不仅仅是 HTML5。
  • RDFa 允许对相同内容混合使用词汇表,并且它本身支持使用反向属性。

无法决定?两者都用。

请注意,您还可以对同一内容使用多种语法,这样您就可以拥有微数据 RDFa(微格式、 JSON-LD、...)以实现最大兼容性。

  • 这是一个简单的微数据片段:

    约翰·多伊是他的名字。

  • 这是使用 RDFa(Lite)的相同片段:

    John Doe是他的名字。

  • 这里两种语法一起使用:

    John Doe;是他的名字。

但通常没有必要/建议走这条路。

Differences between Microdata and RDFa

While there are many (technical, smaller) differences, here’s a selection of those I consider important (used my answer on Webmasters as a base).

Specifications

  • As W3C’s HTML WG found no volunteer to edit the Microdata specification, it is now merely a W3C Group Note (see history), which means that there are no plans for any further work on it.

    So the Microdata section in WHATWG’s "HTML Living Standard" is the only place where Microdata may evolve. Depending on what gets changed, it may happen that their Microdata becomes incompatible to W3C’s HTML5.

    Update: In 2017, work started again, with the aim to publish Microdata as W3C Recommendation.

  • RDFa is published as W3C Recommendation.

Applicability

  • Microdata can only be used in (X)HTML5 (resp. HTML as defined by the WHATWG).

  • RDFa can be used in various host languages, i.e. several (X)HTML variants and XML (thus also in SVG, MathML, Atom etc.).

    And new host languages can be supported, as RDFa Core "is a specification for attributes to express structured data in any markup language".

Use of multiple vocabularies

  • In Microdata, it’s harder, and sometimes impossible, to use several vocabularies for the same content.

  • Thanks to its use of prefixes, RDFa allows to mix vocabularies.

Use of reverse properties

  • Microdata doesn’t provide a way to use reverse properties. You need this for vocabularies that don’t define inverse properties (e.g., they only define parent instead of parent & child). The popular Schema.org is such a vocabulary (with only a few older exceptions).

    While the W3C Note Microdata to RDF defines the experimental itemprop-reverse, this attribute is not part of W3C’s nor WHATWG’s Microdata.

  • RDFa supports the use of reverse properties (with the rev attribute).

Semantic Web

  • By using Microdata, you are not directly playing part in the Semantic Web (and AFAIK Microdata doesn’t intend to), mostly because it’s not defined as RDF serialization (although there are ways to extract RDF from Microdata).

  • RDFa is an RDF serialization, and RDF is the foundation of W3C’s Semantic Web.


The specifications RDFa Core and HTML+RDFa may be more complex than HTML Microdata, but it’s not a "fair" comparison because they offer more features.

Similar to Microdata would be RDFa Lite (which "does work for most day-to-day needs"), and this spec, at least in my opinion, is way less complex than Microdata.

What to do?

If you want to support specific consumers (for example, a search engine and a browser add-on), you should check their documentation about supported syntaxes.

If you want to learn only one syntax and have no specific consumers in mind, (attention, subjective opinion!) go with RDFa. Why?

  • RDFa matured over the years and is a W3C Rec, while Microdata is a relatively new invention and not standardized by the W3C.
  • RDFa can be used in many languages, not only HTML5.
  • RDFa allows mixed use of vocabularies for the same content, and it natively supports the use of reverse properties.

Can’t decide? Use both.

Note that you can also use several syntaxes for the same content, so you could have Microdata and RDFa (and Microformats, and JSON-LD, and …) for maximum compatibility.

  • Here’s a simple Microdata snippet:

    <p itemscope itemtype="http://schema.org/Person">
      <span itemprop="name">John Doe</span> is his name.
    </p>
    
  • Here’s the same snippet using RDFa (Lite):

    <p typeof="schema:Person">
      <span property="schema:name">John Doe</span> is his name.
    </p>
    
  • And here both syntaxes are used together:

    <p itemscope itemtype="http://schema.org/Person" typeof="schema:Person">
      <span itemprop="name" property="schema:name">John Doe</span> is his name.
    </p>
    

But it’s typically not necessary/recommended to go down this route.

过潦 2025-01-04 04:51:41

从任何语义格式中获得的主要优势是消费者能够重用您的数据。

例如,像 Google 这样的搜索引擎是重复使用您的数据来显示丰富摘要的消费者,例如:

Recipe Rich Snippet

为了确定哪种形式最好,您需要知道您想要定位哪些消费者。例如,Google 在常见问题解答中表示他们只会处理微数据(尽管测试工具现在可以使用 RDFa,因此他们有可能接受 RDFa)。

除非您知道您的目标消费者只接受 RDFa,否则您最好使用微数据。虽然许多 RDFa 消费服务(例如语义搜索引擎 Sindice)也接受微数据,但微数据消费服务不太可能接受 RDFa。

The main advantage you get from any semantic format is the ability for consumers to reuse your data.

For example, search engines like Google are consumers that reuse your data to display Rich Snippets, such as this one:

Recipe Rich Snippet

In order to decide which format is best, you need to know which consumers you want to target. For example, Google says in their FAQ that they will only process microdata (though the testing tool does now work with RDFa, so it is possible that they accept RDFa).

Unless you know that your target consumer only accepts RDFa, you are probably best going with microdata. While many RDFa-consuming services (such as the semantic search engine Sindice) also accept microdata, microdata-consuming services are less likely to accept RDFa.

迷荒 2025-01-04 04:51:41

我不确定 unor 使用 Microdata 和 RDFa 的建议是否是一个好主意。如果您在他的示例中使用 Google 的结构化数据测试工具(或其他类似工具),它会显示重复的数据,这似乎意味着 Google 机器人会在网页上找到两个名为 John Doe 的人,而不是最初的意图。

因此,我假设对给定项目使用一种语法是一个更好的主意(只要它们描述单独的实体,您仍然应该能够混合语法)。

尽管我很高兴在这一点上被证明是错误的。

I'm not certain if unor's suggestion to use both Microdata and RDFa is a good idea. If you use Google's Structured Data Testing Tool (or other similar tools) on his example it shows duplicate data which seems to imply that the Google bot would pick up two people named John Doe on the webpage instead of one which was the original intention.

I'm assuming therefore that using one syntax for a given item is a better idea (you should still be able to mix syntaxes as long as they describe separate entities).

Though I would be happy to be proven wrong on this.

百善笑为先 2025-01-04 04:51:41

我想说这很大程度上取决于用例:对于科学用例,RDF 很常见并用于不同方面。

为了丰富网站,现在推荐使用 JSON-LD,例如 Google。

嵌入在页面标题或标签中的 JavaScript 符号
身体。标记不与用户可见的文本交错,这
使嵌套数据项更容易表达,例如某个国家的国家/地区
活动音乐场地的邮政地址。另外,谷歌可以阅读
JSON-LD 数据动态注入页面内容时,
例如通过 JavaScript 代码或内容中嵌入的小部件
管理系统。

I would say it largely depends on the use case: For Scientific use cases, RDF is common and used in different aspects.

For enriching Websites, JSON-LD is now recommended, for example by Google.

A JavaScript notation embedded in a tag in the page head or
body. The markup is not interleaved with the user-visible text, which
makes nested data items easier to express, such as the Country of a
PostalAddress of a MusicVenue of an Event. Also, Google can read
JSON-LD data when it is dynamically injected into the page's contents,
such as by JavaScript code or embedded widgets in your content
management system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文