新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   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 』 → matchmaker.java如何修改成racer推理机 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 7365 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: matchmaker.java如何修改成racer推理机 举报  打印  推荐  IE收藏夹 
       本主题类别: Ontology Language | RDF/RDFS    
     lixiaoming 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(数据结构考了98分!)
      文章:78
      积分:409
      门派:XML.ORG.CN
      注册:2008/12/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给lixiaoming发送一个短消息 把lixiaoming加入好友 查看lixiaoming的个人资料 搜索lixiaoming在『 Web Services & Semantic Web Services 』的所有贴子 引用回复这个贴子 回复这个贴子 查看lixiaoming的博客楼主
    发贴心情 matchmaker.java如何修改成racer推理机


    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");这里是个Pellet推理机,怎么换成racer    }

        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());
        }
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/4/18 20:38:00
     
     iamwym 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      等级:计算机硕士学位(版主)
      文章:2454
      积分:17456
      门派:XML.ORG.CN
      注册:2004/11/14

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给iamwym发送一个短消息 把iamwym加入好友 查看iamwym的个人资料 搜索iamwym在『 Web Services & Semantic Web Services 』的所有贴子 访问iamwym的主页 引用回复这个贴子 回复这个贴子 查看iamwym的博客2
    发贴心情 
    明显pellet是个定义好的吧,你直接吧pellet所对应的reasoner接口换成racer好了

    实际上你用pellet也行啊,非要用racer干啥

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

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

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms