From: <jen...@us...> - 2008-01-07 16:23:00
|
Revision: 349 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=349&view=rev Author: jenslehmann Date: 2008-01-07 08:22:54 -0800 (Mon, 07 Jan 2008) Log Message: ----------- - OWL API reasoner implemented but not recommended yet * Pellet 1.5.1 working but no performance improvement - maybe due to a lot System out calls (one for each instance check) * FaCT++ 1.10 buggy; wrote a sample case for wrong behaviour in FaCTBugDemo and send it to FaCT developer Dmitry Tsarkov - CLI adapted such that new reasoner interface can be used - various smaller fixes in code and examples Modified Paths: -------------- trunk/examples/father2.conf trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Added Paths: ----------- trunk/examples/uncle.owl trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java Modified: trunk/examples/father2.conf =================================================================== --- trunk/examples/father2.conf 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/examples/father2.conf 2008-01-07 16:22:54 UTC (rev 349) @@ -8,7 +8,6 @@ */ reasoner = dig; -digReasonerURL = "http://localhost:8081"; import("father.owl"); // do not display http://example.com/father# in concepts @@ -19,9 +18,9 @@ digProtocolFile = "log/father2_dig.txt"; /** examples **/ -+father("http://example.com/father#stefan"). -+father("http://example.com/father#markus"). -+father("http://example.com/father#martin"). --father("http://example.com/father#heinz"). --father("http://example.com/father#anna"). --father("http://example.com/father#michelle"). ++"http://example.com/father#stefan" ++"http://example.com/father#markus" ++"http://example.com/father#martin" +-"http://example.com/father#heinz" +-"http://example.com/father#anna" +-"http://example.com/father#michelle" Added: trunk/examples/uncle.owl =================================================================== --- trunk/examples/uncle.owl (rev 0) +++ trunk/examples/uncle.owl 2008-01-07 16:22:54 UTC (rev 349) @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE rdf:RDF [ + <!ENTITY owl 'http://www.w3.org/2002/07/owl#'> +]> + +<rdf:RDF + xml:base="http://localhost/foo" + xmlns:a="http://localhost/foo#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> + +<owl:Ontology rdf:about=""/> + +<owl:Class rdf:about="&owl;Nothing"> + <owl:equivalentClass> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <owl:Class rdf:about="#male"/> + <owl:Class rdf:about="#female"/> + </owl:intersectionOf> + </owl:Class> + </owl:equivalentClass> +</owl:Class> + +<owl:ObjectProperty rdf:ID="hasSibling"> + <rdf:type rdf:resource="&owl;SymmetricProperty"/> +</owl:ObjectProperty> + +<owl:ObjectProperty rdf:ID="married"> + <rdf:type rdf:resource="&owl;SymmetricProperty"/> + <rdf:type rdf:resource="&owl;FunctionalProperty"/> +</owl:ObjectProperty> + +<a:male rdf:ID="alex"/> + +<a:male rdf:ID="alfred"> + <a:hasChild rdf:resource="#hans"/> + <a:hasSibling rdf:resource="#heinz"/> + <a:hasSibling rdf:resource="#maria"/> + <a:married rdf:resource="#katrin"/> +</a:male> + +<a:female rdf:ID="anna"> + <a:hasChild rdf:resource="#alfred"/> + <a:hasChild rdf:resource="#heinz"/> + <a:hasChild rdf:resource="#maria"/> + <a:married rdf:resource="#jan"/> +</a:female> + +<a:female rdf:ID="hanna"> + <a:hasChild rdf:resource="#jan"/> + <a:hasSibling rdf:resource="#alex"/> +</a:female> + +<a:male rdf:ID="hans"> + <a:married rdf:resource="#johanna"/> +</a:male> + +<a:male rdf:ID="heinrich"> + <a:married rdf:resource="#susi"/> +</a:male> + +<a:male rdf:ID="heinz"> + <a:hasSibling rdf:resource="#maria"/> +</a:male> + +<a:male rdf:ID="jan"> + <a:hasChild rdf:resource="#alfred"/> + <a:hasChild rdf:resource="#heinz"/> + <a:hasChild rdf:resource="#maria"/> +</a:male> + +<a:female rdf:ID="johanna"> + <a:hasSibling rdf:resource="#mandy"/> +</a:female> + +<a:female rdf:ID="katrin"> + <a:hasChild rdf:resource="#hans"/> +</a:female> + +<a:female rdf:ID="mandy"> + <a:hasChild rdf:resource="#miriam"/> +</a:female> + +<a:female rdf:ID="maria"> + <a:hasChild rdf:resource="#markus"/> +</a:female> + +<a:male rdf:ID="markus"/> + +<a:female rdf:ID="miriam"/> + +<a:female rdf:ID="susi"> + <a:hasSibling rdf:resource="#anna"/> +</a:female> + +<owl:Class rdf:ID="female"/> + +<owl:Class rdf:ID="male"/> + +<owl:ObjectProperty rdf:ID="hasChild"/> + +</rdf:RDF> Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-07 16:22:54 UTC (rev 349) @@ -70,6 +70,7 @@ import org.dllearner.parser.ParseException; import org.dllearner.parser.TokenMgrError; import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; @@ -132,6 +133,8 @@ // default value if (reasonerOption == null || reasonerOption.getStringValue().equals("dig")) reasonerClass = DIGReasoner.class; + else if(reasonerOption.getStringValue().equals("owlAPI")) + reasonerClass = OWLAPIReasoner.class; else { handleError("Unknown value " + reasonerOption.getStringValue() + "for option \"reasoner\"."); @@ -160,6 +163,7 @@ cm.applyConfigEntry(lp, "positiveExamples", posExamples); if(lpClass != PosOnlyDefinitionLP.class) cm.applyConfigEntry(lp, "negativeExamples", negExamples); + configureComponent(cm, lp, componentPrefixMapping, parser); initComponent(cm, lp); // step 4: detect learning algorithm @@ -230,7 +234,9 @@ componentPrefixMapping.put(SparqlEndpointRestructured.class, "sparql2"); // reasoners componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); + componentPrefixMapping.put(OWLAPIReasoner.class, "owlAPIReasoner"); // learning problems - configured via + and - flags for examples + componentPrefixMapping.put(PosNegDefinitionLP.class, "posNegDefinitionLP"); // learning algorithms componentPrefixMapping.put(ROLearner.class, "refinement"); componentPrefixMapping.put(GP.class, "gp"); Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-01-07 16:22:54 UTC (rev 349) @@ -99,9 +99,9 @@ else return negAsPos.size(); } else { - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { // two checks - if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { + if (useMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { Set<Individual> s = reasoningService.instanceCheck(concept, positiveExamples); // if the concept is too weak, then do not query negative // examples @@ -172,13 +172,13 @@ } return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); // instance checks for classification - } else { + } else { SortedSet<Individual> posAsPos = new TreeSet<Individual>(); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); SortedSet<Individual> negAsPos = new TreeSet<Individual>(); SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); - - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { SortedSet<Individual> posClassified = reasoningService.instanceCheck(concept, allExamples); SortedSet<Individual> negClassified = Helper.difference(allExamples, @@ -187,15 +187,20 @@ posAsNeg = Helper.intersection(positiveExamples, negClassified); negAsPos = Helper.intersection(negativeExamples, posClassified); negAsNeg = Helper.intersection(negativeExamples, negClassified); + + // System.out.println("pos classified: " + posClassified); + return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); } else { - + System.out.println("TEST"); + for (Individual example : positiveExamples) { - if (reasoningService.instanceCheck(concept, example)) + if (reasoningService.instanceCheck(concept, example)) { posAsPos.add(example); - else - posAsNeg.add(example); + } else { + posAsNeg.add(example); System.out.println(concept + " " + example); + } } for (Individual example : negativeExamples) { if (reasoningService.instanceCheck(concept, example)) Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-01-07 16:22:54 UTC (rev 349) @@ -124,9 +124,9 @@ SortedSet<Individual> negExInNegatedConcept = Helper.intersection(negativeExamples, inNegatedConcept); return (negativeExamples.size() - negExInNegatedConcept.size()); } else { - if (useDIGMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { // two checks - if (useDIGMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { + if (useMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { Set<Individual> posExInNegatedConcept = reasoningService.instanceCheck(new Negation(concept), positiveExamples); if(posExInNegatedConcept.size()>0) { Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-01-07 16:22:54 UTC (rev 349) @@ -32,6 +32,7 @@ import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; @@ -48,7 +49,7 @@ protected SortedSet<Individual> allExamples; protected boolean useRetrievalForClassification = false; - protected UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + protected UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; protected double percentPerLengthUnit = 0.05; /** @@ -90,6 +91,9 @@ options.add(new BooleanConfigOption("useRetrievalForClassficiation", "Specifies whether to use retrieval or instance checks for testing a concept.")); options.add(CommonConfigOptions.getPercentPerLenghtUnitOption(0.05)); + StringConfigOption multiInstanceChecks = new StringConfigOption("useMultiInstanceChecks", "See UseMultiInstanceChecks enum."); + multiInstanceChecks.setAllowedValues(new String[] {"never", "twoChecks", "oneCheck"}); + options.add(multiInstanceChecks); return options; } @@ -112,6 +116,15 @@ useRetrievalForClassification = (Boolean) entry.getValue(); else if (name.equals("percentPerLengthUnit")) percentPerLengthUnit = (Double) entry.getValue(); + else if (name.equals("useMultiInstanceChecks")) { + String value = (String) entry.getValue(); + if(value.equals("oneCheck")) + useMultiInstanceChecks = UseMultiInstanceChecks.ONECHECK; + else if(value.equals("twoChecks")) + useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + else + useMultiInstanceChecks = UseMultiInstanceChecks.NEVER; + } } /* Added: trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java 2008-01-07 16:22:54 UTC (rev 349) @@ -0,0 +1,65 @@ +package org.dllearner.reasoning; + +import org.semanticweb.owl.model.*; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; +import org.semanticweb.owl.inference.OWLReasonerException; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; +import java.io.File; + +public class FaCTBugDemo { + + public static void main(String[] args) { + + try { + URI uri = new File("examples/father.owl").toURI(); + + // Create our ontology manager in the usual way. + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + // Load a copy of the pizza ontology. We'll load the ontology from the web. + OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri); + + OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); + // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); + + // seems to be needed for some reason although no ontology is imported + Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); + reasoner.loadOntologies(importsClosure); + + reasoner.classify(); + reasoner.realise(); + + OWLDataFactory factory = manager.getOWLDataFactory(); + + OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male")); + OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild")); + OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing()); + Set<OWLDescription> set = new HashSet<OWLDescription>(); + set.add(male); + set.add(hasSomeChild); + OWLDescription father = factory.getOWLObjectIntersectionOf(set); + OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin")); + + if(reasoner.hasType(martin, father, false)) + System.out.println("positive result"); // Pellet 1.5.1 (correct) + else + System.out.println("negative result"); // FaCT++ 1.10 + + } + catch(UnsupportedOperationException exception) { + System.out.println("Unsupported reasoner operation."); + } + catch(OWLReasonerException ex) { + System.out.println("Reasoner error: " + ex.getMessage()); + } + catch (OWLOntologyCreationException e) { + System.out.println("Could not load the pizza ontology: " + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-07 16:12:15 UTC (rev 348) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-01-07 16:22:54 UTC (rev 349) @@ -19,6 +19,7 @@ */ package org.dllearner.reasoning; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -80,7 +81,7 @@ */ public class OWLAPIReasoner extends ReasonerComponent { - private String reasonerType = "FaCT++"; + private String reasonerType = "fact"; private Set<KnowledgeSource> sources; private OWLReasoner reasoner; @@ -109,7 +110,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); StringConfigOption type = new StringConfigOption("reasonerType", "FaCT++ or Pellet", "FaCT++"); - type.setAllowedValues(new String[] {"FaCT++", "Pellet"}); + type.setAllowedValues(new String[] {"fact", "pellet"}); // closure-Option? siehe: // http://owlapi.svn.sourceforge.net/viewvc/owlapi/owl1_1/trunk/tutorial/src/main/java/uk/ac/manchester/owl/tutorial/examples/ClosureAxiomsExample.java?view=markup options.add(type); @@ -143,15 +144,29 @@ Set<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(namedObjectComparator); Set<OWLIndividual> owlIndividuals = new TreeSet<OWLIndividual>(namedObjectComparator); + Set<OWLOntology> allImports = new HashSet<OWLOntology>(); + for(KnowledgeSource source : sources) { if(!(source instanceof OWLFile)) { System.out.println("Currently, only OWL files are supported. Ignoring knowledge source " + source + "."); } else { URL url = ((OWLFile)source).getURL(); + /* try { + url = new URL("http://www.co-ode.org/ontologies/pizza/2007/02/12/pizza.owl"); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + */ + try { OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); + allImports.addAll(manager.getImportsClosure(ontology)); classes.addAll(ontology.getReferencedClasses()); properties.addAll(ontology.getReferencedObjectProperties()); + // does not seem to work => workaround: query all instances of Top + // maybe one can also query for instances of OWLObjectProperty, + // OWLClass, OWLIndividual owlIndividuals.addAll(ontology.getReferencedIndividuals()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); @@ -162,7 +177,7 @@ } // create actual reasoner - if(reasonerType.equals("FaCT++")) { + if(reasonerType.equals("fact")) { try { reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); } catch (Exception e) { @@ -173,9 +188,24 @@ reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); } + /* + Set<OWLOntology> importsClosure = manager.getImportsClosure(ontology); + System.out.println("imports closure : " + importsClosure); + try { + reasoner.loadOntologies(importsClosure); + } catch (OWLReasonerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ + + System.out.println(classes); + System.out.println(properties); + System.out.println(individuals); + // compute class hierarchy and types of individuals // (done here to speed up later reasoner calls) try { + reasoner.loadOntologies(allImports); reasoner.classify(); reasoner.realise(); } catch (OWLReasonerException e) { @@ -184,6 +214,18 @@ factory = manager.getOWLDataFactory(); + + + try { + if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) + System.out.println("DEFINED."); + else + System.out.println("NOT DEFINED."); + } catch (OWLReasonerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // read in primitives atomicConcepts = new TreeSet<AtomicConcept>(conceptComparator); for(OWLClass owlClass : classes) @@ -370,17 +412,20 @@ } } - // TODO @Override public SortedSet<Individual> retrieval(Concept concept) { OWLDescription d = getOWLAPIDescription(concept); + Set<OWLIndividual> individuals = null; try { - reasoner.getIndividuals(d, false); + individuals = reasoner.getIndividuals(d, false); } catch (OWLReasonerException e) { // TODO Auto-generated catch block e.printStackTrace(); } - return null; + SortedSet<Individual> inds = new TreeSet<Individual>(); + for(OWLIndividual ind : individuals) + inds.add(new Individual(ind.getURI().toString())); + return inds; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |