rdf:resource、rdf:about 和 rdf:ID 之间的区别
rdf:resource
、rdf:about
和 rdf:ID
之间的概念差异是什么?我做了一些调查,但我还不清楚它们之间的区别。例如,第一次声明资源时是否使用rdf:ID
、rdf: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要明确的是,这只是关于一种特殊的 rdf 编写方式:即 RDF/XML。其他语法不具有这些差异。
排除了该免责声明:
我们要做的是编写以下形式的语句:
特别是:
那么我们如何在 RDF/XML 中引入主题和对象 URI?
rdf:about
设置语句的主题 URI,它可以是绝对的 (http://example.com/
) 或相对于文档的 BASE 解析(例如/foo/bar
、#frag
)。 (就像 html 中的href
一样)rdf:resource
设置语句的对象 URI,同样可以是绝对的或相对的。rdf:ID
设置主题 URI,但只能在本文档内。一个ID也只能使用一次。非常类似于 html 中的或
id="baz"
。不鼓励使用
rdf:ID
,因为rdf:about
或使用片段#baz
的 rdf:resource code>也就是说,它是多余的并且是潜在的错误来源。
回想起来,通常只需要一个属性来指定 URI,因为从 RDF/XML 语法中可以看出某事物是主语还是宾语:(
经验法则:奇数行
rdf:about
,偶数行,rdf:resource
)并且在元素上同时使用
rdf:about
和rdf: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:
and in particular:
So how do we introduce subject and object URIs in RDF/XML?
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
). (Likehref
in html)rdf:resource
sets the object URI of a statement, once again either absolute or relative.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">
orid="baz"
in html.rdf:ID
is discouraged sincerdf:about
orrdf:resource
with a fragment#baz
andThat 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:
(rule of thumb: odd lines
rdf:about
, even lines,rdf:resource
)and using both
rdf:about
andrdf:resource
on an element is almost always an error (you're either in a subject position or object position).tl;dr
Avoid
rdf:ID
. Userdf:about
andrdf: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. Avoidrdf:ID
.我想澄清所提供答案中的一些要点,但仅限于 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.