使用 GWT 将 OWL 数据从客户端传输到服务器
我正在开发一个使用 GWT 开发的 Web 应用程序。我还使用 OWL 本体和 Jena 框架来构建应用程序中的语义内容。
应用程序中的一个简单功能是从用户处获取一些数据并将其发送到服务器端以使用本体存储为数据图。我想一种方法是将数据存储为相当于本体类的 java 类对象,并使用 GWT 异步通信发送它们。为了将 OWL 类转换为 java,我使用了 Jastor。
我的问题是,服务器收到java类后,是否可以使用Jena和/或Jastor的功能轻松地将其转换为OWL个体并将其添加到数据图中?例如,在服务器端接口实现中,我们这样调用:
Public void StoreUser (User userObj) {
//User: a Jastor created java class. userObj is instantiated using the user data on the client side.
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
//Open the ontology here using inputstream and ontModel.read!
Individual indiv = (Individual) userObj.resource();
//Add the individual to the model here! }
不幸的是,我无法找到任何可以将现有个体添加到模型中的 Jena 函数。
您是否会建议另一种将本体数据传递到服务器端并存储它的方法,而不是使用 Jastor 创建的类(例如使用 XML 文件)?
感谢您的帮助
I am working on a web application which is being developed using GWT. I am also using OWL ontologies and Jena framework to structure semantic contents in the application.
A simple function in the application would be getting some data from the user and send it to the servers side to be stored as a data graph using the ontology. I suppose one way would be to store the data as java class objects equivalent to the ontology classes and send them using the GWT async communication. To convert OWL classes to java, I used Jastor.
My question is that after the server receives the java class, is it possible to easily convert is to an OWL individual and add it to the data graph, using the functions of Jena and/or Jastor? For instance in the server side interface implementation we call something like this:
Public void StoreUser (User userObj) {
//User: a Jastor created java class. userObj is instantiated using the user data on the client side.
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
//Open the ontology here using inputstream and ontModel.read!
Individual indiv = (Individual) userObj.resource();
//Add the individual to the model here! }
Unfortunately I wasn't able to find any Jena function that can add an existing individual to the model.
Would you suggest another way to pass the ontology data to server side and store it, rather than using Jastor created classes (for instance using an XML file)?
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案分为两部分。首先,
Individual
是 JenaResource
的子类,它绝对是您可以添加到模型中的东西。但是,单个资源、属性或文字不会存储在模型
中。Model
仅存储三元组,在 Java API 中表示为Statement
对象。因此,要向模型添加一些资源,您必须将其包含在三元组中。在 Jena 中,个体被定义为三元组的主语,其谓词为 rdf:type 且其客体不是内置语言类之一。因此,如果您有:(
注意:这个例子完全是虚构的!),那么
ex:my_car
将是一个个体,但ex:Ferrari
不会(因为 OWLClass
是内置类型)。因此,要将您的个体添加到您的模型中,您只需断言它是某种类型。由于我不了解 GWT 并且不使用 Jastor,因此我无法确定通常属于 JenaIndividual
一部分的类型关联在序列化后是否保留。我怀疑不是,在这种情况下,您需要使用其他方法来确定要添加的个体的类型,或者使用与 rdf:type 不同的谓词将资源添加到模型
。话虽如此,就我个人而言,我可能根本不会以这种方式解决你的问题。通常,当我使用服务器端 RDF 的客户端表示时,我仅将最少的信息(例如 URI 和标签)作为 JSON 发送到客户端。如果我需要有关给定资源的更多数据,我可以将其与初始 JSON 序列化一起发送,或者只是进行 Ajax 调用。但是,正如我所说,我不使用 GWT,因此这些建议可能对您没有任何用处。
There are two parts to the answer. First, an
Individual
is a sub-class of a JenaResource
, which is definitely something that you can add to a model. However, individual resources, or properties or literals are not stored in aModel
. AModel
stores only triples, represented asStatement
objects in the Java API. So to add some resource to a model, you have to include it in a triple.In Jena, an individual is defined as a subject of a triple whose predicate is
rdf:type
and whose object is not one of the built-in language classes. So if you have:(note: this example is entirely fictitious!), then
ex:my_car
would be an individual, butex:Ferrari
would not (because OWLClass
is a built-in type). So, to add your individual to your model, you just need to assert that it is of some type. Since I don't know GWT and don't use Jastor, I can't say whether the type association that is normally part of a JenaIndividual
is retained after serialization. I suspect not, in which case you'll need to have some other means of determining the type of the individual you want to add, or use a different predicate thanrdf:type
to add the resource to the theModel
.All that said, personally I probably wouldn't solve your problem this way at all. Typically, when I'm working with client-side representations of server-side RDF, I send just the minimal information (e.g. URI and label) to the client as JSON. If I need any more data on a given resource, I either send it along with the initial JSON serialization, or it's just an Ajax call away. But, as I say, I don't use GWT so that advice may not be of any use to you.