How to do reasoning/inference based on Jena

本文介绍了如何通过Jena框架实现OWL本体论中的自动推理过程。作者最初仅使用Jena进行显式陈述的查询,后来引入了Reasoner组件以支持更复杂的推理任务。文章详细展示了如何设置和应用OWL Reasoner来创建推理模型,并通过查询紫藤的上位词示例说明了推理的效果。

Just realize how to do real reasoning by Jena.

 

Before I just used Jena to query the statments expressed explicitly in ontology. That works, but is so simple, and cannot implement the real reasoning. It just works as a dictionary where no entailment knowledge can be infered.

 

I realize this problem when I set some instances as Symmetric and Transitive. At that time, the old code cannot make infer. I thought it could be, but in fact, not.

 

Now, I had a look and add reasoner into the code, and it can make a rough reasoning now!

(Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); I just use this to create a reasoner, no further restriction. Althugh it is still a rough reasoning which returns all the entailments, a little too big and make the search space too big. Need more improvement.)

 

This article from http://www.ibm.com/developerworks/xml/library/j-jena/ helps most. I copy the last paragraph I used as follows:

 

=========================================

 

Inference with Jena

Given an ontology and a model, Jena's inference engine can derive additional statements that the model doesn't express explicitly. Jena provides several Reasoner types to work with different types of ontology. Because you want to use the OWL ontology with the WordNet model, an OWLReasoner is needed.

The following example shows how to apply your OWL WordNet ontology to the WordNet model itself to create an inference model. I'm actually going to use a subset of the WordNet model here, containing only those nouns beneath "plant life" in the hyponym hierarchy. The reason for using only a subset is that the inference model needs to be held in memory, and the WordNet model is too large for an in-memory model to be practical. The code I used to extract the plants model from the full WordNet model is included in the article source, and is named ExtractPlants.java (see Resources).

First, I'll get an OWLReasoner from the ReasonerRegistry. ReasonerRegistry.getOWLReasoner() returns an OWL reasoner in its standard configuration, which is fine for this simple case. The next step is to bind the reasoner to the WordNet ontology. This operation returns a reasoner ready to apply the ontology's rules. Next I'll use the bound reasoner to create an InfModel from the WordNet model.

Having created an inference model from the original data and the OWL ontology, it can be treated just like any other Model instance. Therefore, as Listing 16 shows, the Java code and RDQL query used with a regular Jena model by FindHypernym.java can be re-applied to the inference model without any changes:


Listing 16. Creating and querying an inference model

// Get a reference to the WordNet plants model
ModelMaker maker = ModelFactory.createModelRDBMaker(connection);
Model model = maker.openModel("wordnet-plants",true);

// Create an OWL reasoner 
Reasoner owlReasoner = ReasonerRegistry.getOWLReasoner();

// Bind the reasoner to the WordNet ontology model
Reasoner wnReasoner = owlReasoner.bindSchema(wnOntology);

// Use the reasoner to create an inference model
InfModel infModel = ModelFactory.createInfModel(wnReasoner, model);

// Set the inference model as the source of the query
query.setSource(infModel);

// Execute the query as normal
QueryEngine qe = new QueryEngine(query);
QueryResults results = qe.exec(initialBinding);

The full listing is available in the article source, named FindInferredHypernyms.java. Listing 17 shows what happens when the inference model is queried for hypernyms of "wisteria":


Listing 17. Running the example FindInferredHypernyms program

$ java FindInferredHypernyms wisteria

Hypernyms found for 'wisteria':

vine:   weak-stemmed plant that derives support from climbing, twining, or creeping along a surface
tracheophyte:   green plant having a vascular system: ferns, gymnosperms, angiosperms
vascular plant: green plant having a vascular system: ferns, gymnosperms, angiosperms
plant life:     a living organism lacking the power of locomotion
flora:  a living organism lacking the power of locomotion
plant:  a living organism lacking the power of locomotion

The information contained in the OWL ontology has allowed Jena to infer that "wisteria" has hypernyms right up through the model.

 

打开链接下载源码: https://pan.quark.cn/s/e23b4cd62d42 Linux运维工程师在IT行业扮演着核心的角色,他们承担着对基于Linux操作系统的服务器进行维护和管理的职责,以保障系统的稳定性和运行效率。Linux运维职业的学习和发展路径是结构化且周密的,它包含了从入门到精通的多个层次。以下是对这一主题的深入解析: 一、入门知识阶段 在Linux运维的学习初期,首要任务是掌握Linux操作系统的基本理念和常用指令。这涉及到对Linux不同发行版(例如Ubuntu、CentOS、Red Hat等)的认识,熟悉文件系统的构造,熟练运用文件和目录操作(诸如ls、cd、mkdir、rm等),以及掌握vi/vim等文本编辑器的使用方法。除此之外,学习Linux中的用户和权限管理、进程管理、网络设置和监控也是这一阶段需要重点关注的内容。 二、高级技术阶段 在基础知识的积累之后,需要进一步深入理解Linux内核、Shell脚本编程、系统服务和守护进程的管理。这一阶段应该熟练运用grep、awk、sed等数据处理工具,以及crontab定时任务的设定。同时,要学会通过系统日志进行故障排查,比如查看/var/log目录下的各种日志文件。对于网络服务的配置与管理,如HTTP(Apache或Nginx)、FTP、DNS、DHCP等,也具有非常重要的意义。 三、自动化与编程脚本 在当代运维工作中,自动化是提升工作效率的关键要素。学习Python或Perl等编程语言,编写自动化脚本来处理日常任务,例如系统备份、监控告警、数据整理等。了解Ansible、Puppet、Chef等配置管理工具,能够帮助实现更大范围的系统部署和管理。 四、性能调优与监控 掌握系统性能参...
内容概要:本文围绕虚拟电厂与电动汽车之间的主从博弈关系,结合条件风险价值(CVaR)理论,构建了一个考虑不确定环境下的优化决策模型。研究通过建立上层虚拟电厂调度优化与下层电动汽车用户充放电响应的双层博弈框架,利用CVaR量化参与主体的风险偏好,提升系统在电价波动、负荷不确定性等风险因素下的鲁棒性与经济性。采用Matlab进行仿真建模与求解,验证了该方法在降低运行风险、提高收益水平及促进可再生能源消纳方面的有效性。文档还提供了丰富的相关研究主题和技术资源,涵盖电力系统优化、智能算法、深度学习、路径规划等多个前沿领域,展现了广泛的技术支持与科研应用潜力。; 适合人群:具备电力系统基础知识、优化理论背景及Matlab编程能力的科研人员,特别适用于从事能源互联网、电动汽车调度、虚拟电厂运营、风险管理与低碳电力系统研究的研究生与高校研究人员。; 使用场景及目标:① 掌握主从博弈在综合能源系统中的建模方法;② 学习CVaR在电力市场风险决策中的集成应用;③ 实践基于Matlab的双层优化模型实现与仿真分析;④ 借助配套资源拓展科研视野,支撑高水平论文撰写与课题申报。; 阅读建议:建议读者结合文中提供的百度网盘资料与公众号资源,获取完整代码、参考文献及复现案例,按照文档目录体系循序渐进地学习,并动手调试仿真程序,深入理解博弈结构设计与风险规避机制的实现细节。
内容概要:本文提出了一种基于递进事件触发框架的孤岛微电网DoS攻击容错二次协同控制方法,旨在解决分布式系统中因通信资源受限及遭受拒绝服务(DoS)攻击所引发的稳定性与安全性问题。通过设计递进式事件触发机制,有效降低控制器间的通信频率,减轻通信负担,同时增强系统对DoS攻击的鲁棒性。该方法融合分布式协同控制策略,在实现电压与频率恢复的同时,保障有功功率的精确均分,并提升电能质量。结合Simulink仿真实验验证,结果表明该控制方案在遭遇DoS攻击时仍能维持微电网的稳定运行,具备良好的实用性与工程应用前景。; 适合人群:具备电力系统、自动化或相关专业背景,熟悉微电网控制、网络安全及仿真工具(如Simulink)的研究人员和工程技术人员,尤其适合从事智能电网安全控制、分布式能源系统设计等方向的研究生与科研工作者。; 使用场景及目标:①解决孤岛微电网在面临DoS攻击时的稳定性与安全性问题;②优化通信资源利用,减少不必要的数据传输;③实现电压频率恢复、功率均分与电能质量提升的多目标协同控制; 阅读建议:读者应结合文中提供的Simulink仿真模型深入理解控制策略的设计逻辑与实现细节,重点关注事件触发条件的设计、攻击场景的建模以及系统性能的对比分析,以便将其应用于类似的安全控制研究中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值