本体推理的一个例子

引自http://hi.baidu.com/wxmsona/blog/item/de8e54cbe2ee544df21fe7d4.html

 

近日在学习本体,我参考了网上的一 个族谱的例子

“本体”这个术语来自于哲学,它是研究世界上的各种实体以及他们是怎么关联的科学。本体是对应用领域概念化的显示的解释说明,为某领域提供了一个共 享通用的理解,从而无论是人还是应用系统之间都能够有效地进行语义上的理解和通讯。studer认为,本体是:“共享概念模型的明确的形式化规范说明”。 这包括了4层含义:
      概念化(conceptualization)
      通过抽象出客观世界中一些现象的相关概念而得到的模型,其表示的含义独立于具体的环境状态
      明确(explicit)
      所使用的概念及使用这些概念的约束都有明确的定义
      形式化(formal)
      本体应是计算机可读的。
      共享(share)
      知识本体中体现的是共同认可的知识,反映的是相关领域中公认的概念集,它所针对的是团体而不是个体。本体的目标是捕获相关的领域的知识,提供对该领域知识 的共同理解,确定该陋域内共同认可的词汇,并从不同层次的形式化模式上给出这些词汇和词汇之间相互关系的明确定义。

下面给出一个例子

首先是本体文件:family.owl

规则文件:family.rules:

首先贴出推理的代码:

package com.jena.rule.reasoner;

import java.util.List;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.util.*;
import com.hp.hpl.jena.vocabulary.ReasonerVocabulary;

public class FamilyReasoner {
public void InferenceRelation(Resource a, Resource b) {
   Model model = ModelFactory.createDefaultModel();
   model.read("file:family.owl");
   List rules = Rule.rulesFromURL("file:family.rules");

   GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
   reasoner.setOWLTranslation(true);
   reasoner.setDerivationLogging(true);
   reasoner.setTransitiveClosureCaching(true);
   OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
     model);
   Resource configuration = om.createResource();
   configuration.addProperty(ReasonerVocabulary.PROPruleMode, "hybrid");

   InfModel inf = ModelFactory.createInfModel(reasoner, om);
   StmtIterator stmtIter = inf.listStatements(a, null, b);
   if (!stmtIter.hasNext()) {
    System.out.println("there is no relation between "
      + a.getLocalName() + " and " + b.getLocalName());
    System.out.println("\n-------------------\n");
   }
   while (stmtIter.hasNext()) {
    Statement s = stmtIter.nextStatement();
    System.out.println("Relation between " + a.getLocalName() + " and "
      + b.getLocalName() + " is :");
    System.out.println(a.getLocalName() + " "
      + s.getPredicate().getLocalName() + " " + b.getLocalName());
    System.out.println("\n-------------------\n");
    // System.out.println(s);
   }
}

public static void main(String[] args) {
   FamilyReasoner f = new FamilyReasoner();
   Model m = FileManager.get().loadModel("file:family.owl");
   String NS = "
http://www.semanticweb.org/ontologies/2010/0/family.owl #";
   Resource Jim = m.getResource(NS + "Jim");
   Resource John = m.getResource(NS + "John");
   Resource Lucy = m.getResource(NS + "Lucy");
   Resource Kate = m.getResource(NS + "Kate");
   Resource Sam = m.getResource(NS + "Sam");
   Resource James = m.createResource(NS + "James");
   f.InferenceRelation(Jim, John);
   f.InferenceRelation(John, Jim);
   f.InferenceRelation(John, Sam);
   f.InferenceRelation(Lucy, John);
   f.InferenceRelation(Kate, Sam);
   f.InferenceRelation(Sam, Kate);
   f.InferenceRelation(James, John);
}
}

希望对有些朋友有帮助。。。。。。

参考:

jena 推理:http://jena.sourceforge.net/inference/index.html

protege:http://protege.stanford.edu/

一个前辈的博客,本文参考了他的例子:http://hi.baidu.com/zhumzhu/blog/category/%B1%BE%CC%E5%BA%CD%D3%EF%D2%E5%CD%F8          

一个在线的博客教程 http://www.crabone.com/index.php/protege-introduction

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值