新手问题:如何用rdf表达关系?

发布于 2024-12-02 10:13:51 字数 628 浏览 0 评论 0原文

我知道这听起来非常新手,但即使在阅读了 W3 学校的一些关于 RDF 的教程并阅读了入门书之后,我似乎仍无法理解如何用 XML 表达简单的主谓宾 rdf 关系。

假设我有一个这样的概念:

我有一辆汽车。 我的车有一个 GPS 接收器。 汽车当前的 GPS 坐标为 X 纬度、Y 经度。

我是否将其表示为

<RDF>
 <Owner Name="me">
  <has>car</has>
 <car>
  <has>gpsreceiver</has>
  <has><cordinates X="somevalue", Y="somevalue"></has>
 </car>
 </Owner>
</RDF>

是这样写的?我难以理解的是主语、宾语和谓词如何映射到元素和属性。

一旦我解决了这个问题,最终我希望“car”成为它自己的模式,所以我可以引用它的命名空间并只说“我拥有汽车模型 ABC 车牌 DEF,现在坐标为 12.34 ”。

拜托,请透露一些信息吗?在我束手无策的情况下,我周围似乎没有人知道 rdf 或本体论来启发我:-(

I know this sounds extremely newbieish, but even after going through some of the tutorials on W3 schools on RDF and reading the primer, I cannot seem to fathom how a simple subject-predicate-object rdf relationship is expressed in XML.

Let's say I have a concept like this:

I have a car.
My car has a gps receiver.
The car's current gps coordinates are X latitude, Y longitude.

Do I represent this as

<RDF>
 <Owner Name="me">
  <has>car</has>
 <car>
  <has>gpsreceiver</has>
  <has><cordinates X="somevalue", Y="somevalue"></has>
 </car>
 </Owner>
</RDF>

Is this how it's written? What I have trouble understanding is how subjects, objects and predicates map into elements and attributes.

once I've sorted this out, ultimately I'd like "car" to be its own schema, so I can just refer to its namespace and just say things like "I own car model ABC licence plate DEF that is now at 12.34 coordinates".

Please, please shed some light? At my wits' end and no one around me seems to know rdf or ontologies to enlighten me :-(

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

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

发布评论

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

评论(3

无声静候 2024-12-09 10:13:51

我同意其他响应者的观点,即您不应该担心 XML 语法,但我也不建议立即考虑三元组。首先,首先清楚地思考您要建模的事物,然后三元组就会更加明显。

所以,你有一个东西,你的汽车,它是一种汽车。一般来说,成为任何类型的汽车,和特别是你的汽车,是两个不同的概念。因此,您需要两个单独的名称(RDF 将其称为资源)来表示所有汽车的类和您的汽车的实例。同样,有些东西通常是 GPS,特别是汽车中的 GPS。假设有一个合适的命名空间,那么:

:car127 rdf:type :Car .
:gps99 rdf:type :GPS.

这是一个三元组,表示给定的汽车(主题 car127)是(谓词 rdf:type)所有汽车(对象汽车),同样适用于 GPS。

你的车归尼娜所有,她是一个人。因此,这又是两个关系,一个表示 Nina 是一个人,另一个表示 Nina 拥有该特定汽车(通过重新使用标识该汽车的相同资源):(

:nina rdf:type foaf:Person.
:nina foaf:name "Nina".
:car127 :ownedBy :nina.

好的,我添加了一个额外的三元组来关联资源 URI :nina 改为 Nina)。

特定的 GPS 是特定汽车的一个组件:

:car127 :containsComponent :gps99.

现在,我们非正式地说 GPS“具有”给定的纬度和经度位置。显然,这些随着时间的推移而改变(如果没有,就买一辆新车:)。您可以通过将 x 和 y 谓词直接附加到 GPS 资源并重复更新模型中的值来对此进行建模。但如果您考虑一下您的 GPS 在特定时间提供一系列读数,它似乎更清晰、更具描述性。然后我们有:

:gps99 :reading [
    rdf:type :Reading;
    :lat 51.14276;
    :long -2.71619;
    :at "2011-09-02T123400"^^xsd:dateTime
].

方括号 [...] 是引入新资源的一种简写方式,该资源的属性 - 关系 - 我们可以描述,但我们不知道或不知道其身份关心。从技术上讲,它被称为匿名节点或 bNode,但这不是现在需要担心的细节。只需注意 GPS 设备与 :Reading 类型的资源之间存在一种关系(':reading')(注意大写 R - 这是区分识别类和其他类型的资源的约定)资源)。该阅读资源有四个属性:类型、观察到的纬度和经度以及阅读时间。如果我们愿意,我们可以为其他时间点添加更多读数,这将有助于对轨道进行建模……但那是另一个讨论了!

I agree with the other responders that you should not worry about the XML syntax, but I would also not suggest thinking about the triples immediately either. First start with thinking clearly about the things you're trying to model, then the triples will be more obvious.

So, you have a thing, your car, which is a kind of car. Being any kind of car in general, and being your car in particular, are two different notions. So you'll need two separate names - RDF calls them resources - to represent the class of all cars and the instance of your car. Likewise, there are things that are GPS's in general, and the GPS in your car in particular. Assuming a suitable namespace, then:

:car127 rdf:type :Car .
:gps99 rdf:type :GPS.

That's a triple expressing that a given car (subject car127) is a member of (predicate rdf:type) the class of all cars (object Car), and similarly one for the GPS.

Your car is owned by Nina, who is a person. So that's two more relationships, one saying that Nina is a person, and one that Nina owns that specific car (by re-using the same resource identifying the car):

:nina rdf:type foaf:Person.
:nina foaf:name "Nina".
:car127 :ownedBy :nina.

(OK, I added an extra triple to relate the resource URI :nina to the name Nina).

The specific GPS is a component of the specific car:

:car127 :containsComponent :gps99.

Now, we say informally that the GPS "has" a given lat and long position. Clearly these change over time (if not, get a new car :). You could model this by having the x and y predicates directly attached to the GPS resource, and repeatedly updating the values in the model. But if you think about your GPS giving a series of readings at particular times, it seems a bit clearer and more descriptive. Then we have:

:gps99 :reading [
    rdf:type :Reading;
    :lat 51.14276;
    :long -2.71619;
    :at "2011-09-02T123400"^^xsd:dateTime
].

The square brackets [...] is a short-hand way of introducing a new resource whose properties - relationships - we can describe but whose identity we don't know or don't care about. Technically it's called an anonymous node or bNode, but that's not a detail to worry about now. It's enough to note that there's a relationship (':reading') from the GPS device to a resource of type :Reading (note the capital R - that's a convention to distinguish resources that identify classes from other kinds of resource). This reading resource has four properties: a type, the observed lat and long, and the time of the reading. We could, if we wanted, add more readings for other points in time, which would build up to modelling a track ... but that's another discussion!

恋你朝朝暮暮 2024-12-09 10:13:51

我会尽量不去考虑您需要的 XML 是什么样子,该规范允许使用多种方法来序列化相同的信息,因此我会尝试以三元组的形式来考虑它。

对于你的例子:

:Me :owns :MyCar .
:MyCar :hasPart :GpsReceiver .
:MyCar :hasXPosition "x" .
:MyCar :hasYPosition "y" .

这是一种相当基本的表达方式,还有其他选择,例如皮埃尔建议的方式。

RDF 中的所有内容都表示为三元组,因此请尝试考虑如何以三元组表示数据,然后使用可用的库/工具为您生成 RDF/XML 等序列化。

I would try not to ever think about what you need the XML to look like, the specification allows for multiple ways to serialize the same information so I would try and think about it in triples.

So for your example:

:Me :owns :MyCar .
:MyCar :hasPart :GpsReceiver .
:MyCar :hasXPosition "x" .
:MyCar :hasYPosition "y" .

This is a fairly basic way of expressing it and there are alternatives such as what Pierre has suggested.

Everything in RDF is represented as triples so try to think about how you'd represent your data in triples, then use the available libraries/tools to generate the serializations like RDF/XML for you.

骷髅 2024-12-09 10:13:51

我会写(忽略命名空间 decl)

<rdf:RDF >
 <!-- about 'me' -->
 <my:Owner rd:about="http://example.com/me">
  <my:has rdf:resource="http://example.com/thecar"/>
 </my:Owner>

 <!-- about the car -->
 <my:Car rdf:about="http://example.com/thecar">
  <my:hasPosition>
     <my:Gpsreceiver>
         <my:X>somevalue</my:X>
         <my:Y>somevalue</my:Y>
      </my:Gpsreceiver>
   </my:hasPosition>
 </my:Car>
</rdf:RDF>

您可以在以下位置验证您的 rdf:http://www.w3。 org/RDF/Validator/

I would write (ignoring the namespaces decl)

<rdf:RDF >
 <!-- about 'me' -->
 <my:Owner rd:about="http://example.com/me">
  <my:has rdf:resource="http://example.com/thecar"/>
 </my:Owner>

 <!-- about the car -->
 <my:Car rdf:about="http://example.com/thecar">
  <my:hasPosition>
     <my:Gpsreceiver>
         <my:X>somevalue</my:X>
         <my:Y>somevalue</my:Y>
      </my:Gpsreceiver>
   </my:hasPosition>
 </my:Car>
</rdf:RDF>

You can validate your rdf at: http://www.w3.org/RDF/Validator/

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