新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   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等。
    [返回] 中文XML论坛 - 专业的XML技术讨论区W3CHINA.ORG讨论区 - Web新技术讨论『 Semantic Web(语义Web)/描述逻辑/本体 』 → 关于jena输出rdf文档的命名空间问题?[求助] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3814 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 关于jena输出rdf文档的命名空间问题?[求助] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     badguy_tj 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(Java考了96分!)
      文章:55
      积分:316
      门派:W3CHINA.ORG
      注册:2005/5/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给badguy_tj发送一个短消息 把badguy_tj加入好友 查看badguy_tj的个人资料 搜索badguy_tj在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看badguy_tj的博客楼主
    发贴心情 关于jena输出rdf文档的命名空间问题?[求助]

    请问用jena输出rdf的时候,命名空间为什么都是像:
    <rdf:RDF xmlns:j.0="......"
        xmlns:j.1="......"
        xmlns:rdf="......"
        xmlns:j.2="......" >
    的形式啊?
    怎么样才能使输出的命名空间不是j.0、j.1、j.2......这样的形式,而是我自定义的形式呢?

    还有请问一下jena能用来建rdfs吗?


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    不是因为有些事情难以做到,我们才失去自信的;而是因为我们失去自信,有些事情才显得难以做到。 ======================== * * 自信、进取、独立 * * ========================

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/3/8 22:29:00
     
     qsz888_2006 帅哥哟,离线,有人找我吗?
      
      
      等级:大二(研究C++)
      文章:36
      积分:212
      门派:XML.ORG.CN
      注册:2006/2/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给qsz888_2006发送一个短消息 把qsz888_2006加入好友 查看qsz888_2006的个人资料 搜索qsz888_2006在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看qsz888_2006的博客2
    发贴心情 
    这个在jena的文档里都有例子的,如何建立rdf文档以及使用jena的解析
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/3/9 7:45:00
     
     badguy_tj 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(Java考了96分!)
      文章:55
      积分:316
      门派:W3CHINA.ORG
      注册:2005/5/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给badguy_tj发送一个短消息 把badguy_tj加入好友 查看badguy_tj的个人资料 搜索badguy_tj在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看badguy_tj的博客3
    发贴心情 
    我怎么没找到这些例子?
    在哪

    ----------------------------------------------
    不是因为有些事情难以做到,我们才失去自信的;而是因为我们失去自信,有些事情才显得难以做到。 ======================== * * 自信、进取、独立 * * ========================

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

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jpz6311whu发送一个短消息 把jpz6311whu加入好友 查看jpz6311whu的个人资料 搜索jpz6311whu在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jpz6311whu的博客4
    发贴心情 
    Controlling Prefixes
    explicit prefix definitions
    In the previous section, we saw that the output XML declared a namespace prefix vcard and used that prefix to abbreviate URIs. While RDF uses only the full URIs, and not this shortened form, Jena provides was of controlling the namespaces used on output with its prefix mappings. Here's a simple example.

    Model m = ModelFactory.createDefaultModel();
    String nsA = "http://somewhere/else#";
    String nsB = "http://nowhere/else#";
    Resource root = m.createResource( nsA + "root" );
    Property P = m.createProperty( nsA + "P" );
    Property Q = m.createProperty( nsB + "Q" );
    Resource x = m.createResource( nsA + "x" );
    Resource y = m.createResource( nsA + "y" );
    Resource z = m.createResource( nsA + "z" );
    m.add( root, P, x ).add( root, P, y ).add( y, Q, z );
    System.out.println( "# -- no special prefixes defined" );
    m.write( System.out );
    System.out.println( "# -- nsA defined" );
    m.setNsPrefix( "nsA", nsA );
    m.write( System.out );
    System.out.println( "# -- nsA and cat defined" );
    m.setNsPrefix( "cat", nsB );
    m.write( System.out );

    The output from this fragment is three lots of RDF/XML, with three different prefix mappings. First the default, with no prefixes other than the standard ones:

    # -- no special prefixes defined

    <rdf:RDF
        xmlns:j.0="http://nowhere/else#"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:j.1="http://somewhere/else#" >
      <rdf:Description rdf:about="http://somewhere/else#root">
        <j.1:P rdf:resource="http://somewhere/else#x"/>
        <j.1:P rdf:resource="http://somewhere/else#y"/>
      </rdf:Description>
      <rdf:Description rdf:about="http://somewhere/else#y">
        <j.0:Q rdf:resource="http://somewhere/else#z"/>
      </rdf:Description>
    </rdf:RDF>

    We see that the rdf namespace is declared automatically, since it is required for tags such as <RDF:rdf> and <rdf:resource>. Namespace declarations are also needed for using the two properties P and Q, but since their namespaces have not been introduced to the model, they get invented namespace names: j.0 and j.1.
    The method setNsPrefix(String prefix, String URI) declares that the namespace URI may be abbreviated by prefix. Jena requires that prefix be a legal XML namespace name, and that URI ends with a non-name character. The RDF/XML writer will turn these prefix declarations into XML namespace declarations and use them in its output:


    # -- nsA defined

    <rdf:RDF
        xmlns:j.0="http://nowhere/else#"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:nsA="http://somewhere/else#" >
      <rdf:Description rdf:about="http://somewhere/else#root">
        <nsA:P rdf:resource="http://somewhere/else#x"/>
        <nsA:P rdf:resource="http://somewhere/else#y"/>
      </rdf:Description>
      <rdf:Description rdf:about="http://somewhere/else#y">
        <j.0:Q rdf:resource="http://somewhere/else#z"/>
      </rdf:Description>
    </rdf:RDF>

    The other namespace still gets the constructed name, but the nsA name is now used in the property tags. There's no need for the prefix name to have anything to do with the variables in the Jena code:

    # -- nsA and cat defined

    <rdf:RDF
        xmlns:cat="http://nowhere/else#"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:nsA="http://somewhere/else#" >
      <rdf:Description rdf:about="http://somewhere/else#root">
        <nsA:P rdf:resource="http://somewhere/else#x"/>
        <nsA:P rdf:resource="http://somewhere/else#y"/>
      </rdf:Description>
      <rdf:Description rdf:about="http://somewhere/else#y">
        <cat:Q rdf:resource="http://somewhere/else#z"/>
      </rdf:Description>
    </rdf:RDF>

    Both prefixes are used for output, and no generated prefixes are needed.
    implicit prefix definitions
    As well as prefix declarations provided by calls to setNsPrefix, Jena will remember the prefixes that were used in input to model.read().
    Take the output produced by the previous fragment, and paste it into some file, with URL file:/tmp/fragment.rdf say. Then run the code:


    Model m2 = ModelFactory.createDefaultModel();
    m2.read( "file:/tmp/fragment.rdf" );
    m2.write( System.out );

    You'll see that the prefixes from the input are preserved in the output. All the prefixes are written, even if they're not used anywhere. You can remove a prefix with removeNsPrefix(String prefix) if you don't want it in the output.
    Since NTriples doesn't have any short way of writing URIs, it takes no notice of prefixes on output and doesn't provide any on input. The notation N3, also supported by Jena, does have short prefixed names, and records them on input and uses them on output.

    Jena has further operations on the prefix mappings that a model holds, such as extracting a Java Map of the exiting mappings, or adding a whole group of mappings at once; see the documentation for PrefixMapping for details.

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/3/9 10:23:00
     
     badguy_tj 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(Java考了96分!)
      文章:55
      积分:316
      门派:W3CHINA.ORG
      注册:2005/5/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给badguy_tj发送一个短消息 把badguy_tj加入好友 查看badguy_tj的个人资料 搜索badguy_tj在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看badguy_tj的博客5
    发贴心情 
    谢谢

    ----------------------------------------------
    不是因为有些事情难以做到,我们才失去自信的;而是因为我们失去自信,有些事情才显得难以做到。 ======================== * * 自信、进取、独立 * * ========================

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/3/9 15:03:00
     
     Ambrosia 美女呀,离线,快来找我吧!
      
      
      威望:1
      头衔:天使
      等级:计算机学士学位
      文章:377
      积分:2304
      门派:XHTML.ORG.CN
      注册:2006/2/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Ambrosia发送一个短消息 把Ambrosia加入好友 查看Ambrosia的个人资料 搜索Ambrosia在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看Ambrosia的博客6
    发贴心情 
    请问楼上牛牛的这段话的出处,有没有类似jena使用手册之类的?谢谢拉!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/3/10 12:01:00
     
     jpz6311whu 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      等级:研三(收到微软亚洲研究院的Offer了)(版主)
      文章:1718
      积分:10610
      门派:W3CHINA.ORG
      注册:2005/4/12

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

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

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