在同一个JENA应用程序中处理多个OWL文件 [英] Handle more than one OWL files in a same JENA application

查看:132
本文介绍了在同一个JENA应用程序中处理多个OWL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个可能需要处理大约2-3个OWL文件的应用程序,以便为同一应用程序提供不同的任务.我正在使用Jena作为我的语义Web框架.我的问题是:我们如何组织/设置这些猫头鹰文件? 我应该读取同一数据集中的所有猫头鹰文件,还是应该为不同的猫头鹰维护不同的数据集. 注意:我不考虑输入的猫头鹰,因为它是由耶拿本身处理的.

I am making an application which may require about 2-3 OWL files to work with, in order to serve different task for the same application. I am using Jena as my semantic web framework. My question is: How do we organize/setup these owl files? Should I read all the owl files in the same dataset or I should maintain different datasets for different owls. Note: I am not considering the Imported owls as it is handled by jena itself.

如果我使用相同的数据集,我该如何区分由OntModel.lisRootHierarchyClasses();之类的函数获得的结果?和其他此类功能. 当我将它们读入OntModel时,是否可以命名本体.

If I use same dataset, how can I differentiate to between he results obtained by functions like OntModel.lisRootHierarchyClasses(); and other such types of functions. Is it possible to name the ontologies when I read them into the OntModel.

因此,我们想了解在同一应用程序中处理多个OWL文件的最佳实践

Hence would like to know the best practice to handle more than one OWL files in a same application

例如: 我将自己的本体读入到TDB数据集支持的ontModel中:

For Example: I read my ontologies in the into an ontModel backed by a TDB dataset:

public static void loadModel(){
    dataset.begin(ReadWrite.WRITE);
    try{    
        ontModel = ModelToOntModel(model);
        FileManager.get().readModel( ontModel, "SourceOwl1.owk");
        FileManager.get().readModel( ontModel, "SourceOwl2.owl");

        registerListener();
        dataset.commit();
    } catch (Exception e){
        System.out.println("Error in Loading model from source!!");
        e.printStackTrace();
    } finally {

        dataset.end();
    }

}

一旦ontmodel准备就绪,用户输入将在任何owl文件中指定一个特定的类(例如:SourceOWL2_ClassA),我还需要处理它的Object属性和datatype属性,并在相同的上下文中为用户提供一些信息

Once the ontmodel is ready a user input specifies a particular class (say : SourceOWL2_ClassA) among any of the owl files, which i further need to process its Object properties and datatype properties and provide user some information in the same context.

但是,为此,SourceOWL1的属性也会被列出,因此会导致错误.此外,SourceOWL1和SourceOWL2的结构有很大不同,其中SourceOWL1包含大约3个导入,而SourceOWL2不包含任何导入.

But in order to do that, properties from SourceOWL1 also get listed and hence cause errors. Further more the structure of the SourceOWL1 and SourceOWL2 are very much different, where SourceOWL1 contains about 3 imports and SourceOWL2 contains none.

推荐答案

经过几天的广泛动手,我找到了解决方案.

After few days of extensive hands on I found the solution.

答案是利用Dataset中的命名模型. 上面代码片段中犯的错误是使用的model/ontModel是从 DefaultModel 生成的,即 Model model = dataset.getDefaultModel(); 被感染者应利用: Model namedmodel = dataset.addNamedModel("NameOfModel");其中NameOfModel可以是任何对开发人员方便的字符串. 之后,将OWL文件加载到相应的namedModel.

The answer is to make use of NAMED MODELS in Dataset. The mistake committed in the above code snippet is that model/ontModel used is generated from the DefaultModel i.e. Model model = dataset.getDefaultModel(); Insted one should make use of : Model namedmodel = dataset.addNamedModel("NameOfModel"); where NameOfModel can be any string convenient for the developer. After which load the OWL files in the respective namedModel.

因此上述功能可以重写如下:

Thus the above function can be re-written as follows:

public static void loadModel(){
dataset.begin(ReadWrite.WRITE);
try{    
    Model namedModel1 = dataset.addNamedModel("NamedModel1");
    OntModel ontModel1 = ModelFactory.createOntologyModel();
    FileManager.get().readModel( ontModel1, "SourceOwl1.owl");
// Load second Model    
    Model namedModel1 = dataset.addNamedModel("NamedModel2");
    OntModel ontModel1 = ModelFactory.createOntologyModel();
    FileManager.get().readModel( ontModel, "SourceOwl2.owl");
// Similarly you can load many other models within same dataset.

    dataset.commit();
} catch (Exception e){
    System.out.println("Error in Loading model from source!!");
    e.printStackTrace();
} finally {

    dataset.end();
}

}

要回答问题中指出的问题: 数据集创建完成后,我们可以使用dataset.getNamedModel("NamedModel1")访问特定于我们需求的不同本体/OntModel,因此将其视为独立于其他本体的ontModel. 由于问题中使用的ontModel是通过dataset.getDefaultModel()生成的,因此在ontModel.lisRootHierarchyClasses()上用于生成所有源猫头鹰的根类.但是现在人们可以使用命名的模型概念访问所需的模型,并且ontModel.lisRootHierarchyClasses()将仅回答特定于该本体的根类.

To answer the problems stated in the question: Once dataset creation is complete we can access the different ontologies / OntModel specific to our requirement by using dataset.getNamedModel("NamedModel1") and hence treat it as a ontModel independent of others. Since the ontModel used in the question was generated via dataset.getDefaultModel() hence on ontModel.lisRootHierarchyClasses() used to result in root classes from all the source owls. But now one can access the desiered model using the named model concept and ontModel.lisRootHierarchyClasses() will answer the root classes specific to that ontology only.

有关命名模型的更多信息,您可以在此处参考 它帮助我弄清了概念.希望也能对您有所帮助.

For more information on Named models you can refer here It helped me clear my concepts.. hope it helps you too..

这篇关于在同一个JENA应用程序中处理多个OWL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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