From: <jen...@us...> - 2008-02-22 21:58:49
|
Revision: 630 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=630&view=rev Author: jenslehmann Date: 2008-02-22 13:58:43 -0800 (Fri, 22 Feb 2008) Log Message: ----------- added support for boolean datatype restrictions Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/BooleanDatatypePropertyAssertion.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java 2008-02-22 17:05:52 UTC (rev 629) +++ trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java 2008-02-22 21:58:43 UTC (rev 630) @@ -33,4 +33,6 @@ public void visit(DoubleDatatypePropertyAssertion axiom); + public void visit(BooleanDatatypePropertyAssertion axiom); + } Added: trunk/src/dl-learner/org/dllearner/core/owl/BooleanDatatypePropertyAssertion.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/BooleanDatatypePropertyAssertion.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/BooleanDatatypePropertyAssertion.java 2008-02-22 21:58:43 UTC (rev 630) @@ -0,0 +1,54 @@ +/** + * 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.util.Map; + +/** + * @author Jens Lehmann + * + */ +public class BooleanDatatypePropertyAssertion extends DatatypePropertyAssertion { + + private boolean value; + + public BooleanDatatypePropertyAssertion(DatatypeProperty datatypeProperty, Individual individual, boolean value) { + super(datatypeProperty, individual); + this.value = value; + } + + public String toString(String baseURI, Map<String, String> prefixes) { + return datatypeProperty.toString(baseURI, prefixes) + "(" + individual.toString(baseURI, prefixes) + "," + value +")"; + } + + public boolean getValue() { + return value; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + +} Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-22 17:05:52 UTC (rev 629) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-22 21:58:43 UTC (rev 630) @@ -31,6 +31,7 @@ import java.util.Set; import java.util.TreeSet; +import org.dllearner.core.owl.BooleanDatatypePropertyAssertion; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ClassAssertionAxiom; @@ -88,7 +89,7 @@ // we need a counter for bonds, because they are instances in OWL // but not in Prolog private static int bondNr = 0; - + /** * @param args * No arguments supported. @@ -216,13 +217,27 @@ // Body body = clause.getBody(); // ArrayList<Literal> literals = body.getLiterals(); // handle: atm(compound,atom,element,atomtype,charge) - if (headName.equals("atm")) { - + + // Ames-Test: http://en.wikipedia.org/wiki/Ames_test + // problem: the file apparently mentions only positive + // tests (why is it different from the other tests e.g. in + // gentoxprops.pl?) => we need to add negative axioms for the + // remaining stuff or use closed world assumption in the + // TBox dematerialisation later on + if(headName.equals("ames")) { String compoundName = head.getArgument(0).toPLString(); + BooleanDatatypePropertyAssertion ames = getBooleanDatatypePropertyAssertion(compoundName, "amesTestPositive", true); + axioms.add(ames); + + } else if (headName.equals("atm")) { + String compoundName = head.getArgument(0).toPLString(); String atomName = head.getArgument(1).toPLString(); String elementName = head.getArgument(2).toPLString(); String type = head.getArgument(3).toPLString(); double charge = Double.parseDouble(head.getArgument(4).toPLString()); + // make the compound an instance of the Compound class + ClassAssertionAxiom cmpAxiom = getConceptAssertion("Compound", compoundName); + axioms.add(cmpAxiom); // relate compound and atom ObjectPropertyAssertion ra = getRoleAssertion("hasAtom", compoundName, atomName); axioms.add(ra); @@ -272,6 +287,7 @@ System.out.println("unsupported clause"); System.out.println(clause.toPLString()); System.out.println(clause); +// System.exit(0); } return axioms; } @@ -323,6 +339,13 @@ return new ObjectPropertyAssertion(ar, ind1, ind2); } + private static BooleanDatatypePropertyAssertion getBooleanDatatypePropertyAssertion( + String individual, String datatypeProperty, boolean value) { + Individual ind = getIndividual(individual); + DatatypeProperty dp = getDatatypeProperty(datatypeProperty); + return new BooleanDatatypePropertyAssertion(dp, ind, value); + } + private static DoubleDatatypePropertyAssertion getDoubleDatatypePropertyAssertion( String individual, String datatypeProperty, double value) { Individual ind = getIndividual(individual); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-02-22 17:05:52 UTC (rev 629) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-02-22 21:58:43 UTC (rev 630) @@ -25,6 +25,7 @@ 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; @@ -146,6 +147,19 @@ 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) * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-23 09:10:53
|
Revision: 631 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=631&view=rev Author: jenslehmann Date: 2008-02-23 01:10:40 -0800 (Sat, 23 Feb 2008) Log Message: ----------- carcinogenesis mapping extended Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/KB.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/KB.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/KB.java 2008-02-22 21:58:43 UTC (rev 630) +++ trunk/src/dl-learner/org/dllearner/core/owl/KB.java 2008-02-23 09:10:40 UTC (rev 631) @@ -8,6 +8,7 @@ public class KB implements KBElement { + // private Set<Axiom> axioms = new HashSet<Axiom>(); private Set<AssertionalAxiom> abox = new HashSet<AssertionalAxiom>(); private Set<TerminologicalAxiom> tbox = new HashSet<TerminologicalAxiom>(); private Set<PropertyAxiom> rbox = new HashSet<PropertyAxiom>(); @@ -239,6 +240,23 @@ public void accept(KBElementVisitor visitor) { visitor.visit(this); - } + } + + /** + * Returns all axioms in the ontology. Note that calling this + * method is not efficient for large knowledge bases, since + * internally all axioms are separated into ABox, RBox, and + * TBox, which means that a union of these sets is computed + * and returned here. + * + * @return All axioms in the ontology. + */ + public Set<Axiom> getAxioms() { + Set<Axiom> axioms = new HashSet<Axiom>(); + axioms.addAll(abox); + axioms.addAll(rbox); + axioms.addAll(tbox); + return axioms; + } } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-22 21:58:43 UTC (rev 630) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-23 09:10:40 UTC (rev 631) @@ -24,6 +24,7 @@ import java.io.IOException; import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -82,14 +83,27 @@ // mapping of symbols to names of chemical elements private static Map<String, String> chemElements; - // types of atoms and bonds + // structures in newgroups.pl + private static Set<String> newGroups = new TreeSet<String>(); + + // types of atoms, bonds, and structures private static Set<String> atomTypes = new TreeSet<String>(); private static Set<String> bondTypes = new TreeSet<String>(); + private static Set<String> structureTypes = new TreeSet<String>(); // we need a counter for bonds, because they are instances in OWL // but not in Prolog private static int bondNr = 0; + private static int structureNr = 0; + // list of all compounds + private static Set<String> compounds = new TreeSet<String>(); + // compounds with positive ames test + private static Set<String> compoundsAmes = new TreeSet<String>(); + + // list of all "hasProperty" test + private static Set<String> tests = new TreeSet<String>(); + /** * @param args * No arguments supported. @@ -100,8 +114,8 @@ public static void main(String[] args) throws FileNotFoundException, IOException, ParseException { - String[] files = new String[] { "ames.pl", "atoms.pl", "bonds.pl", "gentoxprops.pl", - "ind_nos.pl", "ind_pos.pl", "newgroups.pl", + String[] files = new String[] { "newgroups.pl", "ames.pl", "atoms.pl", "bonds.pl", "gentoxprops.pl", + "ind_nos.pl", "ind_pos.pl", // "train.b" => not a pure Prolog file but Progol/Aleph specific }; File owlFile = new File("examples/carcinogenesis/pte.owl"); @@ -133,6 +147,7 @@ // prepare mapping KB kb = new KB(); createChemElementsMapping(); + createNewGroups(); // create subclasses of atom NamedClass atomClass = getAtomicConcept("Atom"); for (String element : chemElements.values()) { @@ -161,6 +176,20 @@ for (Axiom axiom : axioms) kb.addAxiom(axiom); } + // special handling for ames test (we assume the ames test + // was performed on all compounds but only the positive ones + // are in ames.pl [the rest is negative in Prolog by CWA], so + // we add negative test results here) + for(String compound : compounds) { + if(!compoundsAmes.contains(compound)) { + BooleanDatatypePropertyAssertion ames = getBooleanDatatypePropertyAssertion(compound, "amesTestPositive", false); + kb.addAxiom(ames); + } + } + + // TODO: disjoint classes axioms + // TODO: all different axiom (UNA) + duration = System.nanoTime() - startTime; time = Helper.prettyPrintNanoSeconds(duration, false, false); System.out.println("OK (" + time + ")."); @@ -210,7 +239,7 @@ // on "Testing Status of Agents at NTP" } - private static List<Axiom> mapClause(Clause clause) { + private static List<Axiom> mapClause(Clause clause) throws IOException, ParseException { List<Axiom> axioms = new LinkedList<Axiom>(); Atom head = clause.getHead(); String headName = head.getName(); @@ -228,7 +257,7 @@ String compoundName = head.getArgument(0).toPLString(); BooleanDatatypePropertyAssertion ames = getBooleanDatatypePropertyAssertion(compoundName, "amesTestPositive", true); axioms.add(ames); - + compoundsAmes.add(compoundName); } else if (headName.equals("atm")) { String compoundName = head.getArgument(0).toPLString(); String atomName = head.getArgument(1).toPLString(); @@ -237,7 +266,8 @@ double charge = Double.parseDouble(head.getArgument(4).toPLString()); // make the compound an instance of the Compound class ClassAssertionAxiom cmpAxiom = getConceptAssertion("Compound", compoundName); - axioms.add(cmpAxiom); + axioms.add(cmpAxiom); + compounds.add(compoundName); // relate compound and atom ObjectPropertyAssertion ra = getRoleAssertion("hasAtom", compoundName, atomName); axioms.add(ra); @@ -282,12 +312,55 @@ ObjectPropertyAssertion op2 = getRoleAssertion("inBond", bondInstance, atom2Name); axioms.add(op1); axioms.add(op2); + } else if (headName.equals("has_property")) { + String compoundName = head.getArgument(0).toPLString(); + String testName = head.getArgument(1).toPLString(); + boolean testResult = Boolean.parseBoolean(head.getArgument(2).toPLString()); + // create a new datatype property if it does not exist already + if(!tests.contains(testName)) { + String axiom1 = "DPDOMAIN(" + getURI2(testName) + ") = " + getURI2("Compound") + ".\n"; + String axiom2 = "DPRANGE(" + getURI2(testName) + ") = BOOLEAN.\n"; + KB kb = KBParser.parseKBFile(axiom1 + axiom2); + axioms.addAll(kb.getAxioms()); + } + // create an axiom with the test result + DatatypePropertyAssertion dpa = getBooleanDatatypePropertyAssertion(compoundName, testName, + testResult); + axioms.add(dpa); + // either parse this or ashby_alert - not both - ashby_alert contains + // all information in ind already + } else if (headName.equals("ind")) { + String compoundName = head.getArgument(0).toPLString(); + String structureName = head.getArgument(1).toPLString(); + int count = Integer.parseInt(head.getArgument(2).toPLString()); + // upper case first letter + String structureClass = structureName.substring(0,1).toUpperCase() + structureName.substring(1);; + String structureInstance = structureName + "-" + structureNr; + + if (!bondTypes.contains(structureClass)) { + NamedClass subClass = getAtomicConcept(structureClass); + SubClassAxiom sc = new SubClassAxiom(subClass, getAtomicConcept("Structure")); + axioms.add(sc); + structureTypes.add(structureClass); + } + + for(int i=0; i<count; i++) { + ObjectPropertyAssertion op = getRoleAssertion("hasStructure", compoundName, structureInstance); + axioms.add(op); + // make e.g. halide10-382 instance of Bond-3 + ClassAssertionAxiom ca = getConceptAssertion(structureClass, structureInstance); + axioms.add(ca); + structureNr++; + } + } else if (headName.equals("ashby_alert")) { + // ... currently ignored ... + } else if (newGroups.contains(headName)) { } else { // print clauses which are not supported yet System.out.println("unsupported clause"); System.out.println(clause.toPLString()); System.out.println(clause); -// System.exit(0); + System.exit(0); } return axioms; } @@ -419,4 +492,19 @@ chemElements.put("v", "Vanadium"); chemElements.put("zn", "Zinc"); } + + private static void createNewGroups() { + String[] groups = new String[] {"six_ring", "non_ar_6c_ring", + "ketone", "amine", "alcohol", "ether", "ar_halide", + "five_ring", "non_ar_5c_ring", "alkyl_halide", + "methyl", "non_ar_hetero_5_ring", "nitro", "sulfo", + "methoxy", "amine", "aldehyde", "sulfide", + "non_ar_hetero_6_ring", "phenol", "carboxylic_acid", + "ester", "imine", + }; + + List<String> list = Arrays.asList(groups); + newGroups.addAll(list); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-23 21:13:15
|
Revision: 632 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=632&view=rev Author: jenslehmann Date: 2008-02-23 13:13:06 -0800 (Sat, 23 Feb 2008) Log Message: ----------- - added support for two axiom types: different individuals and disjoint classes - detected bug in OWL API different individuals export Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/core/owl/AssertionalAxiomVisitor.java 2008-02-23 21:13:06 UTC (rev 632) @@ -35,4 +35,6 @@ public void visit(BooleanDatatypePropertyAssertion axiom); + public void visit(DifferentIndividualsAxiom axiom); + } Added: trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/DifferentIndividualsAxiom.java 2008-02-23 21:13:06 UTC (rev 632) @@ -0,0 +1,65 @@ +/** + * 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.util.Map; +import java.util.Set; + +/** + * @author Jens Lehmann + * + */ +public class DifferentIndividualsAxiom extends AssertionalAxiom { + + private Set<Individual> individuals; + + public DifferentIndividualsAxiom(Set<Individual> individuals) { + this.individuals = individuals; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + return individuals.size() + 1; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + // TODO Auto-generated method stub + return null; + } + + public Set<Individual> getIndividuals() { + return individuals; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/DisjointClassesAxiom.java 2008-02-23 21:13:06 UTC (rev 632) @@ -0,0 +1,71 @@ +/** + * 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.util.Map; +import java.util.Set; + +/** + * @author Jens Lehmann + * + */ +public class DisjointClassesAxiom extends TerminologicalAxiom { + + private Set<Description> descriptions; + + public DisjointClassesAxiom(Set<Description> descriptions) { + this.descriptions = descriptions; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + int length = 1; + for(Description d : descriptions) + length += d.getLength(); + return length; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void accept(AxiomVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + + /** + * @return the descriptions + */ + public Set<Description> getDescriptions() { + return descriptions; + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/core/owl/TerminologicalAxiomVisitor.java 2008-02-23 21:13:06 UTC (rev 632) @@ -29,4 +29,5 @@ public void visit(SubClassAxiom axiom); + public void visit(DisjointClassesAxiom axiom); } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-23 21:13:06 UTC (rev 632) @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -33,6 +34,9 @@ import java.util.TreeSet; import org.dllearner.core.owl.BooleanDatatypePropertyAssertion; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DifferentIndividualsAxiom; +import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.ClassAssertionAxiom; @@ -96,10 +100,14 @@ private static int bondNr = 0; private static int structureNr = 0; + // list of all individuals in the knowlege base +// private static Set<String> individuals = new TreeSet<String>(); // list of all compounds private static Set<String> compounds = new TreeSet<String>(); // compounds with positive ames test private static Set<String> compoundsAmes = new TreeSet<String>(); + // list of all bonds + private static Set<String> bonds = new TreeSet<String>(); // list of all "hasProperty" test private static Set<String> tests = new TreeSet<String>(); @@ -187,9 +195,17 @@ } } - // TODO: disjoint classes axioms - // TODO: all different axiom (UNA) + // disjoint classes axioms + DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); + kb.addAxiom(disjointAtomTypes); + // all different axiom (UNA) + // exporting differentIndividuals axioms is broken in OWL API +// individuals.addAll(compounds); +// individuals.addAll(bonds); +// DifferentIndividualsAxiom una = getDifferentIndividualsAxiom(individuals); +// kb.addAxiom(una); + duration = System.nanoTime() - startTime; time = Helper.prettyPrintNanoSeconds(duration, false, false); System.out.println("OK (" + time + ")."); @@ -294,6 +310,7 @@ String bondType = head.getArgument(3).toPLString(); String bondClass = "Bond-" + bondType; String bondInstance = "bond" + bondNr; + bonds.add(bondInstance); ObjectPropertyAssertion op = getRoleAssertion("hasBond", compoundName, "bond" + bondNr); axioms.add(op); // make Bond-X subclass of Bond if that hasn't been done already @@ -426,6 +443,21 @@ return new DoubleDatatypePropertyAssertion(dp, ind, value); } + private static DisjointClassesAxiom getDisjointClassesAxiom(Set<String> classes) { + Set<Description> descriptions = new HashSet<Description>(); + for(String namedClass : classes) + descriptions.add(new NamedClass(namedClass)); + return new DisjointClassesAxiom(descriptions); + } + + @SuppressWarnings({"unused"}) + private static DifferentIndividualsAxiom getDifferentIndividualsAxiom(Set<String> individuals) { + Set<Individual> inds = new HashSet<Individual>(); + for(String i : individuals) + inds.add(new Individual(i)); + return new DifferentIndividualsAxiom(inds); + } + private static Individual getIndividual(String name) { return new Individual(ontologyURI + "#" + name); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-02-23 09:10:40 UTC (rev 631) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIAxiomConvertVisitor.java 2008-02-23 21:13:06 UTC (rev 632) @@ -31,9 +31,13 @@ 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; @@ -294,4 +298,28 @@ 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); + } + } Added: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-23 21:13:06 UTC (rev 632) @@ -0,0 +1,42 @@ +package org.dllearner.test; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.*; +import org.semanticweb.owl.util.SimpleURIMapper; + +import java.io.File; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +public class OWLAPIBugDemo { + + public static void main(String[] args) { + try { + + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + URI ontologyURI = URI.create("http://www.examples.com/test"); + File f = new File("test.owl"); + URI physicalURI = f.toURI(); + SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); + manager.addURIMapper(mapper); + + OWLOntology ontology = manager.createOntology(ontologyURI); + OWLDataFactory factory = manager.getOWLDataFactory(); + + OWLIndividual a = factory.getOWLIndividual(URI.create(ontologyURI + "#a")); + OWLIndividual b = factory.getOWLIndividual(URI.create(ontologyURI + "#b")); + Set<OWLIndividual> inds = new HashSet<OWLIndividual>(); + inds.add(a); + inds.add(b); + + OWLAxiom axiom = factory.getOWLDifferentIndividualsAxiom(inds); + AddAxiom addAxiom = new AddAxiom(ontology, axiom); + manager.applyChange(addAxiom); + manager.saveOntology(ontology); + } + catch (OWLException e) { + e.printStackTrace(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-24 08:45:18
|
Revision: 633 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=633&view=rev Author: jenslehmann Date: 2008-02-24 00:45:08 -0800 (Sun, 24 Feb 2008) Log Message: ----------- - preparations for boolean data type support in refinement operator - added literals/constants in OWL framework - improved package Javadoc 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/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java trunk/src/dl-learner/org/dllearner/core/owl/package.html trunk/src/dl-learner/org/dllearner/gui/package.html Added Paths: ----------- trunk/src/dl-learner/org/dllearner/cli/package.html trunk/src/dl-learner/org/dllearner/core/config/package.html trunk/src/dl-learner/org/dllearner/core/owl/Constant.java trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java trunk/src/dl-learner/org/dllearner/core/package.html trunk/src/dl-learner/org/dllearner/kb/package.html trunk/src/dl-learner/org/dllearner/learningproblems/package.html trunk/src/dl-learner/org/dllearner/prolog/package.html trunk/src/dl-learner/org/dllearner/test/package.html Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-24 08:45:08 UTC (rev 633) @@ -103,7 +103,8 @@ private boolean improveSubsumptionHierarchy = true; private boolean useAllConstructor = true; private boolean useExistsConstructor = true; - private boolean useNegation = true; + private boolean useNegation = true; + private boolean useBooleanDatatypes = true; private double noisePercentage = 0.0; // Variablen zur Einstellung der Protokollierung @@ -161,6 +162,7 @@ options.add(CommonConfigOptions.useAllConstructor()); options.add(CommonConfigOptions.useExistsConstructor()); options.add(CommonConfigOptions.useNegation()); + options.add(CommonConfigOptions.useBooleanDatatypes()); DoubleConfigOption noisePercentage = new DoubleConfigOption("noisePercentage", "the (approximated) percentage of noise within the examples"); noisePercentage.setLowerLimit(0.0); noisePercentage.setUpperLimit(1.0); @@ -215,6 +217,8 @@ useNegation = (Boolean) entry.getValue(); } else if(name.equals("noisePercentage")) { noisePercentage = (Double) entry.getValue(); + } else if(name.equals("useBooleanDatatypes")) { + useBooleanDatatypes = (Boolean) entry.getValue(); } } @@ -281,7 +285,8 @@ applyExistsFilter, useAllConstructor, useExistsConstructor, - useNegation + useNegation, + useBooleanDatatypes ); // create an algorithm object and pass all configuration Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-24 08:45:08 UTC (rev 633) @@ -67,6 +67,7 @@ private boolean useAllConstructor = true; private boolean useExistsConstructor = true; private boolean useNegation = true; + private boolean useBooleanDatatypes = true; private boolean quiet = false; @@ -208,6 +209,7 @@ options.add(CommonConfigOptions.useAllConstructor()); options.add(CommonConfigOptions.useExistsConstructor()); options.add(CommonConfigOptions.useNegation()); + options.add(CommonConfigOptions.useBooleanDatatypes()); return options; } @@ -258,6 +260,8 @@ useExistsConstructor = (Boolean) entry.getValue(); } else if(name.equals("useNegation")) { useNegation = (Boolean) entry.getValue(); + } else if(name.equals("useBooleanDatatypes")) { + useBooleanDatatypes = (Boolean) entry.getValue(); } } @@ -284,7 +288,7 @@ } // this.learningProblem2 = learningProblem2; - operator = new RhoDown(rs, applyAllFilter, applyExistsFilter, useAllConstructor, useExistsConstructor, useNegation); + operator = new RhoDown(rs, applyAllFilter, applyExistsFilter, useAllConstructor, useExistsConstructor, useNegation, useBooleanDatatypes); // candidate sets entsprechend der gewählten Heuristik initialisieren candidates = new TreeSet<Node>(nodeComparator); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 08:45:08 UTC (rev 633) @@ -89,18 +89,20 @@ private boolean applyExistsFilter = true; private boolean useAllConstructor = true; private boolean useExistsConstructor = true; - private boolean useNegation = true; + private boolean useNegation = true; + private boolean useBooleanDatatypes = true; // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? // TODO: conceptComparator könnte auch noch Parameter sein public RhoDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, - boolean useExistsConstructor, boolean useNegation) { + boolean useExistsConstructor, boolean useNegation, boolean useBooleanDatatypes) { this.rs = reasoningService; this.applyAllFilter = applyAllFilter; this.applyExistsFilter = applyExistsFilter; this.useAllConstructor = useAllConstructor; this.useExistsConstructor = useExistsConstructor; this.useNegation = useNegation; + this.useBooleanDatatypes = useBooleanDatatypes; // this.learningProblem = learningProblem; // rs = learningProblem.getReasoningService(); @@ -141,6 +143,7 @@ } else if (concept instanceof Nothing) { // return new HashSet<Concept>(); +// } else if (concept instanceof ) } else if (concept instanceof NamedClass) { // Erkenntnisse aus Benchmarks: dieser Teil wird sehr häufig aufgerufen, // allerdings lässt er sich kaum weiter verbessern (selbst ohne klonen Added: trunk/src/dl-learner/org/dllearner/cli/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/cli/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>DL-Learner command line interface.</p> +</body> +</html> \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/core/config/CommonConfigOptions.java 2008-02-24 08:45:08 UTC (rev 633) @@ -82,4 +82,8 @@ public static BooleanConfigOption useNegation() { return new BooleanConfigOption("useNegation", "specifies whether negation is used in the learning algorothm"); } + + public static BooleanConfigOption useBooleanDatatypes() { + return new BooleanConfigOption("useBooleanDatatypes", "specifies whether boolean datatypes are used in the learning algorothm"); + } } Added: trunk/src/dl-learner/org/dllearner/core/config/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/config/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,8 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Classes for managing the configuration options of DL-Learner +components.</p> +</body> +</html> \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/core/owl/Constant.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Constant.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/Constant.java 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,42 @@ +/** + * 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; + +/** + * A constant value. + * + * @author Jens Lehmann + * + */ +public abstract class Constant implements KBElement { + + String literal; + + public Constant(String literal) { + this.literal = literal; + } + + /** + * @return the literal + */ + public String getLiteral() { + return literal; + } +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-24 08:45:08 UTC (rev 633) @@ -22,11 +22,17 @@ import java.util.Map; /** + * Examples for datatype value restrictions: + * Male AND hasAge HASVALUE 18 + * Male AND hasDriverLicense HASVALUE true + * * @author Jens Lehmann * */ public class DatatypeValueRestriction extends ValueRestriction { +// public DatatypeValueRestriction(DatatypeProperty) + /* (non-Javadoc) * @see org.dllearner.core.owl.Description#accept(org.dllearner.core.owl.DescriptionVisitor) */ Modified: trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/core/owl/KBElementVisitor.java 2008-02-24 08:45:08 UTC (rev 633) @@ -39,4 +39,8 @@ void visit(KB kb); + void visit(TypedConstant typedConstant); + + void visit(UntypedConstant untypedConstant); + } Added: trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,67 @@ +/** + * 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.util.Map; + +/** + * A constant which has an explicitly assigned datatype. + * + * @author Jens Lehmann + * + */ +public class TypedConstant extends Constant { + + private Datatype datatype; + + public TypedConstant(String literal, Datatype datatype) { + super(literal); + this.datatype = datatype; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + return 1; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + return literal + datatype.toString(baseURI, prefixes); + } + + /** + * @return the datatype + */ + public Datatype getDatatype() { + return datatype; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#accept(org.dllearner.core.owl.KBElementVisitor) + */ + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + +} Added: trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,85 @@ +/** + * 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.util.Map; + +/** + * An untyped constant is a string which has not been assigned + * a datatype and can have an optional language tag. + * + * @author Jens Lehmann + * + */ +public class UntypedConstant extends Constant { + + private String lang; + private boolean hasLang = false; + + public UntypedConstant(String literal) { + super(literal); + } + + public UntypedConstant(String literal, String lang) { + super(literal); + this.lang = lang; + hasLang = true; + } + + + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + return 1; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + if(hasLang) + return literal + "@" + lang; + else + return literal; + } + + /** + * @return the lang + */ + public String getLang() { + return lang; + } + + /** + * @return the hasLang + */ + public boolean hasLang() { + return hasLang; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#accept(org.dllearner.core.owl.KBElementVisitor) + */ + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/package.html 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/core/owl/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -2,6 +2,8 @@ <html> <head></head> <body bgcolor="white"> -<p>Classes for representing OWL constructs.</p> +<p>Classes/Interfaces for representing OWL constructs - see +the <a href="http://www.w3.org/TR/owl11-syntax">OWL 1.1 Structural +Specification</a> for details.</p> </body> </html> \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/core/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/core/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Core structure of DL-Learner including the definition of component types and a component manager.</p> +</body> +</html> \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/gui/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/package.html 2008-02-23 21:13:06 UTC (rev 632) +++ trunk/src/dl-learner/org/dllearner/gui/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -2,6 +2,6 @@ <html> <head></head> <body bgcolor="white"> -<p>Classes to generate a Graphical User Interface for DL-Learner.</p> +<p>Graphical user interface for DL-Learner.</p> </body> </html> \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/kb/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,8 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>DL-Learner knowledge sources, which can be used as background +knowledge in learning problems.</p> +</body> +</html> \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/learningproblems/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/learningproblems/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Supported DL-Learner learning problems.</p> +</body> +</html> \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/prolog/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/prolog/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/prolog/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Prolog syntax structures.</p> +</body> +</html> \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/test/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/test/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/package.html 2008-02-24 08:45:08 UTC (rev 633) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>DL-Learner tests for performance, bug reports etc.</p> +</body> +</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-24 16:28:42
|
Revision: 634 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=634&view=rev Author: jenslehmann Date: 2008-02-24 08:27:53 -0800 (Sun, 24 Feb 2008) Log Message: ----------- aligned core OWL structures closer to OWL 1.1 structure spec Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/CardinalityRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeCardinalityRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeExactCardinalityRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMaxCardinalityRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMinCardinalityRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectAllRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectCardinalityRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyExpression.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectQuantorRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectSomeRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ObjectValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/Property.java trunk/src/dl-learner/org/dllearner/core/owl/PropertyExpression.java trunk/src/dl-learner/org/dllearner/core/owl/QuantorRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/Restriction.java trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/CardinalityRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/CardinalityRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/CardinalityRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -25,4 +25,27 @@ */ public abstract class CardinalityRestriction extends Restriction { + int cardinality; + PropertyRange propertyRange; + + public CardinalityRestriction(PropertyExpression propertyExpression, PropertyRange propertyRange, int cardinality) { + super(propertyExpression); + this.propertyRange = propertyRange; + this.cardinality = cardinality; + } + + /** + * @return the cardinality + */ + public int getCardinality() { + return cardinality; + } + + /** + * @return the propertyRange + */ + public PropertyRange getPropertyRange() { + return propertyRange; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeCardinalityRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeCardinalityRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeCardinalityRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -25,4 +25,9 @@ */ public abstract class DatatypeCardinalityRestriction extends CardinalityRestriction { + public DatatypeCardinalityRestriction(DatatypeProperty datatypeProperty, + DataRange dataRange, int cardinality) { + super(datatypeProperty, dataRange, cardinality); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeExactCardinalityRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeExactCardinalityRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeExactCardinalityRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -27,6 +27,17 @@ */ public class DatatypeExactCardinalityRestriction extends DatatypeCardinalityRestriction { + /** + * @param datatypeProperty + * @param dataRange + * @param cardinality + */ + public DatatypeExactCardinalityRestriction(DatatypeProperty datatypeProperty, + DataRange dataRange, int cardinality) { + super(datatypeProperty, dataRange, cardinality); + // TODO Auto-generated constructor stub + } + /* (non-Javadoc) * @see org.dllearner.core.owl.Concept#getArity() */ Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMaxCardinalityRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMaxCardinalityRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMaxCardinalityRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -27,6 +27,17 @@ */ public class DatatypeMaxCardinalityRestriction extends DatatypeCardinalityRestriction { + /** + * @param datatypeProperty + * @param dataRange + * @param cardinality + */ + public DatatypeMaxCardinalityRestriction(DatatypeProperty datatypeProperty, + DataRange dataRange, int cardinality) { + super(datatypeProperty, dataRange, cardinality); + // TODO Auto-generated constructor stub + } + /* (non-Javadoc) * @see org.dllearner.core.owl.Concept#getArity() */ Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMinCardinalityRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMinCardinalityRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeMinCardinalityRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -27,6 +27,17 @@ */ public class DatatypeMinCardinalityRestriction extends DatatypeCardinalityRestriction { + /** + * @param datatypeProperty + * @param dataRange + * @param cardinality + */ + public DatatypeMinCardinalityRestriction(DatatypeProperty datatypeProperty, + DataRange dataRange, int cardinality) { + super(datatypeProperty, dataRange, cardinality); + // TODO Auto-generated constructor stub + } + /* (non-Javadoc) * @see org.dllearner.core.owl.Concept#getArity() */ Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-02-24 16:27:53 UTC (rev 634) @@ -27,7 +27,7 @@ * @author Jens Lehmann * */ -public class DatatypeProperty extends PropertyExpression implements Property, NamedKBElement { +public class DatatypeProperty implements Property, NamedKBElement { protected String name; Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -25,4 +25,11 @@ */ public abstract class DatatypeQuantorRestriction extends QuantorRestriction { + /** + * @param propertyExpression + */ + public DatatypeQuantorRestriction(DatatypeProperty datatypeProperty) { + super(datatypeProperty); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -32,8 +32,13 @@ */ public class DatatypeSomeRestriction extends DatatypeQuantorRestriction { + /** + * @param datatypeProperty + */ + public DatatypeSomeRestriction(DatatypeProperty datatypeProperty) { + super(datatypeProperty); + } - /* (non-Javadoc) * @see org.dllearner.core.owl.Description#getArity() */ Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -31,26 +31,53 @@ */ public class DatatypeValueRestriction extends ValueRestriction { -// public DatatypeValueRestriction(DatatypeProperty) + public DatatypeValueRestriction(DatatypeProperty restrictedPropertyExpression, Constant value) { + super(restrictedPropertyExpression, value); + } /* (non-Javadoc) - * @see org.dllearner.core.owl.Description#accept(org.dllearner.core.owl.DescriptionVisitor) + * @see org.dllearner.core.owl.Description#toManchesterSyntaxString() */ @Override - public void accept(DescriptionVisitor visitor) { - visitor.visit(this); - } - - public void accept(KBElementVisitor visitor) { - visitor.visit(this); + public String toManchesterSyntaxString(String baseURI, Map<String,String> prefixes) { + // TODO Auto-generated method stub + return null; } /* (non-Javadoc) - * @see org.dllearner.core.owl.Description#toManchesterSyntaxString() + * @see org.dllearner.core.owl.Description#getArity() */ @Override - public String toManchesterSyntaxString(String baseURI, Map<String,String> prefixes) { + public int getArity() { // TODO Auto-generated method stub - return null; + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + return 1 + restrictedPropertyExpression.getLength() + value.getLength(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + return restrictedPropertyExpression.toString(baseURI, prefixes) + " = " + value.toString(baseURI, prefixes); + } + + @Override + public Constant getValue() { + return (Constant) value; } + + @Override + public void accept(DescriptionVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectAllRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectAllRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectAllRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -35,12 +35,12 @@ } public String toString(String baseURI, Map<String,String> prefixes) { - return "ALL " + role + "." + children.get(0).toString(baseURI, prefixes); + return "ALL " + restrictedPropertyExpression.toString(baseURI, prefixes) + "." + children.get(0).toString(baseURI, prefixes); } @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return role.toString(baseURI, prefixes) + " some " + children.get(0).toManchesterSyntaxString(baseURI, prefixes); + return restrictedPropertyExpression.toString(baseURI, prefixes) + " some " + children.get(0).toManchesterSyntaxString(baseURI, prefixes); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectCardinalityRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectCardinalityRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectCardinalityRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -6,6 +6,7 @@ protected int number; public ObjectCardinalityRestriction(int number, ObjectPropertyExpression role, Description c) { + super(role, c, number); addChild(c); this.role = role; this.number = number; Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyExpression.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyExpression.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyExpression.java 2008-02-24 16:27:53 UTC (rev 634) @@ -27,7 +27,7 @@ * @author Jens Lehmann * */ -public abstract class ObjectPropertyExpression extends PropertyExpression implements KBElement { +public abstract class ObjectPropertyExpression implements PropertyExpression { protected String name; Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectQuantorRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectQuantorRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectQuantorRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -1,20 +1,42 @@ +/** + * 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; +/** + * + * @author Jens Lehmann + * + */ public abstract class ObjectQuantorRestriction extends QuantorRestriction { - ObjectPropertyExpression role; - public ObjectQuantorRestriction(ObjectPropertyExpression role, Description c) { - this.role = role; + super(role); addChild(c); } public ObjectPropertyExpression getRole() { - return role; + return (ObjectPropertyExpression) restrictedPropertyExpression; } public int getLength() { - return 1 + role.getLength() + getChild(0).getLength(); + return 1 + restrictedPropertyExpression.getLength() + getChild(0).getLength(); } @Override Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectSomeRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectSomeRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectSomeRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -34,12 +34,12 @@ } public String toString(String baseURI, Map<String,String> prefixes) { - return "EXISTS " + role.toString(baseURI, prefixes) + "." + children.get(0).toString(baseURI, prefixes); + return "EXISTS " + restrictedPropertyExpression.toString(baseURI, prefixes) + "." + children.get(0).toString(baseURI, prefixes); } @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return role.toString(baseURI, prefixes) + " only " + children.get(0).toManchesterSyntaxString(baseURI, prefixes); + return restrictedPropertyExpression.toString(baseURI, prefixes) + " only " + children.get(0).toManchesterSyntaxString(baseURI, prefixes); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ObjectValueRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectValueRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -30,16 +30,11 @@ */ public class ObjectValueRestriction extends ValueRestriction { - /* (non-Javadoc) - * @see org.dllearner.core.owl.Description#accept(org.dllearner.core.owl.DescriptionVisitor) + /** + * @param property */ - @Override - public void accept(DescriptionVisitor visitor) { - visitor.visit(this); - } - - public void accept(KBElementVisitor visitor) { - visitor.visit(this); + public ObjectValueRestriction(Property property, Individual value) { + super(property, value); } /* (non-Javadoc) @@ -49,5 +44,43 @@ public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { // TODO Auto-generated method stub return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.Description#getArity() + */ + @Override + public int getArity() { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#getLength() + */ + public int getLength() { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) + */ + public String toString(String baseURI, Map<String, String> prefixes) { + // TODO Auto-generated method stub + return null; } + + public Individual getIndividual() { + return (Individual) value; + } + + @Override + public void accept(DescriptionVisitor visitor) { + visitor.visit(this); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/Property.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Property.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/Property.java 2008-02-24 16:27:53 UTC (rev 634) @@ -23,6 +23,6 @@ * @author Jens Lehmann * */ -public interface Property extends NamedKBElement { +public interface Property extends PropertyExpression, NamedKBElement { } Modified: trunk/src/dl-learner/org/dllearner/core/owl/PropertyExpression.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/PropertyExpression.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/PropertyExpression.java 2008-02-24 16:27:53 UTC (rev 634) @@ -23,6 +23,6 @@ * @author Jens Lehmann * */ -public abstract class PropertyExpression implements KBElement { +public interface PropertyExpression extends KBElement { } Modified: trunk/src/dl-learner/org/dllearner/core/owl/QuantorRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/QuantorRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/QuantorRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -25,4 +25,8 @@ */ public abstract class QuantorRestriction extends Restriction { + public QuantorRestriction(PropertyExpression restrictedPropertyExpression) { + super(restrictedPropertyExpression); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/Restriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Restriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/Restriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -20,10 +20,21 @@ package org.dllearner.core.owl; /** + * A restriction always acts along a property expression. + * * @author Jens Lehmann * */ public abstract class Restriction extends Description { + + PropertyExpression restrictedPropertyExpression; + + public Restriction(PropertyExpression restrictedPropertyExpression) { + this.restrictedPropertyExpression = restrictedPropertyExpression; + } - + public PropertyExpression getRestrictedPropertyExpression() { + return restrictedPropertyExpression; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java 2008-02-24 16:27:53 UTC (rev 634) @@ -19,37 +19,22 @@ */ package org.dllearner.core.owl; -import java.util.Map; - /** + * + * * @author Jens Lehmann * */ -public abstract class ValueRestriction extends Description { +public abstract class ValueRestriction extends Restriction { - /* (non-Javadoc) - * @see org.dllearner.core.owl.Concept#getArity() - */ - @Override - public int getArity() { - // TODO Auto-generated method stub - return 0; + KBElement value; + + public ValueRestriction(PropertyExpression propertyExpression, KBElement value) { + super(propertyExpression); } - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#getLength() - */ - public int getLength() { - // TODO Auto-generated method stub - return 0; + public KBElement getValue() { + return value; } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) - */ - public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; - } - + } Modified: trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java 2008-02-24 08:45:08 UTC (rev 633) +++ trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java 2008-02-24 16:27:53 UTC (rev 634) @@ -1,3 +1,22 @@ +/** + * 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.utilities; import java.util.Comparator; @@ -5,6 +24,12 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectPropertyExpression; +/** + * Compares two object properties. + * + * @author Jens Lehmann + * + */ public class RoleComparator implements Comparator<ObjectPropertyExpression> { public int compare(ObjectPropertyExpression r1, ObjectPropertyExpression r2) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-24 17:48:02
|
Revision: 635 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=635&view=rev Author: jenslehmann Date: 2008-02-24 09:47:44 -0800 (Sun, 24 Feb 2008) Log Message: ----------- - boolean hasValue restrictions - Datatype now implemented as enum (easier programmatic access) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/core/owl/BooleanDataRange.java trunk/src/dl-learner/org/dllearner/core/owl/DataRange.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DoubleDataRange.java trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java trunk/src/dl-learner/org/dllearner/parser/kb.jj Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 17:47:44 UTC (rev 635) @@ -42,6 +42,7 @@ import org.dllearner.core.owl.ObjectPropertyExpression; import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.ValueRestriction; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; @@ -143,7 +144,8 @@ } else if (concept instanceof Nothing) { // return new HashSet<Concept>(); -// } else if (concept instanceof ) + } else if (concept instanceof ValueRestriction) { + // value restrictions cannot be further refined } else if (concept instanceof NamedClass) { // Erkenntnisse aus Benchmarks: dieser Teil wird sehr häufig aufgerufen, // allerdings lässt er sich kaum weiter verbessern (selbst ohne klonen Modified: trunk/src/dl-learner/org/dllearner/core/owl/BooleanDataRange.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/BooleanDataRange.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/BooleanDataRange.java 2008-02-24 17:47:44 UTC (rev 635) @@ -28,7 +28,7 @@ * @author Jens Lehmann * */ -public class BooleanDataRange extends DataRange { +public class BooleanDataRange implements DataRange { private boolean isTrue; Added: trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java 2008-02-24 17:47:44 UTC (rev 635) @@ -0,0 +1,47 @@ +/** + * 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; + +/** + * Convenience class for boolean value restrictions. + * + * @author Jens Lehmann + * + */ +public class BooleanValueRestriction extends DatatypeValueRestriction { + + /** + * TODO: Internally a typed constant with datatype boolean and + * strings "true" or "false" is created. This is a clean way to + * implement boolean value restrictions. However, if they are + * created millions of times during the run of an algorithm, + * this may cause unnecessary delays. + * Possible Solution: It may be good to create a BooleanConstant + * class, which just holds the boolean value and only performs + * operations when requested. + * + * @param restrictedPropertyExpression + * @param value + */ + public BooleanValueRestriction(DatatypeProperty restrictedPropertyExpression, Boolean value) { + super(restrictedPropertyExpression, new TypedConstant(value.toString(), Datatype.BOOLEAN)); + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/DataRange.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DataRange.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/DataRange.java 2008-02-24 17:47:44 UTC (rev 635) @@ -23,6 +23,6 @@ * @author Jens Lehmann * */ -public abstract class DataRange implements PropertyRange { +public interface DataRange extends PropertyRange { } Deleted: trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2008-02-24 17:47:44 UTC (rev 635) @@ -1,82 +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.owl; - -import java.net.URI; -import java.util.Map; - -/** - * Enumeration of possible types wrapped in a class such that - * it is a valid data range. - * - * @author Jens Lehmann - * - */ -public class Datatype extends DataRange { - - public enum Type { DOUBLE, INT, BOOLEAN }; - - private Type type; - - private static final String xsd = "http://www.w3.org/2001/XMLSchema#"; - - public Datatype(Type type) { - this.type = type; - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#accept(org.dllearner.core.owl.KBElementVisitor) - */ - public void accept(KBElementVisitor visitor) { - visitor.visit(this); - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#getLength() - */ - public int getLength() { - return 1; - } - - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) - */ - public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; - } - - public URI getURI() { - switch(type) { - case DOUBLE: return URI.create(xsd + "double"); - case INT: return URI.create(xsd + "int"); - case BOOLEAN: return URI.create(xsd + "Boolean"); - default: throw new Error("Unknown tpye " + type + "."); - } - } - - /** - * @return the type - */ - public Type getType() { - return type; - } - -} Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-24 17:47:44 UTC (rev 635) @@ -67,6 +67,10 @@ return restrictedPropertyExpression.toString(baseURI, prefixes) + " = " + value.toString(baseURI, prefixes); } + public DatatypeProperty getRestrictedPropertyExpresssion() { + return (DatatypeProperty) restrictedPropertyExpression; + } + @Override public Constant getValue() { return (Constant) value; Modified: trunk/src/dl-learner/org/dllearner/core/owl/DoubleDataRange.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DoubleDataRange.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/DoubleDataRange.java 2008-02-24 17:47:44 UTC (rev 635) @@ -25,6 +25,6 @@ * @author Jens Lehmann * */ -public abstract class DoubleDataRange extends DataRange { +public interface DoubleDataRange extends DataRange { } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java 2008-02-24 17:47:44 UTC (rev 635) @@ -28,7 +28,7 @@ * @author Jens Lehmann * */ -public class DoubleMaxValue extends DoubleDataRange { +public class DoubleMaxValue implements DoubleDataRange { private double value; Modified: trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java 2008-02-24 17:47:44 UTC (rev 635) @@ -28,7 +28,7 @@ * @author Jens Lehmann * */ -public class DoubleMinValue extends DoubleDataRange { +public class DoubleMinValue implements DoubleDataRange { private double value; Modified: trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-02-24 17:47:44 UTC (rev 635) @@ -47,7 +47,7 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return literal + datatype.toString(baseURI, prefixes); + return literal + "^^" + datatype; } /** Modified: trunk/src/dl-learner/org/dllearner/parser/kb.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-02-24 16:27:53 UTC (rev 634) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-02-24 17:47:44 UTC (rev 635) @@ -227,9 +227,9 @@ DatatypePropertyRangeAxiom DatatypePropertyRangeAxiom() : {DatatypeProperty op; DataRange range; } { ( "DPRANGE" | "DATATYPEPROPERTYRANGE") "(" op=DatatypeProperty() ")" "=" - ( "DOUBLE" { range = new Datatype(Datatype.Type.DOUBLE); } - | "BOOLEAN" { range = new Datatype(Datatype.Type.BOOLEAN); } - | "INTEGER" { range = new Datatype(Datatype.Type.INT); } ) + ( "DOUBLE" { range = Datatype.DOUBLE; } + | "BOOLEAN" { range = Datatype.BOOLEAN; } + | "INTEGER" { range = Datatype.INT; } ) <COMMAND_END> { return new DatatypePropertyRangeAxiom(op, range); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-24 17:49:34
|
Revision: 636 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=636&view=rev Author: jenslehmann Date: 2008-02-24 09:49:30 -0800 (Sun, 24 Feb 2008) Log Message: ----------- minor parser modifications Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/KBParser.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java Added: trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2008-02-24 17:49:30 UTC (rev 636) @@ -0,0 +1,61 @@ +/** + * 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; + +/** + * @author Jens Lehmann + * + */ +public enum Datatype implements DataRange { + + DOUBLE ("http://www.w3.org/2001/XMLSchema#double"), + INT ("http://www.w3.org/2001/XMLSchema#int"), + BOOLEAN ("http://www.w3.org/2001/XMLSchema#Boolean"); + + private URI uri; + + private Datatype(String uriString) { + uri = URI.create(uriString); + } + + public URI getURI() { + return uri; + } + + @Override + public String toString() { + return uri.toString(); + } + + public int getLength() { + return 1; + } + + public String toString(String baseURI, Map<String, String> prefixes) { + return uri.toString(); + } + + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } +} Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-02-24 17:47:44 UTC (rev 635) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-02-24 17:49:30 UTC (rev 636) @@ -379,15 +379,15 @@ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 44: jj_consume_token(44); - range = new Datatype(Datatype.Type.DOUBLE); + range = Datatype.DOUBLE; break; case 45: jj_consume_token(45); - range = new Datatype(Datatype.Type.BOOLEAN); + range = Datatype.BOOLEAN; break; case 46: jj_consume_token(46); - range = new Datatype(Datatype.Type.INT); + range = Datatype.INT; break; default: jj_la1[8] = jj_gen; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-24 19:29:09
|
Revision: 637 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=637&view=rev Author: jenslehmann Date: 2008-02-24 11:29:04 -0800 (Sun, 24 Feb 2008) Log Message: ----------- - prepared reasoner datatype support - implemented getRoleMembers in OWL API reasoner - now fully DIG 1.1 compliant - discovered another bug in OWL API export (adds an empty prefix) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.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/examples/Carcinogenesis.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/test/OWLAPIBugDemo.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-24 19:29:04 UTC (rev 637) @@ -550,6 +550,15 @@ } m.put(3,m3); } + + // boolean datatypes, e.g. testPositive = true + if(useBooleanDatatypes) { +// Set<Description> m3 = new TreeSet<Description>(conceptComparator); + // TODO: code for getting boolean datatypes +// m.put(3,m3); + // TODO: do not use put here because we overwrite the + // EXISTS quantor stuff + } } if(maxLength>2) { Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-24 19:29:04 UTC (rev 637) @@ -24,6 +24,7 @@ import java.util.Set; import java.util.SortedSet; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -88,5 +89,11 @@ public Set<ObjectProperty> getAtomicRoles(); + // currently, we do not require that datatype properties can be returned; + // the main reason is that DIG does not distinguish between datatype and + // object properties (of course one could implement it but it is not easy) + public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> getIndividuals(); + } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-24 19:29:04 UTC (rev 637) @@ -25,6 +25,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -120,4 +121,8 @@ throw new ReasoningMethodUnsupportedException(); } + public Set<DatatypeProperty> getDatatypeProperties() 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-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-24 19:29:04 UTC (rev 637) @@ -486,6 +486,7 @@ // Reasoning-Resultate // zur�ckgegeben werden k�nnten private void handleExceptions(ReasoningMethodUnsupportedException e) { + e.printStackTrace(); throw new Error("Reasoning method not supported."); } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-24 19:29:04 UTC (rev 637) @@ -196,8 +196,10 @@ } // disjoint classes axioms - DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); - kb.addAxiom(disjointAtomTypes); + // OWL API is also buggy here, it adds a strange unused prefix + // and cannot parser its own generated file +// DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); +// kb.addAxiom(disjointAtomTypes); // all different axiom (UNA) // exporting differentIndividuals axioms is broken in OWL API @@ -443,6 +445,7 @@ return new DoubleDatatypePropertyAssertion(dp, ind, value); } + @SuppressWarnings({"unused"}) private static DisjointClassesAxiom getDisjointClassesAxiom(Set<String> classes) { Set<Description> descriptions = new HashSet<Description>(); for(String namedClass : classes) Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-24 19:29:04 UTC (rev 637) @@ -35,6 +35,7 @@ import org.dllearner.core.ReasoningService; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; @@ -59,8 +60,8 @@ * model of the knowledge base (TODO: more explanation), which is neither correct nor * complete, but sufficient in many cases. A big advantage of the algorithm is that it * does not need even need to perform any set modifications (union, intersection, difference), - * so it avoids any object creation, which makes it very fast compared to standard - * reasoners (TODO: maybe add some benchmarks once it is implemented). + * so it avoids any Java object creation, which makes it extremely fast compared to standard + * reasoners. * * Note: This algorithm works only on concepts in negation normal form! * @@ -74,10 +75,11 @@ private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; + private Set<DatatypeProperty> datatypeProperties; private SortedSet<Individual> individuals; private ReasoningService rs; - private ReasonerComponent rc; + private OWLAPIReasoner rc; private Set<KnowledgeSource> sources; // we use sorted sets (map indices) here, because they have only log(n) @@ -94,7 +96,6 @@ this.sources = sources; } - /* (non-Javadoc) * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.config.ConfigEntry) */ @@ -109,17 +110,10 @@ @Override public void init() throws ComponentInitException { rc = new OWLAPIReasoner(sources); - // DIG will only be used to get the role pairs; - // outside the constructor, OWL API will be used because - // it is fast than DIG - DIGReasoner rcDIG = new DIGReasoner(sources); - try { - rc.init(); - rcDIG.init(); - } catch (ComponentInitException e1) { - e1.printStackTrace(); - } + rc.init(); + atomicConcepts = rc.getAtomicConcepts(); + datatypeProperties = rc.getDatatypeProperties(); atomicRoles = rc.getAtomicRoles(); individuals = rc.getIndividuals(); rs = new ReasoningService(rc); @@ -135,7 +129,7 @@ } for (ObjectProperty atomicRole : rs.getAtomicRoles()) { - opPos.put(atomicRole, rcDIG.getRoleMembers(atomicRole)); + opPos.put(atomicRole, rc.getRoleMembers(atomicRole)); } long dematDuration = System.currentTimeMillis() - dematStartTime; @@ -233,6 +227,11 @@ return atomicRoles; } + @Override + public Set<DatatypeProperty> getDatatypeProperties() { + return datatypeProperties; + } + /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getIndividuals() */ Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-24 19:29:04 UTC (rev 637) @@ -27,6 +27,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.LinkedList; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; @@ -42,6 +43,7 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.owl.AssertionalAxiom; import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; @@ -76,6 +78,7 @@ import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDataProperty; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLNamedObject; @@ -120,6 +123,8 @@ // primitives Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); + Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); +// Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<Individual> individuals = new TreeSet<Individual>(); public OWLAPIReasoner(Set<KnowledgeSource> sources) { @@ -164,7 +169,8 @@ } }; Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); - Set<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLObjectProperty> owlObjectProperties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLDataProperty> owlDatatypeProperties = new TreeSet<OWLDataProperty>(namedObjectComparator); Set<OWLIndividual> owlIndividuals = new TreeSet<OWLIndividual>(namedObjectComparator); Set<OWLOntology> allImports = new HashSet<OWLOntology>(); @@ -178,7 +184,8 @@ OWLOntology ontology = manager.loadOntologyFromPhysicalURI(url.toURI()); allImports.addAll(manager.getImportsClosure(ontology)); classes.addAll(ontology.getReferencedClasses()); - properties.addAll(ontology.getReferencedObjectProperties()); + owlObjectProperties.addAll(ontology.getReferencedObjectProperties()); + owlDatatypeProperties.addAll(ontology.getReferencedDataProperties()); owlIndividuals.addAll(ontology.getReferencedIndividuals()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); @@ -202,7 +209,8 @@ allImports.add(ontology); atomicConcepts.addAll(kb.findAllAtomicConcepts()); atomicRoles.addAll(kb.findAllAtomicRoles()); - individuals.addAll(kb.findAllIndividuals()); + individuals.addAll(kb.findAllIndividuals()); + // TODO: add method to find datatypes } } @@ -264,11 +272,18 @@ // read in primitives for(OWLClass owlClass : classes) atomicConcepts.add(new NamedClass(owlClass.getURI().toString())); - for(OWLObjectProperty owlProperty : properties) + for(OWLObjectProperty owlProperty : owlObjectProperties) atomicRoles.add(new ObjectProperty(owlProperty.getURI().toString())); + for(OWLDataProperty owlProperty : owlDatatypeProperties) { + // empty ranges are returned for ames test positive +// Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); +// System.out.println(owlProperty); +// System.out.println(ranges); + datatypeProperties.add(new DatatypeProperty(owlProperty.getURI().toString())); + System.exit(0); + } for(OWLIndividual owlIndividual : owlIndividuals) individuals.add(new Individual(owlIndividual.getURI().toString())); - } /* (non-Javadoc) @@ -285,6 +300,11 @@ return atomicRoles; } + @Override + public Set<DatatypeProperty> getDatatypeProperties() { + return datatypeProperties; + } + /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getIndividuals() */ @@ -482,6 +502,31 @@ } } + @Override + public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { + OWLObjectProperty prop = getOWLAPIDescription(atomicRole); + Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); + for(Individual i : individuals) { + OWLIndividual ind = factory.getOWLIndividual(URI.create(i.getName())); + + // get all related individuals via OWL API + 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())); + map.put(i, is); + } + return map; + } + + // OWL API often returns a set of sets of classes, where each inner // set consists of equivalent classes; this method picks one class // from each inner set to flatten the set of sets @@ -561,8 +606,7 @@ } } - @Deprecated - public static OWLObjectProperty getOWLAPIDescription(ObjectProperty role) { + private static OWLObjectProperty getOWLAPIDescription(ObjectProperty role) { return staticFactory.getOWLObjectProperty(URI.create(role.getName())); } Modified: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-24 17:49:30 UTC (rev 636) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-24 19:29:04 UTC (rev 637) @@ -24,15 +24,31 @@ OWLOntology ontology = manager.createOntology(ontologyURI); OWLDataFactory factory = manager.getOWLDataFactory(); + // create a set of two individuals OWLIndividual a = factory.getOWLIndividual(URI.create(ontologyURI + "#a")); OWLIndividual b = factory.getOWLIndividual(URI.create(ontologyURI + "#b")); Set<OWLIndividual> inds = new HashSet<OWLIndividual>(); inds.add(a); inds.add(b); + // create a set of two classes + OWLClass c = factory.getOWLClass(URI.create(ontologyURI + "#c")); + OWLClass d = factory.getOWLClass(URI.create(ontologyURI + "#d")); + Set<OWLClass> classes = new HashSet<OWLClass>(); + classes.add(c); + classes.add(d); + + // state that a and b are different OWLAxiom axiom = factory.getOWLDifferentIndividualsAxiom(inds); AddAxiom addAxiom = new AddAxiom(ontology, axiom); manager.applyChange(addAxiom); + + // state that c and d are disjoint + OWLAxiom axiom2 = factory.getOWLDisjointClassesAxiom(classes); + AddAxiom addAxiom2 = new AddAxiom(ontology, axiom2); + manager.applyChange(addAxiom2); + + // save ontology manager.saveOntology(ontology); } catch (OWLException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-25 17:58:43
|
Revision: 638 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=638&view=rev Author: tonytacker Date: 2008-02-25 09:58:40 -0800 (Mon, 25 Feb 2008) Log Message: ----------- first try to save config, add method toConfString in ConfigEntry Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java Modified: trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -50,4 +50,12 @@ return true; } + /* (non-Javadoc) + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Boolean value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-25 17:58:40 UTC (rev 638) @@ -52,4 +52,12 @@ return value; } + /** + * Get a string to save into a configuration file. + * + * @return a formatted string + */ + public String toConfString(String componentName) { + return componentName.toString() + "." + option.getName() + " = " + option.getValueFormatting(value); + } } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -85,4 +85,6 @@ return "option name: " + name + "\ndescription: " + description + "\nvalues: " + getAllowedValuesDescription() + "\ndefault value: " + defaultValue + "\n"; } + public abstract String getValueFormatting(T value); + } Modified: trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -97,4 +97,14 @@ return str; } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Double value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -19,38 +19,39 @@ */ package org.dllearner.core.config; - /** * A configuration option, which allows values of type integer. A minimum and * maximum value of the argument can optionally be specified. * * @author Jens Lehmann - * + * */ public class IntegerConfigOption extends ConfigOption<Integer> { private int lowerLimit = Integer.MIN_VALUE; private int upperLimit = Integer.MAX_VALUE; - + public IntegerConfigOption(String name, String description) { super(name, description); } - + public IntegerConfigOption(String name, String description, int defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override public boolean isValidValue(Integer value) { - if(value >= lowerLimit && value <= upperLimit) + if (value >= lowerLimit && value <= upperLimit) return true; else - return false; + return false; } - + /** * @return the The lowest possible value for this configuration option. */ @@ -59,7 +60,8 @@ } /** - * @param lowerLimit The lowest possible value for this configuration option. + * @param lowerLimit + * The lowest possible value for this configuration option. */ public void setLowerLimit(int lowerLimit) { this.lowerLimit = lowerLimit; @@ -73,13 +75,16 @@ } /** - * @param upperLimit The highest possible value for this configuration option. + * @param upperLimit + * The highest possible value for this configuration option. */ public void setUpperLimit(int upperLimit) { this.upperLimit = upperLimit; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override @@ -90,11 +95,20 @@ @Override public String getAllowedValuesDescription() { String str = getClass().toString(); - if(lowerLimit != Integer.MIN_VALUE) + if (lowerLimit != Integer.MIN_VALUE) str += " min " + lowerLimit; - if(upperLimit != Integer.MAX_VALUE) + if (upperLimit != Integer.MAX_VALUE) str += " max " + upperLimit; return str; - } - + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Integer value) { + return value.toString(); + } } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -23,37 +23,38 @@ import java.util.Set; import java.util.TreeSet; - /** * A configuration option, which allows values of type String. Optionally a set * of allowed strings can be set. By default all strings are allowed. * * @author Jens Lehmann - * + * */ public class StringConfigOption extends ConfigOption<String> { private Set<String> allowedValues = new TreeSet<String>();; - + public StringConfigOption(String name, String description) { super(name, description); } - + public StringConfigOption(String name, String description, String defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override public boolean isValidValue(String value) { - if(allowedValues.size() == 0 || allowedValues.contains(value)) + if (allowedValues.size() == 0 || allowedValues.contains(value)) return true; else return false; - } - + } + /** * @return the allowedValues */ @@ -62,7 +63,8 @@ } /** - * @param allowedValues the allowedValues to set + * @param allowedValues + * the allowedValues to set */ public void setAllowedValues(Set<String> allowedValues) { this.allowedValues = allowedValues; @@ -71,8 +73,10 @@ public void setAllowedValues(String[] allowedValues) { this.allowedValues = new TreeSet<String>(Arrays.asList(allowedValues)); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override @@ -80,4 +84,14 @@ return (object instanceof String); } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(String value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -21,20 +21,21 @@ import java.util.Set; - /** * A set of strings. * * @author Jens Lehmann - * + * */ public class StringSetConfigOption extends ConfigOption<Set<String>> { public StringSetConfigOption(String name, String description) { super(name, description); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override @@ -42,21 +43,33 @@ return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override public boolean checkType(Object object) { - if(!(object instanceof Set)) + if (!(object instanceof Set)) return false; - + Set<?> set = (Set<?>) object; - for(Object element : set) { - if(!(element instanceof String)) + for (Object element : set) { + if (!(element instanceof String)) return false; } - + return true; } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(Set<String> value) { + return value.toString(); + } + } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-25 17:58:40 UTC (rev 638) @@ -24,8 +24,8 @@ import org.dllearner.utilities.StringTuple; /** - * A list if string tuples, for instance for specifying several - * parameters or replacement rules. + * A list if string tuples, for instance for specifying several parameters or + * replacement rules. * * @author Jens Lehmann */ @@ -34,29 +34,34 @@ public StringTupleListConfigOption(String name, String description) { this(name, description, null); } - - public StringTupleListConfigOption(String name, String description, List<StringTuple> defaultValue) { + + public StringTupleListConfigOption(String name, String description, + List<StringTuple> defaultValue) { super(name, description, defaultValue); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.config.ConfigOption#checkType(java.lang.Object) */ @Override public boolean checkType(Object object) { - if(!(object instanceof List)) + if (!(object instanceof List)) return false; - + List<?> set = (List<?>) object; - for(Object element : set) { - if(!(element instanceof StringTuple)) + for (Object element : set) { + if (!(element instanceof StringTuple)) return false; } - + return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.config.ConfigOption#isValidValue(java.lang.Object) */ @Override @@ -64,4 +69,14 @@ return true; } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) + */ + @Override + public String getValueFormatting(List<StringTuple> value) { + return value.toString(); + } + } Added: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-25 17:58:40 UTC (rev 638) @@ -0,0 +1,125 @@ +package org.dllearner.gui; + +/** + * 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/>. + * + */ + +//import java.io.File; +//import java.net.URL; +import java.util.List; //import java.util.Map; +//import java.util.SortedSet; +//import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; //import org.dllearner.core.KnowledgeSource; +//import org.dllearner.core.LearningProblemUnsupportedException; +//import org.dllearner.learningproblems.PosOnlyDefinitionLP; +//import org.dllearner.parser.ConfParser; +import org.dllearner.core.Component; +import org.dllearner.core.config.ConfigOption; + +//import org.dllearner.cli.ConfFileOption; +//import org.dllearner.cli.Start; +//import org.dllearner.core.config.*; + +/** + * Open a config file. + * + * @author Tilo Hielscher + */ +public class ConfigSave { + + // private File file; + private Config config; + + // private StartGUI startGUI; + + /** + * set config and startGUI + * + * @param config + * @param startGUI + */ + public ConfigSave(Config config, StartGUI startGUI) { + this.config = config; + // this.startGUI = startGUI; + } + + /** + * parse to file + */ + public void startParser() { + // KNOWLEDGE SOURCE + if (config.getKnowledgeSource() != null) { + // System.out.println("knowledge_source: " + + // config.getKnowledgeSource().getClass()); + // KBFile or OWLFile + if (config.getKnowledgeSource().getClass().toString().endsWith("KBFile") + || config.getKnowledgeSource().getClass().toString().endsWith("OWLFile")) { + // url + String url = (String) config.getComponentManager().getConfigOptionValue( + config.getKnowledgeSource(), "url"); + if (url != null) { + System.out.println("import(\"" + url + "\");"); + } + // filename + String filename = (String) config.getComponentManager().getConfigOptionValue( + config.getKnowledgeSource(), "filename"); + if (filename != null) { + System.out.println("import(\"" + filename + "\");"); + } + } + // sparql + if (config.getKnowledgeSource().getClass().toString().endsWith("SparqlKnowledgeSource")) { + String url = (String) config.getComponentManager().getConfigOptionValue( + config.getKnowledgeSource(), "url"); + if (url != null) { + System.out.println("import(\"" + url + "\",\"SPARQL\");"); + // widgets + String prefix = "sparql"; + Component component = config.getKnowledgeSource(); + + Class<? extends Component> componentOption = component.getClass(); // config.getKnowledgeSource().getClass(); + List<ConfigOption<?>> optionList; + optionList = ComponentManager.getConfigOptions(componentOption); + // System.out.println(optionList); + // System.out.println(config.getComponentManager().getConfigOptionValue(component, + // optionName)); + for (int i = 0; i < optionList.size(); i++) { + // if + // (optionList.get(i).getClass().toString().contains("IntegerConfigOption")) + // { + // widgetPanel = new WidgetPanelInteger(config, + // component, oldComponent, componentOption, + // optionList.get(i)); + // System.out.println(optionList.get(i)); + System.out.println(prefix + + "." + + optionList.get(i).getName() + + " = " + + config.getComponentManager().getConfigOptionValue(component, + optionList.get(i).getName())); + System.out.println(config.getComponentManager().getKnowledgeSources() + .get(0)); + // } + } + } + } + } + } + +} Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-24 19:29:04 UTC (rev 637) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-25 17:58:40 UTC (rev 638) @@ -48,6 +48,7 @@ private Config config = new Config(); private ConfigLoad configLoad = new ConfigLoad(config, this);; + private ConfigSave configSave = new ConfigSave(config, this);; private KnowledgeSourcePanel tab0; private ReasonerPanel tab1; @@ -142,6 +143,7 @@ // save config file if (e.getSource() == saveItem) { System.out.println("saveItem was pressed"); + configSave.startParser(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-26 10:47:11
|
Revision: 640 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=640&view=rev Author: jenslehmann Date: 2008-02-26 02:47:09 -0800 (Tue, 26 Feb 2008) Log Message: ----------- added ability to query which datatype properties have one of a specified set of datatypes (double, boolean, int) as ranges in an OWL 1.1 ontology 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/owl/Datatype.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.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-02-26 07:13:31 UTC (rev 639) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-26 10:47:09 UTC (rev 640) @@ -94,6 +94,12 @@ // object properties (of course one could implement it but it is not easy) public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException; + public Set<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException; + + public Set<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException; + + public Set<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> getIndividuals(); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-26 07:13:31 UTC (rev 639) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-26 10:47:09 UTC (rev 640) @@ -124,5 +124,17 @@ public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } + + public Set<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + public Set<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2008-02-26 07:13:31 UTC (rev 639) +++ trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2008-02-26 10:47:09 UTC (rev 640) @@ -30,7 +30,7 @@ DOUBLE ("http://www.w3.org/2001/XMLSchema#double"), INT ("http://www.w3.org/2001/XMLSchema#int"), - BOOLEAN ("http://www.w3.org/2001/XMLSchema#Boolean"); + BOOLEAN ("http://www.w3.org/2001/XMLSchema#boolean"); private URI uri; Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-26 07:13:31 UTC (rev 639) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-26 10:47:09 UTC (rev 640) @@ -166,6 +166,8 @@ // define properties including domain and range String kbString = "DPDOMAIN(" + getURI2("charge") + ") = " + getURI2("Atom") + ".\n"; kbString += "DPRANGE(" + getURI2("charge") + ") = DOUBLE.\n"; + kbString += "DPDOMAIN(" + getURI2("amesTestPositive") + ") = " + getURI2("Compound") + ".\n"; + kbString += "DPRANGE(" + getURI2("amesTestPositive") + ") = BOOLEAN.\n"; kbString += "OPDOMAIN(" + getURI2("hasAtom") + ") = " + getURI2("Compound") + ".\n"; kbString += "OPRANGE(" + getURI2("hasAtom") + ") = " + getURI2("Atom") + ".\n"; kbString += "OPDOMAIN(" + getURI2("hasBond") + ") = " + getURI2("Compound") + ".\n"; Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 07:13:31 UTC (rev 639) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 10:47:09 UTC (rev 640) @@ -25,6 +25,7 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.core.ComponentInitException; @@ -76,6 +77,9 @@ private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; private Set<DatatypeProperty> datatypeProperties; + private Set<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + private Set<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + private Set<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); private SortedSet<Individual> individuals; private ReasoningService rs; @@ -112,10 +116,18 @@ rc = new OWLAPIReasoner(sources); rc.init(); - atomicConcepts = rc.getAtomicConcepts(); - datatypeProperties = rc.getDatatypeProperties(); - atomicRoles = rc.getAtomicRoles(); - individuals = rc.getIndividuals(); + try { + atomicConcepts = rc.getAtomicConcepts(); + datatypeProperties = rc.getDatatypeProperties(); + booleanDatatypeProperties = rc.getBooleanDatatypeProperties(); + doubleDatatypeProperties = rc.getDoubleDatatypeProperties(); + intDatatypeProperties = rc.getIntDatatypeProperties(); + atomicRoles = rc.getAtomicRoles(); + individuals = rc.getIndividuals(); + } catch (ReasoningMethodUnsupportedException e) { + throw new ComponentInitException("Underlying reasoner does not support all necessary reasoning methods.", e); + } + rs = new ReasoningService(rc); // TODO: some code taken from Helper.createFlatABox, but pasted here because additional things need to @@ -232,6 +244,21 @@ return datatypeProperties; } + @Override + public Set<DatatypeProperty> getBooleanDatatypeProperties() { + return booleanDatatypeProperties; + } + + @Override + public Set<DatatypeProperty> getDoubleDatatypeProperties() { + return doubleDatatypeProperties; + } + + @Override + public Set<DatatypeProperty> getIntDatatypeProperties() { + return intDatatypeProperties; + } + /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getIndividuals() */ Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 07:13:31 UTC (rev 639) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 10:47:09 UTC (rev 640) @@ -43,6 +43,7 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.owl.AssertionalAxiom; import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; @@ -79,6 +80,8 @@ import org.semanticweb.owl.model.OWLClass; 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.OWLNamedObject; @@ -124,7 +127,9 @@ Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); -// Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); + Set<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + Set<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + Set<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<Individual> individuals = new TreeSet<Individual>(); public OWLAPIReasoner(Set<KnowledgeSource> sources) { @@ -275,12 +280,19 @@ for(OWLObjectProperty owlProperty : owlObjectProperties) atomicRoles.add(new ObjectProperty(owlProperty.getURI().toString())); for(OWLDataProperty owlProperty : owlDatatypeProperties) { - // empty ranges are returned for ames test positive -// Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); -// System.out.println(owlProperty); -// System.out.println(ranges); - datatypeProperties.add(new DatatypeProperty(owlProperty.getURI().toString())); - System.exit(0); + DatatypeProperty dtp = new DatatypeProperty(owlProperty.getURI().toString()); + Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); + OWLDataRange range = ranges.iterator().next(); + if(range.isDataType()) { + URI uri = ((OWLDataType)range).getURI(); + if(uri.equals(Datatype.BOOLEAN.getURI())) + booleanDatatypeProperties.add(dtp); + else if(uri.equals(Datatype.DOUBLE.getURI())) + doubleDatatypeProperties.add(dtp); + else if(uri.equals(Datatype.INT.getURI())) + intDatatypeProperties.add(dtp); + } + datatypeProperties.add(dtp); } for(OWLIndividual owlIndividual : owlIndividuals) individuals.add(new Individual(owlIndividual.getURI().toString())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-26 13:25:40
|
Revision: 641 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=641&view=rev Author: jenslehmann Date: 2008-02-26 05:25:32 -0800 (Tue, 26 Feb 2008) Log Message: ----------- implemented datatype ABox reasoning/querying using OWL API 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/owl/DatatypeProperty.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-02-26 10:47:09 UTC (rev 640) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-26 13:25:32 UTC (rev 641) @@ -24,6 +24,7 @@ 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.NamedClass; import org.dllearner.core.owl.Description; @@ -71,6 +72,8 @@ public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException; + public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + public boolean instanceCheck(Description concept, Individual individual) throws ReasoningMethodUnsupportedException; // mehrere instance checks für ein Konzept - spart bei DIG Anfragen Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-26 10:47:09 UTC (rev 640) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-26 13:25:32 UTC (rev 641) @@ -23,8 +23,11 @@ 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.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; @@ -75,6 +78,75 @@ 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; + } + public boolean instanceCheck(Description concept, Individual individual) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-02-26 10:47:09 UTC (rev 640) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-02-26 13:25:32 UTC (rev 641) @@ -27,7 +27,7 @@ * @author Jens Lehmann * */ -public class DatatypeProperty implements Property, NamedKBElement { +public class DatatypeProperty implements Comparable<DatatypeProperty>, Property, NamedKBElement { protected String name; @@ -46,14 +46,23 @@ return name; } - /* (non-Javadoc) - * @see org.dllearner.core.dl.KBElement#toString(java.lang.String, java.util.Map) - */ + @Override + public String toString() { + return toString(null, null); + } + public String toString(String baseURI, Map<String, String> prefixes) { return "\"" + Helper.getAbbreviatedString(name, baseURI, prefixes) + "\""; } public void accept(KBElementVisitor visitor) { visitor.visit(this); + } + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(DatatypeProperty o) { + return name.compareTo(o.name); } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 10:47:09 UTC (rev 640) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 13:25:32 UTC (rev 641) @@ -36,6 +36,7 @@ import org.dllearner.core.ReasoningService; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -56,24 +57,24 @@ import org.dllearner.parser.ParseException; /** - * Reasoner for fast instance checks. It works by completely dematerialising the knowledge - * base to speed up later reasoning requests. It then continues by only considering one - * model of the knowledge base (TODO: more explanation), which is neither correct nor - * complete, but sufficient in many cases. A big advantage of the algorithm is that it - * does not need even need to perform any set modifications (union, intersection, difference), - * so it avoids any Java object creation, which makes it extremely fast compared to standard + * Reasoner for fast instance checks. It works by completely dematerialising the + * knowledge base to speed up later reasoning requests. It then continues by + * only considering one model of the knowledge base (TODO: more explanation), + * which is neither correct nor complete, but sufficient in many cases. A big + * advantage of the algorithm is that it does not need even need to perform any + * set modifications (union, intersection, difference), so it avoids any Java + * object creation, which makes it extremely fast compared to standard * reasoners. * * Note: This algorithm works only on concepts in negation normal form! * * @author Jens Lehmann - * + * */ public class FastInstanceChecker extends ReasonerComponent { - private static Logger logger = Logger - .getLogger(FastInstanceChecker.class); - + private static Logger logger = Logger.getLogger(FastInstanceChecker.class); + private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; private Set<DatatypeProperty> datatypeProperties; @@ -81,26 +82,36 @@ private Set<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); private Set<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); private SortedSet<Individual> individuals; - + private ReasoningService rs; private OWLAPIReasoner rc; private Set<KnowledgeSource> sources; - + // we use sorted sets (map indices) here, because they have only log(n) // complexity for checking whether an element is contained in them // instances of classes - private Map<NamedClass,SortedSet<Individual>> classInstancesPos = new TreeMap<NamedClass,SortedSet<Individual>>(); - private Map<NamedClass,SortedSet<Individual>> classInstancesNeg = new TreeMap<NamedClass,SortedSet<Individual>>(); - // object property mappings - private Map<ObjectProperty,Map<Individual,SortedSet<Individual>>> opPos = new TreeMap<ObjectProperty,Map<Individual,SortedSet<Individual>>>(); + private Map<NamedClass, SortedSet<Individual>> classInstancesPos = new TreeMap<NamedClass, SortedSet<Individual>>(); + private Map<NamedClass, SortedSet<Individual>> classInstancesNeg = new TreeMap<NamedClass, SortedSet<Individual>>(); + // object property mappings + private Map<ObjectProperty, Map<Individual, SortedSet<Individual>>> opPos = new TreeMap<ObjectProperty, Map<Individual, SortedSet<Individual>>>(); + // datatype property mappings + // (for booleans we assume that just one mapping exists, e.g. + // hasValue(object,true) and hasValue(object,false) will + // lead to undefined behaviour (they are logical contradictions) + private Map<DatatypeProperty, SortedSet<Individual>> bd = new TreeMap<DatatypeProperty, SortedSet<Individual>>(); + // for int and double we assume that a property can have several values, + // althoug this should be rare, + // e.g. hasValue(object,2) and hasValue(object,3) + private Map<DatatypeProperty, Map<Individual, SortedSet<Double>>> dd = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<Double>>>(); + private Map<DatatypeProperty, Map<Individual, SortedSet<Integer>>> id = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<Integer>>>(); - // TODO: datatype properties - public FastInstanceChecker(Set<KnowledgeSource> sources) { this.sources = sources; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.config.ConfigEntry) */ @Override @@ -108,7 +119,9 @@ } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.Component#init() */ @Override @@ -118,121 +131,152 @@ try { atomicConcepts = rc.getAtomicConcepts(); - datatypeProperties = rc.getDatatypeProperties(); + datatypeProperties = rc.getDatatypeProperties(); booleanDatatypeProperties = rc.getBooleanDatatypeProperties(); doubleDatatypeProperties = rc.getDoubleDatatypeProperties(); intDatatypeProperties = rc.getIntDatatypeProperties(); atomicRoles = rc.getAtomicRoles(); - individuals = rc.getIndividuals(); - } catch (ReasoningMethodUnsupportedException e) { - throw new ComponentInitException("Underlying reasoner does not support all necessary reasoning methods.", e); - } + individuals = rc.getIndividuals(); - rs = new ReasoningService(rc); - - // TODO: some code taken from Helper.createFlatABox, but pasted here because additional things need to - // be done (maybe this can be merge again with the FastRetrievalReasoner later) - long dematStartTime = System.currentTimeMillis(); + rs = new ReasoningService(rc); - for (NamedClass atomicConcept : rs.getAtomicConcepts()) { - classInstancesPos.put(atomicConcept, rs.retrieval(atomicConcept)); - Negation negatedAtomicConcept = new Negation(atomicConcept); - classInstancesNeg.put(atomicConcept, rs.retrieval(negatedAtomicConcept)); - } + // TODO: some code taken from Helper.createFlatABox, but pasted here + // because additional things need to + // be done (maybe this can be merge again with the + // FastRetrievalReasoner later) + long dematStartTime = System.currentTimeMillis(); - for (ObjectProperty atomicRole : rs.getAtomicRoles()) { - opPos.put(atomicRole, rc.getRoleMembers(atomicRole)); + for (NamedClass atomicConcept : rs.getAtomicConcepts()) { + classInstancesPos.put(atomicConcept, rs.retrieval(atomicConcept)); + Negation negatedAtomicConcept = new Negation(atomicConcept); + classInstancesNeg.put(atomicConcept, rs.retrieval(negatedAtomicConcept)); + } + + for (ObjectProperty atomicRole : atomicRoles) { + opPos.put(atomicRole, rc.getRoleMembers(atomicRole)); + } + + for (DatatypeProperty dp : booleanDatatypeProperties) { + bd.put(dp, rc.getTrueDatatypeMembers(dp)); + } + + for (DatatypeProperty dp : intDatatypeProperties) { + id.put(dp, rc.getIntDatatypeMembers(dp)); + } + + for (DatatypeProperty dp : doubleDatatypeProperties) { + dd.put(dp, rc.getDoubleDatatypeMembers(dp)); + } + + long dematDuration = System.currentTimeMillis() - dematStartTime; + logger.info("TBox dematerialised in " + dematDuration + " ms"); + + } catch (ReasoningMethodUnsupportedException e) { + throw new ComponentInitException( + "Underlying reasoner does not support all necessary reasoning methods.", e); } - - long dematDuration = System.currentTimeMillis() - dematStartTime; - logger.info("TBox dematerialised in " + dematDuration + " ms"); - } @Override - public boolean instanceCheck(Description description, Individual individual) throws ReasoningMethodUnsupportedException { - if(description instanceof NamedClass) { - return classInstancesPos.get((NamedClass)description).contains(individual); - } else if(description instanceof Negation) { + public boolean instanceCheck(Description description, Individual individual) + throws ReasoningMethodUnsupportedException { + if (description instanceof NamedClass) { + return classInstancesPos.get((NamedClass) description).contains(individual); + } else if (description instanceof Negation) { Description child = description.getChild(0); - if(child instanceof NamedClass) { - return classInstancesNeg.get((NamedClass)child).contains(individual); + if (child instanceof NamedClass) { + return classInstancesNeg.get((NamedClass) child).contains(individual); } else { - throw new ReasoningMethodUnsupportedException("Instance check for description " + description + " unsupported. Description needs to be in negation normal form."); + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + + " unsupported. Description needs to be in negation normal form."); } - } else if(description instanceof Thing) { + } else if (description instanceof Thing) { return true; - } else if(description instanceof Nothing) { + } else if (description instanceof Nothing) { return false; - } else if(description instanceof Union) { - // if the individual is instance of any of the subdescription of + } else if (description instanceof Union) { + // if the individual is instance of any of the subdescription of // the union, we return true List<Description> children = description.getChildren(); - for(Description child : children) { - if(instanceCheck(child, individual)) + for (Description child : children) { + if (instanceCheck(child, individual)) return true; } return false; - } else if(description instanceof Intersection) { - // if the individual is instance of all of the subdescription of - // the union, we return true + } else if (description instanceof Intersection) { + // if the individual is instance of all of the subdescription of + // the union, we return true List<Description> children = description.getChildren(); - for(Description child : children) { - if(!instanceCheck(child, individual)) + for (Description child : children) { + if (!instanceCheck(child, individual)) return false; } return true; - } else if(description instanceof ObjectSomeRestriction) { - ObjectPropertyExpression ope = ((ObjectSomeRestriction)description).getRole(); - if(!(ope instanceof ObjectProperty)) - throw new ReasoningMethodUnsupportedException("Instance check for description " + description + " unsupported. Inverse object properties not supported."); + } else if (description instanceof ObjectSomeRestriction) { + ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); ObjectProperty op = (ObjectProperty) ope; Description child = description.getChild(0); - Map<Individual,SortedSet<Individual>> mapping = opPos.get(op);; - if(mapping == null) { - logger.warn("Instance check of a description with an undefinied property (" + op + ")."); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + ; + if (mapping == null) { + logger.warn("Instance check of a description with an undefinied property (" + op + + ")."); return false; } SortedSet<Individual> roleFillers = opPos.get(op).get(individual); - if(roleFillers == null) + if (roleFillers == null) return false; - for(Individual roleFiller : roleFillers) { - if(instanceCheck(child, roleFiller)) + for (Individual roleFiller : roleFillers) { + if (instanceCheck(child, roleFiller)) return true; } return false; - } else if(description instanceof ObjectAllRestriction) { - ObjectPropertyExpression ope = ((ObjectAllRestriction)description).getRole(); - if(!(ope instanceof ObjectProperty)) - throw new ReasoningMethodUnsupportedException("Instance check for description " + description + " unsupported. Inverse object properties not supported."); + } else if (description instanceof ObjectAllRestriction) { + ObjectPropertyExpression ope = ((ObjectAllRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); ObjectProperty op = (ObjectProperty) ope; Description child = description.getChild(0); - Map<Individual,SortedSet<Individual>> mapping = opPos.get(op);; - if(mapping == null) { - logger.warn("Instance check of a description with an undefinied property (" + op + ")."); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + ; + if (mapping == null) { + logger.warn("Instance check of a description with an undefinied property (" + op + + ")."); return true; } SortedSet<Individual> roleFillers = opPos.get(op).get(individual); - if(roleFillers == null) + if (roleFillers == null) return true; - for(Individual roleFiller : roleFillers) { - if(!instanceCheck(child, roleFiller)) + for (Individual roleFiller : roleFillers) { + if (!instanceCheck(child, roleFiller)) return false; } return true; + } else if (description instanceof BooleanValueRestriction) { + } - - throw new ReasoningMethodUnsupportedException("Instance check for description " + description + " unsupported."); - } - - /* (non-Javadoc) + + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported."); + } + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Reasoner#getAtomicConcepts() */ public Set<NamedClass> getAtomicConcepts() { return atomicConcepts; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.Reasoner#getAtomicRoles() */ public Set<ObjectProperty> getAtomicRoles() { @@ -242,38 +286,44 @@ @Override public Set<DatatypeProperty> getDatatypeProperties() { return datatypeProperties; - } - + } + @Override public Set<DatatypeProperty> getBooleanDatatypeProperties() { return booleanDatatypeProperties; - } - + } + @Override public Set<DatatypeProperty> getDoubleDatatypeProperties() { return doubleDatatypeProperties; - } - + } + @Override public Set<DatatypeProperty> getIntDatatypeProperties() { return intDatatypeProperties; - } - - /* (non-Javadoc) + } + + /* + * (non-Javadoc) + * * @see org.dllearner.core.Reasoner#getIndividuals() */ public SortedSet<Individual> getIndividuals() { return individuals; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.Reasoner#getReasonerType() */ public ReasonerType getReasonerType() { return ReasonerType.FAST_INSTANCE_CHECKER; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.Reasoner#prepareSubsumptionHierarchy(java.util.Set) */ public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { @@ -283,34 +333,37 @@ @Override public SubsumptionHierarchy getSubsumptionHierarchy() { return rs.getSubsumptionHierarchy(); - } - + } + @Override public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { rs.prepareRoleHierarchy(allowedRoles); - } - + } + @Override public ObjectPropertyHierarchy getRoleHierarchy() { return rs.getRoleHierarchy(); } - + @Override public boolean subsumes(Description superConcept, Description subConcept) { -// Negation neg = new Negation(subConcept); -// Intersection c = new Intersection(neg,superConcept); -// return fastRetrieval.calculateSets(c).getPosSet().isEmpty(); + // Negation neg = new Negation(subConcept); + // Intersection c = new Intersection(neg,superConcept); + // return fastRetrieval.calculateSets(c).getPosSet().isEmpty(); return rs.subsumes(superConcept, subConcept); - } - + } + /** * Test method for fast instance checker. - * @param args No arguments supported. - * @throws ComponentInitException - * @throws ParseException - * @throws ReasoningMethodUnsupportedException + * + * @param args + * No arguments supported. + * @throws ComponentInitException + * @throws ParseException + * @throws ReasoningMethodUnsupportedException */ - public static void main(String[] args) throws ComponentInitException, ParseException, ReasoningMethodUnsupportedException { + public static void main(String[] args) throws ComponentInitException, ParseException, + ReasoningMethodUnsupportedException { ComponentManager cm = ComponentManager.getInstance(); OWLFile owl = cm.knowledgeSource(OWLFile.class); String owlFile = new File("examples/family/father.owl").toURI().toString(); @@ -319,7 +372,7 @@ ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, owl); cm.reasoningService(reasoner); reasoner.init(); - + KBParser.internalNamespace = "http://example.com/father#"; String query = "(male AND EXISTS hasChild.TOP)"; Description d = KBParser.parseConcept(query); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 10:47:09 UTC (rev 640) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 13:25:32 UTC (rev 641) @@ -43,6 +43,7 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.owl.AssertionalAxiom; import org.dllearner.core.owl.ClassAssertionAxiom; +import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; @@ -68,7 +69,9 @@ import org.dllearner.core.owl.TerminologicalAxiom; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.TransitiveObjectPropertyAxiom; +import org.dllearner.core.owl.TypedConstant; import org.dllearner.core.owl.Union; +import org.dllearner.core.owl.UntypedConstant; import org.dllearner.kb.OWLFile; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.RoleComparator; @@ -78,6 +81,7 @@ import org.semanticweb.owl.model.AddAxiom; 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.OWLDataRange; @@ -91,6 +95,8 @@ import org.semanticweb.owl.model.OWLOntologyCreationException; import org.semanticweb.owl.model.OWLOntologyManager; import org.semanticweb.owl.model.OWLOntologyStorageException; +import org.semanticweb.owl.model.OWLTypedConstant; +import org.semanticweb.owl.model.OWLUntypedConstant; import org.semanticweb.owl.model.UnknownOWLOntologyException; import org.semanticweb.owl.util.SimpleURIMapper; @@ -537,8 +543,47 @@ } return map; } - + @Override + public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) { + OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + Map<Individual, SortedSet<Constant>> map = new TreeMap<Individual, SortedSet<Constant>>(); + for(Individual i : individuals) { + OWLIndividual ind = factory.getOWLIndividual(URI.create(i.getName())); + + // get all related values via OWL API + 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())); + } + } + // only add individuals using the datatype property + if(is.size()>0) + map.put(i, is); + } + return map; + } + // OWL API often returns a set of sets of classes, where each inner // set consists of equivalent classes; this method picks one class // from each inner set to flatten the set of sets @@ -618,10 +663,26 @@ } } + 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())); + } + @Deprecated public static OWLDescription getOWLAPIDescription(Description concept) { if (concept instanceof NamedClass) { @@ -773,4 +834,28 @@ } } + /** + * @return the booleanDatatypeProperties + */ + @Override + public Set<DatatypeProperty> getBooleanDatatypeProperties() { + return booleanDatatypeProperties; + } + + /** + * @return the doubleDatatypeProperties + */ + @Override + public Set<DatatypeProperty> getDoubleDatatypeProperties() { + return doubleDatatypeProperties; + } + + /** + * @return the intDatatypeProperties + */ + @Override + public Set<DatatypeProperty> getIntDatatypeProperties() { + return intDatatypeProperties; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-26 18:13:32
|
Revision: 642 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=642&view=rev Author: jenslehmann Date: 2008-02-26 10:13:23 -0800 (Tue, 26 Feb 2008) Log Message: ----------- - datatype TBox reasoning using OWL API - description comparator updated to include boolean datatypes - refinement operator rho extended to include boolean datatypes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-26 18:13:23 UTC (rev 642) @@ -30,6 +30,8 @@ import java.util.TreeSet; import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; @@ -538,8 +540,8 @@ if(topRefinementsLength<3 && maxLength>2) { // Konzepte der Länge 3: EXISTS r.TOP + Set<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { - Set<Description> m3 = new TreeSet<Description>(conceptComparator); // previous operator: uses all roles // for(AtomicRole r : Config.Refinement.allowedRoles) { // m3.add(new Exists(r, new Top())); @@ -548,17 +550,19 @@ for(ObjectProperty r : rs.getMostGeneralRoles()) { m3.add(new ObjectSomeRestriction(r, new Thing())); } - m.put(3,m3); + } // boolean datatypes, e.g. testPositive = true if(useBooleanDatatypes) { -// Set<Description> m3 = new TreeSet<Description>(conceptComparator); - // TODO: code for getting boolean datatypes -// m.put(3,m3); - // TODO: do not use put here because we overwrite the - // EXISTS quantor stuff + Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + for(DatatypeProperty dp : booleanDPs) { + m3.add(new BooleanValueRestriction(dp,true)); + m3.add(new BooleanValueRestriction(dp,false)); + } } + + m.put(3,m3); } if(maxLength>2) { Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-26 18:13:23 UTC (rev 642) @@ -27,6 +27,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -405,6 +406,42 @@ return reasoner.getAtomicRoles(); } + public Set<DatatypeProperty> getDatatypeProperties() { + try { + return reasoner.getDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<DatatypeProperty> getBooleanDatatypeProperties() { + try { + return reasoner.getBooleanDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<DatatypeProperty> getIntDatatypeProperties() { + try { + return reasoner.getIntDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<DatatypeProperty> getDoubleDatatypeProperties() { + try { + return reasoner.getDoubleDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + public SortedSet<Individual> getIndividuals() { return reasoner.getIndividuals(); } Modified: trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java 2008-02-26 18:13:23 UTC (rev 642) @@ -27,6 +27,8 @@ */ public class BooleanValueRestriction extends DatatypeValueRestriction { + private boolean booleanValue; + /** * TODO: Internally a typed constant with datatype boolean and * strings "true" or "false" is created. This is a clean way to @@ -42,6 +44,11 @@ */ public BooleanValueRestriction(DatatypeProperty restrictedPropertyExpression, Boolean value) { super(restrictedPropertyExpression, new TypedConstant(value.toString(), Datatype.BOOLEAN)); + booleanValue = value; } + public boolean getBooleanValue() { + return booleanValue; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-26 18:13:23 UTC (rev 642) @@ -49,8 +49,7 @@ */ @Override public int getArity() { - // TODO Auto-generated method stub - return 0; + return 2; } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java 2008-02-26 18:13:23 UTC (rev 642) @@ -31,6 +31,7 @@ public ValueRestriction(PropertyExpression propertyExpression, KBElement value) { super(propertyExpression); + this.value = value; } public KBElement getValue() { Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 18:13:23 UTC (rev 642) @@ -258,7 +258,16 @@ } return true; } else if (description instanceof BooleanValueRestriction) { - + DatatypeProperty dp = ((BooleanValueRestriction)description).getRestrictedPropertyExpresssion(); + boolean value = ((BooleanValueRestriction)description).getBooleanValue(); + + if(value) { + // check whether the individual is in the set of individuals mapped + // to true by this datatype property + return bd.get(dp).contains(individual); + } else { + return !bd.get(dp).contains(individual); + } } throw new ReasoningMethodUnsupportedException("Instance check for description " Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-02-26 18:13:23 UTC (rev 642) @@ -25,9 +25,12 @@ 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; @@ -43,11 +46,16 @@ import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; 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.OWLDataType; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLObjectProperty; @@ -171,7 +179,7 @@ */ public void visit(ObjectMinCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -179,7 +187,7 @@ */ public void visit(ObjectExactCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -187,7 +195,7 @@ */ public void visit(ObjectMaxCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -195,15 +203,34 @@ */ public void visit(ObjectValueRestriction 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.DatatypeValueRestriction) */ public void visit(DatatypeValueRestriction description) { - // TODO Auto-generated method stub - + // convert OWL constant to OWL API constant + Constant c = description.getValue(); + OWLConstant constant; + 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) @@ -218,7 +245,7 @@ */ public void visit(ADC description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -226,7 +253,7 @@ */ public void visit(DatatypeMinCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -234,7 +261,7 @@ */ public void visit(DatatypeExactCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -242,7 +269,7 @@ */ public void visit(DatatypeMaxCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -250,7 +277,18 @@ */ public void visit(DatatypeSomeRestriction description) { // TODO Auto-generated method stub + throw new Error("OWLAPIDescriptionConverter: not implemented"); + } + + 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"); } - + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 18:13:23 UTC (rev 642) @@ -419,7 +419,7 @@ @Override public boolean subsumes(Description superConcept, Description subConcept) { try { - return reasoner.isSubClassOf(getOWLAPIDescription(subConcept), getOWLAPIDescription(superConcept)); + return reasoner.isSubClassOf(OWLAPIDescriptionConvertVisitor.getOWLDescription(subConcept), OWLAPIDescriptionConvertVisitor.getOWLDescription(superConcept)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("Subsumption Error in OWL API."); Modified: trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-02-26 18:13:23 UTC (rev 642) @@ -3,6 +3,7 @@ import java.util.Comparator; import java.util.Set; +import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; @@ -51,6 +52,9 @@ // Ordnung für atomare Konzepte: Stringvergleich // Ordnung für atomare Rollen: Stringvergleich public int compare(Description concept1, Description concept2) { + // classes higher up are in the source code have lower value + // (they appear first in class descriptions, because sorted sets + // usually use an ascending order) if(concept1 instanceof Nothing) { if(concept2 instanceof Nothing) return 0; @@ -100,6 +104,17 @@ return roleCompare; } else return -1; + } else if(concept1 instanceof BooleanValueRestriction) { + if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction) { + return 1; + } else if(concept2 instanceof BooleanValueRestriction) { + int cmp = rc.compare(((BooleanValueRestriction)concept1).getRestrictedPropertyExpresssion(), ((BooleanValueRestriction)concept2).getRestrictedPropertyExpresssion()); + if(cmp == 0) + return compare(concept1.getChild(0), concept2.getChild(0)); + else + return cmp; + } else + return -1; } else if(concept1 instanceof Intersection) { if(concept2.getChildren().size()<2) return 1; Modified: trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java 2008-02-26 18:13:23 UTC (rev 642) @@ -21,33 +21,47 @@ import java.util.Comparator; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectPropertyInverse; +import org.dllearner.core.owl.PropertyExpression; /** - * Compares two object properties. + * Compares two property expressions. The order is: + * datatype properties first, then inverse object properties, then + * object properties. For equal types, the URI or toString (inverses) + * is used to fix an order. * * @author Jens Lehmann * */ -public class RoleComparator implements Comparator<ObjectPropertyExpression> { +public class RoleComparator implements Comparator<PropertyExpression> { - public int compare(ObjectPropertyExpression r1, ObjectPropertyExpression r2) { + public int compare(PropertyExpression r1, PropertyExpression r2) { if(r1 instanceof ObjectProperty) { if(r2 instanceof ObjectProperty) { - return r1.getName().compareTo(r2.getName()); - // zweite Rolle ist invers + return ((ObjectProperty)r1).getName().compareTo(((ObjectProperty)r2).getName()); + // second role is inverse or datatype property } else { return -1; } - // 1. Rolle ist invers - } else { - if(r1 instanceof ObjectProperty) { + // first property is an inverse object property + } else if(r1 instanceof ObjectPropertyInverse){ + if(r2 instanceof ObjectProperty) { return 1; + } else if(r2 instanceof ObjectPropertyInverse){ + return r1.toString().compareTo(r2.toString()); } else { - return r1.getName().compareTo(r2.getName()); + return -1; } + // r1 is datatype property + } else { + if(r2 instanceof DatatypeProperty) { + return ((DatatypeProperty)r1).getName().compareTo(((DatatypeProperty)r2).getName()); + } else { + return 1; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 09:31:45
|
Revision: 644 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=644&view=rev Author: jenslehmann Date: 2008-02-27 01:31:41 -0800 (Wed, 27 Feb 2008) Log Message: ----------- - several fixes for datatype learning - datatype learning turned off by default, because DIG 1.1 does not support the necessary reasoning methods Modified Paths: -------------- 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/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 09:31:41 UTC (rev 644) @@ -164,8 +164,8 @@ options.add(CommonConfigOptions.useNegation()); options.add(CommonConfigOptions.useBooleanDatatypes()); DoubleConfigOption noisePercentage = new DoubleConfigOption("noisePercentage", "the (approximated) percentage of noise within the examples"); - noisePercentage.setLowerLimit(0.0); - noisePercentage.setUpperLimit(1.0); + noisePercentage.setLowerLimit(0); + noisePercentage.setUpperLimit(100); options.add(noisePercentage); return options; } @@ -228,12 +228,13 @@ */ @Override public void init() { + if(searchTreeFile == null) searchTreeFile = new File(defaultSearchTreeFile); if(writeSearchTree) Files.clearFile(searchTreeFile); - + // adjust heuristic ExampleBasedHeuristic algHeuristic; @@ -243,8 +244,7 @@ if(learningProblem instanceof PosOnlyDefinitionLP) { throw new RuntimeException("does not work with positive examples only yet"); } - algHeuristic = null; - // algHeuristic = new FlexibleHeuristic(learningProblem.getNegativeExamples().size(), learningProblem.getPercentPerLengthUnit()); + algHeuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); } // compute used concepts/roles from allowed/ignored Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 09:31:41 UTC (rev 644) @@ -210,6 +210,7 @@ } public void start() { + // calculate quality threshold required for a solution allowedMisclassifications = (int) Math.round(noise * nrOfExamples); @@ -559,7 +560,7 @@ tooWeakList.add(refinement); } else { // Lösung gefunden - if(quality == 0) { + if(quality >= 0 && quality<allowedMisclassifications) { solutionFound = true; solutions.add(refinement); } @@ -609,8 +610,11 @@ long algorithmRuntime = System.nanoTime() - algorithmStartTime; if(!finalStats) { + ExampleBasedNode bestNode = candidatesStable.last(); + double accuracy = 100 * ((bestNode.getCoveredPositives().size() + + nrOfNegativeExamples - bestNode.getCoveredNegatives().size())/(double)nrOfExamples); // Refinementoperator auf Konzept anwenden - String bestNodeString = "currently best node: " + candidatesStable.last(); + String bestNodeString = "currently best node: " + bestNode + " accuracy: " + df.format(accuracy) + "%"; // searchTree += bestNodeString + "\n"; System.out.println(bestNodeString); String expandedNodeString = "next expanded node: " + candidates.last(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 09:31:41 UTC (rev 644) @@ -67,7 +67,7 @@ private boolean useAllConstructor = true; private boolean useExistsConstructor = true; private boolean useNegation = true; - private boolean useBooleanDatatypes = true; + private boolean useBooleanDatatypes = false; private boolean quiet = false; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-27 09:31:41 UTC (rev 644) @@ -318,7 +318,8 @@ // falls Konzept ungleich Bottom oder Top, dann kann ein Refinement von Top // angehangen werden if(concept instanceof Union || concept instanceof NamedClass || - concept instanceof Negation || concept instanceof ObjectSomeRestriction || concept instanceof ObjectAllRestriction) { + concept instanceof Negation || concept instanceof ObjectQuantorRestriction + || concept instanceof ValueRestriction) { // long someTimeNsStart = System.nanoTime(); // someCount++; // Refinement von Top anhängen Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-27 09:31:41 UTC (rev 644) @@ -324,7 +324,7 @@ } } catch (InvalidConfigOptionValueException e) { - // e.printStackTrace(); + e.printStackTrace(); System.exit(0); } Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-27 09:31:41 UTC (rev 644) @@ -92,6 +92,10 @@ public Set<ObjectProperty> getAtomicRoles(); +// public String getBaseURI; +// +// public Map<String, String> getPrefixes(); + // currently, we do not require that datatype properties can be returned; // the main reason is that DIG does not distinguish between datatype and // object properties (of course one could implement it but it is not easy) Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-27 09:24:04 UTC (rev 643) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-27 09:31:41 UTC (rev 644) @@ -119,6 +119,10 @@ } + public static String getName() { + return "fast instance checker"; + } + /* * (non-Javadoc) * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 10:21:26
|
Revision: 646 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=646&view=rev Author: jenslehmann Date: 2008-02-27 02:21:24 -0800 (Wed, 27 Feb 2008) Log Message: ----------- - added methods (in ReasonerComponent) for getting namespaces of underlying knowledge sources - use toString(baseURI,prefixes) to get a string representation of axioms/concepts using those prefixes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/core/Reasoner.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 Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 09:49:18 UTC (rev 645) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 10:21:24 UTC (rev 646) @@ -236,10 +236,18 @@ int loop = 0; algorithmStartTime = System.nanoTime(); + long lastPrintTime = 0; + long currentTime; while(!solutionFound && !stop) { - printStatistics(false); + // print statistics at most once a second + currentTime = System.nanoTime(); + if(currentTime - lastPrintTime > 1000000000) { + printStatistics(false); + lastPrintTime = currentTime; + logger.debug("--- loop " + loop + " started ---"); + } // chose best node according to heuristics bestNode = candidates.last(); @@ -275,7 +283,7 @@ // Anzahl Schleifendurchläufe loop++; - logger.debug("--- loop " + loop + " finished ---"); + } Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-27 09:49:18 UTC (rev 645) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-27 10:21:24 UTC (rev 646) @@ -92,10 +92,10 @@ public Set<ObjectProperty> getAtomicRoles(); -// public String getBaseURI; -// -// public Map<String, String> getPrefixes(); + public String getBaseURI(); + public Map<String, String> getPrefixes(); + // currently, we do not require that datatype properties can be returned; // the main reason is that DIG does not distinguish between datatype and // object properties (of course one could implement it but it is not easy) Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-02-27 09:49:18 UTC (rev 645) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-02-27 10:21:24 UTC (rev 646) @@ -779,4 +779,18 @@ return reasonerURL; } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getBaseURI() + */ + public String getBaseURI() { + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getPrefixes() + */ + public Map<String, String> getPrefixes() { + return null; + } + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-27 09:49:18 UTC (rev 645) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-27 10:21:24 UTC (rev 646) @@ -394,4 +394,18 @@ System.out.println(reasoner.instanceCheck(d, i)); } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getBaseURI() + */ + public String getBaseURI() { + return rc.getBaseURI(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getPrefixes() + */ + public Map<String, String> getPrefixes() { + return rc.getPrefixes(); + } + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-02-27 09:49:18 UTC (rev 645) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-02-27 10:21:24 UTC (rev 646) @@ -1,5 +1,6 @@ package org.dllearner.reasoning; +import java.util.Map; import java.util.Set; import java.util.HashSet; import java.util.SortedSet; @@ -168,4 +169,18 @@ // TODO Auto-generated method stub } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getBaseURI() + */ + public String getBaseURI() { + return rc.getBaseURI(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getPrefixes() + */ + public Map<String, String> getPrefixes() { + return rc.getPrefixes(); + } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-27 09:49:18 UTC (rev 645) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-27 10:21:24 UTC (rev 646) @@ -93,12 +93,14 @@ import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyFormat; import org.semanticweb.owl.model.OWLOntologyManager; import org.semanticweb.owl.model.OWLOntologyStorageException; import org.semanticweb.owl.model.OWLTypedConstant; import org.semanticweb.owl.model.OWLUntypedConstant; import org.semanticweb.owl.model.UnknownOWLOntologyException; import org.semanticweb.owl.util.SimpleURIMapper; +import org.semanticweb.owl.vocab.NamespaceOWLOntologyFormat; /** * Mapping to OWL API reasoner interface. The OWL API currently @@ -138,6 +140,10 @@ Set<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<Individual> individuals = new TreeSet<Individual>(); + // namespaces + private Map<String, String> prefixes = new TreeMap<String,String>(); + private String baseURI; + public OWLAPIReasoner(Set<KnowledgeSource> sources) { this.sources = sources; } @@ -198,6 +204,14 @@ owlObjectProperties.addAll(ontology.getReferencedObjectProperties()); owlDatatypeProperties.addAll(ontology.getReferencedDataProperties()); owlIndividuals.addAll(ontology.getReferencedIndividuals()); + + OWLOntologyFormat format = manager.getOntologyFormat(ontology); + if(format instanceof NamespaceOWLOntologyFormat) { + prefixes = ((NamespaceOWLOntologyFormat)format).getNamespacesByPrefixMap(); + prefixes.remove(""); + baseURI = prefixes.get(""); + } + } catch (OWLOntologyCreationException e) { e.printStackTrace(); } catch (URISyntaxException e) { @@ -268,8 +282,6 @@ factory = manager.getOWLDataFactory(); - - // try { // if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) // System.out.println("DEFINED."); @@ -858,4 +870,18 @@ return intDatatypeProperties; } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getBaseURI() + */ + public String getBaseURI() { + return baseURI; + } + + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getPrefixes() + */ + public Map<String, String> getPrefixes() { + return prefixes; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 11:24:58
|
Revision: 647 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=647&view=rev Author: jenslehmann Date: 2008-02-27 03:24:56 -0800 (Wed, 27 Feb 2008) Log Message: ----------- preparations for getting domain/range of object/datatype properties (requires conversion from OWL API descriptions to DL-Learner descriptions which is not yet implemented) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.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/refinement/ROLearner.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/reasoning/OWLAPIReasoner.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/ADC.java 2008-02-27 11:24:56 UTC (rev 647) @@ -5,7 +5,18 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DescriptionVisitor; import org.dllearner.core.owl.KBElementVisitor; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDescriptionVisitor; +import org.semanticweb.owl.model.OWLObjectVisitor; +/** + * ADC stand for "automatically defined concept". It is used for + * concept invention in the Genetic Programming Algorithm. + * However, it is not used + * + * @author Jens Lehmann + * + */ public class ADC extends Description { /* @@ -53,6 +64,54 @@ visitor.visit(this); } + /* (non-Javadoc) + * @see org.semanticweb.owl.model.OWLDescription#accept(org.semanticweb.owl.model.OWLDescriptionVisitor) + */ + public void accept(OWLDescriptionVisitor arg0) { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see org.semanticweb.owl.model.OWLDescription#asOWLClass() + */ + public OWLClass asOWLClass() { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see org.semanticweb.owl.model.OWLDescription#isAnonymous() + */ + public boolean isAnonymous() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.semanticweb.owl.model.OWLDescription#isOWLNothing() + */ + public boolean isOWLNothing() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.semanticweb.owl.model.OWLDescription#isOWLThing() + */ + public boolean isOWLThing() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see org.semanticweb.owl.model.OWLObject#accept(org.semanticweb.owl.model.OWLObjectVisitor) + */ + public void accept(OWLObjectVisitor arg0) { + // TODO Auto-generated method stub + + } + + + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-02-27 11:24:56 UTC (rev 647) @@ -9,6 +9,8 @@ import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.refinementoperators.PsiDown; +import org.dllearner.refinementoperators.PsiUp; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Deleted: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java 2008-02-27 11:24:56 UTC (rev 647) @@ -1,245 +0,0 @@ -package org.dllearner.algorithms.hybridgp; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.owl.ObjectAllRestriction; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Nothing; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.Union; -import org.dllearner.core.owl.Negation; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectQuantorRestriction; -import org.dllearner.core.owl.Thing; -import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.utilities.ConceptComparator; - -/** - * Operatoren Psi-Down und Psi-Up müssen noch so umgeschrieben werden, dass sie - * nur konsistente Konzepte (mit korrekten parent-Links) enthalten. Dazu müssen - * alle verwendeten atomaren Konzepte geklont werden. - * - * Außerdem erscheint es ratsam weitere konzeptverkürzende Maßnahmen einzuführen, - * z.B. EXISTS r.A => BOTTOM für down bzw. TOP für up - * => Konzepte erreichen etwa eine Länge von 20 - * - * @author jl - * - */ -public class PsiDown implements RefinementOperator { - - ConceptComparator conceptComparator = new ConceptComparator(); - - PosNegLP learningProblem; - ReasoningService reasoningService; - - private TreeSet<Description> topSet; - - public PsiDown(PosNegLP learningProblem) { - this.learningProblem = learningProblem; - reasoningService = learningProblem.getReasoningService(); - - // Top-Menge erstellen - createTopSet(); - } - - private void createTopSet() { - topSet = new TreeSet<Description>(conceptComparator); - - // TOP OR TOP => Was soll mit Refinements passieren, die immer improper sind? - Union md = new Union(); - md.addChild(new Thing()); - md.addChild(new Thing()); - topSet.add(md); - - // allgemeinste Konzepte - topSet.addAll(reasoningService.getMoreSpecialConcepts(new Thing())); - - // negierte speziellste Konzepte - Set<Description> tmp = learningProblem.getReasoningService().getMoreGeneralConcepts(new Nothing()); - for(Description c : tmp) - topSet.add(new Negation(c)); - - // EXISTS r.TOP und ALL r.TOP für alle r - for(ObjectProperty r : reasoningService.getAtomicRoles()) { - topSet.add(new ObjectAllRestriction(r, new Thing())); - topSet.add(new ObjectSomeRestriction(r, new Thing())); - } - } - - @SuppressWarnings("unchecked") - public Set<Description> refine(Description concept) { - - Set<Description> refinements = new HashSet<Description>(); - Set<Description> tmp = new HashSet<Description>(); - - if (concept instanceof Thing) { - return (Set<Description>) topSet.clone(); - } else if (concept instanceof Nothing) { - // return new TreeSet<Concept>(conceptComparator); - return new HashSet<Description>(); - } else if (concept instanceof NamedClass) { - // beachte: die Funktion gibt bereits nur nicht-äquivalente Konzepte zurück - // beachte weiter: die zurückgegebenen Instanzen dürfen nicht verändert werden, - // da beim Caching der Subsumptionhierarchie (momentan) keine Kopien gemacht werden - // Bottom wird hier ggf. automatisch mit zurückgegeben - refinements.addAll(reasoningService.getMoreSpecialConcepts(concept)); - // negiertes atomares Konzept - } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) { - tmp.addAll(reasoningService.getMoreGeneralConcepts(concept.getChild(0))); - - // Top rausschmeissen - boolean containsTop = false; - Iterator<Description> it = tmp.iterator(); - while(it.hasNext()) { - Description c = it.next(); - if(c instanceof Thing) { - it.remove(); - containsTop = true; - } - } - if(containsTop) - refinements.add(new Nothing()); - - for(Description c : tmp) { - refinements.add(new Negation(c)); - } - } else if (concept instanceof Intersection) { - // eines der Elemente kann verfeinert werden - for(Description child : concept.getChildren()) { - - // Refinement für das Kind ausführen - tmp = refine(child); - - // neue MultiConjunction konstruieren - for(Description c : tmp) { - // TODO: müssen auch alle Konzepte geklont werden?? - // hier wird nur eine neue Liste erstellt - // => eigentlich muss nicht geklont werden (d.h. deep copy) da - // die Konzepte nicht verändert werden während des Algorithmus - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - // es muss genau die vorherige Reihenfolge erhalten bleiben - // (zumindest bis die Normalform definiert ist) - int index = newChildren.indexOf(child); - newChildren.add(index, c); - newChildren.remove(child); - Intersection mc = new Intersection(newChildren); - refinements.add(mc); - } - } - } else if (concept instanceof Union) { - // eines der Elemente kann verfeinert werden - for(Description child : concept.getChildren()) { - - // Refinement für das Kind ausführen - // tmp = refine(child); - tmp = refine(child); - // neue MultiConjunction konstruieren - for(Description c : tmp) { - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - // es muss genau die vorherige Reihenfolge erhalten bleiben - // (zumindest bis die Normalform definiert ist) - int index = newChildren.indexOf(child); - newChildren.add(index, c); - newChildren.remove(child); - Union md = new Union(newChildren); - refinements.add(md); - } - } - - // ein Element der Disjunktion kann weggelassen werden - for(Description child : concept.getChildren()) { - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - newChildren.remove(child); - // wenn nur ein Kind da ist, dann wird Disjunktion gleich weggelassen - if(newChildren.size()==1) - refinements.add(newChildren.get(0)); - else { - Union md = new Union(newChildren); - refinements.add(md); - } - } - - } else if (concept instanceof ObjectSomeRestriction) { - tmp = refine(concept.getChild(0)); - for(Description c : tmp) { - refinements.add(new ObjectSomeRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); - } - - // falls Kind Bottom ist, dann kann exists weggelassen werden - if(concept.getChild(0) instanceof Nothing) - refinements.add(new Nothing()); - - } else if (concept instanceof ObjectAllRestriction) { - tmp = refine(concept.getChild(0)); - for(Description c : tmp) { - refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); - } - - if(concept.getChild(0) instanceof Nothing) - refinements.add(new Nothing()); - - // falls es keine spezielleren atomaren Konzepte gibt, dann wird - // bottom angehangen => nur wenn es ein atomares Konzept (insbesondere != bottom) - // ist - // if(tmp.size()==0) { - // if(concept.getChild(0) instanceof AtomicConcept && tmp.size()==0) { - // refinements.add(new All(((Quantification)concept).getRole(),new Bottom())); - //} - } else - throw new RuntimeException(concept.toString()); - - // falls Konzept ungleich Bottom oder Top, dann kann ein Refinement von Top - // angehangen werden - if(concept instanceof Union || concept instanceof NamedClass || - concept instanceof Negation || concept instanceof ObjectSomeRestriction || concept instanceof ObjectAllRestriction) { - - // es wird AND TOP angehangen - Intersection mc = new Intersection(); - mc.addChild(concept); - mc.addChild(new Thing()); - refinements.add(mc); - } - - // Refinements werden jetzt noch bereinigt, d.h. Verschachtelungen von Konjunktionen - // werden entfernt; es wird eine neue Menge erzeugt, da die Transformationen die - // Ordnung des Konzepts ändern könnten - // TODO: eventuell geht das noch effizienter, da die meisten Refinement-Regeln Refinements - // von Child-Konzepten sind, die bereits geordnet sind, d.h. man könnte dort eventuell - // gleich absichern, dass alle neu hinzugefügten Refinements in geordneter Negationsnormalform - // sind - // SortedSet<Concept> returnSet = new TreeSet<Concept>(conceptComparator); - /* - - Set<Concept> returnSet = new HashSet<Concept>(); - for(Concept c : refinements) { - ConceptTransformation.cleanConcept(c); - // ConceptTransformation.transformToOrderedNegationNormalForm(c, conceptComparator); - returnSet.add(c); - } - - return returnSet; - */ - - // Zwischenschritt wird weggelassen - man muss nicht alle Konzepte cleanen, - // um dann nur eins davon auszuwählen - - return refinements; - - } - - public Set<Description> refine(Description concept, int maxLength, - List<Description> knownRefinements) { - throw new RuntimeException(); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java 2008-02-27 11:24:56 UTC (rev 647) @@ -1,221 +0,0 @@ -package org.dllearner.algorithms.hybridgp; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.owl.ObjectAllRestriction; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Nothing; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.Union; -import org.dllearner.core.owl.Negation; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectQuantorRestriction; -import org.dllearner.core.owl.Thing; -import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.utilities.ConceptComparator; - -public class PsiUp implements RefinementOperator { - - ConceptComparator conceptComparator = new ConceptComparator(); - - PosNegLP learningProblem; - ReasoningService reasoningService; - - private TreeSet<Description> bottomSet; - - public PsiUp(PosNegLP learningProblem) { - this.learningProblem = learningProblem; - reasoningService = learningProblem.getReasoningService(); - - // Top-Menge erstellen - createBottomSet(); - } - - private void createBottomSet() { - bottomSet = new TreeSet<Description>(conceptComparator); - - // BOTTOM AND BOTTOM - Intersection mc = new Intersection(); - mc.addChild(new Nothing()); - mc.addChild(new Nothing()); - bottomSet.add(mc); - - // speziellste Konzepte - bottomSet.addAll(reasoningService.getMoreGeneralConcepts(new Nothing())); - - // negierte allgemeinste Konzepte - Set<Description> tmp = reasoningService.getMoreSpecialConcepts(new Thing()); - for(Description c : tmp) - bottomSet.add(new Negation(c)); - - // EXISTS r.BOTTOM und ALL r.BOTTOM für alle r - for(ObjectProperty r : reasoningService.getAtomicRoles()) { - bottomSet.add(new ObjectAllRestriction(r, new Nothing())); - bottomSet.add(new ObjectSomeRestriction(r, new Nothing())); - } - } - - @SuppressWarnings("unchecked") - public Set<Description> refine(Description concept) { - - Set<Description> refinements = new HashSet<Description>(); - Set<Description> tmp = new HashSet<Description>(); - - if (concept instanceof Thing) { - return new TreeSet<Description>(conceptComparator); - } else if (concept instanceof Nothing) { - return (Set<Description>) bottomSet.clone(); - } else if (concept instanceof NamedClass) { - // Top darf hier mit dabei sein - refinements.addAll(reasoningService.getMoreGeneralConcepts(concept)); - - // negiertes atomares Konzept - } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) { - tmp.addAll(reasoningService.getMoreSpecialConcepts(concept.getChild(0))); - - // Bottom rausschmeissen - boolean containsBottom = false; - Iterator<Description> it = tmp.iterator(); - while(it.hasNext()) { - Description c = it.next(); - if(c instanceof Nothing) { - it.remove(); - containsBottom = true; - } - } - // es soll z.B. NOT male auch zu NOT BOTTOM d.h. zu TOP verfeinert - // werden können - if(containsBottom) - refinements.add(new Thing()); - - for(Description c : tmp) { - refinements.add(new Negation(c)); - } - } else if (concept instanceof Intersection) { - // eines der Elemente kann verfeinert werden - for(Description child : concept.getChildren()) { - - // Refinement für das Kind ausführen - tmp = refine(child); - - // neue MultiConjunction konstruieren - for(Description c : tmp) { - // TODO: müssen auch alle Konzepte geklont werden?? - // hier wird nur eine neue Liste erstellt - // => eigentlich muss nicht geklont werden (d.h. deep copy) da - // die Konzepte nicht verändert werden während des Algorithmus - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - // es muss genau die vorherige Reihenfolge erhalten bleiben - // (zumindest bis die Normalform definiert ist) - int index = newChildren.indexOf(child); - newChildren.add(index, c); - newChildren.remove(child); - Intersection mc = new Intersection(newChildren); - refinements.add(mc); - } - } - - // ein Element der Konjunktion kann weggelassen werden - for(Description child : concept.getChildren()) { - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - newChildren.remove(child); - if(newChildren.size()==1) - refinements.add(newChildren.get(0)); - else { - Intersection md = new Intersection(newChildren); - refinements.add(md); - } - } - } else if (concept instanceof Union) { - // eines der Elemente kann verfeinert werden - for(Description child : concept.getChildren()) { - - // Refinement für das Kind ausführen - // tmp = refine(child); - tmp = refine(child); - // neue MultiConjunction konstruieren - for(Description c : tmp) { - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - // es muss genau die vorherige Reihenfolge erhalten bleiben - // (zumindest bis die Normalform definiert ist) - int index = newChildren.indexOf(child); - newChildren.add(index, c); - newChildren.remove(child); - Union md = new Union(newChildren); - refinements.add(md); - } - } - } else if (concept instanceof ObjectSomeRestriction) { - tmp = refine(concept.getChild(0)); - for(Description c : tmp) { - refinements.add(new ObjectSomeRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); - } - - if(concept.getChild(0) instanceof Thing) - refinements.add(new Thing()); - - } else if (concept instanceof ObjectAllRestriction) { - tmp = refine(concept.getChild(0)); - for(Description c : tmp) { - refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); - } - - if(concept.getChild(0) instanceof Thing) - refinements.add(new Thing()); - - // falls es keine spezielleren atomaren Konzepte gibt, dann wird - // bottom angehangen => nur wenn es ein atomares Konzept (insbesondere != bottom) - // ist - // if(tmp.size()==0) { - // if(concept.getChild(0) instanceof AtomicConcept && tmp.size()==0) { - // refinements.add(new All(((Quantification)concept).getRole(),new Bottom())); - //} - } else - throw new RuntimeException(concept.toString()); - - if(concept instanceof Union || concept instanceof NamedClass || - concept instanceof Negation || concept instanceof ObjectSomeRestriction || concept instanceof ObjectAllRestriction) { - - // es wird OR BOTTOM angehangen - Union md = new Union(); - md.addChild(concept); - md.addChild(new Nothing()); - refinements.add(md); - } - - // Refinements werden jetzt noch bereinigt, d.h. Verschachtelungen von Konjunktionen - // werden entfernt; es wird eine neue Menge erzeugt, da die Transformationen die - // Ordnung des Konzepts ändern könnten - // TODO: eventuell geht das noch effizienter, da die meisten Refinement-Regeln Refinements - // von Child-Konzepten sind, die bereits geordnet sind, d.h. man könnte dort eventuell - // gleich absichern, dass alle neu hinzugefügten Refinements in geordneter Negationsnormalform - // sind - // SortedSet<Concept> returnSet = new TreeSet<Concept>(conceptComparator); - /* - Set<Concept> returnSet = new HashSet<Concept>(); - for(Concept c : refinements) { - ConceptTransformation.cleanConcept(c); - // ConceptTransformation.transformToOrderedNegationNormalForm(c, conceptComparator); - returnSet.add(c); - } - - return returnSet; - */ - return refinements; - } - - public Set<Description> refine(Description concept, int maxLength, - List<Description> knownRefinements) { - throw new RuntimeException(); - } - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 11:24:56 UTC (rev 647) @@ -26,7 +26,6 @@ import java.util.List; import java.util.Set; -import org.dllearner.algorithms.refinement.RhoDown; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -44,6 +43,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 11:24:56 UTC (rev 647) @@ -32,7 +32,6 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.algorithms.refinement.RefinementOperator; -import org.dllearner.algorithms.refinement.RhoDown; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; @@ -43,6 +42,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 11:24:56 UTC (rev 647) @@ -32,6 +32,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; Deleted: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-27 11:24:56 UTC (rev 647) @@ -1,765 +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.algorithms.refinement; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -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.dllearner.core.ReasoningService; -import org.dllearner.core.owl.BooleanValueRestriction; -import org.dllearner.core.owl.DatatypeProperty; -import org.dllearner.core.owl.ObjectAllRestriction; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Nothing; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.Union; -import org.dllearner.core.owl.Negation; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyExpression; -import org.dllearner.core.owl.ObjectQuantorRestriction; -import org.dllearner.core.owl.Thing; -import org.dllearner.core.owl.ValueRestriction; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.ConceptTransformation; - -/** - * Implementation of the downward refinement operator in the DL-Learner refinement - * based algorithm. - * - * See <a href="http://jens-lehmann.org/files/2007_alc_learning_algorithm.pdf" - * >http://jens-lehmann.org/files/2007_alc_learning_algorithm.pdf</a> for - * details. - * - * @author Jens Lehmann - * - */ -public class RhoDown implements RefinementOperator { - -// private PosNegLP learningProblem; - private ReasoningService rs; - - // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts - // bereits berechnet worden => entspricht der max. L�nge der Menge M - private int topRefinementsLength = 0; - - // die Menge M im Refinement-Operator indiziert nach ihrer L�nge - Map<Integer,Set<Description>> m = new HashMap<Integer,Set<Description>>(); - - // Zerlegungen der Zahl n in Mengen - // Map<Integer,Set<IntegerCombo>> combos = new HashMap<Integer,Set<IntegerCombo>>(); - Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); - // abspeichern von Kombinationen während diese rekursiv berechnet werden - // private List<List<Integer>> combosTmp; - - // Refinements des Top-Konzept indiziert nach Länge - Map<Integer, TreeSet<Description>> topRefinements = new HashMap<Integer, TreeSet<Description>>(); - Map<Integer, TreeSet<Description>> topRefinementsCumulative = new HashMap<Integer, TreeSet<Description>>(); - - // comparator für Konzepte - private ConceptComparator conceptComparator = new ConceptComparator(); - - // Statistik - public long mComputationTimeNs = 0; - public long topComputationTimeNs = 0; - - private boolean applyAllFilter = true; - private boolean applyExistsFilter = true; - private boolean useAllConstructor = true; - private boolean useExistsConstructor = true; - private boolean useNegation = true; - private boolean useBooleanDatatypes = true; - - // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? - // TODO: conceptComparator könnte auch noch Parameter sein - public RhoDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, - boolean useExistsConstructor, boolean useNegation, boolean useBooleanDatatypes) { - this.rs = reasoningService; - this.applyAllFilter = applyAllFilter; - this.applyExistsFilter = applyExistsFilter; - this.useAllConstructor = useAllConstructor; - this.useExistsConstructor = useExistsConstructor; - this.useNegation = useNegation; - this.useBooleanDatatypes = useBooleanDatatypes; - -// this.learningProblem = learningProblem; -// rs = learningProblem.getReasoningService(); - } - - public Set<Description> refine(Description concept) { - throw new RuntimeException(); - // TODO Auto-generated method stub - // return null; - } - - // TODO: Methode muss effizienter werden - // Hauptproblem ist nicht die Berechnung von M und Top (siehe Benchmarks) - // => zuerst muss Objekterzeugung minimiert werden - // => als zweites wäre bei nicht ausreichendem Performancegewinn die Implementierung - // von Minimallänge eine Möglichkeit (alle Refinements, auch improper, müssten - // dann im Algorithmus gespeichert werden) - @SuppressWarnings("unchecked") - public SortedSet<Description> refine(Description concept, int maxLength, - List<Description> knownRefinements) { - - - - // Set<Concept> refinements = new HashSet<Concept>(); - SortedSet<Description> refinements = new TreeSet<Description>(conceptComparator); - Set<Description> tmp = new HashSet<Description>(); - // SortedSet<Concept> tmp = new TreeSet<Concept>(conceptComparator); - - if (concept instanceof Thing) { - - // ggf. Refinements von Top erweitern - if(maxLength>topRefinementsLength) - computeTopRefinements(maxLength); - // System.out.println(topRefinements); - refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone(); - // refinements = copyTopRefinements(maxLength); - // refinements = topRefinementsCumulative.get(maxLength); - - } else if (concept instanceof Nothing) { - // return new HashSet<Concept>(); - } else if (concept instanceof ValueRestriction) { - // value restrictions cannot be further refined - } else if (concept instanceof NamedClass) { - // Erkenntnisse aus Benchmarks: dieser Teil wird sehr häufig aufgerufen, - // allerdings lässt er sich kaum weiter verbessern (selbst ohne klonen - // der Konzepte im DIG-Reasoner, was durch das entfernen von Bottom notwendig - // ist und außerdem sicherer vor zukünftigen Bugs, wird es nicht wesentlich - // schneller) - - // beachte: die Funktion gibt bereits nur nicht-äquivalente Konzepte zurück - // TODO: der Cast auf SortedSet ist nur ein Hack und muss später geeignet - // behandelt werden - refinements = rs.getMoreSpecialConcepts(concept); - // refinements.addAll(learningProblem.getReasoningService().getMoreSpecialConcepts(concept)); - - // Bottom rausschmeißen (nicht im Operator vorgesehen) - // Iterator<Concept> it = refinements.iterator(); - // while(it.hasNext()) { - // Concept c = it.next(); - // if(c instanceof Bottom) - // it.remove(); - // } - // geht jetzt auch schneller durch conceptComparator - refinements.remove(new Nothing()); - - // negiertes atomares Konzept - } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) { - - tmp = rs.getMoreGeneralConcepts(concept.getChild(0)); - - //Iterator<Concept> it = tmp.iterator(); - //while(it.hasNext()) { - // Concept c = it.next(); - // if(c instanceof Top) - // it.remove(); - //} - - // tmp.remove(new Top()); - - for(Description c : tmp) { - if(!(c instanceof Thing)) - refinements.add(new Negation(c)); - } - - } else if (concept instanceof Intersection) { - - // eines der Elemente kann verfeinert werden - for(Description child : concept.getChildren()) { - - // Refinement für das Kind ausführen - // System.out.println("child: " + child); - // wenn man von maximaler Länge die Länge des Konzepts außer dem aktuell - // betrachteten Element abzieht, dann bekommt man neue maxLength - tmp = refine(child, maxLength - concept.getLength()+child.getLength(),null); - - // neue MultiConjunction konstruieren - for(Description c : tmp) { - // TODO: müssen auch alle Konzepte geklont werden?? - // hier wird nur eine neue Liste erstellt - // => eigentlich muss nicht geklont werden (d.h. deep copy) da - // die Konzepte nicht verändert werden während des Algorithmus - // => es muss geklont werden, da die top refinements nicht verändert - // werden dürfen - // List<Concept> newChildren = new LinkedList<Concept>(concept.getChildren()); - // TODO: Class Cast ist nur ein Hack - List<Description> newChildren = (List<Description>)((LinkedList)concept.getChildren()).clone(); - // es muss genau die vorherige Reihenfolge erhalten bleiben - // (zumindest bis die Normalform definiert ist) - // int index = newChildren.indexOf(child); - // newChildren.add(index, c); - // newChildren.remove(child); - // MultiConjunction mc = new MultiConjunction(newChildren); - - // Index muss jetzt nich mehr erhalten bleiben, da ohnehin - // neu sortiert wird - newChildren.add(c); - newChildren.remove(child); - Intersection mc = new Intersection(newChildren); - - // sicherstellten, dass Konzept in negation normal form ist - ConceptTransformation.cleanConceptNonRecursive(mc); - ConceptTransformation.transformToOrderedNegationNormalFormNonRecursive(mc, conceptComparator); - - refinements.add(mc); - } - - } - - } else if (concept instanceof Union) { - // eines der Elemente kann verfeinert werden - for(Description child : concept.getChildren()) { - - // Refinement für das Kind ausführen - // tmp = refine(child); - tmp = refine(child, maxLength - concept.getLength()+child.getLength(),null); - - - - // neue MultiConjunction konstruieren - for(Description c : tmp) { - List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); - // es muss genau die vorherige Reihenfolge erhalten bleiben - // (zumindest bis die Normalform definiert ist) - // int index = newChildren.indexOf(child); - // newChildren.add(index, c); - newChildren.remove(child); - newChildren.add(c); - Union md = new Union(newChildren); - - // sicherstellten, dass Konzept in negation normal form ist - // ConceptTransformation.cleanConcept(md); // nicht notwendig, da kein Element einer - // Disjunktion auf eine Disjunktion abgebildet wird (nur Top und das ist nie - // in einer Disjunktion) - ConceptTransformation.transformToOrderedNegationNormalFormNonRecursive(md, conceptComparator); - - - refinements.add(md); - } - - - } - - } else if (concept instanceof ObjectSomeRestriction) { - ObjectPropertyExpression role = ((ObjectQuantorRestriction)concept).getRole(); - - // rule 1: EXISTS r.D => EXISTS r.E - tmp = refine(concept.getChild(0), maxLength-2, null); - - for(Description c : tmp) { - refinements.add(new ObjectSomeRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); - } - - // rule 2: EXISTS r.D => EXISTS s.D or EXISTS r^-1.D => EXISTS s^-1.D - // currently inverse roles are not supported - ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = rs.getMoreSpecialRoles(ar); - for(ObjectProperty moreSpecialRole : moreSpecialRoles) { - refinements.add(new ObjectSomeRestriction(moreSpecialRole, concept.getChild(0))); - } - - } else if (concept instanceof ObjectAllRestriction) { - ObjectPropertyExpression role = ((ObjectQuantorRestriction)concept).getRole(); - - // rule 1: ALL r.D => ALL r.E - tmp = refine(concept.getChild(0), maxLength-2, null); - - for(Description c : tmp) { - refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); - } - - // rule 2: ALL r.D => ALL r.BOTTOM if D is a most specific atomic concept - // falls es keine spezielleren atomaren Konzepte gibt, dann wird - // bottom angehangen => nur wenn es ein atomares Konzept (insbesondere != bottom) - // ist - // if(tmp.size()==0) { - if(concept.getChild(0) instanceof NamedClass && tmp.size()==0) { - refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),new Nothing())); - } - - // rule 3: ALL r.D => ALL s.D or ALL r^-1.D => ALL s^-1.D - // currently inverse roles are not supported - ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = rs.getMoreSpecialRoles(ar); - for(ObjectProperty moreSpecialRole : moreSpecialRoles) { - refinements.add(new ObjectAllRestriction(moreSpecialRole, concept.getChild(0))); - } - - } - - // falls Konzept ungleich Bottom oder Top, dann kann ein Refinement von Top - // angehangen werden - if(concept instanceof Union || concept instanceof NamedClass || - concept instanceof Negation || concept instanceof ObjectQuantorRestriction - || concept instanceof ValueRestriction) { - // long someTimeNsStart = System.nanoTime(); - // someCount++; - // Refinement von Top anhängen - int topRefLength = maxLength - concept.getLength() - 1; //-1 wegen zusätzlichem UND - // es könnte passieren, das wir hier neue Refinements von Top berechnen müssen - if(topRefLength > topRefinementsLength) - computeTopRefinements(topRefLength); - if(topRefLength>0) { - // Set<Concept> topRefs = copyTopRefinements(topRefLength); - Set<Description> topRefs = topRefinementsCumulative.get(topRefLength); - for(Description c : topRefs) { - boolean skip = false; - - // falls Refinement von der Form ALL r ist, dann prüfen, ob - // ALL r nicht bereits vorkommt - if(applyAllFilter) { - if(c instanceof ObjectAllRestriction) { - for(Description child : concept.getChildren()) { - if(child instanceof ObjectAllRestriction) { - ObjectPropertyExpression r1 = ((ObjectAllRestriction)c).getRole(); - ObjectPropertyExpression r2 = ((ObjectAllRestriction)child).getRole(); - if(r1.toString().equals(r2.toString())) - skip = true; - } - } - } - } - - if(!skip) { - // MultiConjunction md = new MultiConjunction(concept.getChildren()); - Intersection mc = new Intersection(); - mc.addChild(concept); - mc.addChild(c); - - // Negationsnormalform herstellen - ConceptTransformation.cleanConceptNonRecursive(mc); - ConceptTransformation.transformToOrderedNegationNormalFormNonRecursive(mc, conceptComparator); - - refinements.add(mc); - } - } - } - // someTimeNs += System.nanoTime() - someTimeNsStart; - } - - - - // Refinements werden jetzt noch bereinigt, d.h. Verschachtelungen von Konjunktionen - // werden entfernt; es wird eine neue Menge erzeugt, da die Transformationen die - // Ordnung des Konzepts ändern könnten - // TODO: eventuell geht das noch effizienter, da die meisten Refinement-Regeln Refinements - // von Child-Konzepten sind, die bereits geordnet sind, d.h. man könnte dort eventuell - // gleich absichern, dass alle neu hinzugefügten Refinements in geordneter Negationsnormalform - // sind - /* - SortedSet<Concept> returnSet = new TreeSet<Concept>(conceptComparator); - for(Concept c : refinements) { - ConceptTransformation.cleanConcept(c); - ConceptTransformation.transformToOrderedNegationNormalForm(c, conceptComparator); - returnSet.add(c); - } - - return returnSet; - */ - // TODO: obiger Code kann noch nicht gelöscht werden (anderes Ergebnis); warum? - // => erstmal so implementieren, dass obiger Code nicht mehr gebraucht wird und - // im zweiten Schritt dann auf die nicht-rekursiven Methoden umsteigen - return refinements; - } - - - // TODO: Methode kann später entfernt werden, es muss nur - // sichergestellt werden, dass die refine-Methode an den - // kumulativen Top-Refinements nichts ändert - @SuppressWarnings("unused") - private SortedSet<Description> copyTopRefinements(int maxLength) { - // return topRefinementsCumulative.get(maxLength); - SortedSet<Description> ret = new TreeSet<Description>(conceptComparator); - for(Description c : topRefinementsCumulative.get(maxLength)) - ret.add(c); - return ret; - } - - - // TODO: später private - public void computeTopRefinements(int maxLength) { - long topComputationTimeStartNs = System.nanoTime(); - - // M erweiteren - computeM(maxLength); - - // berechnen aller möglichen Kombinationen für Disjunktion, - for(int i = topRefinementsLength+1; i <= maxLength; i++) { - combos.put(i,getCombos(i)); - topRefinements.put(i, new TreeSet<Description>(conceptComparator)); - // topRefinements.put(i, new HashSet<Concept>()); - - for(List<Integer> combo : combos.get(i)) { - /* - // für eine Kombo alle Konzeptkombinationen berechnen - Set<Set<Concept>> baseSet = new HashSet<Set<Concept>>(); - // boolean firstNonEmptyNumber = true; - for(Integer j : combo.getNumbers()) { - // initialisiert wird mit der passenden Menge m - //if(firstNonEmptyNumber || ) - // baseSet.add(m.get(j)); - // else { - baseSet = incCrossProduct(baseSet,m.get(j)); - //} - } - - // Disjunktionen erzeugen und hinzufügen - for(Set<Concept> children : baseSet) { - if(children.size() == 1) { - Iterator<Concept> it = children.iterator(); - Concept c = it.next(); - topRefinements.get(i).add(c); - } else { - topRefinements.get(i).add(new MultiDisjunction(children)); - } - } - */ - - /* neue Implementierung */ - - // Kombination besteht aus nur einer Zahl => einfach M benutzen - // if(combo.getNumbers().size()==1) { - if(combo.size()==1) { - topRefinements.get(i).addAll(m.get(i)); - // Kombination besteht aus mehreren Zahlen => Disjunktion erzeugen - } else { - Set<Union> baseSet = new HashSet<Union>(); - for(Integer j : combo) { // combo.getNumbers()) { - baseSet = incCrossProduct2(baseSet, m.get(j)); - } - - // Umwandlung aller Konzepte in Negationsnormalform - for(Description concept : baseSet) { - ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); - } - - if(applyExistsFilter) { - Iterator<Union> it = baseSet.iterator(); - while(it.hasNext()) { - Union md = it.next(); - boolean remove = false; - // falls Exists r für gleiche Rolle zweimal vorkommt, - // dann rausschmeißen - // Map<AtomicRole,Boolean> roleOccured = new HashMap<AtomicRole,Boolean>(); - Set<String> roles = new TreeSet<String>(); - for(Description c : md.getChildren()) { - if(c instanceof ObjectSomeRestriction) { - String role = ((ObjectSomeRestriction)c).getRole().getName(); - boolean roleExists = !roles.add(role); - // falls Rolle schon vorkommt, dann kann ganzes - // Refinement ignoriert werden (man könnte dann auch - // gleich abbrechen, aber das hat nur minimalste - // Auswirkungen auf Effizienz) - if(roleExists) - remove = true; - } - } - if(remove) - it.remove(); - - } - } - - topRefinements.get(i).addAll(baseSet); - } - } - - // neu berechnete Refinements kumulieren, damit sie schneller abgefragt werden können - // computeCumulativeTopRefinements(i); - TreeSet<Description> cumulativeRefinements = new TreeSet<Description>(conceptComparator); - // Set<Concept> cumulativeRefinements = new HashSet<Concept>(); - for(int j=1; j<=i; j++) { - cumulativeRefinements.addAll(topRefinements.get(j)); - } - topRefinementsCumulative.put(i, cumulativeRefinements); - } - - // neue Maximallänge eintragen - topRefinementsLength = maxLength; - - topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; - } - - // computation of the set M - private void computeM(int maxLength) { - long mComputationTimeStartNs = System.nanoTime(); - // System.out.println("compute M from " + (topRefinementsLength+1) + " up to " + maxLength); - - // initialise all not yet initialised lengths - // (avoids null pointers in some cases) - for(int i=topRefinementsLength+1; i<=maxLength; i++) { - m.put(i, new TreeSet<Description>(conceptComparator)); - } - - // Berechnung der Basiskonzepte in M - // TODO: Spezialfälle, dass zwischen Top und Bottom nichts liegt behandeln - if(topRefinementsLength==0 && maxLength>0) { - // Konzepte der Länge 1 = alle Konzepte, die in der Subsumptionhierarchie unter Top liegen - Set<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); - m.put(1,m1); - } - - if(topRefinementsLength<2 && maxLength>1) { - // Konzepte der Länge 2 = Negation aller Konzepte, die über Bottom liegen - if(useNegation) { - Set<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); - Set<Description> m2 = new TreeSet<Description>(conceptComparator); - for(Description c : m2tmp) { - m2.add(new Negation(c)); - } - m.put(2,m2); - } - } - - if(topRefinementsLength<3 && maxLength>2) { - // Konzepte der Länge 3: EXISTS r.TOP - Set<Description> m3 = new TreeSet<Description>(conceptComparator); - if(useExistsConstructor) { - // previous operator: uses all roles - // for(AtomicRole r : Config.Refinement.allowedRoles) { - // m3.add(new Exists(r, new Top())); - //} - // new operator: only uses most general roles - for(ObjectProperty r : rs.getMostGeneralRoles()) { - m3.add(new ObjectSomeRestriction(r, new Thing())); - } - - } - - // boolean datatypes, e.g. testPositive = true - if(useBooleanDatatypes) { - Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); - for(DatatypeProperty dp : booleanDPs) { - m3.add(new BooleanValueRestriction(dp,true)); - m3.add(new BooleanValueRestriction(dp,false)); - } - } - - m.put(3,m3); - } - - if(maxLength>2) { - if(useAllConstructor) { - // Konzepte, die mit ALL r starten - // alle existierenden Konzepte durchgehen, die maximal 2 k�rzer als - // die maximale L�nge sind - // topRefinementsLength - 1, damit Konzepte der Länge mindestens - // topRefinementsLength + 1 erzeugt werden (ALL r) - for(int i=topRefinementsLength-1; i<=maxLength-2; i++) { - // i muss natürlich mindestens 1 sein - if(i>=1) { - - // alle Konzepte durchgehen - for(Description c : m.get(i)) { - // Fall wird jetzt weiter oben schon abgehandelt - // if(!m.containsKey(i+2)) - // m.put(i+2, new TreeSet<Concept>(conceptComparator)); - - // previous operator: uses all roles - // for(AtomicRole r : Config.Refinement.allowedRoles) { - // Mehrfacheinf�gen ist bei einer Menge kein Problem - // m.get(i+2).add(new All(r,c)); - // } - - for(ObjectProperty r : rs.getMostGeneralRoles()) { - m.get(i+2).add(new ObjectAllRestriction(r,c)); - } - } - } - } - } - } - - mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; - } - - - public static void summen(int zahl, int max, String bisher, int recDepth) - { - for(int j=0; j<recDepth; j++) - System.out.print(" "); - System.out.println("f("+zahl+","+max+",\""+bisher+"\")"); - - for (int i = Math.min(zahl, max); i >= 1; i--) - { - - String jetzt = bisher + i; - - if (zahl - i > 1) - { - jetzt += " + "; - // i wird hinzugefügt, d.h. - // - es muss nur noch zahl - i zerlegt werden - // - es darf keine größere Zahl als i mehr vorkommen - // (dadurch gehen keine Kombinationen verloren) - summen(zahl - i -1 , i, jetzt, recDepth+1); - } - // Fall zahl == i, d.h. es muss nicht weiter zerlegt werden - else if(zahl - i == 0){ - for(int j=0; j<recDepth; j++) - System.out.print(" "); - System.out.println(jetzt); - } - // durch die -1 Abzug für jedes Zwischenzeichen gibt es auch Fälle, in denen - // keine Lösung entsteht (zahl-i==1) - - } - } - - @SuppressWarnings("unchecked") - private LinkedList<Integer> cloneList(LinkedList<Integer> list) { - return (LinkedList<Integer>) list.clone(); - } - - /** - * - * Dadurch das max das Maximum der vorkommenden Zahl regelt, kommen - * keine doppelten Kombinationen vor. - * - * TODO: Implementierung mit Speicherung in Datenstruktur statt - * direkter Ausgabe; IntegerCombo wird hier gar nicht benötigt, da - * alle Elemente bereits in richtiger Reihenfolge vorliegen und - * es keine doppelten Nennungen gibt - * - * @param zahl Zu zerlegende Zahl. - * @param max Maximal in Summenzerlegung vorkommende Zahl. - * @param bisher - */ - private void zerlege(int zahl, int max, LinkedList<Integer> bisher, List<List<Integer>> combosTmp) { - - for (int i = Math.min(zahl, max); i >= 1; i--) - { - - LinkedList<Integer> newBisher = null; - // für i==0 wird aus Effizienzgründen die bisherige Liste genommen - if(i==0) { - newBisher = bisher; - newBisher.add(i); - // für zahl - i == 1 muss gar keine Liste erstellt werden, da dann keine - // Zerlegung mehr möglich ist - } else if(zahl - i != 1) { - newBisher = cloneList(bisher); - newBisher.add(i); - } - - - if (zahl - i > 1) - { - // i wird hinzugefügt, d.h. - // - es muss nur noch zahl - i - 1 zerlegt werden (-1 wegen OR-Symbol) - // - es darf keine größere Zahl als i mehr vorkommen - // (dadurch gehen keine Kombinationen verloren) - zerlege(zahl - i - 1, i, newBisher,combosTmp); - } - // Fall zahl == i, d.h. es muss nicht weiter zerlegt werden - else if(zahl - i == 0){ - combosTmp.add(newBisher); - } - - - } - - // numbers.add(bisher); - } - - // auf Notebook: Länge 70 in 17 Sekunden, Länge 50 in 800ms, Länge 30 in 15ms - // http://88.198.173.90/tud/forum/messages?topic=304392 - public List<List<Integer>> getCombos(int length) { - LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>(); - zerlege(length, length, new LinkedList<Integer>(), combosTmp); - return combosTmp; - } - - // neue Implementierung, die nicht mehr zur incompleteness führen soll, - // da die Konzepte in einer MultiDisjunction als Liste gespeichert werden - private Set<Union> incCrossProduct2(Set<Union> baseSet, Set<Description> newSet) { - Set<Union> retSet = new HashSet<Union>(); - - if(baseSet.isEmpty()) { - for(Description c : newSet) { - Union md = new Union(); - md.addChild(c); - retSet.add(md); - } - return retSet; - } - - for(Union md : baseSet) { - for(Description c : newSet) { - Union mdNew = new Union(md.getChildren()); - mdNew.addChild(c); - retSet.add(mdNew); - } - } - - return retSet; - } - - // incremental cross product - // es müssen Listen statt Sets verwendet werden - @SuppressWarnings({"unused"}) - private Set<Set<Description>> incCrossProduct(Set<Set<Description>> baseSet, Set<Description> newSet) { - Set<Set<Description>> retSet = new HashSet<Set<Description>>(); - - // falls erste Menge leer ist, dann wird Menge mit jeweils Singletons aus der - // zweiten Menge zurückgegeben => das müsste dem Fall entsprechen, dass das - // baseSet nur die leere Menge enthält - if(baseSet.isEmpty()) { - for(Description c : newSet) { - Set<Description> singleton = new HashSet<Description>(); - singleton.add(c); - retSet.add(singleton); - } - // retSet.add(newSet); - return retSet; - } - - for(Set<Description> set : baseSet) { - for(Description c : newSet) { - // neues Konzept zu alter Konzeptmenge hinzufügen, indem altes - // Konzept kopiert und ergänzt wird - // beachte: dadurch, dass die Konzepte nach ihrem Hash eingefügt werden, - // ist schon eine Ordnung vorgegeben und es entfallen viele Mengen - // z.B. ist {male,female} = {female,male} - // TODO: das ist allerdings auch gefährlich, denn es gilt auch - // {male,male,female} = {male,female} d.h. es entfallen auch gewünschte - // Lösungen! (Es könnte z.B. sein, dass die Lösung eine Disjunktion von - // 3 atomaren Konzepten ist, die nur über male erreichbar sind.) D.h. diese - // Implementierung führt zur incompleteness des Operators. - Set<Description> newConcept = new HashSet<Description>(set); - newConcept.add(c); - retSet.add(newConcept); - } - } - return retSet; - } - -} Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-02-27 11:24:56 UTC (rev 647) @@ -25,6 +25,7 @@ import java.util.SortedSet; import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; @@ -96,6 +97,14 @@ public Map<String, String> getPrefixes(); + public Description getDomain(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException; + + public Description getDomain(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + + public Description getRange(ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException; + + public DataRange getRange(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + // currently, we do not require that datatype properties can be returned; // the main reason is that DIG does not distinguish between datatype and // object properties (of course one could implement it but it is not easy) Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-02-27 11:24:56 UTC (rev 647) @@ -28,6 +28,7 @@ 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.NamedClass; import org.dllearner.core.owl.Description; @@ -193,6 +194,22 @@ 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 Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-27 10:21:24 UTC (rev 646) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-27 11:24:56 UTC (rev 647) @@ -205,6 +205,7 @@ owlDatatypeProperties.addAll(ontology.getReferencedDataProperties()); owlIndividuals.addAll(ontology.getReferencedIndividuals()); + // TODO: this obviously works only for exactly one knowledge source OWLOntologyFormat format = manager.getOntologyFormat(ontology); if(format instanceof NamespaceOWLOntologyFormat) { prefixes = ((NamespaceOWLOntologyFormat)format).getNamespacesByPrefixMap(); @@ -533,6 +534,23 @@ } @Override + public Description getDomain(ObjectProperty objectProperty) { + OWLObjectProperty prop = getOWLAPIDescription(objectProperty); + try { + // TODO: look up why OWL API return a two dimensional set here + // instead of only one description (probably there can be several + // domain axiom for one property and the inner set is a conjunction + // of descriptions (?)) + OWLDescription d = reasoner.getDomains(prop).iterator().next().iterator().next(); +// OWLAPIDescriptionConvertVisitor.getOWLDescription(d); + } catch (OWLReasonerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + @Override public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { OWLObjectProperty prop = getOWLAPIDescription(atomicRole); Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 11:27:56
|
Revision: 648 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=648&view=rev Author: jenslehmann Date: 2008-02-27 03:27:52 -0800 (Wed, 27 Feb 2008) Log Message: ----------- moved refinement operators to own package Added Paths: ----------- trunk/src/dl-learner/org/dllearner/operators/ trunk/src/dl-learner/org/dllearner/operators/PsiDown.java trunk/src/dl-learner/org/dllearner/operators/PsiUp.java trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/operators/RhoDown.java Copied: trunk/src/dl-learner/org/dllearner/operators/PsiDown.java (from rev 639, trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiDown.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/PsiDown.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/operators/PsiDown.java 2008-02-27 11:27:52 UTC (rev 648) @@ -0,0 +1,245 @@ +package org.dllearner.refinementoperators; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.ObjectAllRestriction; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.Union; +import org.dllearner.core.owl.Negation; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectQuantorRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.utilities.ConceptComparator; + +/** + * Operatoren Psi-Down und Psi-Up müssen noch so umgeschrieben werden, dass sie + * nur konsistente Konzepte (mit korrekten parent-Links) enthalten. Dazu müssen + * alle verwendeten atomaren Konzepte geklont werden. + * + * Außerdem erscheint es ratsam weitere konzeptverkürzende Maßnahmen einzuführen, + * z.B. EXISTS r.A => BOTTOM für down bzw. TOP für up + * => Konzepte erreichen etwa eine Länge von 20 + * + * @author jl + * + */ +public class PsiDown implements RefinementOperator { + + ConceptComparator conceptComparator = new ConceptComparator(); + + PosNegLP learningProblem; + ReasoningService reasoningService; + + private TreeSet<Description> topSet; + + public PsiDown(PosNegLP learningProblem) { + this.learningProblem = learningProblem; + reasoningService = learningProblem.getReasoningService(); + + // Top-Menge erstellen + createTopSet(); + } + + private void createTopSet() { + topSet = new TreeSet<Description>(conceptComparator); + + // TOP OR TOP => Was soll mit Refinements passieren, die immer improper sind? + Union md = new Union(); + md.addChild(new Thing()); + md.addChild(new Thing()); + topSet.add(md); + + // allgemeinste Konzepte + topSet.addAll(reasoningService.getMoreSpecialConcepts(new Thing())); + + // negierte speziellste Konzepte + Set<Description> tmp = learningProblem.getReasoningService().getMoreGeneralConcepts(new Nothing()); + for(Description c : tmp) + topSet.add(new Negation(c)); + + // EXISTS r.TOP und ALL r.TOP für alle r + for(ObjectProperty r : reasoningService.getAtomicRoles()) { + topSet.add(new ObjectAllRestriction(r, new Thing())); + topSet.add(new ObjectSomeRestriction(r, new Thing())); + } + } + + @SuppressWarnings("unchecked") + public Set<Description> refine(Description concept) { + + Set<Description> refinements = new HashSet<Description>(); + Set<Description> tmp = new HashSet<Description>(); + + if (concept instanceof Thing) { + return (Set<Description>) topSet.clone(); + } else if (concept instanceof Nothing) { + // return new TreeSet<Concept>(conceptComparator); + return new HashSet<Description>(); + } else if (concept instanceof NamedClass) { + // beachte: die Funktion gibt bereits nur nicht-äquivalente Konzepte zurück + // beachte weiter: die zurückgegebenen Instanzen dürfen nicht verändert werden, + // da beim Caching der Subsumptionhierarchie (momentan) keine Kopien gemacht werden + // Bottom wird hier ggf. automatisch mit zurückgegeben + refinements.addAll(reasoningService.getMoreSpecialConcepts(concept)); + // negiertes atomares Konzept + } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) { + tmp.addAll(reasoningService.getMoreGeneralConcepts(concept.getChild(0))); + + // Top rausschmeissen + boolean containsTop = false; + Iterator<Description> it = tmp.iterator(); + while(it.hasNext()) { + Description c = it.next(); + if(c instanceof Thing) { + it.remove(); + containsTop = true; + } + } + if(containsTop) + refinements.add(new Nothing()); + + for(Description c : tmp) { + refinements.add(new Negation(c)); + } + } else if (concept instanceof Intersection) { + // eines der Elemente kann verfeinert werden + for(Description child : concept.getChildren()) { + + // Refinement für das Kind ausführen + tmp = refine(child); + + // neue MultiConjunction konstruieren + for(Description c : tmp) { + // TODO: müssen auch alle Konzepte geklont werden?? + // hier wird nur eine neue Liste erstellt + // => eigentlich muss nicht geklont werden (d.h. deep copy) da + // die Konzepte nicht verändert werden während des Algorithmus + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + // es muss genau die vorherige Reihenfolge erhalten bleiben + // (zumindest bis die Normalform definiert ist) + int index = newChildren.indexOf(child); + newChildren.add(index, c); + newChildren.remove(child); + Intersection mc = new Intersection(newChildren); + refinements.add(mc); + } + } + } else if (concept instanceof Union) { + // eines der Elemente kann verfeinert werden + for(Description child : concept.getChildren()) { + + // Refinement für das Kind ausführen + // tmp = refine(child); + tmp = refine(child); + // neue MultiConjunction konstruieren + for(Description c : tmp) { + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + // es muss genau die vorherige Reihenfolge erhalten bleiben + // (zumindest bis die Normalform definiert ist) + int index = newChildren.indexOf(child); + newChildren.add(index, c); + newChildren.remove(child); + Union md = new Union(newChildren); + refinements.add(md); + } + } + + // ein Element der Disjunktion kann weggelassen werden + for(Description child : concept.getChildren()) { + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + newChildren.remove(child); + // wenn nur ein Kind da ist, dann wird Disjunktion gleich weggelassen + if(newChildren.size()==1) + refinements.add(newChildren.get(0)); + else { + Union md = new Union(newChildren); + refinements.add(md); + } + } + + } else if (concept instanceof ObjectSomeRestriction) { + tmp = refine(concept.getChild(0)); + for(Description c : tmp) { + refinements.add(new ObjectSomeRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); + } + + // falls Kind Bottom ist, dann kann exists weggelassen werden + if(concept.getChild(0) instanceof Nothing) + refinements.add(new Nothing()); + + } else if (concept instanceof ObjectAllRestriction) { + tmp = refine(concept.getChild(0)); + for(Description c : tmp) { + refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); + } + + if(concept.getChild(0) instanceof Nothing) + refinements.add(new Nothing()); + + // falls es keine spezielleren atomaren Konzepte gibt, dann wird + // bottom angehangen => nur wenn es ein atomares Konzept (insbesondere != bottom) + // ist + // if(tmp.size()==0) { + // if(concept.getChild(0) instanceof AtomicConcept && tmp.size()==0) { + // refinements.add(new All(((Quantification)concept).getRole(),new Bottom())); + //} + } else + throw new RuntimeException(concept.toString()); + + // falls Konzept ungleich Bottom oder Top, dann kann ein Refinement von Top + // angehangen werden + if(concept instanceof Union || concept instanceof NamedClass || + concept instanceof Negation || concept instanceof ObjectSomeRestriction || concept instanceof ObjectAllRestriction) { + + // es wird AND TOP angehangen + Intersection mc = new Intersection(); + mc.addChild(concept); + mc.addChild(new Thing()); + refinements.add(mc); + } + + // Refinements werden jetzt noch bereinigt, d.h. Verschachtelungen von Konjunktionen + // werden entfernt; es wird eine neue Menge erzeugt, da die Transformationen die + // Ordnung des Konzepts ändern könnten + // TODO: eventuell geht das noch effizienter, da die meisten Refinement-Regeln Refinements + // von Child-Konzepten sind, die bereits geordnet sind, d.h. man könnte dort eventuell + // gleich absichern, dass alle neu hinzugefügten Refinements in geordneter Negationsnormalform + // sind + // SortedSet<Concept> returnSet = new TreeSet<Concept>(conceptComparator); + /* + + Set<Concept> returnSet = new HashSet<Concept>(); + for(Concept c : refinements) { + ConceptTransformation.cleanConcept(c); + // ConceptTransformation.transformToOrderedNegationNormalForm(c, conceptComparator); + returnSet.add(c); + } + + return returnSet; + */ + + // Zwischenschritt wird weggelassen - man muss nicht alle Konzepte cleanen, + // um dann nur eins davon auszuwählen + + return refinements; + + } + + public Set<Description> refine(Description concept, int maxLength, + List<Description> knownRefinements) { + throw new RuntimeException(); + } + +} Copied: trunk/src/dl-learner/org/dllearner/operators/PsiUp.java (from rev 639, trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/PsiUp.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/PsiUp.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/operators/PsiUp.java 2008-02-27 11:27:52 UTC (rev 648) @@ -0,0 +1,221 @@ +package org.dllearner.refinementoperators; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.ObjectAllRestriction; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.Union; +import org.dllearner.core.owl.Negation; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectQuantorRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.utilities.ConceptComparator; + +public class PsiUp implements RefinementOperator { + + ConceptComparator conceptComparator = new ConceptComparator(); + + PosNegLP learningProblem; + ReasoningService reasoningService; + + private TreeSet<Description> bottomSet; + + public PsiUp(PosNegLP learningProblem) { + this.learningProblem = learningProblem; + reasoningService = learningProblem.getReasoningService(); + + // Top-Menge erstellen + createBottomSet(); + } + + private void createBottomSet() { + bottomSet = new TreeSet<Description>(conceptComparator); + + // BOTTOM AND BOTTOM + Intersection mc = new Intersection(); + mc.addChild(new Nothing()); + mc.addChild(new Nothing()); + bottomSet.add(mc); + + // speziellste Konzepte + bottomSet.addAll(reasoningService.getMoreGeneralConcepts(new Nothing())); + + // negierte allgemeinste Konzepte + Set<Description> tmp = reasoningService.getMoreSpecialConcepts(new Thing()); + for(Description c : tmp) + bottomSet.add(new Negation(c)); + + // EXISTS r.BOTTOM und ALL r.BOTTOM für alle r + for(ObjectProperty r : reasoningService.getAtomicRoles()) { + bottomSet.add(new ObjectAllRestriction(r, new Nothing())); + bottomSet.add(new ObjectSomeRestriction(r, new Nothing())); + } + } + + @SuppressWarnings("unchecked") + public Set<Description> refine(Description concept) { + + Set<Description> refinements = new HashSet<Description>(); + Set<Description> tmp = new HashSet<Description>(); + + if (concept instanceof Thing) { + return new TreeSet<Description>(conceptComparator); + } else if (concept instanceof Nothing) { + return (Set<Description>) bottomSet.clone(); + } else if (concept instanceof NamedClass) { + // Top darf hier mit dabei sein + refinements.addAll(reasoningService.getMoreGeneralConcepts(concept)); + + // negiertes atomares Konzept + } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) { + tmp.addAll(reasoningService.getMoreSpecialConcepts(concept.getChild(0))); + + // Bottom rausschmeissen + boolean containsBottom = false; + Iterator<Description> it = tmp.iterator(); + while(it.hasNext()) { + Description c = it.next(); + if(c instanceof Nothing) { + it.remove(); + containsBottom = true; + } + } + // es soll z.B. NOT male auch zu NOT BOTTOM d.h. zu TOP verfeinert + // werden können + if(containsBottom) + refinements.add(new Thing()); + + for(Description c : tmp) { + refinements.add(new Negation(c)); + } + } else if (concept instanceof Intersection) { + // eines der Elemente kann verfeinert werden + for(Description child : concept.getChildren()) { + + // Refinement für das Kind ausführen + tmp = refine(child); + + // neue MultiConjunction konstruieren + for(Description c : tmp) { + // TODO: müssen auch alle Konzepte geklont werden?? + // hier wird nur eine neue Liste erstellt + // => eigentlich muss nicht geklont werden (d.h. deep copy) da + // die Konzepte nicht verändert werden während des Algorithmus + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + // es muss genau die vorherige Reihenfolge erhalten bleiben + // (zumindest bis die Normalform definiert ist) + int index = newChildren.indexOf(child); + newChildren.add(index, c); + newChildren.remove(child); + Intersection mc = new Intersection(newChildren); + refinements.add(mc); + } + } + + // ein Element der Konjunktion kann weggelassen werden + for(Description child : concept.getChildren()) { + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + newChildren.remove(child); + if(newChildren.size()==1) + refinements.add(newChildren.get(0)); + else { + Intersection md = new Intersection(newChildren); + refinements.add(md); + } + } + } else if (concept instanceof Union) { + // eines der Elemente kann verfeinert werden + for(Description child : concept.getChildren()) { + + // Refinement für das Kind ausführen + // tmp = refine(child); + tmp = refine(child); + // neue MultiConjunction konstruieren + for(Description c : tmp) { + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + // es muss genau die vorherige Reihenfolge erhalten bleiben + // (zumindest bis die Normalform definiert ist) + int index = newChildren.indexOf(child); + newChildren.add(index, c); + newChildren.remove(child); + Union md = new Union(newChildren); + refinements.add(md); + } + } + } else if (concept instanceof ObjectSomeRestriction) { + tmp = refine(concept.getChild(0)); + for(Description c : tmp) { + refinements.add(new ObjectSomeRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); + } + + if(concept.getChild(0) instanceof Thing) + refinements.add(new Thing()); + + } else if (concept instanceof ObjectAllRestriction) { + tmp = refine(concept.getChild(0)); + for(Description c : tmp) { + refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); + } + + if(concept.getChild(0) instanceof Thing) + refinements.add(new Thing()); + + // falls es keine spezielleren atomaren Konzepte gibt, dann wird + // bottom angehangen => nur wenn es ein atomares Konzept (insbesondere != bottom) + // ist + // if(tmp.size()==0) { + // if(concept.getChild(0) instanceof AtomicConcept && tmp.size()==0) { + // refinements.add(new All(((Quantification)concept).getRole(),new Bottom())); + //} + } else + throw new RuntimeException(concept.toString()); + + if(concept instanceof Union || concept instanceof NamedClass || + concept instanceof Negation || concept instanceof ObjectSomeRestriction || concept instanceof ObjectAllRestriction) { + + // es wird OR BOTTOM angehangen + Union md = new Union(); + md.addChild(concept); + md.addChild(new Nothing()); + refinements.add(md); + } + + // Refinements werden jetzt noch bereinigt, d.h. Verschachtelungen von Konjunktionen + // werden entfernt; es wird eine neue Menge erzeugt, da die Transformationen die + // Ordnung des Konzepts ändern könnten + // TODO: eventuell geht das noch effizienter, da die meisten Refinement-Regeln Refinements + // von Child-Konzepten sind, die bereits geordnet sind, d.h. man könnte dort eventuell + // gleich absichern, dass alle neu hinzugefügten Refinements in geordneter Negationsnormalform + // sind + // SortedSet<Concept> returnSet = new TreeSet<Concept>(conceptComparator); + /* + Set<Concept> returnSet = new HashSet<Concept>(); + for(Concept c : refinements) { + ConceptTransformation.cleanConcept(c); + // ConceptTransformation.transformToOrderedNegationNormalForm(c, conceptComparator); + returnSet.add(c); + } + + return returnSet; + */ + return refinements; + } + + public Set<Description> refine(Description concept, int maxLength, + List<Description> knownRefinements) { + throw new RuntimeException(); + } + +} Added: trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java 2008-02-27 11:27:52 UTC (rev 648) @@ -0,0 +1,57 @@ +/** + * 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.refinementoperators; + +import java.util.List; +import java.util.Set; + +import org.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.owl.Description; + +/** + * A downward refinement operator, which makes use of domains + * and ranges of properties. The operator is currently under + * development. Its aim is to span a much "cleaner" and smaller search + * tree compared to RhoDown by omitting many class descriptions, + * which are obviously too weak, because they violate + * domain/range restrictions. + * + * @author Jens Lehmann + * + */ +public class RhoDRDown implements RefinementOperator { + + /* (non-Javadoc) + * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description) + */ + public Set<Description> refine(Description concept) { + throw new RuntimeException(); + } + + /* (non-Javadoc) + * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) + */ + public Set<Description> refine(Description concept, int maxLength, + List<Description> knownRefinements) { + + return null; + } + +} Copied: trunk/src/dl-learner/org/dllearner/operators/RhoDown.java (from rev 644, trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/RhoDown.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/operators/RhoDown.java 2008-02-27 11:27:52 UTC (rev 648) @@ -0,0 +1,766 @@ +/** + * 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.refinementoperators; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +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.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.ObjectAllRestriction; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.Union; +import org.dllearner.core.owl.Negation; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectQuantorRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.ValueRestriction; +import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.ConceptTransformation; + +/** + * Implementation of the downward refinement operator in the DL-Learner refinement + * based algorithm. + * + * See <a href="http://jens-lehmann.org/files/2007_alc_learning_algorithm.pdf" + * >http://jens-lehmann.org/files/2007_alc_learning_algorithm.pdf</a> for + * details. + * + * @author Jens Lehmann + * + */ +public class RhoDown implements RefinementOperator { + +// private PosNegLP learningProblem; + private ReasoningService rs; + + // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts + // bereits berechnet worden => entspricht der max. L�nge der Menge M + private int topRefinementsLength = 0; + + // die Menge M im Refinement-Operator indiziert nach ihrer L�nge + Map<Integer,Set<Description>> m = new HashMap<Integer,Set<Description>>(); + + // Zerlegungen der Zahl n in Mengen + // Map<Integer,Set<IntegerCombo>> combos = new HashMap<Integer,Set<IntegerCombo>>(); + Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); + // abspeichern von Kombinationen während diese rekursiv berechnet werden + // private List<List<Integer>> combosTmp; + + // Refinements des Top-Konzept indiziert nach Länge + Map<Integer, TreeSet<Description>> topRefinements = new HashMap<Integer, TreeSet<Description>>(); + Map<Integer, TreeSet<Description>> topRefinementsCumulative = new HashMap<Integer, TreeSet<Description>>(); + + // comparator für Konzepte + private ConceptComparator conceptComparator = new ConceptComparator(); + + // Statistik + public long mComputationTimeNs = 0; + public long topComputationTimeNs = 0; + + private boolean applyAllFilter = true; + private boolean applyExistsFilter = true; + private boolean useAllConstructor = true; + private boolean useExistsConstructor = true; + private boolean useNegation = true; + private boolean useBooleanDatatypes = true; + + // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? + // TODO: conceptComparator könnte auch noch Parameter sein + public RhoDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, + boolean useExistsConstructor, boolean useNegation, boolean useBooleanDatatypes) { + this.rs = reasoningService; + this.applyAllFilter = applyAllFilter; + this.applyExistsFilter = applyExistsFilter; + this.useAllConstructor = useAllConstructor; + this.useExistsConstructor = useExistsConstructor; + this.useNegation = useNegation; + this.useBooleanDatatypes = useBooleanDatatypes; + +// this.learningProblem = learningProblem; +// rs = learningProblem.getReasoningService(); + } + + public Set<Description> refine(Description concept) { + throw new RuntimeException(); + // TODO Auto-generated method stub + // return null; + } + + // TODO: Methode muss effizienter werden + // Hauptproblem ist nicht die Berechnung von M und Top (siehe Benchmarks) + // => zuerst muss Objekterzeugung minimiert werden + // => als zweites wäre bei nicht ausreichendem Performancegewinn die Implementierung + // von Minimallänge eine Möglichkeit (alle Refinements, auch improper, müssten + // dann im Algorithmus gespeichert werden) + @SuppressWarnings("unchecked") + public SortedSet<Description> refine(Description concept, int maxLength, + List<Description> knownRefinements) { + + + + // Set<Concept> refinements = new HashSet<Concept>(); + SortedSet<Description> refinements = new TreeSet<Description>(conceptComparator); + Set<Description> tmp = new HashSet<Description>(); + // SortedSet<Concept> tmp = new TreeSet<Concept>(conceptComparator); + + if (concept instanceof Thing) { + + // ggf. Refinements von Top erweitern + if(maxLength>topRefinementsLength) + computeTopRefinements(maxLength); + // System.out.println(topRefinements); + refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone(); + // refinements = copyTopRefinements(maxLength); + // refinements = topRefinementsCumulative.get(maxLength); + + } else if (concept instanceof Nothing) { + // return new HashSet<Concept>(); + } else if (concept instanceof ValueRestriction) { + // value restrictions cannot be further refined + } else if (concept instanceof NamedClass) { + // Erkenntnisse aus Benchmarks: dieser Teil wird sehr häufig aufgerufen, + // allerdings lässt er sich kaum weiter verbessern (selbst ohne klonen + // der Konzepte im DIG-Reasoner, was durch das entfernen von Bottom notwendig + // ist und außerdem sicherer vor zukünftigen Bugs, wird es nicht wesentlich + // schneller) + + // beachte: die Funktion gibt bereits nur nicht-äquivalente Konzepte zurück + // TODO: der Cast auf SortedSet ist nur ein Hack und muss später geeignet + // behandelt werden + refinements = rs.getMoreSpecialConcepts(concept); + // refinements.addAll(learningProblem.getReasoningService().getMoreSpecialConcepts(concept)); + + // Bottom rausschmeißen (nicht im Operator vorgesehen) + // Iterator<Concept> it = refinements.iterator(); + // while(it.hasNext()) { + // Concept c = it.next(); + // if(c instanceof Bottom) + // it.remove(); + // } + // geht jetzt auch schneller durch conceptComparator + refinements.remove(new Nothing()); + + // negiertes atomares Konzept + } else if (concept instanceof Negation && concept.getChild(0) instanceof NamedClass) { + + tmp = rs.getMoreGeneralConcepts(concept.getChild(0)); + + //Iterator<Concept> it = tmp.iterator(); + //while(it.hasNext()) { + // Concept c = it.next(); + // if(c instanceof Top) + // it.remove(); + //} + + // tmp.remove(new Top()); + + for(Description c : tmp) { + if(!(c instanceof Thing)) + refinements.add(new Negation(c)); + } + + } else if (concept instanceof Intersection) { + + // eines der Elemente kann verfeinert werden + for(Description child : concept.getChildren()) { + + // Refinement für das Kind ausführen + // System.out.println("child: " + child); + // wenn man von maximaler Länge die Länge des Konzepts außer dem aktuell + // betrachteten Element abzieht, dann bekommt man neue maxLength + tmp = refine(child, maxLength - concept.getLength()+child.getLength(),null); + + // neue MultiConjunction konstruieren + for(Description c : tmp) { + // TODO: müssen auch alle Konzepte geklont werden?? + // hier wird nur eine neue Liste erstellt + // => eigentlich muss nicht geklont werden (d.h. deep copy) da + // die Konzepte nicht verändert werden während des Algorithmus + // => es muss geklont werden, da die top refinements nicht verändert + // werden dürfen + // List<Concept> newChildren = new LinkedList<Concept>(concept.getChildren()); + // TODO: Class Cast ist nur ein Hack + List<Description> newChildren = (List<Description>)((LinkedList)concept.getChildren()).clone(); + // es muss genau die vorherige Reihenfolge erhalten bleiben + // (zumindest bis die Normalform definiert ist) + // int index = newChildren.indexOf(child); + // newChildren.add(index, c); + // newChildren.remove(child); + // MultiConjunction mc = new MultiConjunction(newChildren); + + // Index muss jetzt nich mehr erhalten bleiben, da ohnehin + // neu sortiert wird + newChildren.add(c); + newChildren.remove(child); + Intersection mc = new Intersection(newChildren); + + // sicherstellten, dass Konzept in negation normal form ist + ConceptTransformation.cleanConceptNonRecursive(mc); + ConceptTransformation.transformToOrderedNegationNormalFormNonRecursive(mc, conceptComparator); + + refinements.add(mc); + } + + } + + } else if (concept instanceof Union) { + // eines der Elemente kann verfeinert werden + for(Description child : concept.getChildren()) { + + // Refinement für das Kind ausführen + // tmp = refine(child); + tmp = refine(child, maxLength - concept.getLength()+child.getLength(),null); + + + + // neue MultiConjunction konstruieren + for(Description c : tmp) { + List<Description> newChildren = new LinkedList<Description>(concept.getChildren()); + // es muss genau die vorherige Reihenfolge erhalten bleiben + // (zumindest bis die Normalform definiert ist) + // int index = newChildren.indexOf(child); + // newChildren.add(index, c); + newChildren.remove(child); + newChildren.add(c); + Union md = new Union(newChildren); + + // sicherstellten, dass Konzept in negation normal form ist + // ConceptTransformation.cleanConcept(md); // nicht notwendig, da kein Element einer + // Disjunktion auf eine Disjunktion abgebildet wird (nur Top und das ist nie + // in einer Disjunktion) + ConceptTransformation.transformToOrderedNegationNormalFormNonRecursive(md, conceptComparator); + + + refinements.add(md); + } + + + } + + } else if (concept instanceof ObjectSomeRestriction) { + ObjectPropertyExpression role = ((ObjectQuantorRestriction)concept).getRole(); + + // rule 1: EXISTS r.D => EXISTS r.E + tmp = refine(concept.getChild(0), maxLength-2, null); + + for(Description c : tmp) { + refinements.add(new ObjectSomeRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); + } + + // rule 2: EXISTS r.D => EXISTS s.D or EXISTS r^-1.D => EXISTS s^-1.D + // currently inverse roles are not supported + ObjectProperty ar = (ObjectProperty) role; + Set<ObjectProperty> moreSpecialRoles = rs.getMoreSpecialRoles(ar); + for(ObjectProperty moreSpecialRole : moreSpecialRoles) { + refinements.add(new ObjectSomeRestriction(moreSpecialRole, concept.getChild(0))); + } + + } else if (concept instanceof ObjectAllRestriction) { + ObjectPropertyExpression role = ((ObjectQuantorRestriction)concept).getRole(); + + // rule 1: ALL r.D => ALL r.E + tmp = refine(concept.getChild(0), maxLength-2, null); + + for(Description c : tmp) { + refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),c)); + } + + // rule 2: ALL r.D => ALL r.BOTTOM if D is a most specific atomic concept + // falls es keine spezielleren atomaren Konzepte gibt, dann wird + // bottom angehangen => nur wenn es ein atomares Konzept (insbesondere != bottom) + // ist + // if(tmp.size()==0) { + if(concept.getChild(0) instanceof NamedClass && tmp.size()==0) { + refinements.add(new ObjectAllRestriction(((ObjectQuantorRestriction)concept).getRole(),new Nothing())); + } + + // rule 3: ALL r.D => ALL s.D or ALL r^-1.D => ALL s^-1.D + // currently inverse roles are not supported + ObjectProperty ar = (ObjectProperty) role; + Set<ObjectProperty> moreSpecialRoles = rs.getMoreSpecialRoles(ar); + for(ObjectProperty moreSpecialRole : moreSpecialRoles) { + refinements.add(new ObjectAllRestriction(moreSpecialRole, concept.getChild(0))); + } + + } + + // falls Konzept ungleich Bottom oder Top, dann kann ein Refinement von Top + // angehangen werden + if(concept instanceof Union || concept instanceof NamedClass || + concept instanceof Negation || concept instanceof ObjectQuantorRestriction + || concept instanceof ValueRestriction) { + // long someTimeNsStart = System.nanoTime(); + // someCount++; + // Refinement von Top anhängen + int topRefLength = maxLength - concept.getLength() - 1; //-1 wegen zusätzlichem UND + // es könnte passieren, das wir hier neue Refinements von Top berechnen müssen + if(topRefLength > topRefinementsLength) + computeTopRefinements(topRefLength); + if(topRefLength>0) { + // Set<Concept> topRefs = copyTopRefinements(topRefLength); + Set<Description> topRefs = topRefinementsCumulative.get(topRefLength); + for(Description c : topRefs) { + boolean skip = false; + + // falls Refinement von der Form ALL r ist, dann prüfen, ob + // ALL r nicht bereits vorkommt + if(applyAllFilter) { + if(c instanceof ObjectAllRestriction) { + for(Description child : concept.getChildren()) { + if(child instanceof ObjectAllRestriction) { + ObjectPropertyExpression r1 = ((ObjectAllRestriction)c).getRole(); + ObjectPropertyExpression r2 = ((ObjectAllRestriction)child).getRole(); + if(r1.toString().equals(r2.toString())) + skip = true; + } + } + } + } + + if(!skip) { + // MultiConjunction md = new MultiConjunction(concept.getChildren()); + Intersection mc = new Intersection(); + mc.addChild(concept); + mc.addChild(c); + + // Negationsnormalform herstellen + ConceptTransformation.cleanConceptNonRecursive(mc); + ConceptTransformation.transformToOrderedNegationNormalFormNonRecursive(mc, conceptComparator); + + refinements.add(mc); + } + } + } + // someTimeNs += System.nanoTime() - someTimeNsStart; + } + + + + // Refinements werden jetzt noch bereinigt, d.h. Verschachtelungen von Konjunktionen + // werden entfernt; es wird eine neue Menge erzeugt, da die Transformationen die + // Ordnung des Konzepts ändern könnten + // TODO: eventuell geht das noch effizienter, da die meisten Refinement-Regeln Refinements + // von Child-Konzepten sind, die bereits geordnet sind, d.h. man könnte dort eventuell + // gleich absichern, dass alle neu hinzugefügten Refinements in geordneter Negationsnormalform + // sind + /* + SortedSet<Concept> returnSet = new TreeSet<Concept>(conceptComparator); + for(Concept c : refinements) { + ConceptTransformation.cleanConcept(c); + ConceptTransformation.transformToOrderedNegationNormalForm(c, conceptComparator); + returnSet.add(c); + } + + return returnSet; + */ + // TODO: obiger Code kann noch nicht gelöscht werden (anderes Ergebnis); warum? + // => erstmal so implementieren, dass obiger Code nicht mehr gebraucht wird und + // im zweiten Schritt dann auf die nicht-rekursiven Methoden umsteigen + return refinements; + } + + + // TODO: Methode kann später entfernt werden, es muss nur + // sichergestellt werden, dass die refine-Methode an den + // kumulativen Top-Refinements nichts ändert + @SuppressWarnings("unused") + private SortedSet<Description> copyTopRefinements(int maxLength) { + // return topRefinementsCumulative.get(maxLength); + SortedSet<Description> ret = new TreeSet<Description>(conceptComparator); + for(Description c : topRefinementsCumulative.get(maxLength)) + ret.add(c); + return ret; + } + + + // TODO: später private + public void computeTopRefinements(int maxLength) { + long topComputationTimeStartNs = System.nanoTime(); + + // M erweiteren + computeM(maxLength); + + // berechnen aller möglichen Kombinationen für Disjunktion, + for(int i = topRefinementsLength+1; i <= maxLength; i++) { + combos.put(i,getCombos(i)); + topRefinements.put(i, new TreeSet<Description>(conceptComparator)); + // topRefinements.put(i, new HashSet<Concept>()); + + for(List<Integer> combo : combos.get(i)) { + /* + // für eine Kombo alle Konzeptkombinationen berechnen + Set<Set<Concept>> baseSet = new HashSet<Set<Concept>>(); + // boolean firstNonEmptyNumber = true; + for(Integer j : combo.getNumbers()) { + // initialisiert wird mit der passenden Menge m + //if(firstNonEmptyNumber || ) + // baseSet.add(m.get(j)); + // else { + baseSet = incCrossProduct(baseSet,m.get(j)); + //} + } + + // Disjunktionen erzeugen und hinzufügen + for(Set<Concept> children : baseSet) { + if(children.size() == 1) { + Iterator<Concept> it = children.iterator(); + Concept c = it.next(); + topRefinements.get(i).add(c); + } else { + topRefinements.get(i).add(new MultiDisjunction(children)); + } + } + */ + + /* neue Implementierung */ + + // Kombination besteht aus nur einer Zahl => einfach M benutzen + // if(combo.getNumbers().size()==1) { + if(combo.size()==1) { + topRefinements.get(i).addAll(m.get(i)); + // Kombination besteht aus mehreren Zahlen => Disjunktion erzeugen + } else { + Set<Union> baseSet = new HashSet<Union>(); + for(Integer j : combo) { // combo.getNumbers()) { + baseSet = incCrossProduct2(baseSet, m.get(j)); + } + + // Umwandlung aller Konzepte in Negationsnormalform + for(Description concept : baseSet) { + ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); + } + + if(applyExistsFilter) { + Iterator<Union> it = baseSet.iterator(); + while(it.hasNext()) { + Union md = it.next(); + boolean remove = false; + // falls Exists r für gleiche Rolle zweimal vorkommt, + // dann rausschmeißen + // Map<AtomicRole,Boolean> roleOccured = new HashMap<AtomicRole,Boolean>(); + Set<String> roles = new TreeSet<String>(); + for(Description c : md.getChildren()) { + if(c instanceof ObjectSomeRestriction) { + String role = ((ObjectSomeRestriction)c).getRole().getName(); + boolean roleExists = !roles.add(role); + // falls Rolle schon vorkommt, dann kann ganzes + // Refinement ignoriert werden (man könnte dann auch + // gleich abbrechen, aber das hat nur minimalste + // Auswirkungen auf Effizienz) + if(roleExists) + remove = true; + } + } + if(remove) + it.remove(); + + } + } + + topRefinements.get(i).addAll(baseSet); + } + } + + // neu berechnete Refinements kumulieren, damit sie schneller abgefragt werden können + // computeCumulativeTopRefinements(i); + TreeSet<Description> cumulativeRefinements = new TreeSet<Description>(conceptComparator); + // Set<Concept> cumulativeRefinements = new HashSet<Concept>(); + for(int j=1; j<=i; j++) { + cumulativeRefinements.addAll(topRefinements.get(j)); + } + topRefinementsCumulative.put(i, cumulativeRefinements); + } + + // neue Maximallänge eintragen + topRefinementsLength = maxLength; + + topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; + } + + // computation of the set M + private void computeM(int maxLength) { + long mComputationTimeStartNs = System.nanoTime(); + // System.out.println("compute M from " + (topRefinementsLength+1) + " up to " + maxLength); + + // initialise all not yet initialised lengths + // (avoids null pointers in some cases) + for(int i=topRefinementsLength+1; i<=maxLength; i++) { + m.put(i, new TreeSet<Description>(conceptComparator)); + } + + // Berechnung der Basiskonzepte in M + // TODO: Spezialfälle, dass zwischen Top und Bottom nichts liegt behandeln + if(topRefinementsLength==0 && maxLength>0) { + // Konzepte der Länge 1 = alle Konzepte, die in der Subsumptionhierarchie unter Top liegen + Set<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); + m.put(1,m1); + } + + if(topRefinementsLength<2 && maxLength>1) { + // Konzepte der Länge 2 = Negation aller Konzepte, die über Bottom liegen + if(useNegation) { + Set<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); + Set<Description> m2 = new TreeSet<Description>(conceptComparator); + for(Description c : m2tmp) { + m2.add(new Negation(c)); + } + m.put(2,m2); + } + } + + if(topRefinementsLength<3 && maxLength>2) { + // Konzepte der Länge 3: EXISTS r.TOP + Set<Description> m3 = new TreeSet<Description>(conceptComparator); + if(useExistsConstructor) { + // previous operator: uses all roles + // for(AtomicRole r : Config.Refinement.allowedRoles) { + // m3.add(new Exists(r, new Top())); + //} + // new operator: only uses most general roles + for(ObjectProperty r : rs.getMostGeneralRoles()) { + m3.add(new ObjectSomeRestriction(r, new Thing())); + } + + } + + // boolean datatypes, e.g. testPositive = true + if(useBooleanDatatypes) { + Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + for(DatatypeProperty dp : booleanDPs) { + m3.add(new BooleanValueRestriction(dp,true)); + m3.add(new BooleanValueRestriction(dp,false)); + } + } + + m.put(3,m3); + } + + if(maxLength>2) { + if(useAllConstructor) { + // Konzepte, die mit ALL r starten + // alle existierenden Konzepte durchgehen, die maximal 2 k�rzer als + // die maximale L�nge sind + // topRefinementsLength - 1, damit Konzepte der Länge mindestens + // topRefinementsLength + 1 erzeugt werden (ALL r) + for(int i=topRefinementsLength-1; i<=maxLength-2; i++) { + // i muss natürlich mindestens 1 sein + if(i>=1) { + + // alle Konzepte durchgehen + for(Description c : m.get(i)) { + // Fall wird jetzt weiter oben schon abgehandelt + // if(!m.containsKey(i+2)) + // m.put(i+2, new TreeSet<Concept>(conceptComparator)); + + // previous operator: uses all roles + // for(AtomicRole r : Config.Refinement.allowedRoles) { + // Mehrfacheinf�gen ist bei einer Menge kein Problem + // m.get(i+2).add(new All(r,c)); + // } + + for(ObjectProperty r : rs.getMostGeneralRoles()) { + m.get(i+2).add(new ObjectAllRestriction(r,c)); + } + } + } + } + } + } + + mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; + } + + + public static void summen(int zahl, int max, String bisher, int recDepth) + { + for(int j=0; j<recDepth; j++) + System.out.print(" "); + System.out.println("f("+zahl+","+max+",\""+bisher+"\")"); + + for (int i = Math.min(zahl, max); i >= 1; i--) + { + + String jetzt = bisher + i; + + if (zahl - i > 1) + { + jetzt += " + "; + // i wird hinzugefügt, d.h. + // - es muss nur noch zahl - i zerlegt werden + // - es darf keine größere Zahl als i mehr vorkommen + // (dadurch gehen keine Kombinationen verloren) + summen(zahl - i -1 , i, jetzt, recDepth+1); + } + // Fall zahl == i, d.h. es muss nicht weiter zerlegt werden + else if(zahl - i == 0){ + for(int j=0; j<recDepth; j++) + System.out.print(" "); + System.out.println(jetzt); + } + // durch die -1 Abzug für jedes Zwischenzeichen gibt es auch Fälle, in denen + // keine Lösung entsteht (zahl-i==1) + + } + } + + @SuppressWarnings("unchecked") + private LinkedList<Integer> cloneList(LinkedList<Integer> list) { + return (LinkedList<Integer>) list.clone(); + } + + /** + * + * Dadurch das max das Maximum der vorkommenden Zahl regelt, kommen + * keine doppelten Kombinationen vor. + * + * TODO: Implementierung mit Speicherung in Datenstruktur statt + * direkter Ausgabe; IntegerCombo wird hier gar nicht benötigt, da + * alle Elemente bereits in richtiger Reihenfolge vorliegen und + * es keine doppelten Nennungen gibt + * + * @param zahl Zu zerlegende Zahl. + * @param max Maximal in Summenzerlegung vorkommende Zahl. + * @param bisher + */ + private void zerlege(int zahl, int max, LinkedList<Integer> bisher, List<List<Integer>> combosTmp) { + + for (int i = Math.min(zahl, max); i >= 1; i--) + { + + LinkedList<Integer> newBisher = null; + // für i==0 wird aus Effizienzgründen die bisherige Liste genommen + if(i==0) { + newBisher = bisher; + newBisher.add(i); + // für zahl - i == 1 muss gar keine Liste erstellt werden, da dann keine + // Zerlegung mehr möglich ist + } else if(zahl - i != 1) { + newBisher = cloneList(bisher); + newBisher.add(i); + } + + + if (zahl - i > 1) + { + // i wird hinzugefügt, d.h. + // - es muss nur noch zahl - i - 1 zerlegt werden (-1 wegen OR-Symbol) + // - es darf keine größere Zahl als i mehr vorkommen + // (dadurch gehen keine Kombinationen verloren) + zerlege(zahl - i - 1, i, newBisher,combosTmp); + } + // Fall zahl == i, d.h. es muss nicht weiter zerlegt werden + else if(zahl - i == 0){ + combosTmp.add(newBisher); + } + + + } + + // numbers.add(bisher); + } + + // auf Notebook: Länge 70 in 17 Sekunden, Länge 50 in 800ms, Länge 30 in 15ms + // http://88.198.173.90/tud/forum/messages?topic=304392 + public List<List<Integer>> getCombos(int length) { + LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>(); + zerlege(length, length, new LinkedList<Integer>(), combosTmp); + return combosTmp; + } + + // neue Implementierung, die nicht mehr zur incompleteness führen soll, + // da die Konzepte in einer MultiDisjunction als Liste gespeichert werden + private Set<Union> incCrossProduct2(Set<Union> baseSet, Set<Description> newSet) { + Set<Union> retSet = new HashSet<Union>(); + + if(baseSet.isEmpty()) { + for(Description c : newSet) { + Union md = new Union(); + md.addChild(c); + retSet.add(md); + } + return retSet; + } + + for(Union md : baseSet) { + for(Description c : newSet) { + Union mdNew = new Union(md.getChildren()); + mdNew.addChild(c); + retSet.add(mdNew); + } + } + + return retSet; + } + + // incremental cross product + // es müssen Listen statt Sets verwendet werden + @SuppressWarnings({"unused"}) + private Set<Set<Description>> incCrossProduct(Set<Set<Description>> baseSet, Set<Description> newSet) { + Set<Set<Description>> retSet = new HashSet<Set<Description>>(); + + // falls erste Menge leer ist, dann wird Menge mit jeweils Singletons aus der + // zweiten Menge zurückgegeben => das müsste dem Fall entsprechen, dass das + // baseSet nur die leere Menge enthält + if(baseSet.isEmpty()) { + for(Description c : newSet) { + Set<Description> singleton = new HashSet<Description>(); + singleton.add(c); + retSet.add(singleton); + } + // retSet.add(newSet); + return retSet; + } + + for(Set<Description> set : baseSet) { + for(Description c : newSet) { + // neues Konzept zu alter Konzeptmenge hinzufügen, indem altes + // Konzept kopiert und ergänzt wird + // beachte: dadurch, dass die Konzepte nach ihrem Hash eingefügt werden, + // ist schon eine Ordnung vorgegeben und es entfallen viele Mengen + // z.B. ist {male,female} = {female,male} + // TODO: das ist allerdings auch gefährlich, denn es gilt auch + // {male,male,female} = {male,female} d.h. es entfallen auch gewünschte + // Lösungen! (Es könnte z.B. sein, dass die Lösung eine Disjunktion von + // 3 atomaren Konzepten ist, die nur über male erreichbar sind.) D.h. diese + // Implementierung führt zur incompleteness des Operators. + Set<Description> newConcept = new HashSet<Description>(set); + newConcept.add(c); + retSet.add(newConcept); + } + } + return retSet; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 11:37:54
|
Revision: 649 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=649&view=rev Author: jenslehmann Date: 2008-02-27 03:37:51 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Subclipse Bug I Modified Paths: -------------- 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/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/operators/PsiDown.java trunk/src/dl-learner/org/dllearner/operators/PsiUp.java trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/operators/RhoDown.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-02-27 11:37:51 UTC (rev 649) @@ -9,8 +9,8 @@ import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.refinementoperators.PsiDown; -import org.dllearner.refinementoperators.PsiUp; +import org.dllearner.operators.PsiDown; +import org.dllearner.operators.PsiUp; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 11:37:51 UTC (rev 649) @@ -43,7 +43,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.refinementoperators.RhoDown; +import org.dllearner.operators.RhoDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 11:37:51 UTC (rev 649) @@ -42,7 +42,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.refinementoperators.RhoDown; +import org.dllearner.operators.RhoDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 11:37:51 UTC (rev 649) @@ -32,7 +32,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.refinementoperators.RhoDown; +import org.dllearner.operators.RhoDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; Modified: trunk/src/dl-learner/org/dllearner/operators/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/PsiDown.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/operators/PsiDown.java 2008-02-27 11:37:51 UTC (rev 649) @@ -1,4 +1,4 @@ -package org.dllearner.refinementoperators; +package org.dllearner.operators; import java.util.HashSet; import java.util.Iterator; Modified: trunk/src/dl-learner/org/dllearner/operators/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/PsiUp.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/operators/PsiUp.java 2008-02-27 11:37:51 UTC (rev 649) @@ -1,4 +1,4 @@ -package org.dllearner.refinementoperators; +package org.dllearner.operators; import java.util.HashSet; import java.util.Iterator; Modified: trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java 2008-02-27 11:37:51 UTC (rev 649) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.refinementoperators; +package org.dllearner.operators; import java.util.List; import java.util.Set; Modified: trunk/src/dl-learner/org/dllearner/operators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/RhoDown.java 2008-02-27 11:27:52 UTC (rev 648) +++ trunk/src/dl-learner/org/dllearner/operators/RhoDown.java 2008-02-27 11:37:51 UTC (rev 649) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.refinementoperators; +package org.dllearner.operators; import java.util.HashMap; import java.util.HashSet; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 11:39:23
|
Revision: 650 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=650&view=rev Author: jenslehmann Date: 2008-02-27 03:39:21 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Subclipse Bug II Modified Paths: -------------- 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/refinement/ROLearner.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 Added Paths: ----------- trunk/src/dl-learner/org/dllearner/refinementoperators/ Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/operators/ Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-02-27 11:39:21 UTC (rev 650) @@ -9,8 +9,8 @@ import org.dllearner.core.Score; import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.operators.PsiDown; -import org.dllearner.operators.PsiUp; +import org.dllearner.refinementoperators.PsiDown; +import org.dllearner.refinementoperators.PsiUp; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-02-27 11:39:21 UTC (rev 650) @@ -43,7 +43,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.operators.RhoDown; +import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-02-27 11:39:21 UTC (rev 650) @@ -42,7 +42,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.operators.RhoDown; +import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-27 11:39:21 UTC (rev 650) @@ -32,7 +32,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.operators.RhoDown; +import org.dllearner.refinementoperators.RhoDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; Copied: trunk/src/dl-learner/org/dllearner/refinementoperators (from rev 649, trunk/src/dl-learner/org/dllearner/operators) Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/PsiDown.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-02-27 11:39:21 UTC (rev 650) @@ -1,4 +1,4 @@ -package org.dllearner.operators; +package org.dllearner.refinementoperators; import java.util.HashSet; import java.util.Iterator; Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/PsiUp.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-02-27 11:39:21 UTC (rev 650) @@ -1,4 +1,4 @@ -package org.dllearner.operators; +package org.dllearner.refinementoperators; import java.util.HashSet; import java.util.Iterator; Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/RhoDRDown.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-02-27 11:39:21 UTC (rev 650) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.operators; +package org.dllearner.refinementoperators; import java.util.List; import java.util.Set; Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/operators/RhoDown.java 2008-02-27 11:37:51 UTC (rev 649) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-02-27 11:39:21 UTC (rev 650) @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package org.dllearner.operators; +package org.dllearner.refinementoperators; import java.util.HashMap; import java.util.HashSet; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 15:08:28
|
Revision: 655 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=655&view=rev Author: jenslehmann Date: 2008-02-27 07:08:19 -0800 (Wed, 27 Feb 2008) Log Message: ----------- - preliminary datatype domain/range reasoning (bug in OWL API detected) - new refinement operator (and unit tests for it) started Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.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/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-27 15:08:19 UTC (rev 655) @@ -27,6 +27,7 @@ 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.NamedClass; import org.dllearner.core.owl.Description; @@ -446,6 +447,42 @@ 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(); } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-02-27 15:08:19 UTC (rev 655) @@ -173,7 +173,9 @@ kbString += "OPDOMAIN(" + getURI2("hasBond") + ") = " + getURI2("Compound") + ".\n"; kbString += "OPRANGE(" + getURI2("hasBond") + ") = " + getURI2("Bond") + ".\n"; kbString += "OPDOMAIN(" + getURI2("inBond") + ") = " + getURI2("Bond") + ".\n"; - kbString += "OPRANGE(" + getURI2("inBond") + ") = " + getURI2("Atom") + ".\n"; + kbString += "OPRANGE(" + getURI2("inBond") + ") = " + getURI2("Atom") + ".\n"; + kbString += "OPDOMAIN(" + getURI2("hasStructure") + ") = " + getURI2("Compound") + ".\n"; + kbString += "OPRANGE(" + getURI2("hasStructure") + ") = " + getURI2("Structure") + ".\n"; KB kb2 = KBParser.parseKBFile(kbString); kb.addKB(kb2); Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-27 15:08:19 UTC (rev 655) @@ -408,4 +408,19 @@ return rc.getPrefixes(); } + @Override + public Description getDomain(ObjectProperty objectProperty) { + return rc.getDomain(objectProperty); + } + + @Override + public Description getDomain(DatatypeProperty datatypeProperty) { + return rc.getDomain(datatypeProperty); + } + + @Override + public Description getRange(ObjectProperty objectProperty) { + return rc.getRange(objectProperty); + } + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-27 15:08:19 UTC (rev 655) @@ -209,8 +209,8 @@ OWLOntologyFormat format = manager.getOntologyFormat(ontology); if(format instanceof NamespaceOWLOntologyFormat) { prefixes = ((NamespaceOWLOntologyFormat)format).getNamespacesByPrefixMap(); - prefixes.remove(""); baseURI = prefixes.get(""); + prefixes.remove(""); } } catch (OWLOntologyCreationException e) { @@ -541,16 +541,51 @@ // instead of only one description (probably there can be several // domain axiom for one property and the inner set is a conjunction // of descriptions (?)) - OWLDescription d = reasoner.getDomains(prop).iterator().next().iterator().next(); -// OWLAPIDescriptionConvertVisitor.getOWLDescription(d); + // Answer: this function is just horribly broken in OWL API + Set<Set<OWLDescription>> set = reasoner.getDomains(prop); + if(set.size()==0) + return new Thing(); + OWLClass oc = (OWLClass) set.iterator().next(); + return new NamedClass(oc.getURI().toString()); } catch (OWLReasonerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new Error(e); } - return null; } @Override + public Description getDomain(DatatypeProperty datatypeProperty) { + OWLDataProperty prop = getOWLAPIDescription(datatypeProperty); + try { + // TODO: look up why OWL API return a two dimensional set here + // instead of only one description (probably there can be several + // domain axiom for one property and the inner set is a conjunction + // of descriptions (?)) + // Answer: this function is just horribly broken in OWL API + Set<Set<OWLDescription>> set = reasoner.getDomains(prop); + if(set.size()==0) + return new Thing(); + OWLClass oc = (OWLClass) set.iterator().next(); + return new NamedClass(oc.getURI().toString()); + } catch (OWLReasonerException e) { + throw new Error(e); + } + } + + @Override + public Description getRange(ObjectProperty objectProperty) { + OWLObjectProperty prop = getOWLAPIDescription(objectProperty); + try { + Set<OWLDescription> set = reasoner.getRanges(prop); + if(set.size()==0) + return new Thing(); + OWLClass oc = (OWLClass) set.iterator().next(); + return new NamedClass(oc.getURI().toString()); + } catch (OWLReasonerException e) { + throw new Error(e); + } + } + + @Override public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) { OWLObjectProperty prop = getOWLAPIDescription(atomicRole); Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-02-27 15:08:19 UTC (rev 655) @@ -19,11 +19,21 @@ */ package org.dllearner.refinementoperators; +import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; import org.dllearner.algorithms.refinement.RefinementOperator; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.core.owl.Thing; /** * A downward refinement operator, which makes use of domains @@ -38,6 +48,31 @@ */ public class RhoDRDown implements RefinementOperator { + private ReasoningService rs; + + // hierarchies + private SubsumptionHierarchy subHierarchy; + + // domains and ranges + private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>(); + private Map<DatatypeProperty,Description> dpDomains = new TreeMap<DatatypeProperty,Description>(); + private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>(); + + public RhoDRDown(ReasoningService rs) { + this.rs = rs; + subHierarchy = rs.getSubsumptionHierarchy(); + + // query reasoner for domains and ranges + // (because they are used often in the operator) + for(ObjectProperty op : rs.getAtomicRoles()) { + opDomains.put(op, rs.getDomain(op)); + opRanges.put(op, rs.getRange(op)); + } + for(DatatypeProperty dp : rs.getDatatypeProperties()) { + dpDomains.put(dp, rs.getDomain(dp)); + } + } + /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description) */ @@ -48,10 +83,31 @@ /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) */ - public Set<Description> refine(Description concept, int maxLength, + public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements) { + return refine(description, maxLength, knownRefinements, new Thing()); + } + + public Set<Description> refine(Description description, int maxLength, + List<Description> knownRefinements, Description currDomain) { + // TODO: check whether using list or set makes more sense + // here; and whether HashSet or TreeSet should be used + Set<Description> refinements = new HashSet<Description>(); - return null; + // .. do most general rules here ... + // (easier because it may be possible to add return + // statements instead of going through the complete + // function) + + if(description instanceof Thing) { + refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); + } else if(description instanceof Nothing) { + // cannot be further refined + } else if(description instanceof NamedClass) { + refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); + } + + return refinements; } - + } Modified: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-27 15:08:19 UTC (rev 655) @@ -1,6 +1,7 @@ package org.dllearner.test; import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; import org.semanticweb.owl.model.*; import org.semanticweb.owl.util.SimpleURIMapper; @@ -48,6 +49,26 @@ AddAxiom addAxiom2 = new AddAxiom(ontology, axiom2); manager.applyChange(addAxiom2); + // add property p with domain c + OWLObjectProperty p = factory.getOWLObjectProperty(URI.create(ontologyURI + "#p")); + OWLAxiom axiom3 = factory.getOWLObjectPropertyDomainAxiom(p, c); + AddAxiom addAxiom3 = new AddAxiom(ontology, axiom3); + manager.applyChange(addAxiom3); + + Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); + ontologies.add(ontology); + + OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); + reasoner.loadOntologies(ontologies); + + // class cast exception + Set<Set<OWLDescription>> test = reasoner.getDomains(p); + OWLClass oc = (OWLClass) test.iterator().next(); + System.out.println(oc); +// for(Set<OWLDescription> test2 : test) { +// System.out.println(test2); +// } + // save ontology manager.saveOntology(ontology); } Modified: trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2008-02-27 15:08:19 UTC (rev 655) @@ -47,7 +47,8 @@ logger.setLevel(Level.INFO); JUnitCore.main("org.dllearner.test.junit.ComponentTests", - "org.dllearner.test.junit.ReasonerTests"); + "org.dllearner.test.junit.ReasonerTests", + "org.dllearner.test.junit.RefinementOperatorTests"); } } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-02-27 14:10:02 UTC (rev 654) +++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-02-27 15:08:19 UTC (rev 655) @@ -48,7 +48,7 @@ private static Logger logger = Logger.getLogger(ReasonerTests.class); - private KB getSimpleKnowledgeBase() { + public KB getSimpleKnowledgeBase() { String kb = "person SUB TOP."; kb += "man SUB person."; kb += "man SUB male."; Added: trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/RefinementOperatorTests.java 2008-02-27 15:08:19 UTC (rev 655) @@ -0,0 +1,77 @@ +/** + * 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.assertTrue; + +import java.io.File; +import java.util.Set; + +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Description; +import org.dllearner.kb.OWLFile; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.dllearner.refinementoperators.RhoDRDown; +import org.junit.Test; + +/** + * A suite of JUnit tests related to refinement operators. + * + * @author Jens Lehmann + * + */ +public class RefinementOperatorTests { + + private String baseURI; + + @Test + public void rhoDRDownTest() { + try { + String file = "examples/carcinogenesis/pte.owl"; + ComponentManager cm = ComponentManager.getInstance(); + KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); + cm.applyConfigEntry(ks, "url", new File(file).toURI().toString()); + ks.init(); + ReasonerComponent rc = cm.reasoner(OWLAPIReasoner.class, ks); + rc.init(); + baseURI = rc.getBaseURI(); + ReasoningService rs = cm.reasoningService(rc); + RhoDRDown op = new RhoDRDown(rs); + Description concept = KBParser.parseConcept(uri("Compound")); + Set<Description> results = op.refine(concept, 4, null); + System.out.println(results); + assertTrue(results.size()==4); + } catch(ComponentInitException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } + } + + private String uri(String name) { + return "\""+baseURI+name+"\""; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-27 19:04:38
|
Revision: 659 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=659&view=rev Author: jenslehmann Date: 2008-02-27 11:03:22 -0800 (Wed, 27 Feb 2008) Log Message: ----------- extracted math operations in downward refinement operator to separate class such that they can be used by all operators Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java Added: trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java 2008-02-27 19:03:22 UTC (rev 659) @@ -0,0 +1,151 @@ +/** + * 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.refinementoperators; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Union; + +/** + * Math operations related to refinement operators. + * + * @author Jens Lehmann + * + */ +public class MathOperations { + + /** + * This function implements the getCombos method. Through the + * use of the upper limit, it is guaranteed that it + * will never return doublettes, so no special handling for + * them is necessary. + * + * @see #getCombos(int) + * @param number Number to decompose. + * @param upperLimit Maximum number allowed in sum. + * @param bisher Numbers created so far. + * @param combosTmp Temporary list of combinations (filled during run). + */ + private static void decompose(int number, int upperLimit, LinkedList<Integer> bisher, List<List<Integer>> combosTmp) { + + for (int i = Math.min(number, upperLimit); i >= 1; i--) + { + + LinkedList<Integer> newBisher = null; + // für i==0 wird aus Effizienzgründen die bisherige Liste genommen + if(i==0) { + newBisher = bisher; + newBisher.add(i); + // für zahl - i == 1 muss gar keine Liste erstellt werden, da dann keine + // Zerlegung mehr möglich ist + } else if(number - i != 1) { + newBisher = cloneList(bisher); + newBisher.add(i); + } + + + if (number - i > 1) + { + // i wird hinzugefügt, d.h. + // - es muss nur noch zahl - i - 1 zerlegt werden (-1 wegen OR-Symbol) + // - es darf keine größere Zahl als i mehr vorkommen + // (dadurch gehen keine Kombinationen verloren) + decompose(number - i - 1, i, newBisher,combosTmp); + } + // Fall zahl == i, d.h. es muss nicht weiter zerlegt werden + else if(number - i == 0){ + combosTmp.add(newBisher); + } + + + } + + // numbers.add(bisher); + } + + /** + * Given <code>number</code>, the functions returns all + * combinations of natural numbers plus the number count + * (which can be thought of as the number of interconnecting + * symbols between those numbers) adds up to <code>number</code>. + * + * It uses an efficient algorithm to achieve this, which can + * handle number=50 in less than a second and number=30 in + * about 10 milliseconds on an average PC. + * + * For illustrating the function, the return values of the first numbers + * are given: + * number = 1: [[1]] + * number = 2: [[2]] + * number = 3: [[3], [1, 1]] + * number = 4: [[4], [2, 1]] + * number = 5: [[5], [3, 1], [2, 2], [1, 1, 1]] + * number = 6: [[6], [4, 1], [3, 2], [2, 1, 1]] + * number = 7: [[7], [5, 1], [4, 2], [3, 3], [3, 1, 1], [2, 2, 1], [1, 1, 1, 1]] + * + * @param length + * @return + */ + public static List<List<Integer>> getCombos(int length) { + // on Notebook: length 70 in 17 seconds, length 50 in 800ms, length 30 in 15ms + LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>(); + decompose(length, length, new LinkedList<Integer>(), combosTmp); + return combosTmp; + } + + @SuppressWarnings("unchecked") + private static LinkedList<Integer> cloneList(LinkedList<Integer> list) { + return (LinkedList<Integer>) list.clone(); + } + + public static void main(String args[]) { + System.out.println(getCombos(7)); + } + + // neue Implementierung, die nicht mehr zur incompleteness führen soll, + // da die Konzepte in einer MultiDisjunction als Liste gespeichert werden + public static Set<Union> incCrossProduct(Set<Union> baseSet, Set<Description> newSet) { + Set<Union> retSet = new HashSet<Union>(); + + if(baseSet.isEmpty()) { + for(Description c : newSet) { + Union md = new Union(); + md.addChild(c); + retSet.add(md); + } + return retSet; + } + + for(Union md : baseSet) { + for(Description c : newSet) { + Union mdNew = new Union(md.getChildren()); + mdNew.addChild(c); + retSet.add(mdNew); + } + } + + return retSet; + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-02-27 15:59:18 UTC (rev 658) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-02-27 19:03:22 UTC (rev 659) @@ -19,21 +19,31 @@ */ package org.dllearner.refinementoperators; +import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; 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.ObjectProperty; +import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.SubsumptionHierarchy; import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.Union; +import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.ConceptTransformation; /** * A downward refinement operator, which makes use of domains @@ -58,6 +68,37 @@ private Map<DatatypeProperty,Description> dpDomains = new TreeMap<DatatypeProperty,Description>(); private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>(); + // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts + // bereits berechnet worden => entspricht der max. L�nge der Menge M + private int topRefinementsLength = 0; + + // die Menge M im Refinement-Operator indiziert nach ihrer L�nge + private Map<Integer,Set<Description>> m = new HashMap<Integer,Set<Description>>(); + + // Zerlegungen der Zahl n in Mengen + // Map<Integer,Set<IntegerCombo>> combos = new HashMap<Integer,Set<IntegerCombo>>(); + private Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); + // abspeichern von Kombinationen während diese rekursiv berechnet werden + // private List<List<Integer>> combosTmp; + + // Refinements des Top-Konzept indiziert nach Länge + private Map<Integer, TreeSet<Description>> topRefinements = new HashMap<Integer, TreeSet<Description>>(); + private Map<Integer, TreeSet<Description>> topRefinementsCumulative = new HashMap<Integer, TreeSet<Description>>(); + + // comparator für Konzepte + private ConceptComparator conceptComparator = new ConceptComparator(); + + // Statistik + private long mComputationTimeNs = 0; + private long topComputationTimeNs = 0; + +// private boolean applyAllFilter = true; + private boolean applyExistsFilter = true; + private boolean useAllConstructor = true; + private boolean useExistsConstructor = true; + private boolean useNegation = true; + private boolean useBooleanDatatypes = true; + public RhoDRDown(ReasoningService rs) { this.rs = rs; subHierarchy = rs.getSubsumptionHierarchy(); @@ -110,4 +151,176 @@ return refinements; } + // TODO: später private + public void computeTopRefinements(int maxLength) { + long topComputationTimeStartNs = System.nanoTime(); + + // M erweiteren + computeM(maxLength); + + // berechnen aller möglichen Kombinationen für Disjunktion, + for(int i = topRefinementsLength+1; i <= maxLength; i++) { + combos.put(i,MathOperations.getCombos(i)); + topRefinements.put(i, new TreeSet<Description>(conceptComparator)); + // topRefinements.put(i, new HashSet<Concept>()); + + for(List<Integer> combo : combos.get(i)) { + + // Kombination besteht aus nur einer Zahl => einfach M benutzen + // if(combo.getNumbers().size()==1) { + if(combo.size()==1) { + topRefinements.get(i).addAll(m.get(i)); + // Kombination besteht aus mehreren Zahlen => Disjunktion erzeugen + } else { + Set<Union> baseSet = new HashSet<Union>(); + for(Integer j : combo) { // combo.getNumbers()) { + baseSet = MathOperations.incCrossProduct(baseSet, m.get(j)); + } + + // Umwandlung aller Konzepte in Negationsnormalform + for(Description concept : baseSet) { + ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); + } + + if(applyExistsFilter) { + Iterator<Union> it = baseSet.iterator(); + while(it.hasNext()) { + Union md = it.next(); + boolean remove = false; + // falls Exists r für gleiche Rolle zweimal vorkommt, + // dann rausschmeißen + // Map<AtomicRole,Boolean> roleOccured = new HashMap<AtomicRole,Boolean>(); + Set<String> roles = new TreeSet<String>(); + for(Description c : md.getChildren()) { + if(c instanceof ObjectSomeRestriction) { + String role = ((ObjectSomeRestriction)c).getRole().getName(); + boolean roleExists = !roles.add(role); + // falls Rolle schon vorkommt, dann kann ganzes + // Refinement ignoriert werden (man könnte dann auch + // gleich abbrechen, aber das hat nur minimalste + // Auswirkungen auf Effizienz) + if(roleExists) + remove = true; + } + } + if(remove) + it.remove(); + + } + } + + topRefinements.get(i).addAll(baseSet); + } + } + + // neu berechnete Refinements kumulieren, damit sie schneller abgefragt werden können + // computeCumulativeTopRefinements(i); + TreeSet<Description> cumulativeRefinements = new TreeSet<Description>(conceptComparator); + // Set<Concept> cumulativeRefinements = new HashSet<Concept>(); + for(int j=1; j<=i; j++) { + cumulativeRefinements.addAll(topRefinements.get(j)); + } + topRefinementsCumulative.put(i, cumulativeRefinements); + } + + // neue Maximallänge eintragen + topRefinementsLength = maxLength; + + topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; + } + + // computation of the set M + private void computeM(int maxLength) { + long mComputationTimeStartNs = System.nanoTime(); + // System.out.println("compute M from " + (topRefinementsLength+1) + " up to " + maxLength); + + // initialise all not yet initialised lengths + // (avoids null pointers in some cases) + for(int i=topRefinementsLength+1; i<=maxLength; i++) { + m.put(i, new TreeSet<Description>(conceptComparator)); + } + + // Berechnung der Basiskonzepte in M + // TODO: Spezialfälle, dass zwischen Top und Bottom nichts liegt behandeln + if(topRefinementsLength==0 && maxLength>0) { + // Konzepte der Länge 1 = alle Konzepte, die in der Subsumptionhierarchie unter Top liegen + Set<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); + m.put(1,m1); + } + + if(topRefinementsLength<2 && maxLength>1) { + // Konzepte der Länge 2 = Negation aller Konzepte, die über Bottom liegen + if(useNegation) { + Set<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); + Set<Description> m2 = new TreeSet<Description>(conceptComparator); + for(Description c : m2tmp) { + m2.add(new Negation(c)); + } + m.put(2,m2); + } + } + + if(topRefinementsLength<3 && maxLength>2) { + // Konzepte der Länge 3: EXISTS r.TOP + Set<Description> m3 = new TreeSet<Description>(conceptComparator); + if(useExistsConstructor) { + // previous operator: uses all roles + // for(AtomicRole r : Config.Refinement.allowedRoles) { + // m3.add(new Exists(r, new Top())); + //} + // new operator: only uses most general roles + for(ObjectProperty r : rs.getMostGeneralRoles()) { + m3.add(new ObjectSomeRestriction(r, new Thing())); + } + + } + + // boolean datatypes, e.g. testPositive = true + if(useBooleanDatatypes) { + Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + for(DatatypeProperty dp : booleanDPs) { + m3.add(new BooleanValueRestriction(dp,true)); + m3.add(new BooleanValueRestriction(dp,false)); + } + } + + m.put(3,m3); + } + + if(maxLength>2) { + if(useAllConstructor) { + // Konzepte, die mit ALL r starten + // alle existierenden Konzepte durchgehen, die maximal 2 k�rzer als + // die maximale L�nge sind + // topRefinementsLength - 1, damit Konzepte der Länge mindestens + // topRefinementsLength + 1 erzeugt werden (ALL r) + for(int i=topRefinementsLength-1; i<=maxLength-2; i++) { + // i muss natürlich mindestens 1 sein + if(i>=1) { + + // alle Konzepte durchgehen + for(Description c : m.get(i)) { + // Fall wird jetzt weiter oben schon abgehandelt + // if(!m.containsKey(i+2)) + // m.put(i+2, new TreeSet<Concept>(conceptComparator)); + + // previous operator: uses all roles + // for(AtomicRole r : Config.Refinement.allowedRoles) { + // Mehrfacheinf�gen ist bei einer Menge kein Problem + // m.get(i+2).add(new All(r,c)); + // } + + for(ObjectProperty r : rs.getMostGeneralRoles()) { + m.get(i+2).add(new ObjectAllRestriction(r,c)); + } + } + } + } + } + } + + mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; + } + + } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-02-27 15:59:18 UTC (rev 658) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-02-27 19:03:22 UTC (rev 659) @@ -414,7 +414,7 @@ // berechnen aller möglichen Kombinationen für Disjunktion, for(int i = topRefinementsLength+1; i <= maxLength; i++) { - combos.put(i,getCombos(i)); + combos.put(i,MathOperations.getCombos(i)); topRefinements.put(i, new TreeSet<Description>(conceptComparator)); // topRefinements.put(i, new HashSet<Concept>()); @@ -454,7 +454,7 @@ } else { Set<Union> baseSet = new HashSet<Union>(); for(Integer j : combo) { // combo.getNumbers()) { - baseSet = incCrossProduct2(baseSet, m.get(j)); + baseSet = MathOperations.incCrossProduct(baseSet, m.get(j)); } // Umwandlung aller Konzepte in Negationsnormalform @@ -603,6 +603,7 @@ } + // wird nicht mehr verwendet public static void summen(int zahl, int max, String bisher, int recDepth) { for(int j=0; j<recDepth; j++) @@ -635,99 +636,14 @@ } } - @SuppressWarnings("unchecked") - private LinkedList<Integer> cloneList(LinkedList<Integer> list) { - return (LinkedList<Integer>) list.clone(); - } + - /** - * - * Dadurch das max das Maximum der vorkommenden Zahl regelt, kommen - * keine doppelten Kombinationen vor. - * - * TODO: Implementierung mit Speicherung in Datenstruktur statt - * direkter Ausgabe; IntegerCombo wird hier gar nicht benötigt, da - * alle Elemente bereits in richtiger Reihenfolge vorliegen und - * es keine doppelten Nennungen gibt - * - * @param zahl Zu zerlegende Zahl. - * @param max Maximal in Summenzerlegung vorkommende Zahl. - * @param bisher - */ - private void zerlege(int zahl, int max, LinkedList<Integer> bisher, List<List<Integer>> combosTmp) { - - for (int i = Math.min(zahl, max); i >= 1; i--) - { - - LinkedList<Integer> newBisher = null; - // für i==0 wird aus Effizienzgründen die bisherige Liste genommen - if(i==0) { - newBisher = bisher; - newBisher.add(i); - // für zahl - i == 1 muss gar keine Liste erstellt werden, da dann keine - // Zerlegung mehr möglich ist - } else if(zahl - i != 1) { - newBisher = cloneList(bisher); - newBisher.add(i); - } - - - if (zahl - i > 1) - { - // i wird hinzugefügt, d.h. - // - es muss nur noch zahl - i - 1 zerlegt werden (-1 wegen OR-Symbol) - // - es darf keine größere Zahl als i mehr vorkommen - // (dadurch gehen keine Kombinationen verloren) - zerlege(zahl - i - 1, i, newBisher,combosTmp); - } - // Fall zahl == i, d.h. es muss nicht weiter zerlegt werden - else if(zahl - i == 0){ - combosTmp.add(newBisher); - } - - } - - // numbers.add(bisher); - } - // auf Notebook: Länge 70 in 17 Sekunden, Länge 50 in 800ms, Länge 30 in 15ms - // http://88.198.173.90/tud/forum/messages?topic=304392 - public List<List<Integer>> getCombos(int length) { - LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>(); - zerlege(length, length, new LinkedList<Integer>(), combosTmp); - return combosTmp; - } - - // neue Implementierung, die nicht mehr zur incompleteness führen soll, - // da die Konzepte in einer MultiDisjunction als Liste gespeichert werden - private Set<Union> incCrossProduct2(Set<Union> baseSet, Set<Description> newSet) { - Set<Union> retSet = new HashSet<Union>(); - - if(baseSet.isEmpty()) { - for(Description c : newSet) { - Union md = new Union(); - md.addChild(c); - retSet.add(md); - } - return retSet; - } - - for(Union md : baseSet) { - for(Description c : newSet) { - Union mdNew = new Union(md.getChildren()); - mdNew.addChild(c); - retSet.add(mdNew); - } - } - - return retSet; - } - // incremental cross product // es müssen Listen statt Sets verwendet werden @SuppressWarnings({"unused"}) - private Set<Set<Description>> incCrossProduct(Set<Set<Description>> baseSet, Set<Description> newSet) { + private Set<Set<Description>> incCrossProductOld(Set<Set<Description>> baseSet, Set<Description> newSet) { Set<Set<Description>> retSet = new HashSet<Set<Description>>(); // falls erste Menge leer ist, dann wird Menge mit jeweils Singletons aus der Modified: trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-27 15:59:18 UTC (rev 658) +++ trunk/src/dl-learner/org/dllearner/test/OWLAPIBugDemo.java 2008-02-27 19:03:22 UTC (rev 659) @@ -63,11 +63,11 @@ // class cast exception Set<Set<OWLDescription>> test = reasoner.getDomains(p); - OWLClass oc = (OWLClass) test.iterator().next(); - System.out.println(oc); -// for(Set<OWLDescription> test2 : test) { -// System.out.println(test2); -// } +// OWLClass oc = (OWLClass) test.iterator().next(); +// System.out.println(oc); + for(Set<OWLDescription> test2 : test) { + System.out.println(test2); + } // save ontology manager.saveOntology(ontology); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-28 20:25:24
|
Revision: 663 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=663&view=rev Author: sknappe Date: 2008-02-28 12:25:13 -0800 (Thu, 28 Feb 2008) Log Message: ----------- bugfixes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-02-28 14:18:15 UTC (rev 662) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-02-28 20:25:13 UTC (rev 663) @@ -33,7 +33,6 @@ import org.apache.log4j.Logger; import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; /** * SPARQL query cache to avoid possibly expensive multiple queries. The queries @@ -213,19 +212,18 @@ * The SPARQL query. * @return Jena result set. */ - public ResultSet executeSparqlQuery(SparqlQuery query) { + public String executeSparqlQuery(SparqlQuery query) { String result = getCacheEntry(query.getQueryString()); if (result != null) { - return SparqlQuery.JSONtoResultSet(result); + return result; } else { query.send(); - ResultSet rs = query.getResultSet(); - if (rs!=null){ - String json = SparqlQuery.getAsJSON(rs); + String json = query.getResult(); + if (json!=null){ addToCache(query.getQueryString(), json); - return SparqlQuery.JSONtoResultSet(json); } - return rs; + else json=""; + return json; } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-02-28 14:18:15 UTC (rev 662) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-02-28 20:25:13 UTC (rev 663) @@ -50,7 +50,7 @@ private String queryString; private QueryEngineHTTP queryExecution; private SparqlEndpoint endpoint; - private ResultSet rs = null; + private String json = null; private SparqlQueryException sendException=null; /** @@ -69,6 +69,7 @@ */ public ResultSet send() { isRunning = true; + ResultSet rs=null; logger.info(queryString); String service = endpoint.getURL().toString(); @@ -86,6 +87,7 @@ //TODO after overnext Jena release HttpQuery.urlLimit = 3*1024 ; rs = queryExecution.execSelect(); + json=SparqlQuery.getAsJSON(rs); logger.info(rs.getResultVars().toString()); } catch (Exception e){ sendException=new SparqlQueryException(e.getMessage()); @@ -104,8 +106,8 @@ return queryString; } - public ResultSet getResultSet() { - return rs; + public String getResult() { + return json; } public boolean isRunning() { @@ -121,37 +123,10 @@ } public boolean hasCompleted() { - return (rs != null); + return (json != null); } /** - * TODO define the format - * - * @return - */ - @Deprecated - @SuppressWarnings( { "unchecked" }) - public static String[][] getAsStringArray(ResultSet rs) { - List<ResultBinding> l = ResultSetFormatter.toList(rs); - List<String> resultVars = rs.getResultVars(); - String[][] array = new String[l.size()][resultVars.size()]; - Iterator<String> iter = resultVars.iterator(); - int i = 0, j = 0; - - for (ResultBinding resultBinding : l) { - while (iter.hasNext()) { - String varName = (String) iter.next(); - array[i][j] = resultBinding.get(varName).toString(); - j++; - } - iter = resultVars.iterator(); - i++; - j = 0; - } - return array; - } - - /** * sends a query and returns XML * * @return String xml Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java 2008-02-28 14:18:15 UTC (rev 662) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java 2008-02-28 20:25:13 UTC (rev 663) @@ -8,38 +8,36 @@ * */ public class SparqlQueryThreaded { - private boolean isRunning=false; private Cache cache; private SparqlQuery query; - private ResultSet result; + private String result; public SparqlQueryThreaded(Cache cache, SparqlQuery query) { this.cache=cache; this.query=query; + this.result=null; } public void stop() { query.getExecution().abort(); - isRunning = false; + result=null; } public boolean isRunning() { - return isRunning; + return result==null; } public void send() { - isRunning=true; result=cache.executeSparqlQuery(query); - isRunning=false; } public SparqlQuery getSparqlQuery(){ return query; } - public ResultSet getResult(){ + public String getResult(){ return result; } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-02-28 14:18:15 UTC (rev 662) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-02-28 20:25:13 UTC (rev 663) @@ -87,7 +87,7 @@ // .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString); SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); - ResultSet rs = cache.executeSparqlQuery(query); + ResultSet rs = SparqlQuery.JSONtoResultSet(cache.executeSparqlQuery(query)); List<ResultBinding> l = ResultSetFormatter.toList(rs); p(l.toString()); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-02-28 14:18:15 UTC (rev 662) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-02-28 20:25:13 UTC (rev 663) @@ -64,7 +64,7 @@ + "}"; SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); - ResultSet rs = cache.executeSparqlQuery(query); + ResultSet rs = SparqlQuery.JSONtoResultSet(cache.executeSparqlQuery(query)); List<ResultBinding> l = ResultSetFormatter.toList(rs); for (ResultBinding resultBinding : l) { Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-28 14:18:15 UTC (rev 662) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-28 20:25:13 UTC (rev 663) @@ -57,6 +57,7 @@ import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryException; +import org.dllearner.kb.sparql.SparqlQueryThreaded; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -501,29 +502,21 @@ // SPARQL component methods // //////////////////////////////////////// + @WebMethod - public String[][] getAsStringArray(int sessionID, int queryID) throws ClientNotKnownException, SparqlQueryException - { - ClientState state = getState(sessionID); - SparqlQueryException exception=null; - if ((exception=state.getQuery(queryID).getSparqlQuery().getException())!=null) throw exception; - return SparqlQuery.getAsStringArray(state.getQuery(queryID).getResult()); - } - - @WebMethod public String getAsJSON(int sessionID, int queryID) throws ClientNotKnownException, SparqlQueryException { ClientState state = getState(sessionID); SparqlQueryException exception=null; if ((exception=state.getQuery(queryID).getSparqlQuery().getException())!=null) throw exception; - return SparqlQuery.getAsJSON(state.getQuery(queryID).getResult()); + return state.getQuery(queryID).getResult(); } @WebMethod public String getAsXMLString(int sessionID, int queryID) throws ClientNotKnownException { ClientState state = getState(sessionID); - ResultSet resultSet=state.getQuery(queryID).getResult(); + ResultSet resultSet=SparqlQuery.JSONtoResultSet(state.getQuery(queryID).getResult()); return SparqlQuery.getAsXMLString(resultSet); } @@ -544,6 +537,16 @@ } @WebMethod + public String sparqlQuery(int sessionID, int componentID, String query) throws ClientNotKnownException + { + ClientState state = getState(sessionID); + Component component = state.getComponent(componentID); + SparqlQueryThreaded sparql=((SparqlKnowledgeSource)component).sparqlQueryThreaded(query); + sparql.send(); + return sparql.getResult(); + } + + @WebMethod public boolean isSparqlQueryRunning(int sessionID, int queryID) throws ClientNotKnownException { ClientState state = getState(sessionID); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-28 23:17:46
|
Revision: 665 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=665&view=rev Author: tonytacker Date: 2008-02-28 15:17:17 -0800 (Thu, 28 Feb 2008) Log Message: ----------- save config (only system.out.println) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java Modified: trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -19,10 +19,9 @@ */ package org.dllearner.core.config; - /** * @author Jens Lehmann - * + * */ public class BooleanConfigOption extends ConfigOption<Boolean> { @@ -33,8 +32,10 @@ public BooleanConfigOption(String name, String description, boolean defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override @@ -42,7 +43,9 @@ return (object instanceof Boolean); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override @@ -50,12 +53,20 @@ return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Boolean value) { - return value.toString(); + public String getValueFormatting(Boolean value, Integer special) { + if (value != null) { + if (value) + return "true"; + else + return "false"; + } else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-28 23:17:17 UTC (rev 665) @@ -19,45 +19,50 @@ */ package org.dllearner.core.config; - /** * A config entry is a configuration option and a value for the option. * * @author Jens Lehmann - * + * */ public class ConfigEntry<T> { private ConfigOption<T> option; private T value; - + public ConfigEntry(ConfigOption<T> option, T value) throws InvalidConfigOptionValueException { - if(!option.isValidValue(value)) { + if (!option.isValidValue(value)) { throw new InvalidConfigOptionValueException(option, value); } else { this.option = option; this.value = value; } } - + public ConfigOption<T> getOption() { return option; } - + public String getOptionName() { return option.getName(); } - + public T getValue() { return value; } - + /** * Get a string to save into a configuration file. * * @return a formatted string */ public String toConfString(String componentName) { - return componentName.toString() + "." + option.getName() + " = " + option.getValueFormatting(value); + if (option.getName().equalsIgnoreCase("positiveExamples")) { + return option.getValueFormatting(value, 1); + } else if (option.getName() == "negativeExamples") { + return option.getValueFormatting(value, 2); + } else + return componentName.toString() + "." + option.getName() + " = " + + option.getValueFormatting(value, 0); } } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -23,68 +23,81 @@ * This class represents a configuration option (without a value for the * option). * - * Note: Currently, handling the type of a configuration option is not - * straightforward to implement, because Java Generics information is - * erased at runtime. This will be fixed in Java 7, in particular JSR 308, - * which is due at approx. the end of 2008. + * Note: Currently, handling the type of a configuration option is not + * straightforward to implement, because Java Generics information is erased at + * runtime. This will be fixed in Java 7, in particular JSR 308, which is due at + * approx. the end of 2008. * * @author Jens Lehmann - * + * */ public abstract class ConfigOption<T> { protected String name; - + protected String description; - + protected T defaultValue; - + public ConfigOption(String name, String description) { this(name, description, null); } - + public ConfigOption(String name, String description, T defaultValue) { this.name = name; this.description = description; this.defaultValue = defaultValue; } - + public String getName() { return name; } - + public String getDescription() { return description; - } - + } + /** * @return the defaultValue */ public T getDefaultValue() { return defaultValue; - } - + } + /** - * Checks whether the object has the correct type to be used as - * a value for this option (this method is necessary, because - * generic information is erased at runtime in Java). - * - * @param object The object to check. + * Checks whether the object has the correct type to be used as a value for + * this option (this method is necessary, because generic information is + * erased at runtime in Java). + * + * @param object + * The object to check. * @return */ public abstract boolean checkType(Object object); - + public abstract boolean isValidValue(T value); - + public String getAllowedValuesDescription() { return getClass().toString(); } - + @Override public String toString() { - return "option name: " + name + "\ndescription: " + description + "\nvalues: " + getAllowedValuesDescription() + "\ndefault value: " + defaultValue + "\n"; + return "option name: " + name + "\ndescription: " + description + "\nvalues: " + + getAllowedValuesDescription() + "\ndefault value: " + defaultValue + "\n"; } - - public abstract String getValueFormatting(T value); + /** + * Get a formatted value to put into configuration file. + * + * @param value + * @param special + * 0 for normal output. + * 1 for positiveExamples. + * 2 for negativeExamples. + * + * @return a string to put into a file + */ + public abstract String getValueFormatting(T value, Integer special); + } Modified: trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -19,38 +19,39 @@ */ package org.dllearner.core.config; - /** - * Represents a configuration option with values of type value. Similar - * to the integer option a minimum and a maximum value can specified. + * Represents a configuration option with values of type value. Similar to the + * integer option a minimum and a maximum value can specified. * * @author Jens Lehmann - * + * */ public class DoubleConfigOption extends ConfigOption<Double> { private double lowerLimit = Double.MIN_VALUE; private double upperLimit = Double.MAX_VALUE; - + public DoubleConfigOption(String name, String description) { super(name, description); } - + public DoubleConfigOption(String name, String description, double defaultValue) { super(name, description, defaultValue); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#isValidValue(java.lang.Object) */ @Override public boolean isValidValue(Double value) { - if(value >= lowerLimit && value <= upperLimit) + if (value >= lowerLimit && value <= upperLimit) return true; else - return false; + return false; } - + /** * @return the The lowest possible value for this configuration option. */ @@ -59,7 +60,8 @@ } /** - * @param lowerLimit The lowest possible value for this configuration option. + * @param lowerLimit + * The lowest possible value for this configuration option. */ public void setLowerLimit(double lowerLimit) { this.lowerLimit = lowerLimit; @@ -73,26 +75,29 @@ } /** - * @param upperLimit The highest possible value for this configuration option. + * @param upperLimit + * The highest possible value for this configuration option. */ public void setUpperLimit(double upperLimit) { this.upperLimit = upperLimit; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.dllearner.core.ConfigOption#checkType(java.lang.Object) */ @Override public boolean checkType(Object object) { return (object instanceof Double); } - + @Override public String getAllowedValuesDescription() { String str = getClass().toString(); - if(lowerLimit != Double.MIN_VALUE) + if (lowerLimit != Double.MIN_VALUE) str += " min " + lowerLimit; - if(upperLimit != Double.MAX_VALUE) + if (upperLimit != Double.MAX_VALUE) str += " max " + upperLimit; return str; } @@ -103,8 +108,11 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Double value) { - return value.toString(); + public String getValueFormatting(Double value, Integer special) { + if (value != null) + return value.toString(); + else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -108,7 +108,10 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Integer value) { - return value.toString(); + public String getValueFormatting(Integer value, Integer special) { + if (value != null) + return value.toString(); + else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -90,8 +90,11 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(String value) { - return value.toString(); + public String getValueFormatting(String value, Integer special) { + if (value != null) + return value.toString(); + else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -68,8 +68,34 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(Set<String> value) { - return value.toString(); + public String getValueFormatting(Set<String> value, Integer special) { + String back = ""; + if (value != null && special == 0) { + Integer count = 0; + back = "{"; + for (String i : value) { + if (count > 0) + back += ","; + back += "\n\"" + i + "\""; + count++; + } + back += "};"; + return back; + } + // positive examples + if (value != null && special == 1) { + for (String i : value) { + back += "\n+" + i; + } + return back + "\n"; + } + // negative examples + if (value != null && special == 2) { + for (String i : value) { + back += "\n-" + i; + } + return back + "\n"; + } + return null; } - } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2008-02-28 23:17:17 UTC (rev 665) @@ -75,8 +75,20 @@ * @see org.dllearner.core.config.ConfigOption#getValueFormatting(java.lang.Object) */ @Override - public String getValueFormatting(List<StringTuple> value) { - return value.toString(); + public String getValueFormatting(List<StringTuple> value, Integer special) { + Integer count = 0; + if (value != null) { + String back = "["; + for (StringTuple i : value) { + if (count > 0) + back += ","; + back += "\n(\"" + i.a + "\",\"" + i.b + "\")"; + count++; + } + back += "];"; + return back; + } else + return null; } } Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-28 23:17:17 UTC (rev 665) @@ -23,19 +23,15 @@ //import java.io.File; //import java.net.URL; import java.util.List; //import java.util.Map; -//import java.util.SortedSet; -//import org.dllearner.core.ComponentInitException; +import java.util.Map; + import org.dllearner.core.ComponentManager; //import org.dllearner.core.KnowledgeSource; -//import org.dllearner.core.LearningProblemUnsupportedException; -//import org.dllearner.learningproblems.PosOnlyDefinitionLP; -//import org.dllearner.parser.ConfParser; 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.cli.*; -//import org.dllearner.cli.ConfFileOption; -//import org.dllearner.cli.Start; -//import org.dllearner.core.config.*; - /** * Open a config file. * @@ -62,11 +58,10 @@ /** * parse to file */ + @SuppressWarnings("unchecked") public void startParser() { - // KNOWLEDGE SOURCE + // KNOWLEDGE SOURCE (sparql or nothing) if (config.getKnowledgeSource() != null) { - // System.out.println("knowledge_source: " + - // config.getKnowledgeSource().getClass()); // KBFile or OWLFile if (config.getKnowledgeSource().getClass().toString().endsWith("KBFile") || config.getKnowledgeSource().getClass().toString().endsWith("OWLFile")) { @@ -76,11 +71,13 @@ if (url != null) { System.out.println("import(\"" + url + "\");"); } - // filename - String filename = (String) config.getComponentManager().getConfigOptionValue( - config.getKnowledgeSource(), "filename"); - if (filename != null) { - System.out.println("import(\"" + filename + "\");"); + // filename (only for KBFile) + if (config.getKnowledgeSource().getClass().toString().endsWith("KBFile")) { + String filename = (String) config.getComponentManager().getConfigOptionValue( + config.getKnowledgeSource(), "filename"); + if (filename != null) { + System.out.println("import(\"" + filename + "\");"); + } } } // sparql @@ -88,36 +85,59 @@ String url = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "url"); if (url != null) { - System.out.println("import(\"" + url + "\",\"SPARQL\");"); - // widgets - String prefix = "sparql"; - Component component = config.getKnowledgeSource(); + setFileEntry(config.getKnowledgeSource()); + } + } + } + // REASONER + if (config.getReasoner() != null) { + setFileEntry(config.getReasoner()); + } + // LEARNING PROBLEM + if (config.getLearningProblem() != null) { + setFileEntry(config.getLearningProblem()); + } + // LEARNING ALGORITHM + if (config.getLearningAlgorithm() != null) { + setFileEntry(config.getLearningAlgorithm()); + } - Class<? extends Component> componentOption = component.getClass(); // config.getKnowledgeSource().getClass(); - List<ConfigOption<?>> optionList; - optionList = ComponentManager.getConfigOptions(componentOption); - // System.out.println(optionList); - // System.out.println(config.getComponentManager().getConfigOptionValue(component, - // optionName)); - for (int i = 0; i < optionList.size(); i++) { - // if - // (optionList.get(i).getClass().toString().contains("IntegerConfigOption")) - // { - // widgetPanel = new WidgetPanelInteger(config, - // component, oldComponent, componentOption, - // optionList.get(i)); - // System.out.println(optionList.get(i)); - System.out.println(prefix - + "." - + optionList.get(i).getName() - + " = " - + config.getComponentManager().getConfigOptionValue(component, - optionList.get(i).getName())); - System.out.println(config.getComponentManager().getKnowledgeSources() - .get(0)); - // } - } + } + + /** + * Set all entrys to file. + * + * @param component + * i.e. config.getKnowledgeSource(), config.getResaoner(), ... + */ + @SuppressWarnings("unchecked") + public void setFileEntry(Component component) { + // get prefix map + Map<Class<? extends Component>, String> componentPrefixMapping = Start + .createComponentPrefixMapping(); + String prefix = componentPrefixMapping.get(component.getClass()); + if (prefix == null) + return; + Class<? extends Component> componentOption = component.getClass(); + List<ConfigOption<?>> optionList = ComponentManager.getConfigOptions(componentOption); + for (int i = 0; i < optionList.size(); i++) { + try { + Object dflt = optionList.get(i).getDefaultValue(); + Object value = config.getComponentManager().getConfigOptionValue(component, + optionList.get(i).getName()); + // System.out.println("default: " + dflt); + if (optionList.get(i).getName() != "url" + && optionList.get(i).getName() != "filename" && value != null) { + if (value != null) + if (!value.equals(dflt)) { + ConfigOption specialOption = config.getComponentManager() + .getConfigOption(componentOption, optionList.get(i).getName()); + ConfigEntry entry = new ConfigEntry(specialOption, value); + System.out.println(entry.toConfString(prefix)); + } } + } catch (InvalidConfigOptionValueException e) { + e.printStackTrace(); } } } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-28 20:25:39 UTC (rev 664) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-28 23:17:17 UTC (rev 665) @@ -69,7 +69,10 @@ } public void actionPerformed(ActionEvent e) { - + if (cb.getSelectedIndex() == 0) + value = false; + else + value = true; setEntry(); } @@ -100,14 +103,14 @@ else setEntry(); // set cb-index - if (value == false) + if (!value) cb.setSelectedIndex(0); else cb.setSelectedIndex(1); } } // default value - if (value != null && configOption.getDefaultValue() != null) { + else if (value != null && configOption.getDefaultValue() != null) { value = (Boolean) configOption.getDefaultValue(); } // value == null? @@ -115,12 +118,11 @@ value = false; } // set cb-index - if (value == false) + if (!value) cb.setSelectedIndex(0); else cb.setSelectedIndex(1); cb.addActionListener(this); - widgetPanel.add(cb); } // UNKNOWN @@ -139,10 +141,6 @@ @Override public void setEntry() { BooleanConfigOption specialOption; - if (cb.getSelectedIndex() == 0) - value = false; - else - value = true; specialOption = (BooleanConfigOption) config.getComponentManager().getConfigOption( componentOption, configOption.getName()); if (specialOption.isValidValue(value)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-29 05:41:41
|
Revision: 668 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=668&view=rev Author: tonytacker Date: 2008-02-28 21:41:38 -0800 (Thu, 28 Feb 2008) Log Message: ----------- save file works Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Modified: trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/BooleanConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -62,9 +62,9 @@ public String getValueFormatting(Boolean value, Integer special) { if (value != null) { if (value) - return "true"; + return "true;"; else - return "false"; + return "false;"; } else return null; } Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/ConfigEntry.java 2008-02-29 05:41:38 UTC (rev 668) @@ -57,12 +57,12 @@ * @return a formatted string */ public String toConfString(String componentName) { - if (option.getName() == "positiveExamples") { + if (option.getName().equalsIgnoreCase("positiveExamples")) { return option.getValueFormatting(value, 1); - } else if (option.getName() == "negativeExamples") { + } else if (option.getName().equalsIgnoreCase("negativeExamples")) { return option.getValueFormatting(value, 2); - } else - return componentName.toString() + "." + option.getName() + " = " + } + return componentName.toString() + "." + option.getName() + " = " + option.getValueFormatting(value, 0); } } Modified: trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/DoubleConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -110,7 +110,7 @@ @Override public String getValueFormatting(Double value, Integer special) { if (value != null) - return value.toString(); + return value.toString() + ";"; else return null; } Modified: trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/IntegerConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -110,7 +110,7 @@ @Override public String getValueFormatting(Integer value, Integer special) { if (value != null) - return value.toString(); + return value.toString() + ";"; else return null; } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/StringConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -92,7 +92,7 @@ @Override public String getValueFormatting(String value, Integer special) { if (value != null) - return value.toString(); + return value.toString() + ";"; else return null; } Modified: trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2008-02-29 05:41:38 UTC (rev 668) @@ -91,8 +91,13 @@ } // negative examples if (value != null && special == 2) { + Integer count = 0; for (String i : value) { - back += "\n-\"" + i + "\""; + count++; + if (count == 1) + back += "-\"" + i + "\""; + else + back += "\n-\"" + i + "\""; } return back + "\n"; } Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigLoad.java 2008-02-29 05:41:38 UTC (rev 668) @@ -93,6 +93,7 @@ config.setKnowledgeSource(config.getKnowledgeSource()); Start.configureComponent(config.getComponentManager(), config.getKnowledgeSource(), componentPrefixMapping, parser); + startGUI.updateTabColors(); // init if (config.getKnowledgeSource() != null && config.isSetURL()) { try { Modified: trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/gui/ConfigSave.java 2008-02-29 05:41:38 UTC (rev 668) @@ -31,6 +31,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.cli.*; +import java.io.PrintWriter; /** * Open a config file. @@ -57,9 +58,12 @@ /** * parse to file + * + * @param out + * is a PrintWriter to a file */ @SuppressWarnings("unchecked") - public void startParser() { + public void startParser(PrintWriter out) { // KNOWLEDGE SOURCE (sparql or nothing) if (config.getKnowledgeSource() != null) { // KBFile or OWLFile @@ -69,14 +73,19 @@ String url = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "url"); if (url != null) { - System.out.println("import(\"" + url + "\");"); + if (url.startsWith("file")) + url = url.substring(url.lastIndexOf("/") + 1); + // System.out.println("import(\"" + url + "\");"); + out.println("import(\"" + url + "\");"); } // filename (only for KBFile) if (config.getKnowledgeSource().getClass().toString().endsWith("KBFile")) { String filename = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "filename"); if (filename != null) { - System.out.println("import(\"" + filename + "\");"); + filename = filename.substring(filename.lastIndexOf("/") + 1); + // System.out.println("import(\"" + filename + "\");"); + out.println("import(\"" + filename + "\");"); } } } @@ -85,21 +94,22 @@ String url = (String) config.getComponentManager().getConfigOptionValue( config.getKnowledgeSource(), "url"); if (url != null) { - setFileEntry(config.getKnowledgeSource()); + out.println("import(\"" + url + "\",\"SPARQL\");"); + setFileEntry(config.getKnowledgeSource(), out); } } } // REASONER if (config.getReasoner() != null) { - setFileEntry(config.getReasoner()); + setFileEntry(config.getReasoner(), out); } // LEARNING PROBLEM if (config.getLearningProblem() != null) { - setFileEntry(config.getLearningProblem()); + setFileEntry(config.getLearningProblem(), out); } // LEARNING ALGORITHM if (config.getLearningAlgorithm() != null) { - setFileEntry(config.getLearningAlgorithm()); + setFileEntry(config.getLearningAlgorithm(), out); } } @@ -111,7 +121,7 @@ * i.e. config.getKnowledgeSource(), config.getResaoner(), ... */ @SuppressWarnings("unchecked") - public void setFileEntry(Component component) { + public void setFileEntry(Component component, PrintWriter out) { // get prefix map Map<Class<? extends Component>, String> componentPrefixMapping = Start .createComponentPrefixMapping(); @@ -125,7 +135,7 @@ Object dflt = optionList.get(i).getDefaultValue(); Object value = config.getComponentManager().getConfigOptionValue(component, optionList.get(i).getName()); - // System.out.println("default: " + dflt); + // not for url or filename if (optionList.get(i).getName() != "url" && optionList.get(i).getName() != "filename" && value != null) { if (value != null) @@ -133,7 +143,7 @@ ConfigOption specialOption = config.getComponentManager() .getConfigOption(componentOption, optionList.get(i).getName()); ConfigEntry entry = new ConfigEntry(specialOption, value); - System.out.println(entry.toConfString(prefix)); + out.println(entry.toConfString(prefix)); } } } catch (InvalidConfigOptionValueException e) { Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-29 00:06:36 UTC (rev 667) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-29 05:41:38 UTC (rev 668) @@ -33,6 +33,8 @@ import org.apache.log4j.SimpleLayout; import java.io.File; +import java.io.PrintWriter; +import java.io.FileWriter; import javax.swing.filechooser.FileFilter; /** @@ -59,7 +61,7 @@ private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); private JMenuItem openItem = new JMenuItem("Open Config"); - private JMenuItem saveItem = new JMenuItem("Save Config"); + private JMenuItem saveItem = new JMenuItem("Save As Config"); public StartGUI() { this.setTitle("DL-Learner"); @@ -140,10 +142,37 @@ configLoad.startParser(); } } - // save config file + // save as config file if (e.getSource() == saveItem) { - System.out.println("saveItem was pressed"); - configSave.startParser(); + JFileChooser fc = new JFileChooser(new File("examples/")); + // FileFilter only *.conf + fc.addChoosableFileFilter(new FileFilter() { + @Override + public boolean accept(File f) { + if (f.isDirectory()) + return true; + return f.getName().toLowerCase().endsWith(".conf"); + } + + @Override + public String getDescription() { + return "*.conf"; // name for filter + } + }); + if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { + // System.out.println("FILE: " + fc.getSelectedFile()); + File file = fc.getSelectedFile(); + try { + PrintWriter out = new PrintWriter(new FileWriter(file)); + // out.println("test"); + configSave.startParser(out); + out.flush(); + out.close(); + } catch (Exception ex2) { + System.out.println(ex2); + } + } + System.out.println("config file saved"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-03-02 19:06:18
|
Revision: 672 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=672&view=rev Author: jenslehmann Date: 2008-03-02 11:04:28 -0800 (Sun, 02 Mar 2008) Log Message: ----------- started implementation of new refinement operator Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-03-02 15:40:29 UTC (rev 671) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-03-02 19:04:28 UTC (rev 672) @@ -32,8 +32,6 @@ import org.apache.log4j.Logger; -import com.hp.hpl.jena.query.ResultSet; - /** * SPARQL query cache to avoid possibly expensive multiple queries. The queries * and their results are written to files. A cache has an associated cache Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-03-02 15:40:29 UTC (rev 671) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-03-02 19:04:28 UTC (rev 672) @@ -22,8 +22,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.charset.Charset; -import java.util.Iterator; -import java.util.List; import org.apache.log4j.Logger; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; @@ -31,7 +29,6 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFactory; import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.sparql.core.ResultBinding; import com.hp.hpl.jena.sparql.engine.http.HttpQuery; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java 2008-03-02 15:40:29 UTC (rev 671) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryThreaded.java 2008-03-02 19:04:28 UTC (rev 672) @@ -1,7 +1,5 @@ package org.dllearner.kb.sparql; -import com.hp.hpl.jena.query.ResultSet; - /** * The class is used for threaded querying of a Sparql Endpoint. * @author Sebastian Knappe Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-02 15:40:29 UTC (rev 671) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-02 19:04:28 UTC (rev 672) @@ -33,6 +33,7 @@ import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; import org.dllearner.core.owl.Nothing; @@ -51,7 +52,8 @@ * development. Its aim is to span a much "cleaner" and smaller search * tree compared to RhoDown by omitting many class descriptions, * which are obviously too weak, because they violate - * domain/range restrictions. + * domain/range restrictions. Furthermore, it makes use of disjoint + * classes in the knowledge base. * * @author Jens Lehmann * @@ -68,23 +70,39 @@ private Map<DatatypeProperty,Description> dpDomains = new TreeMap<DatatypeProperty,Description>(); private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>(); - // gibt die Gr��e an bis zu der die Refinements des Top-Konzepts - // bereits berechnet worden => entspricht der max. L�nge der Menge M + // start concept (can be used to start from an arbitrary concept, needs + // to be Thing or NamedClass), note that when you use e.g. Compound as + // start class, then the algorithm should start the search with class + // Compound (and not with Thing), because otherwise concepts like + // NOT Carbon-87 will be returned which itself is not a subclass of Compound + private Description startClass = new Thing(); + + // the length of concepts of top refinements, the first values is + // for refinements of \rho_\top(\top), the second one for \rho_A(\top) private int topRefinementsLength = 0; + private Map<NamedClass, Integer> topARefinementsLength = new TreeMap<NamedClass, Integer>(); - // die Menge M im Refinement-Operator indiziert nach ihrer L�nge - private Map<Integer,Set<Description>> m = new HashMap<Integer,Set<Description>>(); + // the sets M_\top and M_A + private Map<Integer,Set<Description>> m = new TreeMap<Integer,Set<Description>>(); + private Map<NamedClass,Map<Integer,Set<Description>>> mA = new TreeMap<NamedClass,Map<Integer,Set<Description>>>(); - // Zerlegungen der Zahl n in Mengen - // Map<Integer,Set<IntegerCombo>> combos = new HashMap<Integer,Set<IntegerCombo>>(); + // @see MathOperations.getCombos private Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); - // abspeichern von Kombinationen während diese rekursiv berechnet werden - // private List<List<Integer>> combosTmp; + + // refinements of the top concept ordered by length + private Map<Integer, TreeSet<Description>> topRefinements = new TreeMap<Integer, TreeSet<Description>>(); + private Map<NamedClass,Map<Integer, TreeSet<Description>>> topARefinements = new TreeMap<NamedClass,Map<Integer, TreeSet<Description>>>(); - // Refinements des Top-Konzept indiziert nach Länge - private Map<Integer, TreeSet<Description>> topRefinements = new HashMap<Integer, TreeSet<Description>>(); + // cumulated refinements of top (all from length one to the specified length) private Map<Integer, TreeSet<Description>> topRefinementsCumulative = new HashMap<Integer, TreeSet<Description>>(); + private Map<NamedClass,Map<Integer, TreeSet<Description>>> topARefinementsCumulative = new TreeMap<NamedClass,Map<Integer, TreeSet<Description>>>(); + // app_A set of applicable properties for a given class (separte for + // object properties, boolean datatypes, and double data types) + private Map<NamedClass, Set<ObjectProperty>> appOP = new TreeMap<NamedClass, Set<ObjectProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + // comparator für Konzepte private ConceptComparator conceptComparator = new ConceptComparator(); @@ -100,6 +118,10 @@ private boolean useBooleanDatatypes = true; public RhoDRDown(ReasoningService rs) { + this(rs, null); + } + + public RhoDRDown(ReasoningService rs, NamedClass startClass) { this.rs = rs; subHierarchy = rs.getSubsumptionHierarchy(); @@ -111,7 +133,10 @@ } for(DatatypeProperty dp : rs.getDatatypeProperties()) { dpDomains.put(dp, rs.getDomain(dp)); - } + } + + if(startClass != null) + this.startClass = startClass; } /* (non-Javadoc) @@ -129,6 +154,7 @@ return refine(description, maxLength, knownRefinements, new Thing()); } + @SuppressWarnings({"unchecked"}) public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements, Description currDomain) { // TODO: check whether using list or set makes more sense @@ -141,7 +167,18 @@ // function) if(description instanceof Thing) { - refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); + // extends top refinements if necessary + if(currDomain instanceof Thing) { + if(maxLength>topRefinementsLength) + computeTopRefinements(maxLength); + refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone(); + } else { + if(maxLength>topARefinementsLength.get(currDomain)) + computeTopRefinements(maxLength); + refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone(); + } + +// refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); } else if(description instanceof Nothing) { // cannot be further refined } else if(description instanceof NamedClass) { @@ -151,8 +188,11 @@ return refinements; } - // TODO: später private - public void computeTopRefinements(int maxLength) { + private void computeTopRefinements(int maxLength) { + computeTopRefinements(maxLength, null); + } + + private void computeTopRefinements(int maxLength, NamedClass domain) { long topComputationTimeStartNs = System.nanoTime(); // M erweiteren @@ -229,98 +269,86 @@ topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; } - // computation of the set M + // compute M_\top private void computeM(int maxLength) { + computeM(maxLength, null); + } + + // computation of the set M_A + // a major difference compared to the ILP 2007 \rho operator is that + // M is finite and contains elements of length (currently) at most 3 + private void computeM(int maxLength, NamedClass domain) { long mComputationTimeStartNs = System.nanoTime(); - // System.out.println("compute M from " + (topRefinementsLength+1) + " up to " + maxLength); - - // initialise all not yet initialised lengths - // (avoids null pointers in some cases) - for(int i=topRefinementsLength+1; i<=maxLength; i++) { + + // initialise all possible lengths (1 to 3) + for(int i=1; i<=3; i++) { m.put(i, new TreeSet<Description>(conceptComparator)); } - // Berechnung der Basiskonzepte in M - // TODO: Spezialfälle, dass zwischen Top und Bottom nichts liegt behandeln - if(topRefinementsLength==0 && maxLength>0) { - // Konzepte der Länge 1 = alle Konzepte, die in der Subsumptionhierarchie unter Top liegen - Set<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); - m.put(1,m1); - } + Set<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); + m.put(1,m1); - if(topRefinementsLength<2 && maxLength>1) { - // Konzepte der Länge 2 = Negation aller Konzepte, die über Bottom liegen - if(useNegation) { - Set<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); - Set<Description> m2 = new TreeSet<Description>(conceptComparator); - for(Description c : m2tmp) { - m2.add(new Negation(c)); - } - m.put(2,m2); + if(useNegation) { + Set<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); + Set<Description> m2 = new TreeSet<Description>(conceptComparator); + for(Description c : m2tmp) { + m2.add(new Negation(c)); } + m.put(2,m2); } - if(topRefinementsLength<3 && maxLength>2) { - // Konzepte der Länge 3: EXISTS r.TOP - Set<Description> m3 = new TreeSet<Description>(conceptComparator); - if(useExistsConstructor) { - // previous operator: uses all roles - // for(AtomicRole r : Config.Refinement.allowedRoles) { - // m3.add(new Exists(r, new Top())); - //} - // new operator: only uses most general roles - for(ObjectProperty r : rs.getMostGeneralRoles()) { - m3.add(new ObjectSomeRestriction(r, new Thing())); - } - - } - - // boolean datatypes, e.g. testPositive = true - if(useBooleanDatatypes) { - Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); - for(DatatypeProperty dp : booleanDPs) { - m3.add(new BooleanValueRestriction(dp,true)); - m3.add(new BooleanValueRestriction(dp,false)); - } - } - - m.put(3,m3); + Set<Description> m3 = new TreeSet<Description>(conceptComparator); + if(useExistsConstructor) { + // only uses most general roles + for(ObjectProperty r : rs.getMostGeneralRoles()) { + m3.add(new ObjectSomeRestriction(r, new Thing())); + } } - if(maxLength>2) { - if(useAllConstructor) { - // Konzepte, die mit ALL r starten - // alle existierenden Konzepte durchgehen, die maximal 2 k�rzer als - // die maximale L�nge sind - // topRefinementsLength - 1, damit Konzepte der Länge mindestens - // topRefinementsLength + 1 erzeugt werden (ALL r) - for(int i=topRefinementsLength-1; i<=maxLength-2; i++) { - // i muss natürlich mindestens 1 sein - if(i>=1) { - - // alle Konzepte durchgehen - for(Description c : m.get(i)) { - // Fall wird jetzt weiter oben schon abgehandelt - // if(!m.containsKey(i+2)) - // m.put(i+2, new TreeSet<Concept>(conceptComparator)); - - // previous operator: uses all roles - // for(AtomicRole r : Config.Refinement.allowedRoles) { - // Mehrfacheinf�gen ist bei einer Menge kein Problem - // m.get(i+2).add(new All(r,c)); - // } - - for(ObjectProperty r : rs.getMostGeneralRoles()) { - m.get(i+2).add(new ObjectAllRestriction(r,c)); - } - } - } - } + if(useAllConstructor) { + // we allow \forall r.\top here because otherwise the operator + // becomes too difficult to manage due to dependencies between + // M_A and M_A' where A'=ran(r) + for(ObjectProperty r : rs.getMostGeneralRoles()) { + m3.add(new ObjectAllRestriction(r, new Thing())); + } + } + + // boolean datatypes, e.g. testPositive = true + if(useBooleanDatatypes) { + Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + for(DatatypeProperty dp : booleanDPs) { + m3.add(new BooleanValueRestriction(dp,true)); + m3.add(new BooleanValueRestriction(dp,false)); } } + m.put(3,m3); + mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } + // computes the set of applicable properties for a given class + private void computeApp(NamedClass domain) { + // TODO: also implement this for boolean/double datatype properties + Set<ObjectProperty> mostGeneral = rs.getAtomicRoles(); + Set<ObjectProperty> applicableRoles = new TreeSet<ObjectProperty>(); + for(ObjectProperty role : mostGeneral) { + // TODO: currently we just rely on named classes as roles, + // instead of computing dom(r) and ran(r) + NamedClass nc = (NamedClass) rs.getDomain(role); + if(!isDisjoint(domain,nc)) + applicableRoles.add(role); + } + appOP.put(domain, applicableRoles); + } -} + // computes whether two classes are disjoint; this should be computed + // by the reasoner only ones and otherwise taken from a matrix + private boolean isDisjoint(NamedClass class1, NamedClass class2) { + // we need to test whether A AND B is equivalent to BOTTOM + Description d = new Intersection(class1, class2); + return rs.subsumes(new Nothing(), d); + } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-03-03 07:47:55
|
Revision: 674 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=674&view=rev Author: jenslehmann Date: 2008-03-02 23:45:57 -0800 (Sun, 02 Mar 2008) Log Message: ----------- - improved datatype support - continued refinement operator implementation 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 trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-03 07:45:57 UTC (rev 674) @@ -27,6 +27,7 @@ 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.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -52,6 +53,7 @@ // (siehe einfacher Traversal in Diplomarbeit) public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts); public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) throws ReasoningMethodUnsupportedException; + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedDatatypeProperties) throws ReasoningMethodUnsupportedException; public boolean subsumes(Description superConcept, Description subConcept) throws ReasoningMethodUnsupportedException; @@ -69,6 +71,8 @@ public ObjectPropertyHierarchy getRoleHierarchy() throws ReasoningMethodUnsupportedException; + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> retrieval(Description concept) throws ReasoningMethodUnsupportedException; public Map<Individual, SortedSet<Individual>> getRoleMembers(ObjectProperty atomicRole) throws ReasoningMethodUnsupportedException; Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-03 07:45:57 UTC (rev 674) @@ -30,6 +30,7 @@ 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.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -186,10 +187,18 @@ 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(); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-03 07:45:57 UTC (rev 674) @@ -29,6 +29,7 @@ import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -328,6 +329,44 @@ 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(getAtomicConcepts()); } @@ -367,6 +406,27 @@ } } + 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; Added: trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java 2008-03-03 07:45:57 UTC (rev 674) @@ -0,0 +1,110 @@ +/** + * 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.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.utilities.RoleComparator; + +/** + * Represents a hierarchy of datatype properties. + * + * @todo. Currently, the role hierarchy pruning algorithm (analogous to the + * subsumption hierarchy) is not implemented. + * + * @author Jens Lehmann + * + */ +public class DatatypePropertyHierarchy { + + RoleComparator rc = new RoleComparator(); + TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyUp; + TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyDown; + TreeSet<DatatypeProperty> mostGeneralRoles = new TreeSet<DatatypeProperty>(rc); + TreeSet<DatatypeProperty> mostSpecialRoles = new TreeSet<DatatypeProperty>(rc); + + public DatatypePropertyHierarchy(Set<DatatypeProperty> atomicRoles, TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyUp , TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyDown) { + this.roleHierarchyUp = roleHierarchyUp; + this.roleHierarchyDown = roleHierarchyDown; + + // find most general and most special roles + for(DatatypeProperty role : atomicRoles) { + if(getMoreGeneralRoles(role).size()==0) + mostGeneralRoles.add(role); + if(getMoreSpecialRoles(role).size()==0) + mostSpecialRoles.add(role); + } + } + + @SuppressWarnings("unchecked") + public SortedSet<DatatypeProperty> getMoreGeneralRoles(DatatypeProperty role) { + // we clone all concepts before returning them such that they cannot be + // modified externally + return (TreeSet<DatatypeProperty>) roleHierarchyUp.get(role).clone(); + } + + @SuppressWarnings("unchecked") + public SortedSet<DatatypeProperty> getMoreSpecialRoles(DatatypeProperty role) { + return (TreeSet<DatatypeProperty>) roleHierarchyDown.get(role).clone(); + } + + + + @Override + public String toString() { + String str = ""; + for(DatatypeProperty role : mostGeneralRoles) { + str += toString(roleHierarchyDown, role, 0); + } + return str; + } + + private String toString(TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> hierarchy, DatatypeProperty role, int depth) { + String str = ""; + for(int i=0; i<depth; i++) + str += " "; + str += role.toString() + "\n"; + Set<DatatypeProperty> tmp = hierarchy.get(role); + if(tmp!=null) { + for(DatatypeProperty c : tmp) + str += toString(hierarchy, c, depth+1); + } + return str; + } + + /** + * @return The most general roles. + */ + public TreeSet<DatatypeProperty> getMostGeneralRoles() { + return mostGeneralRoles; + } + + /** + * @return The most special roles. + */ + public TreeSet<DatatypeProperty> getMostSpecialRoles() { + return mostSpecialRoles; + } + + +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-03 07:45:57 UTC (rev 674) @@ -38,6 +38,7 @@ import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; @@ -359,6 +360,16 @@ } @Override + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { + rs.prepareDatatypePropertyHierarchy(allowedRoles); + } + + @Override + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + return rs.getDatatypePropertyHierarchy(); + } + + @Override public boolean subsumes(Description superConcept, Description subConcept) { // Negation neg = new Negation(subConcept); // Intersection c = new Intersection(neg,superConcept); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-03 07:45:57 UTC (rev 674) @@ -46,6 +46,7 @@ import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; import org.dllearner.core.owl.FunctionalObjectPropertyAxiom; @@ -129,6 +130,7 @@ private RoleComparator roleComparator = new RoleComparator(); private SubsumptionHierarchy subsumptionHierarchy; private ObjectPropertyHierarchy roleHierarchy; + private DatatypePropertyHierarchy datatypePropertyHierarchy; private Set<Description> allowedConceptsInSubsumptionHierarchy; // primitives @@ -430,6 +432,30 @@ } @Override + public void prepareDatatypePropertyHierarchy(Set<DatatypeProperty> allowedRoles) { + // code copied from DIG reasoner + + TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( + roleComparator); + TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( + roleComparator); + + // refinement of atomic concepts + for (DatatypeProperty role : datatypeProperties) { + datatypePropertyHierarchyDown.put(role, getMoreSpecialDatatypeProperties(role)); + datatypePropertyHierarchyUp.put(role, getMoreGeneralDatatypeProperties(role)); + } + + datatypePropertyHierarchy = new DatatypePropertyHierarchy(allowedRoles, datatypePropertyHierarchyUp, + datatypePropertyHierarchyDown); + } + + @Override + public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { + return datatypePropertyHierarchy; + } + + @Override public boolean subsumes(Description superConcept, Description subConcept) { try { return reasoner.isSubClassOf(OWLAPIDescriptionConvertVisitor.getOWLDescription(subConcept), OWLAPIDescriptionConvertVisitor.getOWLDescription(superConcept)); @@ -469,7 +495,7 @@ e.printStackTrace(); throw new Error("OWL API classification error."); } - return getFirstProperties(properties); + return getFirstObjectProperties(properties); } private TreeSet<ObjectProperty> getMoreSpecialRoles(ObjectProperty role) { @@ -480,9 +506,31 @@ e.printStackTrace(); throw new Error("OWL API classification error."); } - return getFirstProperties(properties); + return getFirstObjectProperties(properties); } + private TreeSet<DatatypeProperty> getMoreGeneralDatatypeProperties(DatatypeProperty role) { + Set<Set<OWLDataProperty>> properties; + try { + properties = reasoner.getSuperProperties(getOWLAPIDescription(role)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstDatatypeProperties(properties); + } + + private TreeSet<DatatypeProperty> getMoreSpecialDatatypeProperties(DatatypeProperty role) { + Set<Set<OWLDataProperty>> properties; + try { + properties = reasoner.getSubProperties(getOWLAPIDescription(role)); + } catch (OWLReasonerException e) { + e.printStackTrace(); + throw new Error("OWL API classification error."); + } + return getFirstDatatypeProperties(properties); + } + @Override public boolean instanceCheck(Description concept, Individual individual) { OWLDescription d = getOWLAPIDescription(concept); @@ -681,7 +729,7 @@ return concepts; } - private TreeSet<ObjectProperty> getFirstProperties(Set<Set<OWLObjectProperty>> setOfSets) { + private TreeSet<ObjectProperty> getFirstObjectProperties(Set<Set<OWLObjectProperty>> setOfSets) { TreeSet<ObjectProperty> roles = new TreeSet<ObjectProperty>(roleComparator); for(Set<OWLObjectProperty> innerSet : setOfSets) { // take one element from the set and ignore the rest @@ -692,6 +740,15 @@ return roles; } + private TreeSet<DatatypeProperty> getFirstDatatypeProperties(Set<Set<OWLDataProperty>> setOfSets) { + TreeSet<DatatypeProperty> roles = new TreeSet<DatatypeProperty>(roleComparator); + for(Set<OWLDataProperty> innerSet : setOfSets) { + OWLDataProperty property = innerSet.iterator().next(); + roles.add(new DatatypeProperty(property.getURI().toString())); + } + return roles; + } + @SuppressWarnings({"unused"}) private Set<Description> owlClassesToAtomicConcepts(Set<OWLClass> owlClasses) { Set<Description> concepts = new HashSet<Description>(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-02 19:23:08 UTC (rev 673) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-03 07:45:57 UTC (rev 674) @@ -103,6 +103,9 @@ private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + // most general applicable properties + private Map<NamedClass,Set<ObjectProperty>> mgr = new TreeMap<NamedClass,Set<ObjectProperty>>(); + // comparator für Konzepte private ConceptComparator conceptComparator = new ConceptComparator(); @@ -328,6 +331,23 @@ mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } + private void computeMgr(NamedClass domain) { + // compute the applicable properties if this has not been done yet + if(appOP.get(domain) == null) + computeApp(domain); + Set<ObjectProperty> mostGeneral = rs.getMostGeneralRoles(); + computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); + } + + private void computeMgrRecursive(NamedClass domain, Set<ObjectProperty> currProperties, Set<ObjectProperty> mgrTmp) { + for(ObjectProperty prop : currProperties) { + if(appOP.get(domain).contains(prop)) + mgrTmp.add(prop); + else + computeMgrRecursive(domain, rs.getMoreSpecialRoles(prop), mgrTmp); + } + } + // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { // TODO: also implement this for boolean/double datatype properties This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |