Maryland 大學(xué)計算機(jī)系的Evren Sirin 開發(fā)。OWL-S API的類庫主要建立在Axis, Jena 以及Pellet上。
Apache Axis 是Apache Web Service項目中的子項目,其最初起源于IBM的"SOAP4J",應(yīng)該屬于最早的一批用于構(gòu)造基于SOAP應(yīng)用的Framework。它支持WSDL1.1,可自動由Java Object生成WSDL。
Jena主要用來處理RDF,主要使用Jena的推理能力從本體推斷模型知識。
Pellet是一個開源的基于JAVA的OWL推理機(jī)。
包中還自帶兩個jar包形式的java類庫,owl-s.jar和upnp.jar。
該OWL-S API的主要功能如下:
讀/寫服務(wù)描述:
OWL-S
API中有兩個重要的接口:OWLOntology和OWLKnowledgeBase。OWLOntology代表了存儲在單個文件中的信息,而
OWLKnowledgeBase是許多Ontology的集合。RDF數(shù)據(jù)可以加載到OWLOntology上,只有OWLOntology對象才能組
合起來。OWLKnowledgeBase中只有一個Ontology是用來存儲數(shù)據(jù)的(例如執(zhí)行之后,新的實例會被加到這個OWLOntology上。
函
數(shù)OWLKnowledgeBase.read(URI)從給定的Ontology讀取信息,并產(chǎn)生OWLOntology。函數(shù)
OWLOntology.getService()用來獲取ontology中的服務(wù)實例。如果有許多服務(wù),則用
OWLOntology.getServices()獲取。然后,函數(shù)OWLKnowledgeBase.readService(URI)以及
OWLKnowledgeBase.readServices(URI)將會讀取服務(wù)。如果函數(shù)調(diào)用發(fā)生錯誤將會產(chǎn)生null輸出。
函數(shù)OWLOntology.write(Writer)可以使包含服務(wù)的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);
將舊服務(wù)描述轉(zhuǎn)換為新描述。
驗證
緩存Ontology
執(zhí)行服務(wù):
執(zhí)
行服務(wù)意味著執(zhí)行它的process。Process應(yīng)該有有效的grounding說明,以便有效的調(diào)用服務(wù)。WSDL和UPnP的grounding
由API支持,函數(shù)ProcessExecutionEngine.execute(Process,
ValueMap)可以執(zhí)行一個process,ValueMap表示輸入的值,這個函數(shù)返回輸出值。
舉例如下:
// 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);
執(zhí)行跟蹤功能:
當(dāng)執(zhí)行復(fù)雜的服務(wù)時,知道執(zhí)行的過程是很有用的,ProcessExecutionListener就是為這一目的設(shè)計的。
ProcessExecutionEngine.addExecutionListener(ProcessExecutionListener)就可以
為執(zhí)行器添加這么一個監(jiān)聽器。
生成復(fù)合過程
可以用程序產(chǎn)生服務(wù)的descriptions, profile或者processes描述。OWLOntology接口實現(xiàn)了這個功能。
/**
*
* 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描述的服務(wù)。執(zhí)行OWL-S服務(wù)就是通過這個包實現(xiàn)的。這個功能是建立在AXIS包1.1上的。
posted on 2008-07-23 16:51
胖胖泡泡 閱讀(539)
評論(0) 編輯 收藏