如何使用 Jena 框架加载基于本体的内存模型?

发布于 2024-10-16 23:21:50 字数 693 浏览 1 评论 0原文

我想知道如何从使用 Jena 框架的本体加载一个模型,在该模型中我将检索本体中定义的完全相同的语义。我发现了Jean本体API 提供了在本体模型、类等上工作的可能性

。然后给出以下示例:

<owl:Class rdf:ID="DigitalCamera">
  <rdf:type owl:ObjectProperty />
</owl:Class>

可以这样做:

Resource r = myModel.getResource( myNS + "DigitalCamera" );
OntClass cls = (OntClass) r.as( OntClass.class );

但是我正在寻找直接接触 DigitalCamera 类/实例的方法,而不是通过 OntClass 或资源,如下所示:

DigitalCamera camera = new DigitalCamera();

然后当搜索该相机的某个属性时,我可以直接访问它并像 DSL 一样专注于数据的语义。 耶拿是否提出了这种代表任何本体论的专用(生成?)框架?

谢谢

I am wondering how to, from an ontology using Jena framework, load a model in which I will retrieve the exact same semantic defined in the ontology. I found about Jean ontology API
giving the possibility to work on ontology models, classes, etc.

Then giving the following example :

<owl:Class rdf:ID="DigitalCamera">
  <rdf:type owl:ObjectProperty />
</owl:Class>

It is possible to do :

Resource r = myModel.getResource( myNS + "DigitalCamera" );
OntClass cls = (OntClass) r.as( OntClass.class );

However I am searching to get my hands directly on DigitalCamera class/instances and not passing through OntClass or Resource as followed :

DigitalCamera camera = new DigitalCamera();

Then when searching for a certain property of that camera, I could access directly it and stay focus on the semantic of the datas like a DSL.
Does Jena propose this kind of dedicated (generated ?) framework representing whatever ontology?

Thanks

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

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

发布评论

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

评论(1

丢了幸福的猪 2024-10-23 23:21:50

在执行您所要求的操作时存在一个概念问题,即 RDF 的优点是数据模型具有可塑性。这有时被表达为“任何人都可以对任何事情说任何话”。换句话说,您的应用程序状态完全由图表中任意时刻的内容定义。假设资源 r 当前具有 rdf:type foaf:Person,那么该图的更改是完全可能且合法的,因此 r 具有,例如,改为rdf:type skos:Concept。或者说,两者兼而有之。因此,使用某种 ORM 将资源表示为不变的 Java 类 PersonConcept 可能会导致不完整或过时的风险。这(部分)是 Jena 不这样做的原因:Jena 中的状态完全基于 RDF 图中的内容。

也就是说,如果您愿意接受这种风险,或者您知道在您的应用程序中从资源 URI 到 Java 对象类的映射很少或根本不会发生根本性的改变,那么有一些 Jena 扩展可以帮助您。我建议以 JenaBean 为例。

There's a conceptual problem doing what you are asking for, which is that a strength of RDF is that the data model is malleable. This is sometimes expressed as "anyone can say anything about anything". In other words, your application state is entirely defined by what is in the graph at any one time. Suppose resource r currently has rdf:type foaf:Person, it's perfectly possible and legal for that graph to change so that r has, say, rdf:type skos:Concept instead. Or, indeed, to be both. Hence using some sort of ORM to represent a resource as an unchanging Java class Person or Concept risks becoming incomplete or stale. This is (partly) why Jena doesn't do that: state in Jena is entirely based on what's in the RDF graph.

That said, if you are willing to accept this risk, or you know that in your application there is little or no chance that the mapping from resource URI's to Java object classes will change radically, there are some Jena extensions that can help you. I'd suggest looking at JenaBean as one example.

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