一路拾遗
Collect By Finding All The Way ......
posts - 81,comments - 41,trackbacks - 0

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上的。
posted on 2008-07-23 16:51 胖胖泡泡 阅读(534) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: