|
From: <lor...@us...> - 2014-05-22 02:22:20
|
Revision: 4269
http://sourceforge.net/p/dl-learner/code/4269
Author: lorenz_b
Date: 2014-05-22 02:22:16 +0000 (Thu, 22 May 2014)
Log Message:
-----------
Updated Maven libs.
Modified Paths:
--------------
trunk/components-core/pom.xml
trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java
trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java
trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java
trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java
trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java
trunk/examples/mutagenesis/train1.conf
trunk/pom.xml
trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java
trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java
trunk/test/qtl/alzheimer/train1.conf
Added Paths:
-----------
trunk/dllearner-parent.iml
Modified: trunk/components-core/pom.xml
===================================================================
--- trunk/components-core/pom.xml 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/pom.xml 2014-05-22 02:22:16 UTC (rev 4269)
@@ -115,12 +115,15 @@
<artifactId>log4j</artifactId>
</dependency>
- <!-- Latest JENA ARQ - we have to exclude XercesImpl and use an older version here because use version bei JENA leads to some errors -->
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
-
</dependency>
+
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-core</artifactId>
+ </dependency>
<!--JSON is in Central -->
<dependency>
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -118,7 +118,6 @@
public ELLearningAlgorithm(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) {
super(problem, reasoner);
// configurator = new ELLearningAlgorithmConfigurator(this);
-
timeMonitor = MonitorFactory.getTimeMonitor("time");
}
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -8,7 +8,6 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
@@ -17,11 +16,12 @@
import java.util.SortedSet;
import java.util.TreeSet;
-import org.apache.commons.collections.ListUtils;
import org.apache.log4j.Logger;
import org.dllearner.algorithms.qtl.cache.QueryTreeCache;
import org.dllearner.algorithms.qtl.datastructures.QueryTree;
+import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl;
import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy;
+import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeSubsumptionStrategy;
import org.dllearner.algorithms.qtl.operations.lgg.EvaluatedQueryTree;
import org.dllearner.algorithms.qtl.operations.lgg.LGGGenerator;
import org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorImpl;
@@ -31,9 +31,7 @@
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.KnowledgeSource;
-import org.dllearner.core.LearningProblem;
import org.dllearner.core.LearningProblemUnsupportedException;
-import org.dllearner.core.Score;
import org.dllearner.core.config.ConfigOption;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Individual;
@@ -43,7 +41,6 @@
import org.dllearner.learningproblems.Heuristics;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.learningproblems.QueryTreeScore;
-import org.dllearner.learningproblems.ScoreTwoValued;
import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor;
import org.dllearner.utilities.owl.OWLAPIConverter;
import org.semanticweb.owlapi.io.ToStringRenderer;
@@ -141,6 +138,11 @@
super(qtl.getLearningProblem(), qtl.getReasoner());
this.model = ModelFactory.createDefaultModel();
this.model.add(qtl.model);
+ this.beta = qtl.beta;
+ this.maxExecutionTimeInSeconds = qtl.maxExecutionTimeInSeconds;
+ this.maxTreeComputationTimeInSeconds = qtl.maxTreeComputationTimeInSeconds;
+ this.tryFullCoverage = qtl.tryFullCoverage;
+ this.stopOnFirstDefinition = qtl.stopOnFirstDefinition;
}
public EvaluatedQueryTree<String> getBestSolution(){
@@ -160,10 +162,10 @@
lggGenerator = new LGGGeneratorImpl<String>();
-// if(heuristic == null){
+ if(heuristic == null){
heuristic = new QueryTreeHeuristic();
heuristic.setPosExamplesWeight(beta);
-// }
+ }
logger.info("Initializing...");
treeCache = new QueryTreeCache(model);
@@ -218,12 +220,7 @@
*/
@Override
public void start() {
- String setup = "Setup:";
- setup += "\n#Pos. examples:" + currentPosExamples.size();
- setup += "\n#Neg. examples:" + currentNegExamples.size();
- setup += "Heuristic:" + heuristic.getHeuristicType().name();
- setup += "\nbeta=" + beta;
- logger.info(setup);
+ showSetup();
logger.info("Running...");
startTime = System.currentTimeMillis();
@@ -235,12 +232,9 @@
logger.info("#Remaining pos. examples:" + currentPosExampleTrees.size());
logger.info("#Remaining neg. examples:" + currentNegExampleTrees.size());
- //compute a (partial) solution
- computeBestPartialSolution();
+ //compute best (partial) solution computed so far
+ EvaluatedQueryTree<String> bestPartialSolution = computeBestPartialSolution();
- //pick best (partial) solution computed so far
- EvaluatedQueryTree<String> bestPartialSolution = currentPartialSolutions.first();
-
//add if some criteria are satisfied
if(bestPartialSolution.getScore() >= minimumTreeScore){
@@ -284,12 +278,13 @@
}
- private void computeBestPartialSolution(){
+ private EvaluatedQueryTree<String> computeBestPartialSolution(){
logger.info("Computing best partial solution...");
bestCurrentScore = Double.NEGATIVE_INFINITY;
partialSolutionStartTime = System.currentTimeMillis();
initTodoList(currentPosExampleTrees, currentNegExampleTrees);
+ EvaluatedQueryTree<String> bestPartialSolutionTree = null;
EvaluatedQueryTree<String> currentElement;
QueryTree<String> currentTree;
while(!partialSolutionTerminationCriteriaSatisfied()){
@@ -307,30 +302,34 @@
lggMon.stop();
//evaluate the LGG
- EvaluatedQueryTree<String> solution = evaluate(lgg, true);
- double score = solution.getScore();
- double mas = heuristic.getMaximumAchievableScore(solution);
-
- if(score >= bestCurrentScore){
- //add to todo list, if not already contained in todo list or solution list
- todo(solution);
- if(score > bestCurrentScore){
- logger.info("\tGot better solution:" + solution.getTreeScore());
+ Set<EvaluatedQueryTree<String>> solutions = evaluate(lgg, true);
+ for (EvaluatedQueryTree<String> solution : solutions) {
+ double score = solution.getScore();
+ double mas = heuristic.getMaximumAchievableScore(solution);
+
+ if(score >= bestCurrentScore){
+ //add to todo list, if not already contained in todo list or solution list
+ todo(solution);
+ if(score > bestCurrentScore){
+ logger.info("\tGot better solution:" + solution.getTreeScore());
+ bestCurrentScore = score;
+ bestPartialSolutionTree = solution;
+ }
+
+ } else if(mas >= bestCurrentScore){
+ todo(solution);
+ } else {
+// System.out.println("Too general");
+// System.out.println("MAS=" + mas + "\nBest=" + bestCurrentScore);
}
- bestCurrentScore = solution.getScore();
- } else if(mas < bestCurrentScore){
- todo(solution);
- } else {
- System.out.println("Too general");
+ currentPartialSolutions.add(currentElement);
}
- currentPartialSolutions.add(currentElement);
-
}
currentPartialSolutions.add(currentElement);
}
long endTime = System.currentTimeMillis();
logger.info("...finished in " + (endTime-partialSolutionStartTime) + "ms.");
- EvaluatedDescription bestPartialSolution = currentPartialSolutions.first().asEvaluatedDescription();
+ EvaluatedDescription bestPartialSolution = bestPartialSolutionTree.asEvaluatedDescription(LiteralNodeConversionStrategy.SOME_VALUES_FROM);
logger.info("Best partial solution: " + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()).toString().replace("\n", "") + "\n(" + bestPartialSolution.getScore() + ")");
@@ -340,9 +339,11 @@
logger.trace("Subsumption test time: " + subMon.getTotal() + "ms");
logger.trace("Avg. subsumption test time: " + subMon.getAvg() + "ms");
logger.trace("#Subsumption tests: " + subMon.getHits());
+
+ return bestPartialSolutionTree;
}
- private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){
+ private EvaluatedQueryTree<String> evaluateSimple(QueryTree<String> tree, boolean useSpecifity){
//1. get a score for the coverage = recall oriented
//compute positive examples which are not covered by LGG
List<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees);
@@ -399,45 +400,191 @@
return evaluatedTree;
}
- private EvaluatedDescription buildCombinedSolution(){
- if(partialSolutions.size() == 1){
- EvaluatedDescription combinedSolution = partialSolutions.get(0).asEvaluatedDescription();
- return combinedSolution;
+ /**
+ * Returns a set of evaluated query trees. A set is returned because there are several ways how to convert literal nodes.
+ * @param tree
+ * @param useSpecifity
+ * @return
+ */
+ private Set<EvaluatedQueryTree<String>> evaluate(QueryTree<String> tree, boolean useSpecifity){
+ Set<EvaluatedQueryTree<String>> evaluatedTrees = new TreeSet<EvaluatedQueryTree<String>>();
+
+ LiteralNodeSubsumptionStrategy[] strategies = LiteralNodeSubsumptionStrategy.values();
+ strategies = new LiteralNodeSubsumptionStrategy[]{LiteralNodeSubsumptionStrategy.DATATYPE, LiteralNodeSubsumptionStrategy.INTERVAL};
+ for (LiteralNodeSubsumptionStrategy strategy : strategies) {
+ //1. get a score for the coverage = recall oriented
+ List<QueryTree<String>> uncoveredPositiveExampleTrees = new ArrayList<QueryTree<String>>();
+ List<QueryTree<String>> coveredNegativeExampleTrees = new ArrayList<QueryTree<String>>();
+
+ //compute positive examples which are not covered by LGG
+ for (QueryTree<String> posTree : currentPosExampleTrees) {
+ if(!posTree.isSubsumedBy(tree, strategy)){
+ uncoveredPositiveExampleTrees.add(posTree);
+ }
+ }
+ //compute negative examples which are covered by LGG
+ for (QueryTree<String> negTree : currentNegExampleTrees) {
+ if(negTree.isSubsumedBy(tree, strategy)){
+ coveredNegativeExampleTrees.add(negTree);
+ }
+ }
+ //convert to individuals
+ Set<Individual> uncoveredPosExamples = asIndividuals(uncoveredPositiveExampleTrees);
+ Set<Individual> coveredNegExamples = asIndividuals(coveredNegativeExampleTrees);
+
+ //compute score
+ int coveredPositiveExamples = currentPosExampleTrees.size() - uncoveredPositiveExampleTrees.size();
+ double recall = coveredPositiveExamples / (double)currentPosExampleTrees.size();
+ double precision = (coveredNegativeExampleTrees.size() + coveredPositiveExamples == 0)
+ ? 0
+ : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size());
+
+ double coverageScore = Heuristics.getFScore(recall, precision, beta);
+
+ //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented
+ int nrOfSpecificNodes = 0;
+ for (QueryTree<String> childNode : tree.getChildrenClosure()) {
+ if(!childNode.getUserObject().equals("?")){
+ nrOfSpecificNodes++;
+ }
+ }
+ double specifityScore = 0d;
+ if(useSpecifity){
+ specifityScore = Math.log(nrOfSpecificNodes);
+ }
+
+ //3.compute the total score
+ double score = coverageWeight * coverageScore + specifityWeight * specifityScore;
+
+ QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore,
+ new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples,
+ coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)),
+ specifityScore, nrOfSpecificNodes);
+
+ EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, uncoveredPositiveExampleTrees, coveredNegativeExampleTrees, queryTreeScore);
+
+ //TODO use only the heuristic to compute the score
+ score = heuristic.getScore(evaluatedTree);
+ queryTreeScore.setScore(score);
+ queryTreeScore.setAccuracy(score);
+
+ evaluatedTrees.add(evaluatedTree);
}
- List<Description> disjuncts = new ArrayList<Description>();
- Set<Individual> posCovered = new HashSet<Individual>();
- Set<Individual> negCovered = new HashSet<Individual>();
+ return evaluatedTrees;
+ }
+
+ /**
+ * Returns a set of evaluated query trees. A set is returned because there are several ways how to convert literal nodes.
+ * @param tree
+ * @param useSpecifity
+ * @return
+ */
+ private Set<EvaluatedDescription> evaluate2(QueryTree<String> tree, boolean useSpecifity){
+ Set<EvaluatedDescription> evaluatedDescriptions = new TreeSet<EvaluatedDescription>();
- //build the union of all class expressions
- Description partialDescription;
- for (EvaluatedQueryTree<String> partialSolution : partialSolutions) {
- partialDescription = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(
- partialSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION));
- disjuncts.add(partialDescription);
- posCovered.addAll(partialSolution.getTreeScore().getCoveredPositives());
- negCovered.addAll(partialSolution.getTreeScore().getCoveredNegatives());
+ LiteralNodeConversionStrategy[] strategies = LiteralNodeConversionStrategy.values();
+ strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.SOME_VALUES_FROM, LiteralNodeConversionStrategy.FACET_RESTRICTION};
+ for (LiteralNodeConversionStrategy strategy : strategies) {
+ Description d = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(tree.asOWLClassExpression(strategy));
+ //convert to individuals
+ SortedSet<Individual> coveredExamples = reasoner.getIndividuals(d);
+ Set<Individual> coveredPosExamples = new TreeSet<Individual>(Sets.intersection(currentPosExamples, coveredExamples));
+ Set<Individual> uncoveredPosExamples = new TreeSet<Individual>(Sets.difference(currentPosExamples, coveredExamples));
+ Set<Individual> coveredNegExamples = new TreeSet<Individual>(Sets.intersection(currentNegExamples, coveredExamples));
+
+ //compute score
+ double recall = coveredPosExamples.size() / (double)currentPosExamples.size();
+ double precision = (coveredNegExamples.size() + coveredPosExamples.size() == 0)
+ ? 0
+ : coveredPosExamples.size() / (double)(coveredPosExamples.size() + coveredNegExamples.size());
+
+ double coverageScore = Heuristics.getFScore(recall, precision, beta);
+
+ //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented
+ int nrOfSpecificNodes = 0;
+ for (QueryTree<String> childNode : tree.getChildrenClosure()) {
+ if(!childNode.getUserObject().equals("?")){
+ nrOfSpecificNodes++;
+ }
+ }
+ double specifityScore = 0d;
+ if(useSpecifity){
+ specifityScore = Math.log(nrOfSpecificNodes);
+ }
+
+ //3.compute the total score
+ double score = coverageWeight * coverageScore + specifityWeight * specifityScore;
+
+ QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore,
+ new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples,
+ coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)),
+ specifityScore, nrOfSpecificNodes);
+
+ //TODO use only the heuristic to compute the score
+// score = heuristic.getScore(evaluatedTree);
+// queryTreeScore.setScore(score);
+// queryTreeScore.setAccuracy(score);
+//
+// EvaluatedDescription evaluatedDescription = new EvaluatedDescription(d, queryTreeScore);
+//
+// evaluatedDescriptions.add(evaluatedDescription);
}
- Description unionDescription = new Union(disjuncts);
- Set<Individual> posNotCovered = Sets.difference(lp.getPositiveExamples(), posCovered);
- Set<Individual> negNotCovered = Sets.difference(lp.getNegativeExamples(), negCovered);
-
- //compute the coverage
- double recall = posCovered.size() / (double)lp.getPositiveExamples().size();
- double precision = (posCovered.size() + negCovered.size() == 0)
- ? 0
- : posCovered.size() / (double)(posCovered.size() + negCovered.size());
-
- double coverageScore = Heuristics.getFScore(recall, precision, beta);
-
-// ScoreTwoValued score = new ScoreTwoValued(posCovered, posNotCovered, negCovered, negNotCovered);
-// score.setAccuracy(coverageScore);
- QueryTreeScore score = new QueryTreeScore(coverageScore, coverageScore, posCovered, posNotCovered, negCovered, negNotCovered, -1, -1);
-
- return new EvaluatedDescription(unionDescription, score);
+ return evaluatedDescriptions;
}
+ private EvaluatedDescription buildCombinedSolution(){
+ EvaluatedDescription bestCombinedSolution = null;
+ double bestScore = Double.NEGATIVE_INFINITY;
+ LiteralNodeConversionStrategy[] strategies = LiteralNodeConversionStrategy.values();
+ strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.SOME_VALUES_FROM};
+ for (LiteralNodeConversionStrategy strategy : strategies) {
+ EvaluatedDescription combinedSolution;
+ if(partialSolutions.size() == 1){
+ combinedSolution = partialSolutions.get(0).asEvaluatedDescription(strategy);
+ } else {
+ List<Description> disjuncts = new ArrayList<Description>();
+
+ Set<Individual> posCovered = new HashSet<Individual>();
+ Set<Individual> negCovered = new HashSet<Individual>();
+
+ //build the union of all class expressions
+ Description partialDescription;
+ for (EvaluatedQueryTree<String> partialSolution : partialSolutions) {
+ partialDescription = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(
+ partialSolution.getTree().asOWLClassExpression(strategy));
+ disjuncts.add(partialDescription);
+ posCovered.addAll(partialSolution.getTreeScore().getCoveredPositives());
+ negCovered.addAll(partialSolution.getTreeScore().getCoveredNegatives());
+ }
+ Description unionDescription = new Union(disjuncts);
+
+ Set<Individual> posNotCovered = Sets.difference(lp.getPositiveExamples(), posCovered);
+ Set<Individual> negNotCovered = Sets.difference(lp.getNegativeExamples(), negCovered);
+
+ //compute the coverage
+ double recall = posCovered.size() / (double)lp.getPositiveExamples().size();
+ double precision = (posCovered.size() + negCovered.size() == 0)
+ ? 0
+ : posCovered.size() / (double)(posCovered.size() + negCovered.size());
+
+ double coverageScore = Heuristics.getFScore(recall, precision, beta);
+
+// ScoreTwoValued score = new ScoreTwoValued(posCovered, posNotCovered, negCovered, negNotCovered);
+// score.setAccuracy(coverageScore);
+ QueryTreeScore score = new QueryTreeScore(coverageScore, coverageScore, posCovered, posNotCovered, negCovered, negNotCovered, -1, -1);
+
+ combinedSolution = new EvaluatedDescription(unionDescription, score);
+ }
+ if(combinedSolution.getAccuracy() > bestScore){
+ bestCombinedSolution = combinedSolution;
+ bestCurrentScore = combinedSolution.getAccuracy();
+ }
+ }
+ return bestCombinedSolution;
+ }
+
private void reset(){
currentBestSolution = null;
partialSolutions = new ArrayList<EvaluatedQueryTree<String>>();
@@ -524,7 +671,20 @@
return treeCache;
}
+ private Set<Individual> asIndividuals(Collection<QueryTree<String>> trees){
+ Set<Individual> individuals = new HashSet<Individual>(trees.size());
+ for (QueryTree<String> queryTree : trees) {
+ individuals.add(tree2Individual.get(queryTree));
+ }
+ return individuals;
+ }
+ private void asTree(Description d){
+ QueryTree<String> tree = new QueryTreeImpl<String>("");
+ for (Description child : d.getChildren()) {
+
+ }
+ }
/**
* Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}.
@@ -587,7 +747,7 @@
}
}
for (QueryTree<String> queryTree : distinctTrees) {//System.out.println(queryTree.getStringRepresentation());
- EvaluatedQueryTree<String> evaluatedQueryTree = evaluate(queryTree, false);
+ EvaluatedQueryTree<String> evaluatedQueryTree = evaluateSimple(queryTree, false);
todoList.add(evaluatedQueryTree);
}
}
@@ -656,6 +816,18 @@
}
/**
+ * Shows the current setup of the algorithm.
+ */
+ private void showSetup(){
+ String setup = "Setup:";
+ setup += "\n#Pos. examples:" + currentPosExamples.size();
+ setup += "\n#Neg. examples:" + currentNegExamples.size();
+ setup += "\nHeuristic:" + heuristic.getHeuristicType().name();
+ setup += "\nbeta=" + beta;
+ logger.info(setup);
+ }
+
+ /**
* @param noisePercentage the noisePercentage to set
*/
public void setNoisePercentage(double noisePercentage) {
@@ -684,6 +856,20 @@
this.maxTreeComputationTimeInSeconds = maxTreeComputationTimeInSeconds;
}
+ /**
+ * @return the heuristic
+ */
+ public QueryTreeHeuristic getHeuristic() {
+ return heuristic;
+ }
+
+ /**
+ * @param heuristic the heuristic to set
+ */
+ public void setHeuristic(QueryTreeHeuristic heuristic) {
+ this.heuristic = heuristic;
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -106,15 +106,19 @@
double mas = 0d;
switch (heuristicType) {
case FMEASURE:
+ mas = Double.POSITIVE_INFINITY;
break;
case PRED_ACC:
mas = (posExamplesWeight * tp + tn - fp) / (posExamplesWeight * (tp + fn) + tn + fp);
break;
case ENTROPY:
+ mas = Double.POSITIVE_INFINITY;
break;
case MATTHEWS_CORRELATION:
+ mas = Double.POSITIVE_INFINITY;
break;
case YOUDEN_INDEX:
+ mas = Double.POSITIVE_INFINITY;
break;
default:
break;
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -87,6 +87,8 @@
void addChild(QueryTreeImpl<N> child, Object edge);
+ void addChild(QueryTree<N> child, Object edge);
+
void addChild(QueryTreeImpl<N> child, Object edge, int position);
int removeChild(QueryTreeImpl<N> child);
@@ -150,6 +152,8 @@
RDFDatatype getDatatype();
Set<Literal> getLiterals();
+
+ void setParent(QueryTree<N> parent);
/**
* @param edge
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -53,6 +53,9 @@
import org.jgrapht.ext.GraphMLExporter;
import org.jgrapht.ext.VertexNameProvider;
import org.jgrapht.graph.DefaultDirectedGraph;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
@@ -101,6 +104,8 @@
public enum LiteralNodeSubsumptionStrategy {
DATATYPE,
INTERVAL,
+ MIN,
+ MAX,
ENUMERATION,
OFF
}
@@ -117,7 +122,11 @@
/**
* Literals as datatype, e.g. xsd:integer
*/
- SOME_VALUES_FROM
+ SOME_VALUES_FROM,
+
+ MIN,
+
+ MAX,
}
private N userObject;
@@ -169,7 +178,12 @@
}
public QueryTreeImpl(N userObject, NodeType nodeType) {
+ this(userObject, nodeType, 0);
+ }
+
+ public QueryTreeImpl(N userObject, NodeType nodeType, int id) {
this.userObject = userObject;
+ this.id = id;
children = new ArrayList<QueryTreeImpl<N>>();
child2EdgeMap = new HashMap<QueryTree<N>, Object>();
edge2ChildrenMap = new HashMap<String, List<QueryTree<N>>>();
@@ -305,13 +319,33 @@
this.parent = parent;
this.parent.children.add(this);
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.algorithms.qtl.datastructures.QueryTree#setParent(org.dllearner.algorithms.qtl.datastructures.QueryTree)
+ */
+ @Override
+ public void setParent(QueryTree<N> parent) {
+ setParent((QueryTreeImpl<N>)parent);
+ }
-
public void addChild(QueryTreeImpl<N> child) {
children.add(child);
child.parent = this;
}
+ public void addChild(QueryTree<N> child) {
+ children.add((QueryTreeImpl<N>) child);
+ child.setParent(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.algorithms.qtl.datastructures.QueryTree#addChild(org.dllearner.algorithms.qtl.datastructures.QueryTree, java.lang.Object)
+ */
+ @Override
+ public void addChild(QueryTree<N> child, Object edge) {
+ addChild((QueryTreeImpl<N>)child, edge);
+ }
+
@Override
public void addChild(QueryTreeImpl<N> child, int position) {
children.add(position, child);
@@ -516,10 +550,13 @@
private boolean subsumes(Set<Literal> subsumer, Set<Literal> subsumee, LiteralNodeSubsumptionStrategy strategy){
if(strategy == LiteralNodeSubsumptionStrategy.DATATYPE){
-
+ //check if both datatypes are the same
+ RDFDatatype subsumerDatatype = getDatatype(subsumer);
+ RDFDatatype subsumeeDatatype = getDatatype(subsumee);
+ return subsumerDatatype.equals(subsumeeDatatype);
} else if(strategy == LiteralNodeSubsumptionStrategy.ENUMERATION){
return subsumer.containsAll(subsumee);
- } else if(strategy == LiteralNodeSubsumptionStrategy.INTERVAL){
+ } else {
//check if both datatypes are the same
RDFDatatype subsumerDatatype = getDatatype(subsumer);
RDFDatatype subsumeeDatatype = getDatatype(subsumee);
@@ -532,19 +569,35 @@
return true;
}
- //check if subsumee interval is contained in subsumer interval
- Literal subsumerMin = getMin(subsumer);
- Literal subsumerMax = getMax(subsumer);
+ if(strategy == LiteralNodeSubsumptionStrategy.INTERVAL){
+ //check if subsumee interval is contained in subsumer interval
+ Literal subsumerMin = getMin(subsumer);
+ Literal subsumerMax = getMax(subsumer);
+
+ Literal subsumeeMin = getMin(subsumee);
+ Literal subsumeeMax = getMax(subsumee);
+
+ boolean leftMoreGeneral = isLessOrEqual(subsumerMin, subsumeeMin);
+ boolean rightMoreGeneral = isGreaterOrEqual(subsumerMax, subsumeeMax);
+
+ if(!(leftMoreGeneral && rightMoreGeneral)){
+ // System.out.println("[" + subsumeeMin + "," + subsumeeMax + "] not in interval " + "[" + subsumerMin + "," + subsumerMax + "]");
+ return false;
+ }
+ } else if(strategy == LiteralNodeSubsumptionStrategy.MIN){
- Literal subsumeeMin = getMin(subsumee);
- Literal subsumeeMax = getMax(subsumee);
+ //check if subsumee min is greater than subsumer min
+ Literal subsumerMin = getMin(subsumer);
+ Literal subsumeeMin = getMin(subsumee);
+
+ return isGreaterOrEqual(subsumeeMin, subsumerMin);
+ } else if(strategy == LiteralNodeSubsumptionStrategy.MAX){
- boolean leftMoreGeneral = isLessOrEqual(subsumerMin, subsumeeMin);
- boolean rightMoreGeneral = isGreaterOrEqual(subsumerMax, subsumeeMax);
-
- if(!(leftMoreGeneral && rightMoreGeneral)){
-// System.out.println("[" + subsumeeMin + "," + subsumeeMax + "] not in interval " + "[" + subsumerMin + "," + subsumerMax + "]");
- return false;
+ //check if subsumee min is greater than subsumer min
+ Literal subsumerMax = getMax(subsumer);
+ Literal subsumeeMax = getMax(subsumee);
+
+ return isGreaterOrEqual(subsumerMax, subsumeeMax);
}
}
return true;
@@ -1417,6 +1470,10 @@
dataRange = asDataOneOf(df, literals);
} else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.FACET_RESTRICTION){
dataRange = asFacet(df, literals);
+ } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.MIN){
+ dataRange = asMinFacet(df, literals);
+ } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.MAX){
+ dataRange = asMaxFacet(df, literals);
}
}
classExpressions.add(df.getOWLDataSomeValuesFrom(p, dataRange));
@@ -1462,6 +1519,30 @@
return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), minRestriction, maxRestriction);
}
+ private OWLDataRange asMinFacet(OWLDataFactory df, Set<Literal> literals){
+ //return Boolean datatype because it doesn't make sense to return a facet of Boolean values
+ if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){
+ return df.getBooleanOWLDatatype();
+ }
+ Literal min = getMin(literals);
+
+ OWLFacetRestriction minRestriction = df.getOWLFacetRestriction(OWLFacet.MIN_INCLUSIVE, asOWLLiteral(df, min));
+
+ return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), minRestriction);
+ }
+
+ private OWLDataRange asMaxFacet(OWLDataFactory df, Set<Literal> literals){
+ //return Boolean datatype because it doesn't make sense to return a facet of Boolean values
+ if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){
+ return df.getBooleanOWLDatatype();
+ }
+ Literal max = getMax(literals);
+
+ OWLFacetRestriction maxRestriction = df.getOWLFacetRestriction(OWLFacet.MAX_INCLUSIVE, asOWLLiteral(df, max));
+
+ return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), maxRestriction);
+ }
+
private OWLDataRange asDataOneOf(OWLDataFactory df, Set<Literal> literals){
//return Boolean datatype because it doesn't make sense to return a enumeration of Boolean values
if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){
@@ -1506,6 +1587,45 @@
}
}
+ public String asJSON(){
+
+ PrefixCCMap prefixes = PrefixCCMap.getInstance();
+ JSONObject json = null;
+ try {
+ json = buildJSON(this, prefixes);
+ JSONArray array = new JSONArray();
+ buildJSON2(array, this, prefixes);
+ System.out.println(array);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+
+ return json.toString();
+ }
+
+ private JSONObject buildJSON(QueryTree<N> tree, PrefixCCMap prefixes) throws JSONException{
+ JSONObject json = new JSONObject();
+ json.put("name", prefixed(prefixes, tree.getUserObject().toString()));
+ JSONArray children = new JSONArray();
+ for (QueryTree<N> child : tree.getChildren()) {
+ children.put(buildJSON(child, prefixes));
+ }
+ json.put("children", children);
+ return json;
+ }
+
+ private void buildJSON2(JSONArray array, QueryTree<N> tree, PrefixCCMap prefixes) throws JSONException{
+ for (QueryTree<N> child : tree.getChildren()) {
+ JSONObject json = new JSONObject();
+ json.put("source", tree.getId());
+ json.put("target", child.getId());
+ json.put("type", prefixed(prefixes, tree.getEdge(child).toString()));
+ array.put(json);
+ buildJSON2(array, child, prefixes);
+ }
+ }
+
private String prefixed(Map<String, String> prefixes, String uri){
if(uri.startsWith("http://")){
for (Entry<String, String> entry : prefixes.entrySet()) {
@@ -1561,5 +1681,9 @@
e.printStackTrace();
}
}
+
+
+
+
}
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -8,6 +8,9 @@
import org.dllearner.learningproblems.QueryTreeScore;
import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor;
+import com.google.common.collect.ComparisonChain;
+import com.google.common.collect.Ordering;
+
public class EvaluatedQueryTree<N> implements Comparable<EvaluatedQueryTree<N>>{
private QueryTree<N> tree;
@@ -57,14 +60,17 @@
@Override
public int compareTo(EvaluatedQueryTree<N> other) {
- double diff = getScore() - other.getScore();
- if(diff == 0){
- return -1;
- } else if(diff > 0){
- return -1;
- } else {
- return 1;
- }
+ return ComparisonChain.start()
+ .compare(this.getScore(), other.getScore())
+ .result();
+// double diff = getScore() - other.getScore();
+// if(diff == 0){
+// return -1;
+// } else if(diff > 0){
+// return -1;
+// } else {
+// return 1;
+// }
}
public EvaluatedDescription asEvaluatedDescription(){
@@ -72,6 +78,11 @@
getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)), score);
}
+ public EvaluatedDescription asEvaluatedDescription(LiteralNodeConversionStrategy strategy){
+ return new EvaluatedDescription(DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(
+ getTree().asOWLClassExpression(strategy)), score);
+ }
+
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -4,16 +4,65 @@
package org.dllearner.algorithms.qtl.util;
import java.util.Collection;
+import java.util.Stack;
import org.dllearner.algorithms.qtl.datastructures.QueryTree;
+import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl;
+import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.NodeType;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.io.ToStringRenderer;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassExpression;
+import org.semanticweb.owlapi.model.OWLClassExpressionVisitor;
+import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
+import org.semanticweb.owlapi.model.OWLDataComplementOf;
+import org.semanticweb.owlapi.model.OWLDataExactCardinality;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLDataHasValue;
+import org.semanticweb.owlapi.model.OWLDataIntersectionOf;
+import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
+import org.semanticweb.owlapi.model.OWLDataMinCardinality;
+import org.semanticweb.owlapi.model.OWLDataOneOf;
+import org.semanticweb.owlapi.model.OWLDataRangeVisitor;
+import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
+import org.semanticweb.owlapi.model.OWLDataUnionOf;
+import org.semanticweb.owlapi.model.OWLDatatype;
+import org.semanticweb.owlapi.model.OWLDatatypeRestriction;
+import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
+import org.semanticweb.owlapi.model.OWLObjectComplementOf;
+import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
+import org.semanticweb.owlapi.model.OWLObjectHasSelf;
+import org.semanticweb.owlapi.model.OWLObjectHasValue;
+import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
+import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
+import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
+import org.semanticweb.owlapi.model.OWLObjectOneOf;
+import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
+import org.semanticweb.owlapi.model.OWLObjectUnionOf;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.model.PrefixManager;
+import org.semanticweb.owlapi.reasoner.OWLReasoner;
+import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
+import org.semanticweb.owlapi.util.DefaultPrefixManager;
+import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer;
+
+import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
+import com.hp.hpl.jena.vocabulary.RDF;
+
/**
* Converts query trees into OWL class expressions and vice versa.
* @author Lorenz Buehmann
*
*/
-public class QueryTreeConverter {
+public class QueryTreeConverter implements OWLClassExpressionVisitor, OWLDataRangeVisitor{
+ Stack<QueryTree<String>> stack = new Stack<QueryTree<String>>();
+ int id = 0;
+
/**
* Returns a OWL class expression of the union of the given query trees.
* @param queryTrees
@@ -23,5 +72,246 @@
//check for common paths
}
+
+ public QueryTree<String> asQueryTree(OWLClassExpression expression){
+// stack.push(new QueryTreeImpl<String>("?"));
+ reset();
+ expression.accept(this);
+ return stack.pop();
+ }
+
+ private void reset(){
+ id = 0;
+ stack.clear();
+ }
+ private void fireUnsupportedFeatureException(OWLClassExpression expression) {
+ throw new IllegalArgumentException("Conversion of " + expression.getClass().getSimpleName() + " is not supported.");
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLClass)
+ */
+ @Override
+ public void visit(OWLClass cls) {
+ stack.peek().addChild(new QueryTreeImpl<String>(cls.toStringID(), NodeType.RESOURCE, id++), RDF.type.getURI());
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectIntersectionOf)
+ */
+ @Override
+ public void visit(OWLObjectIntersectionOf expr) {
+ boolean root = stack.isEmpty();
+ stack.push(new QueryTreeImpl<String>("?", NodeType.VARIABLE, id++));
+ for (OWLClassExpression op : expr.getOperandsAsList()) {
+ op.accept(this);
+ }
+// if(!root)
+// stack.pop();
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectUnionOf)
+ */
+ @Override
+ public void visit(OWLObjectUnionOf expr) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectComplementOf)
+ */
+ @Override
+ public void visit(OWLObjectComplementOf expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom)
+ */
+ @Override
+ public void visit(OWLObjectSomeValuesFrom expr) {
+ QueryTree<String> parent = stack.peek();
+ QueryTree<String> child;
+ OWLClassExpression filler = expr.getFiller();
+ if(filler.isAnonymous()){
+ if(!(filler instanceof OWLObjectIntersectionOf)){
+ stack.push(new QueryTreeImpl<String>("?", NodeType.VARIABLE, id++));
+ }
+ expr.getFiller().accept(this);
+ child = stack.pop();
+ } else {
+ child = new QueryTreeImpl<String>(filler.asOWLClass().toStringID(), NodeType.RESOURCE, id++);
+ }
+ parent.addChild(child, expr.getProperty().asOWLObjectProperty().toStringID());
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectAllValuesFrom)
+ */
+ @Override
+ public void visit(OWLObjectAllValuesFrom expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectHasValue)
+ */
+ @Override
+ public void visit(OWLObjectHasValue expr) {
+ QueryTree<String> tree = stack.peek();
+ tree.addChild(new QueryTreeImpl<String>(expr.getValue().asOWLNamedIndividual().toStringID(), NodeType.RESOURCE, id++), expr.getProperty().asOWLObjectProperty().toStringID());
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectMinCardinality)
+ */
+ @Override
+ public void visit(OWLObjectMinCardinality expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectExactCardinality)
+ */
+ @Override
+ public void visit(OWLObjectExactCardinality expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectMaxCardinality)
+ */
+ @Override
+ public void visit(OWLObjectMaxCardinality expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectHasSelf)
+ */
+ @Override
+ public void visit(OWLObjectHasSelf expr) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectOneOf)
+ */
+ @Override
+ public void visit(OWLObjectOneOf expr) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataSomeValuesFrom)
+ */
+ @Override
+ public void visit(OWLDataSomeValuesFrom expr) {
+ QueryTree<String> tree = stack.peek();
+ expr.getFiller().accept(this);
+ QueryTree<String> child = stack.pop();
+ tree.addChild(child, expr.getProperty().asOWLDataProperty().toStringID());
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataAllValuesFrom)
+ */
+ @Override
+ public void visit(OWLDataAllValuesFrom expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataHasValue)
+ */
+ @Override
+ public void visit(OWLDataHasValue expr) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataMinCardinality)
+ */
+ @Override
+ public void visit(OWLDataMinCardinality expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataExactCardinality)
+ */
+ @Override
+ public void visit(OWLDataExactCardinality expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataMaxCardinality)
+ */
+ @Override
+ public void visit(OWLDataMaxCardinality expr) {
+ fireUnsupportedFeatureException(expr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDatatype)
+ */
+ @Override
+ public void visit(OWLDatatype arg0) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataOneOf)
+ */
+ @Override
+ public void visit(OWLDataOneOf arg0) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataComplementOf)
+ */
+ @Override
+ public void visit(OWLDataComplementOf arg0) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataIntersectionOf)
+ */
+ @Override
+ public void visit(OWLDataIntersectionOf arg0) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataUnionOf)
+ */
+ @Override
+ public void visit(OWLDataUnionOf arg0) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDatatypeRestriction)
+ */
+ @Override
+ public void visit(OWLDatatypeRestriction arg0) {
+ }
+
+ public static void main(String[] args) throws Exception {
+ ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer());
+ OWLOntologyManager man = OWLManager.createOWLOntologyManager();
+ OWLDataFactory df = man.getOWLDataFactory();
+ PrefixManager pm = new DefaultPrefixManager("http://example.org/");
+ OWLClassExpression ce = df.getOWLObjectIntersectionOf(
+ df.getOWLClass("A", pm),
+ df.getOWLObjectSomeValuesFrom(
+ df.getOWLObjectProperty("p", pm),
+ df.getOWLObjectSomeValuesFrom(
+ df.getOWLObjectProperty("r", pm),
+ df.getOWLObjectIntersectionOf(
+ df.getOWLClass("A", pm),
+ df.getOWLClass("B", pm))))
+ );
+ System.out.println(ce);
+ QueryTreeConverter converter = new QueryTreeConverter();
+ QueryTree<String> tree = converter.asQueryTree(ce);
+ tree.dump();
+ }
+
}
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -58,11 +58,11 @@
* @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map)
*/
public String toString(String baseURI, Map<String, String> prefixes) {
- return " <= " + value;
+ return " double[<= " + value + "]";
}
public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " <= " + value;
+ return " double[<= " + value + "]";
}
public void accept(KBElementVisitor visitor) {
@@ -74,7 +74,7 @@
*/
@Override
public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " <= " + value;
+ return " double[<= " + value + "]";
}
/* (non-Javadoc)
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -58,11 +58,11 @@
* @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map)
*/
public String toString(String baseURI, Map<String, String> prefixes) {
- return " >= " + value;
+ return " double[>= " + value + "]";
}
public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " >= " + value;
+ return " double[>= " + value + "]";
}
public void accept(KBElementVisitor visitor) {
@@ -74,7 +74,7 @@
*/
@Override
public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " >= " + value;
+ return " double[>= " + value + "]";
}
/* (non-Javadoc)
Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -97,13 +97,16 @@
max = OWLAPIConverter.convertConstant(value);
}
}
- double minValue = Double.parseDouble(min.getLiteral());
- double maxValue = Double.parseDouble(max.getLiteral());
+
if(min != null && max != null){
+ double minValue = Double.parseDouble(min.getLiteral());
+ double maxValue = Double.parseDouble(max.getLiteral());
dataRange = new DoubleMinMaxRange(minValue, maxValue);
} else if(min != null && max == null){
+ double minValue = Double.parseDouble(min.getLiteral());
dataRange = new DoubleMinValue(minValue);
} else if(max != null && min == null){
+ double maxValue = Double.parseDouble(max.getLiteral());
dataRange = new DoubleMaxValue(maxValue);
} else {
Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java
===================================================================
--- trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -67,7 +67,7 @@
tree.dump();
System.out.println("-----------------------------");
cnt++;
- System.out.println(((QueryTreeImpl<String>)tree).toQuery());
+// System.out.println(((QueryTreeImpl<String>)tree).toQuery());
}
@@ -76,6 +76,7 @@
System.out.println("LGG");
lgg.dump();
+ System.out.println(((QueryTreeImpl<String>)lgg).asJSON());
QueryTreeImpl<String> tree = factory.getQueryTree("?");
QueryTreeImpl<String> subTree1 = new QueryTreeImpl<String>("?");
Added: trunk/dllearner-parent.iml
===================================================================
--- trunk/dllearner-parent.iml (rev 0)
+++ trunk/dllearner-parent.iml 2014-05-22 02:22:16 UTC (rev 4269)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
+
Modified: trunk/examples/mutagenesis/train1.conf
===================================================================
--- trunk/examples/mutagenesis/train1.conf 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/examples/mutagenesis/train1.conf 2014-05-22 02:22:16 UTC (rev 4269)
@@ -246,10 +246,11 @@
"kb:f6"
}
-alg.type = "ocel"
+alg.type = "celoe"
alg.noisePercentage = 30
alg.writeSearchTree = false
alg.startClass = "kb:Compound"
+alg.maxExecutionTimeInSeconds = 60
alg.searchTreeFile = "log/mutagenesis/searchTree.log"
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/pom.xml 2014-05-22 02:22:16 UTC (rev 4269)
@@ -195,7 +195,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
- <version>2.7.2</version>
+ <version>2.11.1</version>
</dependency>
<!--SwingX is in central -->
<dependency>
Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java
===================================================================
--- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -63,12 +63,12 @@
private static final Logger logger = Logger.getLogger(EProcurementUseCase.class.getName());
- static final int maxNrOfPositiveExamples = 100;
- static final int maxNrOfNegativeExamples = 200;
+ static final int maxNrOfPositiveExamples = 10000;
+ static final int maxNrOfNegativeExamples = 10000;
static boolean posOnly = false;
- static int maxCBDDepth = 2;
+ static int maxCBDDepth = 3;
static int maxNrOfResults = 100;
- static int maxExecutionTimeInSeconds = 200;
+ static int maxExecutionTimeInSeconds = 500;
static double noiseInPercentage = 50;
static boolean useNegation = false;
static boolean useAllConstructor = false;
@@ -117,10 +117,10 @@
// schema.read(new URL("http://opendata.cz/pco/public-contracts.ttl").openStream(), null, "TURTLE");
model.add(schema);
// get positive examples
- SortedSet<Individual> positiveExamples = getExamples(model, posClass);
+ SortedSet<Individual> positiveExamples = getExamples(model, posClass, maxNrOfPositiveExamples);
// get negative examples
// SortedSet<Individual> negativeExamples = getNegativeExamples(model, cls, positiveExamples);
- SortedSet<Individual> negativeExamples = getExamples(model, negClass);
+ SortedSet<Individual> negativeExamples = getExamples(model, negClass, maxNrOfNegativeExamples);
//get the lgg of the pos. examples
// showLGG(model, positiveExamples);
// build a sample of the kb
@@ -205,14 +205,14 @@
((QueryTreeImpl<String>) lgg).asGraph();
}
- private static SortedSet<Individual> getExamples(Model model, NamedClass cls){
+ private static SortedSet<Individual> getExamples(Model model, NamedClass cls, int limit){
logger.info("Generating examples...");
- SortedSet<Individual> individuals = new SPARQLReasoner(new LocalModelBasedSparqlEndpointKS(model)).getIndividuals(cls, 1000);
+ SortedSet<Individual> individuals = new SPARQLReasoner(new LocalModelBasedSparqlEndpointKS(model)).getIndividuals(cls, limit);
List<Individual> individualsList = new ArrayList<>(individuals);
// Collections.shuffle(individualsList, new Random(1234));
individuals.clear();
individuals.addAll(individualsList.subList(0, Math.min(maxNrOfPositiveExamples, individualsList.size())));
- logger.info("Done. Got " + individuals.size() + ": " + individuals);
+ logger.info("Done. Got " + individuals.size());
return individuals;
}
Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java
===================================================================
--- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-12 09:53:57 UTC (rev 4268)
+++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-22 02:22:16 UTC (rev 4269)
@@ -8,37 +8,30 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Layout;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
import org.dllearner.algorithms.qtl.QTL2Disjunctive;
import org.dllearner.algorithms.qtl.QueryTreeFactory;
-import org.dllearner.algorithms.qtl.datastructures.QueryTree;
-import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl;
+import org.dllearner.algorithms.qtl.QueryTreeHeuristic;
import org.dllearner.algorithms.qtl.impl.QueryTreeFactoryImpl;
import org.dllearner.cli.CLI;
import org.dllearner.cli.CrossValidation;
-import org.dllearner.core.AbstractLearningProblem;
+import org.dllearner.core.AbstractReasonerComponent;
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.LearningProblemUnsupportedException;
-import org.dllearner.core.owl.Individual;
-import org.dllearner.kb.OWLAPIOntology;
+import org.dllearner.learningproblems.Heuristics.HeuristicType;
import org.dllearner.learningproblems.PosNegLP;
-import org.dllearner.learningproblems.PosNegLPStandard;
-import org.dllearner.reasoning.FastInstanceChecker;
-import org.dllearner.scripts.NestedCrossValidation;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
@@ -48,11 +41,17 @@
*/
public class QTLEvaluation {
- int nrOfFolds = 3;
+ int nrOfFolds = 10;
private int nrOfPosExamples = 300;
private int nrOfNegExamples = 300;
- CLI cli = new CLI(new File("../test/qtl/carcinogenesis/train.conf"));
+ CLI carcinogenesis = new CLI(new File("../test/qtl/carcinogenesis/train.conf"));
+ CLI mammographic = new CLI(new File("../test/qtl/mammographic/train.conf"));
+ CLI suramin = new CLI(new File("../test/qtl/suramin/train.conf"));
+ CLI heart = new CLI(new File("../test/qtl/heart/train.conf"));
+ CLI breasttissue = new CLI(new File("../test/qtl/breasttissue/train1.conf"));
+ CLI parkinsons = new CLI(new File("../test/qtl/parkinsons/train.conf"));
+ CLI mutagenesis = new CLI(new File("../test/qtl/mutagenesis/train1.conf"));
private Model model;
private OWLOntology ontology;
@@ -65,7 +64,7 @@
queryTreeFactory = new QueryTreeFactoryImpl();
queryTreeFactory.setMaxDepth(3);
- loadDataset();
+// loadDataset();
loadExamples();
}
@@ -89,46 +88,100 @@
private void loadExamples() throws ComponentInitException, IOException{
- cli.init();
- lp = (PosNegLP) cli.getLearningProblem();
+// cli.init();
+// lp = (PosNegLP) cli.getLearningProblem();
// get examples and shuffle them
- List<Individual> posExamples = new LinkedList<Individual>(((PosNegLP)lp).getPositiveExamples());
- Collections.shuffle(posExamples, new Random(1));
- List<Individual> negExamples = new LinkedList<Individual>(((PosNegLP)lp).getNegativeExamples());
- Collections.shuffle(negExamples, new Random(2));
- posExamples = posExamples.subList(0, Math.min(posExamples.size(), nrOfPosExamples));
- neg...
[truncated message content] |