简体   繁体   English

切换耶拿推理机

[英]Toggle Jena Reasoner

I have a Jena ontology model (OntModel ) which I'm modifying programatically.我有一个 Jena 本体 model (OntModel ),我正在以编程方式对其进行修改。 This model was initially created using the default ModelFactory method to create an Ontology model (with no parameters) .这个 model 最初是使用默认的 ModelFactory 方法创建的,用于创建本体 model(无参数) The problem was, as the program ran and the model was changed, the default Jena Reasoner would run (and run and run and run).问题是,随着程序的运行和 model 的更改,默认的 Jena Reasoner 将运行(并运行并运行并运行)。 The process was entirely too slow for what I need and would run out of memory on large data sets.这个过程对于我需要的东西来说太慢了,并且在大型数据集上会用完 memory。

I changed the program to use a different ontology model factory method to create a model with no reasoner.我更改了程序以使用不同的本体 model 工厂方法来创建没有推理器的 model。 This ran extremely fast and exhibited none of the memory problems I saw earlier (even for very large data sets).这运行得非常快,并且没有出现我之前看到的 memory 问题(即使对于非常大的数据集)。 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).这种方法的问题是我只能通过直接使用它的直接 class 类型来访问数据(我无法使用它的父类访问对象)。

For example, imagine I had two class resources, "flower" and "seed".例如,假设我有两个 class 资源,“花”和“种子”。 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.我的程序获取所有“种子”,运行一个名为“grow”的方法,将“种子”object 转换为“花”object。 The "grow" method runs too slow and runs out of memory when using a Reasoner (even the micro Reasoner).当使用 Reasoner(甚至是 micro Reasoner)时,“增长”方法运行速度太慢并且用完 memory。 If I turn off the Reasoner, then I can't access all the "flowers" and "seeds" using the "plant material" class.如果我关闭 Reasoner,那么我无法使用“植物材料”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?有没有一种首选的方法(一种快乐的媒介)来做到这一点......允许使用它们的超类访问对象的能力,同时也很快而不是 memory 猪?

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.基本上,我在没有 Reasoner 的情况下获得了另一个 model 的访问权限,将我对基本 model 的所有更改批量化,然后使用推理器重新启动完整的 model 以获取更新。

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....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM