From: <jen...@us...> - 2011-08-24 14:38:16
|
Revision: 3116 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3116&view=rev Author: jenslehmann Date: 2011-08-24 14:38:09 +0000 (Wed, 24 Aug 2011) Log Message: ----------- prepared rho refinement operator and OCEL heuristic for usage as components Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/examples/family/father.conf Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -37,6 +37,7 @@ import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.configurators.CELOEConfigurator; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -21,6 +21,12 @@ import java.util.List; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DoubleEditor; +import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Negation; @@ -66,19 +72,32 @@ * @author Jens Lehmann * */ -public class MultiHeuristic implements ExampleBasedHeuristic { +@ComponentAnn(name = "multiple criteria heuristic", shortName = "multiheuristic", version = 0.7) +public class MultiHeuristic implements ExampleBasedHeuristic, Component { private ConceptComparator conceptComparator = new ConceptComparator(); // private OCELConfigurator configurator; // heuristic parameters + + @ConfigOption(name = "expansionPenaltyFactor", defaultValue="0.02", propertyEditorClass = DoubleEditor.class) private double expansionPenaltyFactor = 0.02; + + @ConfigOption(name = "gainBonusFactor", defaultValue="0.5", propertyEditorClass = DoubleEditor.class) private double gainBonusFactor = 0.5; + + @ConfigOption(name = "nodeChildPenalty", defaultValue="0.0001", propertyEditorClass = DoubleEditor.class) private double nodeChildPenalty = 0.0001; // (use higher values than 0.0001 for simple learning problems); + + @ConfigOption(name = "startNodeBonus", defaultValue="0.1", propertyEditorClass = DoubleEditor.class) private double startNodeBonus = 0.1; //was 2.0 + // penalise errors on positive examples harder than on negative examples // (positive weight = 1) + @ConfigOption(name = "negativeWeight", defaultValue="1.0", propertyEditorClass = DoubleEditor.class) private double negativeWeight = 1.0; // was 0.8; + + @ConfigOption(name = "negationPenalty", defaultValue="0", propertyEditorClass = IntegerEditor.class) private int negationPenalty = 0; // examples @@ -108,6 +127,10 @@ // this.gainBonusFactor = gainBonusFactor; // } + @Override + public void init() throws ComponentInitException { + // nothing to do here + } /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) @@ -180,4 +203,5 @@ } return bonus; } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -31,6 +31,7 @@ import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; @@ -79,6 +80,7 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "OWL Class Expression Learner", shortName = "ocel", version = 1.2) public class OCEL extends AbstractCELA { // private OCELConfigurator configurator; @@ -91,14 +93,17 @@ private ROLearner2 algorithm; private static Logger logger = Logger.getLogger(OCEL.class); private String logLevel = CommonConfigOptions.logLevelDefault; - RhoDRDown operator; - + + // dependencies + private RhoDRDown operator; + private ExampleBasedHeuristic heuristic; + // configuration options private boolean writeSearchTree; private File searchTreeFile; private boolean replaceSearchTree = false; private static String defaultSearchTreeFile = "log/searchTree.txt"; - private String heuristic = "multi"; + private String heuristicStr = "multi"; Set<NamedClass> allowedConcepts; Set<ObjectProperty> allowedRoles; Set<NamedClass> ignoredConcepts; @@ -244,9 +249,9 @@ else if(name.equals("heuristic")) { String value = (String) entry.getValue(); if(value.equals("lexicographic")) - heuristic = "lexicographic"; + heuristicStr = "lexicographic"; else - heuristic = "flexible"; + heuristicStr = "flexible"; } else if(name.equals("allowedConcepts")) { allowedConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); } else if(name.equals("allowedRoles")) { @@ -328,21 +333,21 @@ Files.clearFile(searchTreeFile); // adjust heuristic - ExampleBasedHeuristic algHeuristic; + - if(heuristic == "lexicographic") - algHeuristic = new LexicographicHeuristic(); - else if(heuristic == "flexible") { + if(heuristicStr == "lexicographic") + heuristic = new LexicographicHeuristic(); + else if(heuristicStr == "flexible") { if(learningProblem instanceof PosOnlyLP) { throw new RuntimeException("does not work with positive examples only yet"); } - algHeuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); + heuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); } else { if(learningProblem instanceof PosOnlyLP) { // throw new RuntimeException("does not work with positive examples only yet"); - algHeuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); + heuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } else { - algHeuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); + heuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } } @@ -424,7 +429,7 @@ learningProblem, reasoner, operator, - algHeuristic, + heuristic, startClass, // usedConcepts, // usedRoles, @@ -548,11 +553,11 @@ } public String getHeuristic() { - return heuristic; + return heuristicStr; } public void setHeuristic(String heuristic) { - this.heuristic = heuristic; + this.heuristicStr = heuristic; } public Set<NamedClass> getAllowedConcepts() { @@ -842,4 +847,8 @@ public void setTerminateOnNoiseReached(boolean terminateOnNoiseReached) { this.terminateOnNoiseReached = terminateOnNoiseReached; } + + public void setHeuristic(ExampleBasedHeuristic heuristic) { + this.heuristic = heuristic; + } } Added: trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -0,0 +1,83 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +public class DoubleEditor implements PropertyEditor { + + private Double value; + + @Override + public void addPropertyChangeListener(PropertyChangeListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public String getAsText() { + return value.toString(); + } + + @Override + public Component getCustomEditor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getJavaInitializationString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getTags() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isPaintable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void paintValue(Graphics arg0, Rectangle arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = Double.valueOf(text); + } + + @Override + public void setValue(Object arg0) { + // TODO Auto-generated method stub + + } + + @Override + public boolean supportsCustomEditor() { + // TODO Auto-generated method stub + return false; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -63,8 +63,10 @@ // and class instances to positive examples) @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) private double approxDelta = 0.05; + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false, propertyEditorClass = BoolEditor.class) private boolean useApproximations; + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) private String accuracyMethod = "predacc"; Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -35,6 +35,10 @@ import org.apache.log4j.Logger; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.configurators.RefinementOperatorConfigurator; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.owl.BooleanValueRestriction; @@ -84,12 +88,13 @@ * @author Jens Lehmann * */ -public class RhoDRDown extends RefinementOperatorAdapter { +@ComponentAnn(name = "rho refinement operator", shortName = "rho", version = 0.8) +public class RhoDRDown extends RefinementOperatorAdapter implements Component { private static Logger logger = Logger .getLogger(RhoDRDown.class); - private AbstractReasonerComponent rs; + private AbstractReasonerComponent reasoner; // hierarchies private ClassHierarchy subHierarchy; @@ -164,24 +169,47 @@ private Map<DatatypeProperty, Map<Constant, Integer>> dataValueFrequency = new HashMap<DatatypeProperty, Map<Constant, Integer>>(); private boolean useDataHasValueConstructor = false; - // staistics + // statistics public long mComputationTimeNs = 0; public long topComputationTimeNs = 0; + @ConfigOption(name = "applyAllFilter", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean applyAllFilter = true; + + @ConfigOption(name = "applyExistsFilter", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean applyExistsFilter = true; + + @ConfigOption(name = "useAllConstructor", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useAllConstructor = true; + + @ConfigOption(name = "useExistsConstructor", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useExistsConstructor = true; + + @ConfigOption(name = "useHasValueConstructor", defaultValue="false", propertyEditorClass = BooleanEditor.class) private boolean useHasValueConstructor = false; + + @ConfigOption(name = "useCardinalityRestrictions", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useCardinalityRestrictions = true; + + @ConfigOption(name = "useNegation", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useNegation = true; + + @ConfigOption(name = "useBooleanDatatypes", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useBooleanDatatypes = true; + + @ConfigOption(name = "useDoubleDatatypes", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useDoubleDatatypes = true; - @SuppressWarnings("unused") + + @ConfigOption(name = "useStringDatatypes", defaultValue="false", propertyEditorClass = BooleanEditor.class) private boolean useStringDatatypes = false; + + @ConfigOption(name = "disjointChecks", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean disjointChecks = true; + + @ConfigOption(name = "instanceBasedDisjoints", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean instanceBasedDisjoints = true; + @ConfigOption(name = "dropDisjuncts", defaultValue="false", propertyEditorClass = BooleanEditor.class) private boolean dropDisjuncts = false; // caches for reasoner queries @@ -191,15 +219,19 @@ // private Map<NamedClass,Map<NamedClass,Boolean>> notABDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); // private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); + public RhoDRDown() { + + } + public RhoDRDown(AbstractReasonerComponent reasoningService) { // this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null); - this.rs = reasoningService; - this.subHierarchy = rs.getClassHierarchy(); + this.reasoner = reasoningService; + this.subHierarchy = reasoner.getClassHierarchy(); init(); } public RhoDRDown(AbstractReasonerComponent reasoner, ClassHierarchy subHierarchy, Description startClass, RefinementOperatorConfigurator configurator) { - this.rs = reasoner; + this.reasoner = reasoner; this.subHierarchy = subHierarchy; this.startClass = startClass; useAllConstructor = configurator.getUseAllConstructor(); @@ -223,7 +255,7 @@ public RhoDRDown(AbstractReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass, int cardinalityLimit, boolean useStringDatatypes, boolean instanceBasedDisjoints) { - this.rs = reasoningService; + this.reasoner = reasoningService; this.subHierarchy = subHierarchy; this.applyAllFilter = applyAllFilter; this.applyExistsFilter = applyExistsFilter; @@ -248,9 +280,9 @@ public void init() { // query reasoner for domains and ranges // (because they are used often in the operator) - for(ObjectProperty op : rs.getObjectProperties()) { - opDomains.put(op, rs.getDomain(op)); - opRanges.put(op, rs.getRange(op)); + for(ObjectProperty op : reasoner.getObjectProperties()) { + opDomains.put(op, reasoner.getDomain(op)); + opRanges.put(op, reasoner.getRange(op)); if(useHasValueConstructor) { // init @@ -258,7 +290,7 @@ valueFrequency.put(op, opMap); // sets ordered by corresponding individual (which we ignore) - Collection<SortedSet<Individual>> fillerSets = rs.getPropertyMembers(op).values(); + Collection<SortedSet<Individual>> fillerSets = reasoner.getPropertyMembers(op).values(); for(SortedSet<Individual> fillerSet : fillerSets) { for(Individual i : fillerSet) { // System.out.println("op " + op + " i " + i); @@ -286,15 +318,15 @@ } - for(DatatypeProperty dp : rs.getDatatypeProperties()) { - dpDomains.put(dp, rs.getDomain(dp)); + for(DatatypeProperty dp : reasoner.getDatatypeProperties()) { + dpDomains.put(dp, reasoner.getDomain(dp)); if(useDataHasValueConstructor) { Map<Constant, Integer> dpMap = new TreeMap<Constant, Integer>(); dataValueFrequency.put(dp, dpMap); // sets ordered by corresponding individual (which we ignore) - Collection<SortedSet<Constant>> fillerSets = rs.getDatatypeMembers(dp).values(); + Collection<SortedSet<Constant>> fillerSets = reasoner.getDatatypeMembers(dp).values(); for(SortedSet<Constant> fillerSet : fillerSets) { for(Constant i : fillerSet) { // System.out.println("op " + op + " i " + i); @@ -326,16 +358,16 @@ dataValueFrequency = null; // compute splits for double datatype properties - for(DatatypeProperty dp : rs.getDoubleDatatypeProperties()) { + for(DatatypeProperty dp : reasoner.getDoubleDatatypeProperties()) { computeSplits(dp); } // determine the maximum number of fillers for each role // (up to a specified cardinality maximum) if(useCardinalityRestrictions) { - for(ObjectProperty op : rs.getObjectProperties()) { + for(ObjectProperty op : reasoner.getObjectProperties()) { int maxFillers = 0; - Map<Individual,SortedSet<Individual>> opMembers = rs.getPropertyMembers(op); + Map<Individual,SortedSet<Individual>> opMembers = reasoner.getPropertyMembers(op); for(SortedSet<Individual> inds : opMembers.values()) { if(inds.size()>maxFillers) maxFillers = inds.size(); @@ -543,7 +575,7 @@ // 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.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) refinements.add(new ObjectSomeRestriction(moreSpecialRole, description.getChild(0))); @@ -587,7 +619,7 @@ // 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.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) { refinements.add(new ObjectAllRestriction(moreSpecialRole, description.getChild(0))); } @@ -666,7 +698,7 @@ } else if (description instanceof StringValueRestriction) { StringValueRestriction svr = (StringValueRestriction) description; DatatypeProperty dp = svr.getRestrictedPropertyExpression(); - Set<DatatypeProperty> subDPs = rs.getSubProperties(dp); + Set<DatatypeProperty> subDPs = reasoner.getSubProperties(dp); for(DatatypeProperty subDP : subDPs) { refinements.add(new StringValueRestriction(subDP, svr.getStringValue())); } @@ -967,7 +999,7 @@ // boolean datatypes, e.g. testPositive = true if(useBooleanDatatypes) { - Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> booleanDPs = reasoner.getBooleanDatatypeProperties(); for(DatatypeProperty dp : booleanDPs) { m2.add(new BooleanValueRestriction(dp,true)); m2.add(new BooleanValueRestriction(dp,false)); @@ -978,7 +1010,7 @@ SortedSet<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { // only uses most general roles - for(ObjectProperty r : rs.getMostGeneralProperties()) { + for(ObjectProperty r : reasoner.getMostGeneralProperties()) { m3.add(new ObjectSomeRestriction(r, new Thing())); } } @@ -987,13 +1019,13 @@ // 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.getMostGeneralProperties()) { + for(ObjectProperty r : reasoner.getMostGeneralProperties()) { m3.add(new ObjectAllRestriction(r, new Thing())); } } if(useDoubleDatatypes) { - Set<DatatypeProperty> doubleDPs = rs.getDoubleDatatypeProperties(); + Set<DatatypeProperty> doubleDPs = reasoner.getDoubleDatatypeProperties(); for(DatatypeProperty dp : doubleDPs) { if(splits.get(dp).size()>0) { DoubleMaxValue max = new DoubleMaxValue(splits.get(dp).get(splits.get(dp).size()-1)); @@ -1005,7 +1037,7 @@ } if(useDataHasValueConstructor) { - Set<DatatypeProperty> stringDPs = rs.getStringDatatypeProperties(); + Set<DatatypeProperty> stringDPs = reasoner.getStringDatatypeProperties(); for(DatatypeProperty dp : stringDPs) { // loop over frequent values Set<Constant> freqValues = frequentDataValues.get(dp); @@ -1019,7 +1051,7 @@ SortedSet<Description> m4 = new TreeSet<Description>(conceptComparator); if(useCardinalityRestrictions) { - for(ObjectProperty r : rs.getMostGeneralProperties()) { + for(ObjectProperty r : reasoner.getMostGeneralProperties()) { int maxFillers = maxNrOfFillers.get(r); // zero fillers: <= -1 r.C does not make sense // one filler: <= 0 r.C is equivalent to NOT EXISTS r.C, @@ -1199,8 +1231,8 @@ if(instanceBasedDisjoints) { // bug: tests should be performed against the index, not the upper class // SortedSet<Individual> tmp = rs.getIndividuals(upperClass); - SortedSet<Individual> tmp = rs.getIndividuals(index); - tmp.removeAll(rs.getIndividuals(candidate)); + SortedSet<Individual> tmp = reasoner.getIndividuals(index); + tmp.removeAll(reasoner.getIndividuals(candidate)); // System.out.println(" instances of " + index + " and not " + candidate + ": " + tmp.size()); meaningful = tmp.size() != 0; } else { @@ -1242,8 +1274,8 @@ boolean meaningful; // System.out.println("not disjoint"); if(instanceBasedDisjoints) { - SortedSet<Individual> tmp = rs.getIndividuals(index); - tmp.removeAll(rs.getIndividuals(new Negation(candidate))); + SortedSet<Individual> tmp = reasoner.getIndividuals(index); + tmp.removeAll(reasoner.getIndividuals(new Negation(candidate))); meaningful = tmp.size() != 0; // System.out.println("instances " + tmp.size()); } else { @@ -1272,14 +1304,14 @@ mgdd.put(domain, new TreeSet<DatatypeProperty>()); mgsd.put(domain, new TreeSet<DatatypeProperty>()); - SortedSet<ObjectProperty> mostGeneral = rs.getMostGeneralProperties(); + SortedSet<ObjectProperty> mostGeneral = reasoner.getMostGeneralProperties(); computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); - SortedSet<DatatypeProperty> mostGeneralDP = rs.getMostGeneralDatatypeProperties(); + SortedSet<DatatypeProperty> mostGeneralDP = reasoner.getMostGeneralDatatypeProperties(); // we make the (reasonable) assumption here that all sub and super // datatype properties have the same type (e.g. boolean, integer, double) - Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, rs.getBooleanDatatypeProperties()); - Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, rs.getDoubleDatatypeProperties()); - Set<DatatypeProperty> mostGeneralSDP = Helper.intersection(mostGeneralDP, rs.getStringDatatypeProperties()); + Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, reasoner.getBooleanDatatypeProperties()); + Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, reasoner.getDoubleDatatypeProperties()); + Set<DatatypeProperty> mostGeneralSDP = Helper.intersection(mostGeneralDP, reasoner.getStringDatatypeProperties()); computeMgbdRecursive(domain, mostGeneralBDP, mgbd.get(domain)); computeMgddRecursive(domain, mostGeneralDDP, mgdd.get(domain)); computeMgsdRecursive(domain, mostGeneralSDP, mgsd.get(domain)); @@ -1290,7 +1322,7 @@ if(appOP.get(domain).contains(prop)) mgrTmp.add(prop); else - computeMgrRecursive(domain, rs.getSubProperties(prop), mgrTmp); + computeMgrRecursive(domain, reasoner.getSubProperties(prop), mgrTmp); } } @@ -1299,7 +1331,7 @@ if(appBD.get(domain).contains(prop)) mgbdTmp.add(prop); else - computeMgbdRecursive(domain, rs.getSubProperties(prop), mgbdTmp); + computeMgbdRecursive(domain, reasoner.getSubProperties(prop), mgbdTmp); } } @@ -1308,7 +1340,7 @@ if(appDD.get(domain).contains(prop)) mgddTmp.add(prop); else - computeMgddRecursive(domain, rs.getSubProperties(prop), mgddTmp); + computeMgddRecursive(domain, reasoner.getSubProperties(prop), mgddTmp); } } @@ -1317,41 +1349,41 @@ if(appDD.get(domain).contains(prop)) mgsdTmp.add(prop); else - computeMgsdRecursive(domain, rs.getSubProperties(prop), mgsdTmp); + computeMgsdRecursive(domain, reasoner.getSubProperties(prop), mgsdTmp); } } // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { // object properties - Set<ObjectProperty> mostGeneral = rs.getObjectProperties(); + Set<ObjectProperty> mostGeneral = reasoner.getObjectProperties(); 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) - Description d = rs.getDomain(role); + Description d = reasoner.getDomain(role); if(!isDisjoint(domain,d)) applicableRoles.add(role); } appOP.put(domain, applicableRoles); // boolean datatype properties - Set<DatatypeProperty> mostGeneralBDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> mostGeneralBDPs = reasoner.getBooleanDatatypeProperties(); Set<DatatypeProperty> applicableBDPs = new TreeSet<DatatypeProperty>(); for(DatatypeProperty role : mostGeneralBDPs) { // Description d = (NamedClass) rs.getDomain(role); - Description d = rs.getDomain(role); + Description d = reasoner.getDomain(role); if(!isDisjoint(domain,d)) applicableBDPs.add(role); } appBD.put(domain, applicableBDPs); // double datatype properties - Set<DatatypeProperty> mostGeneralDDPs = rs.getDoubleDatatypeProperties(); + Set<DatatypeProperty> mostGeneralDDPs = reasoner.getDoubleDatatypeProperties(); Set<DatatypeProperty> applicableDDPs = new TreeSet<DatatypeProperty>(); for(DatatypeProperty role : mostGeneralDDPs) { // Description d = (NamedClass) rs.getDomain(role); - Description d = rs.getDomain(role); + Description d = reasoner.getDomain(role); // System.out.println("domain: " + d); if(!isDisjoint(domain,d)) applicableDDPs.add(role); @@ -1400,7 +1432,7 @@ result = isDisjointInstanceBased(d1,d2); } else { Description d = new Intersection(d1, d2); - result = rs.isSuperClassOf(new Nothing(), d); + result = reasoner.isSuperClassOf(new Nothing(), d); } // add the result to the cache (we add it twice such that // the order of access does not matter) @@ -1427,8 +1459,8 @@ } private boolean isDisjointInstanceBased(Description d1, Description d2) { - SortedSet<Individual> d1Instances = rs.getIndividuals(d1); - SortedSet<Individual> d2Instances = rs.getIndividuals(d2); + SortedSet<Individual> d1Instances = reasoner.getIndividuals(d1); + SortedSet<Individual> d2Instances = reasoner.getIndividuals(d2); // System.out.println(d1 + " " + d2); // System.out.println(d1 + " " + d1Instances); // System.out.println(d2 + " " + d2Instances); @@ -1459,7 +1491,7 @@ // if(tmp2==null) { Description notA = new Negation(a); Description d = new Intersection(notA, b); - Boolean result = rs.isSuperClassOf(new Nothing(), d); + Boolean result = reasoner.isSuperClassOf(new Nothing(), d); // ... add to cache ... return result; // } else @@ -1474,13 +1506,13 @@ Description notA = new Negation(a); Description d = new Intersection(notA, b); // check b subClassOf b AND NOT A (if yes then it is not meaningful) - return !rs.isSuperClassOf(d, b); + return !reasoner.isSuperClassOf(d, b); } private void computeSplits(DatatypeProperty dp) { Set<Double> valuesSet = new TreeSet<Double>(); // Set<Individual> individuals = rs.getIndividuals(); - Map<Individual,SortedSet<Double>> valueMap = rs.getDoubleDatatypeMembers(dp); + Map<Individual,SortedSet<Double>> valueMap = reasoner.getDoubleDatatypeMembers(dp); // add all values to the set (duplicates will be remove automatically) for(Entry<Individual,SortedSet<Double>> e : valueMap.entrySet()) valuesSet.addAll(e.getValue()); @@ -1507,4 +1539,108 @@ // System.out.println(splits); // System.exit(0); } + + public int getFrequencyThreshold() { + return frequencyThreshold; + } + + public void setFrequencyThreshold(int frequencyThreshold) { + this.frequencyThreshold = frequencyThreshold; + } + + public boolean isUseDataHasValueConstructor() { + return useDataHasValueConstructor; + } + + public void setUseDataHasValueConstructor(boolean useDataHasValueConstructor) { + this.useDataHasValueConstructor = useDataHasValueConstructor; + } + + public boolean isApplyAllFilter() { + return applyAllFilter; + } + + public void setApplyAllFilter(boolean applyAllFilter) { + this.applyAllFilter = applyAllFilter; + } + + public boolean isUseAllConstructor() { + return useAllConstructor; + } + + public void setUseAllConstructor(boolean useAllConstructor) { + this.useAllConstructor = useAllConstructor; + } + + public boolean isUseExistsConstructor() { + return useExistsConstructor; + } + + public void setUseExistsConstructor(boolean useExistsConstructor) { + this.useExistsConstructor = useExistsConstructor; + } + + public boolean isUseHasValueConstructor() { + return useHasValueConstructor; + } + + public void setUseHasValueConstructor(boolean useHasValueConstructor) { + this.useHasValueConstructor = useHasValueConstructor; + } + + public boolean isUseCardinalityRestrictions() { + return useCardinalityRestrictions; + } + + public void setUseCardinalityRestrictions(boolean useCardinalityRestrictions) { + this.useCardinalityRestrictions = useCardinalityRestrictions; + } + + public boolean isUseNegation() { + return useNegation; + } + + public void setUseNegation(boolean useNegation) { + this.useNegation = useNegation; + } + + public boolean isUseBooleanDatatypes() { + return useBooleanDatatypes; + } + + public void setUseBooleanDatatypes(boolean useBooleanDatatypes) { + this.useBooleanDatatypes = useBooleanDatatypes; + } + + public boolean isUseDoubleDatatypes() { + return useDoubleDatatypes; + } + + public void setUseDoubleDatatypes(boolean useDoubleDatatypes) { + this.useDoubleDatatypes = useDoubleDatatypes; + } + + public boolean isUseStringDatatypes() { + return useStringDatatypes; + } + + public void setUseStringDatatypes(boolean useStringDatatypes) { + this.useStringDatatypes = useStringDatatypes; + } + + public boolean isInstanceBasedDisjoints() { + return instanceBasedDisjoints; + } + + public void setInstanceBasedDisjoints(boolean instanceBasedDisjoints) { + this.instanceBasedDisjoints = instanceBasedDisjoints; + } + + public AbstractReasonerComponent getReasoner() { + return reasoner; + } + + public void setReasoner(AbstractReasonerComponent reasoner) { + this.reasoner = reasoner; + } } \ No newline at end of file Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/examples/family/father.conf 2011-08-24 14:38:09 UTC (rev 3116) @@ -10,7 +10,7 @@ // knowledge source definition ks.type = "KB file"; ks.url = "father.kb"; -ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. // reasoner reasoner.type = "fast instance checker"; @@ -20,6 +20,25 @@ embeddedReasoner.sources = {"component:kbFile"}; // learning problem -learningProblem.type = "posNegStandard"; -learningProblem.positiveExamples = {"stefan","markus","bernd"}; -learningProblem.negativeExamples = {"heinz","anna","gabi","michelle"}; +lp.type = "posNegStandard"; +lp.positiveExamples = {"stefan","markus","bernd"}; +lp.negativeExamples = {"heinz","anna","gabi","michelle"}; + +// TODO: the stuff below is untested and just shows what it could look like + +// plug a reasoner into the learning problem +lp.reasoner = reasoner; + +// create a refinement operator and configure it +op.type = "rho"; +op.useCardinalityRestrictions = true; + +// create a heuristic and configure it +h.type = "multiheuristic"; +h.expansionPenaltyFactor = 0.2; + +// create learning algorithm to run +alg.type = "ocel"; +alg.operator = component:op; +alg.learningProblem = component:lp; +alg.heuristic = component:h; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |