因为项目要用到Protege中构建的本体,这些本体又在Protege中编辑,所以存储结构是使用其内部的结构。要想使用Jena推理机,必须要将Protege中的KnowledgeBase导出为Jena内兼容的结构。庆幸的是,ProtegeAPI提供的转换接口。
(1)从本地项目中导出Jena Model,并打印所有的Triple,程序如下:
public static void getLocalModel() {
Collection errors = new ArrayList();
Project p = new Project("d:\\human.pprj", errors);
OWLModel owlmodel = (OWLModel) p.getKnowledgeBase();
Iterator<TripleStore> listtriplestore = owlmodel.getTripleStoreModel()
.listUserTripleStores();
while (listtriplestore.hasNext()) {
TripleStore ts = listtriplestore.next();
System.out.println(ts.getName().toString());
Iterator<Triple> itriple = ts.listTriples();
while (itriple.hasNext()) {
Triple triple = itriple.next();
System.out.println("triple:" + triple.getSubject() + ","
+ triple.getPredicate() + "," + triple.getObject());
}
}
owlmodel.getOntModel().write(System.out);
}
(2)从数据库导出Jena Model,并且进行推理,程序如下:
/**
* 从Protege本体数据库中导出Jena本体,并且进行推理
*/
public static void connectTest() {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://IPaddress:3306/protege?useUnicode=true&characterEncoding=UTF-8";
String table = "test";
String user = "root";
String password = "root";
OWLDatabaseKnowledgeBaseFactory factory = new OWLDatabaseKnowledgeBaseFactory();
Collection errors = new ArrayList();
Project prj = Project.createBuildProject(factory, errors);
try {
OWLDatabaseKnowledgeBaseFactory.setSources(prj.getSources(),
driver, url, table, user, password);
prj.createDomainKnowledgeBase(factory, errors, true);
OWLModel owlmodel = (OWLModel) prj.getKnowledgeBase();
Model ont = owlmodel.getOntModel();
ont.write(new FileOutputStream("onto/human_pro.rdf"));
List<Rule> rule = Rule.rulesFromURL("rules/humantest.rules");
Reasoner reasoner = new GenericRuleReasoner(rule);
InfModel inf = ModelFactory.createInfModel(reasoner, ont);
inf.difference(ont).write(
new FileOutputStream("onto/human_infer_pro.rdf"));
} catch (Exception e) {
e.printStackTrace();
} finally {
prj.dispose();
}
}
分享到:
相关推荐
protege本体建模工具
Protégé软件是斯坦福大学基于Java语言开发的本体编辑和知识获取软件,或者说是本体开发工具,也是基于知识的编辑器,属于开放源代码软件。这个软件主要用于语义网中本体的构建,是语义网中本体构建的核心开发工具...
利用本体编辑工具protege5.2版本,建立一个中文人物关系的本体例子,有助于本体学习。
自己翻译的官方的教程,有些地方感觉还是英文原文更能表达意思,所以就是仍然使用的英文,但是看起来没有难度。
Protege构建本体笔记
创建了一个动物(食肉、食草)、植物(叶子、树枝、树)的本体,设置属性能够使用Protege自带的HermiT进行推理。比如狮子属于食肉动物、长劲鹿属于食草动物。
protege可以构造本体模型,基于JAVA开发的开源本体编辑平台,支持OWL Lite、OWL Full、OWL DL三种版本的OWL子语言
protege本体:pizza案例(owl格式)
使用protege建立的三国例子、动植物例子,主要是用来练手,熟悉protege这个软件
使用protege本体构建工具创建的一个本体,练习使用protege工具的人可以以此为练习,并熟练掌握protege工具!
本人使用Protege4的经验要点总结,并对与本体的推理相关部分进行了重点介绍
本体构建工具Protege实现叙词表的可视化 文章不大,但很全面,基本上将Protege如果使用和实现叙词表描述的很清楚,值得收藏。
介绍protege4.1的用法以及举例介绍怎么使用protege4.1进行本体建模
本体 共享概念模型的明确的形式化规范说明 An explicit,formal and shared specification of conceptualization RDF Schema表达能力太弱 没有构词(如FOL 的连接词) 不能声明属性的性质(如传递性,对称性) ...
我写了一个入门教程: protege本体推理(规则推理)实战练习题(附owl源文件) 这是它的配套资源
protege构建的院士本体,推荐使用protege4.2以上,内置推理机,图可以辅助本体建模。
我写了一个讲解详细地入门教程: 《protege本体推理(规则推理)实战练习题(附owl源文件)》 这是它配套资源的第二个版本
使用protege建立简单一个简单的本体,软件可以通过官网去下,中文版的在GitHub上好像有,可以子集去找一下
可以建立资源的本体模型和生成owl原因的代码,方便用户导入其他软件
此文件为本体构建软件4.1的教程,希望对大家学习有帮助,多多下载