以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Web Services & Semantic Web Services 』  (http://bbs.xml.org.cn/list.asp?boardid=10)
----  OWL-S API(参考DOC文档) -----[经典转贴]  (http://bbs.xml.org.cn/dispbbs.asp?boardid=10&rootid=&id=46105)


--  作者:timothy
--  发布时间:4/27/2007 10:13:00 AM

--  OWL-S API(参考DOC文档) -----[经典转贴]
Maryland 大学计算机系的Evren Sirin 开发。OWL-S API的类库主要建立在Axis, Jena 以及Pellet上。

Apache Axis 是Apache Web Service项目中的子项目,其最初起源于IBM的"SOAP4J",应该属于最早的一批用于构造基于SOAP应用的Framework。它支持WSDL1.1,可自动由Java Object生成WSDL。

Jena主要用来处理RDF,主要使用Jena的推理能力从本体推断模型知识。

Pellet是一个开源的基于JAVA的OWL推理机。

包中还自带两个jar包形式的java类库,owl-s.jar和upnp.jar。
该OWL-S API的主要功能如下:
读/写服务描述:
OWL-S API中有两个重要的接口:OWLOntology和OWLKnowledgeBase。OWLOntology代表了存储在单个文件中的信息,而OWLKnowledgeBase是许多Ontology的集合。RDF数据可以加载到OWLOntology上,只有OWLOntology对象才能组合起来。OWLKnowledgeBase中只有一个Ontology是用来存储数据的(例如执行之后,新的实例会被加到这个OWLOntology上。

函数OWLKnowledgeBase.read(URI)从给定的Ontology读取信息,并产生OWLOntology。函数OWLOntology.getService()用来获取ontology中的服务实例。如果有许多服务,则用OWLOntology.getServices()获取。然后,函数OWLKnowledgeBase.readService(URI)以及OWLKnowledgeBase.readServices(URI)将会读取服务。如果函数调用发生错误将会产生null输出。

函数OWLOntology.write(Writer)可以使包含服务的ontology组合起来。

这是一个例子:
// create a URI for the service (note that this is a 0.9 version file)   
    URI uri = new URI("http://www.mindswap.org/2004/owl-s/0.9/ZipCodeFinder.owl");
    // create a KB  
    OWLKnowledgeBase kb = OWLFactory.createKB();

    // create a generic reader and a 1.0 writer
    OWLOntology ont = kb.read(uri);
    
    // get the service
    Service service = ont.getService();
    
    // write the output to console (a file stream can also be used here)
    ont.write(System.out);


将旧服务描述转换为新描述。

验证

缓存Ontology


执行服务:
执行服务意味着执行它的process。Process应该有有效的grounding说明,以便有效的调用服务。WSDL和UPnP的grounding由API支持,函数ProcessExecutionEngine.execute(Process, ValueMap)可以执行一个process,ValueMap表示输入的值,这个函数返回输出值。
举例如下:
  // create an execution engine
    ProcessExecutionEngine exec = OWLSFactory.createExecutionEngine();
    // load the service description
    Service service = kb.readService("http://www.mindswap.org/2004/owl-s/1.0/Dictionary.owl");
    // get the process of the service
    Process process = service.getProcess();

    // create an empty value map
    ValueMap values = new ValueMap();
    
    // set the value of input parameter
    values.setDataValue(process.getInput("InputString"), "computer");    
    // execute the process with the given input bindings
    values = exec.execute(process, values);  
    
    // get the output value as a string
    String outValue = values.getStringValue(process.getOutput());
    
    // display the result
    System.out.println("Output = " + outValue);

执行跟踪功能:

当执行复杂的服务时,知道执行的过程是很有用的,ProcessExecutionListener就是为这一目的设计的。ProcessExecutionEngine.addExecutionListener(ProcessExecutionListener)就可以为执行器添加这么一个监听器。

生成复合过程

可以用程序产生服务的descriptions, profile或者processes描述。OWLOntology接口实现了这个功能。
/**
   *
   * Create a new Sequence from the processes of the given services and put them in a new
   * Service.
   *
   * @param services List of Services
   * @param baseURI The base URI for the generated service
   * @return The Service which is a Sequence of the given services
   */
  Service createSequenceService(List services, String baseURI) {   
    // create an empty ontology
    OWLOntology ont = OWLFactory.createOntology();
    // create a new service
    Service service = ont.createService(URI.create(baseURI + "Service"));
    // create a new composite process
    CompositeProcess process = ont.createCompositeProcess(URI.create(baseURI + "Process"));     

    // create a new sequence construct
    Sequence sequence = ont.createSequence();
    // put the sequence into composite process
    compositeProcess.setComposedOf(sequence);
    
    for(int i = 0; i < services.size(); i++) {  
      // get the service from the list
      Service s = (Service) services.get(i);
      // get the process fron the service
      Process p = s.getProcess();
      
      // create a perform construct
      Perform perform = ont.createPreform();
      perform.setProcess(p);
      // put the process into the sequence
      sequence.addComponent(p);

      // create data flow if necessary...

    }

    // create profile...

    // create grounding

    return service;
  }

支持功能。

API中包含了org.mindswap.owls.wsdl这个包,可以用来读写WSDL描述的服务。执行OWL-S服务就是通过这个包实现的。这个功能是建立在AXIS包1.1上的。


--  作者:hehengw
--  发布时间:7/1/2007 12:31:00 PM

--  
我最近在使用它,遇到些问题。我在调用函数生成文件时,怎样才能profile中加入Actor的信息,Actor对象怎么生成?属性怎么设置?

--  作者:hehengw
--  发布时间:7/1/2007 12:38:00 PM

--  
希望大哥,早日恢复,提供帮助,QQ:348651656
--  作者:zhouwei_ouc
--  发布时间:8/7/2007 8:27:00 PM

--  
谢谢分享~~
--  作者:thinking11
--  发布时间:8/13/2007 6:05:00 PM

--  
非常需要
--  作者:kokie
--  发布时间:8/29/2007 10:16:00 AM

--  
好东西,谢谢了
--  作者:xiaopengyou
--  发布时间:2/23/2008 3:05:00 PM

--  
非常好
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms