是否可以通过编程方式查明两个实例是否属于同一 RDF 类?
是否可以以编程方式找出两个实例是否属于同一类(使用 api,例如 JENA)
Is it possible to find out whether two instances are of the same class, programmatically (Using api such as JENA)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这是对您之前帖子的扩展,所以
I take it this is an extension to your earlier post so
在 SPARQL 中简单:
在 Jena API 中:
不是很优雅。
Easy in SPARQL:
In Jena API:
Not very elegant.
假设您正在使用 Jena 本体 API,这非常简单。请注意,在 RDF 中,给定实例可以有多种类型,因此您的问题实际上是“如何测试两个实例是否具有一种或多种共同类型?”。
我会这样做。假设您要测试的两个实例是
Individual
对象(请注意,您可以使用OntResource
或什至Resource
来执行此操作,只需稍作更改即可代码):列出每个值的 rdf:type 值,并将它们转换为集合,
如果交集非空,它们具有共同的类型:
Assuming you are using the Jena ontology API, it's pretty straightforward. Note that in RDF, a given instance can have many types, so your question is really "how can I test if two instances have one or more types in common?".
I would do it as follows. Assume the two instances you want to test are
Individual
objects (note that you can do this withOntResource
, or evenResource
with a slight change in the code):List the
rdf:type
values for each, and convert them to setsThey have types in common if the intersection is non-empty:
比较他们的班级:
Compare their classes: