以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  [讨论]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=73824)


--  作者:smiles
--  发布时间:4/3/2009 3:10:00 PM

--  [讨论]
OntModel m = ModelFactory.createOntologyModel();
    OntDocumentManager dm = m.getDocumentManager();
  为什么这一句程序的HTTP的地址不能改动呢?  dm.addAltEntry( "http://www.eswc2006.org/technologies/ontology",
                    "D:/portletpayload_serviceprofile.xml" );
谢谢
--  作者:jpz6311whu
--  发布时间:4/3/2009 5:37:00 PM

--  
"http://www.eswc2006.org/technologies/ontology"后面添加#试一试

并且,文件路径写成这种形式:"file:E:\\workplace\\ontology\\workspace\\TG\\src\\";


--  作者:Humphrey
--  发布时间:4/4/2009 8:19:00 AM

--  
URI在语义网文档中是一个必备项目,而且几乎所有的语义网文档中都有基于超文本传输协议的URI。不过如果不写这个URI而只写本地路径应该也是可以的吧?
--  作者:smiles
--  发布时间:4/6/2009 9:55:00 PM

--  
二楼说的我试过了,不行的。
三楼说的就是我想做的。但是我不知道怎样做
多谢
--  作者:Humphrey
--  发布时间:4/7/2009 7:55:00 AM

--  
我们看到的实例基本上都使用包含URL的URI,URI就是定位资源用的,如果URI错误就不可能连接到所需资源,不过理论上这部分是可以用本地路径替代的。但是如果您用现成的程序或者现成的本体库,有可能不能做这样的更改。
如果使用本地路径,需要注意是否转义以及是否有特别的格式要求。
例如斜线的方向,末端是否要用斜线,如果需要转义那么就要注意斜线的条数是否足够。
因为您没有提供完整的程序段、编辑器、推理机以及所用本体的情况,我只能大致上这样解释了。

--  作者:jpz6311whu
--  发布时间:4/7/2009 1:16:00 PM

--  
请楼主把D:/portletpayload_serviceprofile.xml本体库最开头的部分贴出来看看,就是声明命名空间和本体库import的部分
--  作者:smiles
--  发布时间:4/7/2009 2:40:00 PM

--  
<?xml version="1.0" encoding="GB2312"?>
<rdf:RDF
xmlns:owl ="http://www.w3.org/2002/07/owl#"
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd ="http://www.w3.org/2001/XMLSchema#"
xmlns:profile= "http://www.daml.org/services/owl-s/1.1/profile.owl#"
xmlns:service= "http://www.daml.org/services/owl-s/1.1/Service.owl#"
xmlns:grounding= "http://www.daml.org/services/owl-s/1.1/grounding.owl#"
xml:base="http://127.0.0.1/queries/1.1/portlet_payload_service.owl" >

<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.daml.org/services/owl-s/1.1/Service.owl" />
<owl:imports rdf:resource="http://www.daml.org/services/owl-s/1.1/Process.owl" />
<owl:imports rdf:resource="http://www.daml.org/services/owl-s/1.1/Profile.owl" />
<owl:imports rdf:resource="http://www.daml.org/services/owl-s/1.1/Grounding.owl" />
<owl:imports rdf:resource="http://127.0.0.1/ontology/portlets.owl" />
<owl:imports rdf:resource="http://127.0.0.1/ontology/payload.owl" />
</owl:Ontology>

<service:Service rdf:ID="PORTLET_PAYLOAD_SERVICE">
<service:presents rdf:resource="#PORTLET_PAYLOAD_PROFILE"/>
<service:describedBy rdf:resource="#PORTLET_PAYLOAD_PROCESS_MODEL"/>
<service:supports rdf:resource="#PORTLET_PAYLOAD_GROUNDING"/>
</service:Service>

<profile:Profile rdf:ID="PORTLET_PAYLOAD_PROFILE">
<service:isPresentedBy rdf:resource="#PORTLET_PAYLOAD_SERVICE"/>
<profile:serviceName xml:lang="en">
portletID
</profile:serviceName>
<profile:serviceCategory rdf:resource>负荷显示</profile:serviceCategory><profile:textDescription xml:lang="en">
return payload of a portlet
</profile:textDescription>
<profile:hasInput rdf:resource>
最高负荷
</profile:hasInput>
<profile:hasOutput rdf:resource="#_PAYLOAD"/>
<profile:has_process rdf:resource="PORTLET_PAYLOAD_PROCESS" />
</profile:Profile>
</rdf:RDF>
谢谢五楼六楼的指点。现在我撞墙的心都有了。急呀


--  作者:jpz6311whu
--  发布时间:4/7/2009 2:47:00 PM

--  
你这里面并没有import“http://www.eswc2006.org/technologies/ontology"这个呀?
--  作者:smiles
--  发布时间:4/7/2009 3:00:00 PM

--  怎样改才行呢
http://www.eswc2006.org/technologies/ontology
这一句改为OWL文件中的那一个URI才能运行呢?
因为我一改这一句话程序就报错。
谢谢指教
--  作者:jpz6311whu
--  发布时间:4/7/2009 6:35:00 PM

--  
:)楼主可能还不清楚addAltEntry的含义吧?
--  作者:smiles
--  发布时间:4/7/2009 7:39:00 PM

--  谢谢你的回答
是这样的,怎么做呢??
是什么意思??
--  作者:jpz6311whu
--  发布时间:4/7/2009 7:51:00 PM

--  
http://jena.sourceforge.net/ontology/index.html
这里有详细介绍:

Managing file references
An advantage of working with ontologies is that we can reuse work done by other ontologists, by importing their published ontologies into our own. Sometimes, however, this means that there is an Internet firewall between the ontology-based application and the source of an imported ontology. Even if it's possible to traverse the firewall through an HTTP proxy, retrieving files from an HTTP connection may impose unacceptable delays when starting an application. In the worst case, we may find that ontology on which our application depends is temporarily or permanently unavailable from the original published URL. To alleviate these commonly experienced problems, you can use the ontology document manager to set up a a local indirection, so that an attempt to import a document from a given published URL means that a local copy of the document is retrieved instead. This may be a file copy, or simply a pointer to a local mirror web site.

To specify this local redirection in the policy file, use the following declarations:

<OntologySpec>
  <publicURI rdf:resource="… the public URI to map from…"    />
  <altURL rdf:resource="… the local URL to map to …" />
  <!-- optional ontology language term -->
  <language rdf:resource="… encoding used …" />
  <!-- optional prefix to associate with the public URL -->
  <prefix rdf:datatype="&xsd;string">a prefix</prefix>
</OntologySpec>
For example:

<OntologySpec>
  <!-- local version of the RDFS vocabulary -->
  <publicURI rdf:resource="http://www.w3.org/2000/01/rdf-schema"    />
  <altURL rdf:resource="file:vocabularies/rdf-schema.rdf" />
</OntologySpec>
This specifies that an attempt to load the RDFS vocabulary from http://www.w3.org/2000/01/rdf-schema will transparently cause file:vocabularies/rdf-schema.rdf to be fetched instead. You can specify any number of such re-directions in the policy file, or you can add them to the document manager object directly by calling the various setter methods (see the Javadoc for details). As a side-effect, this mechanism also means that ontologies may be named with any legal URI (not necessarily resolvable) - so long as the altURL is itself resolvable.

Note that the OntDocumentManager is an application of Jena's File Manager. See the notes on FileManager for details of additional options.

In the following example, I programmatically declare that the ESWC ontology is replicated locally on disk, and then I load it using the public URL. Assume that the constant JENA has been initialised to the directory in which Jena was installed.

OntModel m = ModelFactory.createOntologyModel();
  OntDocumentManager dm = m.getDocumentManager();
  dm.addAltEntry( "http://www.eswc2006.org/technologies/ontology",
                  "file:" + JENA + "src-examples/data/eswc-2006-09-21.rdf"    );
  m.read( "http://www.eswc2006.org/technologies/ontology" );


--  作者:smiles
--  发布时间:4/7/2009 10:04:00 PM

--  感激不尽
谢谢你!
好好看看。不懂再请教你

--  作者:smiles
--  发布时间:4/8/2009 2:43:00 PM

--  请有空的高手帮忙
程序如下:
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.ontology.*;

public class ReadOWL {
 public static void main(String[] args) {
  
  // create the model and import owl file
  OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
  try {
   model.read(new FileInputStream("D:/owlreal.owl"), "");
  } catch (IOException ioe) {
   System.err.println(ioe.toString());
  }
 // System.out.println("ok");
      
    for (Iterator<?> i = model.listClasses(); i.hasNext();)

     {
   
       OntClass c = (OntClass) i.next();
     
   String strClass = c.getModel().getGraph().getPrefixMapping()
     .shortForm(c.getURI());

   System.out.println( strClass);
   
   // to list sub-classes for each class
       for (Iterator<?> k = c.listSubClasses(true); k.hasNext();) {
    System.out.print("  " + "hasSubClass");
    OntClass subclass = (OntClass) k.next();
    String strSubClass = subclass.getModel().getNsURIPrefix(subclass.getURI());
    
    System.out.println(strSubClass);
   }
   // list property for each class
   for (Iterator<?> y = c.listDeclaredProperties(true); y.hasNext();) {
    OntProperty property = (OntProperty) y.next();
    String strPropertyName = property.getModel().getNsURIPrefix(
      property.getURI());
    String strRange = property.getRange().toString();
    String strRangeName = property.getModel().getNsURIPrefix(strRange);
    // show just the "has" Properties
    if (strPropertyName.substring(1).substring(0, 3).equals("has")) {
   //System.out.print("  ");
     System.out.print(strPropertyName);
     System.out.println(strRangeName);
     }
   }
     }
 }
}
OWL文件如下:
<?xml version="1.0" encoding="GBK"?>
<rdf:RDF
    xmlns:process="http://www.daml.org/services/owl-s/1.1/Process.owl#"
    xmlns:service="http://www.daml.org/services/owl-s/1.1/Service.owl#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:profile="http://www.daml.org/services/owl-s/1.1/Profile.owl#"
    xmlns:grounding="http://www.daml.org/services/owl-s/1.1/Grounding.owl#"
    xmlns:daml="http://www.daml.org/2001/03/daml+oil#"
    xmlns:expression="http://www.daml.org/services/owl-s/1.1/generic/Expression.owl#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:list="http://www.daml.org/services/owl-s/1.1/generic/ObjectList.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:swrl="http://www.w3.org/2003/11/swrl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <service:Service rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadService">
    <service:describedBy>
      <process:CompositeProcess rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadProcess"/>
    </service:describedBy>
    <service:supports>
      <grounding:WsdlGrounding rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadGrounding"/>
    </service:supports>
    <service:presents>
      <profile:Profile rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadProfile"/>
    </service:presents>
  </service:Service>
  <profile:Profile rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadProfile">
    <profile:hasInput>
      <process:Input rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#平均负荷"/>
    </profile:hasInput>
    <profile:hasOutput>
      <process:Output rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#负荷预警信息"/>
    </profile:hasOutput>
    <rdfs:label>Composite Service</rdfs:label>
    <profile:hasInput>
      <process:Input rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#最低负荷"/>
    </profile:hasInput>
    <profile:hasInput>
      <process:Input rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#最高负荷"/>
    </profile:hasInput>
    <service:presentedBy rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadService"/>
    <profile:textDescription>Composite Service</profile:textDescription>
  </profile:Profile>
  <process:CompositeProcess rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadProcess">
    <process:hasResult>
      <process:Result/>
    </process:hasResult>
    <service:describes rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadService"/>
    <process:hasInput rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#最高负荷"/>
    <process:hasInput rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#最低负荷"/>
    <process:composedOf>
      <process:Sequence>
        <process:components>
          <process:ControlConstructList>
            <list:rest rdf:resource="http://www.daml.org/services/owl-s/1.1/generic/ObjectList.owl#nil"/>
            <list:first>
              <process:Perform>
                <process:process rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadProcess"/>
              </process:Perform>
            </list:first>
          </process:ControlConstructList>
        </process:components>
      </process:Sequence>
    </process:composedOf>
    <process:hasInput rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#平均负荷"/>
    <process:hasOutput rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#负荷预警信息"/>
  </process:CompositeProcess>
  <grounding:WsdlGrounding rdf:about="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadGrounding">
    <service:supportedBy rdf:resource="file:/D:/WorkSpace/CreateOWL-SFile/ontologyFiles/jiaxidianli1.owl#PayloadService"/>
  </grounding:WsdlGrounding>
</rdf:RDF>
为什么解析不出来呢?


--  作者:jpz6311whu
--  发布时间:4/9/2009 11:14:00 AM

--  
代码好乱啊,楼主能整理一下下么,嘿嘿
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
139.648ms