新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   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讨论区 - Web新技术讨论『 Semantic Web(语义Web)/描述逻辑/本体 』 → 关于jena查询推理后的内容问题? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2618 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 关于jena查询推理后的内容问题? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     jiajw0426 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:15
      积分:114
      门派:XML.ORG.CN
      注册:2007/5/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jiajw0426发送一个短消息 把jiajw0426加入好友 查看jiajw0426的个人资料 搜索jiajw0426在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jiajw0426的博客楼主
    发贴心情 关于jena查询推理后的内容问题?

    我建立一个关于字典的本体,主要有两种单词英语单词(eword)和德语单词(gwoed),实现他们之间的翻译,其中eglish_to_german和german_to_eglish是互逆的定义如下:
    <?xml version="1.0"?>
    <!DOCTYPE rdf:RDF [
         <!ENTITY vin  "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#" >
         <!ENTITY food "http://www.w3.org/TR/2003/CR-owl-guide-20030818/food#" >
         <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
         <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
       ]>
    <rdf:RDF xmlns="http://www.owl-ontologies.com/di.owl#"
         xml:base="http://www.owl-ontologies.com/di.owl"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
         xmlns:owl="http://www.w3.org/2002/07/owl#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
        <owl:Ontology rdf:about=""/>
        
        <owl:Class rdf:ID="dictionary"/>
        <dictionary rdf:ID="dictionary_new">
            <content_of rdf:resource="#Kaffee"/>
            <content_of rdf:resource="#Milch"/>
            <content_of rdf:resource="#Kuh"/>
            <content_of rdf:resource="#Katze"/>
            <content_of rdf:resource="#Hund"/>
            <content_of rdf:resource="#milk"/>
            <content_of rdf:resource="#cat"/>
            <content_of rdf:resource="#dog"/>
            <content_of rdf:resource="#cow"/>
            <content_of rdf:resource="#coffee"/>
        </dictionary>
        
        <eword rdf:ID="cat">
        </eword>
        
        <eword rdf:ID="coffee">
        </eword>
        
         <eword rdf:ID="cow">
        </eword>
        
         <eword rdf:ID="dog">
        </eword>
        
         <eword rdf:ID="milk">
        </eword>
        
        <owl:ObjectProperty rdf:ID="content_of">
            <rdfs:domain rdf:resource="#dictionary"/>
            <rdfs:range rdf:resource="#word"/>
        </owl:ObjectProperty>
       
        
       
        <owl:ObjectProperty rdf:ID="eglish_to_german">
            <rdfs:domain rdf:resource="#eword"/>
            <rdfs:range rdf:resource="#gword"/>
            <owl:inverseOf rdf:resource="#german_to_eglish"/>
        </owl:ObjectProperty>
        
         <owl:ObjectProperty rdf:ID="german_to_eglish">
            <rdf:type rdf:resource="&owl;InverseFunctionalProperty"/>
            <rdfs:domain rdf:resource="#gword"/>
            <rdfs:range rdf:resource="#eword"/>
            <owl:inverseOf rdf:resource="#eglish_to_german"/>
        </owl:ObjectProperty>
        
        <owl:Class rdf:ID="eword">
            <rdfs:subClassOf rdf:resource="#word"/>
            <owl:disjointWith rdf:resource="#gword"/>
        </owl:Class>
       
        <owl:Class rdf:ID="gword">
            <rdfs:subClassOf rdf:resource="#word"/>
            <owl:disjointWith rdf:resource="#eword"/>
        </owl:Class>
        
        <gword rdf:ID="Hund">
            <german_to_eglish rdf:resource="#dog"/>
        </gword>
        
        <gword rdf:ID="Kaffee">
            <german_to_eglish rdf:resource="#coffee"/>
        </gword>
        
        <gword rdf:ID="Katze">
            <german_to_eglish rdf:resource="#cat"/>
        </gword>
        
        <gword rdf:ID="Kuh">
            <german_to_eglish rdf:resource="#cow"/>
        </gword>
        
        <gword rdf:ID="Milch">
            <german_to_eglish rdf:resource="#milk"/>
        </gword>
        <owl:Class rdf:ID="word"/>
    </rdf:RDF>
    然后处理程序如下:
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import com.hp.hpl.jena.query.*;
    import com.hp.hpl.jena.rdf.model.*;
    import com.hp.hpl.jena.reasoner.*;


    public class T {

     
     public static void main(String[] args) throws FileNotFoundException {
        String s="PREFIX dictionary:  <http://www.owl-ontologies.com/di.owl#> " +
        "SELECT ?x " +
        "WHERE { dictionary:Katze  dictionary:german_to_eglish   ?x }";
         Model m=ModelFactory.createDefaultModel();
         m.read(new FileInputStream(new File("dictionary.owl")), "");
         Reasoner reasoner=ReasonerRegistry.getOWLReasoner();
         reasoner.bindSchema(m);
         Query query=QueryFactory.create(s);
         InfModel infmodel = ModelFactory.createInfModel(reasoner, m);
        QueryExecution execution=QueryExecutionFactory.create(s, infmodel);
        ResultSet results=execution.execSelect();
        ResultSetFormatter.out(System.out, results, query);

     }

    }

    是输出:
    ------------------
    | x              |
    ==================
    | dictionary:cat |
    ------------------
    而我把查询语句改为:
    String s="PREFIX dictionary:      <http://www.owl-ontologies.com/di.owl#> " +
        "SELECT ?x " +
        "WHERE { dictionary:cat dictionary:english_to_german   ?x }";
    却输出:
    -----
    | x |
    =====
    -----
    我想要的结果是:
    ------------------
    | x              |
    ==================
    | dictionary:Katze |
    ------------------
    请高手指点迷津!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/6/2 9:47:00
     
     jpz6311whu 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      等级:研三(收到微软亚洲研究院的Offer了)(版主)
      文章:1718
      积分:10610
      门派:W3CHINA.ORG
      注册:2005/4/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jpz6311whu发送一个短消息 把jpz6311whu加入好友 查看jpz6311whu的个人资料 搜索jpz6311whu在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jpz6311whu的博客2
    发贴心情 
    呵呵,楼主呀,english 还是 eglish?
    仔细检查一下下你的owl文件吧
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/6/2 10:02:00
     
     jiajw0426 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:15
      积分:114
      门派:XML.ORG.CN
      注册:2007/5/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jiajw0426发送一个短消息 把jiajw0426加入好友 查看jiajw0426的个人资料 搜索jiajw0426在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jiajw0426的博客3
    发贴心情 
    谢谢啊 问题解决论,写错了!又犯低级错误!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/6/2 10:05:00
     
     timothy 帅哥哟,离线,有人找我吗?巨蟹座1982-7-21
      
      
      威望:1
      等级:大四下学期(考上研究生啦!)
      文章:237
      积分:1701
      门派:XML.ORG.CN
      注册:2006/4/4

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给timothy发送一个短消息 把timothy加入好友 查看timothy的个人资料 搜索timothy在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 点击这里发送电邮给timothy 引用回复这个贴子 回复这个贴子 查看timothy的博客4
    发贴心情 
    当然应该是:
    ------------------
    | x              |
    ==================
    | dictionary:cat |
    ------------------

    你仔细看看你的这条语句:
    "SELECT ?x " +
        "WHERE { dictionary:cat dictionary:english_to_german   ?x }";
    的意思,就知道你要查询的目标是什么了!!!

    ----------------------------------------------
    时间永远是向前的!

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/6/2 11:54:00
     
     GoogleAdSense巨蟹座1982-7-21
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 点击这里发送电邮给Google AdSense 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2025/10/8 9:09:20

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

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