From: <ku...@us...> - 2008-10-09 22:26:34
|
Revision: 1358 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1358&view=rev Author: kurzum Date: 2008-10-09 22:26:23 +0000 (Thu, 09 Oct 2008) Log Message: ----------- some changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java Property Changed: ---------------- trunk/src/dl-learner/org/dllearner/cli/ Property changes on: trunk/src/dl-learner/org/dllearner/cli ___________________________________________________________________ Added: svn:ignore + QuickNew.java Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java 2008-10-09 14:20:56 UTC (rev 1357) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/BlankNode.java 2008-10-09 22:26:23 UTC (rev 1358) @@ -153,8 +153,9 @@ tmp.add(next.blankNodes.get(0)); //System.out.println("bnode added"); }else{ - System.out.println("double nesting not supported yet"); - System.exit(0); + + tail("double nesting not supported yet"); + } } }//end while @@ -165,14 +166,14 @@ return factory.getOWLObjectUnionOf(target); }else if(inboundEdge.equals(OWLVocabulary.OWL_complementOf)){ if(target.size()>1) { - logger.warn("more than one complement"+target); - System.exit(0); + tail("more than one complement"+target); + }else{ return factory.getOWLObjectComplementOf(new ArrayList<OWLDescription>(target).remove(0)); } }else{ printAll(); - tail("wrong type: " +inboundEdge+ this); + tail("bnode: wrong type: " +inboundEdge+ this); } } @@ -193,23 +194,23 @@ } public void printAll(){ - System.out.println(this); + logger.debug(this); - System.out.println("otherNodes"); + logger.debug("otherNodes"); for (StringTuple t : otherNodes) { - System.out.println(""+t); + logger.debug(""+t); } - System.out.println("***************"); - System.out.println("dtype "); + logger.debug("***************"); + logger.debug("dtype "); for (DatatypePropertyNode d : datatypeProperties) { - System.out.println(d.getURIString()+" "+d.getNTripleFormOfB()); + logger.debug(d.getURIString()+" "+d.getNTripleFormOfB()); } - System.out.println("***************"); - System.out.println("other bnodes"); + logger.debug("***************"); + logger.debug("other bnodes"); for (BlankNode b : blankNodes) { - System.out.println(b); + logger.debug(b); } - System.out.println("***************"); + logger.debug("***************"); } @@ -221,7 +222,7 @@ int total = otherNodes.size()+blankNodes.size()+datatypeProperties.size(); if(total >=4 ){ - System.out.println("qualified p restrictions not supported currently"); + logger.info("qualified p restrictions not supported currently"); } // get Objectproperty Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-10-09 14:20:56 UTC (rev 1357) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-10-09 22:26:23 UTC (rev 1358) @@ -148,6 +148,7 @@ public void toOWLOntology( OWLAPIOntologyCollector owlAPIOntologyCollector){ try{ OWLDataFactory factory = owlAPIOntologyCollector.getFactory(); + OWLClass me =factory.getOWLClass(getURI()); for (ObjectPropertyNode one : classProperties) { OWLClass c = factory.getOWLClass(one.getBPart().getURI()); @@ -157,8 +158,12 @@ owlAPIOntologyCollector.addAxiom(factory.getOWLDisjointClassesAxiom(me, c)); }else if(one.getURIString().equals(OWLVocabulary.OWL_EQUIVALENT_CLASS)){ owlAPIOntologyCollector.addAxiom(factory.getOWLEquivalentClassesAxiom(me, c)); + }else if(one.getURIString().equals(OWLVocabulary.RDFS_IS_DEFINED_BY)){ + logger.warn("IGNORING: "+OWLVocabulary.RDFS_IS_DEFINED_BY); + continue; }else { - tail( getURIString()+"||"+one.getURIString()); + tail(true, "in ontology conversion"+" object property is: "+one.getURIString()+" connected with: "+one.getBPart().getURIString()); + continue; } one.getBPart().toOWLOntology(owlAPIOntologyCollector); } @@ -173,7 +178,8 @@ OWLLabelAnnotation label = factory.getOWLLabelAnnotation(one.getBPart().getLiteral().getString()); owlAPIOntologyCollector.addAxiom(factory.getOWLEntityAnnotationAxiom(me, label)); }else { - tail(getURIString()+"||"+one.getURIString()); + tail(true, "in ontology conversion, no other datatypes, but annotation allowed for class"+" data property is: "+one.getURIString()+" connected with: "+one.getBPart().getNTripleForm()); + } } @@ -187,7 +193,8 @@ }else if(bn.getInBoundEdge().equals(OWLVocabulary.OWL_EQUIVALENT_CLASS)){ owlAPIOntologyCollector.addAxiom(factory.getOWLEquivalentClassesAxiom(me, target)); }else { - tail( getURIString()+"||"+bn.getInBoundEdge()); + tail( "in ontology conversion"+" bnode is: "+bn.getInBoundEdge()+"||"+ bn ); + } } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-10-09 14:20:56 UTC (rev 1357) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-10-09 22:26:23 UTC (rev 1358) @@ -105,7 +105,7 @@ return tmp; } } catch (Exception e) { - System.out.println("Problem with: " + tuple); + tail("process tuple: problem with: " + tuple); e.printStackTrace(); return null; } @@ -221,7 +221,7 @@ } else { - tail(getURIString()+"||"+one.getURIString()); + tail("strange dataytype in ontology conversion" + one.getURIString()+" datatype: "+one.getBPart().getNTripleForm()); } //handover @@ -229,7 +229,7 @@ }catch (Exception e) { e.printStackTrace(); - System.exit(0); + tail("strange dataytype in ontology conversion" + one.getURIString()+" datatype: "+one.getBPart().getNTripleForm()); } } //factory.getOWLDataPropertyAssertionAxiom() Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-10-09 14:20:56 UTC (rev 1357) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-10-09 22:26:23 UTC (rev 1358) @@ -107,10 +107,27 @@ return expanded; } - public void tail(String uri){ - if(DEBUGTAIL){ - logger.warn("missing: "+uri); - System.exit(0); + public void tail( String tailmessage){ + boolean ignore = !DEBUGTAIL; + tail(ignore, tailmessage); + } + + public void tail(boolean ignore, String tailmessage){ + + String message = "difficult tuple. Subject is: "+ this.getURIString()+" of class"+this.getClass().getSimpleName()+" " + + "info: "+tailmessage; + if(ignore){ + if(DEBUGTAIL){ + logger.info("IGNORING: "+message); + }else { + logger.debug("IGNORING: "+message); + } + + + }else{ + logger.warn(message); + logger.error("exiting "); + System.exit(0); } } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java 2008-10-09 14:20:56 UTC (rev 1357) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ObjectPropertyNode.java 2008-10-09 22:26:23 UTC (rev 1358) @@ -95,7 +95,7 @@ } } catch (Exception e) { - logger.warn("resource "+uri+" with "+ tuple); + tail("expand properties: with tuple: "+ tuple); e.printStackTrace(); } @@ -157,7 +157,7 @@ // XXX comments } else { - tail(getURIString()+"||"+one); + tail("conversion to ontology: property information: " + one); } } @@ -173,7 +173,7 @@ }else if(one.equals(OWLVocabulary.OWL_SymmetricProperty)){ owlAPIOntologyCollector.addAxiom(factory.getOWLSymmetricObjectPropertyAxiom(me)); }else{ - tail(getURIString()+"||"+one); + tail("conversion to ontology: special types: " + one); } } for (BlankNode bn : blankNodes) { Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-10-09 14:20:56 UTC (rev 1357) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-10-09 22:26:23 UTC (rev 1358) @@ -29,6 +29,7 @@ public static final String RDFS_SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; public static final String RDFS_CLASS = "http://www.w3.org/2000/01/rdf-schema#Class"; + public static final String RDFS_IS_DEFINED_BY = "http://www.w3.org/2000/01/rdf-schema#isDefinedBy"; public static final String RDFS_COMMENT = "http://www.w3.org/2000/01/rdf-schema#comment"; public static final String RDFS_LABEL = "http://www.w3.org/2000/01/rdf-schema#label"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-10-10 07:52:16
|
Revision: 1359 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1359&view=rev Author: kurzum Date: 2008-10-10 07:52:08 +0000 (Fri, 10 Oct 2008) Log Message: ----------- Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/manipulator/ObjectReplacementRule.java trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java Modified: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; +import java.util.List; /** * A tool to quickly start a learning example. It detects all conf files in the @@ -38,14 +39,15 @@ * @author Jens Lehmann */ public class QuickStart { - + // static HashMap<String, ArrayList<String>> hm = null; static String pm = ".";// pathmodifier + static List<String> conffiles = new ArrayList<String>(); public static void main(String[] args) { - + String lastused = readit(); String tab = " "; int the_Number = 0; @@ -119,7 +121,27 @@ number = true; break; } catch (Exception e) { + + for(String one:conffiles){ + + if(one.contains(cmd)){ + System.out.println("Did you mean "+one+" ? (Press enter to confirm,\n" + + "any key+enter for another try)"); + cmd = br.readLine(); + if(cmd.length()==0){ + writeit(one); + if(!query) { + Start.main(new String[] { one }); + }else { + Start.main(new String[] {"-q",one}); + } + return; + }else {break;} + } + } + System.out.println("Not a number"); + continue; } }// end while @@ -166,6 +188,7 @@ confs.put(path, new ArrayList<String>()); } confs.get(path).add(act[i].substring(0, act[i].length() - 5)); + conffiles.add(path+act[i]); // System.out.println(act[i].substring(0,act[i].length()-5)); // System.out.println(hm.get(path).size()); // hm.put(new Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -195,7 +195,7 @@ //OWLCommentAnnotation comment = factory.getOWL(one.b.toString()); //owlAPIOntologyCollector.addAxiom(factory.getOWLEntityAnnotationAxiom(me, label)); }else if(one.getURIString().equals(OWLVocabulary.RDFS_LABEL)){ - OWLLabelAnnotation label = factory.getOWLLabelAnnotation(one.b.toString()); + OWLLabelAnnotation label = factory.getOWLLabelAnnotation(ln.getString()); owlAPIOntologyCollector.addAxiom(factory.getOWLEntityAnnotationAxiom(me, label)); }else{ Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/ObjectReplacementRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/ObjectReplacementRule.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/ObjectReplacementRule.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -45,8 +45,9 @@ public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); for (RDFNodeTuple tuple : tuples) { - if(tuple.aPartContains(oldObject)){ - tuple.a = new ResourceImpl(newObject); + if(tuple.bPartContains(oldObject)){ + String tmp = tuple.b.toString().replace(oldObject, newObject); + tuple.b = new ResourceImpl(tmp); JamonMonitorLogger.increaseCount(ObjectReplacementRule.class, "replacedObjects"); } keep.add(tuple); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -440,7 +440,7 @@ rsw.reset(); } catch (Exception e) { - logger.warn("Exception caught in SPARQLTasks, passing emtpy result: "+e.getMessage()); + logger.info("ignoring (see log for details): Exception caught in SPARQLTasks, passing emtpy result: "+e.getMessage()); } return returnSet; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -59,6 +59,7 @@ import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.datastructures.StringTuple; import org.dllearner.utilities.statistics.SimpleClock; +import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLOntology; import com.jamonapi.Monitor; @@ -291,7 +292,9 @@ fragment = m.getOWLAPIOntologyForNodes(seedNodes, configurator.getSaveExtractedFragment()); - + for (OWLAxiom a : fragment.getClassAxioms()){ + System.out.println(a); + } logger.info("Finished collecting fragment. needed "+extractionTime.getLastValue()+" ms"); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -127,16 +127,16 @@ //writeToSparqlLog("JSON: " + json); //}catch (ResultSetException e) { } catch (HTTPException e) { - logger.warn("HTTPException in SparqlQuery\n"+ e.toString()); - logger.warn("query was "+ sparqlQueryString); + logger.debug("HTTPException in SparqlQuery\n"+ e.toString()); + logger.debug("query was "+ sparqlQueryString); writeToSparqlLog("ERROR: HTTPException occured"+ e.toString()); isRunning = false; throw e; }catch (RuntimeException e) { - logger.warn("RuntimeException in SparqlQuery (see /log/sparql.txt): "+ e.toString()); - logger.warn("query was (first 300 chars) "+ sparqlQueryString.substring(0,300).replaceAll("\n", " ")); + logger.debug("RuntimeException in SparqlQuery (see /log/sparql.txt): "+ e.toString()); + logger.debug("query was (first 300 chars) "+ sparqlQueryString.substring(0,300).replaceAll("\n", " ")); writeToSparqlLog("ERROR: HTTPException occured: "+ e.toString()); isRunning = false; throw e; Modified: trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java 2008-10-09 22:26:23 UTC (rev 1358) +++ trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java 2008-10-10 07:52:08 UTC (rev 1359) @@ -91,14 +91,14 @@ // in the conf file about "optimal" parameters) ignore.add("./examples/sparql/govtrack.conf"); // HTTP 500 Server error ignore.add("./examples/sparql/musicbrainz.conf"); // HTTP 502 error - NullPointer in extraction - ignore.add("./examples/sparql/SKOSTEST_local.conf"); // Out of Memory Error + //working fine here ignore.add("./examples/sparql/SKOSTEST_local.conf"); // Out of Memory Error ignore.add("./examples/sparql/scrobble.conf"); // HTTP 502 Proxy Error // ignore.add("./examples/family-benchmark/Cousin.conf"); // Out of Memory Error => disallowing ALL helps (TODO find out details) - ignore.add("./examples/sparql/SilentBobWorking2.conf"); // Out of Memory Error + //also working fine ignore.add("./examples/sparql/SilentBobWorking2.conf"); // Out of Memory Error ignore.add("./examples/sparql/difference/DBPediaSKOS_kohl_vs_angela.conf"); // Pellet: literal cannot be cast to individual // ignore.add("./examples/family-benchmark/Aunt.conf"); // did not terminate so far (waited 45 minutes) => disallowing ALL helps (TODO find out details) ignore.add("./examples/krk/KRK_ZERO_against_1to5_fastInstance.conf"); // Out of Memory Error - ignore.add("./examples/semantic_bible/normal_test.conf"); // did not terminate (waited 55 minutes) + //removed ignore.add("./examples/semantic_bible/normal_test.conf"); // did not terminate (waited 55 minutes) int failedCounter = 0; for (String path : confFiles.keySet()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-10-21 10:25:23
|
Revision: 1385 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1385&view=rev Author: sknappe Date: 2008-10-21 10:25:14 +0000 (Tue, 21 Oct 2008) Log Message: ----------- changes to use specific endpoint for natural language conversion Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-18 19:32:50 UTC (rev 1384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-21 10:25:14 UTC (rev 1385) @@ -44,10 +44,10 @@ private SPARQLTasks tasks; - public NaturalLanguageDescriptionConvertVisitor() + public NaturalLanguageDescriptionConvertVisitor(String endpoint) { //stack.push("subject"); - tasks=new SPARQLTasks(new Cache("cache"),SparqlEndpoint.getEndpointDBpedia()); + tasks=new SPARQLTasks(new Cache("cache"),SparqlEndpoint.getEndpointByName(endpoint)); } private String getDescription() @@ -62,16 +62,16 @@ public static String getNaturalLanguageDescription(Description description) { - NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor(); + NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor("DBpedia"); description.accept(visitor); String ret = visitor.getDescription(); return ret; } - public static String getNaturalLanguageDescription(String descriptionKBSyntax) throws ParseException + public static String getNaturalLanguageDescription(String descriptionKBSyntax, String endpoint) throws ParseException { Description d = KBParser.parseConcept(descriptionKBSyntax); - NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor(); + NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor(endpoint); d.accept(visitor); String ret = visitor.getDescription(); return ret; @@ -98,7 +98,7 @@ s.add("NOT \"http://dbpedia.org/class/yago/Person100007846\""); s.add("(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND \"http://dbpedia.org/class/yago/Representative110522035\"))"); for (String kbsyntax : s) { - result.put(kbsyntax,NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(kbsyntax)); + result.put(kbsyntax,NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(kbsyntax,"DBPEDIA")); } System.out.println("************************"); for (String string : result.keySet()) { Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-18 19:32:50 UTC (rev 1384) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-21 10:25:14 UTC (rev 1385) @@ -720,9 +720,9 @@ } @WebMethod - public String getNaturalDescription(String conceptString) throws ParseException { + public String getNaturalDescription(String conceptString, String endpoint) throws ParseException { // call parser to parse concept - return NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(conceptString); + return NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(conceptString, endpoint); } @WebMethod This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-10-23 08:44:04
|
Revision: 1415 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1415&view=rev Author: JensLehmann Date: 2008-10-23 08:43:03 +0000 (Thu, 23 Oct 2008) Log Message: ----------- EL refinement ctd. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-10-23 07:41:02 UTC (rev 1414) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-10-23 08:43:03 UTC (rev 1415) @@ -71,11 +71,11 @@ // simulation information (list or set?) protected Set<ELDescriptionNode> in = new HashSet<ELDescriptionNode>(); - private Set<ELDescriptionNode> inSC1 = new HashSet<ELDescriptionNode>(); - private Set<ELDescriptionNode> inSC2 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> inSC1 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> inSC2 = new HashSet<ELDescriptionNode>(); protected Set<ELDescriptionNode> out = new HashSet<ELDescriptionNode>(); - private Set<ELDescriptionNode> outSC1 = new HashSet<ELDescriptionNode>(); - private Set<ELDescriptionNode> outSC2 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> outSC1 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> outSC2 = new HashSet<ELDescriptionNode>(); /** * Constructs an EL description tree with empty root label. @@ -98,7 +98,7 @@ tree.rootNode = this; tree.addNodeToLevel(this, level); - // TODO simulation update + // TODO simulation initialization } public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, NavigableSet<NamedClass> label) { @@ -126,16 +126,16 @@ } - if(inSC1.contains(w) && checkSC2(this, w)) { - extendSimulation(this, w); + if(inSC1.contains(w) && tree.checkSC2(this, w)) { + tree.extendSimulation(this, w); update.add(w.parent); } } // loop over all nodes in out set for(ELDescriptionNode w : out) { - if(!checkSC1(this, w)) { - shrinkSimulation(this, w); + if(!tree.checkSC1(this, w)) { + tree.shrinkSimulation(this, w); update.add(w.parent); } } @@ -299,16 +299,16 @@ Set<ELDescriptionNode> tmp = Helper.difference(nodes, in); for(ELDescriptionNode w : tmp) { // we only need to recompute SC2 - if(inSC1.contains(w) && checkSC2(this, w)) { - extendSimulation(this, w); + if(inSC1.contains(w) && tree.checkSC2(this, w)) { + tree.extendSimulation(this, w); update.add(w.parent); } } // loop over all nodes in out set for(ELDescriptionNode w : out) { - if(!checkSC1(this, w)) { - shrinkSimulation(this, w); + if(!tree.checkSC1(this, w)) { + tree.shrinkSimulation(this, w); update.add(w.parent); } } @@ -316,89 +316,36 @@ // apply updates recursively top-down tree.updateSimulation(update); } - - // SC satisfied if both SC1 and SC2 satisfied - private boolean checkSC(ELDescriptionNode node1, ELDescriptionNode node2) { - return checkSC1(node1, node2) && checkSC2(node1, node2); - } - - // tests simulation condition 1 (SC1) - private boolean checkSC1(ELDescriptionNode node1, ELDescriptionNode node2) { - return isSublabel(node1.label, node2.label); - } - - private boolean isSublabel(NavigableSet<NamedClass> subLabel, NavigableSet<NamedClass> superLabel) { - // implemented according to definition in article - // (TODO can probably be done more efficiently) - for(NamedClass nc : superLabel) { - if(!containsSubclass(nc, subLabel)) { - return false; - } - } - return true; - } - - private boolean containsSubclass(NamedClass superClass, NavigableSet<NamedClass> label) { - for(NamedClass nc : label) { - if(tree.subsumptionHierarchy.isSubclassOf(nc, superClass)) { - return true; - } - } - return false; - } - - // tests simulation condition 2 (SC2) - private boolean checkSC2(ELDescriptionNode node1, ELDescriptionNode node2) { - List<ELDescriptionEdge> edges1 = node1.getEdges(); - List<ELDescriptionEdge> edges2 = node2.getEdges(); + + public void refineEdge(int edgeNumber, ObjectProperty op) { + edges.get(edgeNumber).setLabel(op); - for(ELDescriptionEdge edge : edges1) { - // try to find an edge satisfying SC2 in the set - if(!checkSC2Edge(edge, edges2)) { - return false; + // compute the nodes, which need to be updated + Set<ELDescriptionNode> update = new TreeSet<ELDescriptionNode>(); + + // loop over all nodes on the same level, which are not in the in set + Set<ELDescriptionNode> nodes = tree.getNodesOnLevel(level); + Set<ELDescriptionNode> tmp = Helper.difference(nodes, in); + for(ELDescriptionNode w : tmp) { + // we only need to recompute SC1 + if(inSC2.contains(w) && tree.checkSC1(this, w)) { + tree.extendSimulation(this, w); + update.add(w.parent); } } - return true; - } - - // check whether edges contains an element satisfying SC2 - private boolean checkSC2Edge(ELDescriptionEdge edge, List<ELDescriptionEdge> edges) { - ObjectProperty op1 = edge.getLabel(); - ELDescriptionNode node1 = edge.getTree(); - - for(ELDescriptionEdge edge2 : edges) { - ObjectProperty op2 = edge2.getLabel(); - // we first check the condition on the properties - if(tree.roleHierarchy.isSubpropertyOf(op1, op2)) { - // check condition on simulations of referred nodes - ELDescriptionNode node2 = edge2.getTree(); - if(node1.in.contains(node2) || node2.in.contains(node1)) { - // we found a node satisfying the condition, so we can return - return true; - } + // loop over all nodes in out set + for(ELDescriptionNode w : out) { + if(!tree.checkSC2(this, w)) { + tree.shrinkSimulation(this, w); + update.add(w.parent); } } - // none of the edges in the set satisfies the 2nd simulation criterion - // wrt. the first edge - return false; + // apply updates recursively top-down + tree.updateSimulation(update); } - - // adds (node1,node2) to simulation, takes care of all helper sets - private void extendSimulation(ELDescriptionNode node1, ELDescriptionNode node2) { - node1.out.add(node2); - node2.in.add(node1); - // TODO: SC1, SC2 sets ? - } - // removes (node1,node2) from simulation, takes care of all helper sets - private void shrinkSimulation(ELDescriptionNode node1, ELDescriptionNode node2) { - node1.out.remove(node2); - node2.in.remove(node1); - // TODO: SC1, SC2 sets ? - } - /** * Gets the label of this node. Do not modify the returned object, * but use the provided methods instead! @@ -443,4 +390,8 @@ } return str; } + + public ELDescriptionNode getParent() { + return parent; + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-23 07:41:02 UTC (rev 1414) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-23 08:43:03 UTC (rev 1415) @@ -23,7 +23,9 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.NavigableSet; import java.util.Set; +import java.util.Stack; import java.util.TreeSet; import org.dllearner.core.ReasoningService; @@ -222,16 +224,118 @@ } protected void updateSimulation(Set<ELDescriptionNode> nUpdate) { -// for(ELDescriptionNode node : nodes) { -// -// } - Set<ELDescriptionNode> update; - while(nUpdate.size() != 0) { - update = nUpdate; // TODO: clone - + // create a stack and initialize it with the nodes to be updated + Stack<ELDescriptionNode> stack = new Stack<ELDescriptionNode>(); + stack.addAll(nUpdate); + + while(stack.size() != 0) { + // take element from bottom of stack (to ensure that all nodes on the + // same level are tested before any node of a lower level is tested) + ELDescriptionNode v = stack.peek(); // TODO: lookup whether peek is correct (had no Javadoc here) + // loop through all nodes on same level + for(ELDescriptionNode w : levelNodeMapping.get(v.getLevel())) { + if(!v.out.contains(w) && v.outSC1.contains(w) && checkSC2(v,w)) { + extendSimulation(v,w); + stack.add(v.getParent()); + stack.add(w.getParent()); + } + if(!w.out.contains(v) && w.outSC1.contains(v) && checkSC2(w,v)) { + extendSimulation(w,v); + stack.add(v.getParent()); + stack.add(w.getParent()); + } + } } } + // SC satisfied if both SC1 and SC2 satisfied + public boolean checkSC(ELDescriptionNode node1, ELDescriptionNode node2) { + return checkSC1(node1, node2) && checkSC2(node1, node2); + } + + // tests simulation condition 1 (SC1) + public boolean checkSC1(ELDescriptionNode node1, ELDescriptionNode node2) { + return isSublabel(node1.getLabel(), node2.getLabel()); + } + + private boolean isSublabel(NavigableSet<NamedClass> subLabel, NavigableSet<NamedClass> superLabel) { + // implemented according to definition in article + // (TODO can probably be done more efficiently) + for(NamedClass nc : superLabel) { + if(!containsSubclass(nc, subLabel)) { + return false; + } + } + return true; + } + + private boolean containsSubclass(NamedClass superClass, NavigableSet<NamedClass> label) { + for(NamedClass nc : label) { + if(subsumptionHierarchy.isSubclassOf(nc, superClass)) { + return true; + } + } + return false; + } + + // tests simulation condition 2 (SC2) + public boolean checkSC2(ELDescriptionNode node1, ELDescriptionNode node2) { + List<ELDescriptionEdge> edges1 = node1.getEdges(); + List<ELDescriptionEdge> edges2 = node2.getEdges(); + + for(ELDescriptionEdge edge : edges1) { + // try to find an edge satisfying SC2 in the set + if(!checkSC2Edge(edge, edges2)) { + return false; + } + } + + return true; + } + + // check whether edges contains an element satisfying SC2 + private boolean checkSC2Edge(ELDescriptionEdge edge, List<ELDescriptionEdge> edges) { + ObjectProperty op1 = edge.getLabel(); + ELDescriptionNode node1 = edge.getTree(); + + for(ELDescriptionEdge edge2 : edges) { + ObjectProperty op2 = edge2.getLabel(); + // we first check the condition on the properties + if(roleHierarchy.isSubpropertyOf(op1, op2)) { + // check condition on simulations of referred nodes + ELDescriptionNode node2 = edge2.getTree(); + if(node1.in.contains(node2) || node2.in.contains(node1)) { + // we found a node satisfying the condition, so we can return + return true; + } + } + } + + // none of the edges in the set satisfies the 2nd simulation criterion + // wrt. the first edge + return false; + } + + // adds (node1,node2) to simulation, takes care of all helper sets + public void extendSimulation(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.out.add(node2); + node1.outSC1.add(node2); + node1.outSC2.add(node2); + node2.in.add(node1); + node2.inSC1.add(node1); + node2.inSC2.add(node1); + } + + // removes (node1,node2) from simulation, takes care of all helper sets + public void shrinkSimulation(ELDescriptionNode node1, ELDescriptionNode node2) { + node1.out.remove(node2); + node1.outSC1.remove(node2); + node1.outSC2.remove(node2); + node2.in.remove(node1); + node2.inSC1.remove(node1); + node2.inSC2.remove(node1); + } + @Override public ELDescriptionTree clone() { // create a new reference tree Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-10-23 07:41:02 UTC (rev 1414) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-10-23 08:43:03 UTC (rev 1415) @@ -259,9 +259,9 @@ // clone operation ELDescriptionTree clonedTree = tree.clone(); // find cloned edge and replace its label - ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber); - clonedEdge.setLabel(op2); - // TODO simulation update + clonedTree.getNode(position).refineEdge(edgeNumber, op2); +// ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber); +// clonedEdge.setLabel(op2); refinements.add(clonedTree); } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-10-23 07:41:02 UTC (rev 1414) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-10-23 08:43:03 UTC (rev 1415) @@ -34,6 +34,7 @@ import org.dllearner.parser.ParseException; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.ELDown; +import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; import org.junit.Test; @@ -75,6 +76,7 @@ // input description Description input = KBParser.parseConcept("(human AND EXISTS has.animal)"); + System.out.println("refining: " + input); // create reasoner KBFile source = new KBFile(kb); @@ -114,14 +116,21 @@ } // perform refinement and compare solutions + long startTime = System.nanoTime(); Set<Description> refinements = operator.refine(input); + long runTime = System.nanoTime() - startTime; + System.out.println("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + "."); + startTime = System.nanoTime(); + refinements = operator.refine(input); + runTime = System.nanoTime() - startTime; + System.out.println("Identical 2nd refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + "."); // number of refinements has to be correct and each produced // refinement must be in the set of desired refinements // assertTrue(refinements.size() == desired.size()); for(Description refinement : refinements) { System.out.println(refinement); - assertTrue(desired.contains(refinement)); +// assertTrue(desired.contains(refinement)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-10-24 05:25:08
|
Revision: 1420 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1420&view=rev Author: JensLehmann Date: 2008-10-24 05:25:02 +0000 (Fri, 24 Oct 2008) Log Message: ----------- added more EL tests; fixed some bugs Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-23 14:23:29 UTC (rev 1419) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.NavigableSet; @@ -225,24 +226,24 @@ protected void updateSimulation(Set<ELDescriptionNode> nUpdate) { // create a stack and initialize it with the nodes to be updated - Stack<ELDescriptionNode> stack = new Stack<ELDescriptionNode>(); - stack.addAll(nUpdate); + LinkedList<ELDescriptionNode> list = new LinkedList<ELDescriptionNode>(); + list.addAll(nUpdate); - while(stack.size() != 0) { + while(list.size() != 0) { // take element from bottom of stack (to ensure that all nodes on the // same level are tested before any node of a lower level is tested) - ELDescriptionNode v = stack.peek(); // TODO: lookup whether peek is correct (had no Javadoc here) + ELDescriptionNode v = list.pollFirst(); // loop through all nodes on same level for(ELDescriptionNode w : levelNodeMapping.get(v.getLevel())) { if(!v.out.contains(w) && v.outSC1.contains(w) && checkSC2(v,w)) { extendSimulation(v,w); - stack.add(v.getParent()); - stack.add(w.getParent()); + list.add(v.getParent()); + list.add(w.getParent()); } if(!w.out.contains(v) && w.outSC1.contains(v) && checkSC2(w,v)) { extendSimulation(w,v); - stack.add(v.getParent()); - stack.add(w.getParent()); + list.add(v.getParent()); + list.add(w.getParent()); } } } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-10-23 14:23:29 UTC (rev 1419) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -28,11 +28,14 @@ import org.dllearner.algorithms.el.ELDescriptionTreeComparator; import org.dllearner.algorithms.el.Simulation; import org.dllearner.algorithms.el.TreeTuple; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; +import org.dllearner.test.junit.TestOntologies.TestOntology; import org.dllearner.utilities.owl.ConceptTransformation; import org.junit.Test; @@ -47,10 +50,10 @@ @Test public void simulationTest() { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.EMPTY); Simulation s = new Simulation(); - // TODO we need to add background knowledge (possibly empty) - ELDescriptionTree tree1 = null; // new ELDescriptionTree(); - ELDescriptionTree tree2 = null; // new ELDescriptionTree(); + ELDescriptionTree tree1 = new ELDescriptionTree(rs); + ELDescriptionTree tree2 = new ELDescriptionTree(rs); ELDescriptionNode t1 = new ELDescriptionNode(tree1); ELDescriptionNode t2 = new ELDescriptionNode(tree2); TreeTuple tuple1 = new TreeTuple(t1,t2); @@ -65,11 +68,21 @@ } @Test + public void minimalityTest() throws ParseException, ComponentInitException { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.SIMPLE); + // the following should be recognized as non-minimal + Description d = KBParser.parseConcept("(human AND (EXISTS has.animal AND EXISTS has.TOP))"); + ConceptTransformation.cleanConcept(d); + ELDescriptionTree tree = new ELDescriptionTree(rs, d); + assertFalse(tree.isMinimal()); + } + + @Test public void cloneTest() throws ParseException { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.EMPTY); Description d = KBParser.parseConcept("(male AND (human AND EXISTS hasChild.(female AND EXISTS hasChild.male)))"); ConceptTransformation.cleanConcept(d); - // TODO needs to be updated (trees now require background knowledge) - ELDescriptionTree tree = null; // new ELDescriptionTree(rs, d); + ELDescriptionTree tree = new ELDescriptionTree(rs, d); ELDescriptionTree treeCloned = tree.clone(); ELDescriptionTreeComparator comparator = new ELDescriptionTreeComparator(); assertTrue(comparator.compare(tree, treeCloned) == 0); Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-10-23 14:23:29 UTC (rev 1419) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -24,23 +24,17 @@ import java.util.TreeSet; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.KB; -import org.dllearner.kb.KBFile; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.ELDown; +import org.dllearner.test.junit.TestOntologies.TestOntology; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; import org.junit.Test; -import static org.junit.Assert.*; - /** * Tests related to the EL downward refinement operator. * @@ -59,36 +53,12 @@ */ @Test public void refinementTest() throws ParseException, ComponentInitException { - ComponentManager cm = ComponentManager.getInstance(); + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.SIMPLE); - // background knowledge - String kbString = ""; - kbString += "OPDOMAIN(hasChild) = human.\n"; - kbString += "OPRANGE(hasChild) = human.\n"; - kbString += "OPDOMAIN(hasPet) = human.\n"; - kbString += "OPRANGE(hasPet) = animal.\n"; - kbString += "Subrole(hasChild, has).\n"; - kbString += "Subrole(hasPet, has).\n"; - kbString += "bird SUB animal.\n"; - kbString += "cat SUB animal.\n"; - kbString += "(human AND animal) = BOTTOM.\n"; - KB kb = KBParser.parseKBFile(kbString); - // input description Description input = KBParser.parseConcept("(human AND EXISTS has.animal)"); - System.out.println("refining: " + input); + System.out.println("refining: " + input); - // create reasoner - KBFile source = new KBFile(kb); - ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source); - ReasoningService rs = cm.reasoningService(rc); - source.init(); - rc.init(); - // TODO there shouldn't be a need to call this explicitly! - // (otherwise we get a NullPointerException, because the hierarchy is not created) - rs.prepareSubsumptionHierarchy(); - rs.prepareRoleHierarchy(); - // TODO For this test, we need to turn instance based disjoints // off! (We do not have any instances here.) ELDown operator = new ELDown(rs); @@ -129,9 +99,18 @@ // refinement must be in the set of desired refinements // assertTrue(refinements.size() == desired.size()); for(Description refinement : refinements) { - System.out.println(refinement); + boolean ok = desired.contains(refinement); + System.out.println(ok + ": " + refinement); // assertTrue(desired.contains(refinement)); } + + // generated by operator (and currently corresponding to its definition): + // false (http://localhost/foo#human AND EXISTS http://localhost/foo#has.(http://localhost/foo#animal AND http://localhost/foo#human + // false (http://localhost/foo#animal AND http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal + // solution: element of ncc should be tested for disjointness with any other candidate (here: animal and human) + + // edge added, but refinement not recognized as being minimal + // (http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal AND EXISTS http://localhost/foo#has.TOP) } } Added: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-10-24 05:25:02 UTC (rev 1420) @@ -0,0 +1,84 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.test.junit; + +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.KB; +import org.dllearner.kb.KBFile; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.FastInstanceChecker; + +/** + * Some ontologies to simplify unit tests. + * + * @author Jens Lehmann + * + */ +public final class TestOntologies { + + public enum TestOntology { EMPTY, SIMPLE }; + + public static ReasoningService getTestOntology(TestOntology ont) { + String kbString = ""; + + if(ont.equals(TestOntology.EMPTY)) { + // no background knowledge + } else if(ont.equals(TestOntology.SIMPLE)) { + // background knowledge used in EL paper + kbString += "OPDOMAIN(hasChild) = human.\n"; + kbString += "OPRANGE(hasChild) = human.\n"; + kbString += "OPDOMAIN(hasPet) = human.\n"; + kbString += "OPRANGE(hasPet) = animal.\n"; + kbString += "Subrole(hasChild, has).\n"; + kbString += "Subrole(hasPet, has).\n"; + kbString += "bird SUB animal.\n"; + kbString += "cat SUB animal.\n"; + kbString += "(human AND animal) = BOTTOM.\n"; + } + + try { + KB kb = KBParser.parseKBFile(kbString); + + // create reasoner + ComponentManager cm = ComponentManager.getInstance(); + KBFile source = new KBFile(kb); + ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source); + ReasoningService rs = cm.reasoningService(rc); + source.init(); + rc.init(); + // TODO there shouldn't be a need to call this explicitly! + // (otherwise we get a NullPointerException, because the hierarchy is not created) + rs.prepareSubsumptionHierarchy(); + rs.prepareRoleHierarchy(); + return rs; + } catch(ParseException e) { + e.printStackTrace(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + + throw new Error("Test ontology could not be created."); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-10-24 06:21:50
|
Revision: 1421 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1421&view=rev Author: jenslehmann Date: 2008-10-24 06:21:43 +0000 (Fri, 24 Oct 2008) Log Message: ----------- added reasoning methods getRelatedIndividuals + getRelatedValues Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-10-24 05:25:02 UTC (rev 1420) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-10-24 06:21:43 UTC (rev 1421) @@ -75,6 +75,10 @@ public SortedSet<Individual> retrieval(Description concept) throws ReasoningMethodUnsupportedException; + public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException; + + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException; public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-10-24 05:25:02 UTC (rev 1420) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-10-24 06:21:43 UTC (rev 1421) @@ -104,6 +104,14 @@ throw new ReasoningMethodUnsupportedException(); } + public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-10-24 05:25:02 UTC (rev 1420) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-10-24 06:21:43 UTC (rev 1421) @@ -28,6 +28,7 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; @@ -456,8 +457,24 @@ return result; } - // gibt zu einer Rolle alle Elemente zur�ck - // private, da es keine Standardoperation ist + public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + try { + return reasoner.getRelatedIndividuals(individual, objectProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + try { + return reasoner.getRelatedValues(individual, datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { reasoningStartTimeTmp = System.nanoTime(); Map<Individual, SortedSet<Individual>> result; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-10-24 05:25:02 UTC (rev 1420) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-10-24 06:21:43 UTC (rev 1421) @@ -43,6 +43,7 @@ import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.configurators.FastInstanceCheckerConfigurator; import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; @@ -666,6 +667,16 @@ return opPos.get(atomicRole); } + @Override + public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + return rc.getRelatedIndividuals(individual, objectProperty); + } + + @Override + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + return rc.getRelatedValues(individual, datatypeProperty); + } + /* * (non-Javadoc) * Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-10-24 05:25:02 UTC (rev 1420) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-10-24 06:21:43 UTC (rev 1421) @@ -705,6 +705,55 @@ return map; } + @Override + public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) { + OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); + OWLObjectProperty prop = getOWLAPIDescription(objectProperty); + Set<OWLIndividual> inds = null; + try { + inds = reasoner.getRelatedIndividuals(ind, prop); + } catch (OWLReasonerException e) { + e.printStackTrace(); + } + // convert data back to DL-Learner structures + SortedSet<Individual> is = new TreeSet<Individual>(); + for(OWLIndividual oi : inds) { + is.add(new Individual(oi.getURI().toString())); + } + return is; + } + + @Override + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) { + OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); + OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + Set<OWLConstant> constants = null; + try { + constants = reasoner.getRelatedValues(ind, prop); + } catch (OWLReasonerException e) { + e.printStackTrace(); + } + // convert data back to DL-Learner structures + SortedSet<Constant> is = new TreeSet<Constant>(); + for(OWLConstant oi : constants) { + // for typed constants we have to figure out the correct + // data type and value + if(oi instanceof OWLTypedConstant) { + Datatype dt = convertDatatype(((OWLTypedConstant)oi).getDataType()); + is.add(new TypedConstant(oi.getLiteral(),dt)); + // for untyped constants we have to figure out the value + // and language tag (if any) + } else { + OWLUntypedConstant ouc = (OWLUntypedConstant) oi; + if(ouc.hasLang()) + is.add(new UntypedConstant(ouc.getLiteral(), ouc.getLang())); + else + is.add(new UntypedConstant(ouc.getLiteral())); + } + } + return is; + } + public Map<Individual, SortedSet<Double>> getDoubleValues(DatatypeProperty datatypeProperty) { OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); Map<Individual, SortedSet<Double>> map = new TreeMap<Individual, SortedSet<Double>>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-10-24 07:26:53
|
Revision: 1422 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1422&view=rev Author: jenslehmann Date: 2008-10-24 07:26:43 +0000 (Fri, 24 Oct 2008) Log Message: ----------- - annotation support in core OWL library - added method to get rdfs:label from entities Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/owl/Individual.java trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java trunk/src/dl-learner/org/dllearner/core/owl/Property.java trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java trunk/src/dl-learner/org/dllearner/core/owl/Entity.java trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -26,7 +26,6 @@ import java.util.Map; import java.util.NavigableSet; import java.util.Set; -import java.util.Stack; import java.util.TreeSet; import org.dllearner.core.ReasoningService; Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -28,6 +28,7 @@ import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -83,6 +84,11 @@ public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + // annotations (not strictly reasoning methods) + // [OWL API supports only annotations specified in a given ontology, which + // is uncomfortable to handle when several ontologies are loaded] + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException; + // some convenience methods public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -31,6 +31,7 @@ import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -112,6 +113,11 @@ throw new ReasoningMethodUnsupportedException(); } + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -33,6 +33,7 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -475,6 +476,16 @@ } } + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + try { + return reasoner.getLabel(entity); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { reasoningStartTimeTmp = System.nanoTime(); Map<Individual, SortedSet<Individual>> result; Added: trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/Annotation.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,87 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +import java.net.URI; +import java.util.Map; + +/** + * An annotation, e.g. rdfs:label "foo". + * + * @author Jens Lehmann + * + */ +public class Annotation implements KBElement { + + protected URI annotationURI; + protected KBElement annotationValue; + + public Annotation(URI annotationURI, KBElement annotationValue) { + this.annotationURI = annotationURI; + this.annotationValue = annotationValue; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#accept(org.dllearner.core.owl.KBElementVisitor) + */ + @Override + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + @Override + public int getLength() { + return 1 + annotationValue.getLength(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toKBSyntaxString(java.lang.String, java.util.Map) + */ + @Override + public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { + return annotationURI + annotationValue.toKBSyntaxString(baseURI, prefixes); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + @Override + public String toString(String baseURI, Map<String, String> prefixes) { + return annotationURI + annotationValue.toString(baseURI, prefixes); + } + + /** + * @return the annotationURI + */ + public URI getAnnotationURI() { + return annotationURI; + } + + /** + * @return the annotationValue + */ + public KBElement getAnnotationValue() { + return annotationValue; + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/ConstantAnnotation.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +import java.net.URI; + +/** + * @author Jens Lehmann + * + */ +public class ConstantAnnotation extends Annotation { + + public ConstantAnnotation(URI annotationURI, Constant annotationValue) { + super(annotationURI, annotationValue); + } + + @Override + public Constant getAnnotationValue() { + return (Constant) annotationValue; + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/Entity.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Entity.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/Entity.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +/** + * Marker interface for classes, properties, individuals. + * + * @author Jens Lehmann + * + */ +public interface Entity extends NamedKBElement { + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/Individual.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Individual.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/Individual.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -29,7 +29,7 @@ * @author Jens Lehmann * */ -public class Individual implements NamedKBElement, Comparable<Individual> { +public class Individual implements Entity, NamedKBElement, Comparable<Individual> { private String name; Modified: trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -43,4 +43,6 @@ void visit(UntypedConstant untypedConstant); + void visit(Annotation annotation); + } Added: trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/LabelAnnotation.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.owl; + +import java.net.URI; + +/** + * @author Jens Lehmann + * + */ +public class LabelAnnotation extends ConstantAnnotation { + + public LabelAnnotation(URI annotationURI, Constant annotationValue) { + super(annotationURI, annotationValue); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -30,7 +30,7 @@ * @author Jens Lehmann * */ -public class NamedClass extends Description implements NamedKBElement, Comparable<NamedClass> { +public class NamedClass extends Description implements Entity, NamedKBElement, Comparable<NamedClass> { String name; Modified: trunk/src/dl-learner/org/dllearner/core/owl/Property.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Property.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/core/owl/Property.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -23,6 +23,6 @@ * @author Jens Lehmann * */ -public interface Property extends PropertyExpression, NamedKBElement { +public interface Property extends Entity, PropertyExpression, NamedKBElement { } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -1,16 +1,12 @@ package org.dllearner.kb.sparql; -import java.util.HashMap; import java.util.SortedSet; -import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.ADC; import org.dllearner.core.ComponentManager; -import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; import org.dllearner.core.owl.DatatypeMaxCardinalityRestriction; import org.dllearner.core.owl.DatatypeMinCardinalityRestriction; -import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.DatatypeValueRestriction; import org.dllearner.core.owl.Description; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -51,6 +51,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DoubleMaxValue; import org.dllearner.core.owl.DoubleMinValue; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -677,6 +678,11 @@ return rc.getRelatedValues(individual, datatypeProperty); } + @Override + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + return rc.getLabel(entity); + } + /* * (non-Javadoc) * Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -50,6 +50,7 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.KB; import org.dllearner.core.owl.NamedClass; @@ -68,6 +69,7 @@ import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.model.OWLAnnotation; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLConstant; import org.semanticweb.owl.model.OWLDataFactory; @@ -75,7 +77,9 @@ import org.semanticweb.owl.model.OWLDataRange; import org.semanticweb.owl.model.OWLDataType; import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLLabelAnnotation; import org.semanticweb.owl.model.OWLNamedObject; import org.semanticweb.owl.model.OWLObjectProperty; import org.semanticweb.owl.model.OWLOntology; @@ -733,25 +737,7 @@ } catch (OWLReasonerException e) { e.printStackTrace(); } - // convert data back to DL-Learner structures - SortedSet<Constant> is = new TreeSet<Constant>(); - for(OWLConstant oi : constants) { - // for typed constants we have to figure out the correct - // data type and value - if(oi instanceof OWLTypedConstant) { - Datatype dt = convertDatatype(((OWLTypedConstant)oi).getDataType()); - is.add(new TypedConstant(oi.getLiteral(),dt)); - // for untyped constants we have to figure out the value - // and language tag (if any) - } else { - OWLUntypedConstant ouc = (OWLUntypedConstant) oi; - if(ouc.hasLang()) - is.add(new UntypedConstant(ouc.getLiteral(), ouc.getLang())); - else - is.add(new UntypedConstant(ouc.getLiteral())); - } - } - return is; + return convertConstants(constants); } public Map<Individual, SortedSet<Double>> getDoubleValues(DatatypeProperty datatypeProperty) { @@ -907,6 +893,33 @@ } } + public static Set<Constant> convertConstants(Set<OWLConstant> constants) { + SortedSet<Constant> is = new TreeSet<Constant>(); + for(OWLConstant oi : constants) { + is.add(convertConstant(oi)); + } + return is; + } + + public static Constant convertConstant(OWLConstant constant) { + Constant c; + // for typed constants we have to figure out the correct + // data type and value + if(constant instanceof OWLTypedConstant) { + Datatype dt = convertDatatype(((OWLTypedConstant)constant).getDataType()); + c = new TypedConstant(constant.getLiteral(),dt); + // for untyped constants we have to figure out the value + // and language tag (if any) + } else { + OWLUntypedConstant ouc = (OWLUntypedConstant) constant; + if(ouc.hasLang()) + c = new UntypedConstant(ouc.getLiteral(), ouc.getLang()); + else + c = new UntypedConstant(ouc.getLiteral()); + } + return c; + } + public static Datatype convertDatatype(OWLDataType dataType) { URI uri = dataType.getURI(); if(uri.equals(Datatype.BOOLEAN.getURI())) @@ -927,6 +940,19 @@ return staticFactory.getOWLDataProperty(URI.create(datatypeProperty.getName())); } + private static OWLEntity getOWLAPIEntity(Entity entity) { + if(entity instanceof ObjectProperty) { + return staticFactory.getOWLObjectProperty(URI.create(entity.getName())); + } else if(entity instanceof DatatypeProperty) { + return staticFactory.getOWLDataProperty(URI.create(entity.getName())); + } else if(entity instanceof NamedClass) { + return staticFactory.getOWLClass(URI.create(entity.getName())); + } else if(entity instanceof OWLIndividual) { + return staticFactory.getOWLIndividual(URI.create(entity.getName())); + } + throw new Error("OWL API entity conversion for " + entity + " not supported."); + } + /** * Test * @@ -1037,5 +1063,18 @@ } - + @Override + @SuppressWarnings("all") + public Set<Constant> getLabel(Entity entity) { + OWLEntity owlEntity = getOWLAPIEntity(entity); + Set<OWLAnnotation> labelAnnotations = owlEntity.getAnnotations(owlAPIOntologies.get(0), URI.create("http://www.w3.org/2000/01/rdf-schema#label")); + Set<Constant> annotations = new HashSet<Constant>(); + for(OWLAnnotation label : labelAnnotations) { + OWLConstant c = ((OWLLabelAnnotation)label).getAnnotationValue(); + annotations.add(convertConstant(c)); + } + return annotations; + } + + } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java 2008-10-24 06:21:43 UTC (rev 1421) +++ trunk/src/dl-learner/org/dllearner/tools/ore/RepairDialog.java 2008-10-24 07:26:43 UTC (rev 1422) @@ -102,6 +102,7 @@ final Component dialogd = this.getParent(); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent we) { if(allChanges.size() > 0){ if (JOptionPane.showConfirmDialog(dialogd, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-10-24 08:57:05
|
Revision: 1424 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1424&view=rev Author: sknappe Date: 2008-10-24 08:52:43 +0000 (Fri, 24 Oct 2008) Log Message: ----------- changed naturaldescription to use reasoner instead of sparql tasks Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-24 08:45:12 UTC (rev 1423) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-24 08:52:43 UTC (rev 1424) @@ -1,9 +1,14 @@ package org.dllearner.kb.sparql; +import java.util.Iterator; +import java.util.Set; import java.util.SortedSet; import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.ADC; import org.dllearner.core.ComponentManager; +import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; import org.dllearner.core.owl.DatatypeMaxCardinalityRestriction; import org.dllearner.core.owl.DatatypeMinCardinalityRestriction; @@ -11,6 +16,7 @@ import org.dllearner.core.owl.DatatypeValueRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DescriptionVisitor; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -42,12 +48,12 @@ private String query=""; - private SPARQLTasks tasks; + private ReasoningService service; - public NaturalLanguageDescriptionConvertVisitor(String endpoint) + public NaturalLanguageDescriptionConvertVisitor(ReasoningService service) { //stack.push("subject"); - tasks=new SPARQLTasks(new Cache("cache"),SparqlEndpoint.getEndpointByName(endpoint)); + this.service=service; } private String getDescription() @@ -60,23 +66,42 @@ return query; } - public static String getNaturalLanguageDescription(Description description) + public static String getNaturalLanguageDescription(Description description, ReasoningService service) { - NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor("DBpedia"); + NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor(service); description.accept(visitor); String ret = visitor.getDescription(); return ret; } - public static String getNaturalLanguageDescription(String descriptionKBSyntax, String endpoint) throws ParseException + public static String getNaturalLanguageDescription(String descriptionKBSyntax, ReasoningService service) throws ParseException { Description d = KBParser.parseConcept(descriptionKBSyntax); - NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor(endpoint); + NaturalLanguageDescriptionConvertVisitor visitor=new NaturalLanguageDescriptionConvertVisitor(service); d.accept(visitor); String ret = visitor.getDescription(); return ret; } + private String getLabelFromReasoner(Entity ent) + { + String label; + try{ + Set<Constant> set=service.getLabel(ent); + if (set.size()>0){ + Iterator<Constant> iter=set.iterator(); + label=iter.next().getLiteral(); + } + else label=""; + } + catch (ReasoningMethodUnsupportedException e) + { + label=""; + } + + return label; + } + /** * Used for testing the Sparql Query converter. * @@ -110,7 +135,7 @@ //String conj="EXISTS \"http://xmlns.com/foaf/0.1/page\".<= 0 \"http://www.w3.org/2004/02/skos/core#subject\".TOP"; //String conj="(\"Male\" AND (\"hasDog\" = 18))"; ObjectValueRestriction rest=new ObjectValueRestriction(new ObjectProperty("hasAge"),new Individual("18")); - System.out.println(NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(rest)); + //System.out.println(NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(rest)); } catch (/*Parse*/Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -131,8 +156,8 @@ */ public void visit(ObjectAllRestriction description) { logger.trace("ObjectAllRestriction"); - SortedSet<String> label=tasks.queryAsSet("SELECT ?label WHERE {<"+description.getRole().toString()+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label}", "label"); - if (label.size()>0) query+="all "+label.first()+" are "; + String label=getLabelFromReasoner((ObjectProperty)description.getRole()); + if (label.length()>0) query+="all "+label+" are "; else query+="all "+description.getRole().toString().substring(description.getRole().toString().lastIndexOf("/")+1)+" are "; description.getChild(0).accept(this); logger.trace(description.getRole().toString()); @@ -144,8 +169,8 @@ */ public void visit(ObjectSomeRestriction description) { logger.trace("ObjectSomeRestriction"); - SortedSet<String> label=tasks.queryAsSet("SELECT ?label WHERE {<"+description.getRole().toString()+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label}", "label"); - if (label.size()>0) query+="has "+label.first()+" which is "; + String label=getLabelFromReasoner((ObjectProperty)description.getRole()); + if (label.length()>0) query+="has "+label+" which is "; else query+="has "+description.getRole().toString().substring(description.getRole().toString().lastIndexOf("/")+1)+" which is "; description.getChild(0).accept(this); logger.trace(description.getRole().toString()); @@ -234,16 +259,16 @@ public void visit(ObjectValueRestriction description) { ObjectProperty op = (ObjectProperty) description.getRestrictedPropertyExpression(); Individual ind = description.getIndividual(); - SortedSet<String> label = tasks.queryAsSet("SELECT ?label WHERE {<"+ind.getName()+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label}", "label"); + String label=getLabelFromReasoner(ind); String indLabel; - if (label.size()>0) - indLabel =label.first(); + if (label.length()>0) + indLabel =label; else indLabel =ind.getName(); - label = tasks.queryAsSet("SELECT ?label WHERE {<"+op.getName()+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label}", "label"); + label=getLabelFromReasoner(op); String propLabel; - if (label.size()>0) - propLabel =label.first(); + if (label.length()>0) + propLabel =label; else propLabel =op.getName(); query += propLabel + " is " + indLabel; @@ -270,10 +295,10 @@ if (query.endsWith("and ")) query=query.substring(0, query.length()-5); if (query.endsWith("or ")) query=query.substring(0, query.length()-4); } - SortedSet<String> label=tasks.queryAsSet("SELECT ?label WHERE {<"+description.getName()+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label}", "label"); - String l=label.first(); + //SortedSet<String> label=tasks.queryAsSet("SELECT ?label WHERE {<"+description.getName()+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label}", "label"); + String l=getLabelFromReasoner(description); String l2=description.getName().substring(description.getName().lastIndexOf("/")+1, description.getName().length()).replace('_', ' '); - if (l.length()+5<l2.length()&&!l2.matches(".*[0-9]")) l=l2; + if ((l.length()==0)||(l.length()+5<l2.length()&&!l2.matches(".*[0-9]"))) l=l2; //replacements l=l.replaceAll("Cities", "City"); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-10-24 08:45:12 UTC (rev 1423) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-10-24 08:52:43 UTC (rev 1424) @@ -332,6 +332,7 @@ sqm.addPredicateFilter("http://www.w3.org/2000/01/rdf-schema#subClassOf"); sqm.addPredicateFilter("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); sqm.addPredicateFilter("http://www.w3.org/2003/01/geo/wgs84_pos#long"); + sqm.addPredicateFilter("http://www.w3.org/2000/01/rdf-schema#label"); // pred.add("http://dbpedia.org/property/wikipage"); // pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); // pred.add("http://dbpedia.org/property/relatedInstance"); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-24 08:45:12 UTC (rev 1423) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-24 08:52:43 UTC (rev 1424) @@ -54,6 +54,7 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -720,9 +721,11 @@ } @WebMethod - public String getNaturalDescription(String conceptString, String endpoint) throws ParseException { + public String getNaturalDescription(int id, String conceptString, String endpoint) throws ParseException, ClientNotKnownException { // call parser to parse concept - return NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(conceptString, endpoint); + ClientState state = getState(id); + ReasoningService service = state.getReasoningService(); + return NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(conceptString, service); } @WebMethod This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-10-28 08:55:23
|
Revision: 1464 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1464&view=rev Author: sknappe Date: 2008-10-28 08:54:18 +0000 (Tue, 28 Oct 2008) Log Message: ----------- changes to use new ontology Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/TestGetExampleBug.java trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-10-28 08:53:58 UTC (rev 1463) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-10-28 08:54:18 UTC (rev 1464) @@ -149,7 +149,7 @@ // NEGATIVES AutomaticNegativeExampleFinderSPARQL aneg = new AutomaticNegativeExampleFinderSPARQL( - fullPositiveSet, sparqlTasks); + fullPositiveSet, sparqlTasks, new TreeSet<String>()); aneg.makeNegativeExamplesFromParallelClasses(posExamples, sparqlResultLimitNegativeExamples); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-28 08:53:58 UTC (rev 1463) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-28 08:54:18 UTC (rev 1464) @@ -729,29 +729,34 @@ } @WebMethod - public String[] getNegativeExamples(int sessionID, int componentID,String[] positives, int results, String namespace) throws ClientNotKnownException + public String[] getNegativeExamples(int sessionID, int componentID,String[] positives, int results, String namespace, String[] filterClasses) throws ClientNotKnownException { int sparqlResultSetLimit = 500; SortedSet<String> positiveSet = new TreeSet<String>(Arrays.asList(positives)); + SortedSet<String> filterSet = new TreeSet<String>(Arrays.asList(filterClasses)); ClientState state = getState(sessionID); Component component = state.getComponent(componentID); SparqlKnowledgeSource ks=(SparqlKnowledgeSource)component; SPARQLTasks task=ks.getSPARQLTasks(); - AutomaticNegativeExampleFinderSPARQL finder=new AutomaticNegativeExampleFinderSPARQL(positiveSet,task); + AutomaticNegativeExampleFinderSPARQL finder=new AutomaticNegativeExampleFinderSPARQL(positiveSet,task,filterSet); - finder.makeNegativeExamplesFromParallelClasses(positiveSet, sparqlResultSetLimit); + finder.makeNegativeExamplesFromNearbyClasses(positiveSet, sparqlResultSetLimit); SortedSet<String> negExamples=finder.getNegativeExamples(results); - if(negExamples.isEmpty()){ - finder.makeNegativeExamplesFromRelatedInstances(positiveSet, namespace); - negExamples = finder.getNegativeExamples(results); - if(negExamples.isEmpty()){ - finder.makeNegativeExamplesFromSuperClassesOfInstances(positiveSet, sparqlResultSetLimit); + if (negExamples.isEmpty()){ + finder.makeNegativeExamplesFromParallelClasses(positiveSet, sparqlResultSetLimit); + negExamples=finder.getNegativeExamples(results); + if(negExamples.isEmpty()){ + finder.makeNegativeExamplesFromRelatedInstances(positiveSet, namespace); negExamples = finder.getNegativeExamples(results); - if(negExamples.isEmpty()) { - finder.makeNegativeExamplesFromRandomInstances(); + if(negExamples.isEmpty()){ + finder.makeNegativeExamplesFromSuperClassesOfInstances(positiveSet, sparqlResultSetLimit); negExamples = finder.getNegativeExamples(results); + if(negExamples.isEmpty()) { + finder.makeNegativeExamplesFromRandomInstances(); + negExamples = finder.getNegativeExamples(results); + } } - } + } } return negExamples.toArray(new String[negExamples.size()]); Modified: trunk/src/dl-learner/org/dllearner/test/TestGetExampleBug.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/TestGetExampleBug.java 2008-10-28 08:53:58 UTC (rev 1463) +++ trunk/src/dl-learner/org/dllearner/test/TestGetExampleBug.java 2008-10-28 08:54:18 UTC (rev 1464) @@ -40,7 +40,7 @@ SPARQLTasks st = new SPARQLTasks(new SparqlEndpoint(new URL(OntowikiUrl))); AutomaticNegativeExampleFinderSPARQL ane = - new AutomaticNegativeExampleFinderSPARQL(positiveSet,st); + new AutomaticNegativeExampleFinderSPARQL(positiveSet,st, new TreeSet<String>()); SortedSet<String> negExamples = new TreeSet<String>(); int results=100; if(negExamples.isEmpty()){ Modified: trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java 2008-10-28 08:53:58 UTC (rev 1463) +++ trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java 2008-10-28 08:54:18 UTC (rev 1464) @@ -20,6 +20,7 @@ package org.dllearner.tools.ore; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningAlgorithm; @@ -49,7 +50,7 @@ pos.makePositiveExamplesFromConcept("angela_merkel"); SortedSet<String> posExamples = pos.getPosExamples(); - AutomaticNegativeExampleFinderSPARQL neg = new AutomaticNegativeExampleFinderSPARQL(posExamples, task); + AutomaticNegativeExampleFinderSPARQL neg = new AutomaticNegativeExampleFinderSPARQL(posExamples, task, new TreeSet<String>()); SortedSet<String> negExamples = neg.getNegativeExamples(20); LearnSPARQLConfiguration conf = new LearnSPARQLConfiguration(); Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-10-28 08:53:58 UTC (rev 1463) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-10-28 08:54:18 UTC (rev 1464) @@ -36,10 +36,12 @@ private SPARQLTasks sparqltasks; + private SortedSet<String> filterClasses; private SortedSet<String> fullPositiveSet; private SortedSet<String> fromRelated = new TreeSet<String>(); + private SortedSet<String> fromNearbyClasses = new TreeSet<String>(); private SortedSet<String> fromSuperclasses = new TreeSet<String>();; private SortedSet<String> fromParallelClasses = new TreeSet<String>();; private SortedSet<String> fromRandom = new TreeSet<String>();; @@ -58,12 +60,12 @@ */ public AutomaticNegativeExampleFinderSPARQL( SortedSet<String> fullPositiveSet, - SPARQLTasks st) { + SPARQLTasks st, SortedSet<String> filterClasses) { super(); this.fullPositiveSet = new TreeSet<String>(); this.fullPositiveSet.addAll(fullPositiveSet); this.sparqltasks = st; - + this.filterClasses=filterClasses; } @@ -86,6 +88,7 @@ */ public SortedSet<String> getNegativeExamples(int neglimit, boolean stable ) { SortedSet<String> negatives = new TreeSet<String>(); + negatives.addAll(fromNearbyClasses); negatives.addAll(fromParallelClasses); negatives.addAll(fromRelated); negatives.addAll(fromSuperclasses); @@ -158,7 +161,44 @@ this.fromRelated.addAll(sparqltasks.queryAsSet(SPARQLquery, "o")); }*/ - + + public void makeNegativeExamplesFromNearbyClasses(SortedSet<String> positiveSet, int sparqlResultLimit){ + SortedSet<String> classes = new TreeSet<String>(); + Iterator<String> instanceIter = positiveSet.iterator(); + while(classes.isEmpty() && instanceIter.hasNext()) { + classes.addAll(sparqltasks.getClassesForInstance(instanceIter.next(), 100)); + } + String concept=classes.first(); + if (filterClasses!=null&&filterClasses.size()>0){ + boolean br=false; + for (String oneClass : classes){ + Iterator<String> iter=filterClasses.iterator(); + while (iter.hasNext()){ + if (!oneClass.startsWith(iter.next())){ + concept=oneClass; + br=true; + break; + } + } + if (br) break; + } + } + concept = concept.replaceAll("\"", ""); + SortedSet<String> superClasses = sparqltasks.getSuperClasses(concept, 1); + + classes = new TreeSet<String>(); + for (String oneSuperClass : superClasses) { + classes.addAll(sparqltasks.getSubClasses(oneSuperClass, 1)); + } + classes.remove(concept); + for (String oneClass : classes) { + fromNearbyClasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + + oneClass + "\"", sparqlResultLimit)); + } + + this.fromNearbyClasses.removeAll(fullPositiveSet); + } + /** * makes negEx from classes, the posEx belong to. * Gets all Classes from PosEx, gets Instances from these Classes, returns all This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-10-28 12:03:19
|
Revision: 1472 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1472&view=rev Author: JensLehmann Date: 2008-10-28 10:19:29 +0000 (Tue, 28 Oct 2008) Log Message: ----------- added web service method to query a predefined endpoint Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-28 10:15:47 UTC (rev 1471) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-10-28 10:19:29 UTC (rev 1472) @@ -1,7 +1,6 @@ package org.dllearner.kb.sparql; import java.util.Iterator; import java.util.Set; -import java.util.SortedSet; import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.ADC; @@ -134,7 +133,7 @@ System.out.println("Finished");*/ //String conj="EXISTS \"http://xmlns.com/foaf/0.1/page\".<= 0 \"http://www.w3.org/2004/02/skos/core#subject\".TOP"; //String conj="(\"Male\" AND (\"hasDog\" = 18))"; - ObjectValueRestriction rest=new ObjectValueRestriction(new ObjectProperty("hasAge"),new Individual("18")); +// ObjectValueRestriction rest=new ObjectValueRestriction(new ObjectProperty("hasAge"),new Individual("18")); //System.out.println(NaturalLanguageDescriptionConvertVisitor.getNaturalLanguageDescription(rest)); } catch (/*Parse*/Exception e) { // TODO Auto-generated catch block Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2008-10-28 10:15:47 UTC (rev 1471) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2008-10-28 10:19:29 UTC (rev 1472) @@ -83,6 +83,8 @@ return getEndpointDBpedia(); } else if (name.equals("LOCALDBPEDIA")) { return getEndpointLOCALDBpedia(); + } else if (name.equals("LOCALGEONAMES")) { + return getEndpointLOCALGeonames(); } else if (name.equals("LOCALJOSECKI") || name.equals("LOCALJOSEKI") ) { return getEndpointlocalJoseki(); } else if (name.equals("LOCALJOSEKIBIBLE")||name.equals("LOCALJOSECKIBIBLE")) { @@ -157,6 +159,18 @@ return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); } + public static SparqlEndpoint getEndpointLOCALGeonames() { + URL u = null; + try { + u = new URL("http://139.18.2.37:8890/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + LinkedList<String> defaultGraphURIs=new LinkedList<String>(); + defaultGraphURIs.add("http://geonames.org"); + return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); + } + public static SparqlEndpoint getEndpointlocalJoseki() { URL u = null; try { Modified: trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java 2008-10-28 10:15:47 UTC (rev 1471) +++ trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java 2008-10-28 10:19:29 UTC (rev 1472) @@ -44,6 +44,7 @@ * @author Jens Lehmann * */ +@SuppressWarnings("unused") public class CalculatePageRank { private static String datasetDir; Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-28 10:15:47 UTC (rev 1471) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-28 10:19:29 UTC (rev 1472) @@ -64,6 +64,7 @@ import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.NaturalLanguageDescriptionConvertVisitor; import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.kb.sparql.SparqlQueryException; @@ -672,6 +673,19 @@ else return sparql.getJson();*/ } + /** + * Queries one of the standard endpoints defined in DL-Learner. + * @param predefinedEndpoint A string describing the endpoint e.g. DBpedia. + * @param query The SPARQL query. + * @return The result of the SPARQL query in JSON format or null if the endpoint does not exist. + * @see SPARQLEndpoint#getEndpointByName; + */ + public String sparqlQueryPredefinedEndpoint(String predefinedEndpoint, String query) { + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointByName(predefinedEndpoint); + SPARQLTasks st = new SPARQLTasks(endpoint); + return st.query(query); + } + @WebMethod public boolean isSparqlQueryRunning(int sessionID, int queryID) throws ClientNotKnownException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-10-28 14:16:56
|
Revision: 1484 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1484&view=rev Author: sknappe Date: 2008-10-28 14:16:49 +0000 (Tue, 28 Oct 2008) Log Message: ----------- change to yago Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorFilterRule.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorFilterRule.java 2008-10-28 13:23:50 UTC (rev 1483) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorFilterRule.java 2008-10-28 14:16:49 UTC (rev 1484) @@ -48,12 +48,12 @@ typeTuple = tuple; } - /*if (tuple.a.toString().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && !(tuple.b.toString().startsWith("http://dbpedia.org/class/yago"))){ + if (tuple.a.toString().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && !(tuple.b.toString().startsWith("http://dbpedia.org/class/yago"))){ toRemove.add(typeTuple); + } + /*if (tuple.a.toString().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && !(tuple.b.toString().startsWith("http://dbpedia.org/ontology"))){ + toRemove.add(typeTuple); }*/ - if (tuple.a.toString().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") && !(tuple.b.toString().startsWith("http://dbpedia.org/ontology"))){ - toRemove.add(typeTuple); - } }//end for for (RDFNodeTuple tuple : toRemove) tuples.remove(tuple); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-28 13:23:50 UTC (rev 1483) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-10-28 14:16:49 UTC (rev 1484) @@ -761,11 +761,11 @@ SPARQLTasks task=ks.getSPARQLTasks(); AutomaticNegativeExampleFinderSPARQL finder=new AutomaticNegativeExampleFinderSPARQL(positiveSet,task,filterSet); - finder.makeNegativeExamplesFromNearbyClasses(positiveSet, sparqlResultSetLimit); + /*finder.makeNegativeExamplesFromNearbyClasses(positiveSet, sparqlResultSetLimit); SortedSet<String> negExamples=finder.getNegativeExamples(results); - if (negExamples.isEmpty()){ + if (negExamples.isEmpty()){*/ finder.makeNegativeExamplesFromParallelClasses(positiveSet, sparqlResultSetLimit); - negExamples=finder.getNegativeExamples(results); + SortedSet<String> negExamples=finder.getNegativeExamples(results); if(negExamples.isEmpty()){ finder.makeNegativeExamplesFromRelatedInstances(positiveSet, namespace); negExamples = finder.getNegativeExamples(results); @@ -778,7 +778,7 @@ } } } - } + //} return negExamples.toArray(new String[negExamples.size()]); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-04 17:03:02
|
Revision: 1491 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1491&view=rev Author: jenslehmann Date: 2008-11-04 17:02:56 +0000 (Tue, 04 Nov 2008) Log Message: ----------- - three EL description tree simulation tests - started alternative tree clone method Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-04 16:27:07 UTC (rev 1490) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-04 17:02:56 UTC (rev 1491) @@ -20,6 +20,7 @@ package org.dllearner.algorithms.el; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -57,17 +58,17 @@ public class ELDescriptionNode { // the reference tree for storing values, must not be null - private ELDescriptionTree tree; + protected ELDescriptionTree tree; - private NavigableSet<NamedClass> label; + protected TreeSet<NamedClass> label; - private List<ELDescriptionEdge> edges; + protected List<ELDescriptionEdge> edges; - private int level; + protected int level; // parent node in the tree; // null indicates that this node is a root node - private ELDescriptionNode parent = null; + protected ELDescriptionNode parent = null; // simulation information (list or set?) protected Set<ELDescriptionNode> in = new HashSet<ELDescriptionNode>(); @@ -78,6 +79,13 @@ protected Set<ELDescriptionNode> outSC2 = new HashSet<ELDescriptionNode>(); /** + * Internal constructor used for cloning nodes. + */ + protected ELDescriptionNode() { + + } + + /** * Constructs an EL description tree with empty root label. */ public ELDescriptionNode(ELDescriptionTree tree) { @@ -88,7 +96,7 @@ * Constructs an EL description tree given its root label. * @param label Label of the root node. */ - public ELDescriptionNode(ELDescriptionTree tree, NavigableSet<NamedClass> label) { + public ELDescriptionNode(ELDescriptionTree tree, TreeSet<NamedClass> label) { this.label = label; this.edges = new LinkedList<ELDescriptionEdge>(); this.tree = tree; @@ -97,11 +105,14 @@ // this is the root node of the overall tree tree.rootNode = this; tree.addNodeToLevel(this, level); - - // TODO simulation initialization } - public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, NavigableSet<NamedClass> label) { + // convenience constructor + public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, NamedClass... label) { + this(parentNode, parentProperty, new TreeSet<NamedClass>(Arrays.asList(label))); + } + + public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, TreeSet<NamedClass> label) { this.label = label; this.edges = new LinkedList<ELDescriptionEdge>(); parent = parentNode; @@ -394,4 +405,46 @@ public ELDescriptionNode getParent() { return parent; } + + /** + * @return the in + */ + public Set<ELDescriptionNode> getIn() { + return in; + } + + /** + * @return the inSC1 + */ + public Set<ELDescriptionNode> getInSC1() { + return inSC1; + } + + /** + * @return the inSC2 + */ + public Set<ELDescriptionNode> getInSC2() { + return inSC2; + } + + /** + * @return the out + */ + public Set<ELDescriptionNode> getOut() { + return out; + } + + /** + * @return the outSC1 + */ + public Set<ELDescriptionNode> getOutSC1() { + return outSC1; + } + + /** + * @return the outSC2 + */ + public Set<ELDescriptionNode> getOutSC2() { + return outSC2; + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-04 16:27:07 UTC (rev 1490) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-04 17:02:56 UTC (rev 1491) @@ -26,7 +26,9 @@ import java.util.Map; import java.util.NavigableSet; import java.util.Set; +import java.util.TreeMap; import java.util.TreeSet; +import java.util.Map.Entry; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; @@ -336,6 +338,62 @@ node2.inSC2.remove(node1); } + @SuppressWarnings("unchecked") + public ELDescriptionTree cloneNew() { + // clone "global" tree + ELDescriptionTree treeClone = new ELDescriptionTree(rs); + + // a mapping between "old" and "new" nodes + // (hash map should be fast here, but one could also + // experiment with TreeMap) + Map<ELDescriptionNode, ELDescriptionNode> cloneMap = + new HashMap<ELDescriptionNode, ELDescriptionNode>(); + + // create a new (empty) node for each node in the tree + // (we loop through the level mapping, because it is cheaper + // than creating a set of all nodes) + for(int i=1; i<=maxLevel; i++) { + Set<ELDescriptionNode> tmp = levelNodeMapping.get(i); + for(ELDescriptionNode node : tmp) { + ELDescriptionNode nodeNew = new ELDescriptionNode(); + cloneMap.put(node, nodeNew); + } + } + + ELDescriptionNode newRoot = null; + + // loop through all nodes and perform copy operations + for(Entry<ELDescriptionNode, ELDescriptionNode> entry : cloneMap.entrySet()) { + ELDescriptionNode oldNode = entry.getKey(); + ELDescriptionNode newNode = entry.getValue(); + + newNode.tree = treeClone; + newNode.level = oldNode.level; + newNode.label = (TreeSet<NamedClass>) oldNode.label.clone(); + if(oldNode.parent != null) { + newNode.parent = cloneMap.get(oldNode.parent); + } else { + newRoot = newNode; + } + + // TODO: edges, simulation information ... + } + + // update global tree + treeClone.rootNode = newRoot; + treeClone.maxLevel = maxLevel; + for(int i=1; i<=maxLevel; i++) { + Set<ELDescriptionNode> oldNodes = levelNodeMapping.get(i); + Set<ELDescriptionNode> newNodes = new HashSet<ELDescriptionNode>(); + for(ELDescriptionNode oldNode : oldNodes) { + newNodes.add(cloneMap.get(oldNode)); + } + treeClone.levelNodeMapping.put(i, newNodes); + } + + return treeClone; + } + @Override public ELDescriptionTree clone() { // create a new reference tree Added: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-04 17:02:56 UTC (rev 1491) @@ -0,0 +1,213 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.test.junit; + +import static org.junit.Assert.*; + +import java.util.TreeSet; + +import org.dllearner.algorithms.el.ELDescriptionNode; +import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.test.junit.TestOntologies.TestOntology; +import org.junit.Test; + +/** + * We test whether level-restricted, non-reflexive simulations on + * EL description trees are correctly computed. + * + * @author Jens Lehmann + * + */ +public class SimulationTests { + + @Test + public void test1() { + // perform test with empty background knowledge and TOP concept + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.EMPTY); + ELDescriptionTree tree = new ELDescriptionTree(rs); + ELDescriptionNode root = new ELDescriptionNode(tree); + + // simulation relation should be empty + assertEmpty(root); + } + + /** + * v1:{A1} + * / \ + * r1 r2 + * / \ + * v2:{} v3:{} + * + * v1: - + * v2: in=inSC1=inSC2=out=outSC1=outSC2={v3} + * v3: in=inSC1=inSC2=out=outSC1=outSC2={v2} + */ + @Test + public void test2() { + // perform test with empty background knowledge and A1 AND EXISTS r1.TOP AND EXISTS r2.TOP + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.EMPTY); + ELDescriptionTree tree = new ELDescriptionTree(rs); + ELDescriptionNode v1 = new ELDescriptionNode(tree); + ObjectProperty r1 = new ObjectProperty("r1"); + ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, new TreeSet<NamedClass>()); + ObjectProperty r2 = new ObjectProperty("r2"); + ELDescriptionNode v3 = new ELDescriptionNode(v1, r2, new TreeSet<NamedClass>()); + + assertEmpty(v1); + assertAll(v2, v3); + assertAll(v3, v2); + } + + /** + * K: r1 \sqsubset r2 + * + * v1:{} + * / | \ + * r1 r1 r2 + * / | \ + * v2:{A1,A2} v3:{A2} v4:{A1} + * + * v1: - + * v2: in=inSC1=inSC2=outSC2={v3,v4} + * v3: inSC2=outSC2={v2,v4} + * v4: inSC2=outSC2={v2,v3} + */ + @Test + public void test3() { + ReasoningService rs = TestOntologies.getTestOntology(TestOntology.R1SUBR2); + ELDescriptionTree tree = new ELDescriptionTree(rs); + ELDescriptionNode v1 = new ELDescriptionNode(tree); + ObjectProperty r1 = new ObjectProperty("r1"); + NamedClass a1 = new NamedClass("a1"); + NamedClass a2 = new NamedClass("a2"); + ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a1, a2); + ELDescriptionNode v3 = new ELDescriptionNode(v1, r1, a2); + ObjectProperty r2 = new ObjectProperty("r2"); + ELDescriptionNode v4 = new ELDescriptionNode(v1, r2, a1); + + assertEmpty(v1); + + assertAllIn(v2, v3, v4); + assertOutSC2(v2, v3, v4); + assertOutSC1(v2); + assertOut(v2); + + assertSC2(v3, v2, v4); + assertSC1(v3); + assertSC(v3); + + assertSC2(v4, v2, v3); + assertSC1(v4); + assertSC(v4); + } + + // all relations (in, inSC1, inSC2) should have the + // the specified node set as value + private void assertAll(ELDescriptionNode node, ELDescriptionNode... nodes) { + assertAllIn(node, nodes); + assertAllOut(node, nodes); + } + + // all in relations (in, inSC1, inSC2) should have the + // specified node set as value + private void assertAllIn(ELDescriptionNode node, ELDescriptionNode... nodesIn) { + assertIn(node, nodesIn); + assertInSC1(node, nodesIn); + assertInSC2(node, nodesIn); + } + + // all out relations (out, outSC1, outSC2) should have the + // specified node set as value + private void assertAllOut(ELDescriptionNode node, ELDescriptionNode... nodesOut) { + assertOut(node, nodesOut); + assertOutSC1(node, nodesOut); + assertOutSC2(node, nodesOut); + } + + private void assertSC(ELDescriptionNode node, ELDescriptionNode... nodesOut) { + assertIn(node, nodesOut); + assertOut(node, nodesOut); + } + + private void assertSC1(ELDescriptionNode node, ELDescriptionNode... nodesOut) { + assertInSC1(node, nodesOut); + assertOutSC1(node, nodesOut); + } + + private void assertSC2(ELDescriptionNode node, ELDescriptionNode... nodesOut) { + assertInSC2(node, nodesOut); + assertOutSC2(node, nodesOut); + } + + private void assertInSC1(ELDescriptionNode node, ELDescriptionNode... nodes) { + for(ELDescriptionNode nodeTmp : nodes) { + assertTrue(node.getInSC1().contains(nodeTmp)); + } + assertTrue(node.getInSC1().size() == nodes.length); + } + + private void assertInSC2(ELDescriptionNode node, ELDescriptionNode... nodes) { + for(ELDescriptionNode nodeTmp : nodes) { + assertTrue(node.getInSC2().contains(nodeTmp)); + } + assertTrue(node.getInSC2().size() == nodes.length); + } + + private void assertIn(ELDescriptionNode node, ELDescriptionNode... nodes) { + for(ELDescriptionNode nodeTmp : nodes) { + assertTrue(node.getIn().contains(nodeTmp)); + } + assertTrue(node.getIn().size() == nodes.length); + } + + private void assertOutSC2(ELDescriptionNode node, ELDescriptionNode... nodes) { + for(ELDescriptionNode nodeTmp : nodes) { + assertTrue(node.getOutSC2().contains(nodeTmp)); + } + assertTrue(node.getOutSC2().size() == nodes.length); + } + + private void assertOutSC1(ELDescriptionNode node, ELDescriptionNode... nodes) { + for(ELDescriptionNode nodeTmp : nodes) { + assertTrue(node.getOutSC1().contains(nodeTmp)); + } + assertTrue(node.getOutSC1().size() == nodes.length); + } + + private void assertOut(ELDescriptionNode node, ELDescriptionNode... nodes) { + for(ELDescriptionNode nodeTmp : nodes) { + assertTrue(node.getOut().contains(nodeTmp)); + } + assertTrue(node.getOut().size() == nodes.length); + } + + // all simulation relations should be empty for this node + private void assertEmpty(ELDescriptionNode node) { + assertTrue(node.getIn().isEmpty()); + assertTrue(node.getInSC1().isEmpty()); + assertTrue(node.getInSC2().isEmpty()); + assertTrue(node.getOut().isEmpty()); + assertTrue(node.getOutSC1().isEmpty()); + assertTrue(node.getOutSC2().isEmpty()); + } +} Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-04 16:27:07 UTC (rev 1490) +++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-04 17:02:56 UTC (rev 1491) @@ -37,7 +37,7 @@ */ public final class TestOntologies { - public enum TestOntology { EMPTY, SIMPLE }; + public enum TestOntology { EMPTY, SIMPLE, R1SUBR2 }; public static ReasoningService getTestOntology(TestOntology ont) { String kbString = ""; @@ -55,6 +55,8 @@ kbString += "bird SUB animal.\n"; kbString += "cat SUB animal.\n"; kbString += "(human AND animal) = BOTTOM.\n"; + } else if(ont.equals(TestOntology.R1SUBR2)) { + kbString += "Subrole(r1,r2).\n"; } try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-06 12:15:06
|
Revision: 1493 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1493&view=rev Author: jenslehmann Date: 2008-11-06 12:02:22 +0000 (Thu, 06 Nov 2008) Log Message: ----------- - completed new clone operation on EL description trees - added performance test for cloning trees Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-05 12:51:43 UTC (rev 1492) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-06 12:02:22 UTC (rev 1493) @@ -62,7 +62,7 @@ protected TreeSet<NamedClass> label; - protected List<ELDescriptionEdge> edges; + protected List<ELDescriptionEdge> edges = new LinkedList<ELDescriptionEdge>(); protected int level; Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-05 12:51:43 UTC (rev 1492) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-06 12:02:22 UTC (rev 1493) @@ -26,7 +26,6 @@ import java.util.Map; import java.util.NavigableSet; import java.util.Set; -import java.util.TreeMap; import java.util.TreeSet; import java.util.Map.Entry; @@ -338,8 +337,9 @@ node2.inSC2.remove(node1); } + @Override @SuppressWarnings("unchecked") - public ELDescriptionTree cloneNew() { + public ELDescriptionTree clone() { // clone "global" tree ELDescriptionTree treeClone = new ELDescriptionTree(rs); @@ -376,7 +376,32 @@ newRoot = newNode; } - // TODO: edges, simulation information ... + // simulation information + for(ELDescriptionNode node : oldNode.in) { + newNode.in.add(cloneMap.get(node)); + } + for(ELDescriptionNode node : oldNode.inSC1) { + newNode.inSC1.add(cloneMap.get(node)); + } + for(ELDescriptionNode node : oldNode.inSC2) { + newNode.inSC2.add(cloneMap.get(node)); + } + for(ELDescriptionNode node : oldNode.out) { + newNode.out.add(cloneMap.get(node)); + } + for(ELDescriptionNode node : oldNode.outSC1) { + newNode.outSC1.add(cloneMap.get(node)); + } + for(ELDescriptionNode node : oldNode.outSC2) { + newNode.outSC2.add(cloneMap.get(node)); + } + + // edges + for(ELDescriptionEdge edge : oldNode.edges) { + // create a new edge with same label and replace the node the edge points to + newNode.edges.add(new ELDescriptionEdge(edge.getLabel(), cloneMap.get(edge.getTree()))); + } + } // update global tree @@ -394,8 +419,7 @@ return treeClone; } - @Override - public ELDescriptionTree clone() { + public ELDescriptionTree cloneOld() { // create a new reference tree ELDescriptionTree treeClone = new ELDescriptionTree(rs); // create a root node attached to this reference tree Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-11-05 12:51:43 UTC (rev 1492) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-11-06 12:02:22 UTC (rev 1493) @@ -36,6 +36,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.test.junit.TestOntologies.TestOntology; +import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptTransformation; import org.junit.Test; @@ -83,7 +84,21 @@ Description d = KBParser.parseConcept("(male AND (human AND EXISTS hasChild.(female AND EXISTS hasChild.male)))"); ConceptTransformation.cleanConcept(d); ELDescriptionTree tree = new ELDescriptionTree(rs, d); - ELDescriptionTree treeCloned = tree.clone(); + // clone performance (false for simple unit test, true for clone performance test) + boolean testPerformance = false; + ELDescriptionTree treeCloned = null; + if(testPerformance) { + int runs = 1000000; + long startTime = System.nanoTime(); + for(int i=0; i<runs; i++) { + treeCloned = tree.clone(); + } + long runTime = System.nanoTime() - startTime; + System.out.println(Helper.prettyPrintNanoSeconds(runTime/runs, true, true) + " per clone operation"); + } else { + treeCloned = tree.clone(); + } + ELDescriptionTreeComparator comparator = new ELDescriptionTreeComparator(); assertTrue(comparator.compare(tree, treeCloned) == 0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-10 11:00:35
|
Revision: 1500 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1500&view=rev Author: jenslehmann Date: 2008-11-10 11:00:23 +0000 (Mon, 10 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN is now *broken*, please don't update if you want everything to work properly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/LearningProblem.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java trunk/src/dl-learner/org/dllearner/gui/InitWorker.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.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/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/scripts/PaperStatistics.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparqlold.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/ReasonerNew.java Modified: trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -35,7 +35,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasonerComponentOld; +import org.dllearner.core.ReasonerComponent; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.learningproblems.PosNegDefinitionLP; @@ -58,7 +58,7 @@ // mappings between component classes and their names in conf files private static Map<String,Class<? extends KnowledgeSource>> knowledgeSourceMapping = new TreeMap<String,Class<? extends KnowledgeSource>>(); - private static Map<String,Class<? extends ReasonerComponentOld>> reasonerMapping = new TreeMap<String,Class<? extends ReasonerComponentOld>>(); + private static Map<String,Class<? extends ReasonerComponent>> reasonerMapping = new TreeMap<String,Class<? extends ReasonerComponent>>(); private static Map<String,Class<? extends LearningProblem>> learningProblemMapping = new TreeMap<String,Class<? extends LearningProblem>>(); private static Map<String,Class<? extends LearningAlgorithm>> learningAlgorithmMapping = new TreeMap<String,Class<? extends LearningAlgorithm>>(); private static TreeMap<String,Class<? extends Component>> componentMapping = new TreeMap<String,Class<? extends Component>>(); @@ -108,7 +108,7 @@ private static void buildKeys() { // edit this part manually componentTypeMapping.put("import", KnowledgeSource.class); - componentTypeMapping.put("reasoner", ReasonerComponentOld.class); + componentTypeMapping.put("reasoner", ReasonerComponent.class); componentTypeMapping.put("problem", LearningProblem.class); componentTypeMapping.put("algorithm", LearningAlgorithm.class); @@ -123,7 +123,7 @@ return knowledgeSourceMapping.get(confString); } - public Class<? extends ReasonerComponentOld> getReasonerComponentClass(String confString) { + public Class<? extends ReasonerComponent> getReasonerComponentClass(String confString) { return reasonerMapping.get(confString); } Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -56,7 +56,7 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.OntologyFormat; -import org.dllearner.core.ReasonerComponentOld; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; @@ -113,7 +113,7 @@ private LearningAlgorithm la; private LearningProblem lp; private ReasoningService rs; - private ReasonerComponentOld rc; + private ReasonerComponent rc; /** * Entry point for CLI interface. @@ -245,7 +245,7 @@ // step 2: detect used reasoner Monitor rsMonitor = JamonMonitorLogger.getTimeMonitor(Start.class, "initReasoningService").start(); ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); - Class<? extends ReasonerComponentOld> rcClass; + Class<? extends ReasonerComponent> rcClass; if(reasonerOption != null) { rcClass = confMapper.getReasonerComponentClass(reasonerOption.getStringValue()); if(rcClass == null) { @@ -856,7 +856,7 @@ return lp; } - public ReasonerComponentOld getReasonerComponent() { + public ReasonerComponent getReasonerComponent() { return rc; } @@ -889,8 +889,8 @@ * @return reasonerClass reasoner class */ @Deprecated - public static Class<? extends ReasonerComponentOld> getReasonerClass(ConfFileOption reasonerOption) { - Class<? extends ReasonerComponentOld> reasonerClass = null; + public static Class<? extends ReasonerComponent> getReasonerClass(ConfFileOption reasonerOption) { + Class<? extends ReasonerComponent> reasonerClass = null; if (reasonerOption == null || reasonerOption.getStringValue().equals("fastInstanceChecker")) reasonerClass = FastInstanceChecker.class; else if (reasonerOption.getStringValue().equals("owlAPI")) Added: trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; + +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; + +/** + * Contains the following reasoning/query operations: + * <ul> + * <li>queries for elements contained in the knowledge base (classes, properties, ...)</li> + * <li>basic reasoning requests related to the knowledge base as a whole (e.g. consistency)</li> + * </ul> + * + * @author Jens Lehmann + * + */ +public interface BaseReasoner { + + /** + * Gets all named classes in the knowledge base, e.g. Person, City, Car. + * @return All named classes in KB. + */ + public Set<NamedClass> getNamedClasses(); + + /** + * Gets all object properties in the knowledge base, e.g. hasChild, isCapitalOf, hasEngine. + * @return All object properties in KB. + */ + public Set<ObjectProperty> getObjectProperties(); + + /** + * Gets all individuals in the knowledge base, e.g. Eric, London, Car829. + * @return All individuals in KB. + */ + public SortedSet<Individual> getIndividuals(); + + /** + * Returns the base URI of the knowledge base. If several knowledge sources are + * used, we only pick one of their base URIs. + * @return The base URI, e.g. http://dbpedia.org/resource/. + */ + public String getBaseURI(); + + /** + * Returns the prefixes used in the knowledge base, e.g. foaf for + * foaf: <http://xmlns.com/foaf/0.1/>. If several knowledge sources are used, + * their prefixes are merged. (In case a prefix is defined twice with different + * values, we pick one of those.) + * @return The prefix mapping. + */ + public Map<String, String> getPrefixes(); + +} Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -71,7 +71,7 @@ // these variables are valid for the complete lifetime of a DL-Learner session private static Collection<Class<? extends Component>> components; private static Collection<Class<? extends KnowledgeSource>> knowledgeSources; - private static Collection<Class<? extends ReasonerComponentOld>> reasonerComponents; + private static Collection<Class<? extends ReasonerComponent>> reasonerComponents; private static Collection<Class<? extends LearningProblem>> learningProblems; private static Collection<Class<? extends LearningAlgorithm>> learningAlgorithms; // you can either use the components.ini file or directly specify the classes to use @@ -111,7 +111,7 @@ // component list components = new TreeSet<Class<? extends Component>>(classComparator); knowledgeSources = new TreeSet<Class<? extends KnowledgeSource>>(classComparator); - reasonerComponents = new TreeSet<Class<? extends ReasonerComponentOld>>(classComparator); + reasonerComponents = new TreeSet<Class<? extends ReasonerComponent>>(classComparator); learningProblems = new TreeSet<Class<? extends LearningProblem>>(classComparator); learningAlgorithms = new TreeSet<Class<? extends LearningAlgorithm>>(classComparator); algorithmProblemsMapping = new TreeMap<Class<? extends LearningAlgorithm>, Collection<Class<? extends LearningProblem>>>( @@ -126,8 +126,8 @@ if (KnowledgeSource.class.isAssignableFrom(component)) { knowledgeSources.add((Class<? extends KnowledgeSource>) component); - } else if (ReasonerComponentOld.class.isAssignableFrom(component)) { - reasonerComponents.add((Class<? extends ReasonerComponentOld>) component); + } else if (ReasonerComponent.class.isAssignableFrom(component)) { + reasonerComponents.add((Class<? extends ReasonerComponent>) component); } else if (LearningProblem.class.isAssignableFrom(component)) { learningProblems.add((Class<? extends LearningProblem>) component); } else if (LearningAlgorithm.class.isAssignableFrom(component)) { @@ -324,7 +324,7 @@ * @param source A knowledge source. * @return A reasoner component. */ - public <T extends ReasonerComponentOld> T reasoner(Class<T> reasoner, + public <T extends ReasonerComponent> T reasoner(Class<T> reasoner, KnowledgeSource source) { Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); sources.add(source); @@ -340,7 +340,7 @@ * @param sources A set of knowledge sources. * @return A reasoner component. */ - public <T extends ReasonerComponentOld> T reasoner(Class<T> reasoner, + public <T extends ReasonerComponent> T reasoner(Class<T> reasoner, Set<KnowledgeSource> sources) { if (!reasonerComponents.contains(reasoner)) { System.err.println("Warning: reasoner component " + reasoner @@ -365,9 +365,9 @@ * @param reasoner A reasoner component. * @return The reasoning service encapsulating the reasoner. */ - public ReasoningService reasoningService(ReasonerComponentOld reasoner) { - return new ReasoningService(reasoner); - } +// public ReasoningService reasoningService(ReasonerComponent reasoner) { +// return new ReasoningService(reasoner); +// } /** * Factory method for creating a learning problem component. @@ -376,13 +376,13 @@ * @param reasoner A reasoning service object. * @return A learning problem component. */ - public <T extends LearningProblem> T learningProblem(Class<T> lpClass, ReasoningService reasoner) { + public <T extends LearningProblem> T learningProblem(Class<T> lpClass, ReasonerComponent reasoner) { if (!learningProblems.contains(lpClass)) { System.err.println("Warning: learning problem " + lpClass + " is not a registered learning problem component."); } - T lp = invokeConstructor(lpClass, new Class[] { ReasoningService.class }, + T lp = invokeConstructor(lpClass, new Class[] { ReasonerComponent.class }, new Object[] { reasoner }); pool.registerComponent(lp); return lp; @@ -399,7 +399,7 @@ * @throws LearningProblemUnsupportedException Thrown when the learning problem and * the learning algorithm are not compatible. */ - public <T extends LearningAlgorithm> T learningAlgorithm(Class<T> laClass, LearningProblem lp, ReasoningService rs) throws LearningProblemUnsupportedException { + public <T extends LearningAlgorithm> T learningAlgorithm(Class<T> laClass, LearningProblem lp, ReasonerComponent rs) throws LearningProblemUnsupportedException { if (!learningAlgorithms.contains(laClass)) { System.err.println("Warning: learning algorithm " + laClass + " is not a registered learning algorithm component."); @@ -423,7 +423,7 @@ // return null; } - T la = invokeConstructor(laClass, new Class[] { constructorArgument, ReasoningService.class }, new Object[] { lp, rs }); + T la = invokeConstructor(laClass, new Class[] { constructorArgument, ReasonerComponent.class }, new Object[] { lp, rs }); pool.registerComponent(la); return la; } @@ -659,8 +659,8 @@ * @return the components A list of reasoner component classes available in this * instance of <code>ComponentManager</code>. */ - public List<Class<? extends ReasonerComponentOld>> getReasonerComponents() { - return new LinkedList<Class<? extends ReasonerComponentOld>>(reasonerComponents); + public List<Class<? extends ReasonerComponent>> getReasonerComponents() { + return new LinkedList<Class<? extends ReasonerComponent>>(reasonerComponents); } /** Added: trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * Reasoning requests/queries related to individuals in the knowledge base. + * + * @author Jens Lehmann + * + */ +public interface IndividualReasoner { + +} Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -46,17 +46,17 @@ * Implementations of learning problems can use this class * variable to perform reasoner operations. */ - protected ReasoningService reasoningService; + protected ReasonerComponent reasoner; /** * Constructs a learning problem using a reasoning service for * querying the background knowledge. It can be used for * evaluating solution candidates. - * @param reasoningService The reasoning service used as + * @param reasoner The reasoning service used as * background knowledge. */ - public LearningProblem(ReasoningService reasoningService) { - this.reasoningService = reasoningService; + public LearningProblem(ReasonerComponent reasoner) { + this.reasoner = reasoner; } /** @@ -65,10 +65,10 @@ * Implementations, which do not only use the provided reasoning * service class variable, must make sure that a call to this method * indeed changes the reasoning service. - * @param reasoningService New reasoning service. + * @param reasoner New reasoning service. */ - public void changeReasoningService(ReasoningService reasoningService) { - this.reasoningService = reasoningService; + public void changeReasoningService(ReasonerComponent reasoner) { + this.reasoner = reasoner; } /** Copied: trunk/src/dl-learner/org/dllearner/core/Reasoner.java (from rev 1499, trunk/src/dl-learner/org/dllearner/core/ReasonerNew.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * List of available reasoning/query methods. + * + * @author Jens Lehmann + * + */ +public interface Reasoner extends BaseReasoner, SchemaReasoner, IndividualReasoner { + +} Added: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -0,0 +1,934 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Map.Entry; + +import org.apache.log4j.Logger; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.DataRange; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyHierarchy; +import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.reasoning.ReasonerType; +import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +/** + * Abstract component representing a reasoner. Only a few reasoning operations + * are guaranteed to be implemented by the underlying reasoner, while a + * {@link ReasoningMethodUnsupportedException} is thrown for all other methods. + * In addition to calling the actual implementations of reasoning operations, + * the class also collects statistical information, which can be queried. + * + * @author Jens Lehmann + * + */ +public abstract class ReasonerComponent extends Component implements Reasoner { + + public static Logger logger = Logger.getLogger(ReasonerComponent.class); + + // statistical data for particular reasoning operations + private long instanceCheckReasoningTimeNs = 0; + private int nrOfInstanceChecks = 0; + private int nrOfMultiInstanceChecks = 0; + private long retrievalReasoningTimeNs = 0; + private int nrOfRetrievals = 0; + private long subsumptionReasoningTimeNs = 0; + private int nrOfSubsumptionChecks = 0; + private int nrOfMultiSubsumptionChecks = 0; + private int nrOfSubsumptionHierarchyQueries = 0; + + // rest of reasoning time + private long otherReasoningTimeNs = 0; + + // time for all reasoning requests (usually longer than the sum of all + // above) + private long overallReasoningTimeNs = 0; + + // temporary variables (moved here for performance reasons) + private long reasoningStartTimeTmp; + private long reasoningDurationTmp; + + // list view + private List<NamedClass> atomicConceptsList; + private List<ObjectProperty> atomicRolesList; + + // hierarchies (they are computed the first time they are needed) + private SubsumptionHierarchy subsumptionHierarchy; + private ObjectPropertyHierarchy roleHierarchy; + private DatatypePropertyHierarchy datatypePropertyHierarchy; + + /** + * The underlying knowledge sources. + */ + protected Set<KnowledgeSource> sources; + + /** + * Constructs a new reasoner component. + * + * @param sources + * The underlying knowledge sources. + */ + public ReasonerComponent(Set<KnowledgeSource> sources) { + this.sources = sources; + } + + /** + * Gets the knowledge sources used by this reasoner. + * + * @return The underlying knowledge sources. + */ + public Set<KnowledgeSource> getSources() { + return sources; + } + + /** + * Method to exchange the reasoner underlying the learning problem. + * Implementations, which do not only use the provided sources class + * variable, must make sure that a call to this method indeed changes them. + * + * @param sources + * The new knowledge sources. + */ + public void changeSources(Set<KnowledgeSource> sources) { + this.sources = sources; + } + + /** + * Gets the type of the underlying reasoner. Although rarely necessary, + * applications can use this to adapt their behaviour to the reasoner. + * + * @return The reasoner type. + */ + public abstract ReasonerType getReasonerType(); + + /** + * Reset all statistics. Usually, you do not need to call this. However, if + * you e.g. perform benchmarks of learning algorithms and performing + * reasoning operations, such as a consistency check, before starting the + * algorithm, you can use this method to reset all statistical values. + */ + public void resetStatistics() { + instanceCheckReasoningTimeNs = 0; + nrOfInstanceChecks = 0; + retrievalReasoningTimeNs = 0; + nrOfRetrievals = 0; + subsumptionReasoningTimeNs = 0; + nrOfSubsumptionChecks = 0; + // subsumptionHierarchyTimeNs = 0; + nrOfSubsumptionHierarchyQueries = 0; + otherReasoningTimeNs = 0; + overallReasoningTimeNs = 0; + } + + /** + * Call this method to release the knowledge base. Not calling the method + * may (depending on the underlying reasoner) result in resources for this + * knowledge base not being freed, which can cause memory leaks. + */ + public abstract void releaseKB(); + + // we cannot expect callers of reasoning methods to reliably recover if + // certain reasoning methods are not implemented by the backend; we also + // should not require callers to build catch clauses each time they make + // a reasoner request => for this reasoner, we throw a runtime exception + // here + private void handleExceptions(ReasoningMethodUnsupportedException e) { + e.printStackTrace(); + throw new RuntimeException("Reasoning method not supported.", e); + } + + @Override + public boolean subsumes(Description superClass, Description subClass) { + reasoningStartTimeTmp = System.nanoTime(); + boolean result = false; + try { + result = subsumesImpl(superClass, subClass); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfSubsumptionChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + subsumptionReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) { + reasoningStartTimeTmp = System.nanoTime(); + Set<Description> result = null; + try { + result = subsumesImpl(superConcepts, subConcept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfSubsumptionChecks += superConcepts.size(); + nrOfMultiSubsumptionChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + subsumptionReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public SortedSetTuple<Individual> doubleRetrieval(Description concept) { + reasoningStartTimeTmp = System.nanoTime(); + SortedSetTuple<Individual> result; + try { + result = doubleRetrievalImpl(concept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public SortedSetTuple<Individual> doubleRetrieval(Description concept, Description adc) { + reasoningStartTimeTmp = System.nanoTime(); + SortedSetTuple<Individual> result; + try { + result = doubleRetrievalImpl(concept, adc); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public SortedSet<Individual> retrieval(Description concept) { + reasoningStartTimeTmp = System.nanoTime(); + SortedSet<Individual> result; + try { + result = retrievalImpl(concept); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + nrOfRetrievals++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + retrievalReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public boolean instanceCheck(Description concept, Individual s) { + reasoningStartTimeTmp = System.nanoTime(); + boolean result = false; + try { + result = instanceCheckImpl(concept, s); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfInstanceChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + instanceCheckReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public SortedSet<Individual> instanceCheck(Description concept, Set<Individual> s) { + // logger.debug("instanceCheck "+concept.toKBSyntaxString()); + reasoningStartTimeTmp = System.nanoTime(); + SortedSet<Individual> result = null; + try { + result = instanceCheckImpl(concept, s); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + nrOfInstanceChecks += s.size(); + nrOfMultiInstanceChecks++; + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + instanceCheckReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + // logger.debug("instanceCheck done"); + return result; + } + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @param concept + * Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<Description> getMoreGeneralConcepts(Description concept) { + return getSubsumptionHierarchy().getMoreGeneralConcepts(concept); + } + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @param concept + * Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<Description> getMoreSpecialConcepts(Description concept) { + return getSubsumptionHierarchy().getMoreSpecialConcepts(concept); + } + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) + * @param role + * Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<ObjectProperty> getMoreGeneralRoles(ObjectProperty role) { + return getRoleHierarchy().getMoreGeneralRoles(role); + } + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) + * @param role + * Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<ObjectProperty> getMoreSpecialRoles(ObjectProperty role) { + return getRoleHierarchy().getMoreSpecialRoles(role); + } + + /** + * @see ObjectPropertyHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<ObjectProperty> getMostGeneralRoles() { + return getRoleHierarchy().getMostGeneralRoles(); + } + + /** + * @see ObjectPropertyHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<ObjectProperty> getMostSpecialRoles() { + return getRoleHierarchy().getMostSpecialRoles(); + } + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) + * @param role + * Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<DatatypeProperty> getMoreGeneralDatatypeProperties(DatatypeProperty role) { + return getDatatypePropertyHierarchy().getMoreGeneralRoles(role); + } + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) + * @param role + * Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<DatatypeProperty> getMoreSpecialDatatypeProperties(DatatypeProperty role) { + return getDatatypePropertyHierarchy().getMoreSpecialRoles(role); + } + + /** + * @see ObjectPropertyHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties() { + return getDatatypePropertyHierarchy().getMostGeneralRoles(); + } + + /** + * @see ObjectPropertyHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties() { + return getDatatypePropertyHierarchy().getMostSpecialRoles(); + } + + protected void prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Subsumption hierarchy creation not supported by this reasoner."); + } + + public SubsumptionHierarchy getSubsumptionHierarchy() { + if (subsumptionHierarchy == null) { + try { + prepareSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + return subsumptionHierarchy; + } + + protected void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Object property hierarchy creation not supported by this reasoner."); + } + + public ObjectPropertyHierarchy getRoleHierarchy() { + if (roleHierarchy == null) { + try { + prepareRoleHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + return roleHierarchy; + } + + protected void prepareDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Datatype property hierarchy creation not supported by this reasoner."); + } + + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + if (datatypePropertyHierarchy == null) { + try { + prepareDatatypePropertyHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + return datatypePropertyHierarchy; + } + + public boolean isSatisfiable() { + reasoningStartTimeTmp = System.nanoTime(); + boolean result; + try { + result = isSatisfiableImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return false; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public Set<Individual> getRelatedIndividuals(Individual individual, + ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + try { + return getRelatedIndividualsImpl(individual, objectProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) + throws ReasoningMethodUnsupportedException { + try { + return getRelatedValuesImpl(individual, datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + try { + return getLabelImpl(entity); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + reasoningStartTimeTmp = System.nanoTime(); + Map<Individual, SortedSet<Individual>> result; + try { + result = getRoleMembersImpl(atomicRole); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; + otherReasoningTimeNs += reasoningDurationTmp; + overallReasoningTimeNs += reasoningDurationTmp; + return result; + } + + public abstract boolean hasDatatypeSupport(); + + public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers( + DatatypeProperty datatypeProperty) { + try { + return getDoubleDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Integer>> getIntDatatypeMembers( + DatatypeProperty datatypeProperty) { + try { + return getIntDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return getTrueDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return getFalseDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public SortedSet<DatatypeProperty> getDatatypeProperties() { + try { + return getDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { + try { + return getBooleanDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public SortedSet<DatatypeProperty> getIntDatatypeProperties() { + try { + return getIntDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { + try { + return getDoubleDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Description getDomain(ObjectProperty objectProperty) { + try { + return getDomainImpl(objectProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Description getDomain(DatatypeProperty datatypeProperty) { + try { + return getDomainImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Description getRange(ObjectProperty objectProperty) { + try { + return getRangeImpl(objectProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public DataRange getRange(DatatypeProperty datatypeProperty) { + try { + return getRangeImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public List<NamedClass> getAtomicConceptsList() { + if (atomicConceptsList == null) + atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); + return atomicConceptsList; + } + + public List<NamedClass> getAtomicConceptsList(boolean removeOWLThing) { + if (!removeOWLThing) { + return getAtomicConceptsList(); + } else { + List<NamedClass> l = new LinkedList<NamedClass>(); + for (NamedClass class1 : getAtomicConceptsList()) { + if (class1.compareTo(new NamedClass(OWLVocabulary.OWL_NOTHING)) == 0 + || class1.compareTo(new NamedClass(OWLVocabulary.OWL_THING)) == 0) { + ;// do nothing + } else { + l.add(class1); + } + } + return l; + } + + } + + public List<ObjectProperty> getAtomicRolesList() { + if (atomicRolesList == null) + atomicRolesList = new LinkedList<ObjectProperty>(getObjectProperties()); + return atomicRolesList; + } + + public long getInstanceCheckReasoningTimeNs() { + return instanceCheckReasoningTimeNs; + } + + public long getRetrievalReasoningTimeNs() { + return retrievalReasoningTimeNs; + } + + public int getNrOfInstanceChecks() { + return nrOfInstanceChecks; + } + + public int getNrOfRetrievals() { + return nrOfRetrievals; + } + + public int getNrOfSubsumptionChecks() { + return nrOfSubsumptionChecks; + } + + public long getSubsumptionReasoningTimeNs() { + return subsumptionReasoningTimeNs; + } + + /* + * public long getSubsumptionHierarchyTimeNs() { return + * subsumptionHierarchyTimeNs; } + */ + public int getNrOfSubsumptionHierarchyQueries() { + return nrOfSubsumptionHierarchyQueries; + } + + public long getOverallReasoningTimeNs() { + return overallReasoningTimeNs; + } + + public long getTimePerRetrievalNs() { + return retrievalReasoningTimeNs / nrOfRetrievals; + } + + public long getTimePerInstanceCheckNs() { + return instanceCheckReasoningTimeNs / nrOfInstanceChecks; + } + + public long getTimePerSubsumptionCheckNs() { + return subsumptionReasoningTimeNs / nrOfSubsumptionChecks; + } + + public int getNrOfMultiSubsumptionChecks() { + return nrOfMultiSubsumptionChecks; + } + + public int getNrOfMultiInstanceChecks() { + return nrOfMultiInstanceChecks; + } + + public boolean subsumesImpl(Description superConcept, Description subConcept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<Description> subsumesImpl(Description superConcept, Set<Description> subConcepts) + throws ReasoningMethodUnsupportedException { + Set<Description> returnSet = new HashSet<Description>(); + for (Description subConcept : subConcepts) { + if (subsumes(superConcept, subConcept)) + returnSet.add(subConcept); + } + return returnSet; + } + + public Set<Description> subsumesImpl(Set<Description> superConcepts, Description subConcept) + throws ReasoningMethodUnsupportedException { + Set<Description> returnSet = new HashSet<Description>(); + for (Description superConcept : superConcepts) { + if (subsumes(superConcept, subConcept)) + returnSet.add(superConcept); + } + return returnSet; + } + + public SortedSet<Individual> retrievalImpl(Description concept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<Individual> getRelatedIndividualsImpl(Individual individual, + ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<Constant> getRelatedValuesImpl(Individual individual, + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<Constant> getLabelImpl(Entity entity) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Map<Individual, SortedSet<Individual>> getRoleMembersImpl(ObjectProperty atomicRole) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Map<Individual, SortedSet<Constant>> getDatatypeMembersImpl( + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + // convenience method to get int value mappings of a datatype property + public Map<Individual, SortedSet<Integer>> getIntDatatypeMembersImpl( + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); + Map<Individual, SortedSet<Integer>> ret = new TreeMap<Individual, SortedSet<Integer>>(); + for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + SortedSet<Integer> valuesInt = new TreeSet<Integer>(); + for (Constant c : values) { + int v = Integer.parseInt(c.getLiteral()); + valuesInt.add(v); + } + ret.put(e.getKey(), valuesInt); + } + return ret; + } + + // convenience method to get double value mappings of a datatype property + public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembersImpl( + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); + Map<Individual, SortedSet<Double>> ret = new TreeMap<Individual, SortedSet<Double>>(); + for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + SortedSet<Double> valuesDouble = new TreeSet<Double>(); + for (Constant c : values) { + double v = Double.parseDouble(c.getLiteral()); + valuesDouble.add(v); + } + ret.put(e.getKey(), valuesDouble); + } + return ret; + } + + // convenience method to get boolean value mappings of a datatype property + public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembersImpl( + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); + Map<Individual, SortedSet<Boolean>> ret = new TreeMap<Individual, SortedSet<Boolean>>(); + for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + SortedSet<Boolean> valuesBoolean = new TreeSet<Boolean>(); + for (Constant c : values) { + boolean v = Boolean.parseBoolean(c.getLiteral()); + valuesBoolean.add(v); + } + ret.put(e.getKey(), valuesBoolean); + } + return ret; + } + + // convenience method returning those values which have value "true" for + // this + // datatype property + public SortedSet<Individual> getTrueDatatypeMembersImpl(DatatypeProperty datatypeProperty) + throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); + SortedSet<Individual> ret = new TreeSet<Individual>(); + for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + for (Constant c : values) { + boolean v = Boolean.parseBoolean(c.getLiteral()); + if (v == true) + ret.add(e.getKey()); + } + } + return ret; + } + + // convenience method returning those values which have value "false" for + // this + // datatype property + public SortedSet<Individual> getFalseDatatypeMembersImpl(DatatypeProperty datatypeProperty) + throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); + SortedSet<Individual> ret = new TreeSet<Individual>(); + for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + for (Constant c : values) { + boolean v = Boolean.parseBoolean(c.getLiteral()); + if (v == false) + ret.add(e.getKey()); + } + } + return ret; + } + + public boolean instanceCheckImpl(Description concept, Individual individual) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSet<Individual> instanceCheckImpl(Description concept, Set<Individual> individuals) + throws ReasoningMethodUnsupportedException { + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + for (Individual individual : individuals) { + if (instanceCheck(concept, individual)) + returnSet.add(individual); + } + return returnSet; + } + + public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept, Description adc) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public boolean isSatisfiableImpl() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SubsumptionHierarchy getSubsumptionHierarchyImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedDatatypeProperties) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public ObjectPropertyHierarchy getRoleHierarchyImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public DatatypePropertyHierarchy getDatatypePropertyHierarchyImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<NamedClass> getConceptsImpl(Individual i) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Description getDomainImpl(ObjectProperty objectProperty) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Description getDomainImpl(DatatypeProperty datatypeProperty) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Description getRangeImpl(ObjectProperty objectProperty) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public DataRange getRangeImpl(DatatypeProperty datatypeProperty) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSet<DatatypeProperty> getBooleanDatatypePropertiesImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSet<DatatypeProperty> getDoubleDatatypePropertiesImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public SortedSet<DatatypeProperty> getIntDatatypePropertiesImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<NamedClass> getInconsistentClassesImpl() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -46,6 +46,7 @@ * @author Jens Lehmann * */ +@Deprecated public abstract class ReasonerComponentOld extends Component implements ReasonerOld { protected Set<KnowledgeSource> sources; Deleted: trunk/src/dl-learner/org/dllearner/core/ReasonerNew.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerNew.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerNew.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.core; - -/** - * List of available reasoning/query methods. - * - * @author Jens Lehmann - * - */ -public interface ReasonerNew extends BaseReasoner, SchemaReasoner, IndividualReasoner { - -} Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -44,6 +44,7 @@ * @author Jens Lehmann * */ +@Deprecated public interface ReasonerOld { public ReasonerType getReasonerType(); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -53,6 +53,7 @@ * @author Jens Lehmann * */ +@Deprecated public class ReasoningService { public static Logger logger = Logger.getLogger(ReasoningService.class); Added: trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +import java.util.Set; + +import org.dllearner.core.owl.Description; + +/** + * Reasoning requests related to the schema of the knowledge base. + * + * @author Jens Lehmann + * + */ +public interface SchemaReasoner { + + public boolean subsumes(Description superConcept, Description subConcept); + + public Set<Description> subsumes(Description superConcept, Set<Description> subConcepts); + + public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept); + +} Modified: trunk/src/dl-learner/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -21,7 +21,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasonerComponentOld; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.owl.ClassAssertionAxiom; @@ -85,12 +85,12 @@ static HashMap<String, SortedSet<Individual>> classToInd = new HashMap<String, SortedSet<Individual>>(); static HashMap<Individual, String> indToClass = new HashMap<Individual, String>(); - static Set<ReasonerComponentOld> allReasoners = new HashSet<ReasonerComponentOld>(); + static Set<ReasonerComponent> allReasoners = new HashSet<ReasonerComponent>(); static int negativeExamplesAdded = 200; // static LinkedList<String> words; public KB kb; - public ReasonerComponentOld reasoner; + public ReasonerComponent reasoner; //public FastInstanceChecker fic; @@ -254,19 +254,19 @@ try { Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); sources.add(new KBFile(kb)); - ReasonerComponentOld r = new FastInstanceChecker(sources); + ReasonerComponent r = new FastInstanceChecker(sources); r.init(); - ReasoningService rs = new ReasoningService(r); +// ReasoningService rs = new ReasoningService(r); //cm.learningProblem(lpClass, reasoner) - LearningProblem lp = new PosNegDefinitionLP(rs); + LearningProblem lp = new PosNegDefinitionLP(r); //cm.getConfigOptionValue(lp, ""); cm.applyConfigEntry(lp, "positiveExamples",pos); cm.applyConfigEntry(lp, "negativeExamples",neg); lp.init(); - la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs); + la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, r); SortedSet<String> ignoredConcepts = getIgnoredConcepts(pos, neg); cm.applyConfigEntry(la,"useAllConstructor",false); @@ -470,7 +470,7 @@ SortedSet<Individual> ret = new TreeSet<Individual>(); try{ - for (ReasonerComponentOld onereasoner : allReasoners) { + for (ReasonerComponent onereasoner : allReasoners) { ret.addAll(onereasoner.retrieval(d)); } Modified: trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2008-11-10 09:54:48 UTC (rev 1499) +++ trunk/src/dl-learner/org/dllearner/gui/ComponentPanel.java 2008-11-10 11:00:23 UTC (rev 1500) @@ -34,7 +34,7 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.ReasonerComponentOld; +import org.dllearner.core.ReasonerComponent; /** * Class displaying a component (and its options). @@ -102,7 +102,7 @@ selectableComponents = new LinkedList<Class<? extends Component>>(); if (panelClass == KnowledgeSource.class) { selectableComponents.addAll(config.getComponentManager().getKnowledgeSources()); - } else if (panelClass == Reasone... [truncated message content] |
From: <jen...@us...> - 2008-11-10 12:44:30
|
Revision: 1501 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1501&view=rev Author: jenslehmann Date: 2008-11-10 12:44:17 +0000 (Mon, 10 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN is still *broken*, please don't update if you want everything to work properly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/core/LearningProblem.java trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.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/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java trunk/src/dl-learner/org/dllearner/scripts/DumbLPFinder.java trunk/src/dl-learner/org/dllearner/scripts/NewSample.java trunk/src/dl-learner/org/dllearner/scripts/PaperStatistics.java trunk/src/dl-learner/org/dllearner/scripts/RoleLearning.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java trunk/src/dl-learner/org/dllearner/test/junit/ExampleTests.java trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifier.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFileConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparqlold.java trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/learn/ComponentCombo.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -29,7 +29,8 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.CommonConfigOptions; import org.dllearner.core.config.ConfigEntry; @@ -67,7 +68,7 @@ private LearningProblem learningProblem; - private ReasoningService rs; + private ReasonerComponent rs; private Description bestDefinition; private Score bestScore; @@ -82,7 +83,7 @@ // list of all generated concepts sorted by length private Map<Integer,List<Description>> generatedDefinitions = new HashMap<Integer,List<Description>>(); - public BruteForceLearner(LearningProblem learningProblem, ReasoningService rs) { + public BruteForceLearner(LearningProblem learningProblem, ReasonerComponent rs) { super(learningProblem, rs); this.learningProblem = learningProblem; this.rs = rs; Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -28,7 +28,8 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigOptions; @@ -63,11 +64,11 @@ } -// private ReasoningService rs; +// private ReasonerComponent rs; private ExampleBasedROLComponent learner; private static String defaultSearchTreeFile = "log/searchTree.txt"; - public DBpediaNavigationSuggestor(LearningProblem learningProblem, ReasoningService rs) { + public DBpediaNavigationSuggestor(LearningProblem learningProblem, ReasonerComponent rs) { super(learningProblem, rs); // this.rs=rs; this.configurator = new DBpediaNavigationSuggestorConfigurator(this); @@ -97,12 +98,12 @@ return "DBpedia Navigation Suggestor"; } - public DBpediaNavigationSuggestor(PosOnlyDefinitionLP learningProblem, ReasoningService rs) { + public DBpediaNavigationSuggestor(PosOnlyDefinitionLP learningProblem, ReasonerComponent rs) { super(learningProblem, rs); System.out.println("test1"); } - public DBpediaNavigationSuggestor(PosNegDefinitionLP learningProblem, ReasoningService rs) { + public DBpediaNavigationSuggestor(PosNegDefinitionLP learningProblem, ReasonerComponent rs) { super(learningProblem, rs); System.out.println("test2"); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -28,7 +28,7 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; @@ -48,17 +48,14 @@ private Description bestDefinition = null; private Score bestScore; private double bestFitness = Double.NEGATIVE_INFINITY; - private LearningProblem learningProblem; - private ReasoningService rs; + private int numberOfTrees; private int maxDepth; private static Logger logger = Logger.getLogger(RandomGuesser.class); - public RandomGuesser(LearningProblem learningProblem, ReasoningService rs) { - super(learningProblem, rs); - this.learningProblem = learningProblem; - this.rs = rs; + public RandomGuesser(LearningProblem learningProblem, ReasonerComponent rs) { + super(learningProblem, rs); this.configurator = new RandomGuesserConfigurator(this); } @@ -110,7 +107,7 @@ for(int i=0; i<numberOfTrees; i++) { // p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth); - p = GPUtilities.createGrowRandomProgram(learningProblem, rs, maxDepth, false); + p = GPUtilities.createGrowRandomProgram(learningProblem, reasoner, maxDepth, false); if(p.getFitness()>bestFitness) { bestFitness = p.getFitness(); bestScore = p.getScore(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -25,7 +25,7 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.configurators.SimpleSuggestionLearningAlgorithmConfigurator; @@ -103,7 +103,7 @@ } - public Set<Description> getSimpleSuggestions(ReasoningService rs, Set<Individual> indi) { + public Set<Description> getSimpleSuggestions(ReasonerComponent rs, Set<Individual> indi) { // EXISTS property.TOP // ESISTS hasChild // EXISTS hasChild.male Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -19,17 +19,14 @@ */ package org.dllearner.algorithms.el; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.NavigableSet; import java.util.Set; -import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -29,7 +29,7 @@ import java.util.TreeSet; import java.util.Map.Entry; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -65,11 +65,11 @@ // the background knowledge (we need to have it explicitly here, // since we store simulation information in the tree and simulation // updates depend on background knowledge) - protected ReasoningService rs; + protected ReasonerComponent rs; protected SubsumptionHierarchy subsumptionHierarchy; protected ObjectPropertyHierarchy roleHierarchy; - public ELDescriptionTree(ReasoningService rs) { + public ELDescriptionTree(ReasonerComponent rs) { this.rs = rs; subsumptionHierarchy = rs.getSubsumptionHierarchy(); roleHierarchy = rs.getRoleHierarchy(); @@ -81,7 +81,7 @@ * @param description * A description */ - public ELDescriptionTree(ReasoningService rs, Description description) { + public ELDescriptionTree(ReasonerComponent rs, Description description) { this(rs); // construct root node and recursively build the tree rootNode = new ELDescriptionNode(this); Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -33,7 +33,7 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.ConfigEntry; @@ -140,7 +140,7 @@ * 1.0 and a probability of mutation of 0.01. * */ - public GP(PosNegLP learningProblem, ReasoningService rs) { + public GP(PosNegLP learningProblem, ReasonerComponent rs) { super(learningProblem, rs); this.configurator = new GPConfigurator(this); } @@ -270,14 +270,14 @@ */ @Override public void init() { - reasoningService.prepareSubsumptionHierarchy(); - reasoningService.prepareRoleHierarchy(); +// reasoner.prepareSubsumptionHierarchy(); +// reasoner.prepareRoleHierarchy(); } @Override public void start() { // falls refinement-Wahrscheinlichkeit größer 0, dann erzeuge psi - psi = new Psi((PosNegLP)learningProblem, reasoningService); + psi = new Psi((PosNegLP)learningProblem, reasoner); System.out.println(); System.out.println("Starting Genetic Programming Learner"); @@ -440,11 +440,11 @@ i++; // mutation } else if(rand >= crossoverBoundary && rand < mutationBoundary) { - newIndividuals[i] = GPUtilities.mutation(learningProblem, reasoningService, individuals[selectedIndividuals[i]]); + newIndividuals[i] = GPUtilities.mutation(learningProblem, reasoner, individuals[selectedIndividuals[i]]); // hill climbing } else if(rand >= mutationBoundary && rand < hillClimbingBoundary) { // System.out.println("hill climbing"); - newIndividuals[i] = GPUtilities.hillClimbing(learningProblem, reasoningService, individuals[selectedIndividuals[i]]); + newIndividuals[i] = GPUtilities.hillClimbing(learningProblem, reasoner, individuals[selectedIndividuals[i]]); // refinement operator } else if(rand >= hillClimbingBoundary && rand < refinementBoundary) { newIndividuals[i] = psi.applyOperator(individuals[selectedIndividuals[i]]); @@ -583,7 +583,7 @@ } /* - Collection<Concept> test = ReasoningService.retrievals; + Collection<Concept> test = ReasonerComponent.retrievals; // for(Concept c : ) test.removeAll(psi.evalCache.keySet()); @@ -618,9 +618,9 @@ // int depth = rand.nextInt(initMaxDepth-initMinDepth)+initMinDepth; if(grow) - individuals[i] = GPUtilities.createGrowRandomProgram(learningProblem, reasoningService, depth, adc); + individuals[i] = GPUtilities.createGrowRandomProgram(learningProblem, reasoner, depth, adc); else - individuals[i] = GPUtilities.createFullRandomProgram(learningProblem, reasoningService, depth, adc); + individuals[i] = GPUtilities.createFullRandomProgram(learningProblem, reasoner, depth, adc); } /* @@ -843,7 +843,7 @@ // long algorithmTime = System.nanoTime() - Main.getAlgorithmStartTime(); long algorithmTime = System.nanoTime() - startTime; System.out.println("overall algorithm runtime: " + Helper.prettyPrintNanoSeconds(algorithmTime)); - // System.out.println("instance checks: " + learningProblem.getReasoningService().getNrOfInstanceChecks()); + // System.out.println("instance checks: " + learningProblem.getReasonerComponent().getNrOfInstanceChecks()); // System.out.println("fitness evals: " + Program.fitnessEvaluations); // System.out.println("nr. of individuals: " + individuals.length + " (" + numberOfSelectedIndividuals + " selected)"); Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -8,8 +8,8 @@ import java.util.TreeMap; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; -import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; @@ -135,7 +135,7 @@ * Perform a point mutation on the given program. * @param p The program to be mutated. */ - public static Program mutation(LearningProblem learningProblem, ReasoningService rs, Program p) { + public static Program mutation(LearningProblem learningProblem, ReasonerComponent rs, Program p) { mutation++; if(p.getAdc() != null) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. @@ -159,7 +159,7 @@ } } - private static Description mutation(LearningProblem learningProblem, ReasoningService rs, Description tree, boolean useADC) { + private static Description mutation(LearningProblem learningProblem, ReasonerComponent rs, Description tree, boolean useADC) { // auch bei Mutation muss darauf geachtet werden, dass // Baum nicht modifiziert wird (sonst w�rde man automatisch auch // andere "selected individuals" modifizieren) @@ -304,7 +304,7 @@ // m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas // ver�ndert wird - public static Program hillClimbing(LearningProblem learningProblem, ReasoningService rs, Program p) { + public static Program hillClimbing(LearningProblem learningProblem, ReasonerComponent rs, Program p) { hillClimbing++; // checken, ob Bedingungen f�r hill-climbing erf�llt sind if(!rs.getReasonerType().equals(ReasonerType.FAST_RETRIEVAL) @@ -327,7 +327,7 @@ // Alternativen zu speichern und dann ein Element zuf�llig auszuw�hlen, // aber w�rde man das nicht machen, dann w�re das ein starker Bias // zu z.B. Disjunktion (weil die als erstes getestet wird) - private static Description hillClimbing(LearningProblem learningProblem, ReasoningService rs, Description node, ScoreThreeValued score) { + private static Description hillClimbing(LearningProblem learningProblem, ReasonerComponent rs, Description node, ScoreThreeValued score) { SortedSetTuple<Individual> tuple = new SortedSetTuple<Individual>(score.getPosClassified(),score.getNegClassified()); SortedSetTuple<String> stringTuple = Helper.getStringTuple(tuple); // FlatABox abox = FlatABox.getInstance(); @@ -452,7 +452,7 @@ } } - private static ScoreThreeValued getScore(int conceptLength, LearningProblem learningProblem, ReasoningService rs, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { + private static ScoreThreeValued getScore(int conceptLength, LearningProblem learningProblem, ReasonerComponent rs, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { // es muss hier die Helper-Methode verwendet werden, sonst werden // Individuals gel�scht !! SortedSet<Individual> neutClassified = Helper.intersection(rs.getIndividuals(),posClassified); @@ -489,7 +489,7 @@ return returnMap; } - private static Description pickTerminalSymbol(LearningProblem learningProblem, ReasoningService rs, boolean useADC) { + private static Description pickTerminalSymbol(LearningProblem learningProblem, ReasonerComponent rs, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; int nrOfConcepts = rs.getNamedClasses().size(); @@ -619,7 +619,7 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(LearningProblem learningProblem, ReasoningService rs, int depth, boolean adc) { + public static Program createFullRandomProgram(LearningProblem learningProblem, ReasonerComponent rs, int depth, boolean adc) { if(adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, rs, depth, true), @@ -629,7 +629,7 @@ return createProgram(learningProblem, createFullRandomTree(learningProblem, rs, depth, false)); } - private static Description createFullRandomTree(LearningProblem learningProblem, ReasoningService rs, int depth, boolean useADC) { + private static Description createFullRandomTree(LearningProblem learningProblem, ReasonerComponent rs, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int numberOfRoles = rs.getObjectProperties().size(); // abox.roles.size(); @@ -680,7 +680,7 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(LearningProblem learningProblem, ReasoningService rs, int depth, boolean adc) { + public static Program createGrowRandomProgram(LearningProblem learningProblem, ReasonerComponent rs, int depth, boolean adc) { if(adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,rs,depth,true), @@ -690,7 +690,7 @@ return createProgram(learningProblem, createGrowRandomTree(learningProblem, rs, depth,false)); } - private static Description createGrowRandomTree(LearningProblem learningProblem, ReasoningService rs, int depth, boolean useADC) { + private static Description createGrowRandomTree(LearningProblem learningProblem, ReasonerComponent rs, int depth, boolean useADC) { /* private static Concept pickAlphabetSymbol(boolean useADC) { FlatABox abox = FlatABox.getInstance(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -6,7 +6,7 @@ import java.util.TreeMap; import org.dllearner.algorithms.gp.Program; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.PosNegLP; @@ -49,7 +49,7 @@ private long someTimeStart = 0; public long someTime = 0; - public Psi(PosNegLP learningProblem, ReasoningService reasoningService) { //, PsiUp pu, PsiDown pd) { + public Psi(PosNegLP learningProblem, ReasonerComponent reasoningService) { //, PsiUp pu, PsiDown pd) { // this.pu = pu; // this.pd = pd; this.learningProblem = learningProblem; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -33,7 +33,8 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigMappings; @@ -150,12 +151,12 @@ // soll später einen Operator und eine Heuristik entgegennehmen // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { - public ExampleBasedROLComponent(PosNegLP learningProblem, ReasoningService reasoningService) { + public ExampleBasedROLComponent(PosNegLP learningProblem, ReasonerComponent reasoningService) { super(learningProblem, reasoningService); this.configurator = new ExampleBasedROLComponentConfigurator(this); } - public ExampleBasedROLComponent(PosOnlyDefinitionLP learningProblem, ReasoningService reasoningService) { + public ExampleBasedROLComponent(PosOnlyDefinitionLP learningProblem, ReasonerComponent reasoningService) { super(learningProblem, reasoningService); this.configurator = new ExampleBasedROLComponentConfigurator(this); } @@ -300,7 +301,7 @@ public void init() throws ComponentInitException { // exit with a ComponentInitException if the reasoner is unsupported for this learning algorithm - if(reasoningService.getReasonerType() == ReasonerType.DIG) { + if(reasoner.getReasonerType() == ReasonerType.DIG) { throw new ComponentInitException("DIG does not support the inferences needed in the selected learning algorithm component: " + getName()); } @@ -337,38 +338,38 @@ // concepts/roles if(allowedConcepts != null) { // sanity check to control if no non-existing concepts are in the list - Helper.checkConcepts(reasoningService, allowedConcepts); + Helper.checkConcepts(reasoner, allowedConcepts); usedConcepts = allowedConcepts; } else if(ignoredConcepts != null) { - usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoningService, ignoredConcepts); + usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoner, ignoredConcepts); } else { - usedConcepts = Helper.computeConcepts(reasoningService); + usedConcepts = Helper.computeConcepts(reasoner); } if(allowedRoles != null) { - Helper.checkRoles(reasoningService, allowedRoles); + Helper.checkRoles(reasoner, allowedRoles); usedRoles = allowedRoles; } else if(ignoredRoles != null) { - Helper.checkRoles(reasoningService, ignoredRoles); - usedRoles = Helper.difference(reasoningService.getObjectProperties(), ignoredRoles); + Helper.checkRoles(reasoner, ignoredRoles); + usedRoles = Helper.difference(reasoner.getObjectProperties(), ignoredRoles); } else { - usedRoles = reasoningService.getObjectProperties(); + usedRoles = reasoner.getObjectProperties(); } // prepare subsumption and role hierarchies, because they are needed // during the run of the algorithm - reasoningService.prepareSubsumptionHierarchy(usedConcepts); + reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoningService.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - reasoningService.prepareRoleHierarchy(usedRoles); + reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary - if(reasoningService.hasDatatypeSupport()) - reasoningService.prepareDatatypePropertyHierarchy(); + if(reasoner.hasDatatypeSupport()) + reasoner.prepareDatatypePropertyHierarchy(); // create a refinement operator and pass all configuration // variables to it RhoDRDown operator = new RhoDRDown( - reasoningService, + reasoner, applyAllFilter, applyExistsFilter, useAllConstructor, @@ -386,7 +387,7 @@ // options to it algorithm = new ExampleBasedROLearner( learningProblem, - reasoningService, + reasoner, operator, algHeuristic, startClass, Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -35,7 +35,8 @@ import org.apache.log4j.Logger; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -75,7 +76,7 @@ private static Logger logger = Logger.getLogger(ExampleBasedROLearner.class); // basic setup: learning problem and reasoning service - private ReasoningService rs; + private ReasonerComponent rs; // often the learning problems needn't be accessed directly; instead // use the example sets below and the posonly variable private PosNegLP learningProblem; @@ -233,7 +234,7 @@ public ExampleBasedROLearner( LearningProblem learningProblem, - ReasoningService rs, + ReasonerComponent rs, RefinementOperator operator, ExampleBasedHeuristic heuristic, Description startDescription, @@ -722,7 +723,7 @@ improperConcepts = rs.subsumes(toEvaluateConcepts, concept); propernessTestsReasoner += toEvaluateConcepts.size(); // boolean isProper = - // !learningProblem.getReasoningService().subsumes(refinement, + // !learningProblem.getReasonerComponent().subsumes(refinement, // concept); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -2,16 +2,16 @@ import java.util.Comparator; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Description; import org.dllearner.utilities.owl.ConceptComparator; public class SubsumptionComparator implements Comparator<Description> { - private ReasoningService rs; + private ReasonerComponent rs; private ConceptComparator cc = new ConceptComparator(); - public SubsumptionComparator(ReasoningService rs) { + public SubsumptionComparator(ReasonerComponent rs) { this.rs = rs; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -17,7 +17,8 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigMappings; @@ -194,9 +195,7 @@ // prefixes private String baseURI; - // soll später einen Operator und eine Heuristik entgegennehmen - // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { - public ROLearner(PosNegLP learningProblem, ReasoningService reasoningService) { + public ROLearner(PosNegLP learningProblem, ReasonerComponent reasoningService) { super(learningProblem, reasoningService); this.learningProblem = learningProblem; this.configurator = new ROLearnerConfigurator(this); @@ -205,7 +204,7 @@ } - public ROLearner(PosOnlyDefinitionLP learningProblem, ReasoningService reasoningService) { + public ROLearner(PosOnlyDefinitionLP learningProblem, ReasonerComponent reasoningService) { super(learningProblem, reasoningService); this.posOnlyLearningProblem = learningProblem; this.configurator = new ROLearnerConfigurator(this); @@ -346,7 +345,7 @@ } // this.learningProblem2 = learningProblem2; - operator = new RhoDown(reasoningService, applyAllFilter, applyExistsFilter, useAllConstructor, useExistsConstructor, useNegation, useBooleanDatatypes); + operator = new RhoDown(reasoner, applyAllFilter, applyExistsFilter, useAllConstructor, useExistsConstructor, useNegation, useBooleanDatatypes); // candidate sets entsprechend der gewählten Heuristik initialisieren candidates = new TreeSet<Node>(nodeComparator); @@ -354,30 +353,30 @@ if(allowedConcepts != null) { // sanity check to control if no non-existing concepts are in the list - Helper.checkConcepts(reasoningService, allowedConcepts); + Helper.checkConcepts(reasoner, allowedConcepts); usedConcepts = allowedConcepts; } else if(ignoredConcepts != null) { - usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoningService, ignoredConcepts); + usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoner, ignoredConcepts); } else { - usedConcepts = Helper.computeConcepts(reasoningService); + usedConcepts = Helper.computeConcepts(reasoner); } if(allowedRoles != null) { - Helper.checkRoles(reasoningService, allowedRoles); + Helper.checkRoles(reasoner, allowedRoles); usedRoles = allowedRoles; } else if(ignoredRoles != null) { - Helper.checkRoles(reasoningService, ignoredRoles); - usedRoles = Helper.difference(reasoningService.getObjectProperties(), ignoredRoles); + Helper.checkRoles(reasoner, ignoredRoles); + usedRoles = Helper.difference(reasoner.getObjectProperties(), ignoredRoles); } else { - usedRoles = reasoningService.getObjectProperties(); + usedRoles = reasoner.getObjectProperties(); } // prepare subsumption and role hierarchies, because they are needed // during the run of the algorithm - reasoningService.prepareSubsumptionHierarchy(usedConcepts); + reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoningService.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - reasoningService.prepareRoleHierarchy(usedRoles); + reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + reasoner.prepareRoleHierarchy(usedRoles); } public static String getName() { @@ -565,7 +564,7 @@ // solutionsSorted.addAll(solutions); // System.out.println("retrievals:"); - // for(Concept c : ReasoningService.retrievals) { + // for(Concept c : ReasonerComponent.retrievals) { // System.out.println(c); // } @@ -761,9 +760,9 @@ if(toEvaluateConcepts.size()>0) { // Test aller Konzepte auf properness (mit DIG in nur einer Anfrage) long propCalcReasoningStart = System.nanoTime(); - improperConcepts = reasoningService.subsumes(toEvaluateConcepts, concept); + improperConcepts = reasoner.subsumes(toEvaluateConcepts, concept); propernessTestsReasoner+=toEvaluateConcepts.size(); - // boolean isProper = !learningProblem.getReasoningService().subsumes(refinement, concept); + // boolean isProper = !learningProblem.getReasonerComponent().subsumes(refinement, concept); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; } @@ -880,7 +879,7 @@ if(refinement.getLength()>node.getHorizontalExpansion()) { // Test auf properness long propCalcReasoningStart = System.nanoTime(); - boolean isProper = !learningProblem.getReasoningService().subsumes(refinement, concept); + boolean isProper = !learningProblem.getReasonerComponent().subsumes(refinement, concept); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; if(isProper) { @@ -986,19 +985,19 @@ // System.out.println("properness max recursion depth: " + maxRecDepth); // System.out.println("max. number of one-step refinements: " + maxNrOfRefinements); // System.out.println("max. number of children of a node: " + maxNrOfChildren); - logger.debug("subsumption time: " + Helper.prettyPrintNanoSeconds(reasoningService.getSubsumptionReasoningTimeNs())); - logger.debug("instance check time: " + Helper.prettyPrintNanoSeconds(reasoningService.getInstanceCheckReasoningTimeNs())); + logger.debug("subsumption time: " + Helper.prettyPrintNanoSeconds(reasoner.getSubsumptionReasoningTimeNs())); + logger.debug("instance check time: " + Helper.prettyPrintNanoSeconds(reasoner.getInstanceCheckReasoningTimeNs())); } if(showBenchmarkInformation) { - long reasoningTime = reasoningService.getOverallReasoningTimeNs(); + long reasoningTime = reasoner.getOverallReasoningTimeNs(); double reasoningPercentage = 100 * reasoningTime/(double)algorithmRuntime; long propWithoutReasoning = propernessCalcTimeNs-propernessCalcReasoningTimeNs; double propPercentage = 100 * propWithoutReasoning/(double)algorithmRuntime; double deletionPercentage = 100 * childConceptsDeletionTimeNs/(double)algorithmRuntime; - long subTime = reasoningService.getSubsumptionReasoningTimeNs(); + long subTime = reasoner.getSubsumptionReasoningTimeNs(); double subPercentage = 100 * subTime/(double)algorithmRuntime; double refinementPercentage = 100 * refinementCalcTimeNs/(double)algorithmRuntime; double redundancyCheckPercentage = 100 * redundancyCheckTimeNs/(double)algorithmRuntime; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -57,7 +57,7 @@ import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.ConfigEntry; @@ -112,7 +112,6 @@ private Set<KnowledgeSource> sources; private LearningAlgorithm la; private LearningProblem lp; - private ReasoningService rs; private ReasonerComponent rc; /** @@ -243,7 +242,7 @@ // step 2: detect used reasoner - Monitor rsMonitor = JamonMonitorLogger.getTimeMonitor(Start.class, "initReasoningService").start(); + Monitor rsMonitor = JamonMonitorLogger.getTimeMonitor(Start.class, "initReasonerComponent").start(); ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); Class<? extends ReasonerComponent> rcClass; if(reasonerOption != null) { @@ -257,7 +256,6 @@ rc = cm.reasoner(rcClass, sources); configureComponent(cm, rc, parser); initComponent(cm, rc); - rs = cm.reasoningService(rc); rsMonitor.stop(); // step 3: detect learning problem @@ -272,7 +270,7 @@ } else { lpClass = PosNegDefinitionLP.class; } - lp = cm.learningProblem(lpClass, rs); + lp = cm.learningProblem(lpClass, rc); SortedSet<String> posExamples = parser.getPositiveExamples(); SortedSet<String> negExamples = parser.getNegativeExamples(); cm.applyConfigEntry(lp, "positiveExamples", posExamples); @@ -295,7 +293,7 @@ laClass = ExampleBasedROLComponent.class; } try { - la = cm.learningAlgorithm(laClass, lp, rs); + la = cm.learningAlgorithm(laClass, lp, rc); } catch (LearningProblemUnsupportedException e) { e.printStackTrace(); } @@ -304,22 +302,22 @@ laMonitor.stop(); // perform file exports - performExports(parser, baseDir, sources, rs); + performExports(parser, baseDir, sources, rc); // handle any CLI options - processCLIOptions(cm, parser, rs, lp); + processCLIOptions(cm, parser, rc, lp); } public void start(boolean inQueryMode) { if (inQueryMode) - processQueryMode(lp, rs); + processQueryMode(lp, rc); else { // start algorithm long algStartTime = System.nanoTime(); la.start(); long algDuration = System.nanoTime() - algStartTime; - printConclusions(rs, algDuration); + printConclusions(rc, algDuration); } } @@ -519,7 +517,7 @@ } private static void performExports(ConfParser parser, String baseDir, - Set<KnowledgeSource> sources, ReasoningService rs) { + Set<KnowledgeSource> sources, ReasonerComponent rs) { List<List<String>> exports = parser.getFunctionCalls().get("export"); if (exports == null) @@ -556,7 +554,7 @@ } private static void processCLIOptions(ComponentManager cm, ConfParser parser, - ReasoningService rs, LearningProblem lp) { + ReasonerComponent rs, LearningProblem lp) { // CLI options (i.e. options which are related to the CLI // user interface but not to one of the components) List<ConfFileOption> cliOptions = parser.getConfOptionsByPrefix("cli"); @@ -684,7 +682,7 @@ + Helper.prettyPrintNanoSeconds(initTime, false, false) + ")"); } - private static void printConclusions(ReasoningService rs, long algorithmDuration) { + private static void printConclusions(ReasonerComponent rs, long algorithmDuration) { if (rs.getNrOfRetrievals() > 0) { logger.info("number of retrievals: " + rs.getNrOfRetrievals()); logger.info("retrieval reasoning time: " @@ -731,7 +729,7 @@ } // performs a query - used for debugging learning examples - private static void processQueryMode(LearningProblem lp, ReasoningService rs) { + private static void processQueryMode(LearningProblem lp, ReasonerComponent rs) { logger.info("Entering query mode. Enter a concept for performing " + "retrieval or q to quit. Use brackets for complex expresssions," @@ -859,10 +857,6 @@ public ReasonerComponent getReasonerComponent() { return rc; } - - public ReasoningService getReasoningService() { - return rs; - } /** * @deprecated See ConfMapper. Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -354,8 +354,8 @@ } /** - * This method returns an instance of <code>ReasoningService</code>. The - * difference between <code>ReasoningService</code> and <code>ReasonerComponent</code> + * This method returns an instance of <code>ReasonerComponent</code>. The + * difference between <code>ReasonerComponent</code> and <code>ReasonerComponent</code> * is that the former delegates all calls to the latter and collects statistics * while doing this. This means that the reasoning service enables the * collection of query information, while the <code>ReasonerComponent</code> @@ -365,8 +365,8 @@ * @param reasoner A reasoner component. * @return The reasoning service encapsulating the reasoner. */ -// public ReasoningService reasoningService(ReasonerComponent reasoner) { -// return new ReasoningService(reasoner); +// public ReasonerComponent reasoningService(ReasonerComponent reasoner) { +// return new ReasonerComponent(reasoner); // } /** Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -54,7 +54,7 @@ * The reasoning service variable, which must be used by * all learning algorithm implementations. */ - protected ReasoningService reasoningService; + protected ReasonerComponent reasoner; /** * Each learning algorithm gets a learning problem and @@ -63,9 +63,9 @@ * @param reasoningService The reasoner connecting to the * underlying knowledge base. */ - public LearningAlgorithm(LearningProblem learningProblem, ReasoningService reasoningService) { + public LearningAlgorithm(LearningProblem learningProblem, ReasonerComponent reasoningService) { this.learningProblem = learningProblem; - this.reasoningService = reasoningService; + this.reasoner = reasoningService; } /** @@ -90,8 +90,8 @@ * indeed changes the reasoning service. * @param reasoningService The new reasoning service. */ - public void changeReasoningService(ReasoningService reasoningService) { - this.reasoningService = reasoningService; + public void changeReasonerComponent(ReasonerComponent reasoningService) { + this.reasoner = reasoningService; } /** @@ -253,7 +253,7 @@ // be in the search of the learning algorith, which leads to // unpredictable behaviour) Description d = ed.getDescription().clone(); - ConceptTransformation.replaceRange(d, reasoningService); + ConceptTransformation.replaceRange(d, reasoner); ed.setDescription(d); returnList.add(ed); Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -67,7 +67,7 @@ * indeed changes the reasoning service. * @param reasoner New reasoning service. */ - public void changeReasoningService(ReasonerComponent reasoner) { + public void changeReasonerComponent(ReasonerComponent reasoner) { this.reasoner = reasoner; } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -50,7 +50,7 @@ public ReasonerType getReasonerType(); // Methode, die Subsumptionhierarchie initialisiert (sollte nur einmal - // pro erstelltem ReasoningService bzw. Reasoner aufgerufen werden) + // pro erstelltem ReasonerComponent bzw. Reasoner aufgerufen werden) // => erstellt auch vereinfachte Sichten auf Subsumptionhierarchie // (siehe einfacher Traversal in Diplomarbeit) public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts); Modified: trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -24,7 +24,7 @@ import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; /** * automatically generated, do not edit manually. @@ -50,7 +50,7 @@ * @throws LearningProblemUnsupportedException see * @return BruteForceLearner **/ -public static BruteForceLearner getBruteForceLearner(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException{ +public static BruteForceLearner getBruteForceLearner(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException{ BruteForceLearner component = ComponentManager.getInstance().learningAlgorithm(BruteForceLearner.class, learningProblem, reasoningService); return component; } Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2008-11-10 11:00:23 UTC (rev 1500) +++ trunk/src/dl-learner/org/dllearner/core/configurators/ComponentFactory.java 2008-11-10 12:44:17 UTC (rev 1501) @@ -32,7 +32,7 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.ReasoningService; +import org.dllearner.core.ReasonerComponent; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; @@ -121,118 +121,118 @@ /** * @param positiveExamples positive examples * @param negativeExamples negative examples -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @return a component ready for initialization PosNegDefinitionLP **/ -public static PosNegDefinitionLP getPosNegDefinitionLP(ReasoningService reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { +public static PosNegDefinitionLP getPosNegDefinitionLP(ReasonerComponent reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { return PosNegDefinitionLPConfigurator.getPosNegDefinitionLP(reasoningService, positiveExamples, negativeExamples); } /** * @param positiveExamples positive examples * @param negativeExamples negative examples -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @return a component ready for initialization PosNegDefinitionLPStrict **/ -public static PosNegDefinitionLPStrict getPosNegDefinitionLPStrict(ReasoningService reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { +public static PosNegDefinitionLPStrict getPosNegDefinitionLPStrict(ReasonerComponent reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { return PosNegDefinitionLPStrictConfigurator.getPosNegDefinitionLPStrict(reasoningService, positiveExamples, negativeExamples); } /** * @param positiveExamples positive examples * @param negativeExamples negative examples -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @return a component ready for initialization PosNegInclusionLP **/ -public static PosNegInclusionLP getPosNegInclusionLP(ReasoningService reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { +public static PosNegInclusionLP getPosNegInclusionLP(ReasonerComponent reasoningService, Set<String> positiveExamples, Set<String> negativeExamples) { return PosNegInclusionLPConfigurator.getPosNegInclusionLP(reasoningService, positiveExamples, negativeExamples); } /** * @param positiveExamples positive examples -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @return a component ready for initialization PosOnlyDefinitionLP **/ -public static PosOnlyDefinitionLP getPosOnlyDefinitionLP(ReasoningService reasoningService, Set<String> positiveExamples) { +public static PosOnlyDefinitionLP getPosOnlyDefinitionLP(ReasonerComponent reasoningService, Set<String> positiveExamples) { return PosOnlyDefinitionLPConfigurator.getPosOnlyDefinitionLP(reasoningService, positiveExamples); } /** * @param positiveExamples positive examples -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @return a component ready for initialization PosOnlyInclusionLP **/ -public static PosOnlyInclusionLP getPosOnlyInclusionLP(ReasoningService reasoningService, Set<String> positiveExamples) { +public static PosOnlyInclusionLP getPosOnlyInclusionLP(ReasonerComponent reasoningService, Set<String> positiveExamples) { return PosOnlyInclusionLPConfigurator.getPosOnlyInclusionLP(reasoningService, positiveExamples); } /** * @param learningProblem see LearningProblem -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @throws LearningProblemUnsupportedException see * @return a component ready for initialization BruteForceLearner **/ -public static BruteForceLearner getBruteForceLearner(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException { +public static BruteForceLearner getBruteForceLearner(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { return BruteForceLearnerConfigurator.getBruteForceLearner(learningProblem, reasoningService); } /** * @param learningProblem see LearningProblem -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @throws LearningProblemUnsupportedException see * @return a component ready for initialization DBpediaNavigationSuggestor **/ -public static DBpediaNavigationSuggestor getDBpediaNavigationSuggestor(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException { +public static DBpediaNavigationSuggestor getDBpediaNavigationSuggestor(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { return DBpediaNavigationSuggestorConfigurator.getDBpediaNavigationSuggestor(learningProblem, reasoningService); } /** * @param learningProblem see LearningProblem -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @throws LearningProblemUnsupportedException see * @return a component ready for initialization RandomGuesser **/ -public static RandomGuesser getRandomGuesser(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException { +public static RandomGuesser getRandomGuesser(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { return RandomGuesserConfigurator.getRandomGuesser(learningProblem, reasoningService); } /** * @param learningProblem see LearningProblem -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @throws LearningProblemUnsupportedException see * @return a component ready for initialization SimpleSuggestionLearningAlgorithm **/ -public static SimpleSuggestionLearningAlgorithm getSimpleSuggestionLearningAlgorithm(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException { +public static SimpleSuggestionLearningAlgorithm getSimpleSuggestionLearningAlgorithm(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { return SimpleSuggestionLearningAlgorithmConfigurator.getSimpleSuggestionLearningAlgorithm(learningProblem, reasoningService); } /** * @param learningProblem see LearningProblem -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @throws LearningProblemUnsupportedException see * @return a component ready for initialization GP **/ -public static GP getGP(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException { +public static GP getGP(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedException { return GPConfigurator.getGP(learningProblem, reasoningService); } /** * @param learningProblem see LearningProblem -* @param reasoningService see ReasoningService +* @param reasoningService see ReasonerComponent * @throws LearningProblemUnsupportedException see * @return a component ready for initialization ExampleBasedROLComponent **/ -public static ExampleBasedROLComponent getExampleBasedROLComponent(LearningProblem learningProblem, ReasoningService reasoningService) throws LearningProblemUnsupportedException { +public static ExampleBasedROLComponent getExampleBasedROLComponent(LearningProblem learningProblem, ReasonerComponent reasoningService) throws LearningProblemUnsupportedExce... [truncated message content] |
From: <jen...@us...> - 2008-11-10 13:46:11
|
Revision: 1502 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1502&view=rev Author: jenslehmann Date: 2008-11-10 13:46:08 +0000 (Mon, 10 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN is still *broken*, please don't update if you want everything to work properly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java Modified: trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -33,6 +33,8 @@ * <li>queries for elements contained in the knowledge base (classes, properties, ...)</li> * <li>basic reasoning requests related to the knowledge base as a whole (e.g. consistency)</li> * </ul> + * (Many methods in this interface do not require reasoning algorithms, but rather + * return information about the knowledge base.) * * @author Jens Lehmann * Modified: trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -19,6 +19,11 @@ */ package org.dllearner.core; +import java.util.Set; + +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; + /** * Reasoning requests/queries related to individuals in the knowledge base. * @@ -27,4 +32,13 @@ */ public interface IndividualReasoner { + /** + * Returns types of an individual, i.e. those classes where the individual + * is instance of. For instance, the individual eric could have type Person. + * + * @param individual An individual in the knowledge base. + * @return Types this individual is instance of. + */ + public Set<NamedClass> getTypes(Individual individual); + } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -52,6 +52,23 @@ * In addition to calling the actual implementations of reasoning operations, * the class also collects statistical information, which can be queried. * + * Guidelines for extending the class: + * <ul> + * <li>add the needed method to the corresponding interface (currenty + * {@link BaseReasoner}, {@link SchemaReasoner}, {@link IndividualReasoner} + * exist)</li> + * <li>reasoning methods which need to be supported by all reasoners: + * create method() and methodImpl() here, where the former is an overridden, final + * method delegating to the latter abstract, protected method</li> + * <li>reasoning method, which do not need to be supported by all reasoners: + * create method() and methodImpl() as before, but this time methodImpl() is + * not abstract and throws a {@link ReasoningMethodUnsupportedException} + * </li> + * </ul> + * Note, that the method delegation is done to collect statistical information + * about reasoning performance, e.g. count how often certain methods were called + * and how long it took to execute them. + * * @author Jens Lehmann * */ @@ -171,7 +188,14 @@ } @Override - public boolean subsumes(Description superClass, Description subClass) { + public final Set<NamedClass> getTypes(Individual individual) { + return getTypesImpl(individual); + } + + protected abstract Set<NamedClass> getTypesImpl(Individual individual); + + @Override + public final boolean subsumes(Description superClass, Description subClass) { reasoningStartTimeTmp = System.nanoTime(); boolean result = false; try { @@ -883,10 +907,6 @@ throw new ReasoningMethodUnsupportedException(); } - public Set<NamedClass> getConceptsImpl(Individual i) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - public Description getDomainImpl(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -218,7 +218,7 @@ // start if (e.getSource() == runButton) { algorithmThread = new AlgorithmThread(); - config.getReasonerComponent().resetStatistics(); + config.getReasoner().resetStatistics(); algorithmThread.start(); // algorithmStartTime = System.nanoTime(); // algorithmThread. @@ -275,32 +275,32 @@ percent[0].setText("100%"); // update overall reasoning time - overallReasoningTime = config.getReasonerComponent().getOverallReasoningTimeNs(); + overallReasoningTime = config.getReasoner().getOverallReasoningTimeNs(); bar[1].update((double) overallReasoningTime / (double) algorithmRunTime); time[1].setText(makeTime(overallReasoningTime)); percent[1].setText(Percent(overallReasoningTime, algorithmRunTime)); - if (config.getReasonerComponent().getNrOfInstanceChecks() > 0) { - instanceCheckReasoningTime = config.getReasonerComponent() + if (config.getReasoner().getNrOfInstanceChecks() > 0) { + instanceCheckReasoningTime = config.getReasoner() .getInstanceCheckReasoningTimeNs(); - name[2].setText(names[2] + " (" + config.getReasonerComponent().getNrOfInstanceChecks() + name[2].setText(names[2] + " (" + config.getReasoner().getNrOfInstanceChecks() + ")"); bar[2].update((double) instanceCheckReasoningTime / (double) algorithmRunTime); time[2].setText(makeTime(instanceCheckReasoningTime)); percent[2].setText(Percent(instanceCheckReasoningTime, algorithmRunTime)); } - if (config.getReasonerComponent().getNrOfRetrievals() > 0) { - retrievalReasoningTime = config.getReasonerComponent().getRetrievalReasoningTimeNs(); - name[3].setText(names[3] + " (" + config.getReasonerComponent().getNrOfRetrievals() + if (config.getReasoner().getNrOfRetrievals() > 0) { + retrievalReasoningTime = config.getReasoner().getRetrievalReasoningTimeNs(); + name[3].setText(names[3] + " (" + config.getReasoner().getNrOfRetrievals() + ")"); bar[3].update((double) retrievalReasoningTime / (double) algorithmRunTime); time[3].setText(makeTime(retrievalReasoningTime)); percent[3].setText(Percent(retrievalReasoningTime, algorithmRunTime)); } - if (config.getReasonerComponent().getNrOfSubsumptionChecks() > 0) { - subsumptionReasoningTime = config.getReasonerComponent().getSubsumptionReasoningTimeNs(); + if (config.getReasoner().getNrOfSubsumptionChecks() > 0) { + subsumptionReasoningTime = config.getReasoner().getSubsumptionReasoningTimeNs(); name[4].setText(names[4] + " (" - + config.getReasonerComponent().getNrOfSubsumptionChecks() + ")"); + + config.getReasoner().getNrOfSubsumptionChecks() + ")"); bar[4].update((double) subsumptionReasoningTime / (double) algorithmRunTime); time[4].setText(makeTime(subsumptionReasoningTime)); percent[4].setText(Percent(subsumptionReasoningTime, algorithmRunTime)); @@ -378,8 +378,8 @@ } private String getSolutionString(List<EvaluatedDescription> solutions) { - String baseURI = config.getReasonerComponent().getBaseURI(); - Map<String,String> prefixes = config.getReasonerComponent().getPrefixes(); + String baseURI = config.getReasoner().getBaseURI(); + Map<String,String> prefixes = config.getReasoner().getPrefixes(); String string = ""; for (EvaluatedDescription d : solutions) { string += "accuracy: " + (df.format(d.getAccuracy()*100)) + "%: \t" Modified: trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -81,7 +81,7 @@ PosNegDefinitionLP lp = (PosNegDefinitionLP) config.getLearningProblem(); Set<String> posExamples = lp.getConfigurator().getPositiveExamples(); Set<String> negExamples = lp.getConfigurator().getNegativeExamples(); - String baseURI = config.getReasonerComponent().getBaseURI(); + String baseURI = config.getReasoner().getBaseURI(); int nrOfPositiveExamples = posExamples.size(); int nrOfNegativeExamples = negExamples.size(); Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -213,7 +213,7 @@ if (configOption.getName().equalsIgnoreCase("positiveExamples") || configOption.getName().equalsIgnoreCase("negativeExamples")) { // fill lists - Set<Individual> individualsSet = config.getReasonerComponent() + Set<Individual> individualsSet = config.getReasoner() .getIndividuals(); if(individualsSet != null) { LinkedList<Individual> individuals = new LinkedList<Individual>( @@ -233,7 +233,7 @@ if (configOption.getName().equalsIgnoreCase("allowedConcepts") || configOption.getName().equalsIgnoreCase("ignoredConcepts")) { // fill lists - Set<NamedClass> atomicsSet = config.getReasonerComponent() + Set<NamedClass> atomicsSet = config.getReasoner() .getNamedClasses(); if(atomicsSet != null) { LinkedList<NamedClass> atomicConcepts = new LinkedList<NamedClass>( @@ -247,7 +247,7 @@ if (configOption.getName().equalsIgnoreCase("allowedRoles") || configOption.getName().equalsIgnoreCase("ignoredRoles")) { // fill lists - Set<ObjectProperty> atomicsSet = config.getReasonerComponent() + Set<ObjectProperty> atomicsSet = config.getReasoner() .getObjectProperties(); if(atomicsSet != null) { LinkedList<ObjectProperty> atomicRoles = new LinkedList<ObjectProperty>( Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -399,7 +399,7 @@ } @Override - public boolean subsumes(Description superConcept, Description subConcept) { + public boolean subsumesImpl(Description superConcept, Description subConcept) { // System.out.println("subsumes(" + superConcept + "," + subConcept + // ")"); String subsumesDIG = asksPrefix; @@ -671,7 +671,7 @@ // ToDo: gibt momentan nur einen Wert bei äquivalenten Klassen aus @Override - public Set<NamedClass> getConcepts(Individual individual) { + public Set<NamedClass> getTypesImpl(Individual individual) { String typesDIG = asksPrefix; typesDIG += "<types id=\"query_types\">"; typesDIG += "<individual name=\"" + individual.getName() + "\" />"; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -593,7 +593,7 @@ } @Override - public boolean subsumes(Description superConcept, Description subConcept) { + public boolean subsumesImpl(Description superConcept, Description subConcept) { // Negation neg = new Negation(subConcept); // Intersection c = new Intersection(neg,superConcept); // return fastRetrieval.calculateSets(c).getPosSet().isEmpty(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -127,7 +127,7 @@ // C \sqsubseteq D is rewritten to a retrieval for \not C \sqcap D @Override - public boolean subsumes(Description superConcept, Description subConcept) { + public boolean subsumesImpl(Description superConcept, Description subConcept) { // Negation neg = new Negation(subConcept); // Intersection c = new Intersection(neg,superConcept); // return fastRetrieval.calculateSets(c).getPosSet().isEmpty(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -504,7 +504,7 @@ } @Override - public boolean subsumes(Description superConcept, Description subConcept) { + public boolean subsumesImpl(Description superConcept, Description subConcept) { try { return reasoner.isSubClassOf(OWLAPIDescriptionConvertVisitor.getOWLDescription(subConcept), OWLAPIDescriptionConvertVisitor.getOWLDescription(superConcept)); } catch (OWLReasonerException e) { @@ -612,7 +612,7 @@ } @Override - public Set<NamedClass> getConcepts(Individual individual) { + public Set<NamedClass> getTypesImpl(Individual individual) { Set<Set<OWLClass>> result = null; try { result = reasoner.getTypes(factory.getOWLIndividual(URI.create(individual.getName())),false); @@ -766,7 +766,7 @@ } @Override - public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) { + public Map<Individual, SortedSet<Constant>> getDatatypeMembersImpl(DatatypeProperty datatypeProperty) { OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); Map<Individual, SortedSet<Constant>> map = new TreeMap<Individual, SortedSet<Constant>>(); for(Individual i : individuals) { @@ -1037,7 +1037,7 @@ } @Override - public Set<NamedClass> getInconsistentClasses(){ + public Set<NamedClass> getInconsistentClassesImpl(){ Set<NamedClass> concepts = new HashSet<NamedClass>(); try { Modified: trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/tools/ore/StatsPanel.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -100,7 +100,7 @@ classPane = new JXTaskPane(); classPane.setTitle("Classes"); - oldClasses = ore.getOwlReasoner().getConcepts(ind); + oldClasses = ore.getOwlReasoner().getTypes(ind); for(NamedClass nc : oldClasses){ classPane.add(new JLabel(nc.toManchesterSyntaxString(baseURI, prefixes))); } @@ -154,7 +154,7 @@ classPane.removeAll(); Set<String> newClassesString = new HashSet<String>(); - for (NamedClass nc : ore.getOwlReasoner().getConcepts(ind)){ + for (NamedClass nc : ore.getOwlReasoner().getTypes(ind)){ newClassesString.add(nc.toManchesterSyntaxString(baseURI, prefixes)); } Set<String> oldClassesString = new HashSet<String>(); Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-11-10 12:44:17 UTC (rev 1501) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-11-10 13:46:08 UTC (rev 1502) @@ -758,7 +758,7 @@ if (positiveExamples != null) { if (positiveExamples.toString().contains(indi2.toString())) { // if yes then get the concepts of this individuals - Set<NamedClass> concept = reasoner.getConcepts(indi2); + Set<NamedClass> concept = reasoner.getTypes(indi2); // adds all concepts to old concept OWLAPI for (Iterator<NamedClass> k = concept.iterator(); k .hasNext();) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-10 16:54:06
|
Revision: 1503 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1503&view=rev Author: jenslehmann Date: 2008-11-10 16:53:59 +0000 (Mon, 10 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN partially broken Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.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/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/ReasonerType.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/scripts/NewSample.java trunk/src/dl-learner/org/dllearner/scripts/PaperStatistics.java trunk/src/dl-learner/org/dllearner/scripts/Sample.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifier.java trunk/src/dl-learner/org/dllearner/tools/ore/SPARQLTest.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyClassRewriter.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/components/ trunk/src/dl-learner/org/dllearner/utilities/components/ComponentCombo.java trunk/src/dl-learner/org/dllearner/utilities/components/ReasonerComponentFactory.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIConverter.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIDescriptionConvertVisitor.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/scripts/DumbLPFinder.java trunk/src/dl-learner/org/dllearner/utilities/learn/ComponentCombo.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnOWLFile.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparqlold.java trunk/src/dl-learner/org/dllearner/utilities/learn/SPARQLExtractionEvaluation.java trunk/src/dl-learner/org/dllearner/utilities/learn/SPARQLMassLearning.java trunk/src/dl-learner/org/dllearner/utilities/owl/ReasoningServiceFactory.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -30,7 +30,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.CommonConfigOptions; import org.dllearner.core.config.ConfigEntry; Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -29,7 +29,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigOptions; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -34,7 +34,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigMappings; @@ -358,13 +357,13 @@ // prepare subsumption and role hierarchies, because they are needed // during the run of the algorithm - reasoner.prepareSubsumptionHierarchy(usedConcepts); +// reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - reasoner.prepareRoleHierarchy(usedRoles); +// reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary - if(reasoner.hasDatatypeSupport()) - reasoner.prepareDatatypePropertyHierarchy(); +// if(reasoner.hasDatatypeSupport()) +// reasoner.prepareDatatypePropertyHierarchy(); // create a refinement operator and pass all configuration // variables to it Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -36,7 +36,6 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -18,7 +18,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigMappings; @@ -373,10 +372,10 @@ // prepare subsumption and role hierarchies, because they are needed // during the run of the algorithm - reasoner.prepareSubsumptionHierarchy(usedConcepts); +// reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); - reasoner.prepareRoleHierarchy(usedRoles); +// reasoner.prepareRoleHierarchy(usedRoles); } public static String getName() { Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -57,7 +57,6 @@ import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.ConfigEntry; Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -25,7 +25,7 @@ import org.dllearner.core.owl.Individual; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.ScoreTwoValued; -import org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLAPIRenderers; import org.json.JSONArray; import org.json.JSONException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -64,6 +64,8 @@ * create method() and methodImpl() as before, but this time methodImpl() is * not abstract and throws a {@link ReasoningMethodUnsupportedException} * </li> + * <li>a few very basic methods (where we do not care about statistics) + * do not have an "Impl" variant, e.g. getting all named classes of a KB</li> * </ul> * Note, that the method delegation is done to collect statistical information * about reasoning performance, e.g. count how often certain methods were called @@ -189,10 +191,18 @@ @Override public final Set<NamedClass> getTypes(Individual individual) { - return getTypesImpl(individual); + Set<NamedClass> types = null; + try { + types = getTypesImpl(individual); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + return types; } - protected abstract Set<NamedClass> getTypesImpl(Individual individual); + protected Set<NamedClass> getTypesImpl(Individual individual) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException("Reasoner does not support to determine type of individual."); + } @Override public final boolean subsumes(Description superClass, Description subClass) { @@ -210,7 +220,8 @@ return result; } - public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) { + @Override + public final Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) { reasoningStartTimeTmp = System.nanoTime(); Set<Description> result = null; try { Modified: trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -33,8 +33,8 @@ public boolean subsumes(Description superConcept, Description subConcept); - public Set<Description> subsumes(Description superConcept, Set<Description> subConcepts); + //public Set<Description> subsumes(Description superConcept, Set<Description> subConcepts); public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept); - + } Modified: trunk/src/dl-learner/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/examples/KRKModular.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -22,7 +22,6 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.owl.ClassAssertionAxiom; import org.dllearner.core.owl.Description; Modified: trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -46,7 +46,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.kb.OWLFile; @@ -151,8 +150,8 @@ // TODO Auto-generated catch block e1.printStackTrace(); } - rs = cm.reasoningService(reasoner); - Set<Individual> individualsSet = rs.getIndividuals(); +// rs = cm.reasoningService(reasoner); + Set<Individual> individualsSet = reasoner.getIndividuals(); individuals = new LinkedList<Individual>(individualsSet); DefaultListModel listModel = new DefaultListModel(); Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -38,7 +38,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.OWLAPIAxiomConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLOntologyCreationException; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -25,7 +25,6 @@ import java.util.TreeSet; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.configurators.PosNegDefinitionLPConfigurator; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -24,7 +24,6 @@ import java.util.TreeSet; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.ConfigEntry; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -23,7 +23,6 @@ import java.util.SortedSet; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.configurators.PosNegInclusionLPConfigurator; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegLP.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -26,7 +26,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.CommonConfigMappings; import org.dllearner.core.config.CommonConfigOptions; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -20,7 +20,6 @@ package org.dllearner.learningproblems; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.configurators.PosOnlyDefinitionLPConfigurator; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -20,7 +20,6 @@ package org.dllearner.learningproblems; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -26,7 +26,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.config.CommonConfigMappings; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -268,7 +268,6 @@ * * TODO Does not yet take ignored roles into account. */ - @Override public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( roleComparator); @@ -289,7 +288,7 @@ // bei null bleibt; bei der aktuellen Implementierung ist der parent-Link // nicht immer null, was bei GP negative Auswirkungen haben könnte // Update: wird durch klonen innerhalb der GP-Operationen erledigt - public Set<NamedClass> getAtomicConcepts() { + public Set<NamedClass> getNamedClasses() { /* * if(Config.algorithm == Config.Algorithm.GP || Config.algorithm == * Config.Algorithm.HYBRID_GP) { Set<AtomicConcept> returnSet = new @@ -343,7 +342,7 @@ return atomicConcepts; } - public Set<ObjectProperty> getAtomicRoles() { + public Set<ObjectProperty> getObjectProperties() { return atomicRoles; } @@ -394,6 +393,7 @@ return digIndividuals; } + @Override public ReasonerType getReasonerType() { return ReasonerType.DIG; } @@ -412,7 +412,7 @@ } @Override - public Set<Description> subsumes(Description superConcept, Set<Description> subConcepts) { + public Set<Description> subsumesImpl(Description superConcept, Set<Description> subConcepts) { String subsumesDIG = asksPrefix; int id = 0; // ID-Konzept-Zuordnung speichern, da bei der Antwort nur die IDs @@ -439,7 +439,7 @@ } @Override - public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) { + public Set<Description> subsumesImpl(Set<Description> superConcepts, Description subConcept) { String subsumesDIG = asksPrefix; int id = 0; Map<String, Description> queryMap = new HashMap<String, Description>(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -182,13 +182,13 @@ rc.getConfigurator().setReasonerType(configurator.getReasonerType()); rc.init(); - try { - atomicConcepts = rc.getAtomicConcepts(); +// try { + atomicConcepts = rc.getNamedClasses(); datatypeProperties = rc.getDatatypeProperties(); booleanDatatypeProperties = rc.getBooleanDatatypeProperties(); doubleDatatypeProperties = rc.getDoubleDatatypeProperties(); intDatatypeProperties = rc.getIntDatatypeProperties(); - atomicRoles = rc.getAtomicRoles(); + atomicRoles = rc.getObjectProperties(); individuals = rc.getIndividuals(); // rs = new ReasonerComponent(rc); @@ -201,7 +201,7 @@ logger.debug("dematerialising concepts"); - for (NamedClass atomicConcept : rc.getAtomicConcepts()) { + for (NamedClass atomicConcept : rc.getNamedClasses()) { SortedSet<Individual> pos = rc.retrieval(atomicConcept); classInstancesPos.put(atomicConcept, pos); @@ -244,10 +244,10 @@ long dematDuration = System.currentTimeMillis() - dematStartTime; logger.debug("TBox dematerialised in " + dematDuration + " ms"); - } catch (ReasoningMethodUnsupportedException e) { - throw new ComponentInitException( - "Underlying reasoner does not support all necessary reasoning methods.", e); - } +// } catch (ReasoningMethodUnsupportedException e) { +// throw new ComponentInitException( +// "Underlying reasoner does not support all necessary reasoning methods.", e); +// } } @Override @@ -562,8 +562,7 @@ * * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) */ - @Override - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { + public void prepareSubsumptionHierarchyImpl(Set<NamedClass> allowedConcepts) { rc.prepareSubsumptionHierarchy(allowedConcepts); } @@ -573,7 +572,7 @@ } @Override - public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { + public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) { rc.prepareRoleHierarchy(allowedRoles); } @@ -583,8 +582,8 @@ } @Override - public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { - rc.prepareDatatypePropertyHierarchy(allowedRoles); + public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles) { + rc.prepareDatatypePropertyHierarchyImpl(allowedRoles); } @Override @@ -617,7 +616,7 @@ cm.applyConfigEntry(owl, "url", owlFile); owl.init(); ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, owl); - cm.reasoningService(reasoner); +// cm.reasoningService(reasoner); reasoner.init(); KBParser.internalNamespace = "http://example.com/father#"; @@ -698,4 +697,12 @@ return true; } + /* (non-Javadoc) + * @see org.dllearner.core.ReasonerComponent#getTypesImpl(org.dllearner.core.owl.Individual) + */ + @Override + protected Set<NamedClass> getTypesImpl(Individual individual) { + return rc.getTypesImpl(individual); + } + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -10,7 +10,6 @@ import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; -import org.dllearner.core.ReasonerComponent; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.configurators.ComponentFactory; @@ -89,6 +88,7 @@ } + @Override public ReasonerType getReasonerType() { return ReasonerType.FAST_RETRIEVAL; } @@ -109,11 +109,12 @@ return Helper.getIndividualSet(fastRetrieval.calculateSets(concept).getPosSet()); } - public Set<NamedClass> getAtomicConcepts() { + public Set<NamedClass> getNamedClasses() { return atomicConcepts; } - public Set<ObjectProperty> getAtomicRoles() { + @Override + public Set<ObjectProperty> getObjectProperties() { return atomicRoles; } @@ -134,19 +135,19 @@ return rs.subsumes(superConcept, subConcept); } - @Override - public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { - rs.prepareRoleHierarchy(allowedRoles); - } +// @Override +// public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { +// rs.prepareRoleHierarchy(allowedRoles); +// } @Override public ObjectPropertyHierarchy getRoleHierarchy() { return rs.getRoleHierarchy(); } - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { - rs.prepareSubsumptionHierarchy(allowedConcepts); - } +// public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { +// rs.prepareSubsumptionHierarchy(allowedConcepts); +// } @Override public SubsumptionHierarchy getSubsumptionHierarchy() { Deleted: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -1,325 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.reasoning; - -import java.net.URI; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.AxiomVisitor; -import org.dllearner.core.owl.BooleanDatatypePropertyAssertion; -import org.dllearner.core.owl.ClassAssertionAxiom; -import org.dllearner.core.owl.DataRange; -import org.dllearner.core.owl.Datatype; -import org.dllearner.core.owl.DatatypePropertyDomainAxiom; -import org.dllearner.core.owl.DatatypePropertyRangeAxiom; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.DifferentIndividualsAxiom; -import org.dllearner.core.owl.DisjointClassesAxiom; -import org.dllearner.core.owl.DoubleDatatypePropertyAssertion; -import org.dllearner.core.owl.EquivalentClassesAxiom; -import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.InverseObjectPropertyAxiom; -import org.dllearner.core.owl.KB; -import org.dllearner.core.owl.ObjectPropertyAssertion; -import org.dllearner.core.owl.ObjectPropertyDomainAxiom; -import org.dllearner.core.owl.ObjectPropertyRangeAxiom; -import org.dllearner.core.owl.SubClassAxiom; -import org.dllearner.core.owl.SubObjectPropertyAxiom; -import org.dllearner.core.owl.SymmetricObjectPropertyAxiom; -import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; -import org.semanticweb.owl.model.AddAxiom; -import org.semanticweb.owl.model.OWLAxiom; -import org.semanticweb.owl.model.OWLDataFactory; -import org.semanticweb.owl.model.OWLDataProperty; -import org.semanticweb.owl.model.OWLDataType; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLObjectProperty; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLOntologyChangeException; -import org.semanticweb.owl.model.OWLOntologyManager; -import org.semanticweb.owl.model.OWLTypedConstant; -import org.semanticweb.owl.vocab.XSDVocabulary; - -// static import for easy access to the description converter -import static org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor.getOWLDescription; - -/** - * A converter from DL-Learner axioms to OWL API axioms based on the visitor - * pattern. - * - * TODO: Investigate whether OWLOntologyManager and OWLOntology should be - * removed as parameters. It would be natural to have a DL-Learner KB as input - * and an OWL API OWLOntology as output. - * - * @author Jens Lehmann - * - */ -public class OWLAPIAxiomConvertVisitor implements AxiomVisitor { - - OWLDataFactory factory; - private OWLOntology ontology; - private OWLOntologyManager manager; - - public OWLAPIAxiomConvertVisitor(OWLOntologyManager manager, OWLOntology ontology, KB kb) { - this.manager = manager; - this.ontology = ontology; - factory = manager.getOWLDataFactory(); - } - - public static void fillOWLOntology(OWLOntologyManager manager, OWLOntology ontology, KB kb) { - OWLAPIAxiomConvertVisitor converter = new OWLAPIAxiomConvertVisitor(manager, ontology, kb); - for(Axiom axiom : kb.getTbox()) - axiom.accept(converter); - for(Axiom axiom : kb.getRbox()) - axiom.accept(converter); - for(Axiom axiom : kb.getAbox()) - axiom.accept(converter); - } - - // convencience function for adding an axiom to the ontology - private void addAxiom(OWLAxiom axiom) { - AddAxiom addAxiom = new AddAxiom(ontology, axiom); - try { - manager.applyChange(addAxiom); - } catch (OWLOntologyChangeException e) { - e.printStackTrace(); - } - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.dl.AxiomVisitor#visit(org.dllearner.core.dl.ObjectPropertyAssertion) - */ - public void visit(ObjectPropertyAssertion axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty(URI - .create(((ObjectPropertyAssertion) axiom).getRole().getName())); - OWLIndividual i1 = factory.getOWLIndividual(URI.create(((ObjectPropertyAssertion) axiom) - .getIndividual1().getName())); - OWLIndividual i2 = factory.getOWLIndividual(URI.create(((ObjectPropertyAssertion) axiom) - .getIndividual2().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLObjectPropertyAssertionAxiom(i1, role, i2); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.AssertionalAxiomVisitor#visit(org.dllearner.core.owl.ClassAssertionAxiom) - */ - public void visit(ClassAssertionAxiom axiom) { - OWLDescription d = getOWLDescription(axiom.getConcept()); - OWLIndividual i = factory.getOWLIndividual(URI.create(((ClassAssertionAxiom) axiom) - .getIndividual().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLClassAssertionAxiom(i, d); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.AssertionalAxiomVisitor#visit(org.dllearner.core.owl.DoubleDatatypePropertyAssertion) - */ - public void visit(DoubleDatatypePropertyAssertion axiom) { - OWLIndividual i = factory.getOWLIndividual(URI.create(axiom.getIndividual().getName())); - OWLDataProperty dp = factory.getOWLDataProperty(URI.create(axiom.getDatatypeProperty().getName())); - Double value = axiom.getValue(); - OWLDataType doubleType = factory.getOWLDataType(XSDVocabulary.DOUBLE.getURI()); - OWLTypedConstant valueConstant = factory.getOWLTypedConstant(value.toString(), doubleType); - OWLAxiom axiomOWLAPI = factory.getOWLDataPropertyAssertionAxiom(i, dp, valueConstant); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.AssertionalAxiomVisitor#visit(org.dllearner.core.owl.BooleanDatatypePropertyAssertion) - */ - public void visit(BooleanDatatypePropertyAssertion axiom) { - OWLIndividual i = factory.getOWLIndividual(URI.create(axiom.getIndividual().getName())); - OWLDataProperty dp = factory.getOWLDataProperty(URI.create(axiom.getDatatypeProperty().getName())); - Boolean value = axiom.getValue(); - OWLDataType booleanType = factory.getOWLDataType(XSDVocabulary.BOOLEAN.getURI()); - OWLTypedConstant valueConstant = factory.getOWLTypedConstant(value.toString(), booleanType); - OWLAxiom axiomOWLAPI = factory.getOWLDataPropertyAssertionAxiom(i, dp, valueConstant); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.FunctionalObjectPropertyAxiom) - */ - public void visit(FunctionalObjectPropertyAxiom axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(((FunctionalObjectPropertyAxiom) axiom).getRole().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLFunctionalObjectPropertyAxiom(role); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.InverseObjectPropertyAxiom) - */ - public void visit(InverseObjectPropertyAxiom axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(((InverseObjectPropertyAxiom) axiom).getRole().getName())); - OWLObjectProperty inverseRole = factory.getOWLObjectProperty( - URI.create(((InverseObjectPropertyAxiom) axiom).getInverseRole().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLInverseObjectPropertiesAxiom(role, inverseRole); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.SymmetricObjectPropertyAxiom) - */ - public void visit(SymmetricObjectPropertyAxiom axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(((SymmetricObjectPropertyAxiom) axiom).getRole().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLSymmetricObjectPropertyAxiom(role); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.TransitiveObjectPropertyAxiom) - */ - public void visit(TransitiveObjectPropertyAxiom axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(axiom.getRole().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLTransitiveObjectPropertyAxiom(role); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.SubObjectPropertyAxiom) - */ - public void visit(SubObjectPropertyAxiom axiom) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(((SubObjectPropertyAxiom) axiom).getRole().getName())); - OWLObjectProperty subRole = factory.getOWLObjectProperty( - URI.create(((SubObjectPropertyAxiom) axiom).getSubRole().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLSubObjectPropertyAxiom(subRole, role); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.TerminologicalAxiomVisitor#visit(org.dllearner.core.owl.EquivalentClassesAxiom) - */ - public void visit(EquivalentClassesAxiom axiom) { - OWLDescription d1 = getOWLDescription(axiom.getConcept1()); - OWLDescription d2 = getOWLDescription(axiom.getConcept2()); - Set<OWLDescription> ds = new HashSet<OWLDescription>(); - ds.add(d1); - ds.add(d2); - OWLAxiom axiomOWLAPI = factory.getOWLEquivalentClassesAxiom(ds); - addAxiom(axiomOWLAPI); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.owl.TerminologicalAxiomVisitor#visit(org.dllearner.core.owl.SubClassAxiom) - */ - public void visit(SubClassAxiom axiom) { - OWLDescription d1 = getOWLDescription(axiom.getSubConcept()); - OWLDescription d2 = getOWLDescription(axiom.getSuperConcept()); - Set<OWLDescription> ds = new HashSet<OWLDescription>(); - ds.add(d1); - ds.add(d2); - OWLAxiom axiomOWLAPI = factory.getOWLSubClassAxiom(d1,d2); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.DatatypePropertyDomainAxiom) - */ - public void visit(DatatypePropertyDomainAxiom datatypePropertyDomainAxiom) { - OWLDescription d = getOWLDescription(datatypePropertyDomainAxiom.getDomain()); - OWLDataProperty dp = factory.getOWLDataProperty(URI.create(datatypePropertyDomainAxiom.getProperty().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLDataPropertyDomainAxiom(dp, d); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.ObjectPropertyDomainAxiom) - */ - public void visit(ObjectPropertyDomainAxiom objectPropertyDomainAxiom) { - OWLDescription d = getOWLDescription(objectPropertyDomainAxiom.getDomain()); - OWLObjectProperty op = factory.getOWLObjectProperty(URI.create(objectPropertyDomainAxiom.getProperty().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLObjectPropertyDomainAxiom(op, d); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.DatatypePropertyRangeAxiom) - */ - public void visit(DatatypePropertyRangeAxiom axiom) { - DataRange dr = axiom.getRange(); - Datatype dt = (Datatype) dr; - OWLDataType odt = factory.getOWLDataType(dt.getURI()); - OWLDataProperty dp = factory.getOWLDataProperty(URI.create(axiom.getProperty().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLDataPropertyRangeAxiom(dp, odt); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.PropertyAxiomVisitor#visit(org.dllearner.core.owl.ObjectPropertyRangeAxiom) - */ - public void visit(ObjectPropertyRangeAxiom axiom) { - OWLDescription d = getOWLDescription(axiom.getRange()); - OWLObjectProperty op = factory.getOWLObjectProperty(URI.create(axiom.getProperty().getName())); - OWLAxiom axiomOWLAPI = factory.getOWLObjectPropertyRangeAxiom(op, d); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.AssertionalAxiomVisitor#visit(org.dllearner.core.owl.DifferentIndividualsAxiom) - */ - public void visit(DifferentIndividualsAxiom axiom) { - Set<Individual> individuals = axiom.getIndividuals(); - Set<OWLIndividual> owlAPIIndividuals = new HashSet<OWLIndividual>(); - for(Individual individual : individuals) - owlAPIIndividuals.add(factory.getOWLIndividual(URI.create(individual.getName()))); - OWLAxiom axiomOWLAPI = factory.getOWLDifferentIndividualsAxiom(owlAPIIndividuals); - addAxiom(axiomOWLAPI); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.TerminologicalAxiomVisitor#visit(org.dllearner.core.owl.DisjointClassesAxiom) - */ - public void visit(DisjointClassesAxiom axiom) { - Set<Description> descriptions = axiom.getDescriptions(); - Set<OWLDescription> owlAPIDescriptions = new HashSet<OWLDescription>(); - for(Description description : descriptions) - owlAPIDescriptions.add(getOWLDescription(description)); - OWLAxiom axiomOWLAPI = factory.getOWLDisjointClassesAxiom(owlAPIDescriptions); - addAxiom(axiomOWLAPI); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -1,361 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.reasoning; - -import java.net.URI; -import java.util.HashSet; -import java.util.Set; -import java.util.Stack; - -import org.dllearner.algorithms.gp.ADC; -import org.dllearner.core.owl.Constant; -import org.dllearner.core.owl.Datatype; -import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; -import org.dllearner.core.owl.DatatypeMaxCardinalityRestriction; -import org.dllearner.core.owl.DatatypeMinCardinalityRestriction; -import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.DatatypeSomeRestriction; -import org.dllearner.core.owl.DatatypeValueRestriction; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.DescriptionVisitor; -import org.dllearner.core.owl.DoubleMinValue; -import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Negation; -import org.dllearner.core.owl.Nothing; -import org.dllearner.core.owl.ObjectAllRestriction; -import org.dllearner.core.owl.ObjectExactCardinalityRestriction; -import org.dllearner.core.owl.ObjectMaxCardinalityRestriction; -import org.dllearner.core.owl.ObjectMinCardinalityRestriction; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.ObjectValueRestriction; -import org.dllearner.core.owl.SimpleDoubleDataRange; -import org.dllearner.core.owl.Thing; -import org.dllearner.core.owl.TypedConstant; -import org.dllearner.core.owl.Union; -import org.dllearner.core.owl.UntypedConstant; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.model.OWLConstant; -import org.semanticweb.owl.model.OWLDataFactory; -import org.semanticweb.owl.model.OWLDataProperty; -import org.semanticweb.owl.model.OWLDataRange; -import org.semanticweb.owl.model.OWLDataType; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLObjectProperty; -import org.semanticweb.owl.model.OWLTypedConstant; -import org.semanticweb.owl.vocab.OWLRestrictedDataRangeFacetVocabulary; -import org.semanticweb.owl.vocab.XSDVocabulary; - -/** - * Converter from DL-Learner descriptions to OWL API descriptions based - * on the visitor pattern. - * - * @author Jens Lehmann - * - */ -public class OWLAPIDescriptionConvertVisitor implements DescriptionVisitor { - - // private OWLDescription description; - private Stack<OWLDescription> stack = new Stack<OWLDescription>(); - - private OWLDataFactory factory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); - - public OWLDescription getOWLDescription() { - return stack.pop(); - } - - /** - * Converts a DL-Learner description into an OWL API decription. - * @param description DL-Learner description. - * @return Corresponding OWL API description. - */ - public static OWLDescription getOWLDescription(Description description) { - OWLAPIDescriptionConvertVisitor converter = new OWLAPIDescriptionConvertVisitor(); - description.accept(converter); - return converter.getOWLDescription(); - } - - /** - * Used for testing the OWL API converter. - * - * @param args - */ - public static void main(String[] args) { - try { - Description d = KBParser.parseConcept("(male AND (rich OR NOT stupid))"); - OWLDescription od = OWLAPIDescriptionConvertVisitor.getOWLDescription(d); - System.out.println(d); - System.out.println(od); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.Negation) - */ - public void visit(Negation description) { - description.getChild(0).accept(this); - OWLDescription d = stack.pop(); - stack.push(factory.getOWLObjectComplementOf(d)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectAllRestriction) - */ - public void visit(ObjectAllRestriction description) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(description.getRole().getName())); - description.getChild(0).accept(this); - OWLDescription d = stack.pop(); - stack.push(factory.getOWLObjectAllRestriction(role, d)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectSomeRestriction) - */ - public void visit(ObjectSomeRestriction description) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(description.getRole().getName())); - description.getChild(0).accept(this); - OWLDescription d = stack.pop(); - stack.push(factory.getOWLObjectSomeRestriction(role, d)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.Nothing) - */ - public void visit(Nothing description) { - stack.push(factory.getOWLNothing()); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.Thing) - */ - public void visit(Thing description) { - stack.push(factory.getOWLThing()); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.Intersection) - */ - public void visit(Intersection description) { - Set<OWLDescription> descriptions = new HashSet<OWLDescription>(); - for(Description child : description.getChildren()) { - child.accept(this); - descriptions.add(stack.pop()); - } - stack.push(factory.getOWLObjectIntersectionOf(descriptions)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.Union) - */ - public void visit(Union description) { - Set<OWLDescription> descriptions = new HashSet<OWLDescription>(); - for(Description child : description.getChildren()) { - child.accept(this); - descriptions.add(stack.pop()); - } - stack.push(factory.getOWLObjectUnionOf(descriptions)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectMinCardinalityRestriction) - */ - public void visit(ObjectMinCardinalityRestriction description) { - // TODO Taken from ObjectSomeRestriction above, hope its correct - //throw new Error("OWLAPIDescriptionConverter: not implemented"); - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(description.getRole().getName())); - description.getChild(0).accept(this); - OWLDescription d = stack.pop(); - int minmax = description.getCardinality(); - stack.push(factory.getOWLObjectMinCardinalityRestriction(role, minmax, d)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectExactCardinalityRestriction) - */ - public void visit(ObjectExactCardinalityRestriction description) { - // TODO Taken from ObjectSomeRestriction above, hope its correct - //throw new Error("OWLAPIDescriptionConverter: not implemented"); - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(description.getRole().getName())); - description.getChild(0).accept(this); - OWLDescription d = stack.pop(); - int minmax = description.getCardinality(); - stack.push(factory.getOWLObjectExactCardinalityRestriction(role, minmax, d)); - - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectMaxCardinalityRestriction) - */ - public void visit(ObjectMaxCardinalityRestriction description) { - // TODO Taken from ObjectSomeRestriction above, hope its correct - //throw new Error("OWLAPIDescriptionConverter: not implemented"); - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(description.getRole().getName())); - description.getChild(0).accept(this); - OWLDescription d = stack.pop(); - int minmax = description.getCardinality(); - stack.push(factory.getOWLObjectMaxCardinalityRestriction(role, minmax, d)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectValueRestriction) - */ - public void visit(ObjectValueRestriction description) { - OWLObjectProperty role = factory.getOWLObjectProperty( - URI.create(((ObjectProperty)description.getRestrictedPropertyExpression()).getName())); - OWLIndividual i = factory.getOWLIndividual(URI.create(description.getIndividual().getName())); - stack.push(factory.getOWLObjectValueRestriction(role, i)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeValueRestriction) - */ - public void visit(DatatypeValueRestriction description) { - // convert OWL constant to OWL API constant - Constant c = description.getValue(); - OWLConstant constant = convertConstant(c); - /* - if(c instanceof TypedConstant) { - Datatype dt = ((TypedConstant)c).getDatatype(); - OWLDataType odt = convertDatatype(dt); - constant = factory.getOWLTypedConstant(c.getLiteral(), odt); - } else { - UntypedConstant uc = (UntypedConstant) c; - if(uc.hasLang()) { - constant = factory.getOWLUntypedConstant(uc.getLiteral(), uc.getLang()); - } else { - constant = factory.getOWLUntypedConstant(uc.getLiteral()); - } - } - */ - - // get datatype property - DatatypeProperty dtp = description.getRestrictedPropertyExpresssion(); - OWLDataProperty prop = factory.getOWLDataProperty(URI.create(dtp.getName())); - - stack.push(factory.getOWLDataValueRestriction(prop, constant)); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.NamedClass) - */ - public void visit(NamedClass description) { - stack.push(factory.getOWLClass(URI.create(description.getName()))); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.algorithms.gp.ADC) - */ - public void visit(ADC description) { - // TODO Auto-generated method stub - throw new Error("OWLAPIDescriptionConverter: not implemented"); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeMinCardinalityRestriction) - */ - public void visit(DatatypeMinCardinalityRestriction description) { - // TODO Auto-generated method stub - throw new Error("OWLAPIDescriptionConverter: not implemented"); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeExactCardinalityRestriction) - */ - public void visit(DatatypeExactCardinalityRestriction description) { - // TODO Auto-generated method stub - throw new Error("OWLAPIDescriptionConverter: not implemented"); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeMaxCardinalityRestriction) - */ - public void visit(DatatypeMaxCardinalityRestriction description) { - // TODO Auto-generated method stub - throw new Error("OWLAPIDescriptionConverter: not implemented"); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeSomeRestriction) - */ - public void visit(DatatypeSomeRestriction description) { - - // TODO: currently works only for double min/max - - DatatypeProperty dp = (DatatypeProperty) description.getRestrictedPropertyExpression(); - // currently only double restrictions implemented - SimpleDoubleDataRange dr = (SimpleDoubleDataRange) description.getDataRange(); - Double value = dr.getValue(); - - OWLDataType doubleDataType = factory.getOWLDataType(XSDVocabulary.DOUBLE.getURI()); - OWLTypedConstant constant = factory.getOWLTypedConstant(value.toString(), doubleDataType); - - OWLRestrictedDataRangeFacetVocabulary facet; - if(dr instanceof DoubleMinValue) - facet = OWLRestrictedDataRangeFacetVocabulary.MIN_INCLUSIVE; - else - facet = OWLRestrictedDataRangeFacetVocabulary.MAX_INCLUSIVE; - - OWLDataRange owlDataRange = factory.getOWLDataRangeRestriction(doubleDataType, facet, constant); - OWLDataProperty odp = factory.getOWLDataProperty(URI.create(dp.getName())); - OWLDescription d = factory.getOWLDataSomeRestriction(odp, owlDataRange); - - stack.push(d); - } - - public OWLDataType convertDatatype(Datatype datatype) { - if(datatype.equals(Datatype.BOOLEAN)) - return factory.getOWLDataType(Datatype.BOOLEAN.getURI()); - else if(datatype.equals(Datatype.INT)) - return factory.getOWLDataType(Datatype.INT.getURI()); - else if(datatype.equals(Datatype.DOUBLE)) - return factory.getOWLDataType(Datatype.DOUBLE.getURI()); - - throw new Error("OWLAPIDescriptionConverter: datatype not implemented"); - } - - private OWLConstant convertConstant(Constant constant) { - OWLConstant owlConstant; - if(constant instanceof TypedConstant) { - Datatype dt = ((TypedConstant)constant).getDatatype(); - OWLDataType odt = convertDatatype(dt); - owlConstant = factory.getOWLTypedConstant(constant.getLiteral(), odt); - } else { - UntypedConstant uc = (UntypedConstant) constant; - if(uc.hasLang()) { - owlConstant = factory.getOWLUntypedConstant(uc.getLiteral(), uc.getLang()); - } else { - owlConstant = factory.getOWLUntypedConstant(uc.getLiteral()); - } - } - return owlConstant; - } -} Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-10 13:46:08 UTC (rev 1502) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-10 16:53:59 UTC (rev 1503) @@ -65,6 +65,8 @@ import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.RoleComparator; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; @@ -370,14 +372,14 @@ /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getAtomicConcepts() */ - public Set<NamedClass> getAtomicConcepts() { + public Set<NamedClass> getNamedClasses() { return atomicConcepts; } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getAtomicRoles() */ - public Set<ObjectProperty> getAtomicRoles() { + public Set<ObjectProperty> getObjectProperties() { return atomicRoles; } @@ -396,11 +398,12 @@ /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getReasonerType() */ + @Override public ReasonerType getReasonerType() { if(configurator.getReasonerType().equals("fact")) - return ReasonerType.FACT; + return ReasonerType.OWLAPI_FACT; else - return ReasonerType.PELLET; + return ReasonerType.OWLAPI_PELLET; } /* (non-Javadoc) @@ -422,22 +425,22 @@ conceptComparator); // refinements of top - TreeSet<Description> tmp = getMoreSpecialConcepts(new Thing()); + TreeSet<Description> tmp = getMoreSpecialConceptsImpl(new Thing()); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyDown.put(new Thing(), tmp); // refinements of bottom - tmp = getMoreGeneralConcepts(new Nothing()); + tmp = getMoreGeneralConceptsImpl(new Nothing()); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyUp.put(new Nothing(), tmp); // refinements of atomic concepts for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConcepts(atom); + tmp = getMoreSpecialConceptsImpl(atom); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyDown.put(atom, tmp); - tmp = getMoreGeneralConcepts(atom); + tmp = getMoreGeneralConceptsImpl(atom); tmp.retainAll(allowedConceptsInSubsumptionHierarchy); subsumptionHierarchyUp.put(atom, tmp); } @@ -455,7 +458,6 @@ /* (non-Javadoc) * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) */ - @Override public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { // code copied from DIG reasoner @@ -466,8 +468,8 @@ // refinement of atomic concepts for (ObjectProperty role : atomicRoles) { - roleHierarchyDown.put(role, getMoreSpecialRoles(role)); - roleHierarchyUp.put(role, getMoreGeneralRoles(role)); + roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); } roleHierarchy = new ObjectPropertyHierarchy(allowedRoles, roleHierarchyUp, @@ -480,7 +482,7 @@ } @Override - public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { + public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles)... [truncated message content] |
From: <jen...@us...> - 2008-11-10 18:09:23
|
Revision: 1504 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1504&view=rev Author: jenslehmann Date: 2008-11-10 18:09:19 +0000 (Mon, 10 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN partially broken Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java trunk/src/dl-learner/org/dllearner/examples/KRKModular.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java trunk/src/dl-learner/org/dllearner/scripts/DumbLPFinder.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -36,7 +36,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.UnsupportedLanguageException; @@ -66,12 +66,12 @@ // since we store simulation information in the tree and simulation // updates depend on background knowledge) protected ReasonerComponent rs; - protected SubsumptionHierarchy subsumptionHierarchy; + protected ClassHierarchy subsumptionHierarchy; protected ObjectPropertyHierarchy roleHierarchy; public ELDescriptionTree(ReasonerComponent rs) { this.rs = rs; - subsumptionHierarchy = rs.getSubsumptionHierarchy(); + subsumptionHierarchy = rs.getClassHierarchy(); roleHierarchy = rs.getRoleHierarchy(); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -359,7 +359,7 @@ // during the run of the algorithm // reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + reasoner.getClassHierarchy().improveSubsumptionHierarchy(); // reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary // if(reasoner.hasDatatypeSupport()) Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -719,7 +719,7 @@ // Test aller Konzepte auf properness (mit DIG in nur einer Anfrage) if (usePropernessChecks) { long propCalcReasoningStart = System.nanoTime(); - improperConcepts = rs.subsumes(toEvaluateConcepts, concept); + improperConcepts = rs.isSuperClassOf(toEvaluateConcepts, concept); propernessTestsReasoner += toEvaluateConcepts.size(); // boolean isProper = // !learningProblem.getReasonerComponent().subsumes(refinement, @@ -813,7 +813,7 @@ for (Individual i : coveredPositives) { // TODO: move code to a separate function if (quality != -1) { - boolean covered = rs.instanceCheck(refinement, i); + boolean covered = rs.hasType(refinement, i); if (!covered) misclassifiedPositives++; else @@ -831,7 +831,7 @@ newlyCoveredNegatives = new HashSet<Individual>(); for (Individual i : coveredNegatives) { - boolean covered = rs.instanceCheck(refinement, i); + boolean covered = rs.hasType(refinement, i); if (covered) newlyCoveredNegatives.add(i); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/SubsumptionComparator.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -23,11 +23,11 @@ public int compare(Description concept1, Description concept2) { // return true if concept1 is a super concept of concept2 - boolean value1 = rs.subsumes(concept1, concept2); + boolean value1 = rs.isSuperClassOf(concept1, concept2); if(value1) return 1; - boolean value2 = rs.subsumes(concept2, concept1); + boolean value2 = rs.isSuperClassOf(concept2, concept1); if(value2) return -1; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -374,7 +374,7 @@ // during the run of the algorithm // reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + reasoner.getClassHierarchy().improveSubsumptionHierarchy(); // reasoner.prepareRoleHierarchy(usedRoles); } @@ -759,7 +759,7 @@ if(toEvaluateConcepts.size()>0) { // Test aller Konzepte auf properness (mit DIG in nur einer Anfrage) long propCalcReasoningStart = System.nanoTime(); - improperConcepts = reasoner.subsumes(toEvaluateConcepts, concept); + improperConcepts = reasoner.isSuperClassOf(toEvaluateConcepts, concept); propernessTestsReasoner+=toEvaluateConcepts.size(); // boolean isProper = !learningProblem.getReasonerComponent().subsumes(refinement, concept); propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -621,7 +621,7 @@ } else if (name.equals("showSubsumptionHierarchy")) { if (cliOption.getStringValue().equals("true")) { System.out.println("Subsumption Hierarchy:"); - System.out.println(rs.getSubsumptionHierarchy()); + System.out.println(rs.getClassHierarchy()); } // satisfiability check } else if (name.equals("checkSatisfiability")) { @@ -812,7 +812,7 @@ // pose retrieval query Set<Individual> result = null; - result = rs.retrieval(concept); + result = rs.getIndividuals(concept); logger.info("retrieval result (" + result.size() + "): " + result); Modified: trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -20,9 +20,12 @@ package org.dllearner.core; import java.util.Set; +import java.util.SortedSet; +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.utilities.datastructures.SortedSetTuple; /** * Reasoning requests/queries related to individuals in the knowledge base. @@ -41,4 +44,32 @@ */ public Set<NamedClass> getTypes(Individual individual); + /** + * Checks whether <code>individual</code> is instance of <code>description</code>. + * For instance, "Leipzig" may be an instance of "City". + * + * @param description An OWL class description. + * @param individual An individual. + * @return True if the instance has the description as type and false otherwise. + */ + public boolean hasType(Description description, Individual individual); + + /** + * Gets all instances of a given class description in the knowledge base. + * @param description An OWL class description. + * @return All instances of the class description. + */ + public SortedSet<Individual> getIndividuals(Description description); + + /** + * Performs a query for all instances of the given class description and + * its negation. (Note that in OWL it is possible that the reasoner can + * neither deduce that an individual is instance of a class nor its + * negation.) This method might be more efficient that performing a + * two retrievals. + * + * @param description An OWL class description. + * @return All instances of the class description and its negation. + */ + public SortedSetTuple<Individual> doubleRetrieval(Description description); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -40,7 +40,7 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.owl.OWLVocabulary; @@ -54,18 +54,18 @@ * * Guidelines for extending the class: * <ul> - * <li>add the needed method to the corresponding interface (currenty - * {@link BaseReasoner}, {@link SchemaReasoner}, {@link IndividualReasoner} - * exist)</li> - * <li>reasoning methods which need to be supported by all reasoners: - * create method() and methodImpl() here, where the former is an overridden, final - * method delegating to the latter abstract, protected method</li> - * <li>reasoning method, which do not need to be supported by all reasoners: - * create method() and methodImpl() as before, but this time methodImpl() is - * not abstract and throws a {@link ReasoningMethodUnsupportedException} - * </li> - * <li>a few very basic methods (where we do not care about statistics) - * do not have an "Impl" variant, e.g. getting all named classes of a KB</li> + * <li>add the needed method to the corresponding interface (currenty + * {@link BaseReasoner}, {@link SchemaReasoner}, {@link IndividualReasoner} + * exist)</li> + * <li>reasoning methods which need to be supported by all reasoners: create + * method() and methodImpl() here, where the former is an overridden, final + * method delegating to the latter abstract, protected method</li> + * <li>reasoning method, which do not need to be supported by all reasoners: + * create method() and methodImpl() as before, but this time methodImpl() is not + * abstract and throws a {@link ReasoningMethodUnsupportedException} </li> + * <li>a few very basic methods (where we do not care about statistics) do not + * have an "Impl" variant, e.g. getting all named classes of a KB; those are + * directly inherited from the reasoner interface</li> * </ul> * Note, that the method delegation is done to collect statistical information * about reasoning performance, e.g. count how often certain methods were called @@ -105,9 +105,9 @@ private List<ObjectProperty> atomicRolesList; // hierarchies (they are computed the first time they are needed) - private SubsumptionHierarchy subsumptionHierarchy; - private ObjectPropertyHierarchy roleHierarchy; - private DatatypePropertyHierarchy datatypePropertyHierarchy; + private ClassHierarchy subsumptionHierarchy = null; + private ObjectPropertyHierarchy roleHierarchy = null; + private DatatypePropertyHierarchy datatypePropertyHierarchy = null; /** * The underlying knowledge sources. @@ -173,6 +173,16 @@ } /** + * Notify the reasoner component that the underlying knowledge base has + * changed and all caches (for named classes, subsumption hierarchies, etc.) + * should be invalidaded. TODO Currently, nothing is done to behave + * correctly after updates. + */ + public void setUpdated() { + // TODO currently, nothing is done to behave correctly after updates + } + + /** * Call this method to release the knowledge base. Not calling the method * may (depending on the underlying reasoner) result in resources for this * knowledge base not being freed, which can cause memory leaks. @@ -199,17 +209,19 @@ } return types; } - - protected Set<NamedClass> getTypesImpl(Individual individual) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException("Reasoner does not support to determine type of individual."); + + protected Set<NamedClass> getTypesImpl(Individual individual) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Reasoner does not support to determine type of individual."); } - + @Override - public final boolean subsumes(Description superClass, Description subClass) { + public final boolean isSuperClassOf(Description superClass, Description subClass) { reasoningStartTimeTmp = System.nanoTime(); boolean result = false; try { - result = subsumesImpl(superClass, subClass); + result = isSuperClassOfImpl(superClass, subClass); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); } @@ -220,12 +232,18 @@ return result; } + protected boolean isSuperClassOfImpl(Description superConcept, Description subConcept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + @Override - public final Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) { + public final Set<Description> isSuperClassOf(Set<Description> superConcepts, + Description subConcept) { reasoningStartTimeTmp = System.nanoTime(); Set<Description> result = null; try { - result = subsumesImpl(superConcepts, subConcept); + result = isSuperClassOfImpl(superConcepts, subConcept); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); } @@ -234,29 +252,25 @@ reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; subsumptionReasoningTimeNs += reasoningDurationTmp; overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - public SortedSetTuple<Individual> doubleRetrieval(Description concept) { - reasoningStartTimeTmp = System.nanoTime(); - SortedSetTuple<Individual> result; - try { - result = doubleRetrievalImpl(concept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - otherReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; return result; } - public SortedSetTuple<Individual> doubleRetrieval(Description concept, Description adc) { + protected Set<Description> isSuperClassOfImpl(Set<Description> superConcepts, + Description subConcept) throws ReasoningMethodUnsupportedException { + Set<Description> returnSet = new HashSet<Description>(); + for (Description superConcept : superConcepts) { + if (isSuperClassOf(superConcept, subConcept)) + returnSet.add(superConcept); + } + return returnSet; + } + + @Override + public final SortedSetTuple<Individual> doubleRetrieval(Description concept) { reasoningStartTimeTmp = System.nanoTime(); SortedSetTuple<Individual> result; try { - result = doubleRetrievalImpl(concept, adc); + result = doubleRetrievalImpl(concept); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); return null; @@ -267,11 +281,17 @@ return result; } - public SortedSet<Individual> retrieval(Description concept) { + protected SortedSetTuple<Individual> doubleRetrievalImpl(Description concept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override + public final SortedSet<Individual> getIndividuals(Description concept) { reasoningStartTimeTmp = System.nanoTime(); SortedSet<Individual> result; try { - result = retrievalImpl(concept); + result = getIndividualsImpl(concept); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); return null; @@ -283,11 +303,17 @@ return result; } - public boolean instanceCheck(Description concept, Individual s) { + protected SortedSet<Individual> getIndividualsImpl(Description concept) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override + public final boolean hasType(Description concept, Individual s) { reasoningStartTimeTmp = System.nanoTime(); boolean result = false; try { - result = instanceCheckImpl(concept, s); + result = hasTypeImpl(concept, s); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); } @@ -298,6 +324,13 @@ return result; } + protected boolean hasTypeImpl(Description concept, Individual individual) + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + // ////// STOPPED HERE ////////// + public SortedSet<Individual> instanceCheck(Description concept, Set<Individual> s) { // logger.debug("instanceCheck "+concept.toKBSyntaxString()); reasoningStartTimeTmp = System.nanoTime(); @@ -324,7 +357,7 @@ * @return A set of more general concepts. */ public SortedSet<Description> getMoreGeneralConcepts(Description concept) { - return getSubsumptionHierarchy().getMoreGeneralConcepts(concept); + return getClassHierarchy().getMoreGeneralConcepts(concept); } /** @@ -335,7 +368,7 @@ * @return A set of more special concepts. */ public SortedSet<Description> getMoreSpecialConcepts(Description concept) { - return getSubsumptionHierarchy().getMoreSpecialConcepts(concept); + return getClassHierarchy().getMoreSpecialConcepts(concept); } /** @@ -418,22 +451,29 @@ return getDatatypePropertyHierarchy().getMostSpecialRoles(); } - protected void prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { + protected ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException( "Subsumption hierarchy creation not supported by this reasoner."); } - public SubsumptionHierarchy getSubsumptionHierarchy() { - if (subsumptionHierarchy == null) { - try { - prepareSubsumptionHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); + @Override + public final ClassHierarchy getClassHierarchy() { + try { + if (subsumptionHierarchy == null) { + subsumptionHierarchy = prepareSubsumptionHierarchy(); } +// subsumptionHierarchy = getSubsumptionHierarchyImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } + return subsumptionHierarchy; } + public ClassHierarchy getSubsumptionHierarchyImpl() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + protected void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException( "Object property hierarchy creation not supported by this reasoner."); @@ -723,36 +763,6 @@ return nrOfMultiInstanceChecks; } - public boolean subsumesImpl(Description superConcept, Description subConcept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Description> subsumesImpl(Description superConcept, Set<Description> subConcepts) - throws ReasoningMethodUnsupportedException { - Set<Description> returnSet = new HashSet<Description>(); - for (Description subConcept : subConcepts) { - if (subsumes(superConcept, subConcept)) - returnSet.add(subConcept); - } - return returnSet; - } - - public Set<Description> subsumesImpl(Set<Description> superConcepts, Description subConcept) - throws ReasoningMethodUnsupportedException { - Set<Description> returnSet = new HashSet<Description>(); - for (Description superConcept : superConcepts) { - if (subsumes(superConcept, subConcept)) - returnSet.add(superConcept); - } - return returnSet; - } - - public SortedSet<Individual> retrievalImpl(Description concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - public Set<Individual> getRelatedIndividualsImpl(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); @@ -864,26 +874,16 @@ return ret; } - public boolean instanceCheckImpl(Description concept, Individual individual) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - public SortedSet<Individual> instanceCheckImpl(Description concept, Set<Individual> individuals) throws ReasoningMethodUnsupportedException { SortedSet<Individual> returnSet = new TreeSet<Individual>(); for (Individual individual : individuals) { - if (instanceCheck(concept, individual)) + if (hasType(concept, individual)) returnSet.add(individual); } return returnSet; } - public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept, Description adc) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); @@ -893,11 +893,8 @@ throw new ReasoningMethodUnsupportedException(); } - public SubsumptionHierarchy getSubsumptionHierarchyImpl() - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } + public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Deleted: trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponentOld.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -1,304 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.core; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.Map.Entry; - -import org.dllearner.core.owl.Constant; -import org.dllearner.core.owl.DataRange; -import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.DatatypePropertyHierarchy; -import org.dllearner.core.owl.Entity; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.SubsumptionHierarchy; -import org.dllearner.utilities.datastructures.SortedSetTuple; - -/** - * Component representing a reasoner. - * - * @author Jens Lehmann - * - */ -@Deprecated -public abstract class ReasonerComponentOld extends Component implements ReasonerOld { - - protected Set<KnowledgeSource> sources; - - public ReasonerComponentOld(Set<KnowledgeSource> sources) { - this.sources = sources; - } - - /** - * @return the sources - */ - public Set<KnowledgeSource> getSources() { - return sources; - } - - /** - * Method to exchange the reasoner underlying the learning - * problem. - * Implementations, which do not only use the provided sources - * class variable, must make sure that a call to this method - * indeed changes them. - * @param sources The new knowledge sources. - */ - public void changeSources(Set<KnowledgeSource> sources) { - this.sources = sources; - } - - public abstract boolean hasDatatypeSupport(); - - public boolean subsumes(Description superConcept, Description subConcept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Description> subsumes(Description superConcept, Set<Description> subConcepts) - throws ReasoningMethodUnsupportedException { - Set<Description> returnSet = new HashSet<Description>(); - for (Description subConcept : subConcepts) { - if (subsumes(superConcept, subConcept)) - returnSet.add(subConcept); - } - return returnSet; - } - - public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) - throws ReasoningMethodUnsupportedException { - Set<Description> returnSet = new HashSet<Description>(); - for (Description superConcept : superConcepts) { - if (subsumes(superConcept, subConcept)) - returnSet.add(superConcept); - } - return returnSet; - } - - public SortedSet<Individual> retrieval(Description concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - - public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - // convenience method to get int value mappings of a datatype property - public Map<Individual, SortedSet<Integer>> getIntDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembers(datatypeProperty); - Map<Individual, SortedSet<Integer>> ret = new TreeMap<Individual, SortedSet<Integer>>(); - for(Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { - SortedSet<Constant> values = e.getValue(); - SortedSet<Integer> valuesInt = new TreeSet<Integer>(); - for(Constant c : values) { - int v = Integer.parseInt(c.getLiteral()); - valuesInt.add(v); - } - ret.put(e.getKey(),valuesInt); - } - return ret; - } - - // convenience method to get double value mappings of a datatype property - public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembers(datatypeProperty); - Map<Individual, SortedSet<Double>> ret = new TreeMap<Individual, SortedSet<Double>>(); - for(Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { - SortedSet<Constant> values = e.getValue(); - SortedSet<Double> valuesDouble = new TreeSet<Double>(); - for(Constant c : values) { - double v = Double.parseDouble(c.getLiteral()); - valuesDouble.add(v); - } - ret.put(e.getKey(),valuesDouble); - } - return ret; - } - - // convenience method to get boolean value mappings of a datatype property - public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembers(datatypeProperty); - Map<Individual, SortedSet<Boolean>> ret = new TreeMap<Individual, SortedSet<Boolean>>(); - for(Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { - SortedSet<Constant> values = e.getValue(); - SortedSet<Boolean> valuesBoolean = new TreeSet<Boolean>(); - for(Constant c : values) { - boolean v = Boolean.parseBoolean(c.getLiteral()); - valuesBoolean.add(v); - } - ret.put(e.getKey(),valuesBoolean); - } - return ret; - } - - // convenience method returning those values which have value "true" for this - // datatype property - public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembers(datatypeProperty); - SortedSet<Individual> ret = new TreeSet<Individual>(); - for(Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { - SortedSet<Constant> values = e.getValue(); - for(Constant c : values) { - boolean v = Boolean.parseBoolean(c.getLiteral()); - if(v == true) - ret.add(e.getKey()); - } - } - return ret; - } - - // convenience method returning those values which have value "false" for this - // datatype property - public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembers(datatypeProperty); - SortedSet<Individual> ret = new TreeSet<Individual>(); - for(Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { - SortedSet<Constant> values = e.getValue(); - for(Constant c : values) { - boolean v = Boolean.parseBoolean(c.getLiteral()); - if(v == false) - ret.add(e.getKey()); - } - } - return ret; - } - - public boolean instanceCheck(Description concept, Individual individual) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<Individual> instanceCheck(Description concept, Set<Individual> individuals) - throws ReasoningMethodUnsupportedException { - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for (Individual individual : individuals) { - if (instanceCheck(concept, individual)) - returnSet.add(individual); - } - return returnSet; - } - - public SortedSetTuple<Individual> doubleRetrieval(Description concept) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSetTuple<Individual> doubleRetrieval(Description concept, Description adc) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public boolean isSatisfiable() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SubsumptionHierarchy getSubsumptionHierarchy() - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedDatatypeProperties) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public ObjectPropertyHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public DatatypePropertyHierarchy getDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<NamedClass> getConcepts(Individual i) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Description getDomain(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Description getDomain(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Description getRange(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public DataRange getRange(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public SortedSet<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public abstract void releaseKB(); - - public Set<NamedClass> getInconsistentClasses() throws ReasoningMethodUnsupportedException{ - throw new ReasoningMethodUnsupportedException(); - } - -} Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerOld.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -34,7 +34,7 @@ import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.datastructures.SortedSetTuple; @@ -69,7 +69,7 @@ // public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) throws ReasoningMethodUnsupportedException; // public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) throws ReasoningMethodUnsupportedException; - public SubsumptionHierarchy getSubsumptionHierarchy() throws ReasoningMethodUnsupportedException; + public ClassHierarchy getSubsumptionHierarchy() throws ReasoningMethodUnsupportedException; public ObjectPropertyHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException; Deleted: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-11-10 16:53:59 UTC (rev 1503) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-11-10 18:09:19 UTC (rev 1504) @@ -1,748 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -package org.dllearner.core; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; -import org.dllearner.core.owl.Constant; -import org.dllearner.core.owl.DataRange; -import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.DatatypePropertyHierarchy; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Entity; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.SubsumptionHierarchy; -import org.dllearner.reasoning.ReasonerType; -import org.dllearner.utilities.datastructures.SortedSetTuple; -import org.dllearner.utilities.owl.OWLVocabulary; - -/** - * The reasoning service is the interface to the used reasoner. Basically, - * it delegates all incoming reasoner request to the <code>Reasoner</code> - * object which has been specified in the constructor. However, it calculates - * some additional statistics about the time the reasoner needs to answer - * the query. - * - * @author Jens Lehmann - * - */ -@Deprecated -public class ReasoningService { - - public static Logger logger = Logger.getLogger(ReasoningService.class); - - // statistische Daten - private long instanceCheckReasoningTimeNs = 0; - private int nrOfInstanceChecks = 0; - private int nrOfMultiInstanceChecks = 0; - private long retrievalReasoningTimeNs = 0; - private int nrOfRetrievals = 0; - private long subsumptionReasoningTimeNs = 0; - private int nrOfSubsumptionChecks = 0; - private int nrOfMultiSubsumptionChecks = 0; - // private long subsumptionHierarchyTimeNs = 0; - private int nrOfSubsumptionHierarchyQueries = 0; - - // restliche Reasoning-Zeit - private long otherReasoningTimeNs = 0; - - // Zeit für alle Reasoningaufgabe (normalerweise länger als nur - // obige Sachen) - private long overallReasoningTimeNs = 0; - - // temporäre Variablen (ausgelagert wg. Performance und Vereinfachung) - private long reasoningStartTimeTmp; - private long reasoningDurationTmp; - - // Listenansicht - private List<NamedClass> atomicConceptsList; - private List<ObjectProperty> atomicRolesList; - - // private SortedSet<Concept> retrievalsSet = new TreeSet<Concept>(new ConceptComparator()); - - private ReasonerComponentOld reasoner; - - /** - * Constructs a reasoning service object. Note that you must not - * modify the underlying knowledge base of a reasoning service - * (if you do, you have to create a new reasoning service object). - * Further note, that the initialisation is lazy, e.g. you can - * feed the constructor with a non-initialised reasoner component. - * However, of course you need to make sure that the resoner component - * is initialised before the first reasoner query. - * - * @param reasoner - */ - public ReasoningService(ReasonerComponentOld reasoner) { - this.reasoner = reasoner; - - resetStatistics(); - } - - // zurücksetzen aller Statistiken (wenn z.B. vorher ein Satisfiability Check gemacht wird, - // der allerdings nicht zum eigentlichen Algorithmus gehört) - public void resetStatistics() { - instanceCheckReasoningTimeNs = 0; - nrOfInstanceChecks = 0; - retrievalReasoningTimeNs = 0; - nrOfRetrievals = 0; - subsumptionReasoningTimeNs = 0; - nrOfSubsumptionChecks = 0; - // subsumptionHierarchyTimeNs = 0; - nrOfSubsumptionHierarchyQueries = 0; - otherReasoningTimeNs = 0; - overallReasoningTimeNs = 0; - } - - public SortedSetTuple<Individual> doubleRetrieval(Description concept) { - reasoningStartTimeTmp = System.nanoTime(); - SortedSetTuple<Individual> result; - try { - result = reasoner.doubleRetrieval(concept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - otherReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - public SortedSetTuple<Individual> doubleRetrieval(Description concept, Description adc) { - reasoningStartTimeTmp = System.nanoTime(); - SortedSetTuple<Individual> result; - try { - result = reasoner.doubleRetrieval(concept, adc); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - otherReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - // nachher wieder entfernen - // public static List<Concept> retrievals = new LinkedList<Concept>(); - - public SortedSet<Individual> retrieval(Description concept) { - // Test, ob tatsächlich keine doppelten Retrievals ausgeführt werden - // retrievals.add(concept); - //logger.debug("retrieval "+concept.toKBSyntaxString()); - - reasoningStartTimeTmp = System.nanoTime(); - SortedSet<Individual> result; - try { - result = reasoner.retrieval(concept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - nrOfRetrievals++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - retrievalReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - //logger.debug("retrieval done"); - return result; - } - - public boolean instanceCheck(Description concept, Individual s) { - //logger.debug("instanceCheck "+concept.toKBSyntaxString()); - reasoningStartTimeTmp = System.nanoTime(); - boolean result = false; - try { - result = reasoner.instanceCheck(concept, s); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - nrOfInstanceChecks++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - instanceCheckReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - //logger.debug("instanceCheck done"); - return result; - } - - public SortedSet<Individual> instanceCheck(Description concept, Set<Individual> s) { - //logger.debug("instanceCheck "+concept.toKBSyntaxString()); - reasoningStartTimeTmp = System.nanoTime(); - SortedSet<Individual> result = null; - try { - result = reasoner.instanceCheck(concept, s); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - nrOfInstanceChecks+=s.size(); - nrOfMultiInstanceChecks++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - instanceCheckReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - //logger.debug("instanceCheck done"); - return result; - } - - // c1 subsummiert c2 - public boolean subsumes(Description superConcept, Description subConcept) { - reasoningStartTimeTmp = System.nanoTime(); - boolean result = false; - try { - result = reasoner.subsumes(superConcept, subConcept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - nrOfSubsumptionChecks++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - subsumptionReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - public Set<Description> subsumes(Set<Description> superConcepts, Description subConcept) { - reasoningStartTimeTmp = System.nanoTime(); - Set<Description> result = null; - try { - result = reasoner.subsumes(superConcepts, subConcept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - nrOfSubsumptionChecks += superConcepts.size(); - nrOfMultiSubsumptionChecks++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - subsumptionReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - /* - // Problem: wie behandle ich Top und Bottom? - // TODO: schauen wie das in KAON2 gemacht wird - public SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - if(Config.useHierarchyReasonerBenchmarks) - reasoningStartTimeTmp = System.nanoTime(); - SortedSet<Concept> result; - try { - result = reasoner.getMoreGeneralConcepts(concept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - if(Config.useHierarchyReasonerBenchmarks) { - nrOfSubsumptionHierarchyQueries++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - subsumptionHierarchyTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - } - return result; - } - - public SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - if(Config.useHierarchyReasonerBenchmarks) - reasoningStartTimeTmp = System.nanoTime(); - SortedSet<Concept> result; - try { - result = reasoner.getMoreSpecialConcepts(concept); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - if(Config.useHierarchyReasonerBenchmarks) { - nrOfSubsumptionHierarchyQueries++; - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - subsumptionHierarchyTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - } - return result; - } - */ - - /** - * Returns more general concepts in the subsumption hierarchy. - * - * @param concept Atomic concept, top, or bottom. - * @return A set of more general concepts. - */ - public SortedSet<Description> getMoreGeneralConcepts(Description concept) { - return getSubsumptionHierarchy().getMoreGeneralConcepts(concept); - } - - /** - * Returns more special concepts in the subsumption hierarchy. - * - * @param concept Atomic concept, top, or bottom. - * @return A set of more special concepts. - */ - public SortedSet<Description> getMoreSpecialConcepts(Description concept) { - return getSubsumptionHierarchy().getMoreSpecialConcepts(concept); - } - - /** - * Returns more general concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) - * @param role Atomic concept, top, or bottom. - * @return A set of more general concepts. - */ - public SortedSet<ObjectProperty> getMoreGeneralRoles(ObjectProperty role) { - return getRoleHierarchy().getMoreGeneralRoles(role); - } - - /** - * Returns more special concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) - * @param role Atomic concept, top, or bottom. - * @return A set of more special concepts. - */ - public SortedSet<ObjectProperty> getMoreSpecialRoles(ObjectProperty role) { - return getRoleHierarchy().getMoreSpecialRoles(role); - } - - /** - * @see ObjectPropertyHierarchy#getMostGeneralRoles() - * @return The most general roles. - */ - public TreeSet<ObjectProperty> getMostGeneralRoles() { - return getRoleHierarchy().getMostGeneralRoles(); - } - - /** - * @see ObjectPropertyHierarchy#getMostSpecialRoles() - * @return The most special roles. - */ - public TreeSet<ObjectProperty> getMostSpecialRoles() { - return getRoleHierarchy().getMostSpecialRoles(); - } - - /** - * Returns more general concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) - * @param role Atomic concept, top, or bottom. - * @return A set of more general concepts. - */ - public SortedSet<DatatypeProperty> getMoreGeneralDatatypeProperties(DatatypeProperty role) { - return getDatatypePropertyHierarchy().getMoreGeneralRoles(role); - } - - /** - * Returns more special concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) - * @param role Atomic concept, top, or bottom. - * @return A set of more special concepts. - */ - public SortedSet<DatatypeProperty> getMoreSpecialDatatypeProperties(DatatypeProperty role) { - return getDatatypePropertyHierarchy().getMoreSpecialRoles(role); - } - - /** - * @see ObjectPropertyHierarchy#getMostGeneralRoles() - * @return The most general roles. - */ - public TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties() { - return getDatatypePropertyHierarchy().getMostGeneralRoles(); - } - - /** - * @see ObjectPropertyHierarchy#getMostSpecialRoles() - * @return The most special roles. - */ - public TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties() { - return getDatatypePropertyHierarchy().getMostSpecialRoles(); - } - - public void prepareSubsumptionHierarchy() { - reasoner.prepareSubsumptionHierarchy(getNamedClasses()); - } - - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { - reasoner.prepareSubsumptionHierarchy(allowedConcepts); - } - - public SubsumptionHierarchy getSubsumptionHierarchy() { - try { - if(reasoner.getSubsumptionHierarchy() == null){ - this.prepareSubsumptionHierarchy(); - } - - nrOfSubsumptionHierarchyQueries++; - return reasoner.getSubsumptionHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public void prepareRoleHierarchy() { - prepareRoleHierarchy(getObjectProperties()); - } - - public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { - try { - reasoner.prepareRoleHierarchy(allowedRoles); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - } - - public ObjectPropertyHierarchy getRoleHierarchy() { - try { - return reasoner.getRoleHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public void prepareDatatypePropertyHierarchy() { - prepareDatatypePropertyHierarchy(getDatatypeProperties()); - } - - public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { - try { - reasoner.prepareDatatypePropertyHierarchy(allowedRoles); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - } - - public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { - try { - return reasoner.getDatatypePropertyHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public boolean isSatisfiable() { - reasoningStartTimeTmp = System.nanoTime(); - boolean result; - try { - result = reasoner.isSatisfiable(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return false; - } - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - otherReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { - try { - return reasoner.getRelatedIndividuals(individual, objectProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - try { - return reasoner.getRelatedValues(individual, datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { - try { - return reasoner.getLabel(entity); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - - public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { - reasoningStartTimeTmp = System.nanoTime(); - Map<Individual, SortedSet<Individual>> result; - try { - result = reasoner.getRoleMembers(atomicRole); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - reasoningDurationTmp = System.nanoTime() - reasoningStartTimeTmp; - otherReasoningTimeNs += reasoningDurationTmp; - overallReasoningTimeNs += reasoningDurationTmp; - return result; - } - - public boolean hasDatatypeSupport() { - return reasoner.hasDatatypeSupport(); - } - - public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) { - try { - return reasoner.getDoubleDatatypeMembers(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Map<Individual, SortedSet<Double>> getIntDatatypeMembers(DatatypeProperty datatypeProperty) { - try { - return reasoner.getDoubleDatatypeMembers(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Map<Individual, SortedSet<Double>> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) { - try { - return reasoner.getDoubleDatatypeMembers(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Map<Individual, SortedSet<Double>> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) { - try { - return reasoner.getDoubleDatatypeMembers(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Set<NamedClass> getNamedClasses() { - return reasoner.getAtomicConcepts(); - } - - public Set<ObjectProperty> getObjectProperties() { - return reasoner.getAtomicRoles(); - } - - public SortedSet<DatatypeProperty> getDatatypeProperties() { - try { - return reasoner.getDatatypeProperties(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { - try { - return reasoner.getBooleanDatatypeProperties(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public SortedSet<DatatypeProperty> getIntDatatypeProperties() { - try { - return reasoner.getIntDatatypeProperties(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { - try { - return reasoner.getDoubleDatatypeProperties(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public SortedSet<Individual> getIndividuals() { - return reasoner.getIndividuals(); - } - - public Description getDomain(ObjectProperty objectProperty) { - try { - return reasoner.getDomain(objectProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Description getDomain(DatatypeProperty datatypeProperty) { - try { - return reasoner.getDomain(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Description getRange(ObjectProperty objectProperty) { - try { - return reasoner.getRange(objectProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public DataRange getRange(DatatypeProperty datatypeProperty) { - try { - return reasoner.getRange(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public ReasonerType getReasonerType() { - return reasoner.getReasonerType(); - } - - public List<NamedClass> getAtomicConceptsList() { - if(atomicConceptsList == null) - atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); - return atomicConceptsList; - } - - public List<NamedClass> getAtomicConceptsList(boolean removeOWLThing) { - if(!removeOWLThing) { - return getAtomicConceptsList(); - }else { - List<NamedClass> l = new LinkedList<NamedClass>(); - for (NamedClass class1 : getAtomicConceptsList()) { - if(class1.compareTo(new NamedClass(OWLVocabulary.OWL_NOTHING)) == 0 || - class1.compareTo(new NamedClass(OWLVocabulary.OWL_THING)) == 0 ){ - ;//do nothing - }else{ - l.add(class1); - } - } - return l; - } - - } - - public List<ObjectProperty> getAtomicRolesList() { - if(atomicRolesList == null) - atomicRolesList = new LinkedList<ObjectProperty>(getObjectProperties()); - return atomicRolesList; - } - - public String getBaseURI() { - return reasoner.getBaseURI(); - } - - public Map<String, String> getPrefixes() { - return reasoner.getPrefixes(); - } - - public void releaseKB() { - reasoner.releaseKB(); - } - - public long getInstanceCheckReasoningTimeNs() { - return instance... [truncated message content] |
From: <jen...@us...> - 2008-11-11 10:59:35
|
Revision: 1505 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1505&view=rev Author: jenslehmann Date: 2008-11-11 10:59:23 +0000 (Tue, 11 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN partially broken Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentPool.java trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java trunk/src/dl-learner/org/dllearner/core/options/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/CommonConfigMappings.java trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/core/options/ConfigEntry.java trunk/src/dl-learner/org/dllearner/core/options/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/InvalidConfigOptionValueException.java trunk/src/dl-learner/org/dllearner/core/options/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/StringTupleListConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/URLConfigOption.java trunk/src/dl-learner/org/dllearner/core/options/UnknownConfigOptionException.java trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/widgets/AbstractWidgetPanel.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelBoolean.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDefault.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDouble.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelInteger.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelString.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringTupleList.java trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/kb/OWLAPIOntology.java trunk/src/dl-learner/org/dllearner/kb/OWLFile.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.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/learningproblems/PosOnlyInclusionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java trunk/src/dl-learner/org/dllearner/scripts/CrossValidation.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/tools/ore/OntologyModifier.java trunk/src/dl-learner/org/dllearner/utilities/components/ComponentCombo.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/options/ Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/config/ Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -31,12 +31,12 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.CommonConfigOptions; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.configurators.BruteForceLearnerConfigurator; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.IntegerConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -30,15 +30,15 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.CommonConfigOptions; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.configurators.ComponentFactory; import org.dllearner.core.configurators.DBpediaNavigationSuggestorConfigurator; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; +import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegLP; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -30,11 +30,11 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.configurators.RandomGuesserConfigurator; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.IntegerConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.Description; public class RandomGuesser extends LearningAlgorithm { Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -27,8 +27,8 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.configurators.SimpleSuggestionLearningAlgorithmConfigurator; +import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.ObjectProperty; Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -72,7 +72,7 @@ public ELDescriptionTree(ReasonerComponent rs) { this.rs = rs; subsumptionHierarchy = rs.getClassHierarchy(); - roleHierarchy = rs.getRoleHierarchy(); + roleHierarchy = rs.getObjectPropertyHierarchy(); } /** @@ -153,7 +153,7 @@ // we first check inclusion property on edges ObjectProperty op1 = edges.get(j).getLabel(); ObjectProperty op2 = edges.get(k).getLabel(); - if(rs.getRoleHierarchy().isSubpropertyOf(op1, op2)) { + if(rs.getObjectPropertyHierarchy().isSubpropertyOf(op1, op2)) { ELDescriptionNode node1 = edges.get(j).getTree(); ELDescriptionNode node2 = edges.get(k).getTree(); // check simulation condition Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -35,14 +35,14 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.configurators.GPConfigurator; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.IntegerConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; +import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -35,16 +35,16 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.CommonConfigMappings; -import org.dllearner.core.config.CommonConfigOptions; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.configurators.ExampleBasedROLComponentConfigurator; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.CommonConfigMappings; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.IntegerConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; +import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -388,8 +388,8 @@ startNode.setCoveredExamples(positiveExamples, negativeExamples); } else { startNode = new ExampleBasedNode(startDescription); - Set<Individual> coveredNegatives = rs.instanceCheck(startDescription, negativeExamples); - Set<Individual> coveredPositives = rs.instanceCheck(startDescription, positiveExamples); + Set<Individual> coveredNegatives = rs.hasType(startDescription, negativeExamples); + Set<Individual> coveredPositives = rs.hasType(startDescription, positiveExamples); startNode.setCoveredExamples(coveredPositives, coveredNegatives); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -19,15 +19,15 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.CommonConfigMappings; -import org.dllearner.core.config.CommonConfigOptions; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.configurators.ROLearnerConfigurator; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.CommonConfigMappings; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; +import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -58,15 +58,15 @@ import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.Score; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; -import org.dllearner.core.config.StringSetConfigOption; -import org.dllearner.core.config.StringTupleListConfigOption; +import org.dllearner.core.options.BooleanConfigOption; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.IntegerConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; +import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.options.StringSetConfigOption; +import org.dllearner.core.options.StringTupleListConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; Modified: trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -42,6 +42,12 @@ public interface BaseReasoner { /** + * Checks consistency of the knowledge. + * @return True if the knowledge base is consistent and false otherwise. + */ + public boolean isSatisfiable(); + + /** * Gets all named classes in the knowledge base, e.g. Person, City, Car. * @return All named classes in KB. */ Modified: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -22,11 +22,11 @@ import java.util.Collection; import java.util.LinkedList; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.configurators.Configurator; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.DoubleConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; /** * Base class of all components. See also http://dl-learner.org/wiki/Architecture. Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -43,9 +43,9 @@ import org.apache.log4j.Logger; import org.dllearner.cli.ConfMapper; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.utilities.Files; /** Modified: trunk/src/dl-learner/org/dllearner/core/ComponentPool.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentPool.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/ComponentPool.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -25,8 +25,8 @@ import java.util.Map; import org.apache.log4j.Logger; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; /** * Stores all live components and the configuration options, which were applied Modified: trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -55,6 +55,15 @@ public boolean hasType(Description description, Individual individual); /** + * Performs instance checks on a set of instances (reasoners might be more + * efficient than handling each check separately). + * @param description An OWL class description. + * @param individuals An individual. + * @return The subset of those instances, which have the given type. + */ + public SortedSet<Individual> hasType(Description description, Set<Individual> individuals); + + /** * Gets all instances of a given class description in the knowledge base. * @param description An OWL class description. * @return All instances of the class description. Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -328,15 +328,14 @@ throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - - // ////// STOPPED HERE ////////// - - public SortedSet<Individual> instanceCheck(Description concept, Set<Individual> s) { + + @Override + public final SortedSet<Individual> hasType(Description concept, Set<Individual> s) { // logger.debug("instanceCheck "+concept.toKBSyntaxString()); reasoningStartTimeTmp = System.nanoTime(); SortedSet<Individual> result = null; try { - result = instanceCheckImpl(concept, s); + result = hasTypeImpl(concept, s); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); } @@ -349,164 +348,18 @@ return result; } - /** - * Returns more general concepts in the subsumption hierarchy. - * - * @param concept - * Atomic concept, top, or bottom. - * @return A set of more general concepts. - */ - public SortedSet<Description> getMoreGeneralConcepts(Description concept) { - return getClassHierarchy().getMoreGeneralConcepts(concept); - } - - /** - * Returns more special concepts in the subsumption hierarchy. - * - * @param concept - * Atomic concept, top, or bottom. - * @return A set of more special concepts. - */ - public SortedSet<Description> getMoreSpecialConcepts(Description concept) { - return getClassHierarchy().getMoreSpecialConcepts(concept); - } - - /** - * Returns more general concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) - * @param role - * Atomic concept, top, or bottom. - * @return A set of more general concepts. - */ - public SortedSet<ObjectProperty> getMoreGeneralRoles(ObjectProperty role) { - return getRoleHierarchy().getMoreGeneralRoles(role); - } - - /** - * Returns more special concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) - * @param role - * Atomic concept, top, or bottom. - * @return A set of more special concepts. - */ - public SortedSet<ObjectProperty> getMoreSpecialRoles(ObjectProperty role) { - return getRoleHierarchy().getMoreSpecialRoles(role); - } - - /** - * @see ObjectPropertyHierarchy#getMostGeneralRoles() - * @return The most general roles. - */ - public TreeSet<ObjectProperty> getMostGeneralRoles() { - return getRoleHierarchy().getMostGeneralRoles(); - } - - /** - * @see ObjectPropertyHierarchy#getMostSpecialRoles() - * @return The most special roles. - */ - public TreeSet<ObjectProperty> getMostSpecialRoles() { - return getRoleHierarchy().getMostSpecialRoles(); - } - - /** - * Returns more general concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) - * @param role - * Atomic concept, top, or bottom. - * @return A set of more general concepts. - */ - public SortedSet<DatatypeProperty> getMoreGeneralDatatypeProperties(DatatypeProperty role) { - return getDatatypePropertyHierarchy().getMoreGeneralRoles(role); - } - - /** - * Returns more special concepts in the subsumption hierarchy. - * - * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) - * @param role - * Atomic concept, top, or bottom. - * @return A set of more special concepts. - */ - public SortedSet<DatatypeProperty> getMoreSpecialDatatypeProperties(DatatypeProperty role) { - return getDatatypePropertyHierarchy().getMoreSpecialRoles(role); - } - - /** - * @see ObjectPropertyHierarchy#getMostGeneralRoles() - * @return The most general roles. - */ - public TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties() { - return getDatatypePropertyHierarchy().getMostGeneralRoles(); - } - - /** - * @see ObjectPropertyHierarchy#getMostSpecialRoles() - * @return The most special roles. - */ - public TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties() { - return getDatatypePropertyHierarchy().getMostSpecialRoles(); - } - - protected ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException( - "Subsumption hierarchy creation not supported by this reasoner."); - } - - @Override - public final ClassHierarchy getClassHierarchy() { - try { - if (subsumptionHierarchy == null) { - subsumptionHierarchy = prepareSubsumptionHierarchy(); - } -// subsumptionHierarchy = getSubsumptionHierarchyImpl(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); + protected SortedSet<Individual> hasTypeImpl(Description concept, Set<Individual> individuals) + throws ReasoningMethodUnsupportedException { + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + for (Individual individual : individuals) { + if (hasType(concept, individual)) + returnSet.add(individual); } - - return subsumptionHierarchy; - } - - public ClassHierarchy getSubsumptionHierarchyImpl() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); + return returnSet; } - - protected void prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException( - "Object property hierarchy creation not supported by this reasoner."); - } - public ObjectPropertyHierarchy getRoleHierarchy() { - if (roleHierarchy == null) { - try { - prepareRoleHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - } - return roleHierarchy; - } - - protected void prepareDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException( - "Datatype property hierarchy creation not supported by this reasoner."); - } - - public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { - if (datatypePropertyHierarchy == null) { - try { - prepareDatatypePropertyHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - } - } - return datatypePropertyHierarchy; - } - - public boolean isSatisfiable() { + @Override + public final boolean isSatisfiable() { reasoningStartTimeTmp = System.nanoTime(); boolean result; try { @@ -521,6 +374,10 @@ return result; } + protected boolean isSatisfiableImpl() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { try { @@ -677,92 +534,6 @@ } } - public List<NamedClass> getAtomicConceptsList() { - if (atomicConceptsList == null) - atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); - return atomicConceptsList; - } - - public List<NamedClass> getAtomicConceptsList(boolean removeOWLThing) { - if (!removeOWLThing) { - return getAtomicConceptsList(); - } else { - List<NamedClass> l = new LinkedList<NamedClass>(); - for (NamedClass class1 : getAtomicConceptsList()) { - if (class1.compareTo(new NamedClass(OWLVocabulary.OWL_NOTHING)) == 0 - || class1.compareTo(new NamedClass(OWLVocabulary.OWL_THING)) == 0) { - ;// do nothing - } else { - l.add(class1); - } - } - return l; - } - - } - - public List<ObjectProperty> getAtomicRolesList() { - if (atomicRolesList == null) - atomicRolesList = new LinkedList<ObjectProperty>(getObjectProperties()); - return atomicRolesList; - } - - public long getInstanceCheckReasoningTimeNs() { - return instanceCheckReasoningTimeNs; - } - - public long getRetrievalReasoningTimeNs() { - return retrievalReasoningTimeNs; - } - - public int getNrOfInstanceChecks() { - return nrOfInstanceChecks; - } - - public int getNrOfRetrievals() { - return nrOfRetrievals; - } - - public int getNrOfSubsumptionChecks() { - return nrOfSubsumptionChecks; - } - - public long getSubsumptionReasoningTimeNs() { - return subsumptionReasoningTimeNs; - } - - /* - * public long getSubsumptionHierarchyTimeNs() { return - * subsumptionHierarchyTimeNs; } - */ - public int getNrOfSubsumptionHierarchyQueries() { - return nrOfSubsumptionHierarchyQueries; - } - - public long getOverallReasoningTimeNs() { - return overallReasoningTimeNs; - } - - public long getTimePerRetrievalNs() { - return retrievalReasoningTimeNs / nrOfRetrievals; - } - - public long getTimePerInstanceCheckNs() { - return instanceCheckReasoningTimeNs / nrOfInstanceChecks; - } - - public long getTimePerSubsumptionCheckNs() { - return subsumptionReasoningTimeNs / nrOfSubsumptionChecks; - } - - public int getNrOfMultiSubsumptionChecks() { - return nrOfMultiSubsumptionChecks; - } - - public int getNrOfMultiInstanceChecks() { - return nrOfMultiInstanceChecks; - } - public Set<Individual> getRelatedIndividualsImpl(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); @@ -874,27 +645,16 @@ return ret; } - public SortedSet<Individual> instanceCheckImpl(Description concept, Set<Individual> individuals) - throws ReasoningMethodUnsupportedException { - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - for (Individual individual : individuals) { - if (hasType(concept, individual)) - returnSet.add(individual); - } - return returnSet; - } public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept, Description adc) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public boolean isSatisfiableImpl() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } + public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); @@ -957,6 +717,199 @@ public Set<NamedClass> getInconsistentClassesImpl() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); + } + + @Override + public final SortedSet<Description> getSuperClasses(Description concept) { + return getClassHierarchy().getMoreGeneralConcepts(concept); } + @Override + public final SortedSet<Description> getSubClasses(Description concept) { + return getClassHierarchy().getMoreSpecialConcepts(concept); + } + + @Override + public final SortedSet<ObjectProperty> getSuperProperties(ObjectProperty role) { + return getObjectPropertyHierarchy().getMoreGeneralRoles(role); + } + + @Override + public final SortedSet<ObjectProperty> getSubProperties(ObjectProperty role) { + return getObjectPropertyHierarchy().getMoreSpecialRoles(role); + } + + @Override + public final TreeSet<ObjectProperty> getMostGeneralProperties() { + return getObjectPropertyHierarchy().getMostGeneralRoles(); + } + + @Override + public final TreeSet<ObjectProperty> getMostSpecialProperties() { + return getObjectPropertyHierarchy().getMostSpecialRoles(); + } + + @Override + public final SortedSet<DatatypeProperty> getSuperProperties(DatatypeProperty role) { + return getDatatypePropertyHierarchy().getMoreGeneralRoles(role); + } + + @Override + public final SortedSet<DatatypeProperty> getSubProperties(DatatypeProperty role) { + return getDatatypePropertyHierarchy().getMoreSpecialRoles(role); + } + + @Override + public final TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties() { + return getDatatypePropertyHierarchy().getMostGeneralRoles(); + } + + @Override + public final TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties() { + return getDatatypePropertyHierarchy().getMostSpecialRoles(); + } + + protected ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Subsumption hierarchy creation not supported by this reasoner."); + } + + @Override + public final ClassHierarchy getClassHierarchy() { + try { + if (subsumptionHierarchy == null) { + subsumptionHierarchy = prepareSubsumptionHierarchy(); + } +// subsumptionHierarchy = getSubsumptionHierarchyImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + + return subsumptionHierarchy; + } + +// public ClassHierarchy getSubsumptionHierarchyImpl() throws ReasoningMethodUnsupportedException { +// throw new ReasoningMethodUnsupportedException(); +// } + + protected ObjectPropertyHierarchy prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Object property hierarchy creation not supported by this reasoner."); + } + + @Override + public final ObjectPropertyHierarchy getObjectPropertyHierarchy() { + if (roleHierarchy == null) { + try { + prepareRoleHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + return roleHierarchy; + } + + protected DatatypePropertyHierarchy prepareDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException( + "Datatype property hierarchy creation not supported by this reasoner."); + } + + @Override + public final DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + if (datatypePropertyHierarchy == null) { + try { + prepareDatatypePropertyHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + } + } + return datatypePropertyHierarchy; + } + + public List<NamedClass> getAtomicConceptsList() { + if (atomicConceptsList == null) + atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); + return atomicConceptsList; + } + + public List<NamedClass> getAtomicConceptsList(boolean removeOWLThing) { + if (!removeOWLThing) { + return getAtomicConceptsList(); + } else { + List<NamedClass> l = new LinkedList<NamedClass>(); + for (NamedClass class1 : getAtomicConceptsList()) { + if (class1.compareTo(new NamedClass(OWLVocabulary.OWL_NOTHING)) == 0 + || class1.compareTo(new NamedClass(OWLVocabulary.OWL_THING)) == 0) { + ;// do nothing + } else { + l.add(class1); + } + } + return l; + } + + } + + public List<ObjectProperty> getAtomicRolesList() { + if (atomicRolesList == null) + atomicRolesList = new LinkedList<ObjectProperty>(getObjectProperties()); + return atomicRolesList; + } + + public long getInstanceCheckReasoningTimeNs() { + return instanceCheckReasoningTimeNs; + } + + public long getRetrievalReasoningTimeNs() { + return retrievalReasoningTimeNs; + } + + public int getNrOfInstanceChecks() { + return nrOfInstanceChecks; + } + + public int getNrOfRetrievals() { + return nrOfRetrievals; + } + + public int getNrOfSubsumptionChecks() { + return nrOfSubsumptionChecks; + } + + public long getSubsumptionReasoningTimeNs() { + return subsumptionReasoningTimeNs; + } + + /* + * public long getSubsumptionHierarchyTimeNs() { return + * subsumptionHierarchyTimeNs; } + */ + public int getNrOfSubsumptionHierarchyQueries() { + return nrOfSubsumptionHierarchyQueries; + } + + public long getOverallReasoningTimeNs() { + return overallReasoningTimeNs; + } + + public long getTimePerRetrievalNs() { + return retrievalReasoningTimeNs / nrOfRetrievals; + } + + public long getTimePerInstanceCheckNs() { + return instanceCheckReasoningTimeNs / nrOfInstanceChecks; + } + + public long getTimePerSubsumptionCheckNs() { + return subsumptionReasoningTimeNs / nrOfSubsumptionChecks; + } + + public int getNrOfMultiSubsumptionChecks() { + return nrOfMultiSubsumptionChecks; + } + + public int getNrOfMultiInstanceChecks() { + return nrOfMultiInstanceChecks; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -20,9 +20,15 @@ package org.dllearner.core; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyHierarchy; /** * Reasoning requests related to the schema of the knowledge base. @@ -31,13 +37,6 @@ * */ public interface SchemaReasoner { - - /** - * Computes and returns the class hierarchy of the knowledge base. - * - * @return The subsumption hierarchy of this knowledge base. - */ - public ClassHierarchy getClassHierarchy(); /** * Checks whether <code>superClass</code> is a super class of <code>subClass</code>. @@ -55,4 +54,107 @@ */ public Set<Description> isSuperClassOf(Set<Description> superClasses, Description subClasses); + /** + * Computes and returns the class hierarchy of the knowledge base. + * + * @return The subsumption hierarchy of this knowledge base. + */ + public ClassHierarchy getClassHierarchy(); + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @param description + * Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<Description> getSuperClasses(Description description); + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @param description + * Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<Description> getSubClasses(Description description); + + /** + * Computes and returns the object property hierarchy of the knowledge base. + * @return The object property hierarchy of the knowlege base. + */ + public ObjectPropertyHierarchy getObjectPropertyHierarchy(); + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) + * @param objectProperty + * Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<ObjectProperty> getSuperProperties(ObjectProperty objectProperty); + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) + * @param objectProperty + * Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<ObjectProperty> getSubProperties(ObjectProperty objectProperty); + + /** + * TODO Outdated in OWL 2, because the universal role is the most general. + * @see ObjectPropertyHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<ObjectProperty> getMostGeneralProperties(); + + /** + * TODO Outdated in OWL, because the bottom role is the most specific. + * @see ObjectPropertyHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<ObjectProperty> getMostSpecialProperties(); + + /** + * Computes and returns the data property hierarchy of the knowledge base. + * @return The data property hierarchy of the knowlege base. + */ + public DatatypePropertyHierarchy getDatatypePropertyHierarchy(); + + /** + * Returns more general concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreGeneralRoles(ObjectProperty) + * @param dataProperty + * Atomic concept, top, or bottom. + * @return A set of more general concepts. + */ + public SortedSet<DatatypeProperty> getSuperProperties(DatatypeProperty dataProperty); + + /** + * Returns more special concepts in the subsumption hierarchy. + * + * @see ObjectPropertyHierarchy#getMoreSpecialRoles(ObjectProperty) + * @param dataProperty + * Atomic concept, top, or bottom. + * @return A set of more special concepts. + */ + public SortedSet<DatatypeProperty> getSubProperties(DatatypeProperty dataProperty); + + /** + * @see ObjectPropertyHierarchy#getMostGeneralRoles() + * @return The most general roles. + */ + public TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties(); + + /** + * @see ObjectPropertyHierarchy#getMostSpecialRoles() + * @return The most special roles. + */ + public TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties(); + } Modified: trunk/src/dl-learner/org/dllearner/core/options/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/BooleanConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; /** Modified: trunk/src/dl-learner/org/dllearner/core/options/CommonConfigMappings.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/CommonConfigMappings.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/CommonConfigMappings.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import java.util.Set; import java.util.SortedSet; Modified: trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; Modified: trunk/src/dl-learner/org/dllearner/core/options/ConfigEntry.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/ConfigEntry.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; /** * A config entry is a configuration option and a value for the option. Modified: trunk/src/dl-learner/org/dllearner/core/options/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/ConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import java.util.SortedSet; import java.util.TreeSet; Modified: trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; /** Modified: trunk/src/dl-learner/org/dllearner/core/options/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/IntegerConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; /** Modified: trunk/src/dl-learner/org/dllearner/core/options/InvalidConfigOptionValueException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/InvalidConfigOptionValueException.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/InvalidConfigOptionValueException.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; /** Modified: trunk/src/dl-learner/org/dllearner/core/options/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/StringConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import java.util.Arrays; import java.util.Set; Modified: trunk/src/dl-learner/org/dllearner/core/options/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/StringSetConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import java.util.Set; import java.util.SortedSet; Modified: trunk/src/dl-learner/org/dllearner/core/options/StringTupleListConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/StringTupleListConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import java.util.List; import java.util.SortedSet; Modified: trunk/src/dl-learner/org/dllearner/core/options/URLConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/URLConfigOption.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/URLConfigOption.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import java.net.URL; import java.util.SortedSet; Modified: trunk/src/dl-learner/org/dllearner/core/options/UnknownConfigOptionException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/UnknownConfigOptionException.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/core/options/UnknownConfigOptionException.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.core.config; +package org.dllearner.core.options; import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -36,8 +36,8 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -33,9 +33,9 @@ import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -31,7 +31,7 @@ import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; -import org.dllearner.core.config.*; +import org.dllearner.core.options.*; import org.dllearner.gui.widgets.WidgetPanelBoolean; import org.dllearner.gui.widgets.WidgetPanelDefault; import org.dllearner.gui.widgets.WidgetPanelDouble; Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/AbstractWidgetPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/AbstractWidgetPanel.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/AbstractWidgetPanel.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -23,9 +23,9 @@ import javax.swing.JPanel; import org.dllearner.core.Component; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.options.ConfigEntry; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.gui.Config; /** Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelBoolean.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelBoolean.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -25,12 +25,12 @@ import javax.swing.JComboBox; import org.dllearner.core.Component; -import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.gui.Config; /** * Panel for option Boolean, defined in - * {@link org.dllearner.core.config.BooleanConfigOption}. + * {@link org.dllearner.core.options.BooleanConfigOption}. * * @author Jens Lehmann * @author Tilo Hielscher Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDefault.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDefault.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDefault.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -24,7 +24,7 @@ import javax.swing.JLabel; import org.dllearner.core.Component; -import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.options.ConfigOption; import org.dllearner.gui.Config; /** Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDouble.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDouble.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelDouble.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -28,12 +28,12 @@ import javax.swing.JTextField; import org.dllearner.core.Component; -import org.dllearner.core.config.DoubleConfigOption; +import org.dllearner.core.options.DoubleConfigOption; import org.dllearner.gui.Config; /** * Panel for option Double, defined in - * {@link org.dllearner.core.config.DoubleConfigOption}. + * {@link org.dllearner.core.options.DoubleConfigOption}. * * @author Tilo Hielscher * Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelInteger.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelInteger.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -28,7 +28,7 @@ import javax.swing.JTextField; import org.dllearner.core.Component; -import org.dllearner.core.config.IntegerConfigOption; +import org.dllearner.core.options.IntegerConfigOption; import org.dllearner.gui.Config; /** Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelString.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelString.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -27,12 +27,12 @@ import javax.swing.JTextField; import org.dllearner.core.Component; -import org.dllearner.core.config.StringConfigOption; +import org.dllearner.core.options.StringConfigOption; import org.dllearner.gui.Config; /** * Panel for option String, defined in - * {@link org.dllearner.core.config.StringConfigOption}. + * {@link org.dllearner.core.options.StringConfigOption}. * * @author Jens Lehmann * @author Tilo Hielscher Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringSet.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -38,7 +38,7 @@ import javax.swing.JTextField; import org.dllearner.core.Component; -import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.options.StringSetConfigOption; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringTupleList.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringTupleList.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelStringTupleList.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -38,7 +38,7 @@ import javax.swing.JTextField; import org.dllearner.core.Component; -import org.dllearner.core.config.StringTupleListConfigOption; +import org.dllearner.core.options.StringTupleListConfigOption; import org.dllearner.gui.Config; import org.dllearner.utilities.datastructures.StringTuple; Modified: trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java 2008-11-10 18:09:19 UTC (rev 1504) +++ trunk/src/dl-learner/org/dllearner/gui/widgets/WidgetPanelURL.java 2008-11-11 10:59:23 UTC (rev 1505) @@ -30,7 +30,7 @@ import javax.swing.JTextField; import org.dllearner.core.Component; -import org.dllearner.core.config.URLConfigOption; +import org.dllearner.core.options.URLConfigOption; import org.dllearner.gui.Config; import org.dllearner.gui.ExampleFileChooser; import org.dllearner.kb.OWLFile; Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.... [truncated message content] |
From: <jen...@us...> - 2008-11-11 12:57:23
|
Revision: 1506 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1506&view=rev Author: jenslehmann Date: 2008-11-11 12:57:12 +0000 (Tue, 11 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN partially broken Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java Modified: trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -23,6 +23,9 @@ import java.util.Set; import java.util.SortedSet; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -60,6 +63,37 @@ public Set<ObjectProperty> getObjectProperties(); /** + * Gets all data properties in the knowledge base, e.g. hasIncome, height. + * @return All data properties in KB. + */ + public SortedSet<DatatypeProperty> getDatatypeProperties(); + + /** + * Gets all data properties with range xsd:boolean. + * @see org.dllearner.core.owl.Datatype#BOOLEAN + * @return Boolean data properties in KB. + */ + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties(); + + /** + * Gets all data properties with range xsd:double. + * TODO We could extend this to all types, which can be parsed into + * a double value, e.g. floats. + * @see org.dllearner.core.owl.Datatype#DOUBLE + * @return Double data properties in KB. + */ + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties(); + + /** + * Gets all data properties with range xsd:int. + * TODO We could extend this to all types, which can be parsed into + * Integers, e.g. xsd:integer, xsd:negativeInteger, xsd:nonNegativeInteger etc. + * @see org.dllearner.core.owl.Datatype#INT + * @return Integer data properties in KB. + */ + public SortedSet<DatatypeProperty> getIntDatatypeProperties(); + + /** * Gets all individuals in the knowledge base, e.g. Eric, London, Car829. * @return All individuals in KB. */ @@ -81,4 +115,11 @@ */ public Map<String, String> getPrefixes(); + /** + * Returns the RDFS labels of an entity. + * @param entity An entity, e.g. Machine. + * @return All values of rdfs:label for the entity, e.g. {"Machine"@en, "Maschine"@de}. + */ + public Set<Constant> getLabel(Entity entity); + } Modified: trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -19,12 +19,16 @@ */ package org.dllearner.core; +import java.util.Map; import java.util.Set; import java.util.SortedSet; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.utilities.datastructures.SortedSetTuple; /** @@ -81,4 +85,92 @@ * @return All instances of the class description and its negation. */ public SortedSetTuple<Individual> doubleRetrieval(Description description); + + /** + * Returns the set of individuals, which are connect to the given individual + * with the specified object property. + * @param individual An individual, e.g. eric. + * @param objectProperty An object property, e.g. hasChild. + * @return A set of individuals, e.g. {anna, maria}. + */ + public Set<Individual> getRelatedIndividuals(Individual individual, + ObjectProperty objectProperty); + + /** + * Returns the set of individuals, which are connect to the given individual + * with the specified data property. + * @param individual An individual, e.g. eric. + * @param datatyoeProperty A data property, e.g. hasIncome. + * @return A set of individuals, e.g. {48000^^xsd:int}. + */ + public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty); + + /** + * Computes and returns all connections between individuals through the specified + * property, e.g. {eric => {maria, anna}, anna => {eric}}. + * @param objectProperty An object property. + * @return The mapping of individuals to other individuals through this object property. + */ + public Map<Individual, SortedSet<Individual>> getPropertyMembers(ObjectProperty objectProperty); + + /** + * Computes and returns all connections between individuals and values through the + * specified property, e.g. {eric => {48000^^xsd:int}, sarah => {56000^^xsd:int}}. + * @param datatypeProperty A data property. + * @return The mapping between individuals and values through the given property. + */ + public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty); + + /** + * Convenience method, which can be used if it is known that the property has + * values which can be parsed as double. + * @see #getDatatypeMembers(DatatypeProperty) + * @see Double#valueOf(String) + * @param datatypeProperty A data property. + * @return The mapping between individuals and double values through the given property. + */ + public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty); + + /** + * Convenience method, which can be used if it is known that the property has + * values which can be parsed as integer. + * @see #getDatatypeMembers(DatatypeProperty) + * @see Integer#valueOf(String) + * @param datatypeProperty A data property. + * @return The mapping between individuals and integer values through the given property. + */ + public Map<Individual, SortedSet<Integer>> getIntDatatypeMembers(DatatypeProperty datatypeProperty); + + /** + * Convenience method, which can be used if it is known that the property has + * values which can be parsed as boolean value. Only "true" or "false" are + * accepted. If other values occur, a warning will be issued. + * @see #getDatatypeMembers(DatatypeProperty) + * @param datatypeProperty A data property. + * @return The mapping between individuals and boolean values through the given property. + */ + public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty); + + /** + * Convenience method, which can be used to get all individuals, which have value + * "true" for the given property. Usually, data properties can have several values + * for a given individual, but this method will throw a runtime exception if this + * is the case (i.e. the set of values is {"true", "false"}). + * @see #getDatatypeMembers(DatatypeProperty) + * @param datatypeProperty A data property. + * @return The set of individuals for which the boolean property holds. + */ + public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty); + + /** + * Convenience method, which can be used to get all individuals, which have value + * "false" for the given property. Usually, data properties can have several values + * for a given individual, but this method will throw a runtime exception if this + * is the case (i.e. the set of values is {"true", "false"}). + * @see #getDatatypeMembers(DatatypeProperty) + * @param datatypeProperty A data property. + * @return The set of individuals for which the boolean property does not hold. + */ + public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty); + } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -328,7 +328,7 @@ throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - + @Override public final SortedSet<Individual> hasType(Description concept, Set<Individual> s) { // logger.debug("instanceCheck "+concept.toKBSyntaxString()); @@ -356,9 +356,23 @@ returnSet.add(individual); } return returnSet; - } + } @Override + public final Set<NamedClass> getInconsistentClasses() { + try { + return getInconsistentClassesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + protected Set<NamedClass> getInconsistentClassesImpl() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override public final boolean isSatisfiable() { reasoningStartTimeTmp = System.nanoTime(); boolean result; @@ -376,10 +390,11 @@ protected boolean isSatisfiableImpl() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); - } - - public Set<Individual> getRelatedIndividuals(Individual individual, - ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + } + + @Override + public final Set<Individual> getRelatedIndividuals(Individual individual, + ObjectProperty objectProperty) { try { return getRelatedIndividualsImpl(individual, objectProperty); } catch (ReasoningMethodUnsupportedException e) { @@ -388,8 +403,14 @@ } } - public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) - throws ReasoningMethodUnsupportedException { + protected Set<Individual> getRelatedIndividualsImpl(Individual individual, + ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override + public final Set<Constant> getRelatedValues(Individual individual, + DatatypeProperty datatypeProperty) { try { return getRelatedValuesImpl(individual, datatypeProperty); } catch (ReasoningMethodUnsupportedException e) { @@ -398,7 +419,13 @@ } } - public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + protected Set<Constant> getRelatedValuesImpl(Individual individual, + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override + public final Set<Constant> getLabel(Entity entity) { try { return getLabelImpl(entity); } catch (ReasoningMethodUnsupportedException e) { @@ -407,11 +434,16 @@ } } - public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + protected Set<Constant> getLabelImpl(Entity entity) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override + public final Map<Individual, SortedSet<Individual>> getPropertyMembers(ObjectProperty atomicRole) { reasoningStartTimeTmp = System.nanoTime(); Map<Individual, SortedSet<Individual>> result; try { - result = getRoleMembersImpl(atomicRole); + result = getPropertyMembersImpl(atomicRole); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); return null; @@ -422,152 +454,74 @@ return result; } - public abstract boolean hasDatatypeSupport(); - - public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers( - DatatypeProperty datatypeProperty) { - try { - return getDoubleDatatypeMembersImpl(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } + protected Map<Individual, SortedSet<Individual>> getPropertyMembersImpl( + ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); } - public Map<Individual, SortedSet<Integer>> getIntDatatypeMembers( + @Override + public final Map<Individual, SortedSet<Constant>> getDatatypeMembers( DatatypeProperty datatypeProperty) { try { - return getIntDatatypeMembersImpl(datatypeProperty); + return getDatatypeMembersImpl(datatypeProperty); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); return null; } } - public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) { - try { - return getTrueDatatypeMembersImpl(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } + protected Map<Individual, SortedSet<Constant>> getDatatypeMembersImpl( + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); } - public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) { + @Override + public final Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers( + DatatypeProperty datatypeProperty) { try { - return getFalseDatatypeMembersImpl(datatypeProperty); + return getDoubleDatatypeMembersImpl(datatypeProperty); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); return null; } } - public SortedSet<DatatypeProperty> getDatatypeProperties() { - try { - return getDatatypePropertiesImpl(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; + protected Map<Individual, SortedSet<Double>> getDoubleDatatypeMembersImpl( + DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); + Map<Individual, SortedSet<Double>> ret = new TreeMap<Individual, SortedSet<Double>>(); + for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + SortedSet<Double> valuesDouble = new TreeSet<Double>(); + for (Constant c : values) { + double v = Double.valueOf(c.getLiteral()); + valuesDouble.add(v); + } + ret.put(e.getKey(), valuesDouble); } + return ret; } - public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { + @Override + public final Map<Individual, SortedSet<Integer>> getIntDatatypeMembers( + DatatypeProperty datatypeProperty) { try { - return getBooleanDatatypePropertiesImpl(); + return getIntDatatypeMembersImpl(datatypeProperty); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); return null; } } - public SortedSet<DatatypeProperty> getIntDatatypeProperties() { - try { - return getIntDatatypePropertiesImpl(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { - try { - return getDoubleDatatypePropertiesImpl(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Description getDomain(ObjectProperty objectProperty) { - try { - return getDomainImpl(objectProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Description getDomain(DatatypeProperty datatypeProperty) { - try { - return getDomainImpl(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Description getRange(ObjectProperty objectProperty) { - try { - return getRangeImpl(objectProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public DataRange getRange(DatatypeProperty datatypeProperty) { - try { - return getRangeImpl(datatypeProperty); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); - return null; - } - } - - public Set<Individual> getRelatedIndividualsImpl(Individual individual, - ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Constant> getRelatedValuesImpl(Individual individual, + protected Map<Individual, SortedSet<Integer>> getIntDatatypeMembersImpl( DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Set<Constant> getLabelImpl(Entity entity) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Map<Individual, SortedSet<Individual>> getRoleMembersImpl(ObjectProperty atomicRole) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - public Map<Individual, SortedSet<Constant>> getDatatypeMembersImpl( - DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - - // convenience method to get int value mappings of a datatype property - public Map<Individual, SortedSet<Integer>> getIntDatatypeMembersImpl( - DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); Map<Individual, SortedSet<Integer>> ret = new TreeMap<Individual, SortedSet<Integer>>(); for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { SortedSet<Constant> values = e.getValue(); SortedSet<Integer> valuesInt = new TreeSet<Integer>(); for (Constant c : values) { - int v = Integer.parseInt(c.getLiteral()); + int v = Integer.valueOf(c.getLiteral()); valuesInt.add(v); } ret.put(e.getKey(), valuesInt); @@ -575,25 +529,18 @@ return ret; } - // convenience method to get double value mappings of a datatype property - public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembersImpl( - DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { - Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); - Map<Individual, SortedSet<Double>> ret = new TreeMap<Individual, SortedSet<Double>>(); - for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { - SortedSet<Constant> values = e.getValue(); - SortedSet<Double> valuesDouble = new TreeSet<Double>(); - for (Constant c : values) { - double v = Double.parseDouble(c.getLiteral()); - valuesDouble.add(v); - } - ret.put(e.getKey(), valuesDouble); + @Override + public final Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers( + DatatypeProperty datatypeProperty) { + try { + return getBooleanDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; } - return ret; } - // convenience method to get boolean value mappings of a datatype property - public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembersImpl( + protected Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembersImpl( DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); Map<Individual, SortedSet<Boolean>> ret = new TreeMap<Individual, SortedSet<Boolean>>(); @@ -601,124 +548,203 @@ SortedSet<Constant> values = e.getValue(); SortedSet<Boolean> valuesBoolean = new TreeSet<Boolean>(); for (Constant c : values) { - boolean v = Boolean.parseBoolean(c.getLiteral()); - valuesBoolean.add(v); + String s = c.getLiteral(); + if (s.equalsIgnoreCase("true")) { + valuesBoolean.add(true); + } else if (s.equalsIgnoreCase("false")) { + valuesBoolean.add(false); + } else { + logger.warn("Requested to parse boolean value of property " + datatypeProperty + + ", but " + c + " could not be parsed successfully."); + } } ret.put(e.getKey(), valuesBoolean); } return ret; } - // convenience method returning those values which have value "true" for - // this - // datatype property - public SortedSet<Individual> getTrueDatatypeMembersImpl(DatatypeProperty datatypeProperty) + @Override + public final SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return getTrueDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + protected SortedSet<Individual> getTrueDatatypeMembersImpl(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); SortedSet<Individual> ret = new TreeSet<Individual>(); for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { SortedSet<Constant> values = e.getValue(); - for (Constant c : values) { - boolean v = Boolean.parseBoolean(c.getLiteral()); - if (v == true) + if (values.size() > 1) { + logger.warn("Property " + datatypeProperty + " has value " + e.getValue() + + ". Cannot determine whether it is true."); + } else { + if (values.first().getLiteral().equalsIgnoreCase("true")) { ret.add(e.getKey()); + } } } return ret; } - // convenience method returning those values which have value "false" for - // this - // datatype property - public SortedSet<Individual> getFalseDatatypeMembersImpl(DatatypeProperty datatypeProperty) + @Override + public final SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return getFalseDatatypeMembersImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + protected SortedSet<Individual> getFalseDatatypeMembersImpl(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembersImpl(datatypeProperty); SortedSet<Individual> ret = new TreeSet<Individual>(); for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { SortedSet<Constant> values = e.getValue(); - for (Constant c : values) { - boolean v = Boolean.parseBoolean(c.getLiteral()); - if (v == false) + if (values.size() > 1) { + logger.warn("Property " + datatypeProperty + " has value " + e.getValue() + + ". Cannot determine whether it is false."); + } else { + if (values.first().getLiteral().equalsIgnoreCase("false")) { ret.add(e.getKey()); + } } } return ret; } + @Override + public final SortedSet<DatatypeProperty> getDatatypeProperties() { + try { + return getDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } - public SortedSetTuple<Individual> doubleRetrievalImpl(Description concept, Description adc) + protected SortedSet<DatatypeProperty> getDatatypePropertiesImpl() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } + @Override + public final SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { + try { + return getBooleanDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } - - - - public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) + // TODO Even if there is a small performance penalty, we could implement + // the method right here by iterating over all data properties and + // querying their ranges. At least, this should be done once we have a + // reasoner independant of OWL API with datatype support. + protected SortedSet<DatatypeProperty> getBooleanDatatypePropertiesImpl() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedDatatypeProperties) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); + @Override + public final SortedSet<DatatypeProperty> getIntDatatypeProperties() { + try { + return getIntDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } } - public ObjectPropertyHierarchy getRoleHierarchyImpl() + protected SortedSet<DatatypeProperty> getIntDatatypePropertiesImpl() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public DatatypePropertyHierarchy getDatatypePropertyHierarchyImpl() - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); + @Override + public final SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { + try { + return getDoubleDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } } - public Description getDomainImpl(ObjectProperty objectProperty) + protected SortedSet<DatatypeProperty> getDoubleDatatypePropertiesImpl() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public Description getDomainImpl(DatatypeProperty datatypeProperty) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); + @Override + public final Description getDomain(ObjectProperty objectProperty) { + try { + return getDomainImpl(objectProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } } - public Description getRangeImpl(ObjectProperty objectProperty) + protected Description getDomainImpl(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public DataRange getRangeImpl(DatatypeProperty datatypeProperty) - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); + @Override + public final Description getDomain(DatatypeProperty datatypeProperty) { + try { + return getDomainImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } } - public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() + protected Description getDomainImpl(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public SortedSet<DatatypeProperty> getBooleanDatatypePropertiesImpl() - throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); + @Override + public final Description getRange(ObjectProperty objectProperty) { + try { + return getRangeImpl(objectProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } } - public SortedSet<DatatypeProperty> getDoubleDatatypePropertiesImpl() + protected Description getRangeImpl(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public SortedSet<DatatypeProperty> getIntDatatypePropertiesImpl() + @Override + public final DataRange getRange(DatatypeProperty datatypeProperty) { + try { + return getRangeImpl(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + protected DataRange getRangeImpl(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public Set<NamedClass> getInconsistentClassesImpl() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException(); - } - + + @Override public final SortedSet<Description> getSuperClasses(Description concept) { return getClassHierarchy().getMoreGeneralConcepts(concept); @@ -769,7 +795,16 @@ return getDatatypePropertyHierarchy().getMostSpecialRoles(); } - protected ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { + /** + * Creates the class hierarchy. Invoking this method is optional (if not + * called explicitly, it is called the first time, it is needed). + * + * @return The class hierarchy. + * @throws ReasoningMethodUnsupportedException + * Thrown if subsumption hierarchy creation is not supported by + * the reasoner. + */ + public ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException( "Subsumption hierarchy creation not supported by this reasoner."); } @@ -780,7 +815,7 @@ if (subsumptionHierarchy == null) { subsumptionHierarchy = prepareSubsumptionHierarchy(); } -// subsumptionHierarchy = getSubsumptionHierarchyImpl(); + // subsumptionHierarchy = getSubsumptionHierarchyImpl(); } catch (ReasoningMethodUnsupportedException e) { handleExceptions(e); } @@ -788,11 +823,17 @@ return subsumptionHierarchy; } -// public ClassHierarchy getSubsumptionHierarchyImpl() throws ReasoningMethodUnsupportedException { -// throw new ReasoningMethodUnsupportedException(); -// } - - protected ObjectPropertyHierarchy prepareRoleHierarchy() throws ReasoningMethodUnsupportedException { + /** + * Creates the object property hierarchy. Invoking this method is optional + * (if not called explicitly, it is called the first time, it is needed). + * + * @return The object property hierarchy. + * @throws ReasoningMethodUnsupportedException + * Thrown if object property hierarchy creation is not supported + * by the reasoner. + */ + public ObjectPropertyHierarchy prepareRoleHierarchy() + throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException( "Object property hierarchy creation not supported by this reasoner."); } @@ -809,7 +850,17 @@ return roleHierarchy; } - protected DatatypePropertyHierarchy prepareDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { + /** + * Creates the data property hierarchy. Invoking this method is optional (if + * not called explicitly, it is called the first time, it is needed). + * + * @return The data property hierarchy. + * @throws ReasoningMethodUnsupportedException + * Thrown if data property hierarchy creation is not supported + * by the reasoner. + */ + public DatatypePropertyHierarchy prepareDatatypePropertyHierarchy() + throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException( "Datatype property hierarchy creation not supported by this reasoner."); } @@ -824,8 +875,8 @@ } } return datatypePropertyHierarchy; - } - + } + public List<NamedClass> getAtomicConceptsList() { if (atomicConceptsList == null) atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); @@ -880,10 +931,6 @@ return subsumptionReasoningTimeNs; } - /* - * public long getSubsumptionHierarchyTimeNs() { return - * subsumptionHierarchyTimeNs; } - */ public int getNrOfSubsumptionHierarchyQueries() { return nrOfSubsumptionHierarchyQueries; } Modified: trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -23,10 +23,12 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; @@ -39,6 +41,43 @@ public interface SchemaReasoner { /** + * Returns all named classes, which are not satisfiable, i.e. cannot + * have instances. + * @return The set of inconsistent classes. + */ + public Set<NamedClass> getInconsistentClasses(); + + /** + * Returns the domain of this object property. (Theoretically, there could + * be more than one domain axiom. However, this can be considered a modelling + * error.) + * @param objectProperty An object property in the knowledge base. + * @return The rdfs:domain of <code>objectProperty</code> + */ + public Description getDomain(ObjectProperty objectProperty); + + /** + * Returns the domain of this data property. + * @param datatypeProperty An data property in the knowledge base. + * @return The rdfs:domain of <code>datatypeProperty</code> + */ + public Description getDomain(DatatypeProperty datatypeProperty); + + /** + * Returns the range of this object property. + * @param objectProperty An object property in the knowledge base. + * @return The rdfs:range of <code>objectProperty</code> + */ + public Description getRange(ObjectProperty objectProperty); + + /** + * Returns the range of this data property. + * @param datatypeProperty An data property in the knowledge base. + * @return The rdfs:range of <code>datatypeProperty</code> + */ + public DataRange getRange(DatatypeProperty datatypeProperty); + + /** * Checks whether <code>superClass</code> is a super class of <code>subClass</code>. * @param superClass The (supposed) super class. * @param subClass The (supposed) sub class. Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/NaturalLanguageDescriptionConvertVisitor.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -5,7 +5,6 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.ADC; import org.dllearner.core.ComponentManager; -import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; @@ -85,18 +84,18 @@ private String getLabelFromReasoner(Entity ent) { String label; - try{ +// try{ Set<Constant> set=service.getLabel(ent); if (set.size()>0){ Iterator<Constant> iter=set.iterator(); label=iter.next().getLiteral(); } else label=""; - } - catch (ReasoningMethodUnsupportedException e) - { - label=""; - } +// } +// catch (ReasoningMethodUnsupportedException e) +// { +// label=""; +// } return label; } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -699,7 +699,7 @@ // das in Responsegroup auch nicht definiert // => deswegen wird hier die XML-Cursor-API verwendet @Override - public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { String relatedIndividualsDIG = asksPrefix; relatedIndividualsDIG += "<relatedIndividuals id=\"related_individuals\">"; relatedIndividualsDIG += "<ratom name=\"" + atomicRole.getName() + "\" />"; @@ -800,9 +800,9 @@ return null; } - @Override - public boolean hasDatatypeSupport() { - return false; - } +// @Override +// public boolean hasDatatypeSupport() { +// return false; +// } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -221,7 +221,7 @@ logger.debug("dematerialising object properties"); for (ObjectProperty atomicRole : atomicRoles) { - opPos.put(atomicRole, rc.getRoleMembers(atomicRole)); + opPos.put(atomicRole, rc.getPropertyMembers(atomicRole)); } logger.debug("dematerialising datatype properties"); @@ -499,11 +499,11 @@ return atomicConcepts; } - @Override - public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers( - DatatypeProperty datatypeProperty) { - return rc.getDoubleDatatypeMembers(datatypeProperty); - } +// @Override +// public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembersImpl( +// DatatypeProperty datatypeProperty) { +// return rc.getDoubleDatatypeMembers(datatypeProperty); +// } /* * (non-Javadoc) @@ -516,22 +516,22 @@ } @Override - public SortedSet<DatatypeProperty> getDatatypeProperties() { + public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() { return datatypeProperties; } @Override - public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { + public SortedSet<DatatypeProperty> getBooleanDatatypePropertiesImpl() { return booleanDatatypeProperties; } @Override - public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { + public SortedSet<DatatypeProperty> getDoubleDatatypePropertiesImpl() { return doubleDatatypeProperties; } @Override - public SortedSet<DatatypeProperty> getIntDatatypeProperties() { + public SortedSet<DatatypeProperty> getIntDatatypePropertiesImpl() { return intDatatypeProperties; } @@ -565,20 +565,20 @@ // return rc.getClassHierarchy(); // } - @Override - public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) { - rc.prepareRoleHierarchy(allowedRoles); - } +// @Override +// public void prepareRoleHierarchyImpl(Set<ObjectProperty> allowedRoles) { +// rc.prepareRoleHierarchy(allowedRoles); +// } // @Override // public ObjectPropertyHierarchy getRoleHierarchy() { // return rc.getRoleHierarchy(); // } - @Override - public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles) { - rc.prepareDatatypePropertyHierarchyImpl(allowedRoles); - } +// @Override +// public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles) { +// rc.prepareDatatypePropertyHierarchyImpl(allowedRoles); +// } // @Override // public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { @@ -642,37 +642,37 @@ } @Override - public Description getDomain(ObjectProperty objectProperty) { + public Description getDomainImpl(ObjectProperty objectProperty) { return rc.getDomain(objectProperty); } @Override - public Description getDomain(DatatypeProperty datatypeProperty) { + public Description getDomainImpl(DatatypeProperty datatypeProperty) { return rc.getDomain(datatypeProperty); } @Override - public Description getRange(ObjectProperty objectProperty) { + public Description getRangeImpl(ObjectProperty objectProperty) { return rc.getRange(objectProperty); } @Override - public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { return opPos.get(atomicRole); } @Override - public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { + public Set<Individual> getRelatedIndividualsImpl(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException { return rc.getRelatedIndividuals(individual, objectProperty); } @Override - public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + public Set<Constant> getRelatedValuesImpl(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { return rc.getRelatedValues(individual, datatypeProperty); } @Override - public Set<Constant> getLabel(Entity entity) throws ReasoningMethodUnsupportedException { + public Set<Constant> getLabelImpl(Entity entity) throws ReasoningMethodUnsupportedException { return rc.getLabel(entity); } @@ -686,10 +686,10 @@ rc.releaseKB(); } - @Override - public boolean hasDatatypeSupport() { - return true; - } +// @Override +// public boolean hasDatatypeSupport() { +// return true; +// } /* (non-Javadoc) * @see org.dllearner.core.ReasonerComponent#getTypesImpl(org.dllearner.core.owl.Individual) Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -208,8 +208,8 @@ rc.releaseKB(); } - @Override - public boolean hasDatatypeSupport() { - return true; - } +// @Override +// public boolean hasDatatypeSupport() { +// return true; +// } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -384,7 +384,7 @@ } @Override - public SortedSet<DatatypeProperty> getDatatypeProperties() { + public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() { return datatypeProperties; } @@ -512,8 +512,7 @@ // public ObjectPropertyHierarchy getRoleHierarchy() { // return roleHierarchy; // } - - @Override + public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles) { // code copied from DIG reasoner @@ -668,7 +667,7 @@ } @Override - public Description getDomain(ObjectProperty objectProperty) { + public Description getDomainImpl(ObjectProperty objectProperty) { OWLObjectProperty prop = getOWLAPIDescription(objectProperty); try { // TODO: look up why OWL API return a two dimensional set here @@ -687,7 +686,7 @@ } @Override - public Description getDomain(DatatypeProperty datatypeProperty) { + public Description getDomainImpl(DatatypeProperty datatypeProperty) { OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); try { // TODO: look up why OWL API return a two dimensional set here @@ -706,7 +705,7 @@ } @Override - public Description getRange(ObjectProperty objectProperty) { + public Description getRangeImpl(ObjectProperty objectProperty) { OWLObjectProperty prop = getOWLAPIDescription(objectProperty); try { Set<OWLDescription> set = reasoner.getRanges(prop); @@ -720,7 +719,7 @@ } @Override - public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { OWLObjectProperty prop = getOWLAPIDescription(atomicRole); Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); for(Individual i : individuals) { @@ -744,7 +743,7 @@ } @Override - public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) { + public Set<Individual> getRelatedIndividualsImpl(Individual individual, ObjectProperty objectProperty) { OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); OWLObjectProperty prop = getOWLAPIDescription(objectProperty); Set<OWLIndividual> inds = null; @@ -762,7 +761,7 @@ } @Override - public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty) { + public Set<Constant> getRelatedValuesImpl(Individual individual, DatatypeProperty datatypeProperty) { OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); Set<OWLConstant> constants = null; @@ -1009,7 +1008,7 @@ * @return the booleanDatatypeProperties */ @Override - public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { + public SortedSet<DatatypeProperty> getBooleanDatatypePropertiesImpl() { return booleanDatatypeProperties; } @@ -1017,7 +1016,7 @@ * @return the doubleDatatypeProperties */ @Override - public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { + public SortedSet<DatatypeProperty> getDoubleDatatypePropertiesImpl() { return doubleDatatypeProperties; } @@ -1025,7 +1024,7 @@ * @return the intDatatypeProperties */ @Override - public SortedSet<DatatypeProperty> getIntDatatypeProperties() { + public SortedSet<DatatypeProperty> getIntDatatypePropertiesImpl() { return intDatatypeProperties; } @@ -1065,10 +1064,10 @@ configurator.setReasonerType(type); }*/ - @Override - public boolean hasDatatypeSupport() { - return true; - } +// @Override +// public boolean hasDatatypeSupport() { +// return true; +// } @Override public Set<NamedClass> getInconsistentClassesImpl(){ @@ -1099,7 +1098,7 @@ @Override @SuppressWarnings("all") - public Set<Constant> getLabel(Entity entity) { + public Set<Constant> getLabelImpl(Entity entity) { OWLEntity owlEntity = getOWLAPIEntity(entity); Set<OWLAnnotation> labelAnnotations = owlEntity.getAnnotations(owlAPIOntologies.get(0), URI.create("http://www.w3.org/2000/01/rdf-schema#label")); Set<Constant> annotations = new HashSet<Constant>(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -217,7 +217,7 @@ valueFrequency.put(op, opMap); // sets ordered by corresponding individual (which we ignore) - Collection<SortedSet<Individual>> fillerSets = rs.getRoleMembers(op).values(); + Collection<SortedSet<Individual>> fillerSets = rs.getPropertyMembers(op).values(); for(SortedSet<Individual> fillerSet : fillerSets) { for(Individual i : fillerSet) { // System.out.println("op " + op + " i " + i); @@ -264,7 +264,7 @@ if(useCardinalityRestrictions) { for(ObjectProperty op : rs.getObjectProperties()) { int maxFillers = 0; - Map<Individual,SortedSet<Individual>> opMembers = rs.getRoleMembers(op); + Map<Individual,SortedSet<Individual>> opMembers = rs.getPropertyMembers(op); for(SortedSet<Individual> inds : opMembers.values()) { if(inds.size()>maxFillers) maxFillers = inds.size(); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -580,7 +580,7 @@ @WebMethod public String[] getIndividualsForARole(int id, String role) throws ClientNotKnownException { ClientState state = getState(id); - Map<Individual,SortedSet<Individual>> m = state.getReasonerComponent().getRoleMembers(new ObjectProperty(role)); + Map<Individual,SortedSet<Individual>> m = state.getReasonerComponent().getPropertyMembers(new ObjectProperty(role)); Set<Individual> individuals = m.keySet(); return Datastructures.sortedSet2StringListIndividuals(individuals); } Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -564,7 +564,7 @@ } for (ObjectProperty atomicRole : rs.getObjectProperties()) { - aBox.rolesPos.put(atomicRole.getName(), getStringMap(rs.getRoleMembers(atomicRole))); + aBox.rolesPos.put(atomicRole.getName(), getStringMap(rs.getPropertyMembers(atomicRole))); aBox.roles.add(atomicRole.getName()); } Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderOWL.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -250,7 +250,7 @@ public void makeNegativeExamplesFromDomain(ObjectProperty atomicRole){ fromDomain.clear(); logger.debug("making Negative Examples from Domain of : "+atomicRole); - fromDomain.addAll(reasoningService.getRoleMembers(atomicRole).keySet()); + fromDomain.addAll(reasoningService.getPropertyMembers(atomicRole).keySet()); fromDomain.removeAll(fullPositiveSet); logger.debug("|-neg Example size from Domain: "+this.fromDomain.size()); } @@ -265,7 +265,7 @@ public void makeNegativeExamplesFromRange(ObjectProperty atomicRole){ fromRange.clear(); logger.debug("making Negative Examples from Range of : "+atomicRole); - Collection<SortedSet<Individual>> tmp = reasoningService.getRoleMembers(atomicRole).values(); + Collection<SortedSet<Individual>> tmp = reasoningService.getPropertyMembers(atomicRole).values(); for (SortedSet<Individual> set : tmp) { fromRange.addAll(set); } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -96,7 +96,7 @@ // System.out.println(oneRole.getClass()); Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs - .getRoleMembers(oneRole); + .getPropertyMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); if (fillers.size() > 0) { @@ -126,7 +126,7 @@ // System.out.println(oneRole.getClass()); Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs - .getRoleMembers(oneRole); + .getPropertyMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); if (fillers.size() > 0) { @@ -177,7 +177,7 @@ // System.out.println(oneRole.getClass()); Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs - .getRoleMembers(oneRole); + .getPropertyMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); //if (fillers.size() > 0) { Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java 2008-11-11 10:59:23 UTC (rev 1505) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java 2008-11-11 12:57:12 UTC (rev 1506) @@ -59,7 +59,7 @@ for (ObjectProperty oneRole : allRoles) { Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs - .getRoleMembers(oneRole); + .getPropertyMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); // only where roles exist @@ -100,7 +100,7 @@ // collect info for roles and individuals for (ObjectProperty oneRole : allRoles) { Map<Individual, SortedSet<Individual>> allRoleMembers = this.rs - .getRoleMembers(oneRole); + .getPropertyMembers(oneRole); for (Individual oneInd : allRoleMembers.keySet()) { SortedSet<Individual> fillers = allRoleMembers.get(oneInd); if (fillers.size() > 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-11 16:17:30
|
Revision: 1507 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1507&view=rev Author: jenslehmann Date: 2008-11-11 16:17:24 +0000 (Tue, 11 Nov 2008) Log Message: ----------- - reasoner component redesign continued - SVN version should mostly be working again - subsumption hierarchy queries/caching has moved to ReasonerComponent (instead of the particular reasoner implementations) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -359,7 +359,7 @@ // during the run of the algorithm // reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getClassHierarchy().improveSubsumptionHierarchy(); + reasoner.getClassHierarchy().thinOutSubsumptionHierarchy(); // reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary // if(reasoner.hasDatatypeSupport()) Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -374,7 +374,7 @@ // during the run of the algorithm // reasoner.prepareSubsumptionHierarchy(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getClassHierarchy().improveSubsumptionHierarchy(); + reasoner.getClassHierarchy().thinOutSubsumptionHierarchy(); // reasoner.prepareRoleHierarchy(usedRoles); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -38,11 +38,14 @@ import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Thing; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.OWLVocabulary; /** @@ -366,12 +369,13 @@ handleExceptions(e); return null; } - } - - protected Set<NamedClass> getInconsistentClassesImpl() throws ReasoningMethodUnsupportedException { + } + + protected Set<NamedClass> getInconsistentClassesImpl() + throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); - } - + } + @Override public final boolean isSatisfiable() { reasoningStartTimeTmp = System.nanoTime(); @@ -743,18 +747,24 @@ throw new ReasoningMethodUnsupportedException(); } - - @Override public final SortedSet<Description> getSuperClasses(Description concept) { return getClassHierarchy().getMoreGeneralConcepts(concept); } + protected SortedSet<Description> getSuperClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + @Override public final SortedSet<Description> getSubClasses(Description concept) { return getClassHierarchy().getMoreSpecialConcepts(concept); } + protected SortedSet<Description> getSubClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + @Override public final SortedSet<ObjectProperty> getSuperProperties(ObjectProperty role) { return getObjectPropertyHierarchy().getMoreGeneralRoles(role); @@ -800,26 +810,54 @@ * called explicitly, it is called the first time, it is needed). * * @return The class hierarchy. - * @throws ReasoningMethodUnsupportedException - * Thrown if subsumption hierarchy creation is not supported by - * the reasoner. + * @throws ReasoningMethodUnsupportedException */ - public ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { - throw new ReasoningMethodUnsupportedException( - "Subsumption hierarchy creation not supported by this reasoner."); + public final ClassHierarchy prepareSubsumptionHierarchy() throws ReasoningMethodUnsupportedException { + ConceptComparator conceptComparator = new ConceptComparator(); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + + // refinements of top + SortedSet<Description> tmp = getSubClassesImpl(Thing.instance); + subsumptionHierarchyDown.put(new Thing(), tmp); + + // refinements of bottom + tmp = getSuperClassesImpl(Nothing.instance); + subsumptionHierarchyUp.put(new Nothing(), tmp); + + // refinements of atomic concepts + Set<NamedClass> atomicConcepts = getNamedClasses(); + for (NamedClass atom : atomicConcepts) { + tmp = getSubClassesImpl(atom); + // quality control: we explicitly check that no reasoner implementation returns null here + if(tmp == null) { + logger.error("Class hierarchy: getSubClasses returned null instead of empty set."); + } + subsumptionHierarchyDown.put(atom, tmp); + + tmp = getSuperClassesImpl(atom); + // quality control: we explicitly check that no reasoner implementation returns null here + if(tmp == null) { + logger.error("Class hierarchy: getSuperClasses returned null instead of empty set."); + } + subsumptionHierarchyUp.put(atom, tmp); + } + + return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); } @Override public final ClassHierarchy getClassHierarchy() { - try { - if (subsumptionHierarchy == null) { + // class hierarchy is created on first invocation + if (subsumptionHierarchy == null) { + try { subsumptionHierarchy = prepareSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } - // subsumptionHierarchy = getSubsumptionHierarchyImpl(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); } - return subsumptionHierarchy; } @@ -840,13 +878,15 @@ @Override public final ObjectPropertyHierarchy getObjectPropertyHierarchy() { - if (roleHierarchy == null) { - try { - prepareRoleHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); + + try { + if (roleHierarchy == null) { + roleHierarchy = prepareRoleHierarchy(); } + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } + return roleHierarchy; } @@ -867,13 +907,15 @@ @Override public final DatatypePropertyHierarchy getDatatypePropertyHierarchy() { - if (datatypePropertyHierarchy == null) { - try { + + try { + if (datatypePropertyHierarchy == null) { prepareDatatypePropertyHierarchy(); - } catch (ReasoningMethodUnsupportedException e) { - handleExceptions(e); } + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); } + return datatypePropertyHierarchy; } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -23,98 +23,136 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.Map.Entry; +import org.apache.log4j.Logger; import org.dllearner.utilities.owl.ConceptComparator; /** * Represents a subsumption hierarchy (ignoring equivalent concepts). - * + * * @author Jens Lehmann - * + * */ public class ClassHierarchy { + public static Logger logger = Logger.getLogger(ClassHierarchy.class); + ConceptComparator conceptComparator = new ConceptComparator(); - TreeMap<Description,TreeSet<Description>> subsumptionHierarchyUp; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Description,TreeSet<Description>> subsumptionHierarchyDown; // = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - Set<Description> allowedConceptsInSubsumptionHierarchy; + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp; + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown; - public ClassHierarchy(Set<NamedClass> atomicConcepts, TreeMap<Description,TreeSet<Description>> subsumptionHierarchyUp , TreeMap<Description,TreeSet<Description>> subsumptionHierarchyDown) { + /** + * The arguments specify the superclasses and subclasses of each class. This + * is used to build the subsumption hierarchy. + * @param subsumptionHierarchyUp Contains super classes for each class. + * @param subsumptionHierarchyDown Contains sub classes for each class. + */ + public ClassHierarchy( + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp, + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown) { + this.subsumptionHierarchyUp = subsumptionHierarchyUp; - this.subsumptionHierarchyDown = subsumptionHierarchyDown; - allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(atomicConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Thing()); - allowedConceptsInSubsumptionHierarchy.add(new Nothing()); + } + + public SortedSet<Description> getMoreGeneralConcepts(Description concept) { + SortedSet<Description> result = subsumptionHierarchyUp.get(concept); + if(result == null) { + logger.error("Query for super class of " + concept + " in subsumption hierarchy, but the class is not contained in the (upward) hierarchy"); + } - @SuppressWarnings("unchecked") - public SortedSet<Description> getMoreGeneralConcepts(Description concept) { - // we clone all concepts before returning them such that they cannot be + // we copy all concepts before returning them such that they cannot be // modified externally - return (TreeSet<Description>) subsumptionHierarchyUp.get(concept).clone(); + return new TreeSet<Description>(result); } - - @SuppressWarnings("unchecked") + public SortedSet<Description> getMoreSpecialConcepts(Description concept) { - if(subsumptionHierarchyDown==null) { return new TreeSet<Description>();} - else if( subsumptionHierarchyDown.get(concept)==null){ return new TreeSet<Description>();} - else {return (TreeSet<Description>) subsumptionHierarchyDown.get(concept).clone();} - } - - public void improveSubsumptionHierarchy() { - TreeMap<Description,TreeSet<Description>> hierarchyDownNew = new TreeMap<Description,TreeSet<Description>>(conceptComparator); - // hierarchyDownNew.put(new Top(), new TreeSet<Concept>(conceptComparator)); - TreeMap<Description,TreeSet<Description>> hierarchyUpNew = new TreeMap<Description,TreeSet<Description>>(conceptComparator); + SortedSet<Description> result = subsumptionHierarchyDown.get(concept); + if(result == null) { + logger.error("Query for sub class of " + concept + " in subsumption hierarchy, but the class is not contained in the (downward) hierarchy"); + } - // Einträge für alle Konzepte machen (init) - for(Description c : allowedConceptsInSubsumptionHierarchy) { - hierarchyDownNew.put(c, new TreeSet<Description>(conceptComparator)); - hierarchyUpNew.put(c, new TreeSet<Description>(conceptComparator)); + return new TreeSet<Description>(result); + + // commented out, because these hacks just worked around a problem +// if (subsumptionHierarchyDown == null) { +// return new TreeSet<Description>(); +// } else if (subsumptionHierarchyDown.get(concept) == null) { +// return new TreeSet<Description>(); +// } else { +// return (TreeSet<Description>) subsumptionHierarchyDown.get(concept).clone(); +// } + } + + /** + * This method modifies the subsumption hierarchy such that for each class, + * there is only a single path to reach it via upward and downward + * refinement respectively. + */ + public void thinOutSubsumptionHierarchy() { + TreeMap<Description, SortedSet<Description>> hierarchyDownNew = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + TreeMap<Description, SortedSet<Description>> hierarchyUpNew = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + + Set<Description> conceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); + conceptsInSubsumptionHierarchy.addAll(subsumptionHierarchyUp.keySet()); + conceptsInSubsumptionHierarchy.addAll(subsumptionHierarchyDown.keySet()); + + // add empty sets for each concept + for (Description c : conceptsInSubsumptionHierarchy) { + hierarchyDownNew.put(c, new TreeSet<Description>(conceptComparator)); + hierarchyUpNew.put(c, new TreeSet<Description>(conceptComparator)); } - - for(Description c : allowedConceptsInSubsumptionHierarchy) { - // schauen, ob es mehrere allgemeinere Nachbarn gibt + + for (Description c : conceptsInSubsumptionHierarchy) { + // look whether there are more general concepts + // (if yes, pick the first one) SortedSet<Description> moreGeneral = subsumptionHierarchyUp.get(c); - if(moreGeneral != null && moreGeneral.size() != 0) { + if (moreGeneral != null && moreGeneral.size() != 0) { Description chosenParent = moreGeneral.first(); hierarchyDownNew.get(chosenParent).add(c); } - } - - // for(Concept c : allowedConceptsInSubsumptionHierarchy) { - for(Description c : allowedConceptsInSubsumptionHierarchy) { + } + + for (Description c : conceptsInSubsumptionHierarchy) { SortedSet<Description> moreSpecial = subsumptionHierarchyDown.get(c); - if(moreSpecial != null && moreSpecial.size() != 0) { + if (moreSpecial != null && moreSpecial.size() != 0) { Description chosenParent = moreSpecial.first(); hierarchyUpNew.get(chosenParent).add(c); } - } + } subsumptionHierarchyDown = hierarchyDownNew; subsumptionHierarchyUp = hierarchyUpNew; } - + /** - * Implements a subsumption check using the hierarchy (no further - * reasoning checks are used). - * @param subClass The (supposedly) more special class. - * @param superClass The (supposedly) more general class. - * @return True if <code>subClass</code> is a subclass of <code>superclass</code>. + * Implements a subsumption check using the hierarchy (no further reasoning + * checks are used). + * + * @param subClass + * The (supposedly) more special class. + * @param superClass + * The (supposedly) more general class. + * @return True if <code>subClass</code> is a subclass of + * <code>superclass</code>. */ public boolean isSubclassOf(NamedClass subClass, NamedClass superClass) { - if(subClass.equals(superClass)) { + if (subClass.equals(superClass)) { return true; } else { - for(Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { + for (Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { // search the upper classes of the subclass - if(moreGeneralClass instanceof NamedClass) { - if(isSubclassOf((NamedClass)moreGeneralClass, superClass)) { + if (moreGeneralClass instanceof NamedClass) { + if (isSubclassOf((NamedClass) moreGeneralClass, superClass)) { return true; } - // we reached top, so we can return false (if top is a direct upper - // class, then no other upper classes can exist) + // we reached top, so we can return false (if top is a + // direct upper + // class, then no other upper classes can exist) } else { return false; } @@ -124,14 +162,14 @@ return false; } } - - @Override + + @Override public String toString() { return toString(false); } - + public String toString(boolean showUpwardHierarchy) { - if(showUpwardHierarchy) { + if (showUpwardHierarchy) { String str = "downward subsumption:\n"; str += toString(subsumptionHierarchyDown, new Thing(), 0); str += "upward subsumption:\n"; @@ -141,17 +179,85 @@ return toString(subsumptionHierarchyDown, new Thing(), 0); } } - - private String toString(TreeMap<Description,TreeSet<Description>> hierarchy, Description concept, int depth) { + + private String toString(TreeMap<Description, SortedSet<Description>> hierarchy, + Description concept, int depth) { String str = ""; - for(int i=0; i<depth; i++) + for (int i = 0; i < depth; i++) str += " "; str += concept.toString() + "\n"; Set<Description> tmp = hierarchy.get(concept); - if(tmp!=null) { - for(Description c : tmp) - str += toString(hierarchy, c, depth+1); + if (tmp != null) { + for (Description c : tmp) + str += toString(hierarchy, c, depth + 1); } return str; - } + } + + /** + * The method computes a new class hierarchy, which is a copy of this + * one, but only the specified classes are allowed to occur. For instance, + * if we have subclass relationships between 1sYearStudent, Student, and + * Person, but Student is not allowed, then there a is a subclass relationship + * between 1stYearStudent and Person. + * @param allowedClasses The classes, which are allowed to occur in the new + * class hierarchy. + * @return A copy of this hierarchy, which is restricted to a certain set + * of classes. + */ + public ClassHierarchy cloneAndRestrict(Set<NamedClass> allowedClasses) { + // create new maps + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUpNew + = new TreeMap<Description, SortedSet<Description>>(); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDownNew + = new TreeMap<Description, SortedSet<Description>>(); + + for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyUp.entrySet()) { + Description key = entry.getKey(); + // we only store mappings for allowed classes + if(allowedClasses.contains(key)) { + // copy the set of all super classes (we consume them until + // they are empty) + TreeSet<Description> superClasses = new TreeSet<Description>(entry.getValue()); + // storage for new super classes + TreeSet<Description> newSuperClasses = new TreeSet<Description>(entry.getValue()); + + while(!superClasses.isEmpty()) { + // pick and remove the first element + Description d = superClasses.pollFirst(); + // case 1: it is allowed, so we add it + if(allowedClasses.contains(d)) { + newSuperClasses.add(d); + // case 2: it is not allowed, so we try its super classes + } else { + superClasses.addAll(subsumptionHierarchyUp.get(d)); + } + } + + subsumptionHierarchyUpNew.put(key, newSuperClasses); + } + } + + // downward case is analogous + for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyDown.entrySet()) { + Description key = entry.getKey(); + if(allowedClasses.contains(key)) { + TreeSet<Description> subClasses = new TreeSet<Description>(entry.getValue()); + TreeSet<Description> newSubClasses = new TreeSet<Description>(entry.getValue()); + + while(!subClasses.isEmpty()) { + Description d = subClasses.pollFirst(); + if(allowedClasses.contains(d)) { + newSubClasses.add(d); + } else { + subClasses.addAll(subsumptionHierarchyDown.get(d)); + } + } + + subsumptionHierarchyDownNew.put(key, newSubClasses); + } + } + + return new ClassHierarchy(subsumptionHierarchyUpNew, subsumptionHierarchyDownNew); + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -47,13 +47,13 @@ import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; @@ -223,45 +223,45 @@ * Construct a subsumption hierarchy using DIG queries. After calling this * method one can ask for children or parents in the subsumption hierarchy. */ - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { - allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Thing()); - allowedConceptsInSubsumptionHierarchy.add(new Nothing()); +// public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { +// allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); +// allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); +// allowedConceptsInSubsumptionHierarchy.add(new Thing()); +// allowedConceptsInSubsumptionHierarchy.add(new Nothing()); +// +// TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( +// conceptComparator); +// TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( +// conceptComparator); +// +// // Subsumptionhierarchy berechnen +// // TODO: kann man effizienter auch in einer Abfrage machen +// +// // Refinements von Top +// TreeSet<Description> tmp = getMoreSpecialConceptsDIG(new Thing()); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyDown.put(new Thing(), tmp); +// +// // Refinements von Bottom +// tmp = getMoreGeneralConceptsDIG(new Nothing()); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyUp.put(new Nothing(), tmp); +// +// // Refinement atomarer Konzepte +// for (NamedClass atom : atomicConcepts) { +// tmp = getMoreSpecialConceptsDIG(atom); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyDown.put(atom, tmp); +// +// tmp = getMoreGeneralConceptsDIG(atom); +// tmp.retainAll(allowedConceptsInSubsumptionHierarchy); +// subsumptionHierarchyUp.put(atom, tmp); +// } +// +// subsumptionHierarchy = new ClassHierarchy( +// subsumptionHierarchyUp, subsumptionHierarchyDown); +// } - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - - // Subsumptionhierarchy berechnen - // TODO: kann man effizienter auch in einer Abfrage machen - - // Refinements von Top - TreeSet<Description> tmp = getMoreSpecialConceptsDIG(new Thing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(new Thing(), tmp); - - // Refinements von Bottom - tmp = getMoreGeneralConceptsDIG(new Nothing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(new Nothing(), tmp); - - // Refinement atomarer Konzepte - for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsDIG(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); - } - - subsumptionHierarchy = new ClassHierarchy(allowedConcepts, - subsumptionHierarchyUp, subsumptionHierarchyDown); - } - /** * Constructs a role hierarchy using DIG queries. After calling this method, * one can query parents or children of roles. @@ -481,7 +481,8 @@ // return roleHierarchy; // } - private TreeSet<Description> getMoreGeneralConceptsDIG(Description concept) { + @Override + protected TreeSet<Description> getSuperClassesImpl(Description concept) { String moreGeneralDIG = asksPrefix; moreGeneralDIG += "<parents id=\"query_parents\">"; moreGeneralDIG += DIGConverter.getDIGString(concept); @@ -520,7 +521,7 @@ // Konzept ist // (sonst wäre es weiter oben gefunden wurden) NamedClass ignoredAtomicConcept = new NamedClass(atoms[0].getName()); - resultsSet.addAll(getMoreGeneralConceptsDIG(ignoredAtomicConcept)); + resultsSet.addAll(getSuperClassesImpl(ignoredAtomicConcept)); } } @@ -528,7 +529,8 @@ return resultsSet; } - private TreeSet<Description> getMoreSpecialConceptsDIG(Description concept) { + @Override + protected TreeSet<Description> getSubClassesImpl(Description concept) { String moreSpecialDIG = asksPrefix; moreSpecialDIG += "<children id=\"query_children\">"; moreSpecialDIG += DIGConverter.getDIGString(concept); @@ -553,7 +555,7 @@ if (resultsSet.size() == 0 && atoms.length > 0) { NamedClass ignoredAtomicConcept = new NamedClass(atoms[0].getName()); - resultsSet.addAll(getMoreSpecialConceptsDIG(ignoredAtomicConcept)); + resultsSet.addAll(getSubClassesImpl(ignoredAtomicConcept)); } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -43,7 +43,6 @@ import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.options.StringConfigOption; import org.dllearner.core.owl.BooleanValueRestriction; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; @@ -555,11 +554,6 @@ return ReasonerType.FAST_INSTANCE_CHECKER; } - @Override - public ClassHierarchy prepareSubsumptionHierarchy() { - return rc.prepareSubsumptionHierarchy(); - } - // @Override // public ClassHierarchy getClassHierarchy() { // return rc.getClassHierarchy(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-11 12:57:12 UTC (rev 1506) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-11 16:17:24 UTC (rev 1507) @@ -57,7 +57,6 @@ import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyHierarchy; -import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.TypedConstant; import org.dllearner.core.owl.UntypedConstant; @@ -124,10 +123,10 @@ private ConceptComparator conceptComparator = new ConceptComparator(); private RoleComparator roleComparator = new RoleComparator(); - private ClassHierarchy subsumptionHierarchy; +// private ClassHierarchy subsumptionHierarchy; private ObjectPropertyHierarchy roleHierarchy; private DatatypePropertyHierarchy datatypePropertyHierarchy; - private Set<Description> allowedConceptsInSubsumptionHierarchy; +// private Set<Description> allowedConceptsInSubsumptionHierarchy; // primitives Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); @@ -407,85 +406,24 @@ } @Override - public ClassHierarchy prepareSubsumptionHierarchy() { - - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - - // refinements of top - TreeSet<Description> tmp = getMoreSpecialConceptsImpl(new Thing()); - subsumptionHierarchyDown.put(new Thing(), tmp); - - // refinements of bottom - tmp = getMoreGeneralConceptsImpl(new Nothing()); - subsumptionHierarchyUp.put(new Nothing(), tmp); - - // refinements of atomic concepts - for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConceptsImpl(atom); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsImpl(atom); - subsumptionHierarchyUp.put(atom, tmp); - } - - // create subsumption hierarchy - subsumptionHierarchy = new ClassHierarchy(atomicConcepts, - subsumptionHierarchyUp, subsumptionHierarchyDown); + public ObjectPropertyHierarchy prepareRoleHierarchy() { + // code copied from DIG reasoner - return subsumptionHierarchy; - } - - /* (non-Javadoc) - * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) - */ - public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { - - // implementation almost identical to DIG reasoner - // except function calls - - allowedConceptsInSubsumptionHierarchy = new TreeSet<Description>(conceptComparator); - allowedConceptsInSubsumptionHierarchy.addAll(allowedConcepts); - allowedConceptsInSubsumptionHierarchy.add(new Thing()); - allowedConceptsInSubsumptionHierarchy.add(new Nothing()); - - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - TreeMap<Description, TreeSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, TreeSet<Description>>( - conceptComparator); - - // refinements of top - TreeSet<Description> tmp = getMoreSpecialConceptsImpl(new Thing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(new Thing(), tmp); - - // refinements of bottom - tmp = getMoreGeneralConceptsImpl(new Nothing()); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(new Nothing(), tmp); - - // refinements of atomic concepts - for (NamedClass atom : atomicConcepts) { - tmp = getMoreSpecialConceptsImpl(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyDown.put(atom, tmp); - - tmp = getMoreGeneralConceptsImpl(atom); - tmp.retainAll(allowedConceptsInSubsumptionHierarchy); - subsumptionHierarchyUp.put(atom, tmp); + TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( + roleComparator); + TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( + roleComparator); + + // refinement of atomic concepts + for (ObjectProperty role : atomicRoles) { + roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); + roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); } - // create subsumption hierarchy - subsumptionHierarchy = new ClassHierarchy(allowedConcepts, - subsumptionHierarchyUp, subsumptionHierarchyDown); + roleHierarchy = new ObjectPropertyHierarchy(atomicRoles, roleHierarchyUp, + roleHierarchyDown); + return roleHierarchy; } - -// @Override -// public ClassHierarchy getClassHierarchy() { -// return subsumptionHierarchy; -// } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) @@ -546,7 +484,8 @@ } } - private TreeSet<Description> getMoreGeneralConceptsImpl(Description concept) { + @Override + protected TreeSet<Description> getSuperClassesImpl(Description concept) { Set<Set<OWLClass>> classes = null; try { classes = reasoner.getSuperClasses(OWLAPIDescriptionConvertVisitor.getOWLDescription(concept)); @@ -557,19 +496,17 @@ return getFirstClasses(classes); } - private TreeSet<Description> getMoreSpecialConceptsImpl(Description concept) { + @Override + protected TreeSet<Description> getSubClassesImpl(Description concept) { Set<Set<OWLClass>> classes = null; try { -// System.out.println(OWLAPIDescriptionConvertVisitor.getOWLDescription(concept)); -// System.out.println(getSubsumptionHierarchy()); -// System.out.println(reasoner); classes = reasoner.getSubClasses(OWLAPIDescriptionConvertVisitor.getOWLDescription(concept)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("OWL API classification error."); } return getFirstClasses(classes); - } + } private TreeSet<ObjectProperty> getMoreGeneralRolesImpl(ObjectProperty role) { Set<Set<OWLObjectProperty>> properties; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-11 17:07:12
|
Revision: 1508 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1508&view=rev Author: jenslehmann Date: 2008-11-11 17:06:49 +0000 (Tue, 11 Nov 2008) Log Message: ----------- refexamples can now handle ignored classes (again) without interfering with the reasoner (it keeps its own restricted view of the subsumption hierarchy to do this) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -45,6 +45,7 @@ import org.dllearner.core.options.IntegerConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -356,10 +357,13 @@ } // prepare subsumption and role hierarchies, because they are needed - // during the run of the algorithm -// reasoner.prepareSubsumptionHierarchy(usedConcepts); + // during the run of the algorithm; + // in contrast to before, the learning algorithms have to maintain their + // own view on the class hierarchy + ClassHierarchy classHierarchy = reasoner.getClassHierarchy().cloneAndRestrict(usedConcepts); if(improveSubsumptionHierarchy) - reasoner.getClassHierarchy().thinOutSubsumptionHierarchy(); + classHierarchy.thinOutSubsumptionHierarchy(); + // reasoner.prepareRoleHierarchy(usedRoles); // prepare datatype hierarchy only if necessary // if(reasoner.hasDatatypeSupport()) @@ -369,6 +373,7 @@ // variables to it RhoDRDown operator = new RhoDRDown( reasoner, + classHierarchy, applyAllFilter, applyExistsFilter, useAllConstructor, Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -749,7 +749,7 @@ @Override public final SortedSet<Description> getSuperClasses(Description concept) { - return getClassHierarchy().getMoreGeneralConcepts(concept); + return getClassHierarchy().getSuperClasses(concept); } protected SortedSet<Description> getSuperClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { @@ -758,7 +758,7 @@ @Override public final SortedSet<Description> getSubClasses(Description concept) { - return getClassHierarchy().getMoreSpecialConcepts(concept); + return getClassHierarchy().getSubClasses(concept); } protected SortedSet<Description> getSubClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { @@ -819,15 +819,19 @@ TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( conceptComparator); - // refinements of top + // parents/children of top ... SortedSet<Description> tmp = getSubClassesImpl(Thing.instance); - subsumptionHierarchyDown.put(new Thing(), tmp); + subsumptionHierarchyUp.put(Thing.instance, new TreeSet<Description>()); + subsumptionHierarchyDown.put(Thing.instance, tmp); - // refinements of bottom + + + // ... bottom ... tmp = getSuperClassesImpl(Nothing.instance); - subsumptionHierarchyUp.put(new Nothing(), tmp); + subsumptionHierarchyUp.put(Nothing.instance, tmp); + subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>()); - // refinements of atomic concepts + // ... and named classes Set<NamedClass> atomicConcepts = getNamedClasses(); for (NamedClass atom : atomicConcepts) { tmp = getSubClassesImpl(atom); @@ -845,6 +849,8 @@ subsumptionHierarchyUp.put(atom, tmp); } + + return new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -54,10 +54,12 @@ this.subsumptionHierarchyUp = subsumptionHierarchyUp; this.subsumptionHierarchyDown = subsumptionHierarchyDown; + + } - public SortedSet<Description> getMoreGeneralConcepts(Description concept) { + public SortedSet<Description> getSuperClasses(Description concept) { SortedSet<Description> result = subsumptionHierarchyUp.get(concept); if(result == null) { logger.error("Query for super class of " + concept + " in subsumption hierarchy, but the class is not contained in the (upward) hierarchy"); @@ -68,7 +70,7 @@ return new TreeSet<Description>(result); } - public SortedSet<Description> getMoreSpecialConcepts(Description concept) { + public SortedSet<Description> getSubClasses(Description concept) { SortedSet<Description> result = subsumptionHierarchyDown.get(concept); if(result == null) { logger.error("Query for sub class of " + concept + " in subsumption hierarchy, but the class is not contained in the (downward) hierarchy"); @@ -200,22 +202,31 @@ * if we have subclass relationships between 1sYearStudent, Student, and * Person, but Student is not allowed, then there a is a subclass relationship * between 1stYearStudent and Person. + * Currently, owl:Thing and owl:Nothing are always allowed for technical + * reasons. * @param allowedClasses The classes, which are allowed to occur in the new * class hierarchy. * @return A copy of this hierarchy, which is restricted to a certain set * of classes. */ public ClassHierarchy cloneAndRestrict(Set<NamedClass> allowedClasses) { + // currently TOP and BOTTOM are always allowed + // (TODO would be easier if Thing/Nothing were declared as named classes) + Set<Description> allowed = new TreeSet<Description>(conceptComparator); + allowed.addAll(allowedClasses); + allowed.add(Thing.instance); + allowed.add(Nothing.instance); + // create new maps TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUpNew - = new TreeMap<Description, SortedSet<Description>>(); + = new TreeMap<Description, SortedSet<Description>>(conceptComparator); TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDownNew - = new TreeMap<Description, SortedSet<Description>>(); + = new TreeMap<Description, SortedSet<Description>>(conceptComparator); for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyUp.entrySet()) { Description key = entry.getKey(); // we only store mappings for allowed classes - if(allowedClasses.contains(key)) { + if(allowed.contains(key)) { // copy the set of all super classes (we consume them until // they are empty) TreeSet<Description> superClasses = new TreeSet<Description>(entry.getValue()); @@ -226,7 +237,7 @@ // pick and remove the first element Description d = superClasses.pollFirst(); // case 1: it is allowed, so we add it - if(allowedClasses.contains(d)) { + if(allowed.contains(d)) { newSuperClasses.add(d); // case 2: it is not allowed, so we try its super classes } else { @@ -241,13 +252,13 @@ // downward case is analogous for(Entry<Description, SortedSet<Description>> entry : subsumptionHierarchyDown.entrySet()) { Description key = entry.getKey(); - if(allowedClasses.contains(key)) { + if(allowed.contains(key)) { TreeSet<Description> subClasses = new TreeSet<Description>(entry.getValue()); TreeSet<Description> newSubClasses = new TreeSet<Description>(entry.getValue()); while(!subClasses.isEmpty()) { Description d = subClasses.pollFirst(); - if(allowedClasses.contains(d)) { + if(allowed.contains(d)) { newSubClasses.add(d); } else { subClasses.addAll(subsumptionHierarchyDown.get(d)); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -182,16 +182,17 @@ // private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); public RhoDRDown(ReasonerComponent reasoningService) { - this(reasoningService, true, true, true, true, true, 3, true, true, true, true, null); + this(reasoningService, reasoningService.getClassHierarchy(), true, true, true, true, true, 3, true, true, true, true, null); } // TODO constructor which takes a RhoDRDownConfigurator object; // this should be an interface implemented e.g. by ExampleBasedROLComponentConfigurator; // the goal is to use the configurator system while still being flexible enough to // use one refinement operator in several learning algorithms - public RhoDRDown(ReasonerComponent reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, + public RhoDRDown(ReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass) { this.rs = reasoningService; + this.subHierarchy = subHierarchy; this.applyAllFilter = applyAllFilter; this.applyExistsFilter = applyExistsFilter; this.useAllConstructor = useAllConstructor; @@ -203,7 +204,7 @@ this.useBooleanDatatypes = useBooleanDatatypes; this.useDoubleDatatypes = useDoubleDatatypes; - subHierarchy = rs.getClassHierarchy(); +// subHierarchy = rs.getClassHierarchy(); // query reasoner for domains and ranges // (because they are used often in the operator) @@ -369,11 +370,11 @@ } else if(description instanceof Nothing) { // cannot be further refined } else if(description instanceof NamedClass) { - refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); + refinements.addAll(subHierarchy.getSubClasses(description)); refinements.remove(new Nothing()); } else if (description instanceof Negation && description.getChild(0) instanceof NamedClass) { - tmp = rs.getSuperClasses(description.getChild(0)); + tmp = subHierarchy.getSuperClasses(description.getChild(0)); for(Description c : tmp) { if(!(c instanceof Thing)) @@ -839,12 +840,12 @@ m.put(i, new TreeSet<Description>(conceptComparator)); } - SortedSet<Description> m1 = rs.getSubClasses(new Thing()); + SortedSet<Description> m1 = subHierarchy.getSubClasses(new Thing()); m.put(1,m1); SortedSet<Description> m2 = new TreeSet<Description>(conceptComparator); if(useNegation) { - Set<Description> m2tmp = rs.getSuperClasses(new Nothing()); + Set<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { m2.add(new Negation(c)); } @@ -919,7 +920,7 @@ mA.get(nc).put(i, new TreeSet<Description>(conceptComparator)); } - SortedSet<Description> m1 = rs.getSubClasses(nc); + SortedSet<Description> m1 = subHierarchy.getSubClasses(nc); mA.get(nc).put(1,m1); SortedSet<Description> m2 = new TreeSet<Description>(conceptComparator); @@ -930,7 +931,7 @@ // recursive method because for A subClassOf A' we have not A' // subClassOf A and thus: if A and B are disjoint then also A' // and B; if not A AND B = B then also not A' AND B = B - SortedSet<Description> m2tmp = rs.getSuperClasses(new Nothing()); + SortedSet<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { if(c instanceof Thing) Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-11-11 16:17:24 UTC (rev 1507) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-11-11 17:06:49 UTC (rev 1508) @@ -114,7 +114,7 @@ // there are 4 checks a class has to satisfy to get into the set; // for 2 of them we can stop further traversal in the subsumption // hierarchy - for(Description d : sh.getMoreSpecialConcepts(upperClass)) { + for(Description d : sh.getSubClasses(upperClass)) { // owl:Nothing is never a candidate (not in EL) if(!(d instanceof Nothing)) { NamedClass candidate = (NamedClass) d; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-12 16:16:29
|
Revision: 1510 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1510&view=rev Author: jenslehmann Date: 2008-11-12 16:16:24 +0000 (Wed, 12 Nov 2008) Log Message: ----------- - continued EL learning algorithm: although other parts are not yet complete, it already passed the "father test" - slightly changed CLI logging (can now also log to an HTML file in addition to console output) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.NavigableSet; @@ -399,6 +400,28 @@ return str; } + public String toDescriptionString() { + String str = ""; + if(label.isEmpty()) { + str = "TOP"; + } else { + Iterator<NamedClass> it = label.iterator(); + while(it.hasNext()) { + NamedClass nc = it.next(); + if(it.hasNext()) { + str += nc.toString() + " AND "; + } else { + str += nc.toString(); + } + } + } + for(ELDescriptionEdge edge : edges) { + str += " AND EXISTS " + edge.getLabel().toString() + ".("; + str += edge.getTree().toDescriptionString() + ")"; + } + return str; + } + public ELDescriptionNode getParent() { return parent; } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -443,4 +443,13 @@ public String toString() { return rootNode.toString(); } + + /** + * Returns a string of the tree description (without the overhead of converting + * the tree into a description). + * @return A string for the description the tree stands for. + */ + public String toDescriptionString() { + return rootNode.toDescriptionString(); + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -26,6 +26,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Logger; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; @@ -36,7 +37,6 @@ import org.dllearner.core.configurators.ELLearningAlgorithmConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; -import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.refinementoperators.ELDown; import org.dllearner.utilities.owl.EvaluatedDescriptionSet; @@ -52,6 +52,7 @@ */ public class ELLearningAlgorithm extends LearningAlgorithm { + private static Logger logger = Logger.getLogger(ELLearningAlgorithm.class); private ELLearningAlgorithmConfigurator configurator; private ELDown operator; @@ -64,12 +65,16 @@ private SearchTreeNode startNode; private ELHeuristic heuristic; - private SortedSet<SearchTreeNode> candidates; + private TreeSet<SearchTreeNode> candidates; public ELLearningAlgorithm(PosNegLP problem, ReasonerComponent reasoner) { super(problem, reasoner); } + public static String getName() { + return "standard EL learning algorithm"; + } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); @@ -101,18 +106,28 @@ isRunning = true; reset(); + // create start node ELDescriptionTree top = new ELDescriptionTree(reasoner, Thing.instance); addDescriptionTree(top, null); + // main loop + int loop = 0; while(!stop && !stoppingCriteriaSatisfied()) { // pick the best candidate according to the heuristic - SearchTreeNode best = candidates.last(); + SearchTreeNode best = candidates.pollLast(); // apply operator Set<ELDescriptionTree> refinements = operator.refine(best.getDescriptionTree()); // add all refinements to search tree, candidates, best descriptions for(ELDescriptionTree refinement : refinements) { addDescriptionTree(refinement, best); } + loop++; + // logging + if(logger.isTraceEnabled()) { + logger.trace("Choosen node " + best); + logger.trace(startNode.getTreeString()); + logger.trace("Loop " + loop + " completed."); + } } isRunning = false; @@ -146,18 +161,16 @@ // check whether we want to add it to the best evaluated descriptions; // to do this we pick the worst considered evaluated description - // (remember that the set has limited size, so it's likely not the worst overall) - EvaluatedDescription worst = bestEvaluatedDescriptions.getSet().first(); + // (remember that the set has limited size, so it's likely not the worst overall); // the description has a chance to make it in the set if it has // at least as high accuracy - if not we can save the reasoner calls // for fully computing the evaluated description - if(worst.getCoveredNegatives().size() >= node.getCoveredNegatives()) { + if(bestEvaluatedDescriptions.size() == 0 || bestEvaluatedDescriptions.getWorst().getCoveredNegatives().size() >= node.getCoveredNegatives()) { Score score = learningProblem.computeScore(description); EvaluatedDescription ed = new EvaluatedDescription(description, score); bestEvaluatedDescriptions.add(ed); } - // TODO add a method to EvaluatedDescriptionSet for returning the - // minimum accuracy required + } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -19,8 +19,11 @@ */ package org.dllearner.algorithms.el; +import java.util.LinkedList; import java.util.List; +import org.dllearner.algorithms.refinement.Node; + /** * A node in the search tree of an EL algorithm. * @@ -31,7 +34,7 @@ private ELDescriptionTree descriptionTree; - private List<SearchTreeNode> children; + private List<SearchTreeNode> children = new LinkedList<SearchTreeNode>(); private int coveredNegatives; private boolean tooWeak = false; @@ -87,4 +90,32 @@ return children; } + @Override + public String toString() { + String ret = descriptionTree.toDescriptionString() + " [q:"; + if(tooWeak) + ret += "tw"; + else + ret += coveredNegatives; + ret += ", children:" + children.size() + "]"; + return ret; + } + + public String getTreeString() { + return getTreeString(0).toString(); + } + + private StringBuilder getTreeString(int depth) { + StringBuilder treeString = new StringBuilder(); + for(int i=0; i<depth-1; i++) + treeString.append(" "); + if(depth!=0) + treeString.append("|--> "); + treeString.append(toString()+"\n"); + for(SearchTreeNode child : children) { + treeString.append(child.getTreeString(depth+1)); + } + return treeString; + } + } Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -37,11 +37,11 @@ import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; +import org.apache.log4j.HTMLLayout; import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; -import org.apache.log4j.SimpleLayout; import org.dllearner.Info; import org.dllearner.algorithms.BruteForceLearner; import org.dllearner.algorithms.RandomGuesser; @@ -104,7 +104,8 @@ */ public class Start { - private static Logger logger = Logger.getRootLogger(); + private static Logger logger = Logger.getLogger(Start.class); + private static Logger rootLogger = Logger.getRootLogger(); private static ConfMapper confMapper = new ConfMapper(); @@ -145,28 +146,51 @@ // logger 1 is the console, where we print only info messages; // the logger is plain, i.e. does not output log level etc. Layout layout = new PatternLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + // setting a threshold suppresses log messages below this level; + // this means that if you want to e.g. see all trace messages on + // console, you have to set the threshold and log level to trace + // (but we recommend just setting the log level to trace and observe + // the log file) consoleAppender.setThreshold(Level.INFO); // logger 2 is writes to a file; it records all debug messages - // and includes the log level - Layout layout2 = new SimpleLayout(); + // (you can choose HTML or TXT) + boolean htmlLog = false; + Layout layout2 = null; FileAppender fileAppenderNormal = null; - File f = new File("log/sparql.txt"); + String fileName; + if(htmlLog) { + layout2 = new HTMLLayout(); + fileName = "log/log.html"; + } else { + // simple variant: layout2 = new SimpleLayout(); + layout2 = new PatternLayout("%r [%t] %-5p %c :\n%m%n\n"); + fileName = "log/log.txt"; + } try { - fileAppenderNormal = new FileAppender(layout2, "log/log.txt", false); - f.delete(); - f.createNewFile(); + fileAppenderNormal = new FileAppender(layout2, fileName, false); } catch (IOException e) { e.printStackTrace(); + } + + // add both loggers + rootLogger.removeAllAppenders(); + rootLogger.addAppender(consoleAppender); + rootLogger.addAppender(fileAppenderNormal); + rootLogger.setLevel(Level.DEBUG); + + // SPARQL log + File f = new File("log/sparql.txt"); + f.delete(); + try { + f.createNewFile(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); } -// fileAppenderNormal.setThreshold(Level.DEBUG); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.addAppender(fileAppenderNormal); - logger.setLevel(Level.DEBUG); - // Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); // Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN); // Logger.getLogger(TypedSparqlQuery.class).setLevel(Level.WARN); @@ -640,19 +664,19 @@ } else if (name.equals("logLevel")) { String level = cliOption.getStringValue(); if (level.equals("off")) - logger.setLevel(Level.OFF); + rootLogger.setLevel(Level.OFF); else if (level.equals("trace")) - logger.setLevel(Level.TRACE); + rootLogger.setLevel(Level.TRACE); else if (level.equals("info")) - logger.setLevel(Level.INFO); + rootLogger.setLevel(Level.INFO); else if (level.equals("debug")) - logger.setLevel(Level.DEBUG); + rootLogger.setLevel(Level.DEBUG); else if (level.equals("warn")) - logger.setLevel(Level.WARN); + rootLogger.setLevel(Level.WARN); else if (level.equals("error")) - logger.setLevel(Level.ERROR); + rootLogger.setLevel(Level.ERROR); else if (level.equals("fatal")) - logger.setLevel(Level.FATAL); + rootLogger.setLevel(Level.FATAL); } else handleError("Unknown CLI option \"" + name + "\"."); } Modified: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -51,7 +51,8 @@ /** * Returns the name of this component. By default, "unnamed * component" is returned, but all implementations of components - * are strongly encouraged to overwrite this method. + * are strongly encouraged to provide a static method returning + * the name. * @return The name of this component. */ public static String getName() { Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2008-11-12 12:07:48 UTC (rev 1509) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2008-11-12 16:16:24 UTC (rev 1510) @@ -64,6 +64,18 @@ } } + public int size() { + return set.size(); + } + + public EvaluatedDescription getBest() { + return set.last(); + } + + public EvaluatedDescription getWorst() { + return set.first(); + } + /** * @return the set */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-12 16:25:49
|
Revision: 1511 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1511&view=rev Author: jenslehmann Date: 2008-11-12 16:25:45 +0000 (Wed, 12 Nov 2008) Log Message: ----------- small fix Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-11-12 16:16:24 UTC (rev 1510) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-11-12 16:25:45 UTC (rev 1511) @@ -130,6 +130,9 @@ } } + // print solution(s) + logger.info("solution : " + bestEvaluatedDescriptions.getBest()); + isRunning = false; } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2008-11-12 16:16:24 UTC (rev 1510) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java 2008-11-12 16:25:45 UTC (rev 1511) @@ -69,11 +69,11 @@ } public EvaluatedDescription getBest() { - return set.last(); + return set.first(); } public EvaluatedDescription getWorst() { - return set.first(); + return set.last(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-11-14 11:59:10
|
Revision: 1512 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1512&view=rev Author: jenslehmann Date: 2008-11-14 11:48:57 +0000 (Fri, 14 Nov 2008) Log Message: ----------- - added reasoning method to get all object property relationships for an individual - added some more methods to OWLAPIConverter Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIConverter.java Modified: trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-12 16:25:45 UTC (rev 1511) +++ trunk/src/dl-learner/org/dllearner/core/IndividualReasoner.java 2008-11-14 11:48:57 UTC (rev 1512) @@ -106,6 +106,16 @@ public Set<Constant> getRelatedValues(Individual individual, DatatypeProperty datatypeProperty); /** + * A map of properties related to an individual, e.g. + * {hasChild => {eric,anna}, hasSibling => {sebastian}}. + * + * @param individual An individual. + * @return A map of of properties connected to the individual as keys and the individuals + * they point to as values. + */ + public Map<ObjectProperty,Set<Individual>> getObjectPropertyRelationships(Individual individual); + + /** * Computes and returns all connections between individuals through the specified * property, e.g. {eric => {maria, anna}, anna => {eric}}. * @param objectProperty An object property. Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-12 16:25:45 UTC (rev 1511) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-14 11:48:57 UTC (rev 1512) @@ -398,6 +398,21 @@ } @Override + public final Map<ObjectProperty,Set<Individual>> getObjectPropertyRelationships(Individual individual) { + try { + return getObjectPropertyRelationshipsImpl(individual); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + protected Map<ObjectProperty,Set<Individual>> getObjectPropertyRelationshipsImpl(Individual individual) throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + + @Override public final Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) { try { Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-12 16:25:45 UTC (rev 1511) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-14 11:48:57 UTC (rev 1512) @@ -34,12 +34,14 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.Map.Entry; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.configurators.OWLAPIReasonerConfigurator; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; @@ -64,6 +66,7 @@ import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIConverter; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.RoleComparator; import org.semanticweb.owl.apibinding.OWLManager; @@ -118,7 +121,7 @@ // the data factory is used to generate OWL API objects private OWLDataFactory factory; // static factory - private static OWLDataFactory staticFactory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); +// private static OWLDataFactory staticFactory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); private ConceptComparator conceptComparator = new ConceptComparator(); private RoleComparator roleComparator = new RoleComparator(); @@ -511,7 +514,7 @@ protected TreeSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) { Set<Set<OWLObjectProperty>> properties; try { - properties = reasoner.getSuperProperties(getOWLAPIDescription(role)); + properties = reasoner.getSuperProperties(OWLAPIConverter.getOWLAPIObjectProperty(role)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("OWL API classification error."); @@ -523,7 +526,7 @@ protected TreeSet<ObjectProperty> getSubPropertiesImpl(ObjectProperty role) { Set<Set<OWLObjectProperty>> properties; try { - properties = reasoner.getSubProperties(getOWLAPIDescription(role)); + properties = reasoner.getSubProperties(OWLAPIConverter.getOWLAPIObjectProperty(role)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("OWL API classification error."); @@ -534,7 +537,7 @@ private TreeSet<DatatypeProperty> getMoreGeneralDatatypePropertiesImpl(DatatypeProperty role) { Set<Set<OWLDataProperty>> properties; try { - properties = reasoner.getSuperProperties(getOWLAPIDescription(role)); + properties = reasoner.getSuperProperties(OWLAPIConverter.getOWLAPIDataProperty(role)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("OWL API classification error."); @@ -545,7 +548,7 @@ private TreeSet<DatatypeProperty> getMoreSpecialDatatypePropertiesImpl(DatatypeProperty role) { Set<Set<OWLDataProperty>> properties; try { - properties = reasoner.getSubProperties(getOWLAPIDescription(role)); + properties = reasoner.getSubProperties(OWLAPIConverter.getOWLAPIDataProperty(role)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("OWL API classification error."); @@ -606,7 +609,7 @@ @Override public Description getDomainImpl(ObjectProperty objectProperty) { - OWLObjectProperty prop = getOWLAPIDescription(objectProperty); + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); try { // TODO: look up why OWL API return a two dimensional set here // instead of only one description (probably there can be several @@ -625,7 +628,7 @@ @Override public Description getDomainImpl(DatatypeProperty datatypeProperty) { - OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); try { // TODO: look up why OWL API return a two dimensional set here // instead of only one description (probably there can be several @@ -644,7 +647,7 @@ @Override public Description getRangeImpl(ObjectProperty objectProperty) { - OWLObjectProperty prop = getOWLAPIDescription(objectProperty); + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); try { Set<OWLDescription> set = reasoner.getRanges(prop); if(set.size()==0) @@ -658,7 +661,7 @@ @Override public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { - OWLObjectProperty prop = getOWLAPIDescription(atomicRole); + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(atomicRole); Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); for(Individual i : individuals) { OWLIndividual ind = factory.getOWLIndividual(URI.create(i.getName())); @@ -681,9 +684,27 @@ } @Override + protected Map<ObjectProperty,Set<Individual>> getObjectPropertyRelationshipsImpl(Individual individual) { + OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); + Map<OWLObjectProperty,Set<OWLIndividual>> mapAPI = null; + try { + mapAPI = reasoner.getObjectPropertyRelationships(ind); + } catch (OWLReasonerException e) { + e.printStackTrace(); + } + Map<ObjectProperty,Set<Individual>> map = new TreeMap<ObjectProperty, Set<Individual>>(); + for(Entry<OWLObjectProperty,Set<OWLIndividual>> entry : mapAPI.entrySet()) { + ObjectProperty prop = OWLAPIConverter.convertObjectProperty(entry.getKey()); + Set<Individual> inds = OWLAPIConverter.convertIndividuals(entry.getValue()); + map.put(prop, inds); + } + return map; + } + + @Override public Set<Individual> getRelatedIndividualsImpl(Individual individual, ObjectProperty objectProperty) { OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); - OWLObjectProperty prop = getOWLAPIDescription(objectProperty); + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); Set<OWLIndividual> inds = null; try { inds = reasoner.getRelatedIndividuals(ind, prop); @@ -701,18 +722,18 @@ @Override public Set<Constant> getRelatedValuesImpl(Individual individual, DatatypeProperty datatypeProperty) { OWLIndividual ind = factory.getOWLIndividual(URI.create(individual.getName())); - OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); Set<OWLConstant> constants = null; try { constants = reasoner.getRelatedValues(ind, prop); } catch (OWLReasonerException e) { e.printStackTrace(); } - return convertConstants(constants); + return OWLAPIConverter.convertConstants(constants); } public Map<Individual, SortedSet<Double>> getDoubleValues(DatatypeProperty datatypeProperty) { - OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); Map<Individual, SortedSet<Double>> map = new TreeMap<Individual, SortedSet<Double>>(); for(Individual i : individuals) { OWLIndividual ind = factory.getOWLIndividual(URI.create(i.getName())); @@ -738,7 +759,7 @@ @Override public Map<Individual, SortedSet<Constant>> getDatatypeMembersImpl(DatatypeProperty datatypeProperty) { - OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); Map<Individual, SortedSet<Constant>> map = new TreeMap<Individual, SortedSet<Constant>>(); for(Individual i : individuals) { OWLIndividual ind = factory.getOWLIndividual(URI.create(i.getName())); @@ -757,7 +778,7 @@ // for typed constants we have to figure out the correct // data type and value if(oi instanceof OWLTypedConstant) { - Datatype dt = convertDatatype(((OWLTypedConstant)oi).getDataType()); + Datatype dt = OWLAPIConverter.convertDatatype(((OWLTypedConstant)oi).getDataType()); is.add(new TypedConstant(oi.getLiteral(),dt)); // for untyped constants we have to figure out the value // and language tag (if any) @@ -832,14 +853,10 @@ private Set<Description> owlClassesToAtomicConcepts(Set<OWLClass> owlClasses) { Set<Description> concepts = new HashSet<Description>(); for(OWLClass owlClass : owlClasses) - concepts.add(owlClassToAtomicConcept(owlClass)); + concepts.add(OWLAPIConverter.convertClass(owlClass)); return concepts; } - private Description owlClassToAtomicConcept(OWLClass owlClass) { - return new NamedClass(owlClass.getURI().toString()); - } - public static void exportKBToOWL(File owlOutputFile, KB kb, URI ontologyURI) { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); //URI ontologyURI = URI.create("http://example.com"); @@ -864,66 +881,6 @@ } } - public static Set<Constant> convertConstants(Set<OWLConstant> constants) { - SortedSet<Constant> is = new TreeSet<Constant>(); - for(OWLConstant oi : constants) { - is.add(convertConstant(oi)); - } - return is; - } - - public static Constant convertConstant(OWLConstant constant) { - Constant c; - // for typed constants we have to figure out the correct - // data type and value - if(constant instanceof OWLTypedConstant) { - Datatype dt = convertDatatype(((OWLTypedConstant)constant).getDataType()); - c = new TypedConstant(constant.getLiteral(),dt); - // for untyped constants we have to figure out the value - // and language tag (if any) - } else { - OWLUntypedConstant ouc = (OWLUntypedConstant) constant; - if(ouc.hasLang()) - c = new UntypedConstant(ouc.getLiteral(), ouc.getLang()); - else - c = new UntypedConstant(ouc.getLiteral()); - } - return c; - } - - public static Datatype convertDatatype(OWLDataType dataType) { - URI uri = dataType.getURI(); - if(uri.equals(Datatype.BOOLEAN.getURI())) - return Datatype.BOOLEAN; - else if(uri.equals(Datatype.DOUBLE.getURI())) - return Datatype.DOUBLE; - else if(uri.equals(Datatype.INT.getURI())) - return Datatype.INT; - - throw new Error("Unsupported datatype " + dataType + ". Please inform a DL-Learner developer to add it."); - } - - private static OWLObjectProperty getOWLAPIDescription(ObjectProperty role) { - return staticFactory.getOWLObjectProperty(URI.create(role.getName())); - } - - private static OWLDataProperty getOWLAPIDescription(DatatypeProperty datatypeProperty) { - return staticFactory.getOWLDataProperty(URI.create(datatypeProperty.getName())); - } - - private static OWLEntity getOWLAPIEntity(Entity entity) { - if(entity instanceof ObjectProperty) { - return staticFactory.getOWLObjectProperty(URI.create(entity.getName())); - } else if(entity instanceof DatatypeProperty) { - return staticFactory.getOWLDataProperty(URI.create(entity.getName())); - } else if(entity instanceof NamedClass) { - return staticFactory.getOWLClass(URI.create(entity.getName())); - } else if(entity instanceof OWLIndividual) { - return staticFactory.getOWLIndividual(URI.create(entity.getName())); - } - throw new Error("OWL API entity conversion for " + entity + " not supported."); - } - /** * Test * @@ -1035,14 +992,14 @@ } @Override - @SuppressWarnings("all") + @SuppressWarnings("unchecked") public Set<Constant> getLabelImpl(Entity entity) { - OWLEntity owlEntity = getOWLAPIEntity(entity); + OWLEntity owlEntity = OWLAPIConverter.getOWLAPIEntity(entity); Set<OWLAnnotation> labelAnnotations = owlEntity.getAnnotations(owlAPIOntologies.get(0), URI.create("http://www.w3.org/2000/01/rdf-schema#label")); Set<Constant> annotations = new HashSet<Constant>(); for(OWLAnnotation label : labelAnnotations) { OWLConstant c = ((OWLLabelAnnotation)label).getAnnotationValue(); - annotations.add(convertConstant(c)); + annotations.add(OWLAPIConverter.convertConstant(c)); } return annotations; } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIConverter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIConverter.java 2008-11-12 16:25:45 UTC (rev 1511) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLAPIConverter.java 2008-11-14 11:48:57 UTC (rev 1512) @@ -19,10 +19,37 @@ */ package org.dllearner.utilities.owl; +import java.net.URI; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.Datatype; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.TypedConstant; +import org.dllearner.core.owl.UntypedConstant; +import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLConstant; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDataProperty; +import org.semanticweb.owl.model.OWLDataType; import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLEntity; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLObjectProperty; +import org.semanticweb.owl.model.OWLTypedConstant; +import org.semanticweb.owl.model.OWLUntypedConstant; /** * A collection of methods for exchanging objects between OWL API and @@ -33,6 +60,8 @@ */ public final class OWLAPIConverter { + private static OWLDataFactory staticFactory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); + /** * Converts a DL-Learner axiom into an OWL API axiom. * @@ -40,7 +69,7 @@ * @param axiom The axiom to convert. * @return An OWL API axiom. */ - public static OWLAxiom convertAxiom(Axiom axiom) { + public static OWLAxiom getOWLAPIAxiom(Axiom axiom) { return OWLAPIAxiomConvertVisitor.convertAxiom(axiom); } @@ -51,9 +80,103 @@ * @param description DL-Learner description. * @return Corresponding OWL API description. */ - public static OWLDescription getOWLDescription(Description description) { + public static OWLDescription getOWLAPIDescription(Description description) { return OWLAPIDescriptionConvertVisitor.getOWLDescription(description); + } + + public static OWLIndividual getOWLAPIIndividual(Individual individual) { + return staticFactory.getOWLIndividual(URI.create(individual.getName())); } + public static OWLObjectProperty getOWLAPIObjectProperty(ObjectProperty role) { + return staticFactory.getOWLObjectProperty(URI.create(role.getName())); + } + public static OWLDataProperty getOWLAPIDataProperty(DatatypeProperty datatypeProperty) { + return staticFactory.getOWLDataProperty(URI.create(datatypeProperty.getName())); + } + + public static OWLEntity getOWLAPIEntity(Entity entity) { + if(entity instanceof ObjectProperty) { + return staticFactory.getOWLObjectProperty(URI.create(entity.getName())); + } else if(entity instanceof DatatypeProperty) { + return staticFactory.getOWLDataProperty(URI.create(entity.getName())); + } else if(entity instanceof NamedClass) { + return staticFactory.getOWLClass(URI.create(entity.getName())); + } else if(entity instanceof OWLIndividual) { + return staticFactory.getOWLIndividual(URI.create(entity.getName())); + } + // should never happen + throw new Error("OWL API entity conversion for " + entity + " not supported."); + } + + public static Individual convertIndividual(OWLIndividual individual) { + return new Individual(individual.getURI().toString()); + } + + public static Set<Individual> convertIndividuals(Set<OWLIndividual> individuals) { + Set<Individual> inds = new TreeSet<Individual>(); + for(OWLIndividual individual : individuals) { + inds.add(convertIndividual(individual)); + } + return inds; + } + + public static ObjectProperty convertObjectProperty(OWLObjectProperty property) { + return new ObjectProperty(property.getURI().toString()); + } + + public static DatatypeProperty convertIndividual(OWLDataProperty property) { + return new DatatypeProperty(property.getURI().toString()); + } + + public static Description convertClass(OWLClass owlClass) { + if(owlClass.isOWLThing()) { + return Thing.instance; + } else if(owlClass.isOWLNothing()) { + return Nothing.instance; + } else { + return new NamedClass(owlClass.getURI().toString()); + } + } + + public static Constant convertConstant(OWLConstant constant) { + Constant c; + // for typed constants we have to figure out the correct + // data type and value + if(constant instanceof OWLTypedConstant) { + Datatype dt = OWLAPIConverter.convertDatatype(((OWLTypedConstant)constant).getDataType()); + c = new TypedConstant(constant.getLiteral(),dt); + // for untyped constants we have to figure out the value + // and language tag (if any) + } else { + OWLUntypedConstant ouc = (OWLUntypedConstant) constant; + if(ouc.hasLang()) + c = new UntypedConstant(ouc.getLiteral(), ouc.getLang()); + else + c = new UntypedConstant(ouc.getLiteral()); + } + return c; + } + + public static Set<Constant> convertConstants(Set<OWLConstant> constants) { + SortedSet<Constant> is = new TreeSet<Constant>(); + for(OWLConstant oi : constants) { + is.add(convertConstant(oi)); + } + return is; + } + + public static Datatype convertDatatype(OWLDataType dataType) { + URI uri = dataType.getURI(); + if(uri.equals(Datatype.BOOLEAN.getURI())) + return Datatype.BOOLEAN; + else if(uri.equals(Datatype.DOUBLE.getURI())) + return Datatype.DOUBLE; + else if(uri.equals(Datatype.INT.getURI())) + return Datatype.INT; + + throw new Error("Unsupported datatype " + dataType + ". Please inform a DL-Learner developer to add it."); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |