- 浏览: 61582 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
pkmu8426:
楼主 您好小弟初学Jena 发觉网上文件实在是太少正好看到您这 ...
本体推理的一个例子 -
hadesmile:
确实是个问题,不过一般不这样用,
奇怪的notify()与notifyAll()的执行问题 -
yydcj:
hadesmile 写道10个reduce线程虽然是顺序实例化 ...
一个notify()的实例分析 -
hadesmile:
10个reduce线程虽然是顺序实例化的,但是他们并不是顺序拿 ...
一个notify()的实例分析 -
biganer2008:
你好,按着你的步骤安装后,OWLVizTab标签空白啊,不知道 ...
在 Protege中安装owl-s editor、graphviz插件
语义Web服务的API使用实例:OWL-S API结合matchmaker、推理机(Jena、Pellet)进行语义转换、匹配、组合及调用web服务
- 博客分类:
- 语义web与本体
引自http://www.cnblogs.com/armymen1980/archive/2008/10/22/1316731.html
OWL-S API支持对语义Web服务的描述,读写,以及调用原子的或者组合的Web服务。
OWL API用来表达Web上的本体,并提
供推理引擎。
JENA是一个构建语义Web应用的JAVA框架,提供了基于规则的推理引擎。
附:OWL-S API指南
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上的。
其他应用:
类CreateSequence表明了如何将一系列服务串联起来,并自动产生一个描述新服务的profile,这个类假定每个服务都是单输入单输出
的(除了第一个服务和最后一个服务),这样前面的服务的输出将作为后一个服务的输入。第一个服务不需要有输入,最后一个服务不需要有输出。组合服务的名字
命名为
[Service1 + Service2 + ... + ServiceN]。最后在main函数中进行测试,将BookFinder.owl和
BNPrice.owl进行组合,输入"City of Glass",先查通过BookFinder.owl查到书号,然后将书号输入
BNPrice.owl,得到输出:
Executing...done
Book Price =
Price:
currency: USD
amount: 14.00
完整代码如下:
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.mindswap.owl.EntityFactory;
import org.mindswap.owl.OWLFactory;
import org.mindswap.owl.OWLIndividual;
import org.mindswap.owl.OWLKnowledgeBase;
import org.mindswap.owl.OWLOntology;
import org.mindswap.owls.OWLSFactory;
import org.mindswap.owls.grounding.Grounding;
import org.mindswap.owls.process.AtomicProcess;
import org.mindswap.owls.process.CompositeProcess;
import org.mindswap.owls.process.Input;
import org.mindswap.owls.process.Output;
import org.mindswap.owls.process.Perform;
import org.mindswap.owls.process.Process;
import org.mindswap.owls.process.ProcessList;
import org.mindswap.owls.process.Result;
import org.mindswap.owls.process.Sequence;
import org.mindswap.owls.process.execution.ProcessExecutionEngine;
import org.mindswap.owls.profile.Profile;
import org.mindswap.owls.service.Service;
import org.mindswap.query.ValueMap;
import org.mindswap.utils.URIUtils;
import org.mindswap.utils.Utils;
/**
* An example to show how service descriptions can be created on the fly, saved and executed.
*
* @author Evren Sirin
*/
public class CreateSequence {
public static final URI baseURI = URI.create("http://www.example.org/BookPrice.owl
#");
OWLOntology ont;
public CreateSequence() {
}
/**
*
* Create a new Sequence from the processes of the given services and put them in a new
* Service object with a automatically generated Profile. This function assumes that
* each service in the list has exactly one input and one output (except the first and
* last one) such that in the resulting Service the output of each service will be fed
* as input to the next one. The first service does not have to have an input and the
* last one does not need to have an output. The resulting service will have an input
* (or an output) depending on this.
*
* @param services List of Service objects
* @param baseURI The base URI for the generated service
* @return The Service which is a Sequence of the given services
*/
Service createSequenceService(List services) {
Service service = ont.createService(URIUtils.createURI(baseURI, "TestService"));
CompositeProcess process = ont.createCompositeProcess(URIUtils.createURI(baseURI, "TestProcess"));
Profile profile = ont.createProfile(URIUtils.createURI(baseURI, "TestProfile"));
Grounding grounding = ont.createGrounding(URIUtils.createURI(baseURI, "TestGrounding"));
System.out.println(ont.getKB().getServices());
service.setProfile(profile);
service.setProcess(process);
service.setGrounding(grounding);
createSequenceProcess(process, services);
createProfile(profile, process);
ProcessList list = process.getComposedOf().getAllProcesses();
for(int i = 0; i < list.size(); i++) {
Process pc = list.processAt(i);
if(pc instanceof AtomicProcess) {
grounding.addGrounding(((AtomicProcess)pc).getGrounding());
}
}
profile.setLabel(createLabel(services));
profile.setTextDescription(profile.getLabel());
service.setProfile(profile);
service.setProcess(process);
service.setGrounding(grounding);
return service;
}
/**
*
* Create a label for the composite service based on the labels of services. Basically
* return the string [Service1 + Service2 + ... + ServiceN] as the label
*
* @param services List of Servie objects
* @return
*/
String createLabel(List services) {
String label = "[";
for(int i = 0; i < services.size(); i++) {
Service s = (Service) services.get(i);
if(i > 0) label += " + ";
label += s.getLabel();
}
label += "]";
return label;
}
/**
*
* Create a Profile for the composite service. We only set the input and output of the profile
* based on the process.
*
* @param profile
* @param process
* @return
*/
Profile createProfile(Profile profile, Process process) {
for(int i = 0; i < process.getInputs().size(); i++) {
Input input = process.getInputs().inputAt(i);
profile.addInput(input);
}
for(int i = 0; i < process.getOutputs().size(); i++) {
Output output = process.getOutputs().outputAt(i);
profile.addOutput(output);
}
return profile;
}
/**
*
* Create a Sequence process for the processes of given services. Creates the DataFlow asssuming each
* service has one output and one intput (except first and last one).
*
* @param compositeProcess
* @param grounding
* @param services
* @return
*/
CompositeProcess createSequenceProcess(CompositeProcess compositeProcess, List services) {
Sequence sequence = ont.createSequence();
compositeProcess.setComposedOf(sequence);
Perform[] performs = new Perform[services.size()];
for(int i = 0; i < services.size(); i++) {
Service s = (Service) services.get(i);
Process p = s.getProcess();
performs[i] = ont.createPerform();
performs[i].setProcess(p);
sequence.addComponent(performs[i]);
if(i > 0) {
Perform prevPerform = performs[i - 1];
Input input = p.getInputs().inputAt(0);
Output output = prevPerform.getProcess().getOutputs().outputAt(0);
// the value of 'input' is the value of 'output' from 'prevPerform'
performs[i].addBinding(input, prevPerform, output);
}
}
Perform firstPerform = performs[0];
Perform lastPerform = performs[services.size()-1];
boolean createInput = firstPerform.getProcess().getInputs().size() > 0;
boolean createOutput = lastPerform.getProcess().getOutputs().size() > 0;
if(createInput) {
Input input = firstPerform.getProcess().getInputs().inputAt(0);
Input newInput = ont.createInput(URIUtils.createURI(baseURI, "TestInput"));
newInput.setLabel(input.getLabel());
newInput.setParamType(input.getParamType());
newInput.setProcess(compositeProcess);
// input of the first perform is directly read from the input of the
// composite process
performs[0].addBinding(input, Perform.TheParentPerform, newInput);
}
if(createOutput) {
Output output = lastPerform.getProcess().getOutputs().outputAt(0);
Output newOutput = ont.createOutput(URIUtils.createURI(baseURI, "TestOutput"));
newOutput.setLabel(output.getLabel());
newOutput.setParamType(output.getParamType());
newOutput.setProcess(compositeProcess);
// the output of the composite process is the output pf last process
Result result = ont.createResult();
result.addBinding(newOutput, lastPerform, output);
compositeProcess.setResult(result);
}
return compositeProcess;
}
public void runTest() throws Exception {
// create an OWL-S knowledge base
OWLKnowledgeBase kb = OWLFactory.createKB();
// create an empty ontology in this KB
ont = kb.createOntology();
// create an execution engine
ProcessExecutionEngine exec = OWLSFactory.createExecutionEngine();
// load two services
Service s1 = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl
#");
Service s2 = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/BNPrice.owl
#");
// put the services in a list
List services = new ArrayList();
services.add(s1);
services.add(s2);
// create a new service as a sequence of the list
Service s = createSequenceService(services);
// print the description of new service to standard output
ont.write(System.out, baseURI);
System.out.println();
// get the process of the new service
Process process = s.getProcess();
// initialize the input values to be empty
ValueMap values = new ValueMap();
// get the parameter using the local name
values.setValue(process.getInputs().inputAt(0), EntityFactory.createDataValue("City of Glass"));
// execute the service
System.out.print("Executing...");
values = exec.execute(process, values);
System.out.println("done");
// get the output param using the index
OWLIndividual outValue = values.getIndividualValue(process.getOutput());
// display the result
System.out.println("Book Price = ");
System.out.println(Utils.formatRDF(outValue.toRDF()));
System.out.println();
}
public static void main(String[] args) throws Exception {
CreateSequence test = new CreateSequence();
test.runTest();
}
}
ForEachExample类是对多输入值进行操作的例子,例如,分别输入三个邮政编码,然后调用服务得到三个地区的纬度和经度。
完整代码如下:
import impl.owls.process.execution.ProcessExecutionEngineImpl;
import java.net.URI;
import org.mindswap.owl.OWLClass;
import org.mindswap.owl.OWLDataProperty;
import org.mindswap.owl.OWLFactory;
import org.mindswap.owl.OWLIndividual;
import org.mindswap.owl.OWLKnowledgeBase;
import org.mindswap.owl.OWLOntology;
import org.mindswap.owl.list.RDFList;
import org.mindswap.owls.OWLSFactory;
import org.mindswap.owls.process.CompositeProcess;
import org.mindswap.owls.process.ForEach;
import org.mindswap.owls.process.Input;
import org.mindswap.owls.process.Local;
import org.mindswap.owls.process.Perform;
import org.mindswap.owls.process.Process;
import org.mindswap.owls.process.execution.ProcessExecutionEngine;
import org.mindswap.owls.service.Service;
import org.mindswap.owls.vocabulary.OWLS;
import org.mindswap.query.ValueMap;
/**
*
* Example to show how to create and execute a forEach control construct.
*
* @author Evren Sirin
*/
public class ForEachExample {
public void run() throws Exception {
String ns = "http://www.example.org/test
#";
// print the inputs and outputs during each iteration of the loop
ProcessExecutionEngineImpl.DEBUG = true;
ProcessExecutionEngine exec = OWLSFactory.createExecutionEngine();
OWLKnowledgeBase kb = OWLFactory.createKB();
Service service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/FindLatLong.owl"
);
Process process = service.getProcess();
OWLOntology ont = kb.createOntology();
CompositeProcess cp = ont.createCompositeProcess();
Input in = ont.createInput(URI.create( ns + "in" ));
in.setParamType(OWLS.ObjList.List());
cp.addInput(in);
// create a ForEach construct
ForEach forEach = ont.createForEach();
Local loopVar = ont.createLocal( URI.create( ns + "loopVar") );
cp.setComposedOf(forEach);
forEach.setListValue( Perform.TheParentPerform, in );
forEach.setLoopVar( loopVar );
// perform the process by passing the loop variable
Perform perform = ont.createPerform();
perform.setProcess(process);
perform.addBinding(process.getInput(), Perform.TheParentPerform, loopVar);
forEach.setComponent(perform);
// display how the construct looks like in RDF/XML
ont.write(System.out);
// create some zip code values
String zipcodeOnt = "http://www.daml.org/2001/10/html/zipcode-ont
#";
OWLClass ZipCode = kb.getClass(URI.create(zipcodeOnt + "ZipCode"));
OWLDataProperty zip = kb.getDataProperty(URI.create(zipcodeOnt + "zip"));
OWLIndividual zip1 = ont.createInstance(ZipCode);
zip1.setProperty(zip, "20740");
OWLIndividual zip2 = ont.createInstance(ZipCode);
zip2.setProperty(zip, "11430");
OWLIndividual zip3 = ont.createInstance(ZipCode);
zip3.setProperty(zip, "94102");
// put them in a list
RDFList list = ont.createList(zip1).add(zip2).add(zip3);
ValueMap values = new ValueMap();
values.setValue(cp.getInput("in"), list);
exec.execute( cp , values );
}
public static void main(String[] args) throws Exception {
ForEachExample test = new ForEachExample();
test.run();
}
}
运行后得到输出:
Executing AtomicProcess http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#FindLatLongProcess
Inputs:
(http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#ZipCode=
<j.0:ZipCode>
<j.0:zip>20740</j.0:zip>
</j.0:ZipCode>
)
Invoking http://cheeso.members.winisp.net/zips/ZipService.asmx?WSDL
Result:
(http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#LatLong=
<j.0:LatLon>
<j.0:latitude>38.996303</j.0:latitude>
<j.0:longitude>-76.929891</j.0:longitude>
</j.0:LatLon>
)
Executing AtomicProcess http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#FindLatLongProcess
Inputs:
(http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#ZipCode=
<rdf:Description>
<j.0:zip>11430</j.0:zip>
</rdf:Description>
)
Invoking http://cheeso.members.winisp.net/zips/ZipService.asmx?WSDL
Result:
(http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#LatLong=
<j.0:LatLon>
<j.0:latitude>-0</j.0:latitude>
<j.0:longitude>-0</j.0:longitude>
</j.0:LatLon>
)
Executing AtomicProcess http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#FindLatLongProcess
Inputs:
(http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#ZipCode=
<rdf:Description>
<j.0:zip>94102</j.0:zip>
</rdf:Description>
)
Invoking http://cheeso.members.winisp.net/zips/ZipService.asmx?WSDL
Result:
(http://www.mindswap.org/2004/owl-s/1.1/FindLobjectatLong.owl
#LatLong=
<j.0:LatLon>
<j.0:latitude>-0</j.0:latitude>
<j.0:longitude>-0</j.0:longitude>
</j.0:LatLon>
)
Matchmaker这个例子说明了如何对服务进行匹配,实现服务的组合。服务的输出与服务的输入进行匹配,分别运 用"EXACT, SUBSUME以及RELAXED"作为匹配标准。这里应用了Pellet推理机。
对以下几个文件进行输入输出匹配:
http://www.mindswap.org/2004/owl-s/1.1/BNPrice.owl
http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl
http://www.mindswap.org/2004/owl-s/1.1/CurrencyConverter.owl
http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl
http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl
http://www.mindswap.org/2004/owl-s/1.1/FindLatLong.owl
http://www.mindswap.org/2004/owl-s/1.1/BabelFishTranslator.owl
得到运行结果:
Reading http://www.mindswap.org/2004/owl-s/1.1/BNPrice.owl
Reading http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl
Reading
http://www.mindswap.org/2004/owl-s/1.1/CurrencyConverter.owl
Reading
http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl
Reading
http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl
Reading
http://www.mindswap.org/2004/owl-s/1.1/FindLatLong.owl
Reading
http://www.mindswap.org/2004/owl-s/1.1/BabelFishTranslator.owl
#
Computing
matches...
Matches:
EXACT BNPriceService.BookPrice ->
CurrencyConverterService.InputPrice
EXACT BookFinderService.BookInfo
-> BNPriceService.BookInfo
EXACT
CurrencyConverterService.OutputPrice ->
CurrencyConverterService.InputPrice
EXACT
DictionaryService.OutputString -> BookFinderService.BookName
EXACT
DictionaryService.OutputString -> DictionaryService.InputString
EXACT
DictionaryService.OutputString -> ZipCodeFinderService.City
EXACT
DictionaryService.OutputString -> ZipCodeFinderService.State
EXACT
DictionaryService.OutputString ->
BabelFishTranslatorService.InputString
EXACT
ZipCodeFinderService.ZipCode -> FindLatLongService.ZipCode
EXACT
BabelFishTranslatorService.OutputString -> BookFinderService.BookName
EXACT
BabelFishTranslatorService.OutputString ->
DictionaryService.InputString
EXACT
BabelFishTranslatorService.OutputString -> ZipCodeFinderService.City
EXACT
BabelFishTranslatorService.OutputString ->
ZipCodeFinderService.State
EXACT
BabelFishTranslatorService.OutputString ->
BabelFishTranslatorService.InputString
完整代码如下:
import java.io.FileNotFoundException;
import java.net.URI;
import
java.net.URISyntaxException;
import java.util.ArrayList;
import
java.util.Iterator;
import java.util.List;
import org.mindswap.owl.OWLFactory;
import
org.mindswap.owl.OWLIndividual;
import
org.mindswap.owl.OWLKnowledgeBase;
import org.mindswap.owl.OWLType;
import
org.mindswap.owls.process.Input;
import
org.mindswap.owls.process.Output;
import
org.mindswap.owls.service.Service;
import
org.mindswap.query.ValueMap;
/**
* An example that finds service matches for composition. The
outputs of services are matched with
* the inputs of services using
one of EXACT, SUBSUME and RELAXED match criteria. Pellet reasoner is
*
used to find matches but can be replaced with any other reasoner.
*
* @author Evren Sirin
*/
public class Matchmaker {
OWLKnowledgeBase kb;
public static class Match {
public static String[] MATCHES = {"EXACT", "SUBSUME", "RELAXED",
"FAIL"};
public static int EXACT = 0;
public
static int SUBSUME = 1;
public static int RELAXED = 2;
public static int FAIL = 3;
int
matchType;
boolean listMatch;
Service
outputService;
Output output;
Service
inputService;
Input input;
public
Match(int matchType, Output output, Input input) {
this.matchType = matchType;
this.outputService =
output.getService();
this.output = output;
this.inputService = input.getService();
this.input =
input;
}
public String toString() {
String str = "";
str +=
MATCHES[matchType] + " ";
if(listMatch)
str += ".LIST";
str += outputService.getLocalName() +
"." + output.getLocalName();
str += " -> ";
str += inputService.getLocalName() + "." + input.getLocalName();
return str;
}
}
public
Matchmaker() {
kb = OWLFactory.createKB();
kb.setReasoner("Pellet");
}
public void addOntology( String ont ) throws
FileNotFoundException, URISyntaxException {
System.out.println( "Reading " + ont );
kb.read( new URI( ont
) );
}
public void addOntology( URI ont ) throws
FileNotFoundException {
System.out.println( "Reading " + ont
);
kb.read( ont );
}
public List
findServices(boolean getProducers) {
String hasParameter =
getProducers ? "process:hasOutput" : "process:hasInput";
String queryString =
"SELECT * " +
"WHERE " +
" (?process rdf:type process:Process)" +
" (?process " + hasParameter + " ?param)" +
"USING " +
" process FOR <http://www.daml.org/services/owl-s/1.1/Process.owl
#>";
return kb.query( queryString );
}
public List findOutputs() {
return findServices(true);
}
public List findInputs() {
return
findServices(false);
}
public int
getMatchType(OWLType outputType, OWLType inputType) {
if(outputType.isEquivalent(inputType))
return Match.EXACT;
else if(outputType.isSubTypeOf(inputType))
return
Match.SUBSUME;
else
if(inputType.isSubTypeOf(outputType))
return
Match.RELAXED;
else
return Match.FAIL;
}
public List displayAllMatches() {
List matches = new
ArrayList();
System.out.println( "Computing matches..." );
List
producers = findOutputs();
List consumers = findInputs();
Iterator
i = producers.iterator();
while( i.hasNext() ) {
ValueMap
binding = (ValueMap) i.next();
Output output = (Output)
((OWLIndividual) binding.getValue("param")).castTo(Output.class);
OWLType outputType = output.getParamType();
Iterator
j = consumers.iterator();
while( j.hasNext() ) {
binding = (ValueMap) j.next() ;
Input input = (Input)
((OWLIndividual) binding.getValue("param")).castTo(Input.class);
OWLType inputType = input.getParamType();
//
System.out.println("Trying " +
//
URIUtils.getLocalName(outputType.getURI()) + " " +
//
URIUtils.getLocalName(inputType.getURI()) + " " +
//
producer.getLocalName() + " " +
// output.getLocalName() +
" " +
// consumer.getLocalName() + " " +
//
input.getLocalName()
// );
int
matchType = getMatchType(outputType, inputType);
if(matchType != Match.FAIL)
matches.add(new
Match(matchType, output, input));
}
}
return
matches;
}
public static void printIterator(Iterator i) {
if(i.hasNext()) {
while (i.hasNext())
System.out.println( i.next() );
}
else
System.out.println("<EMPTY>");
System.out.println();
}
public static void
main(String[] args) throws FileNotFoundException, URISyntaxException {
Matchmaker matchmaker = new Matchmaker();
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/BNPrice.owl
");
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl
");
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/CurrencyConverter.owl
");
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl
");
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl
");
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/FindLatLong.owl
");
matchmaker.addOntology("http://www.mindswap.org/2004/owl-s/1.1/BabelFishTranslator.owl
#");
List matches = matchmaker.displayAllMatches();
System.out.println();
System.out.println("Matches:");
printIterator(matches.iterator());
}
}
对其他几个类作简单介绍:
OWLSValidator主要是对OWL-S文件的有效性进行检验。
PreconditionCheck说明了服务如何被执行。
OWLSExtensions
说明了API包的可扩展性,显示了默认Profile的可以扩充为用户自定义的Profile。
Translator主要是对不同版本的
service description进行转换,以保证兼容性。
WSDL2OWLS主要是将WDSL描述的服务自动转化为OWL-S描述。
发表评论
-
DAML-S简介
2010-08-02 11:30 882引自:http://hi.baidu.com/fe ... -
OWL-S API指南
2010-07-15 16:13 1231引自http://yoancn.blogbus.com/log ... -
在 Protege中安装owl-s editor、graphviz插件
2010-07-15 15:59 29651.软件安装: 双击install_protege.exe安 ... -
Jena 环境的配置
2010-07-15 15:55 1187引自 http://www.cnblogs.com/armym ... -
基于OWL-S的语义Web服务发现组装的常用工具
2010-07-15 15:54 1204Protege + OWL-S Editor + ... -
使用jena持久化OWL本体到MySQL
2010-07-15 15:54 1390引自http://www.cnblogs.com/ar ... -
语义Web Service检索服务的工具下载
2010-07-15 15:52 875Eclipse下载: http://www.eclipse.o ... -
本体推理的一个例子
2010-07-15 15:19 2485引自http://hi.baidu.com/wxmsona/b ... -
家族族谱推理规则文件
2010-07-15 15:19 694引自http://hi.baidu.com/wxmsona/b ... -
家族族谱owl文件
2010-07-15 15:17 1052引自http://hi.baidu.com/wxmsona/b ... -
RDF数据查询语言SPARQL
2010-07-15 15:16 1576数据源,一个RDF文件,就是帮助文档中的vc-db-1.rdf ... -
jena持久化到数据库
2010-07-15 15:15 1102Jena 由 HP Labs (http://www.hp ... -
用 SPARQL 搜索 RDF 数据
2010-07-15 15:14 1697随着越来越多的数据使用类似 RSS 的 RDF 格式保存, ... -
jena 操作RDF的一个例子(参考IBM的一篇文章)
2010-07-15 15:13 1267jena 操作RDF的一个例子 ... -
Jena的一个例子
2010-07-15 15:12 1185摘自:http://www.crabone.com/index ... -
本体(Ontology)综述
2010-07-15 15:10 1024本体作为一种能在语义和知识层次 上描述领域概念的建模工具,其 ... -
语义Web和本体开发相关技术
2010-07-15 15:09 1316摘自:http://iMarine.blog.163.com/ ... -
owl-s API一个简单例子
2010-07-15 15:09 1164owl-s语义Web服务标记语言, 在Tim Berners- ... -
语义Web
2010-07-15 14:48 858语 义Web概念: 1998 ... -
语义Web中语言与本体
2010-07-15 14:43 842随着人们对网络上信 ...
相关推荐
OWL-S(Ontology Web Language for Services)是一种基于OWL(Web Ontology Language)的语义网标准,用于描述、发布和发现Web服务。这个"owl-s-1.0.1.zip"压缩包文件包含了OWL-S API的1.0.1版本,它提供了对处理和...
### OWL-S简介及其推理机 #### 一、从WebService到Semantic ...通过利用OWL-S进行服务描述,结合OWL推理机和工具如OWLAPI、Jena等,可以实现更高级别的自动化处理和服务发现,从而推动了语义网的发展和应用。
OWL-S(Ontology Web Language for Services)是一种基于OWL(Web Ontology Language)的语义网服务描述语言,用于描述和理解Web服务的语义、功能和行为。这个测试集是针对OWL-S进行的一个实例集合,旨在帮助开发者...
3.基于描述逻辑引擎的推理:Protege-OWL-API 提供了基于描述逻辑引擎的推理功能,允许开发者进行复杂的逻辑推理。 4.图形用户界面的实现:Protege-OWL-API 优化了图形用户界面的实现,允许开发者轻松地构建图形用户...
在信息技术领域,OWL-S API是由Maryland大学开发的一个重要工具,主要用于处理和操作OWL-S(Web Ontology Language for Services)语义网服务描述。OWL-S是一种基于OWL(Web Ontology Language)的扩展,用于描述、...
- OWL-S与WSDL转换:API的一大亮点在于能将OWL-S服务描述转换为WSDL(Web Services Description Language)格式,使得OWL-S服务可以被传统Web服务框架识别和调用。 2. **使用方法** 使用`OWLS_API`通常涉及以下...
而在语义Web环境中,通过使用OWL-S描述的服务,用户可以通过语义查询找到完全符合需求的酒店预订服务。 **5.3 服务设定** 服务设定是描述服务的基本特性的过程,包括服务名称、提供的功能、所需的输入参数和产生的...
"OWL-S Semantic Markup for Web Services.mht"文件很可能是关于OWL-S的详细说明文档,其中可能包含了OWL-S语法、语义以及如何使用OWL-S来描述Web服务的示例。MHT文件是一种单一文件的网页存档格式,它将HTML内容和...
**CMU大学的OWL-S/UDDI Matchmaker 1.3** 是一款专门针对语义Web服务进行匹配的工具,由知名的卡耐基梅陇大学(Carnegie Mellon University)研发。这款工具的核心功能是利用语义技术来帮助发现、理解和结合Web服务...
OWL-S(Web Ontology Language for Services)是一种用于描述语义Web服务的语言,旨在解决Web服务自动化发现、动态组合等挑战。本教程《An OWL-S Editor Tutorial》提供了一个实践指南,帮助用户通过OWL-S编辑器创建...
通过使用OWL-S,我们可以为Web服务提供丰富的语义描述,从而增强服务的自动发现、匹配和组合能力。 OWL-S是构建在OWL(Web Ontology Language)基础之上,专门用于服务建模的语言。它提供了服务的元数据描述,包括...
基于OWL-S的服务发现语义匹配机制通过引入语义元素、采用语义服务匹配算法、数据映射机制、本体概念索引机制以及近似概念搜寻算法等多种技术手段,有效地解决了传统UDDI服务发现机制存在的问题,提高了Web服务发现的...
标题“OWL-S2UDDI”表明这是一个关于将OWL-S(Web本体语言服务)的Profile注册到UDDI(统一发现、描述和集成)的服务转换工具。OWL-S是一种用于描述Web服务语义的本体语言,而UDDI则是一个标准的Web服务目录,用于...
总的来说,本课题通过研究PETRI-OWL-S的结合,为语义Web服务的并发执行问题提供了新的解决方案,同时也为服务的自动发现、匹配和组合提供了理论支持和实用工具。这一研究对推动语义Web服务的实际应用具有重要的价值...
网上一个经典的owl-s例子其www.bs-byg.dk/hashclass.wsdl不能用了,故又找了一个globalweather服务http://www.webservicex.com/globalweather.asmx?WSDL 来自...
通过学习和使用OWL API和Jena OWL API,开发者可以在其应用程序中实现高级的语义网功能,如智能数据处理、知识推理以及复杂的数据整合。结合文档`OWL Jena.docx`,你可以深入了解这两个工具的用法,进一步提升你的...
为了解决上述问题,研究人员提出了使用OWL-S(一种基于本体的Web服务描述语言)来增强Web服务的语义描述,并提出了基于本体的服务发现模型。这种方法的主要优点包括: 1. **增加语义信息**:通过使用OWL-S,可以将...