-- 作者:tianshiwgq
-- 发布时间:12/5/2008 12:05:00 PM
-- 求助:owl-s api 中的matchmaker 例子出错,高人请指教
修改后的原代码: 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://localhost:8080/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()); } } 运行错误,如下,不知道为什么,总是读不到顶极本体 Reading http://localhost:8080/BNPrice.owl WARNING: Cannot read file http://www.daml.org/services/owl-s/1.1/Service.owl WARNING: The import file http://www.daml.org/services/owl-s/1.1/Service.owl cannot be parsed WARNING: Cannot read file http://www.daml.org/services/owl-s/1.1/Process.owl WARNING: The import file http://www.daml.org/services/owl-s/1.1/Process.owl cannot be parsed WARNING: Cannot read file http://www.daml.org/services/owl-s/1.1/generic/ObjectList.owl WARNING: The import file http://www.daml.org/services/owl-s/1.1/generic/ObjectList.owl cannot be parsed WARNING: Cannot read file http://www.daml.org/services/owl-s/1.1/generic/Expression.owl WARNING: The import file http://www.daml.org/services/owl-s/1.1/generic/Expression.owl cannot be parsed WARNING: Cannot read file http://www.daml.org/services/owl-s/1.1/Service.owl WARNING: The import file http://www.daml.org/services/owl-s/1.1/Service.owl cannot be parsed WARNING: Cannot read file http://www.mindswap.org/ontologies/bibtex.owl WARNING: The import file http://www.mindswap.org/ontologies/bibtex.owl cannot be parsed WARNING: Cannot read file http://www.mindswap.org/2004/owl-s/concepts.owl WARNING: The import file http://www.mindswap.org/2004/owl-s/concepts.owl cannot be parsed WARNING: Cannot read file http://localhost:8080/Grounding.owl WARNING: The import file http://localhost:8080/Grounding.owl cannot be parsed Reading http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl WARNING: Cannot read file http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl Exception in thread "main" java.io.FileNotFoundException: The file http://www.mindswap.org/2004/owl-s/1.1/BookFinder.owl cannot be parsed at impl.jena.OWLReaderImpl.createInputSource(OWLReaderImpl.java:125) at impl.jena.OWLReaderImpl.createInputSource(OWLReaderImpl.java:109) at impl.jena.OWLReaderImpl.read(OWLReaderImpl.java:169) at impl.jena.OWLKnowledgeBaseImpl.read(OWLKnowledgeBaseImpl.java:245) at examples.Matchmaker.addOntology(Matchmaker.java:76) at examples.Matchmaker.main(Matchmaker.java:170)
|