新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     >>W3CHINA.ORG讨论区<<     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Semantic Web(语义Web,语义网或语义万维网, Web 3.0)及相关理论,如:Ontology(本体,本体论), OWL(Web Ontology Langauge,Web本体语言), Description Logic(DL, 描述逻辑),RDFa,Ontology Engineering等。
    [返回] W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWLW3CHINA.ORG讨论区 - Web新技术讨论『 Semantic Web(语义Web)/描述逻辑/本体 』 → Jena rules reasoner通用规则推理不出东西来,是神马情况啊?大神快出现吧 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6564 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: Jena rules reasoner通用规则推理不出东西来,是神马情况啊?大神快出现吧 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     alexlinym 帅哥哟,离线,有人找我吗?双鱼座1988-3-5
      
      
      等级:大一新生
      文章:1
      积分:52
      门派:XML.ORG.CN
      注册:2011/3/11

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给alexlinym发送一个短消息 把alexlinym加入好友 查看alexlinym的个人资料 搜索alexlinym在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看alexlinym的博客楼主
    发贴心情 Jena rules reasoner通用规则推理不出东西来,是神马情况啊?大神快出现吧

    test1.owl:

    <?xml version="1.0"?>
    <rdf:RDF
        xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
        xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
        xmlns:swrl="http://www.w3.org/2003/11/swrl#"
        xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
        xmlns="http://www.owl-ontologies.com/Ontology1300450048.owl#"
        xmlns:owl="http://www.w3.org/2002/07/owl#"
      xml:base="http://www.owl-ontologies.com/Ontology1300450048.owl">
      <owl:Ontology rdf:about=""/>
      <owl:Class rdf:ID="Leaf">
        <rdfs:subClassOf>
          <owl:Restriction>
            <owl:allValuesFrom>
              <owl:Class rdf:ID="Branch"/>
            </owl:allValuesFrom>
            <owl:onProperty>
              <owl:ObjectProperty rdf:ID="is_part_of"/>
            </owl:onProperty>
          </owl:Restriction>
        </rdfs:subClassOf>
      </owl:Class>
    </rdf:RDF>

    <!-- Created with Protege (with OWL Plugin 3.4, Build 533)  http://protege.stanford.edu -->

    test1.rules:

    [restriction:(?a rdf:type rdfs:Class),(?b rdf:type rdfs:Class),(?c rdf:type owl:ObjectProperty),(?b owl:onProperty ?c),(?b owl:allValuesFrom ?d),(?a rdfs:subClassOf ?b)-> (?a owl:onProperty ?c),(?a owl:allValuesFrom ?d)]

    其中(?b rdf:type rdfs:Class),我用过(?b rdf:type owl:Restriction),也达不到效果


    package myfinaltest;

    import com.hp.hpl.jena.rdf.model.*;
    import com.hp.hpl.jena.util.FileManager;
    import com.hp.hpl.jena.util.PrintUtil;
    import com.hp.hpl.jena.util.iterator.ExtendedIterator;
    import com.hp.hpl.jena.reasoner.rulesys.Rule;
    import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;

    import java.util.List;
    import java.io.InputStream;

    public class myfinaltest {
    public static void main(String[] args) {
    String BaseURI = "http://www.owl-ontologies.com/Ontology1300450048.owl#"; 
    PrintUtil.registerPrefix("Base", BaseURI);
    String filename="file:F:\\ontology\\test1.owl";
    String spacename="http://www.owl-ontologies.com/Ontology1300450048.owl#";
    String name="Leaf";
      
    InputStream in=FileManager.get().open(filename);
    Model model=ModelFactory.createDefaultModel();
    model.read(in,"");

    //Print Statement before reasoning in Model model
    ExtendedIterator iter_1=model.listStatements();
    int Count1=0;
    while(iter_1.hasNext()){
      Count1++;
      System.out.println("Statement"+Count1+":"+PrintUtil.print(iter_1.next()));
    }
    System.out.println();

    //Load Rules
    List rules=Rule.rulesFromURL("file:F:\\ontology\\test1.rules");  
    GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
    reasoner.setOWLTranslation(true);               
    reasoner.setTransitiveClosureCaching(true);
        
    InfModel infmodel = ModelFactory.createInfModel(reasoner, model);
    //infmodel.write(System.out, "N-TRIPLE");
      
    //Print Statement after reasoning in Model infmodel
    Resource resource_2=infmodel.getResource(spacename+name);
    ExtendedIterator iter_2=infmodel.listStatements(resource_2 ,null, (RDFNode)null);
    int Count2=0;
    while(iter_2.hasNext()){
      Count2++;
      System.out.println("Statement"+Count2+":"+PrintUtil.print(iter_2.next()));
    }  
    }
    }
    输出:
    Statement1:(Base:is_part_of rdf:type owl:ObjectProperty)
    Statement2:(Base:Branch rdf:type owl:Class)
    Statement3:(http://www.owl-ontologies.com/Ontology1300450048.owl rdf:type owl:Ontology)
    Statement4:(Base:Leaf rdfs:subClassOf -14789782:12ece00b99e:-7fff)
    Statement5:(Base:Leaf rdf:type owl:Class)
    Statement6:(-14789782:12ece00b99e:-7fff owl:onProperty Base:is_part_of)
    Statement7:(-14789782:12ece00b99e:-7fff owl:allValuesFrom Base:Branch)
    Statement8:(-14789782:12ece00b99e:-7fff rdf:type owl:Restriction)

    Statement1:(Base:Leaf rdfs:subClassOf -14789782:12ece00b99e:-7fff)
    Statement2:(Base:Leaf rdf:type owl:Class)
    Statement3:(Base:Leaf rdfs:subClassOf Base:Leaf)


    我想得到的是:
    Statement1:(Base:Leaf owl:onProperty Base:is_part_of)
    Statement2:(Base:Leaf owl:allValuesFrom Base:Branch)

    我参考的是http://blog.csdn.net/java_2005/archive/2010/05/28/5630205.aspx


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/3/19 19:53:00
     
     yezhunan3h 帅哥哟,离线,有人找我吗?
      
      
      威望:1
      等级:大二期末(数据结构考了98分!)
      文章:52
      积分:424
      门派:XML.ORG.CN
      注册:2007/12/13

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给yezhunan3h发送一个短消息 把yezhunan3h加入好友 查看yezhunan3h的个人资料 搜索yezhunan3h在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看yezhunan3h的博客2
    发贴心情 
    建议仔细看下rdfs的entailment rules,你想得到的这两条并不能从那里面得到。。  其实有很多看似很直白的东西用rdfs都是推不出来的。。 看看这个slides稍后的一部分。http://www.semantic-web-book.org/w/images/1/12/W2011-05-rdfsemantics.pdf
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/3/22 10:22:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/14 2:10:21

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms