新手问题:如何用rdf表达关系?
我知道这听起来非常新手,但即使在阅读了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我同意其他响应者的观点,即您不应该担心 XML 语法,但我也不建议立即考虑三元组。首先,首先清楚地思考您要建模的事物,然后三元组就会更加明显。
所以,你有一个东西,你的汽车,它是一种汽车。一般来说,成为任何类型的汽车,和特别是你的汽车,是两个不同的概念。因此,您需要两个单独的名称(RDF 将其称为资源)来表示所有汽车的类和您的汽车的实例。同样,有些东西通常是 GPS,特别是汽车中的 GPS。假设有一个合适的命名空间,那么:
这是一个三元组,表示给定的汽车(主题
car127
)是(谓词rdf:type
)所有汽车(对象汽车
),同样适用于 GPS。你的车归尼娜所有,她是一个人。因此,这又是两个关系,一个表示 Nina 是一个人,另一个表示 Nina 拥有该特定汽车(通过重新使用标识该汽车的相同资源):(
好的,我添加了一个额外的三元组来关联资源 URI
:nina
改为 Nina)。特定的 GPS 是特定汽车的一个组件:
现在,我们非正式地说 GPS“具有”给定的纬度和经度位置。显然,这些随着时间的推移而改变(如果没有,就买一辆新车:)。您可以通过将 x 和 y 谓词直接附加到 GPS 资源并重复更新模型中的值来对此进行建模。但如果您考虑一下您的 GPS 在特定时间提供一系列读数,它似乎更清晰、更具描述性。然后我们有:
方括号
[...]
是引入新资源的一种简写方式,该资源的属性 - 关系 - 我们可以描述,但我们不知道或不知道其身份关心。从技术上讲,它被称为匿名节点或 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:
That's a triple expressing that a given car (subject
car127
) is a member of (predicaterdf:type
) the class of all cars (objectCar
), 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):
(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:
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:
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!我会尽量不去考虑您需要的 XML 是什么样子,该规范允许使用多种方法来序列化相同的信息,因此我会尝试以三元组的形式来考虑它。
对于你的例子:
这是一种相当基本的表达方式,还有其他选择,例如皮埃尔建议的方式。
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:
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.
我会写(忽略命名空间 decl)
您可以在以下位置验证您的 rdf:http://www.w3。 org/RDF/Validator/
I would write (ignoring the namespaces decl)
You can validate your rdf at: http://www.w3.org/RDF/Validator/