新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   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求助]如何给模型添加base语句 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3234 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [Jena求助]如何给模型添加base语句 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     Jiasui 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:62
      门派:XML.ORG.CN
      注册:2005/11/24

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Jiasui发送一个短消息 把Jiasui加入好友 查看Jiasui的个人资料 搜索Jiasui在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看Jiasui的博客楼主
    发贴心情 [Jena求助]如何给模型添加base语句

    我用jena写owl文件的时候,写出的文件头如下:

    <rdf:RDF
        xmlns:fdod="http://www.fudan.edu.cn/fdod#"
        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:owl="http://www.w3.org/2002/07/owl#"
        xmlns:daml="http://www.daml.org/2001/03/daml+oil#"
        xmlns:dc="http://purl.org/dc/elements/1.1/">

    没有xmlns:base,请问怎么才能使用jena api 添加xmlns:base

    谢谢


       收藏   分享  
    顶(0)
      




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

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jpz6311whu发送一个短消息 把jpz6311whu加入好友 查看jpz6311whu的个人资料 搜索jpz6311whu在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jpz6311whu的博客2
    发贴心情 
    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/1/20 16:32:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/13 17:06:37

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

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