切换耶拿推理机 [英] Toggle Jena Reasoner

查看:110
本文介绍了切换耶拿推理机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jena本体模型( OntModel ),我正在以编程方式对其进行修改.该模型最初是使用默认的ModelFactory方法来创建本体模型(不带参数).问题是,随着程序的运行和模型的更改,默认的Jena Reasoner将运行(并运行,运行,运行).该过程对于我所需的速度来说太慢了,并且在大型数据集上将耗尽内存.

I have a Jena ontology model (OntModel) which I'm modifying programatically. This model was initially created using the default ModelFactory method to create an Ontology model (with no parameters). The problem was, as the program ran and the model was changed, the default Jena Reasoner would run (and run and run and run). The process was entirely too slow for what I need and would run out of memory on large data sets.

我将程序更改为使用

I changed the program to use a different ontology model factory method to create a model with no reasoner. This ran extremely fast and exhibited none of the memory problems I saw earlier (even for very large data sets). The problem with this approach is that I can only access the data by directly using it's direct class type (I can not gain access to objects using it's parent class).

例如,假设我有两个班级资源,花"和种子".这些继承自一个共同的父母,即植物材料".我的程序使用所有种子",运行一个名为"grow"的方法,该方法将种子"对象转换为花"对象.使用推理机"(甚至是微型推理机")时,增长"方法运行太慢,并且内存不足.如果我关闭了推理机,则无法使用植物材料"类访问所有的花"和种子".

For example, imagine I had two class resources, "flower" and "seed". These inherit from a common parent, "plant material". My program takes all the "seeds", runs a method called "grow" which transforms the "seed" object into a "flower" object. The "grow" method runs too slow and runs out of memory when using a Reasoner (even the micro Reasoner). If I turn off the Reasoner, then I can't access all the "flowers" and "seeds" using the "plant material" class.

是否有一种首选的方法(一种令人满意的方法)来实现...允许使用其超类访问对象,同时又快速又不占用内存的能力?

Is there a preferred way (a happy medium) to doing this... allowing the ability to access objects using their superclass while also being fast and not a memory hog?

我一直在寻找一种方法,可以在运行增长"方法时关闭推理机",然后在该方法完成后再将其关闭.这有可能吗?

I've been looking for a way to "turn off the reasoner" while I run my "grow" method and then turn it back one once the method completes. Is this possible somehow?

推荐答案

我得到了一些

I got some help and suggestions, then this is how I solved this problem.

基本上,我可以使用没有推理机的其他模型,将对基本模型的所有更改分批处理,然后用推理机反弹整个模型以获取更新.

Basically, I gained access to another model without a Reasoner, batched all my changes to the basic model, then rebound the full model with the reasoner to get the updates.

这是一些伪代码.它与我的真实"场景不完全匹配,但是您明白了.

Here's some psuedo code. It doesn't exactly match my "real" scenario, but you get the idea.

// Create a model with a reasoner and load the full model from owl files or
// whatever
OntModel fullModel = ModelFactory.createOntologyModel();
fullModel.read(...);

// create a model without a reasoner and load it from the full model with
// reified statements
OntModel basicModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
basicModel.add(fullModel);

// batch modifications to the basic model programatically
//(**** RUNS REALLY QUICK *****)

// rebind the full model
fullModel.rebind();

// continue on....

这篇关于切换耶拿推理机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆