rdf:resource、rdf:about 和 rdf:ID 之间的区别

发布于 2024-11-30 09:29:30 字数 210 浏览 0 评论 0原文

rdf:resourcerdf:aboutrdf:ID 之间的概念差异是什么?我做了一些调查,但我还不清楚它们之间的区别。例如,第一次声明资源时是否使用rdf:IDrdf:resource用于引用已经存在的资源等。

如果您提供一些小例子,我会很高兴。

What are the conceptual differences between rdf:resource, rdf:about, and rdf:ID. I did some investigation but the difference between them are not clear for me yet. For example, whether rdf:ID is used when declaring a resource for the first time, rdf:resource is used for referencing an already existing resource, etc.

I would be glad if you provide some little examples.

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

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

发布评论

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

评论(2

來不及說愛妳 2024-12-07 09:29:30

需要明确的是,这只是关于一种特殊的 rdf 编写方式:即 RDF/XML。其他语法不具有这些差异。

排除了该免责声明:

我们要做的是编写以下形式的语句:

subject predicate object

特别是:

subjectURI predicate objectURI

那么我们如何在 RDF/XML 中引入主题和对象 URI?

  1. rdf:about 设置语句的主题 URI,它可以是绝对的 (http://example.com/) 或相对于文档的 BASE 解析(例如/foo/bar#frag)。 (就像 html 中的 href 一样)
  2. rdf:resource 设置语句的对象 URI,同样可以是绝对的或相对的。
  3. rdf:ID 设置主题 URI,但只能在本文档内。一个ID也只能使用一次。非常类似于 html 中的 id="baz"

不鼓励使用 rdf:ID,因为

  1. 您可以将其替换为 rdf:about 或使用片段 #baz 的 rdf:resource code>
  2. 如果多次使用相同的 id,可能会导致 xml 问题。

也就是说,它是多余的并且是潜在的错误来源。

回想起来,通常只需要一个属性来指定 URI,因为从 RDF/XML 语法中可以看出某事物是主语还是宾语:(

<ex:Foo ...> - subject
  <ex:prop ... /> - property then object
</ex:Foo>

<ex:Foo ...> - subject
  <ex:prop> - property
    <ex:Bar ... /> - subject (and implictly an object chaining from previous) 
...

经验法则:奇数行 rdf:about,偶数行,rdf:resource

并且在元素上同时使用rdf:aboutrdf:resource几乎总是一个错误(你是无论处于主语位置还是宾语位置)。

tl;dr

避免使用rdf:ID。使用 rdf:about 和 rdf:resource 与 href 非常相似,前者用于主题,后者用于对象。

附加

忘记提及 rdf:ID 可以在属性元素上使用,但它做了一些您可能会发现意想不到的事情:它具体化了三元组。避免使用rdf:ID

To be clear this is only about a particular way of writing rdf: namely RDF/XML. Other syntaxes don't feature these differences.

With that disclaimer out of the way:

What we're trying to do is write statements of the form:

subject predicate object

and in particular:

subjectURI predicate objectURI

So how do we introduce subject and object URIs in RDF/XML?

  1. rdf:about sets the subject URI of a statement, which may be absolute (http://example.com/) or resolved relative to the BASE of the document (e.g. /foo/bar, #frag). (Like href in html)
  2. rdf:resource sets the object URI of a statement, once again either absolute or relative.
  3. rdf:ID sets the subject URI, but it can only be within this document. An ID can also only be used once. Very like <a name="baz"> or id="baz" in html.

rdf:ID is discouraged since

  1. you can replace it with an rdf:about or rdf:resource with a fragment #baz and
  2. it can cause xml issues if you use the same id more than once.

That is, it's redundant and a potential source of errors.

In retrospect there typically only needs to be one attribute to specify a URI, since whether something is a subject or object is apparent from the RDF/XML syntax:

<ex:Foo ...> - subject
  <ex:prop ... /> - property then object
</ex:Foo>

<ex:Foo ...> - subject
  <ex:prop> - property
    <ex:Bar ... /> - subject (and implictly an object chaining from previous) 
...

(rule of thumb: odd lines rdf:about, even lines, rdf:resource)

and using both rdf:about and rdf:resource on an element is almost always an error (you're either in a subject position or object position).

tl;dr

Avoid rdf:ID. Use rdf:about and rdf:resource much like an href, the former for subject, the latter for objects.

Additional

Forgot to mention that rdf:ID can be used on a property element, but it does something you may find unexpected: it reifies the triple. Avoid rdf:ID.

淡莣 2024-12-07 09:29:30

我想澄清所提供答案中的一些要点,但仅限于 rdf:ID 和 rdf:about。

这些标签用于构建 URI。如果未提供完整的 URI(例如 rdf:ID="x"),则生成的 URI 相对于通常从文档位置派生的范围内基本 URI,但可以使用 xml:base 属性指定。

(上面提到的)要点是 rdf:about 可能是一个完全限定的 URI,因此很容易设置它。

rdf:ID 不能是完全限定的 URI,但是,如果您手动设置 xml:base 属性,您仍然可以控制它。

因此,我的一般经验法则是使用 rdf:about 作为“全局已知”标识符(当您希望 URI 始终相同时),并在描述 URI 不是的本地资源时使用 rdf:ID关心当前文档之外的内容。

I would like to clarify a few of the excellent points in the provided answer, but only with respect to rdf:ID and rdf:about.

The tags are used to build a URI. If the full URI is not provided (such as rdf:ID="x"), then the generated URI is relative to the in-scope base URI usually derived from the document's location, but it can be specified with the xml:base attribute.

The point (mentioned above) is that rdf:about may be a fully qualified URI, so it is easy to just set it.

rdf:ID cannot be a fully qualified URI, but, you can still control that if you manually set the xml:base attribute.

The general rule of thumb for me, therefore, is to use rdf:about for a "globally known" identifier (when you want the URI to always be the same) and to use rdf:ID when describing a local resource whose URI is not cared about outside of the current document.

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