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

          Maryland 大學(xué)計(jì)算機(jī)系的Evren Sirin 開(kāi)發(fā)。OWL-S API的類(lèi)庫(kù)主要建立在Axis, Jena 以及Pellet上。
           
          Apache Axis 是Apache Web Service項(xiàng)目中的子項(xiàng)目,其最初起源于IBM的"SOAP4J",應(yīng)該屬于最早的一批用于構(gòu)造基于SOAP應(yīng)用的Framework。它支持WSDL1.1,可自動(dòng)由Java Object生成WSDL。
           
          Jena主要用來(lái)處理RDF,主要使用Jena的推理能力從本體推斷模型知識(shí)。
           
          Pellet是一個(gè)開(kāi)源的基于JAVA的OWL推理機(jī)。
           
          包中還自帶兩個(gè)jar包形式的java類(lèi)庫(kù),owl-s.jar和upnp.jar。
          該OWL-S API的主要功能如下:
          讀/寫(xiě)服務(wù)描述:
          OWL-S API中有兩個(gè)重要的接口:OWLOntology和OWLKnowledgeBase。OWLOntology代表了存儲(chǔ)在單個(gè)文件中的信息,而 OWLKnowledgeBase是許多Ontology的集合。RDF數(shù)據(jù)可以加載到OWLOntology上,只有OWLOntology對(duì)象才能組 合起來(lái)。OWLKnowledgeBase中只有一個(gè)Ontology是用來(lái)存儲(chǔ)數(shù)據(jù)的(例如執(zhí)行之后,新的實(shí)例會(huì)被加到這個(gè)OWLOntology上。
           
          函 數(shù)OWLKnowledgeBase.read(URI)從給定的Ontology讀取信息,并產(chǎn)生OWLOntology。函數(shù) OWLOntology.getService()用來(lái)獲取ontology中的服務(wù)實(shí)例。如果有許多服務(wù),則用 OWLOntology.getServices()獲取。然后,函數(shù)OWLKnowledgeBase.readService(URI)以及 OWLKnowledgeBase.readServices(URI)將會(huì)讀取服務(wù)。如果函數(shù)調(diào)用發(fā)生錯(cuò)誤將會(huì)產(chǎn)生null輸出。
           
          函數(shù)OWLOntology.write(Writer)可以使包含服務(wù)的ontology組合起來(lái)。
           
          這是一個(gè)例子:


           // 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)換為新描述。
           
          驗(yàn)證
           
          緩存Ontology
           
           
          執(zhí)行服務(wù):
          執(zhí) 行服務(wù)意味著執(zhí)行它的process。Process應(yīng)該有有效的grounding說(shuō)明,以便有效的調(diào)用服務(wù)。WSDL和UPnP的grounding 由API支持,函數(shù)ProcessExecutionEngine.execute(Process, ValueMap)可以執(zhí)行一個(gè)process,ValueMap表示輸入的值,這個(gè)函數(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ù)時(shí),知道執(zhí)行的過(guò)程是很有用的,ProcessExecutionListener就是為這一目的設(shè)計(jì)的。 ProcessExecutionEngine.addExecutionListener(ProcessExecutionListener)就可以 為執(zhí)行器添加這么一個(gè)監(jiān)聽(tīng)器。
           
          生成復(fù)合過(guò)程
           
          可以用程序產(chǎn)生服務(wù)的descriptions, profile或者processes描述。OWLOntology接口實(shí)現(xiàn)了這個(gè)功能。
           

          /**
             *
             * 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這個(gè)包,可以用來(lái)讀寫(xiě)WSDL描述的服務(wù)。執(zhí)行OWL-S服務(wù)就是通過(guò)這個(gè)包實(shí)現(xiàn)的。這個(gè)功能是建立在AXIS包1.1上的。
          posted on 2008-07-23 16:51 胖胖泡泡 閱讀(539) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 夏邑县| 岳池县| 古丈县| 马龙县| 怀宁县| 台江县| 澄江县| 甘德县| 彭水| 桑日县| 株洲县| 肇源县| 措美县| 武穴市| 浦东新区| 兴海县| 唐河县| 浠水县| 陵川县| 封开县| 丰原市| 济宁市| 乾安县| 揭西县| 安达市| 桐城市| 达孜县| 阿鲁科尔沁旗| 凤台县| 贵阳市| 思南县| 博客| 大同市| 正蓝旗| 洪洞县| 沿河| 新和县| 玛多县| 大同市| 隆子县| 安阳县|