新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> Web服务(Web Services,WS), 语义Web服务(Semantic Web Services, SWS)讨论区: WSDL, SOAP, UDDI, DAML-S, OWL-S, SWSF, SWSL, WSMO, WSML,BPEL, BPEL4WS, WSFL, WS-*,REST, PSL, Pi-calculus(Pi演算), Petri-net,WSRF,
    [返回] 中文XML论坛 - 专业的XML技术讨论区W3CHINA.ORG讨论区 - Web新技术讨论『 Web Services & Semantic Web Services 』 → 利用API对OWL-S描述的服务进行操作 ---[经典转贴] 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 10403 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: 利用API对OWL-S描述的服务进行操作 ---[经典转贴] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     timothy 帅哥哟,离线,有人找我吗?巨蟹座1982-7-21
      
      
      威望:1
      等级:大四下学期(考上研究生啦!)
      文章:237
      积分:1701
      门派:XML.ORG.CN
      注册:2006/4/4

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给timothy发送一个短消息 把timothy加入好友 查看timothy的个人资料 搜索timothy在『 Web Services & Semantic Web Services 』的所有贴子 点击这里发送电邮给timothy 引用回复这个贴子 回复这个贴子 查看timothy的博客楼主
    发贴心情 利用API对OWL-S描述的服务进行操作 ---[经典转贴]

    下面这篇文章转自:http://blog.csdn.net/Pottercn/archive/2006/07/24/970088.aspx
    查询邮政编码的服务用OWL-S描述,位于http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl

    对该文件调用API中的类库进行操作,最重要的是如下几段代码:
      
    OWLKnowledgeBase kb = OWLFactory.createKB();

    service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl");
      
    process = service.getProcess();     // 读取服务的process

    // 输入初始值为0,输入值为"College Park"和"MD",函数values.setDataValue得到这两个值,调用服务,并将结果输出。

    values = new ValueMap();
      
    values.setDataValue(process.getInput("City"), "College Park");  

    values.setDataValue(process.getInput("State"), "MD");  

    values = exec.execute(process, values);

    完整代码如下:


    import org.mindswap.owl.OWLFactory;
    import org.mindswap.owl.OWLIndividual;
    import org.mindswap.owl.OWLKnowledgeBase;
    import org.mindswap.owls.OWLSFactory;
    import org.mindswap.owls.process.AtomicProcess;
    import org.mindswap.owls.process.Process;
    import org.mindswap.owls.process.execution.ProcessExecutionEngine;
    import org.mindswap.owls.process.execution.ProcessExecutionListener;
    import org.mindswap.owls.profile.Profile;
    import org.mindswap.owls.service.Service;
    import org.mindswap.query.ValueMap;
    import org.mindswap.utils.Utils;
    import org.mindswap.wsdl.WSDLOperation;
    import org.mindswap.wsdl.WSDLService;


    public class RunService {
    Service service;
    Profile profile;
    Process process;
    WSDLService s;
    WSDLOperation op;
    String inValue;
    String outValue;
    ValueMap values;
    ProcessExecutionEngine exec;

    public RunService() {
      // create an execution engine
      exec = OWLSFactory.createExecutionEngine();
      
      // Attach a listener to the execution engine
      exec.addExecutionListener(new ProcessExecutionListener() {

       public void setCurrentExecuteService(Process p) {
        System.out.println("Start executing process " + p);
       }
       
       public void printMessage(String message) {
       }

       public void finishExecution(int retCode) {
        System.out.println("Finished execution " +
            ((retCode == ProcessExecutionListener.EXEC_ERROR)
            ? "with errors" : "successfully"));  
       }   
      });
    }

    public void runZipCode() throws Exception {
         OWLKnowledgeBase kb = OWLFactory.createKB();

         service = kb.readService("http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl");
      process = service.getProcess();  

      // initialize the input values to be empty
      values = new ValueMap();
      
      values.setDataValue(process.getInput("City"), "College Park");  
      values.setDataValue(process.getInput("State"), "MD");  

      values = exec.execute(process, values);

      // get the result
      OWLIndividual out = values.getIndividualValue(process.getOutput());
        
      // display the results
      System.out.println("Executed service '" + service + "'");
      System.out.println("Grounding WSDL: " +
          ((AtomicProcess) process).getGrounding().getDescriptionURL());
      System.out.println("City   = " + "College Park");
      System.out.println("State  = " + "MD");
      System.out.println("Output = ");
      System.out.println(Utils.formatRDF(out.toRDF()));
      System.out.println();
    }


    public static void main(String[] args) throws Exception {  
      RunService test = new RunService();
      

      try {
       test.runZipCode();
            } catch(Exception e) {
                e.printStackTrace();
            }

    }

    }


    在ECLISPE下运行,得到输出:

    Start executing process http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl#ZipCodeFinderProcess
    Finished execution successfully
    Executed service 'http://www.mindswap.org/2004/owl-s/1.1/ZipCodeFinder.owl#ZipCodeFinderService'
    Grounding WSDL: http://www.tilisoft.com/ws/LocInfo/ZipCode.asmx?WSDL
    City   = College Park
    State  = MD
    Output =
       ZipCode:
         zip: 20740


    同样,对http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl和http://www.mindswap.org/2004/owl-s/1.1/Dictionary.owl等描述的服务进行操作,也可以得到正确的输出。


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    时间永远是向前的!

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/4/27 10:04:00
     
     GoogleAdSense巨蟹座1982-7-21
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Web Services & Semantic Web Services 』的所有贴子 点击这里发送电邮给Google AdSense 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/2 9:07:13

    本主题贴数7,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  利用API对OWL-S描述的服务进行操作 ---[经典转贴](4068字) - timothy,2007年4月27日
        回复:  学习中(6字) - thinking11,2007年8月13日
        回复:  谢谢分享(8字) - zhouwei_ouc,2007年8月7日
        回复:  LZ怎么配置的ECLISPE?我的导入OWLS API 还是有错误,编译不了啊。..(61字) - nicholas628,2007年7月3日
        回复:  不太懂,楼主能把代码详细解释一下吗,如何体现语义?(47字) - ricky_lxl,2007年6月5日
        回复:  这只是对API进行操作嘛,语义体现在构建的模型里!(47字) - timothy,2007年6月4日
        回复:  感觉到这些OWL-S的描述还是构建在WSDL的基础上,并没有体现出语义来..(63字) - MerryZhang,2007年6月4日

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