|
1 | 1 | /** |
2 | 2 | * Copyright (C) 2007 - 2016, Jens Lehmann |
3 | | - * |
| 3 | + * <p> |
4 | 4 | * This file is part of DL-Learner. |
5 | | - * |
| 5 | + * <p> |
6 | 6 | * DL-Learner is free software; you can redistribute it and/or modify |
7 | 7 | * it under the terms of the GNU General Public License as published by |
8 | 8 | * the Free Software Foundation; either version 3 of the License, or |
9 | 9 | * (at your option) any later version. |
10 | | - * |
| 10 | + * <p> |
11 | 11 | * DL-Learner is distributed in the hope that it will be useful, |
12 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 | * GNU General Public License for more details. |
15 | | - * |
| 15 | + * <p> |
16 | 16 | * You should have received a copy of the GNU General Public License |
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 | */ |
19 | 19 | package org.dllearner.learningproblems; |
20 | 20 |
|
| 21 | +import com.google.common.collect.Sets; |
21 | 22 | import org.dllearner.core.AbstractReasonerComponent; |
22 | 23 | import org.dllearner.core.ComponentAnn; |
23 | 24 | import org.dllearner.core.ComponentInitException; |
24 | 25 | import org.dllearner.core.EvaluatedDescription; |
25 | 26 | import org.dllearner.core.config.ConfigOption; |
| 27 | +import org.dllearner.utilities.Helper; |
26 | 28 | import org.semanticweb.owlapi.model.OWLClassExpression; |
27 | 29 | import org.semanticweb.owlapi.model.OWLIndividual; |
28 | 30 |
|
29 | 31 | import java.util.Set; |
30 | 32 | import java.util.SortedSet; |
31 | 33 | import java.util.TreeSet; |
| 34 | + |
32 | 35 | /** |
33 | 36 | * A ternary learning problem (positive, negative and uncertain instances) to manage the problem of the Open World Assumption |
34 | 37 | * typically employed for ontologies |
35 | 38 | * @author Utente |
36 | 39 | * |
37 | 40 | */ |
38 | | -@ComponentAnn(name="PosNegUndLP", shortName="posNegUndLP", version=1.0, description="A learning problem with uncertain-membership instances") |
39 | | -public class PosNegUndLP extends PosNegLPStandard implements Cloneable{ |
40 | | - //private SortedSet<OWLIndividual> positiveExample; |
41 | | - //private SortedSet<OWLIndividual> negativeExample; |
42 | | - @ConfigOption(description = "the uncertain examples", required = true) |
43 | | - private Set<OWLIndividual> uncertainExamples; |
44 | | - |
45 | | - // getter and setters |
46 | | - public Set<OWLIndividual> getPositiveExamples() { |
47 | | - return new TreeSet<>(super.getPositiveExamples()); |
48 | | - } |
| 41 | +@ComponentAnn(name = "PosNegUndLP", shortName = "posNegUndLP", version = 1.0, description = "A learning problem with uncertain-membership instances") |
| 42 | +public class PosNegUndLP extends PosNegLPStandard implements Cloneable { |
49 | 43 |
|
50 | | - public void setPositiveExamples(SortedSet<OWLIndividual> positiveExample) { |
51 | | - this.positiveExamples = positiveExample; |
52 | | - } |
| 44 | + @ConfigOption(description = "the uncertain examples", required = true) |
| 45 | + private Set<OWLIndividual> uncertainExamples; |
53 | 46 |
|
54 | | - public Set<OWLIndividual> getNegativeExamples() { |
55 | | - return new TreeSet<>(super.getNegativeExamples());//negativeExamples; |
56 | | - } |
| 47 | + public PosNegUndLP() {} |
57 | 48 |
|
58 | | - public void setNegativeExamples(Set<OWLIndividual> negativeExample) { |
59 | | - this.negativeExamples = negativeExample; |
| 49 | + public PosNegUndLP(AbstractReasonerComponent reasoner) { |
| 50 | + super(reasoner); |
60 | 51 | } |
61 | 52 |
|
62 | | - public Set<OWLIndividual> getUncertainExamples() { |
63 | | - return new TreeSet<>(uncertainExamples); |
| 53 | + public PosNegUndLP(AbstractReasonerComponent reasoningService, |
| 54 | + SortedSet<OWLIndividual> positiveExamples, |
| 55 | + SortedSet<OWLIndividual> negativeExamples, |
| 56 | + SortedSet<OWLIndividual> uncertainExamples) { |
| 57 | + super(reasoningService, positiveExamples, negativeExamples); |
| 58 | + this.uncertainExamples = uncertainExamples; |
64 | 59 | } |
65 | 60 |
|
66 | | - public void setUncertainExamples(Set<OWLIndividual> uncertainExample) { |
67 | | - this.uncertainExamples = uncertainExample; |
68 | | - } |
| 61 | + public Set<OWLIndividual> getPositiveExamples() { |
| 62 | + return new TreeSet<>(super.getPositiveExamples()); |
| 63 | + } |
69 | 64 |
|
70 | | - |
71 | | - |
72 | | - public PosNegUndLP(){ |
73 | | - |
74 | | - super(); |
75 | | - } |
| 65 | + public Set<OWLIndividual> getNegativeExamples() { |
| 66 | + return new TreeSet<>(super.getNegativeExamples()); |
| 67 | + } |
76 | 68 |
|
77 | | - public PosNegUndLP(AbstractReasonerComponent reasoner){ |
78 | | - super(reasoner); |
79 | | - |
80 | | - } |
| 69 | + public Set<OWLIndividual> getUncertainExamples() { |
| 70 | + return new TreeSet<>(uncertainExamples); |
| 71 | + } |
81 | 72 |
|
82 | | - public PosNegUndLP(AbstractReasonerComponent reasoningService, SortedSet<OWLIndividual> positiveExamples, SortedSet<OWLIndividual> negativeExamples, SortedSet<OWLIndividual> uncertainExamples){ |
83 | | - |
84 | | -// this.setReasoner(reasoningService); |
85 | | -// this.positiveExamples=positiveExamples; |
86 | | -// this.negativeExamples=negativeExamples; |
87 | | - super(reasoningService, positiveExamples, negativeExamples); |
88 | | - this.uncertainExamples=uncertainExamples; |
89 | | - } |
90 | | - |
91 | | - @Override |
92 | | - public void init() throws ComponentInitException { |
93 | | - initialized = true; |
94 | | - } |
| 73 | + public void setUncertainExamples(Set<OWLIndividual> uncertainExample) { |
| 74 | + this.uncertainExamples = uncertainExample; |
| 75 | + } |
95 | 76 |
|
96 | | - @Override |
97 | | - public ScorePosNeg computeScore(OWLClassExpression description) { |
98 | | - // TODO Auto-generated method stub |
99 | | - return super.computeScore(description); |
100 | | - } |
| 77 | + @Override |
| 78 | + public void init() throws ComponentInitException { |
| 79 | + // sanity check whether examples are contained in KB |
| 80 | + Helper.checkIndividuals(reasoner, Sets.union(Sets.union(positiveExamples, negativeExamples), uncertainExamples)); |
101 | 81 |
|
102 | | - @Override |
103 | | - public EvaluatedDescription evaluate(OWLClassExpression description) { |
104 | | - // TODO Auto-generated method stub |
105 | | - return super.evaluate(description); |
106 | | - } |
| 82 | + initialized = true; |
| 83 | + } |
| 84 | + |
| 85 | + //TODO add two methods: the first one performs classification by inducing the derived concept definition (see the source code of PosNegstandard ) |
| 86 | + // the second one performs classification with the induced algorithms.tree.models in order to deal with specific settings such as binary classification or missing values for TDTs and ETDTs |
107 | 87 |
|
108 | | - //TODO add two methods: the first one performs classification by inducing the derived concept definition (see the source code of PosNegstandard ) |
109 | | - // the second one performs classification with the induced algorithms.tree.models in order to deal with specific settings such as binary classification or missing values for TDTs and ETDTs |
110 | | - /** |
111 | | - * A method for binarizing a ternary learning problem. This is important to work if you want to run a method |
112 | | - * such as CELOE starting from randomly generated queries |
113 | | - * @return the pos/neg learning problem |
114 | | - */ |
115 | | - public PosNegLP getPosNegLP(){ |
116 | | - PosNegLPStandard binaryProblem= new PosNegLPStandard(getReasoner()); |
117 | | - binaryProblem.setPositiveExamples(getPositiveExamples()); |
118 | | - SortedSet<OWLIndividual> therestOfWorld= new TreeSet<>(); |
119 | | - //positive vs. the rest of world |
120 | | - therestOfWorld.addAll(getNegativeExamples()); |
121 | | - therestOfWorld.addAll(uncertainExamples); |
122 | | - binaryProblem.setNegativeExamples(therestOfWorld); |
| 88 | + /** |
| 89 | + * A method for binarizing a ternary learning problem. This is important to work if you want to run a method |
| 90 | + * such as CELOE starting from randomly generated queries |
| 91 | + * @return the pos/neg learning problem |
| 92 | + */ |
| 93 | + public PosNegLP getPosNegLP() { |
| 94 | + PosNegLP binaryProblem = new PosNegLPStandard(getReasoner()); |
| 95 | + binaryProblem.setPositiveExamples(getPositiveExamples()); |
| 96 | + SortedSet<OWLIndividual> therestOfWorld = new TreeSet<>(); |
| 97 | + //positive vs. the rest of world |
| 98 | + therestOfWorld.addAll(getNegativeExamples()); |
| 99 | + therestOfWorld.addAll(uncertainExamples); |
| 100 | + binaryProblem.setNegativeExamples(therestOfWorld); |
123 | 101 | // System.out.println(getPositiveExamples().size()+" "+therestOfWorld.size()); |
124 | | - |
125 | | - return binaryProblem; |
126 | | - } |
| 102 | + |
| 103 | + return binaryProblem; |
| 104 | + } |
127 | 105 |
|
128 | 106 | } |
0 commit comments