OWLSAPI示例Word下载.docx
《OWLSAPI示例Word下载.docx》由会员分享,可在线阅读,更多相关《OWLSAPI示例Word下载.docx(22页珍藏版)》请在冰点文库上搜索。
create
a
URI
for
the
service
(note
that
this
is
0.9
version
file)
uri
=
new
URI("
http:
//www.mindswap.org/2004/owl-s/0.9/ZipCodeFinder.owl"
);
KB
OWLKnowledgeBase
kb
OWLFactory.createKB();
generic
reader
and
1.0
writer
OWLOntology
ont
kb.read(uri);
get
service
Service
ont.getService();
write
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表示输入的值,这个函数返回输出值。
举例如下:
an
execution
engine
ProcessExecutionEngine
exec
OWLSFactory.createExecutionEngine();
load
description
kb.readService("
//www.mindswap.org/2004/owl-s/1.0/Dictionary.owl"
process
of
Process
service.getProcess();
empty
value
map
ValueMap
values
ValueMap();
set
input
parameter
values.setDataValue(process.getInput("
InputString"
),
"
computer"
);
execute
with
given
bindings
exec.execute(process,
values);
as
string
String
outValue
values.getStringValue(process.getOutput());
display
result
System.out.println("
Output
+
outValue);
执行跟踪功能:
当执行复杂的服务时,知道执行的过程是很有用的,ProcessExecutionListener就是为这一目的设计的。
ProcessExecutionEngine.addExecutionListener(ProcessExecutionListener)就可以为执行器添加这么一个监听器。
生成复合过程
可以用程序产生服务的descriptions,
profile或者processes描述。
OWLOntology接口实现了这个功能。
/**
*
Create
Sequence
from
processes
services
put
them
in
new
Service.
@param
List
Services
baseURI
The
base
generated
@return
which
*/
createSequenceService(List
services,
baseURI)
{
ontology
OWLFactory.createOntology();
ont.createService(URI.create(baseURI
Service"
));
composite
CompositeProcess
ont.createCompositeProcess(URI.create(baseURI
Process"
sequence
construct
ont.createSequence();
into
compositeProcess.setComposedOf(sequence);
for(int
i
0;
<
services.size();
i++)
list
s
(Service)
services.get(i);
fron
p
s.getProcess();
perform
Perform
ont.createPreform();
perform.setProcess(p);
sequence
sequence.addComponent(p);
data
flow
if
necessary...
}
profile...
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
Glass"
,先查通过BookFinder.owl查到书号,然后将书号输入BNPrice.owl,得到输出:
Executing...done
Book
Price
Price:
currency:
USD
amount:
14.00
完整代码如下:
import
.URI;
java.util.ArrayList;
java.util.List;
org.mindswap.owl.EntityFactory;
org.mindswap.owl.OWLFactory;
org.mindswap.owl.OWLIndividual;
org.mindswap.owl.OWLKnowledgeBase;
org.mindswap.owl.OWLOntology;
org.mindswap.owls.OWLSFactory;
org.mindswap.owls.grounding.Grounding;
org.mindswap.owls.process.AtomicProcess;
org.mindswap.owls.process.CompositeProcess;
org.mindswap.owls.process.Input;
org.mindswap.owls.process.Output;
org.mindswap.owls.process.Perform;
org.mindswap.owls.process.Process;
org.mindswap.owls.process.ProcessList;
org.mindswap.owls.process.Result;
org.mindswap.owls.process.Sequence;
org.mindswap.owls.process.execution.ProcessExecutionEngine;
org.mindswap.owls.profile.Profile;
org.mindswap.owls.service.Service;
org.mindswap.query.ValueMap;
org.mindswap.utils.URIUtils;
org.mindswap.utils.Utils;
An
example
show
how
descriptions
created
on
fly,
saved
executed.
@author
Evren
Sirin
public
class
CreateSequence
{
static
final
URI.create("
//www.example.org/BookPrice.owl#"
ont;
CreateSequence()
object
automatically
Profile.
This
function
assumes
that
each
list
has
exactly
one
(except
first
last
one)
such
resulting
will
fed
next
one.
does
not
have
need
output.
input
(or
output)
depending
this.
objects
services)
ont.createService(URIUtils.createURI(baseURI,
TestService"
ont.createCompositeProcess(URIUtils.createURI(baseURI,
TestProcess"
Profile
profile
ont.createProfile(URIUtils.createURI(baseURI,
TestProfile"
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
process.getComposedOf().getAllProcesses();
list.size();
pc
list.processAt(i);
if(pc
instanceof
AtomicProcess)
grounding.addGrounding(((AtomicProcess)pc).getGrounding());
profile.setLabel(createLabel(services));
profile.setTextDescription(profile.getLabel());
label
based
labels
services.
Basically
string
[Service1
ServiceN]
label
Servie
@return
createLabel(List
["
;
if(i
>
0)
+=
s.getLabel();
]"
label;
service.
We
only
profile
process.
process
createProfile(Profile
profile,
process)
process.getInputs().size();
Input
process.getInputs().inputAt(i);
profile.addInput(input);
process.getOutputs().size();
process.getOutputs().outputAt(i);
profile.addOutput(output);
profile;
Creates
DataFlow
asssuming
each
intput
one).
compositeProcess
grounding
services
createSequenceProcess(CompositeProcess
compositeProcess,
Perform[]
performs
Perform[services.size()];
performs[i]
ont.createPerform();
performs[i].setProcess(p);
sequence.addComponent(performs[i]);
prevPerform
performs[i
-
1];
p.getInputs().inputAt(0);
prevPerform.getPr