为什么某些rdf文件不包含< rdf:说明rdf:about = ...&gt ;? [英] Why some rdf files does not contain <rdf:Description rdf:about=...>?

查看:134
本文介绍了为什么某些rdf文件不包含< rdf:说明rdf:about = ...&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jena编写一个描述在线帖子的rdf文件.根据我正在使用的sioc本体/名称空间,例如,有以下内容:

I'm using Jena to write a rdf file that describes online posts. According to the sioc ontology/namespace that I'm using there is, for instance, the following:

  • 类别:sioc:Post
  • 属性:sioc:has_creator

如何在耶拿(Jena)中将sioc:Post包含为文件

How can I, in Jena, include the sioc:Post in the file as

<sioc:Post rdf:about="http://example.com/vb/1035092"> 

代替

<rdf:Description rdf:about="http://example.com/vb/1035092">

什么是最佳做法?

推荐答案

到目前为止,这两个答案都很好:

Both of the answers so far make good points:

  • 您不应该特别注意RDF图的特定序列化,因为存在许多不同的序列化,并且应该使用公开 graph 的API来访问它们,而不是序列化. (例如,请参见我以前的回答之一中的不要使用XPath查询RDF(或OWL)有关取决于特定XML序列化的注释.)
  • 您看到的区别是,最简单的RDF/XML序列化将使用许多rdf:Description元素,并且这些元素将包含rdf:type元素以指示所描述元素的类型.但是,RDF/XML序列化格式定义了许多缩写,可用于使图的序列化更短,更易读,并且在某些情况下更像传统的XML文档.其他人提到使用类型作为元素名称只是这样的缩写之一,但是我认为在这一点上值得研究规范.此特殊缩写在 2.13类型的节点:
  • You should not pay much attention to the particular serialization of your RDF graph, because there are lots of different serializations, and you should be accessing them using an API that exposes the graph, not the serialization. (See, for instance, Don't query RDF (or OWL) with XPath in one of my previous answers, for some comments about depending on a particular XML serialization.)
  • The difference that you're seeing is that the most simple RDF/XML serialization will use lots of rdf:Description elements, and these will contain rdf:type elements to indicate the types of the described element. However, the RDF/XML serialization format defines many abbreviations that can be used to make the serialization of a graph much shorter, more readable, and, in some cases, more like a traditional XML document. Others have mentioned that using the type as the element name is just one such abbreviation, but I think it's worth examining the spec on this point. This particular abbreviation is defined in 2.13 Typed Nodes:

RDF图通常具有主题的rdf:type谓词 节点.这些在图中通常称为类型化节点,或者 RDF/XML中的类型化节点元素. RDF/XML允许该三元组为 表达得更简洁.通过替换rdf:Description节点 具有与 RDF URI 类型关系的值的引用.当然有可能 是多个rdf:type谓词,但只能以这种方式使用一个谓词, 其他的必须保留为属性元素或属性.

It is common for RDF graphs to have rdf:type predicates from subject nodes. These are conventionally called typed nodes in the graph, or typed node elements in the RDF/XML. RDF/XML allows this triple to be expressed more concisely. by replacing the rdf:Description node element name with the namespaced-element corresponding to the RDF URI reference of the value of the type relationship. There may, of course, be multiple rdf:type predicates but only one can be used in this way, the others must remain as property elements or property attributes.

类型化的节点元素通常在内置的RDF/XML中使用 RDF词汇中的类:rdf:Seqrdf:Bagrdf:Altrdf:Statementrdf:Propertyrdf:List.

The typed node elements are commonly used in RDF/XML with the built-in classes in the RDF vocabulary: rdf:Seq, rdf:Bag, rdf:Alt, rdf:Statement, rdf:Property and rdf:List.

例如,可以将示例14中的RDF/XML编写为 示例15.

For example, the RDF/XML in Example 14 could be written as shown in Example 15.

示例14:使用rdf:type的完整示例( example14.rdf 输出 example14.nt )

Example 14: Complete example with rdf:type (example14.rdf output example14.nt)

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:ex="http://example.org/stuff/1.0/">
  <rdf:Description rdf:about="http://example.org/thing">
    <rdf:type rdf:resource="http://example.org/stuff/1.0/Document"/>
    <dc:title>A marvelous thing</dc:title>
  </rdf:Description>
</rdf:RDF>

示例15:使用键入的节点元素替换rdf:type的完整示例( example15.rdf 输出 example15 .nt )

Example 15: Complete example using a typed node element to replace an rdf:type (example15.rdf output example15.nt)

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:ex="http://example.org/stuff/1.0/">
  <ex:Document rdf:about="http://example.org/thing">
    <dc:title>A marvelous thing</dc:title>
  </ex:Document>
</rdf:RDF>

如果使用的是Jena,则可以对RDF/XML输出的格式进行广泛控制.这些选项记录在高级RDF/XML输出文档部分.但是,对于您想要的情况,只需在RDF/XMLRDF/XML-ABBREV中进行序列化即可处理您要执行的操作.例如,使用Jena命令行rdfcat工具查看结果.这是我们的数据(在Turtle中):

If you're using Jena, you can get extensive control over the way that your RDF/XML output is formatted. These options are documented in the Advanced RDF/XML Output section of the documentation. However, for the case that you want, simply serializing in RDF/XML versus RDF/XML-ABBREV will take care of what you want to do. For instance, look at the results using the Jena command line rdfcat tool. Here's our data (in Turtle):

# The actual namespace doesn't matter for this example.
@prefix sioc: <http://example.org/> . 

<http://example.com/vb/1035092>
  a sioc:Post ;
  sioc:has_creator "someone" .

让我们将其转换为简单的RDF/XML:

Let's convert this to simple RDF/XML:

$ rdfcat -out RDF/XML data.n3
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:sioc="http://example.org/" > 
  <rdf:Description rdf:about="http://example.com/vb/1035092">
    <rdf:type rdf:resource="http://example.org/Post"/>
    <sioc:has_creator>someone</sioc:has_creator>
  </rdf:Description>
</rdf:RDF>

现在让我们将其转换为RDF/XML-ABBREV:

Now let's convert it to RDF/XML-ABBREV:

$ rdfcat -out RDF/XML-ABBREV data.n3
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:sioc="http://example.org/">
  <sioc:Post rdf:about="http://example.com/vb/1035092">
    <sioc:has_creator>someone</sioc:has_creator>
  </sioc:Post>
</rdf:RDF>

在第一种情况下,您看到带有rdf:typesioc:has_creator子元素的rdf:Description元素,但是在第二种情况下,您看到仅具有sioc:has_creator子元素的sioc:Post元素.

In the first case you see an rdf:Description element with rdf:type and sioc:has_creator subelements, but in the second case you see a sioc:Post element with only a sioc:has_creator subelement.

关于最佳做法,我不知道这真的很重要. RDF/XML-ABBREV通常会短一些,因此将减少传输,磁盘存储上的网络开销,并且更易于阅读.不过,更简单的RDF/XML编写起来会更快.在大多数图表上,这没有什么大不同,但是生成RDF/XML-ABBREV可能会非常昂贵,因为

As to best practice, I don't know that it really matters. The RDF/XML-ABBREV will typically be a bit shorter, so would incur less network overhead on transmission, storage on disk, and would be easier to read. The simpler RDF/XML will be a faster to write, though. On most graphs this won't make a big a difference, but generating RDF/XML-ABBREV can be pretty expensive, as a recent thread on the Jena mailing list discusses.

这篇关于为什么某些rdf文件不包含&lt; rdf:说明rdf:about = ...&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆