|
From: <jen...@us...> - 2008-07-24 11:06:49
|
Revision: 1017
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1017&view=rev
Author: jenslehmann
Date: 2008-07-24 11:06:45 +0000 (Thu, 24 Jul 2008)
Log Message:
-----------
- bug fix in evaluated description comparator
- sample script cleanup
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/scripts/Sample.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
Modified: trunk/src/dl-learner/org/dllearner/scripts/Sample.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/Sample.java 2008-07-24 09:36:02 UTC (rev 1016)
+++ trunk/src/dl-learner/org/dllearner/scripts/Sample.java 2008-07-24 11:06:45 UTC (rev 1017)
@@ -18,11 +18,9 @@
package org.dllearner.scripts;
import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashSet;
+import java.io.IOException;
+import java.text.DecimalFormat;
import java.util.List;
-import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -32,49 +30,41 @@
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent;
+import org.dllearner.core.ComponentInitException;
import org.dllearner.core.ComponentManager;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.KnowledgeSource;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
+import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.ReasoningService;
-import org.dllearner.core.owl.Description;
import org.dllearner.kb.OWLFile;
import org.dllearner.learningproblems.PosNegDefinitionLP;
-import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.reasoning.FastInstanceChecker;
-import org.dllearner.utilities.JamonMonitorLogger;
-import org.dllearner.utilities.datastructures.SetManipulation;
+import org.dllearner.utilities.Files;
-// TODO COMMENT !!! added a sample java call class for the dl-learner (as a
-// possible entry point for tool developers)
+import com.jamonapi.MonitorFactory;
+
+/**
+ * Sample script showing how to use DL-Learner. Provides an entry point for tool
+ * developers.
+ *
+ * @author Sebastian Hellmann
+ * @author Jens Lehmann
+ *
+ */
public class Sample {
private static Logger logger = Logger.getRootLogger();
+ private static DecimalFormat df = new DecimalFormat();
- String owlfile = "";
+ public static void main(String[] args) throws IOException, ComponentInitException,
+ LearningProblemUnsupportedException {
- // examples
- SortedSet<String> posExamples = new TreeSet<String>();
-
- SortedSet<String> negExamples = new TreeSet<String>();
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- System.out.println("Start");
-
- // create logger (a simple logger which outputs
- // its messages to the console)
+ // create logger (configure this to your needs)
SimpleLayout layout = new SimpleLayout();
- FileAppender fileAppender = null;
- ;
- try {
- fileAppender = new FileAppender(layout, "the_log.txt", false);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ FileAppender fileAppender = new FileAppender(layout, "log/sample_log.txt", false);
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
logger.removeAllAppenders();
@@ -82,127 +72,86 @@
logger.addAppender(fileAppender);
logger.setLevel(Level.DEBUG);
- Sample s = new Sample();
+ // OWL file containing background knowledge
+ String owlFile = "examples/trains/trains.owl";
- s.owlfile = "examples/trains/trains.owl";
+ // examples
+ SortedSet<String> posExamples = new TreeSet<String>();
+ posExamples.add("http://example.com/foo#east1");
+ posExamples.add("http://example.com/foo#east2");
+ posExamples.add("http://example.com/foo#east3");
+ posExamples.add("http://example.com/foo#east4");
+ posExamples.add("http://example.com/foo#east5");
- s.posExamples = new TreeSet<String>();
- s.negExamples = new TreeSet<String>();
+ SortedSet<String> negExamples = new TreeSet<String>();
+ negExamples.add("http://example.com/foo#west6");
+ negExamples.add("http://example.com/foo#west7");
+ negExamples.add("http://example.com/foo#west8");
+ negExamples.add("http://example.com/foo#west9");
+ negExamples.add("http://example.com/foo#west10");
- /* Examples */
- s.posExamples.add("http://example.com/foo#east1");
- s.posExamples.add("http://example.com/foo#east2");
- s.posExamples.add("http://example.com/foo#east3");
- s.posExamples.add("http://example.com/foo#east4");
- s.posExamples.add("http://example.com/foo#east5");
-
- s.negExamples.add("http://example.com/foo#west6");
- s.negExamples.add("http://example.com/foo#west7");
- s.negExamples.add("http://example.com/foo#west8");
- s.negExamples.add("http://example.com/foo#west9");
- s.negExamples.add("http://example.com/foo#west10");
-
- List<Description> conceptresults = s.learn();
+ List<EvaluatedDescription> results = learn(owlFile, posExamples, negExamples, 5);
int x = 0;
- for (Description description : conceptresults) {
- if (x >= 5)
- break;
- System.out
- .println(description.toManchesterSyntaxString(null, null));
+ for (EvaluatedDescription ed : results) {
+ System.out.println("solution: " + x);
+ System.out.println(" description: \t"
+ + ed.getDescription().toManchesterSyntaxString(null, null));
+ System.out.println(" accuracy: \t" + df.format(ed.getAccuracy() * 100) + "%");
+ System.out.println();
x++;
}
- System.out.println("Finished");
- JamonMonitorLogger.printAllSortedByLabel();
-
+ Files.createFile(new File("log/jamon_sample.html"), MonitorFactory.getReport());
}
- public List<Description> learn() {
+ public static List<EvaluatedDescription> learn(String owlFile, SortedSet<String> posExamples,
+ SortedSet<String> negExamples, int maxNrOfResults) throws ComponentInitException,
+ LearningProblemUnsupportedException {
logger.info("Start Learning with");
logger.info("positive examples: \t" + posExamples.size());
logger.info("negative examples: \t" + negExamples.size());
- // Components
+ // the component manager is the central object to create
+ // and configure components
ComponentManager cm = ComponentManager.getInstance();
- LearningAlgorithm la = null;
- ReasoningService rs = null;
- LearningProblem lp = null;
- KnowledgeSource ks = null;
- try {
- Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>();
- ks = cm.knowledgeSource(OWLFile.class);
+ // knowledge source
+ KnowledgeSource ks = cm.knowledgeSource(OWLFile.class);
+ String fileURL = new File(owlFile).toURI().toString();
+ cm.applyConfigEntry(ks, "url", fileURL);
- // there are probably better ways, but this works
- File f = new File(this.owlfile);
- URL url = null;
- try {
- url = new URL("file://" + f.getAbsolutePath());
+ // reasoner
+ ReasonerComponent r = cm.reasoner(FastInstanceChecker.class, ks);
+ ReasoningService rs = cm.reasoningService(r);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- cm.applyConfigEntry(ks, "url", url.toString());
+ // learning problem
+ LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs);
+ cm.applyConfigEntry(lp, "positiveExamples", posExamples);
+ cm.applyConfigEntry(lp, "negativeExamples", negExamples);
- ReasonerComponent r = new FastInstanceChecker(sources);
- rs = new ReasoningService(r);
- // System.out.println("satisfy: "+rs.isSatisfiable());
+ // learning algorithm
+ LearningAlgorithm la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs);
+ cm.applyConfigEntry(la, "useAllConstructor", false);
+ cm.applyConfigEntry(la, "useExistsConstructor", true);
+ cm.applyConfigEntry(la, "useCardinalityRestrictions", false);
+ cm.applyConfigEntry(la, "useNegation", false);
+ cm.applyConfigEntry(la, "writeSearchTree", false);
+ cm.applyConfigEntry(la, "searchTreeFile", "log/searchTree.txt");
+ cm.applyConfigEntry(la, "replaceSearchTree", true);
+ cm.applyConfigEntry(la, "noisePercentage", 0.0);
- lp = new PosNegDefinitionLP(rs);
- lp = new PosNegDefinitionLP(rs);
+ // all components need to be initialised before they can be used
+ ks.init();
+ r.init();
+ lp.init();
+ la.init();
- // This method is a workaround, it should be like the two commented
- // lines below
- ((PosNegLP) lp).setPositiveExamples(SetManipulation
- .stringToInd(this.posExamples));
- ((PosNegLP) lp).setNegativeExamples(SetManipulation
- .stringToInd(this.negExamples));
- // cm.applyConfigEntry(lp,"positiveExamples",this.posExamples);
- // cm.applyConfigEntry(lp,"negativeExamples",this.negExamples);
-
- la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs);
-
- logger.debug("start learning");
-
- // KNOWLEDGESOURCE
- //
-
- // LEARNINGALGORITHM
- cm.applyConfigEntry(la, "useAllConstructor", false);
- cm.applyConfigEntry(la, "useExistsConstructor", true);
- cm.applyConfigEntry(la, "useCardinalityRestrictions", false);
- cm.applyConfigEntry(la, "useNegation", false);
-
- cm.applyConfigEntry(la, "writeSearchTree", false);
- cm.applyConfigEntry(la, "searchTreeFile", "log/searchtree.txt");
- cm.applyConfigEntry(la, "replaceSearchTree", true);
- // cm.applyConfigEntry(la,"noisePercentage",noise);
-
- /*
- * if(ignoredConcepts.size()>0)
- * cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts);
- */
-
- // initialization
- ks.init();
- sources.add(ks);
- r.init();
- lp.init();
- la.init();
-
- la.start();
- // Statistics.addTimeCollecting(sc.getTime());
- // Statistics.addTimeLearning(sc.getTime());
-
- return la.getCurrentlyBestDescriptions();
- // return la.getCurrentlyBestEvaluatedDescriptions();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
-
+ // start learning algorithm
+ logger.debug("start learning");
+ la.start();
+
+ return la.getCurrentlyBestEvaluatedDescriptions(maxNrOfResults);
}
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2008-07-24 09:36:02 UTC (rev 1016)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2008-07-24 11:06:45 UTC (rev 1017)
@@ -43,16 +43,16 @@
double acc1 = ed1.getAccuracy();
double acc2 = ed2.getAccuracy();
if(acc1 > acc2)
+ return -1;
+ else if(acc1 < acc2)
return 1;
- else if(acc1 < acc2)
- return -1;
else {
int length1 = ed1.getDescriptionLength();
int length2 = ed2.getDescriptionLength();
if(length1 < length2)
+ return -1;
+ else if(length1 > length2)
return 1;
- else if(length1 > length2)
- return -1;
else
return cc.compare(ed1.getDescription(), ed2.getDescription());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-07-28 09:21:14
|
Revision: 1019
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1019&view=rev
Author: jenslehmann
Date: 2008-07-28 09:21:08 +0000 (Mon, 28 Jul 2008)
Log Message:
-----------
- added isRunning() method to abstract learning algorithm class
- removed getReasoningService() from learning problem base class and changed all affected classes
- documentation improvements
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java
trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java
trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java
trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
trunk/src/dl-learner/org/dllearner/core/Component.java
trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java
trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/core/LearningProblem.java
trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java
trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java
trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java
trunk/src/dl-learner/org/dllearner/core/owl/Description.java
trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java
trunk/src/dl-learner/org/dllearner/learningproblems/EvaluationCache.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java
trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java
trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
trunk/src/dl-learner/org/dllearner/server/ClientState.java
trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -59,6 +59,7 @@
public class BruteForceLearner extends LearningAlgorithm {
private LearningProblem learningProblem;
+ private ReasoningService rs;
private Description bestDefinition;
private Score bestScore;
@@ -67,12 +68,14 @@
private String returnType;
private boolean stop = false;
+ private boolean isRunning = false;
// list of all generated concepts sorted by length
private Map<Integer,List<Description>> generatedDefinitions = new HashMap<Integer,List<Description>>();
public BruteForceLearner(LearningProblem learningProblem, ReasoningService rs) {
this.learningProblem = learningProblem;
+ this.rs = rs;
}
public static String getName() {
@@ -121,6 +124,7 @@
@Override
public void start() {
+ isRunning = true;
// FlatABox abox = FlatABox.getInstance();
System.out.print("Generating definitions up to length " + maxLength + " ... ");
@@ -148,7 +152,7 @@
//System.out.println("false negatives: " + Helper.intersection(bestDefNegSet,posExamples));
//System.out.print("Score: " + bestScore + " Max: " + maxScore + " Difference: " + (maxScore-bestScore));
//System.out.println(" Accuracy: " + df.format((double)bestScore/maxScore*100) + "%");
-
+ isRunning = false;
}
private void testGeneratedDefinitions(int maxLength) {
@@ -203,7 +207,7 @@
if(length==1) {
generatedDefinitions.get(1).add(new Thing());
generatedDefinitions.get(1).add(new Nothing());
- for(NamedClass atomicConcept : learningProblem.getReasoningService().getAtomicConcepts()) {
+ for(NamedClass atomicConcept : rs.getAtomicConcepts()) {
generatedDefinitions.get(1).add(atomicConcept);
}
}
@@ -261,7 +265,7 @@
// EXISTS and ALL
for(Description childNode : generatedDefinitions.get(length-2)) {
- for(ObjectProperty atomicRole : learningProblem.getReasoningService().getAtomicRoles()) {
+ for(ObjectProperty atomicRole : rs.getAtomicRoles()) {
Description root1 = new ObjectSomeRestriction(atomicRole,childNode);
generatedDefinitions.get(length).add(root1);
@@ -310,4 +314,12 @@
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ return isRunning;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -177,4 +177,13 @@
// TODO Auto-generated method stub
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -42,6 +42,7 @@
private Score bestScore;
private double bestFitness = Double.NEGATIVE_INFINITY;
private LearningProblem learningProblem;
+ private ReasoningService rs;
private int numberOfTrees;
private int maxDepth;
@@ -49,6 +50,7 @@
public RandomGuesser(LearningProblem learningProblem, ReasoningService rs) {
this.learningProblem = learningProblem;
+ this.rs = rs;
}
public static String getName() {
@@ -99,7 +101,7 @@
for(int i=0; i<numberOfTrees; i++) {
// p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth);
- p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth, false);
+ p = GPUtilities.createGrowRandomProgram(learningProblem, rs, maxDepth, false);
if(p.getFitness()>bestFitness) {
bestFitness = p.getFitness();
bestScore = p.getScore();
@@ -133,4 +135,13 @@
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -100,4 +100,13 @@
}
return simpleSuggestions;
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -274,7 +274,7 @@
@Override
public void start() {
// falls refinement-Wahrscheinlichkeit größer 0, dann erzeuge psi
- psi = new Psi(learningProblem);
+ psi = new Psi(learningProblem, rs);
System.out.println();
System.out.println("Starting Genetic Programming Learner");
@@ -437,11 +437,11 @@
i++;
// mutation
} else if(rand >= crossoverBoundary && rand < mutationBoundary) {
- newIndividuals[i] = GPUtilities.mutation(learningProblem, individuals[selectedIndividuals[i]]);
+ newIndividuals[i] = GPUtilities.mutation(learningProblem, rs, individuals[selectedIndividuals[i]]);
// hill climbing
} else if(rand >= mutationBoundary && rand < hillClimbingBoundary) {
// System.out.println("hill climbing");
- newIndividuals[i] = GPUtilities.hillClimbing(learningProblem, individuals[selectedIndividuals[i]]);
+ newIndividuals[i] = GPUtilities.hillClimbing(learningProblem, rs, individuals[selectedIndividuals[i]]);
// refinement operator
} else if(rand >= hillClimbingBoundary && rand < refinementBoundary) {
newIndividuals[i] = psi.applyOperator(individuals[selectedIndividuals[i]]);
@@ -615,9 +615,9 @@
// int depth = rand.nextInt(initMaxDepth-initMinDepth)+initMinDepth;
if(grow)
- individuals[i] = GPUtilities.createGrowRandomProgram(learningProblem,depth, adc);
+ individuals[i] = GPUtilities.createGrowRandomProgram(learningProblem, rs, depth, adc);
else
- individuals[i] = GPUtilities.createFullRandomProgram(learningProblem, depth, adc);
+ individuals[i] = GPUtilities.createFullRandomProgram(learningProblem, rs, depth, adc);
}
/*
@@ -965,6 +965,15 @@
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
/**
* This allows to set the number of individuals in the whole population. A
* higher value slows down the algorithm, but will in general improve
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -9,6 +9,7 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasoningMethodUnsupportedException;
+import org.dllearner.core.ReasoningService;
import org.dllearner.core.Score;
import org.dllearner.core.owl.ObjectAllRestriction;
import org.dllearner.core.owl.NamedClass;
@@ -134,31 +135,31 @@
* Perform a point mutation on the given program.
* @param p The program to be mutated.
*/
- public static Program mutation(LearningProblem learningProblem, Program p) {
+ public static Program mutation(LearningProblem learningProblem, ReasoningService rs, Program p) {
mutation++;
if(p.getAdc() != null) {
// TODO: hier kann man noch mehr Feinabstimmung machen, d.h.
// Mutation abh�ngig von Knotenanzahl
if(Math.random()<0.5) {
- Description mainTree = mutation(learningProblem, p.getTree(),true);
+ Description mainTree = mutation(learningProblem, rs, p.getTree(),true);
Description adc = p.getAdc();
Score score = calculateFitness(learningProblem,mainTree,adc);
return new Program(score, mainTree, adc);
}
else {
Description mainTree = p.getTree();
- Description adc = mutation(learningProblem, p.getAdc(),false);
+ Description adc = mutation(learningProblem, rs, p.getAdc(),false);
Score score = calculateFitness(learningProblem,mainTree,adc);
return new Program(score, mainTree, adc);
}
} else {
- Description tree = mutation(learningProblem, p.getTree(),false);
+ Description tree = mutation(learningProblem, rs,p.getTree(),false);
Score score = calculateFitness(learningProblem, tree);
return new Program(score, tree);
}
}
- private static Description mutation(LearningProblem learningProblem, Description tree, boolean useADC) {
+ private static Description mutation(LearningProblem learningProblem, ReasoningService rs, Description tree, boolean useADC) {
// auch bei Mutation muss darauf geachtet werden, dass
// Baum nicht modifiziert wird (sonst w�rde man automatisch auch
// andere "selected individuals" modifizieren)
@@ -185,11 +186,11 @@
Description st = t.getSubtree(randNr);
Description stParent = st.getParent();
stParent.getChildren().remove(st);
- Description treeNew = createGrowRandomTree(learningProblem,3, useADC);
+ Description treeNew = createGrowRandomTree(learningProblem, rs, 3, useADC);
stParent.addChild(treeNew);
} else
// return createLeafNode(useADC);
- return pickTerminalSymbol(learningProblem,useADC);
+ return pickTerminalSymbol(learningProblem,rs,useADC);
return t;
}
@@ -303,10 +304,10 @@
// m�sste auch mit ADC funktionieren, da nur am Hauptbaum etwas
// ver�ndert wird
- public static Program hillClimbing(LearningProblem learningProblem, Program p) {
+ public static Program hillClimbing(LearningProblem learningProblem, ReasoningService rs, Program p) {
hillClimbing++;
// checken, ob Bedingungen f�r hill-climbing erf�llt sind
- if(!learningProblem.getReasoningService().getReasonerType().equals(ReasonerType.FAST_RETRIEVAL)
+ if(!rs.getReasonerType().equals(ReasonerType.FAST_RETRIEVAL)
|| !(p.getScore() instanceof ScoreThreeValued)) {
throw new Error("Hill climbing can only be used with the fast-retrieval-algorithm on a three valued learning problem.");
}
@@ -316,9 +317,9 @@
// parent-Link ver�ndert)
Description treecloned = (Description) p.getTree().clone();
if(p.getAdc() != null)
- return createProgram(learningProblem,hillClimbing(learningProblem,treecloned,(ScoreThreeValued)p.getScore()),p.getAdc());
+ return createProgram(learningProblem,hillClimbing(learningProblem,rs,treecloned,(ScoreThreeValued)p.getScore()),p.getAdc());
else
- return createProgram(learningProblem,hillClimbing(learningProblem,treecloned,(ScoreThreeValued)p.getScore()));
+ return createProgram(learningProblem,hillClimbing(learningProblem,rs,treecloned,(ScoreThreeValued)p.getScore()));
}
// one-step hill-climbing
@@ -326,7 +327,7 @@
// Alternativen zu speichern und dann ein Element zuf�llig auszuw�hlen,
// aber w�rde man das nicht machen, dann w�re das ein starker Bias
// zu z.B. Disjunktion (weil die als erstes getestet wird)
- private static Description hillClimbing(LearningProblem learningProblem, Description node, ScoreThreeValued score) {
+ private static Description hillClimbing(LearningProblem learningProblem, ReasoningService rs, Description node, ScoreThreeValued score) {
SortedSetTuple<Individual> tuple = new SortedSetTuple<Individual>(score.getPosClassified(),score.getNegClassified());
SortedSetTuple<String> stringTuple = Helper.getStringTuple(tuple);
// FlatABox abox = FlatABox.getInstance();
@@ -345,7 +346,7 @@
// FlatABox abox = Main.getFlatAbox();
FlatABox abox = null;
try {
- abox = Helper.createFlatABox(learningProblem.getReasoningService());
+ abox = Helper.createFlatABox(rs);
} catch (ReasoningMethodUnsupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -361,14 +362,14 @@
// TODO: double retrieval nutzen
tmp2 = FastRetrieval.calculateDisjunctionSets(stringTuple, tmp);
- tmpScore = getScore(node.getLength()+2, learningProblem,Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet()));
+ tmpScore = getScore(node.getLength()+2, learningProblem, rs, Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet()));
if(tmpScore.getScore()==bestScore)
bestNeighbours = updateMap(bestNeighbours,1,concept,false);
else if(tmpScore.getScore()>bestScore)
bestNeighbours = updateMap(bestNeighbours,1,concept,true);
tmp2 = FastRetrieval.calculateConjunctionSets(stringTuple, tmp);
- tmpScore = getScore(node.getLength()+2,learningProblem,Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet()));
+ tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet()));
if(tmpScore.getScore()==bestScore)
bestNeighbours = updateMap(bestNeighbours,2,concept,false);
else if(tmpScore.getScore()>bestScore)
@@ -378,14 +379,14 @@
// Tests f�r All und Exists
for(String role : abox.roles) {
tmp = FastRetrieval.calculateAllSet(abox,role,stringTuple);
- tmpScore = getScore(node.getLength()+2,learningProblem,Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet()));
+ tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet()));
if(tmpScore.getScore()==bestScore)
bestNeighbours = updateMap(bestNeighbours,3,role,false);
else if(tmpScore.getScore()>bestScore)
bestNeighbours = updateMap(bestNeighbours,3,role,true);
tmp = FastRetrieval.calculateExistsSet(abox,role,stringTuple);
- tmpScore = getScore(node.getLength()+2,learningProblem,Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet()));
+ tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet()));
if(tmpScore.getScore()==bestScore)
bestNeighbours = updateMap(bestNeighbours,4,role,false);
else if(tmpScore.getScore()>bestScore)
@@ -451,10 +452,10 @@
}
}
- private static ScoreThreeValued getScore(int conceptLength, LearningProblem learningProblem, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) {
+ private static ScoreThreeValued getScore(int conceptLength, LearningProblem learningProblem, ReasoningService rs, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) {
// es muss hier die Helper-Methode verwendet werden, sonst werden
// Individuals gel�scht !!
- SortedSet<Individual> neutClassified = Helper.intersection(learningProblem.getReasoningService().getIndividuals(),posClassified);
+ SortedSet<Individual> neutClassified = Helper.intersection(rs.getIndividuals(),posClassified);
// learningProblem.getReasoner().getIndividuals();
// neutClassified.retainAll(posClassified);
neutClassified.retainAll(negClassified);
@@ -488,10 +489,10 @@
return returnMap;
}
- private static Description pickTerminalSymbol(LearningProblem learningProblem, boolean useADC) {
+ private static Description pickTerminalSymbol(LearningProblem learningProblem, ReasoningService rs, boolean useADC) {
// FlatABox abox = FlatABox.getInstance();
int nr;
- int nrOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size();
+ int nrOfConcepts = rs.getAtomicConcepts().size();
// ein Blattknoten kann folgendes sein:
// Top, Bottom, Konzept => alles am Besten gleichwahrscheinlich
@@ -510,7 +511,7 @@
return new ADC();
}
else
- return (NamedClass) learningProblem.getReasoningService().getAtomicConceptsList().get(nr-2).clone();
+ return (NamedClass) rs.getAtomicConceptsList().get(nr-2).clone();
}
// Funktion nach Umstelllung der Konstruktoren nicht mehr ben�tigt
@@ -618,28 +619,28 @@
* @param depth Depth of the tree.
* @return The created program.
*/
- public static Program createFullRandomProgram(LearningProblem learningProblem, int depth, boolean adc) {
+ public static Program createFullRandomProgram(LearningProblem learningProblem, ReasoningService rs, int depth, boolean adc) {
if(adc) {
// erster Baum Hauptbaum, zweiter Baum ADC
- return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true),
- createFullRandomTree(learningProblem, depth, false));
+ return createProgram(learningProblem, createFullRandomTree(learningProblem, rs, depth, true),
+ createFullRandomTree(learningProblem, rs, depth, false));
}
else
- return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, false));
+ return createProgram(learningProblem, createFullRandomTree(learningProblem, rs, depth, false));
}
- private static Description createFullRandomTree(LearningProblem learningProblem, int depth, boolean useADC) {
+ private static Description createFullRandomTree(LearningProblem learningProblem, ReasoningService rs, int depth, boolean useADC) {
// FlatABox abox = FlatABox.getInstance();
- int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size(); // abox.roles.size();
+ int numberOfRoles = rs.getAtomicRoles().size(); // abox.roles.size();
if (depth > 1) {
int nr = rand.nextInt(3+2*numberOfRoles);
// System.out.println(nr);
// Node node = createNonLeafNodeEqualProp();
// Concept node = pickFunctionSymbol();
- Description child1 = createFullRandomTree(learningProblem, depth-1, useADC);
+ Description child1 = createFullRandomTree(learningProblem, rs, depth-1, useADC);
if(nr == 0 || nr == 1) {
- Description child2 = createFullRandomTree(learningProblem, depth-1, useADC);
+ Description child2 = createFullRandomTree(learningProblem, rs, depth-1, useADC);
if(nr == 0) {
// if(useMultiStructures)
return new Union(child1,child2);
@@ -654,9 +655,9 @@
} else if(nr==2) {
return new Negation(child1);
} else if(nr - 3 < numberOfRoles)
- return new ObjectSomeRestriction(learningProblem.getReasoningService().getAtomicRolesList().get(nr-3),child1);
+ return new ObjectSomeRestriction(rs.getAtomicRolesList().get(nr-3),child1);
else
- return new ObjectAllRestriction(learningProblem.getReasoningService().getAtomicRolesList().get(nr-3-numberOfRoles),child1);
+ return new ObjectAllRestriction(rs.getAtomicRolesList().get(nr-3-numberOfRoles),child1);
/*
if(node instanceof Disjunction || node instanceof Conjunction) {
@@ -670,7 +671,7 @@
// return node;
} else {
// return createLeafNode(useADC);
- return pickTerminalSymbol(learningProblem, useADC);
+ return pickTerminalSymbol(learningProblem, rs, useADC);
}
}
@@ -679,17 +680,17 @@
* @param depth The maximum depth of the program tree.
* @return The created program.
*/
- public static Program createGrowRandomProgram(LearningProblem learningProblem, int depth, boolean adc) {
+ public static Program createGrowRandomProgram(LearningProblem learningProblem, ReasoningService rs, int depth, boolean adc) {
if(adc) {
// erster Baum Hauptbaum, zweiter Baum ADC
- return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true),
- createGrowRandomTree(learningProblem,depth,false));
+ return createProgram(learningProblem, createGrowRandomTree(learningProblem,rs,depth,true),
+ createGrowRandomTree(learningProblem,rs,depth,false));
}
else
- return createProgram(learningProblem, createGrowRandomTree(learningProblem, depth,false));
+ return createProgram(learningProblem, createGrowRandomTree(learningProblem, rs, depth,false));
}
- private static Description createGrowRandomTree(LearningProblem learningProblem, int depth, boolean useADC) {
+ private static Description createGrowRandomTree(LearningProblem learningProblem, ReasoningService rs, int depth, boolean useADC) {
/*
private static Concept pickAlphabetSymbol(boolean useADC) {
FlatABox abox = FlatABox.getInstance();
@@ -724,8 +725,8 @@
*/
// FlatABox abox = FlatABox.getInstance();
- int numberOfConcepts = learningProblem.getReasoningService().getAtomicConcepts().size();
- int numberOfRoles = learningProblem.getReasoningService().getAtomicRoles().size();
+ int numberOfConcepts = rs.getAtomicConcepts().size();
+ int numberOfRoles = rs.getAtomicRoles().size();
// TODO: ev. größere Wahrscheinlichkeit für Konjunktion/Disjunktion (?),
// mit größerer Konzept-, und Rollenanzahl kommen die sonst kaum noch vor
int numberOfAlphabetSymbols = numberOfConcepts + 2*numberOfRoles + 5; //7;// 5;
@@ -768,23 +769,23 @@
else if(nr==numberOfConcepts + 2*numberOfRoles + 5)
return new ADC();
else if(nr>=2 && nr < numberOfConcepts+2)
- return (NamedClass)learningProblem.getReasoningService().getAtomicConceptsList().get(nr-2).clone();
+ return (NamedClass)rs.getAtomicConceptsList().get(nr-2).clone();
else if(nr==numberOfConcepts+2) {
// if(useMultiStructures)
- return new Intersection(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC));
+ return new Intersection(createGrowRandomTree(learningProblem, rs, depth-1, useADC),createGrowRandomTree(learningProblem, rs, depth-1, useADC));
// else
// return new Conjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC));
} else if(nr==numberOfConcepts+3) {
// if(useMultiStructures)
- return new Union(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC));
+ return new Union(createGrowRandomTree(learningProblem, rs, depth-1, useADC),createGrowRandomTree(learningProblem, rs, depth-1, useADC));
// else
// return new Disjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC));
} else if(nr==numberOfConcepts+4)
- return new Negation(createGrowRandomTree(learningProblem, depth-1, useADC));
+ return new Negation(createGrowRandomTree(learningProblem, rs, depth-1, useADC));
else if(nr>=numberOfConcepts+5 && nr<numberOfConcepts+5+numberOfRoles)
- return new ObjectSomeRestriction(learningProblem.getReasoningService().getAtomicRolesList().get(nr-numberOfConcepts-5),createGrowRandomTree(learningProblem,depth-1, useADC));
+ return new ObjectSomeRestriction(rs.getAtomicRolesList().get(nr-numberOfConcepts-5),createGrowRandomTree(learningProblem, rs, depth-1, useADC));
else
- return new ObjectAllRestriction(learningProblem.getReasoningService().getAtomicRolesList().get(nr-numberOfConcepts-5-numberOfRoles),createGrowRandomTree(learningProblem,depth-1, useADC));
+ return new ObjectAllRestriction(rs.getAtomicRolesList().get(nr-numberOfConcepts-5-numberOfRoles),createGrowRandomTree(learningProblem, rs, depth-1, useADC));
/*
if(node instanceof Disjunction || node instanceof Conjunction) {
@@ -798,7 +799,7 @@
// return node;
} else {
// return createLeafNode(useADC);
- return pickTerminalSymbol(learningProblem, useADC);
+ return pickTerminalSymbol(learningProblem, rs, useADC);
}
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -6,6 +6,7 @@
import java.util.TreeMap;
import org.dllearner.algorithms.gp.Program;
+import org.dllearner.core.ReasoningService;
import org.dllearner.core.Score;
import org.dllearner.core.owl.Description;
import org.dllearner.learningproblems.PosNegLP;
@@ -48,12 +49,12 @@
private long someTimeStart = 0;
public long someTime = 0;
- public Psi(PosNegLP learningProblem) { //, PsiUp pu, PsiDown pd) {
+ public Psi(PosNegLP learningProblem, ReasoningService reasoningService) { //, PsiUp pu, PsiDown pd) {
// this.pu = pu;
// this.pd = pd;
this.learningProblem = learningProblem;
- pu = new PsiUp(learningProblem);
- pd = new PsiDown(learningProblem);
+ pu = new PsiUp(learningProblem, reasoningService);
+ pd = new PsiDown(learningProblem, reasoningService);
nrOfPositiveExamples = learningProblem.getPositiveExamples().size();
nrOfNegativeExamples = learningProblem.getNegativeExamples().size();
random = new Random();
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -430,5 +430,13 @@
public void resume() {
// TODO: not implemented
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ return algorithm.isRunning();
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -143,6 +143,7 @@
// setting to true gracefully stops the algorithm
private boolean stop = false;
+ private boolean isRunning = false;
// node from which algorithm has started
private ExampleBasedNode startNode;
@@ -287,6 +288,7 @@
}
public void start() {
+ isRunning = true;
runtime=System.currentTimeMillis();
JamonMonitorLogger.getTimeMonitor(ExampleBasedROLComponent.class, "totalLearningTime").start();
// TODO: write a JUnit test for this problem (long-lasting or infinite loops because
@@ -483,6 +485,7 @@
logger.info("Algorithm terminated succesfully.");
JamonMonitorLogger.getTimeMonitor(ExampleBasedROLComponent.class, "totalLearningTime").stop();
+ isRunning = false;
}
@@ -1222,5 +1225,9 @@
else return false;
}
+
+ public boolean isRunning() {
+ return isRunning;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -93,6 +93,7 @@
private boolean quiet = false;
private boolean stop = false;
+ private boolean isRunning = false;
private ReasoningService rs;
@@ -388,6 +389,7 @@
@Override
@SuppressWarnings("unchecked")
public void start() {
+ isRunning = true;
runtime=System.currentTimeMillis();
// Suche wird mit Top-Konzept gestartet
Thing top = new Thing();
@@ -582,6 +584,8 @@
System.out.println("Algorithm stopped.");
else
System.out.println("Algorithm terminated succesfully.");
+
+ isRunning = false;
}
// einfache Erweiterung des Knotens (ohne properness)
@@ -1147,4 +1151,12 @@
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.LearningAlgorithm#isRunning()
+ */
+ @Override
+ public boolean isRunning() {
+ return isRunning;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/core/Component.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/Component.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/Component.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -68,5 +68,6 @@
* @param option A configuration option of this component.
* @return Current value of the configuration option.
*/
+// now implemented in ComponentManager
// public abstract <T> T getConfigValue(ConfigOption<T> option) throws UnknownConfigOptionException;
}
Modified: trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -21,9 +21,9 @@
/**
* Exception which is thrown when a component cannot be intialised,
- * e.g. due to bad configuration parameteres or unforeseen
- * circumstances unreachable web files. It can encapsulate arbitrary
- * exceptions occuring during initialisation.
+ * e.g. due to bad configuration parameters, or unforeseen
+ * circumstances, e.g. unreachable web files. It can encapsulate arbitrary
+ * exceptions occurring during initialisation.
*
* @author Jens Lehmann
*
@@ -32,15 +32,31 @@
private static final long serialVersionUID = -3550079897929658317L;
+ /**
+ * Creates a <code>ComponentInitException</code> with the specified message.
+ * @param message The specified detail message.
+ */
public ComponentInitException(String message) {
super(message);
}
- public ComponentInitException(Exception exception) {
- super(exception);
+ /**
+ * Creates a <code>ComponentInitException</code> with the
+ * specified cause.
+ * @param cause The cause of this exception.
+ */
+ public ComponentInitException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates a <code>ComponentInitException</code> with the
+ * specified message and cause.
+ * @param message The specified detail message.
+ * @param cause The cause of this exception.
+ */
+ public ComponentInitException(String message, Throwable cause) {
+ super(message, cause);
}
-
- public ComponentInitException(String message, Exception exception) {
- super(message, exception);
- }
+
}
Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -72,6 +72,14 @@
public abstract void stop();
/**
+ * Returns whether the learning algorithm is running. Implementation
+ * should use a boolean status variable in their implementations of
+ * the start and resume methods.
+ * @return True if the algorithm is running, false otherwise.
+ */
+ public abstract boolean isRunning();
+
+ /**
* Every algorithm must be able to return the score of the
* best solution found.
*
Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007, Jens Lehmann
+ * Copyright (C) 2007-2008, Jens Lehmann
*
* This file is part of DL-Learner.
*
@@ -23,18 +23,19 @@
/**
* Base class for all learning problems.
+ * See also the wiki page for
+ * <a href="http://dl-learner.org/Projects/DLLearner/Architecture">DL-Learner-Architecture</a>.
+ * Currently, we assume that all learning problems have the goal
+ * of learning class descriptions. However, this may be extended
+ * to other scenarios if desired.
*
- * @todo The current learning problem implementations
- * assume that we learn a concept, which does not exist
- * in the knowledge base so far. However, often we want
- * to learn a complex definition for a concept which
- * is already integrated in a subsumption hierarchy. This
- * means it would make sense to specifiy the list of these
- * superclasses as an additional argument of the learning
- * problem. The learning algorithms could then make use of
- * this to optimise their search for a solution. (More
- * generally, one could specify the name of the concept, which
- * should be improved.)
+ * TODO: The current learning problem implementations assume that
+ * we learn a description for a class, which does not exist
+ * in the knowledge base so far (if it exists, it needs to be ignored
+ * explicitly). However, often we want to learn a complex definition
+ * for a concept which is already integrated in a subsumption hierarchy
+ * or may already have an associated description. It may make sense
+ * to use this knowledge for (re-)learning descriptions.
*
* @author Jens Lehmann
*
@@ -43,16 +44,25 @@
protected ReasoningService reasoningService;
+ /**
+ * Constructs a learning problem using a reasoning service for
+ * querying the background knowledge. It can be used for
+ * evaluating solution candidates.
+ * @param reasoningService The reasoning service used as
+ * background knowledge.
+ */
public LearningProblem(ReasoningService reasoningService) {
this.reasoningService = reasoningService;
}
- public abstract Score computeScore(Description concept);
+ /**
+ * Computes the <code>Score</code> of a given class description
+ * with respect to this learning problem.
+ * This can (but does not need to) be used by learning algorithms
+ * to measure how good the description fits the learning problem.
+ * @param description A class description (as solution candidate for this learning problem).
+ * @return A <code>Score</code> object.
+ */
+ public abstract Score computeScore(Description description);
- // TODO: remove? reasoning service should probably not be accessed via
- // learning problem
- public ReasoningService getReasoningService() {
- return reasoningService;
- }
-
}
Modified: trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/config/ConfigOption.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -71,7 +71,7 @@
*
* @param object
* The object to check.
- * @return
+ * @return True of the type is correct, false otherwise.
*/
public abstract boolean checkType(Object object);
Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -29,7 +29,7 @@
/**
* Represents a hierarchy of datatype properties.
*
- * @todo. Currently, the role hierarchy pruning algorithm (analogous to the
+ * TODO: Currently, the role hierarchy pruning algorithm (analogous to the
* subsumption hierarchy) is not implemented.
*
* @author Jens Lehmann
Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeQuantorRestriction.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -20,13 +20,19 @@
package org.dllearner.core.owl;
/**
+ * Represents datatype quantor restrictions. For instance,
+ * \exists salary < 100.000 can be used to specify
+ * those objects (persons) which have a salary of below 100.000.
+ *
* @author Jens Lehmann
*
*/
public abstract class DatatypeQuantorRestriction extends QuantorRestriction {
/**
- * @param propertyExpression
+ * Creates a <code>DatatypeQuantorRestriction</code> along the
+ * given property.
+ * @param propertyExpression The datatype property along which this restriction acts.
*/
public DatatypeQuantorRestriction(DatatypeProperty datatypeProperty) {
super(datatypeProperty);
Modified: trunk/src/dl-learner/org/dllearner/core/owl/Description.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -127,14 +127,16 @@
/**
* Adds a description as child of this one. The parent link
- * of the concept will point to this one.
+ * of the description will point to this one. For instance,
+ * if the description is an intersection, then this method adds
+ * an element to the intersection, e.g. A AND B becomes A AND B
+ * AND C.
*
- * @param child
- * @return
+ * @param child The child description.
*/
- public boolean addChild(Description child) {
+ public void addChild(Description child) {
child.setParent(this);
- return children.add(child);
+ children.add(child);
}
/**
Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -29,7 +29,7 @@
/**
* Represents a hierarchy of roles.
*
- * @todo Currently, the role hierarchy pruning algorithm (analogous to the
+ * TODO: Currently, the role hierarchy pruning algorithm (analogous to the
* subsumption hierarchy) is not implemented.
*
* @author Jens Lehmann
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/EvaluationCache.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluationCache.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/EvaluationCache.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -37,7 +37,7 @@
* which tries to infer the covered examples of a given concept
* from previous results.
*
- * @todo Under construction.
+ * TODO Under construction.
* @author Jens Lehmann
*
*/
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -75,8 +75,8 @@
* If it is not weak, it returns the number of covered negative example. It
* can use retrieval or instance checks for classification.
*
- * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks
- * @todo Performance could be slightly improved by counting the number of
+ * @see org.dllearner.learningproblems.PosNegLP.MultiInstanceChecks
+ * TODO: Performance could be slightly improved by counting the number of
* covers instead of using sets and counting their size.
* @param concept
* The concept to test.
@@ -154,7 +154,7 @@
* to implement TWO_CHECKS in this function, because we have to test all
* examples to create a score object anyway).
*
- * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks
+ * @see org.dllearner.learningproblems.PosNegLP.MultiInstanceChecks
* @param concept
* The concept to test.
* @return Corresponding Score object.
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -101,7 +101,7 @@
* concept. Thus, this methods uses a different notion of coverage than
* the one for the standard definition learning problem.
*
- * @see org.dllearner.learningproblems.DefinitionLP.MultiInstanceChecks
+ * @see org.dllearner.learningproblems.PosNegLP.MultiInstanceChecks
* @param concept
* The concept to test.
* @return -1 if concept is too weak and the number of covered negative
@@ -173,7 +173,7 @@
* Calls the same method on the standard definition learning problem, but
* negates the concept before and permutes positive and negative examples.
*
- * @see org.dllearner.core.LearningProblemNew#computeScore(org.dllearner.core.owl.Description)
+ * @see org.dllearner.core.LearningProblem#computeScore(org.dllearner.core.owl.Description)
*/
@Override
public Score computeScore(Description concept) {
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -32,7 +32,7 @@
* Computes the score (a negative value) by comparing the classification results
* with ideal results.
*
- * @todo: The implementation is not very efficient, because some things are
+ * TODO: The implementation is not very efficient, because some things are
* only computed to be able to present the score results. This means that
* it would be better to compute only the necessary computations and do
* the other ones only when they are needed to calculate statistical values.
Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -256,7 +256,7 @@
* Constructs a role hierarchy using DIG queries. After calling this method,
* one can query parents or children of roles.
*
- * @todo Does not yet take ignored roles into account.
+ * TODO Does not yet take ignored roles into account.
*/
@Override
public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) {
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -107,21 +107,24 @@
* number = 6: [[6], [4, 1], [3, 2], [2, 1, 1]]
* number = 7: [[7], [5, 1], [4, 2], [3, 3], [3, 1, 1], [2, 2, 1], [1, 1, 1, 1]]
*
- * @param length
- * @return
+ * @param number A natural number.
+ * @return A two dimensional list constructed as described above.
*/
- public static List<List<Integer>> getCombos(int length) {
+ public static List<List<Integer>> getCombos(int number) {
// on Notebook: length 70 in 17 seconds, length 50 in 800ms, length 30 in 15ms
LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>();
- decompose(length, length, new LinkedList<Integer>(), combosTmp);
+ decompose(number, number, new LinkedList<Integer>(), combosTmp);
return combosTmp;
}
/**
+ * Methods for computing combinations with the additional restriction
+ * that <code>maxValue</code> is the highest natural number, which can
+ * occur.
* @see #getCombos(int)
* @param length Length of construct.
* @param maxValue Maximum value which can occur in sum.
- * @return
+ * @return A two dimensional list constructed in {@link #getCombos(int)}.
*/
public static List<List<Integer>> getCombos(int length, int maxValue) {
LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>();
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -44,9 +44,9 @@
private TreeSet<Description> topSet;
- public PsiDown(PosNegLP learningProblem) {
+ public PsiDown(PosNegLP learningProblem, ReasoningService reasoningService) {
this.learningProblem = learningProblem;
- reasoningService = learningProblem.getReasoningService();
+ this.reasoningService = reasoningService;
// Top-Menge erstellen
createTopSet();
@@ -65,7 +65,7 @@
topSet.addAll(reasoningService.getMoreSpecialConcepts(new Thing()));
// negierte speziellste Konzepte
- Set<Description> tmp = learningProblem.getReasoningService().getMoreGeneralConcepts(new Nothing());
+ Set<Description> tmp = reasoningService.getMoreGeneralConcepts(new Nothing());
for(Description c : tmp)
topSet.add(new Negation(c));
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -32,9 +32,9 @@
private TreeSet<Description> bottomSet;
- public PsiUp(PosNegLP learningProblem) {
+ public PsiUp(PosNegLP learningProblem, ReasoningService reasoningService) {
this.learningProblem = learningProblem;
- reasoningService = learningProblem.getReasoningService();
+ this.reasoningService = reasoningService;
// Top-Menge erstellen
createBottomSet();
Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -94,6 +94,7 @@
/**
* @return the isAlgorithmRunning
*/
+ @Deprecated
public boolean isAlgorithmRunning() {
return isAlgorithmRunning;
}
@@ -101,6 +102,7 @@
/**
* @param isAlgorithmRunning the isAlgorithmRunning to set
*/
+ @Deprecated
public void setAlgorithmRunning(boolean isAlgorithmRunning) {
this.isAlgorithmRunning = isAlgorithmRunning;
}
@@ -199,8 +201,8 @@
}
/**
- * @param key
- * @return
+ * @param is A component ID.
+ * @return The component associated with this ID.
* @see java.util.Map#get(java.lang.Object)
*/
public Component getComponent(int id) {
@@ -208,8 +210,10 @@
}
/**
- * @param e
- * @return
+ * Adds a knowledge source to the client session. Use the
+ * returned value to refer to this knowledge source.
+ * @param ks The knowledge source to add.
+ * @return The component ID for the newly added knowledge source.
*/
public int addKnowledgeSource(KnowledgeSource ks) {
knowledgeSources.add(ks);
Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -348,9 +348,9 @@
Thread learningThread = new Thread() {
@Override
public void run() {
- state.setAlgorithmRunning(true);
+// state.setAlgorithmRunning(true);
state.getLearningAlgorithm().start();
- state.setAlgorithmRunning(false);
+// state.setAlgorithmRunning(false);
}
};
learningThread.start();
@@ -393,7 +393,7 @@
@WebMethod
public boolean isAlgorithmRunning(int id) throws ClientNotKnownException {
- return getState(id).isAlgorithmRunning();
+ return getState(id).getLearningAlgorithm().isRunning();
}
/**
Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-07-24 16:42:40 UTC (rev 1018)
+++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-07-28 09:21:08 UTC (rev 1019)
@@ -11,7 +11,6 @@
import org.dllearner.core.owl.Description;
-import org.semanticweb.owl.model.OWLDescription;
/**
*
* @author Heero Yuy
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-07-29 08:24:26
|
Revision: 1021
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1021&view=rev
Author: kurzum
Date: 2008-07-29 08:24:15 +0000 (Tue, 29 Jul 2008)
Log Message:
-----------
some comments
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-28 17:50:10 UTC (rev 1020)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-29 08:24:15 UTC (rev 1021)
@@ -1,3 +1,22 @@
+/**
+ * Copyright (C) 2007, Sebastian Hellmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package org.dllearner.kb.sparql;
import java.util.LinkedList;
@@ -11,72 +30,78 @@
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.sparql.core.ResultBinding;
+
+/**
+ * @author Sebastian Hellmann
+ * Convenience class for SPARQL queries
+ * initialized with a SparqlEndpoint.
+ * A Cache can also be used to further improve query time.
+ * Some methods allow basic reasoning
+ */
public class SPARQLTasks {
-
- //@SuppressWarnings("unused")
- //LOGGER: SPARQLTasks
- private static Logger logger = Logger
- .getLogger(SPARQLTasks.class);
- private Cache c;
- private SparqlEndpoint se;
-
- public SPARQLTasks(Cache c, SparqlEndpoint se) {
+
+ private static final Logger logger = Logger.getLogger(SPARQLTasks.class);
+
+ private final Cache cache;
+
+ private final SparqlEndpoint sparqlEndpoint;
+
+ public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) {
super();
- this.c = c;
- this.se = se;
+ this.cache = cache;
+ this.sparqlEndpoint = sparqlEndpoint;
}
-
- public SPARQLTasks( SparqlEndpoint se) {
+
+ public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) {
super();
- this.c = null;
- this.se = se;
+ this.cache = null;
+ this.sparqlEndpoint = sparqlEndpoint;
}
-
-
-
-
+
/**
- * QUALITY: doesn't seem optimal, check!
- * get all superclasses up to a certain depth
- * 1 means direct superclasses
- * depth
+ * QUALITY: doesn't seem optimal, check! get all superclasses up to a
+ * certain depth 1 means direct superclasses depth
+ *
* @param superClasses
- * @param depth
+ * @param maxdepth
* @return
*/
- public SortedSet<String> getSuperClasses(String oneClass, int depth) {
+ public SortedSet<String> getSuperClasses(final String oneClass,
+ final int maxdepth) {
+ int depth = maxdepth;
SortedSet<String> superClasses = new TreeSet<String>();
superClasses.add(oneClass);
SortedSet<String> ret = new TreeSet<String>();
SortedSet<String> tmpset = new TreeSet<String>();
- //ret.addAll(superClasses);
- //logger.debug(superClasses);
-
-
String SPARQLquery = "";
- for (; depth != 0 ; depth--) {
+ // ret.addAll(superClasses);
+ // logger.debug(superClasses);
+
+ for (; depth != 0; depth--) {
for (String oneSuperClass : superClasses) {
-
- //tmp = oneSuperClass.replace("\"", "");
- SPARQLquery = "SELECT * WHERE { \n" + "<" + oneSuperClass + "> "
- + "<http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass. \n"
- + "}";
-
+
+ // tmp = oneSuperClass.replace("\"", "");
+ SPARQLquery = "SELECT * WHERE { \n"
+ + "<"
+ + oneSuperClass
+ + "> "
+ + "<http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass. \n"
+ + "}";
+
tmpset.addAll(queryAsSet(SPARQLquery, "superclass"));
-
- }
+
+ }// end inner for
ret.addAll(tmpset);
- //logger.debug(ret);
+ // logger.debug(ret);
superClasses.clear();
superClasses.addAll(tmpset);
tmpset.clear();
- }
- //logger.debug(concept);
- //logger.debug(query);
- return ret;
+ }// end outer for
+ // logger.debug(concept);
+ // logger.debug(query);
+ return ret;
}
-
-
+
/**
* gets a SortedSet of all subclasses QUALITY: maybe it is better to have a
* parameter int depth, to choose a depth of subclass interference
@@ -84,13 +109,13 @@
* @see conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache
* c, boolean simple )
* @param description
- * @param se
- * @param c
+ * @param sparqlEndpoint
+ * @param cache
* @param simple
* @return
*/
- public SortedSet<String> getSubClasses(String description, boolean simple) {
-
+ public SortedSet<String> getSubClasses(final String description,
+ final boolean simple) {
// ResultSet rs = null;
// System.out.println(description);
SortedSet<String> alreadyQueried = new TreeSet<String>();
@@ -100,7 +125,8 @@
LinkedList<String> remainingClasses = new LinkedList<String>();
// collect remaining classes
- remainingClasses.addAll(getDirectSubClasses(description.replaceAll("\"", "")));
+ remainingClasses.addAll(getDirectSubClasses(description.replaceAll(
+ "\"", "")));
// remainingClasses.addAll(alreadyQueried);
@@ -109,12 +135,14 @@
if (simple) {
alreadyQueried.addAll(remainingClasses);
- return alreadyQueried;
+
} else {
- logger.warn("Retrieval auf all subclasses via SPARQL is cost intensive and might take a while");
- while (remainingClasses.size() != 0) {
- SortedSet<String> tmpSet = new TreeSet<String>();
+ logger
+ .warn("Retrieval auf all subclasses via SPARQL is cost intensive and might take a while");
+ SortedSet<String> tmpSet = new TreeSet<String>();
+ while (!remainingClasses.isEmpty()) {
+
String tmp = remainingClasses.removeFirst();
alreadyQueried.add(tmp);
@@ -124,11 +152,12 @@
remainingClasses.add(string);
}// if
}// for
+ tmpSet.clear();
}// while
}// else
} catch (Exception e) {
-
+ logger.error(e.getStackTrace());
}
return alreadyQueried;
@@ -136,252 +165,245 @@
/**
* QUALITY: workaround for a sparql glitch {?a owl:subclassOf ?b} returns an
- * empty set on some entpoints. returns all direct subclasses of String
+ * empty set on some endpoints. returns all direct subclasses of String
* concept
*
* @param concept
* @return SortedSet of direct subclasses as String
*/
- private SortedSet<String> getDirectSubClasses(String concept) {
- String SPARQLquery = "SELECT * \n";
- SPARQLquery += "WHERE {\n";
- SPARQLquery += " ?subject ?predicate <" + concept + "> \n";
- SPARQLquery += "}\n";
+ private SortedSet<String> getDirectSubClasses(final String concept) {
- ResultSet rs = queryAsResultSet(SPARQLquery);
-
+ String SPARQLquery;
SortedSet<String> subClasses = new TreeSet<String>();
+ ResultSet resultSet;
+
+ SPARQLquery = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <"
+ + concept + "> \n" + "}\n";
+
+ resultSet = queryAsResultSet(SPARQLquery);
+
@SuppressWarnings("unchecked")
- List<ResultBinding> l = ResultSetFormatter.toList(rs);
- String p = "", s = "";
- for (ResultBinding resultBinding : l) {
+ List<ResultBinding> bindings = ResultSetFormatter.toList(resultSet);
+ String subject = "";
+ String predicate = "";
- s = ((resultBinding.get("subject").toString()));
- p = ((resultBinding.get("predicate").toString()));
- if (p.equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#subClassOf")) {
- subClasses.add(s);
+ for (ResultBinding resultBinding : bindings) {
+
+ subject = ((resultBinding.get("subject").toString()));
+ predicate = ((resultBinding.get("predicate").toString()));
+ if (predicate
+ .equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#subClassOf")) {
+ subClasses.add(subject);
}
}
return subClasses;
}
/**
- * QUALITY: buggy because role doesn't work sometimes
- * get subject with fixed role and object
+ * QUALITY: buggy because role doesn't work sometimes get subject with fixed
+ * role and object
+ *
* @param role
* @param object
* @param resultLimit
* @return
*/
- public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(String role, String object,int resultLimit) {
- String SPARQLquery =
- "SELECT DISTINCT * WHERE { \n " +
- "?subject " +
- "<"+role+"> " +
- "<" + object + "> \n" +
- "} "+limit(resultLimit);
-
- return queryAsSet(SPARQLquery, "subject");
+ public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(
+ String role, String object, int resultLimit) {
+ String SPARQLquery = "SELECT DISTINCT * WHERE { \n " + "?subject "
+ + "<" + role + "> " + "<" + object + "> \n" + "} "
+ + limit(resultLimit);
+
+ return queryAsSet(SPARQLquery, "subject");
}
-
- public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject, String role, int resultLimit) {
- String SPARQLquery =
- "SELECT DISTINCT * WHERE { \n " +
- "<" +subject+ "> "+
- "<"+role+"> " +
- " ?object \n" +
- "} LIMIT "+resultLimit;
-
- return queryAsSet(SPARQLquery, "object");
+
+ public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject,
+ String role, int resultLimit) {
+ String SPARQLquery = "SELECT DISTINCT * WHERE { \n " + "<" + subject
+ + "> " + "<" + role + "> " + " ?object \n" + "} LIMIT "
+ + resultLimit;
+
+ return queryAsSet(SPARQLquery, "object");
}
-
+
/**
* all instances for a SKOS concept
+ *
* @param SKOSconcept
* @param resultLimit
* @return
*/
- public SortedSet<String> retrieveInstancesForSKOSConcept(String SKOSconcept,int resultLimit) {
- return queryPatternAsSet("?subject", "?predicate", "<"+SKOSconcept+">", "subject", resultLimit);
- //return retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject",
+ public SortedSet<String> retrieveInstancesForSKOSConcept(
+ String SKOSconcept, int resultLimit) {
+ return queryPatternAsSet("?subject", "?predicate", "<" + SKOSconcept
+ + ">", "subject", resultLimit);
+ // return
+ // retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject",
}
-
-
-
+
/**
* get all instances for a concept
+ *
* @param conceptKBSyntax
* @param sparqlResultLimit
* @return
*/
- public SortedSet<String> retrieveInstancesForConcept (String conceptKBSyntax,int sparqlResultLimit) {
-
- String SPARQLquery = "";
- try{
- SPARQLquery = SparqlQueryDescriptionConvertVisitor
- .getSparqlQuery(conceptKBSyntax,sparqlResultLimit);
- }catch (Exception e) {e.printStackTrace();}
- return queryAsSet(SPARQLquery, "subject");
+ public SortedSet<String> retrieveInstancesForConcept(
+ String conceptKBSyntax, int sparqlResultLimit) {
+
+ String SPARQLquery = "";
+ try {
+ SPARQLquery = SparqlQueryDescriptionConvertVisitor.getSparqlQuery(
+ conceptKBSyntax, sparqlResultLimit);
+ } catch (Exception e) {
+ logger.warn(e.getMessage());
+ }
+ return queryAsSet(SPARQLquery, "subject");
}
-
+
/**
* get all instances for a concept including RDFS Reasoning
+ *
* @param conceptKBSyntax
* @param sparqlResultLimit
* @return
*/
- public SortedSet<String> retrieveInstancesForConceptIncludingSubclasses (String conceptKBSyntax,int sparqlResultLimit) {
-
- String SPARQLquery = "";
- try{
+ public SortedSet<String> retrieveInstancesForConceptIncludingSubclasses(
+ String conceptKBSyntax, int sparqlResultLimit) {
+
+ String SPARQLquery = "";
+ try {
SPARQLquery = SparqlQueryDescriptionConvertVisitor
- .getSparqlQueryIncludingSubclasses(conceptKBSyntax,sparqlResultLimit,this,true);
-
- }catch (Exception e) {e.printStackTrace();}
- return queryAsSet(SPARQLquery, "subject");
+ .getSparqlQueryIncludingSubclasses(conceptKBSyntax,
+ sparqlResultLimit, this, true);
+
+ } catch (Exception e) {
+ logger.warn(e.getMessage());
+ }
+ return queryAsSet(SPARQLquery, "subject");
}
-
-
-
-
+
/**
* get all direct Classes of an instance
+ *
* @param instance
* @param resultLimit
* @return
*/
- public SortedSet<String> getClassesForInstance(String instance, int resultLimit) {
-
- String SPARQLquery = "SELECT ?subject WHERE { \n " +
- "<" + instance + ">"+
- " a " +
- "?subject " +
- "\n" +
- "} "+limit(resultLimit);
-
- return queryAsSet(SPARQLquery, "subject");
+ public SortedSet<String> getClassesForInstance(String instance,
+ int resultLimit) {
+
+ String SPARQLquery = "SELECT ?subject WHERE { \n " + "<" + instance
+ + ">" + " a " + "?subject " + "\n" + "} " + limit(resultLimit);
+
+ return queryAsSet(SPARQLquery, "subject");
}
-
-
- public SortedSet<String> getDomain(String role,int resultLimit){
-
- String SPARQLquery = "" +
- "SELECT DISTINCT ?domain " +
- "WHERE { \n" +
- "?domain <" + role + "> " + " ?o. \n" +
- "?domain a []\n." +
- "FILTER (!isLiteral(?domain))." +
- "}\n" + limit(resultLimit);
-
+ public SortedSet<String> getDomain(String role, int resultLimit) {
+
+ String SPARQLquery = "SELECT DISTINCT ?domain " + "WHERE { \n"
+ + "?domain <" + role + "> " + " ?o. \n" + "?domain a []\n."
+ + "FILTER (!isLiteral(?domain))." + "}\n" + limit(resultLimit);
+
return queryAsSet(SPARQLquery, "domain");
-
-
+
}
-
-
- public SortedSet<String> getRange(String role,int resultLimit){
-
- String SPARQLquery = "" +
- "SELECT DISTINCT ?range " +
- "WHERE { \n" +
- "?s <" + role + "> " + " ?range. \n" +
- "?range a [].\n" +
- "FILTER (!isLiteral(?range))." +
- "}\n" + limit(resultLimit);
+ public SortedSet<String> getRange(String role, int resultLimit) {
+
+ String SPARQLquery = "SELECT DISTINCT ?range " + "WHERE { \n" + "?s <"
+ + role + "> " + " ?range. \n" + "?range a [].\n"
+ + "FILTER (!isLiteral(?range))." + "}\n" + limit(resultLimit);
+
return queryAsSet(SPARQLquery, "range");
-
+
}
-
-
-
+
/**
- * query a pattern with a standard SPARQL query
- * usage (?subject, ?predicate, <http:something> , subject )
+ * query a pattern with a standard SPARQL query usage (?subject, ?predicate,
+ * <http:something> , subject )
+ *
* @param subject
* @param predicate
* @param object
* @param var
* @return
*/
- public SortedSet<String> queryPatternAsSet(String subject, String predicate, String object, String var, int resultLimit){
- String SPARQLquery = "SELECT ?subject WHERE { \n " +
- " " + subject +
- " " + predicate +
- " " + object +
- " \n" +
- "} "+limit(resultLimit);
- return queryAsSet( SPARQLquery, var);
- }
-
-
- /**
- * little higher level, executes query ,returns all resources for a variable
+ public SortedSet<String> queryPatternAsSet(String subject,
+ String predicate, String object, String var, int resultLimit) {
+ String SPARQLquery = "SELECT ?subject WHERE { \n " + " " + subject
+ + " " + predicate + " " + object + " \n" + "} "
+ + limit(resultLimit);
+ return queryAsSet(SPARQLquery, var);
+ }
+
+ /**
+ * little higher level, executes query ,returns all resources for a variable
+ *
* @param SPARQLquery
* @param var
* @return
*/
- public SortedSet<String> queryAsSet(String SPARQLquery, String var){
- ResultSet rs = null;
- try {
+ public SortedSet<String> queryAsSet(String SPARQLquery, String var) {
+ ResultSet rs = null;
+ try {
String JSON = query(SPARQLquery);
rs = SparqlQuery.JSONtoResultSet(JSON);
} catch (Exception e) {
- e.printStackTrace();
+ logger.warn(e.getMessage());
}
- return getStringListForVariable(rs,var);
- }
-
-
+ return getStringListForVariable(rs, var);
+ }
+
/**
* low level, executes query returns ResultSet
+ *
* @param SPARQLquery
* @return jena ResultSet
*/
- public ResultSet queryAsResultSet(String SPARQLquery){
+ public ResultSet queryAsResultSet(String SPARQLquery) {
return SparqlQuery.JSONtoResultSet(query(SPARQLquery));
-
+
}
-
+
/**
- * low level, executes query returns JSON
+ * low level, executes query returns JSON
+ *
* @param SPARQLquery
* @return
*/
- public String query(String SPARQLquery){
- if(c==null){
- SparqlQuery sq = new SparqlQuery(SPARQLquery,se);
-// sq.extraDebugInfo+=se.getURL();
+ public String query(String SPARQLquery) {
+ String JSON;
+ if (cache == null) {
+ SparqlQuery sq = new SparqlQuery(SPARQLquery, sparqlEndpoint);
sq.send();
- String JSON = sq.getJson();
- return JSON;
- }else{
- return c.executeSparqlQuery(new SparqlQuery(SPARQLquery,se));
+ JSON = sq.getJson();
+ } else {
+ JSON = cache.executeSparqlQuery(new SparqlQuery(SPARQLquery,
+ sparqlEndpoint));
}
-
+ return JSON;
}
-
- private String limit(int resultLimit){
- if(resultLimit>0)return " LIMIT "+resultLimit;
- return "";
+
+ private String limit(int resultLimit) {
+ return (resultLimit > 0) ? " LIMIT " + resultLimit : "";
}
-
-
- public static SortedSet<String> getStringListForVariable(ResultSet rs, String var){
+
+ public static SortedSet<String> getStringListForVariable(ResultSet rs,
+ String var) {
SortedSet<String> result = new TreeSet<String>();
-
- //String s=ResultSetFormatter.asXMLString(this.rs);
+
+ // String s=ResultSetFormatter.asXMLString(this.rs);
@SuppressWarnings("unchecked")
- List<ResultBinding> l = ResultSetFormatter.toList(rs);
-
+ List<ResultBinding> l = ResultSetFormatter.toList(rs);
+
for (ResultBinding resultBinding : l) {
result.add(resultBinding.get(var).toString());
}
-
+
return result;
-
+
}
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-28 17:50:10 UTC (rev 1020)
+++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-29 08:24:15 UTC (rev 1021)
@@ -1,5 +1,26 @@
+/**
+ * Copyright (C) 2007, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package org.dllearner.scripts;
+import java.io.File;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -13,6 +34,7 @@
import org.apache.log4j.SimpleLayout;
import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent;
import org.dllearner.core.ComponentManager;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.KnowledgeSource;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
@@ -26,6 +48,7 @@
import org.dllearner.learningproblems.PosNegDefinitionLP;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.reasoning.FastInstanceChecker;
+import org.dllearner.utilities.Files;
import org.dllearner.utilities.JamonMonitorLogger;
import org.dllearner.utilities.datastructures.SetManipulation;
import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
@@ -34,156 +57,192 @@
public class SKOS7030 {
private static SPARQLTasks sparqlTasks;
-
+
+ private static LearningAlgorithm la;
+
+ private static final long wash = 1216800000000L;
+
+ private boolean stable = true;
+
+ // private static long wash = 1216901570168
+
private static Logger logger = Logger.getRootLogger();
- static boolean local = true;
- static String url = "";
-
- //LEARNING
- static int recursiondepth=1;
- static boolean closeAfterRecursion=true;
- static boolean randomizeCache=false;
- static double noise=15;
+
+ static boolean local = true;
+
+ static String url = "";
+
+ // LEARNING
+ static int recursiondepth = 1;
+
+ static boolean closeAfterRecursion = true;
+
+ static boolean randomizeCache = false;
+
+ static double noise = 15;
+
static int maxExecutionTimeInSeconds = 30;
+
static int guaranteeXgoodDescriptions = 40;
-
-
- //examples
- static int sparqlResultSize=2000;
- static double percentOfSKOSSet=0.2;
- static double negfactor=1.0;
+
+ // examples
+ static int sparqlResultSize = 2000;
+
+ static double percentOfSKOSSet = 0.2;
+
+ static double negfactor = 1.0;
+
SortedSet<String> posExamples = new TreeSet<String>();
+
SortedSet<String> fullPositiveSet = new TreeSet<String>();
+
SortedSet<String> fullPosSetWithoutPosExamples = new TreeSet<String>();
+
SortedSet<String> negExamples = new TreeSet<String>();
-
-
-
-
-
+
/**
* @param args
*/
public static void main(String[] args) {
- System.out.println("Start");
-
+ logger.info("Start");
+ // String resultString="";
+ // System.out.println(time());
+ // System.out.println(System.currentTimeMillis());
+
initLogger();
- //parameters
-
-
- if(local){
+ // parameters
+
+ if (local) {
url = "http://139.18.2.37:8890/sparql";
- sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),SparqlEndpoint.EndpointLOCALDBpedia());
- }else{
+ sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),
+ SparqlEndpoint.EndpointLOCALDBpedia());
+ } else {
url = "http://dbpedia.openlinksw.com:8890/sparql";
- sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),SparqlEndpoint.EndpointDBpedia());
+ sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),
+ SparqlEndpoint.EndpointDBpedia());
}
+
+ //System.out.println(sparqlTasks.getDomain(
+ // "http://dbpedia.org/property/predecessor", 1000));
- System.out.println(sparqlTasks.getDomain("http://dbpedia.org/property/predecessor", 1000));
-
- String prim="http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
-
-// String award=("http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners");
-
- SKOS7030 s= new SKOS7030();
-
- s.makeExamples(prim, percentOfSKOSSet, negfactor, sparqlResultSize);
-
- List<Description> conceptresults = s.learn();
- logger.debug("found nr of concepts: "+conceptresults.size());
+ String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
+
+ // String
+ // award=("http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners");
+
+ SKOS7030 s = new SKOS7030();
+
+ s.makeExamples(target, percentOfSKOSSet, negfactor, sparqlResultSize);
+
+ // System.exit(0);
+ List<Description> conceptresults = new ArrayList<Description>();
+ List<EvaluatedDescription> conceptresults2 = new ArrayList<EvaluatedDescription>();
+ s.learn();
+
+ recordConceptClasses();
+
+ System.exit(0);
+
+ // EvaluatedDescription
+ logger.debug("found nr of concepts: " + conceptresults.size());
System.out.println(conceptresults);
-
- int x=0;
-
+
+ int x = 0;
+
SortedSet<ResultMostCoveredInRest> res = new TreeSet<ResultMostCoveredInRest>();
for (Description concept : conceptresults) {
- if(x++==100)break;
+ if (x++ == 100)
+ break;
res.add(s.evaluate(concept, 1000));
-
+
}
-
- x=0;
+
+ x = 0;
for (ResultMostCoveredInRest resultMostCoveredInRest : res) {
- if(x++==10)break;
+ if (x++ == 10)
+ break;
System.out.println(resultMostCoveredInRest.concept);
System.out.println(resultMostCoveredInRest.accuracy);
System.out.println(resultMostCoveredInRest.retrievedInstancesSize);
-
-
+
}
-
+
s.print(res.first().concept, 1000);
-
+
System.out.println("Finished");
JamonMonitorLogger.printAllSortedByLabel();
-
- }
-
- void print(Description concept, int sparqlResultLimit){
- logger.debug("evaluating concept: "+concept);
-// SortedSet<String> instances = sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(), sparqlResultLimit);
- SortedSet<String> instances =
- sparqlTasks.retrieveInstancesForConceptIncludingSubclasses(
- concept.toKBSyntaxString(),sparqlResultLimit);
-
- SortedSet<String> coveredInRest = new TreeSet<String>(fullPosSetWithoutPosExamples);
+
+ }
+
+ void print(final Description concept, final int sparqlResultLimit) {
+ logger.debug("evaluating concept: " + concept);
+ // SortedSet<String> instances =
+ // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(),
+ // sparqlResultLimit);
+ SortedSet<String> instances = sparqlTasks
+ .retrieveInstancesForConceptIncludingSubclasses(concept
+ .toKBSyntaxString(), sparqlResultLimit);
+
+ SortedSet<String> coveredInRest = new TreeSet<String>(
+ fullPosSetWithoutPosExamples);
coveredInRest.retainAll(instances);
-
-
+
SortedSet<String> coveredTotal = new TreeSet<String>(fullPositiveSet);
coveredTotal.retainAll(instances);
-
-
- SortedSet<String> notCoveredInRest = new TreeSet<String>(fullPosSetWithoutPosExamples);
+
+ SortedSet<String> notCoveredInRest = new TreeSet<String>(
+ fullPosSetWithoutPosExamples);
notCoveredInRest.retainAll(coveredInRest);
System.out.println(notCoveredInRest);
-
+
SortedSet<String> notCoveredTotal = new TreeSet<String>(fullPositiveSet);
notCoveredTotal.retainAll(coveredTotal);
System.out.println(notCoveredTotal);
-
+
}
-
- ResultMostCoveredInRest evaluate(Description concept, int sparqlResultLimit){
- logger.debug("evaluating concept: "+concept);
-// SortedSet<String> instances = sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(), sparqlResultLimit);
- SortedSet<String> instances =
- sparqlTasks.retrieveInstancesForConceptIncludingSubclasses(
- concept.toKBSyntaxString(),sparqlResultLimit);
-
- SortedSet<String> coveredInRest = new TreeSet<String>(fullPosSetWithoutPosExamples);
+
+ ResultMostCoveredInRest evaluate(Description concept, int sparqlResultLimit) {
+ logger.debug("evaluating concept: " + concept);
+ // SortedSet<String> instances =
+ // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(),
+ // sparqlResultLimit);
+ SortedSet<String> instances = sparqlTasks
+ .retrieveInstancesForConceptIncludingSubclasses(concept
+ .toKBSyntaxString(), sparqlResultLimit);
+
+ SortedSet<String> coveredInRest = new TreeSet<String>(
+ fullPosSetWithoutPosExamples);
coveredInRest.retainAll(instances);
-
+
SortedSet<String> coveredTotal = new TreeSet<String>(fullPositiveSet);
coveredTotal.retainAll(instances);
-
-
- SortedSet<String> notCoveredInRest = new TreeSet<String>(fullPosSetWithoutPosExamples);
+
+ SortedSet<String> notCoveredInRest = new TreeSet<String>(
+ fullPosSetWithoutPosExamples);
notCoveredInRest.retainAll(coveredInRest);
-
+
SortedSet<String> notCoveredTotal = new TreeSet<String>(fullPositiveSet);
notCoveredTotal.retainAll(coveredTotal);
- double acc = (double) (coveredInRest.size() / fullPosSetWithoutPosExamples.size());
- System.out.println("Accuracy: "+acc);
- return new ResultMostCoveredInRest(concept,acc,instances.size());
-
-
-
-
-
+ double acc = (double) (coveredInRest.size() / fullPosSetWithoutPosExamples
+ .size());
+ System.out.println("Accuracy: " + acc);
+ return new ResultMostCoveredInRest(concept, acc, instances.size());
+
}
-
-
-
- public static void initLogger() {
-
+
+ private static void initLogger() {
+
SimpleLayout layout = new SimpleLayout();
// create logger (a simple logger which outputs
// its messages to the console)
- FileAppender fileAppender =null; ;
- try{
- fileAppender = new FileAppender(layout,"the_log.txt",false);
- }catch (Exception e) {e.printStackTrace();}
+ FileAppender fileAppender = null;
+ ;
+ try {
+ fileAppender = new FileAppender(layout, "log/progress/skos"
+ + time() + ".txt", false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
logger.removeAllAppenders();
@@ -191,253 +250,298 @@
logger.addAppender(fileAppender);
logger.setLevel(Level.DEBUG);
Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
-
+
}
-
- /*public static SortedSet<String> selectDBpediaConcepts(int number){
- String query = "SELECT DISTINCT ?concept WHERE { \n" +
- "[] a ?concept .FILTER (regex(str(?concept),'yago'))" +
- " \n} \n"; //LIMIT "+number+"
-
- String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
- ResultSet rs =SparqlQuery.JSONtoResultSet(JSON);
- JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs);
- return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number);
- }*/
-
- public void makeExamples(String SKOSConcept, double percentOfSKOSSet , double negfactor, int sparqlResultSize){
-
- //POSITIVES
- AutomaticPositiveExampleFinderSPARQL apos = new AutomaticPositiveExampleFinderSPARQL(sparqlTasks);
+ /*
+ * public static SortedSet<String> selectDBpediaConcepts(int number){
+ * String query = "SELECT DISTINCT ?concept WHERE { \n" + "[] a ?concept
+ * .FILTER (regex(str(?concept),'yago'))" + " \n} \n"; //LIMIT "+number+"
+ *
+ * String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
+ * ResultSet rs =SparqlQuery.JSONtoResultSet(JSON); JenaResultSetConvenience
+ * rsc = new JenaResultSetConvenience(rs); return
+ * SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number); }
+ */
+
+ public void makeExamples(String SKOSConcept, double percentOfSKOSSet,
+ double negfactor, int sparqlResultSize) {
+
+ // POSITIVES
+ AutomaticPositiveExampleFinderSPARQL apos = new AutomaticPositiveExampleFinderSPARQL(
+ sparqlTasks);
apos.makePositiveExamplesFromSKOSConcept(SKOSConcept);
- fullPositiveSet = apos.getPosExamples();
-
- //System.exit(0);
-
- int poslimit=(int)Math.round(percentOfSKOSSet*fullPositiveSet.size());
- int neglimit=(int)Math.round(poslimit*negfactor);
-
- this.posExamples = SetManipulation.fuzzyShrink(fullPositiveSet,poslimit);
-
-
-
- //NEGATIVES
-
- AutomaticNegativeExampleFinderSPARQL aneg = new AutomaticNegativeExampleFinderSPARQL(fullPositiveSet,sparqlTasks);
-
- aneg.makeNegativeExamplesFromParallelClasses(posExamples, sparqlResultSize);
- this.negExamples = aneg.getNegativeExamples(neglimit);
-
+ fullPositiveSet = apos.getPosExamples();
+
+ // System.exit(0);
+
+ int poslimit = (int) Math.round(percentOfSKOSSet
+ * fullPositiveSet.size());
+ int neglimit = (int) Math.round(poslimit * negfactor);
+
+ posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit);
+
+ // NEGATIVES
+
+ AutomaticNegativeExampleFinderSPARQL aneg = new AutomaticNegativeExampleFinderSPARQL(
+ fullPositiveSet, sparqlTasks);
+
+ aneg.makeNegativeExamplesFromParallelClasses(posExamples,
+ sparqlResultSize);
+ negExamples = aneg.getNegativeExamples(neglimit, stable);
+
logger.debug("POSITIVE EXAMPLES");
for (String pos : posExamples) {
- logger.debug("+"+pos);
+ logger.debug("+" + pos);
}
-
+
logger.debug("NEGATIVE EXAMPLES");
for (String negs : this.negExamples) {
- logger.debug("-"+negs);
+ logger.debug("-" + negs);
}
-
-
-
+
fullPosSetWithoutPosExamples = fullPositiveSet;
fullPosSetWithoutPosExamples.removeAll(posExamples);
-
-
+
logger.debug(fullPositiveSet);
logger.debug(fullPosSetWithoutPosExamples);
}
-
- public List<Description> learn(){
-
+
+ public void learn() {
+
SortedSet<String> instances = new TreeSet<String>();
instances.addAll(this.posExamples);
instances.addAll(this.negExamples);
-
-
+
logger.info("Start Learning with");
- logger.info("positive examples: \t"+posExamples.size());
- logger.info("negative examples: \t"+negExamples.size());
- logger.info("instances \t"+instances.size());
-
-
-
-
-
+ logger.info("positive examples: \t" + posExamples.size());
+ logger.info("negative examples: \t" + negExamples.size());
+ logger.info("instances \t" + instances.size());
+
ComponentManager cm = ComponentManager.getInstance();
- LearningAlgorithm la = null;
+ // LearningAlgorithm la = null;
ReasoningService rs = null;
- LearningProblem lp = null;
- SparqlKnowledgeSource ks =null;
+ LearningProblem lp = null;
+ SparqlKnowledgeSource ks = null;
try {
- Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>();
- ks = cm.knowledgeSource(SparqlKnowledgeSource.class);
- ReasonerComponent r = new FastInstanceChecker(sources);
- rs = new ReasoningService(r);
- //System.out.println("satisfy: "+rs.isSatisfiable());
- lp = new PosNegDefinitionLP(rs);
- ((PosNegLP) lp).setPositiveExamples(SetManipulation.stringToInd(this.posExamples));
- ((PosNegLP) lp).setNegativeExamples(SetManipulation.stringToInd(this.negExamples));
-
- la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs);
+ Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>();
+ ks = cm.knowledgeSource(SparqlKnowledgeSource.class);
+ ReasonerComponent r = new FastInstanceChecker(sources);
+ rs = new ReasoningService(r);
+ // System.out.println("satisfy: "+rs.isSatisfiable());
+ lp = new PosNegDefinitionLP(rs);
+ ((PosNegLP) lp).setPositiveExamples(SetManipulation
+ .stringToInd(this.posExamples));
+ ((PosNegLP) lp).setNegativeExamples(SetManipulation
+ .stringToInd(this.negExamples));
- logger.debug("start learning");
-
-
- //KNOWLEDGESOURCE
- cm.applyConfigEntry(ks, "instances",instances);
- cm.applyConfigEntry(ks, "url",url);
- cm.applyConfigEntry(ks, "recursionDepth",recursiondepth);
- cm.applyConfigEntry(ks, "closeAfterRecursion",closeAfterRecursion);
- cm.applyConfigEntry(ks, "predefinedFilter","YAGO");
- if(local)
- cm.applyConfigEntry(ks, "predefinedEndpoint","LOCALDBPEDIA");
- else {
- cm.applyConfigEntry(ks, "predefinedEndpoint","DBPEDIA");
+ la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs);
+
+ logger.debug("start learning");
+
+ // KNOWLEDGESOURCE
+ cm.applyConfigEntry(ks, "instances", instances);
+ cm.applyConfigEntry(ks, "url", url);
+ cm.applyConfigEntry(ks, "recursionDepth", recursiondepth);
+ cm.applyConfigEntry(ks, "closeAfterRecursion", closeAfterRecursion);
+ cm.applyConfigEntry(ks, "predefinedFilter", "YAGO");
+ if (local)
+ cm.applyConfigEntry(ks, "predefinedEndpoint", "LOCALDBPEDIA");
+ else {
+ cm.applyConfigEntry(ks, "predefinedEndpoint", "DBPEDIA");
+ }
+ if (randomizeCache)
+ cm.applyConfigEntry(ks, "cacheDir", "cache/"
+ + System.currentTimeMillis() + "");
+ else {
+ cm.applyConfigEntry(ks, "cacheDir", Cache.getDefaultCacheDir());
+ }
+
+ // LEARNINGALGORITHM
+ cm.applyConfigEntry(la, "useAllConstructor", false);
+ cm.applyConfigEntry(la, "useExistsConstructor", true);
+ cm.applyConfigEntry(la, "useCardinalityRestrictions", false);
+ cm.applyConfigEntry(la, "useNegation", false);
+ cm.applyConfigEntry(la, "minExecutionTimeInSeconds", 0);
+ cm.applyConfigEntry(la, "maxExecutionTimeInSeconds",
+ maxExecutionTimeInSeconds);
+ cm.applyConfigEntry(la, "guaranteeXgoodDescriptions",
+ guaranteeXgoodDescriptions);
+ cm.applyConfigEntry(la, "writeSearchTree", false);
+ cm.applyConfigEntry(la, "searchTreeFile", "log/SKOS.txt");
+ cm.applyConfigEntry(la, "replaceSearchTree", true);
+ cm.applyConfigEntry(la, "noisePercentage", noise);
+ // cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",999999);
+ cm.applyConfigEntry(la, "logLevel", "TRACE");
+ /*
+ * if(ignoredConcepts.size()>0)
+ * cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts);
+ */
+
+ ks.init();
+ sources.add(ks);
+ r.init();
+ lp.init();
+ la.init();
+
+ la.start();
+ // Statistics.addTimeCollecting(sc.getTime());
+ // Statistics.addTimeLearning(sc.getTime());
+
+ // return la.getCurrentlyBestDescriptions();
+
+ } catch (Exception e) {
+ e.printStackTrace();
}
- if(randomizeCache)
- cm.applyConfigEntry(ks, "cacheDir","cache/"+System.currentTimeMillis()+"");
- else {cm.applyConfigEntry(ks, "cacheDir",Cache.getDefaultCacheDir());}
-
- //LEARNINGALGORITHM
- cm.applyConfigEntry(la,"useAllConstructor",false);
- cm.applyConfigEntry(la,"useExistsConstructor",true);
- cm.applyConfigEntry(la,"useCardinalityRestrictions",false);
- cm.applyConfigEntry(la,"useNegation",false);
- cm.applyConfigEntry(la,"minExecutionTimeInSeconds",0);
- cm.applyConfigEntry(la,"maxExecutionTimeInSeconds",maxExecutionTimeInSeconds);
- cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",guaranteeXgoodDescriptions);
- cm.applyConfigEntry(la,"writeSearchTree",false);
- cm.applyConfigEntry(la,"searchTreeFile","log/SKOS.txt");
- cm.applyConfigEntry(la,"replaceSearchTree",true);
- cm.applyConfigEntry(la,"noisePercentage",noise);
- //cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",999999);
- cm.applyConfigEntry(la,"logLevel","TRACE");
- /*if(ignoredConcepts.size()>0)
- cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts);
- */
-
- ks.init();
- sources.add(ks);
- r.init();
- lp.init();
- la.init();
-
-
- la.start();
- //Statistics.addTimeCollecting(sc.getTime());
- //Statistics.addTimeLearning(sc.getTime());
-
-
- return la.getCurrentlyBestDescriptions();
-
- }catch (Exception e) {e.printStackTrace();}
- return null;
-
+ // return null;
+
}
-
-// String t="\"http://dbpedia.org/class/yago/Fiction106367107\"";
-// t="(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND \"http://dbpedia.org/class/yago/Representative110522035\"))";
-// //System.out.println(t);
-// //t="\"http://www.w3.org/2004/02/skos/core#subject\"";
-// //conceptRewrite(t);
-// //getSubClasses(t);
-//
-// AutomaticExampleFinderSKOSSPARQL ae= new AutomaticExampleFinderSKOSSPARQL( se);
-// try{
-// System.out.println("oneconcept: "+t);
-// SortedSet<String> instances = ae.queryConceptAsStringSet(conceptRewrite(t), 200);
-// if(instances.size()>=0)System.out.println("size of instances "+instances.size());
-// if(instances.size()>=0 && instances.size()<100) System.out.println("instances"+instances);
-// }catch (Exception e) {
-// e.printStackTrace();
-// }
- //SortedSet<String> concepts = new TreeSet<String>();
-
-
-
- //System.out.println(DBpediaSKOS(prim));
-// double acc1=0.0;
-// for (int i = 0; i < 5; i++) {
-// acc1+=DBpediaSKOS(prim);
-// }
-// System.out.println("accprim"+(acc1/5));
-//
-// double acc2=0.0;
-// for (int i = 0; i < 5; i++) {
-// acc2+=DBpediaSKOS(award);
-// }
-// System.out.println("accprim"+(acc2/5));
-
-// DBpediaSKOS(concepts.first());
-// DBpediaSKOS(concepts.first());
-// concepts.remove(concepts.first());
-// DBpediaSKOS(concepts.first());
-// DBpediaSKOS(concepts.first());
-// concepts.remove(concepts.first());
-// DBpediaSKOS(concepts.first());
-// DBpediaSKOS(concepts.first());
- //algorithm="refinement";
- //roles();
-
- /*System.out.println(Level.DEBUG.getClass());
- System.out.println(Level.toLevel("INFO"));
- System.out.println(Level.INFO);*/
- //System.exit(0);
-
- private class ResultCompare implements Comparable<ResultCompare>{
- Description concept ;
+ // String t="\"http://dbpedia.org/class/yago/Fiction106367107\"";
+ // t="(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND
+ // (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND
+ // \"http://dbpedia.org/class/yago/Representative110522035\"))";
+ // //System.out.println(t);
+ // //t="\"http://www.w3.org/2004/02/skos/core#subject\"";
+ // //conceptRewrite(t);
+ // //getSubClasses(t);
+ //
+ // AutomaticExampleFinderSKOSSPARQL ae= new
+ // AutomaticExampleFinderSKOSSPARQL( se);
+ // try{
+ // System.out.println("oneconcept: "+t);
+ // SortedSet<String> instances =
+ // ae.queryConceptAsStringSet(conceptRewrite(t), 200);
+ // if(instances.size()>=0)System.out.println("size of instances
+ // "+instances.size());
+ // if(instances.size()>=0 && instances.size()<100)
+ // System.out.println("instances"+instances);
+ // }catch (Exception e) {
+ // e.printStackTrace();
+ // }
+ // SortedSet<String> concepts = new TreeSet<String>();
+
+ // System.out.println(DBpediaSKOS(prim));
+ // double acc1=0.0;
+ // for (int i = 0; i < 5; i++) {
+ // acc1+=DBpediaSKOS(prim);
+ // }
+ // System.out.println("accprim"+(acc1/5));
+ //
+ // double acc2=0.0;
+ // for (int i = 0; i < 5; i++) {
+ // acc2+=DBpediaSKOS(award);
+ // }
+ // System.out.println("accprim"+(acc2/5));
+
+ // DBpediaSKOS(concepts.first());
+ // DBpediaSKOS(concepts.first());
+ // concepts.remove(concepts.first());
+ // DBpediaSKOS(concepts.first());
+ // DBpediaSKOS(concepts.first());
+ // concepts.remove(concepts.first());
+ // DBpediaSKOS(concepts.first());
+ // DBpediaSKOS(concepts.first());
+ // algorithm="refinement";
+ // roles();
+
+ /*
+ * System.out.println(Level.DEBUG.getClass());
+ * System.out.println(Level.toLevel("INFO"));
+ * System.out.println(Level.INFO);
+ */
+ // System.exit(0);
+ private class ResultCompare implements Comparable<ResultCompare> {
+ Description concept;
+
double accuracy = 0.0;
- int retrievedInstancesSize=0;
-
+
+ int retrievedInstancesSize = 0;
+
public int compareTo(ResultCompare o2) {
return 0;
}
- public boolean equals(ResultCompare o2){
+
+ public boolean equals(ResultCompare o2) {
return this.concept.equals(o2.concept);
}
-
-
- public ResultCompare(Description conceptKBSyntax, double accuracy, int retrievedInstancesSize) {
+
+ public ResultCompare(Description conceptKBSyntax, double accuracy,
+ int retrievedInstancesSize) {
super();
this.concept = conceptKBSyntax;
this.accuracy = accuracy;
this.retrievedInstancesSize = retrievedInstancesSize;
}
-
-
+
}
-
- private class ResultMostCoveredInRest extends ResultCompare{
-
+
+ private class ResultMostCoveredInRest extends ResultCompare {
+
public ResultMostCoveredInRest(Description concept, double accuracy,
int retrievedInstancesSize) {
super(concept, accuracy, retrievedInstancesSize);
-
+
}
public int compareTo(ResultMostCoveredInRest o2) {
- if(this.equals(o2))return 0;
-
- if(this.accuracy > o2.accuracy){
+ if (this.equals(o2))
+ return 0;
+
+ if (this.accuracy > o2.accuracy) {
return 1;
- }
- else if(this.accuracy == o2.accuracy) {
- if(this.retrievedInstancesSize < o2.retrievedInstancesSize )
+ } else if (this.accuracy == o2.accuracy) {
+ if (this.retrievedInstancesSize < o2.retrievedInstancesSize)
return 1;
- else if(this.retrievedInstancesSize > o2.retrievedInstancesSize){
+ else if (this.retrievedInstancesSize > o2.retrievedInstancesSize) {
return -1;
- }
- else return this.concept.toKBSyntaxString().compareTo(o2.concept.toKBSyntaxString());
- }else {
+ } else
+ return this.concept.toKBSyntaxString().compareTo(
+ o2.concept.toKBSyntaxString());
+ } else {
return -1;
}
-
+
}
-
+
}
-
-
+
+ public static String time() {
+ return ("" + (System.currentTimeMillis() - wash)).substring(0, 7);
+
+ }
+
+ public static void recordConceptClasses() {
+ String result = "";
+ String result1 = "\n\n ***********Entity*****\n";
+ String result2 = "\n\n ***********OR*****\n";
+ int result1count = 1;
+ int result2count = 1;
+ List<EvaluatedDescription> conceptresults = la
+ .getCurrentlyBestEvaluatedDescriptions(5000, .70, true);
+
+ int x = 0;
+ for (EvaluatedDescription description : conceptresults) {
+ if (x < 50) {
+ x++;
+ result += description + "\n";
+ }
+
+ if (!description.toString().contains("Entity")) {
+ result1 += description + "\n";
+ result1count++;
+ }
+ if (!description.toString().contains("OR")) {
+ result2 += description + "\n";
+ result2count++;
+ }
+ }
+ result += "full size: " + conceptresults.size() + "";
+ result += result1 + " size: " + result1count + "\n";
+ result += result2 + " size: " + result2count + "\n";
+
+ Files.createFile(new File("results/descriptions/concepts" + time()
+ + ".txt"), result);
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-07-28 17:50:10 UTC (rev 1020)
+++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-07-29 08:24:15 UTC (rev 1021)
@@ -11,7 +11,7 @@
/**
* shrinks a set to the limit
- * size will be roughly the same as limit, but can be more or less a bit
+ * fuzzy here means the elements will be randomly picked
* @param set
* @param limit
* @return
@@ -37,6 +37,27 @@
return ret;
}
+ /**
+ * shrinks a set to the limit
+ * takes the first elements up to limit
+ * @param set
+ * @param limit
+ * @return
+ */
+ public static SortedSet<String> stableShrink(SortedSet<String> set, int limit) {
+ if (set.size()<=limit)return set;
+ SortedSet<String> ret = new TreeSet<String>();
+
+
+ for (String oneInd : set) {
+ ret.add(oneInd);
+ if(ret.size()>= limit)break;
+
+ }
+
+ return ret;
+ }
+
public static SortedSet<Individual> stringToInd(SortedSet<String> set ){
SortedSet<Individual> ret = new TreeSet<Individual>();
for (String ind : set) {
Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-28 17:50:10 UTC (rev 1020)
+++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-29 08:24:15 UTC (rev 1021)
@@ -1,3 +1,22 @@
+/**
+ * Copyright (C) 2007, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package org.dllearner.utilities.examples;
import java.util.SortedSet;
@@ -15,6 +34,7 @@
private SPARQLTasks sparqltasks;
+
private SortedSet<String> fullPositiveSet;
private SortedSet<String> fromRelated = new TreeSet<String>();
@@ -42,21 +62,29 @@
}
-
+ public SortedSet<String> getNegativeExamples(int neglimit ) {
+ return getNegativeExamples(neglimit, false);
+ }
/**
* aggregates all collected neg examples
- * @param neglimit
+ * @param neglimit size of negative Example set
+ * @param stable decides whether neg Examples are randomly picked, default false, faster for developing
* @return
*/
- public SortedSet<String> getNegativeExamples(int neglimit ) {
+ public SortedSet<String> getNegativeExamples(int neglimit, boolean stable ) {
SortedSet<String> negatives = new TreeSet<String>();
negatives.addAll(fromParallelClasses);
negatives.addAll(fromRelated);
negatives.addAll(fromSuperclasses);
logger.debug("neg Example size before shrinking: " + negatives.size());
- negatives = SetManipulation.fuzzyShrink(negatives,neglimit);
+ if (stable) {
+ negatives = SetManipulation.stableShrink(negatives,neglimit);
+ }
+ else {
+ negatives = SetManipulation.fuzzyShrink(negatives,neglimit);
+ }
logger.debug("neg Example size after shrinking: " + negatives.size());
return negatives;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Jen...@us...> - 2008-07-29 11:50:58
|
Revision: 1022
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1022&view=rev
Author: JensLehmann
Date: 2008-07-29 11:50:56 +0000 (Tue, 29 Jul 2008)
Log Message:
-----------
added EvaluatedDescription support to ROLearner
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
trunk/src/dl-learner/org/dllearner/test/ComponentTest.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-29 08:24:15 UTC (rev 1021)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-29 11:50:56 UTC (rev 1022)
@@ -40,6 +40,7 @@
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptComparator;
import org.dllearner.utilities.owl.ConceptTransformation;
+import org.dllearner.utilities.owl.EvaluatedDescriptionComparator;
public class ROLearner extends LearningAlgorithm {
@@ -100,6 +101,8 @@
private Comparator<Node> nodeComparator;
private NodeComparatorStable nodeComparatorStable = new NodeComparatorStable();
private ConceptComparator conceptComparator = new ConceptComparator();
+ // comparator for evaluated descriptions
+ private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator();
DecimalFormat df = new DecimalFormat();
private PosNegLP learningProblem;
@@ -1047,6 +1050,21 @@
return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore());
}
+ public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ int count = 0;
+ SortedSet<Node> rev = candidatesStable.descendingSet();
+ SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator);
+ for(Node eb : rev) {
+ cbd.add(new EvaluatedDescription(eb.getConcept(), getSolutionScore(eb.getConcept())));
+ // return a maximum of 200 elements (we need a maximum, because the
+ // candidate set can be very large)
+ if(count > 200)
+ return cbd;
+ count++;
+ }
+ return cbd;
+ }
+
public void printBestSolutions(int nrOfSolutions){
if(!logLevel.equalsIgnoreCase("TRACE")){return;}
if(nrOfSolutions==0)nrOfSolutions=solutions.size();
Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-07-29 08:24:15 UTC (rev 1021)
+++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-07-29 11:50:56 UTC (rev 1022)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007, Jens Lehmann
+ * Copyright (C) 2007-2008, Jens Lehmann
*
* This file is part of DL-Learner.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-07-29 14:30:29
|
Revision: 1024
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1024&view=rev
Author: kurzum
Date: 2008-07-29 14:30:25 +0000 (Tue, 29 Jul 2008)
Log Message:
-----------
some comments, some improvements
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
trunk/src/dl-learner/org/dllearner/cli/QuickStart.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-29 12:42:52 UTC (rev 1023)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-29 14:30:25 UTC (rev 1024)
@@ -238,8 +238,8 @@
// unterzogen und dann ein neues Programm erstellt
if(Math.random()<0.5) {
pt = crossover(p1.getTree(), p2.getTree());
- result[0] = createProgram(learningProblem, pt[0],p1.getAdc());
- result[1] = createProgram(learningProblem, pt[1],p2.getAdc());
+ result[0] = createProgram(learningProblem, pt[0], p1.getAdc());
+ result[1] = createProgram(learningProblem, pt[1], p2.getAdc());
} else {
pt = crossover(p1.getAdc(), p2.getAdc());
result[0] = createProgram(learningProblem, p1.getTree(),pt[0]);
Modified: trunk/src/dl-learner/org/dllearner/cli/QuickStart.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2008-07-29 12:42:52 UTC (rev 1023)
+++ trunk/src/dl-learner/org/dllearner/cli/QuickStart.java 2008-07-29 14:30:25 UTC (rev 1024)
@@ -119,7 +119,7 @@
} catch (Exception e) {
System.out.println("Not a number");
}
- ;
+
}// end while
if (number) {
try {
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-29 12:42:52 UTC (rev 1023)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-29 14:30:25 UTC (rev 1024)
@@ -40,31 +40,38 @@
*/
public class SPARQLTasks {
- private static final Logger logger = Logger.getLogger(SPARQLTasks.class);
+ private static Logger logger = Logger.getLogger(SPARQLTasks.class);
private final Cache cache;
private final SparqlEndpoint sparqlEndpoint;
- public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) {
+ /**
+ * @param c a cache object
+ * @param se the Endpoint the sparql queries will be send to
+ */
+ public SPARQLTasks(final Cache c, final SparqlEndpoint se) {
super();
- this.cache = cache;
- this.sparqlEndpoint = sparqlEndpoint;
+ this.cache = c;
+ this.sparqlEndpoint = se;
}
- public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) {
+ /**
+ * @param se the Endpoint the sparql queries will be send to
+ */
+ public SPARQLTasks(final SparqlEndpoint se) {
super();
this.cache = null;
- this.sparqlEndpoint = sparqlEndpoint;
+ this.sparqlEndpoint = se;
}
/**
* QUALITY: doesn't seem optimal, check! get all superclasses up to a
* certain depth 1 means direct superclasses depth
*
- * @param superClasses
- * @param maxdepth
- * @return
+ * @param oneClass the class for which the superclasses will be retrieved
+ * @param maxdepth how far the RDF graph will be explored (1 means only direct SuperClasses)
+ * @return a Sorted String Set of all ClassNames, including the starting class
*/
public SortedSet<String> getSuperClasses(final String oneClass,
final int maxdepth) {
@@ -73,7 +80,7 @@
superClasses.add(oneClass);
SortedSet<String> ret = new TreeSet<String>();
SortedSet<String> tmpset = new TreeSet<String>();
- String SPARQLquery = "";
+ String sparqlQuery = "";
// ret.addAll(superClasses);
// logger.debug(superClasses);
@@ -81,14 +88,14 @@
for (String oneSuperClass : superClasses) {
// tmp = oneSuperClass.replace("\"", "");
- SPARQLquery = "SELECT * WHERE { \n"
+ sparqlQuery = "SELECT * WHERE { \n"
+ "<"
+ oneSuperClass
+ "> "
+ "<http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass. \n"
+ "}";
- tmpset.addAll(queryAsSet(SPARQLquery, "superclass"));
+ tmpset.addAll(queryAsSet(sparqlQuery, "superclass"));
}// end inner for
ret.addAll(tmpset);
@@ -103,7 +110,8 @@
}
/**
- * gets a SortedSet of all subclasses QUALITY: maybe it is better to have a
+ * gets a SortedSet of all subclasses.
+ * QUALITY: maybe it is better to have a
* parameter int depth, to choose a depth of subclass interference
*
* @see conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache
@@ -138,8 +146,7 @@
} else {
- logger
- .warn("Retrieval auf all subclasses via SPARQL is cost intensive and might take a while");
+ logger.warn("Retrieval auf all subclasses via SPARQL is cost intensive and might take a while");
SortedSet<String> tmpSet = new TreeSet<String>();
while (!remainingClasses.isEmpty()) {
@@ -173,14 +180,14 @@
*/
private SortedSet<String> getDirectSubClasses(final String concept) {
- String SPARQLquery;
+ String sparqlQueryString;
SortedSet<String> subClasses = new TreeSet<String>();
ResultSet resultSet;
- SPARQLquery = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <"
+ sparqlQueryString = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <"
+ concept + "> \n" + "}\n";
- resultSet = queryAsResultSet(SPARQLquery);
+ resultSet = queryAsResultSet(sparqlQueryString);
@SuppressWarnings("unchecked")
List<ResultBinding> bindings = ResultSetFormatter.toList(resultSet);
@@ -200,6 +207,8 @@
}
/**
+ * Retrieves all resource for a fixed role and object.
+ * These instances are distinct.
* QUALITY: buggy because role doesn't work sometimes get subject with fixed
* role and object
*
@@ -210,39 +219,39 @@
*/
public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(
String role, String object, int resultLimit) {
- String SPARQLquery = "SELECT DISTINCT * WHERE { \n " + "?subject "
+ String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "?subject "
+ "<" + role + "> " + "<" + object + "> \n" + "} "
+ limit(resultLimit);
- return queryAsSet(SPARQLquery, "subject");
+ return queryAsSet(sparqlQueryString, "subject");
}
public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject,
String role, int resultLimit) {
- String SPARQLquery = "SELECT DISTINCT * WHERE { \n " + "<" + subject
+ String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" + subject
+ "> " + "<" + role + "> " + " ?object \n" + "} LIMIT "
+ resultLimit;
- return queryAsSet(SPARQLquery, "object");
+ return queryAsSet(sparqlQueryString, "object");
}
/**
- * all instances for a SKOS concept
+ * all instances for a SKOS concept.
*
- * @param SKOSconcept
+ * @param skosConcept
* @param resultLimit
* @return
*/
public SortedSet<String> retrieveInstancesForSKOSConcept(
- String SKOSconcept, int resultLimit) {
- return queryPatternAsSet("?subject", "?predicate", "<" + SKOSconcept
+ String skosConcept, int resultLimit) {
+ return queryPatternAsSet("?subject", "?predicate", "<" + skosConcept
+ ">", "subject", resultLimit);
// return
// retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject",
}
/**
- * get all instances for a concept
+ * get all instances for a concept.
*
* @param conceptKBSyntax
* @param sparqlResultLimit
@@ -251,18 +260,18 @@
public SortedSet<String> retrieveInstancesForConcept(
String conceptKBSyntax, int sparqlResultLimit) {
- String SPARQLquery = "";
+ String sparqlQueryString = "";
try {
- SPARQLquery = SparqlQueryDescriptionConvertVisitor.getSparqlQuery(
+ sparqlQueryString = SparqlQueryDescriptionConvertVisitor.getSparqlQuery(
conceptKBSyntax, sparqlResultLimit);
} catch (Exception e) {
logger.warn(e.getMessage());
}
- return queryAsSet(SPARQLquery, "subject");
+ return queryAsSet(sparqlQueryString, "subject");
}
/**
- * get all instances for a concept including RDFS Reasoning
+ * get all instances for a concept including RDFS Reasoning.
*
* @param conceptKBSyntax
* @param sparqlResultLimit
@@ -271,20 +280,20 @@
public SortedSet<String> retrieveInstancesForConceptIncludingSubclasses(
String conceptKBSyntax, int sparqlResultLimit) {
- String SPARQLquery = "";
+ String sparqlQueryString = "";
try {
- SPARQLquery = SparqlQueryDescriptionConvertVisitor
+ sparqlQueryString = SparqlQueryDescriptionConvertVisitor
.getSparqlQueryIncludingSubclasses(conceptKBSyntax,
sparqlResultLimit, this, true);
} catch (Exception e) {
logger.warn(e.getMessage());
}
- return queryAsSet(SPARQLquery, "subject");
+ return queryAsSet(sparqlQueryString, "subject");
}
/**
- * get all direct Classes of an instance
+ * get all direct Classes of an instance.
*
* @param instance
* @param resultLimit
@@ -293,35 +302,35 @@
public SortedSet<String> getClassesForInstance(String instance,
int resultLimit) {
- String SPARQLquery = "SELECT ?subject WHERE { \n " + "<" + instance
+ String sparqlQueryString = "SELECT ?subject WHERE { \n " + "<" + instance
+ ">" + " a " + "?subject " + "\n" + "} " + limit(resultLimit);
- return queryAsSet(SPARQLquery, "subject");
+ return queryAsSet(sparqlQueryString, "subject");
}
public SortedSet<String> getDomain(String role, int resultLimit) {
- String SPARQLquery = "SELECT DISTINCT ?domain " + "WHERE { \n"
+ String sparqlQueryString = "SELECT DISTINCT ?domain " + "WHERE { \n"
+ "?domain <" + role + "> " + " ?o. \n" + "?domain a []\n."
+ "FILTER (!isLiteral(?domain))." + "}\n" + limit(resultLimit);
- return queryAsSet(SPARQLquery, "domain");
+ return queryAsSet(sparqlQueryString, "domain");
}
public SortedSet<String> getRange(String role, int resultLimit) {
- String SPARQLquery = "SELECT DISTINCT ?range " + "WHERE { \n" + "?s <"
+ String sparqlQueryString = "SELECT DISTINCT ?range " + "WHERE { \n" + "?s <"
+ role + "> " + " ?range. \n" + "?range a [].\n"
+ "FILTER (!isLiteral(?range))." + "}\n" + limit(resultLimit);
- return queryAsSet(SPARQLquery, "range");
+ return queryAsSet(sparqlQueryString, "range");
}
/**
* query a pattern with a standard SPARQL query usage (?subject, ?predicate,
- * <http:something> , subject )
+ * <http://something> , subject ).
*
* @param subject
* @param predicate
@@ -331,24 +340,24 @@
*/
public SortedSet<String> queryPatternAsSet(String subject,
String predicate, String object, String var, int resultLimit) {
- String SPARQLquery = "SELECT ?subject WHERE { \n " + " " + subject
+ String sparqlQueryString = "SELECT ?subject WHERE { \n " + " " + subject
+ " " + predicate + " " + object + " \n" + "} "
+ limit(resultLimit);
- return queryAsSet(SPARQLquery, var);
+ return queryAsSet(sparqlQueryString, var);
}
/**
- * little higher level, executes query ,returns all resources for a variable
+ * little higher level, executes query ,returns all resources for a variable.
*
- * @param SPARQLquery
+ * @param sparqlQueryString
* @param var
* @return
*/
- public SortedSet<String> queryAsSet(String SPARQLquery, String var) {
+ public SortedSet<String> queryAsSet(String sparqlQueryString, String var) {
ResultSet rs = null;
try {
- String JSON = query(SPARQLquery);
- rs = SparqlQuery.JSONtoResultSet(JSON);
+ String jsonString = query(sparqlQueryString);
+ rs = SparqlQuery.JSONtoResultSet(jsonString);
} catch (Exception e) {
logger.warn(e.getMessage());
@@ -357,37 +366,37 @@
}
/**
- * low level, executes query returns ResultSet
+ * low level, executes query returns ResultSet.
*
- * @param SPARQLquery
+ * @param sparqlQueryString
* @return jena ResultSet
*/
- public ResultSet queryAsResultSet(String SPARQLquery) {
- return SparqlQuery.JSONtoResultSet(query(SPARQLquery));
+ public ResultSet queryAsResultSet(String sparqlQueryString) {
+ return SparqlQuery.JSONtoResultSet(query(sparqlQueryString));
}
/**
- * low level, executes query returns JSON
+ * low level, executes query returns JSON.
*
- * @param SPARQLquery
+ * @param sparqlQueryString
* @return
*/
- public String query(String SPARQLquery) {
- String JSON;
+ public String query(String sparqlQueryString) {
+ String jsonString;
if (cache == null) {
- SparqlQuery sq = new SparqlQuery(SPARQLquery, sparqlEndpoint);
+ SparqlQuery sq = new SparqlQuery(sparqlQueryString, sparqlEndpoint);
sq.send();
- JSON = sq.getJson();
+ jsonString = sq.getJson();
} else {
- JSON = cache.executeSparqlQuery(new SparqlQuery(SPARQLquery,
+ jsonString = cache.executeSparqlQuery(new SparqlQuery(sparqlQueryString,
sparqlEndpoint));
}
- return JSON;
+ return jsonString;
}
private String limit(int resultLimit) {
- return (resultLimit > 0) ? " LIMIT " + resultLimit : "";
+ return (resultLimit > 0) ? (" LIMIT " + resultLimit) : "";
}
public static SortedSet<String> getStringListForVariable(ResultSet rs,
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-29 12:42:52 UTC (rev 1023)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-29 14:30:25 UTC (rev 1024)
@@ -2,7 +2,7 @@
* Copyright (C) 2007-2008, Jens Lehmann
*
* This file is part of DL-Learner.
- *
+ *
* DL-Learner is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-29 12:42:52 UTC (rev 1023)
+++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-29 14:30:25 UTC (rev 1024)
@@ -55,6 +55,8 @@
import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
public class SKOS7030 {
+
+ public int test = 0;
private static SPARQLTasks sparqlTasks;
@@ -104,12 +106,23 @@
* @param args
*/
public static void main(String[] args) {
+ initLogger();
logger.info("Start");
// String resultString="";
// System.out.println(time());
// System.out.println(System.currentTimeMillis());
-
- initLogger();
+ String[] a = new String[2];
+ int x1=0;
+ try {
+ while(true)
+ a[x1++]="";
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ }
+
+ System.exit(0);
+
// parameters
if (local) {
@@ -236,7 +249,6 @@
// create logger (a simple logger which outputs
// its messages to the console)
FileAppender fileAppender = null;
- ;
try {
fileAppender = new FileAppender(layout, "log/progress/skos"
+ time() + ".txt", false);
@@ -462,6 +474,7 @@
return 0;
}
+
public boolean equals(ResultCompare o2) {
return this.concept.equals(o2.concept);
}
@@ -511,10 +524,13 @@
}
+ /**
+ *
+ */
public static void recordConceptClasses() {
- String result = "";
- String result1 = "\n\n ***********Entity*****\n";
- String result2 = "\n\n ***********OR*****\n";
+ StringBuffer result =new StringBuffer();
+ StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n");
+ StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n");
int result1count = 1;
int result2count = 1;
List<EvaluatedDescription> conceptresults = la
@@ -524,24 +540,24 @@
for (EvaluatedDescription description : conceptresults) {
if (x < 50) {
x++;
- result += description + "\n";
+ result.append(description + "\n");
}
if (!description.toString().contains("Entity")) {
- result1 += description + "\n";
+ result1.append(description + "\n");
result1count++;
}
if (!description.toString().contains("OR")) {
- result2 += description + "\n";
+ result2.append(description + "\n");
result2count++;
}
}
- result += "full size: " + conceptresults.size() + "";
- result += result1 + " size: " + result1count + "\n";
- result += result2 + " size: " + result2count + "\n";
+ result.append("full size: " + conceptresults.size());
+ result.append(result1.toString() + " size: " + result1count + "\n");
+ result.append(result2.toString() + " size: " + result2count + "\n");
Files.createFile(new File("results/descriptions/concepts" + time()
- + ".txt"), result);
+ + ".txt"), result.toString());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-07-30 06:53:40
|
Revision: 1025
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1025&view=rev
Author: kurzum
Date: 2008-07-30 06:53:34 +0000 (Wed, 30 Jul 2008)
Log Message:
-----------
more comments, renamed some simple functions, which is responsible for the changes in the most classes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java
trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java
trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java
trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java
trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java
trunk/src/dl-learner/org/dllearner/test/SparqlEndpointTest.java
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -99,7 +99,7 @@
// query.extraDebugInfo=uri.toString();
String JSON = cache.executeSparqlQuery(query);
- ResultSet rs = SparqlQuery.JSONtoResultSet(JSON);
+ ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON);
List<ResultBinding> l = ResultSetFormatter.toList(rs);
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -65,7 +65,7 @@
SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint());
// query.extraDebugInfo=uri.toString();
- ResultSet rs = SparqlQuery.JSONtoResultSet(cache.executeSparqlQuery(query));
+ ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(query));
List<ResultBinding> l = ResultSetFormatter.toList(rs);
for (ResultBinding resultBinding : l) {
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -82,18 +82,29 @@
this("cache");
} */
+ /**
+ * A Persistant cache is stored in the folder cachePersistant.
+ * It has longer freshness 365 days and is mainly usefull for developing
+ * @return a Cache onject
+ */
public static Cache getPersistentCache(){
Cache c = new Cache("cachePersistant");
c.setFreshnessInDays(365);
return c;
}
+ /**
+ * @return the default cache object
+ */
public static Cache getDefaultCache(){
Cache c = new Cache("cache");
-
return c;
}
+ /**
+ * the default cachedir normally is "cache".
+ * @return Default Cache Dir
+ */
public static String getDefaultCacheDir(){
return "cache";
}
@@ -146,17 +157,20 @@
*
* @param sparqlQuery
* SPARQL query to check.
- * @return Query result or null if no result has been found or it is
+ * @return Query result as JSON or null if no result has been found or it is
* outdated.
*/
@SuppressWarnings({"unchecked"})
private String getCacheEntry(String sparqlQuery) {
+
String filename = getFilename(sparqlQuery);
File file = new File(filename);
// return null (indicating no result) if file does not exist
- if(!file.exists())
+ if(!file.exists()) {
return null;
+ }
+
LinkedList<Object> entry = null;
try {
@@ -221,10 +235,7 @@
// check whether the given timestamp is fresh
private boolean checkFreshness(long timestamp) {
- if ((System.currentTimeMillis() - timestamp) <= (freshnessSeconds * 1000))
- return true;
- else
- return false;
+ return ((System.currentTimeMillis() - timestamp) <= (freshnessSeconds * 1000));
}
/**
@@ -242,7 +253,7 @@
JamonMonitorLogger.increaseCount(Cache.class, "TotalQueries");
JamonMonitorLogger.getTimeMonitor(Cache.class, "ReadTime").start();
- String result = getCacheEntry(query.getQueryString());
+ String result = getCacheEntry(query.getSparqlQueryString());
JamonMonitorLogger.getTimeMonitor(Cache.class, "ReadTime").stop();
if (result != null) {
@@ -250,8 +261,8 @@
query.setRunning(false);
SparqlQuery.writeToSparqlLog("***********\nJSON retrieved from cache");
- SparqlQuery.writeToSparqlLog(query.getQueryString());
- SparqlQuery.writeToSparqlLog(query.getEndpoint().getURL().toString());
+ SparqlQuery.writeToSparqlLog(query.getSparqlQueryString());
+ SparqlQuery.writeToSparqlLog(query.getSparqlEndpoint().getURL().toString());
SparqlQuery.writeToSparqlLog("JSON: "+result);
JamonMonitorLogger.increaseCount(Cache.class, "SuccessfulHits");
@@ -261,16 +272,15 @@
query.send();
String json = query.getJson();
if (json!=null){
- addToCache(query.getQueryString(), json);
+ addToCache(query.getSparqlQueryString(), json);
SparqlQuery.writeToSparqlLog("result added to cache: "+json);
result=json;
//query.setJson(result);
- }
- else {
+ } else {
json="";
result="";
- logger.warn(Cache.class.getSimpleName()+"empty result: "+query.getQueryString());
- SparqlQuery.writeToSparqlLog("empty result for : "+query.getQueryString());
+ logger.warn(Cache.class.getSimpleName()+"empty result: "+query.getSparqlQueryString());
+ SparqlQuery.writeToSparqlLog("empty result for : "+query.getSparqlQueryString());
}
//return json;
@@ -279,6 +289,10 @@
return result;
}
+ /**
+ * Changes how long cached results will stay fresh (default 15 days).
+ * @param days number of days
+ */
public void setFreshnessInDays(int days){
freshnessSeconds = days * 24 * 60 * 60;
}
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -47,22 +47,22 @@
private final SparqlEndpoint sparqlEndpoint;
/**
- * @param c a cache object
- * @param se the Endpoint the sparql queries will be send to
+ * @param cache a cache object
+ * @param sparqlEndpoint the Endpoint the sparql queries will be send to
*/
- public SPARQLTasks(final Cache c, final SparqlEndpoint se) {
+ public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) {
super();
- this.cache = c;
- this.sparqlEndpoint = se;
+ this.cache = cache;
+ this.sparqlEndpoint = sparqlEndpoint;
}
/**
- * @param se the Endpoint the sparql queries will be send to
+ * @param sparqlEndpoint the Endpoint the sparql queries will be send to
*/
- public SPARQLTasks(final SparqlEndpoint se) {
+ public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) {
super();
this.cache = null;
- this.sparqlEndpoint = se;
+ this.sparqlEndpoint = sparqlEndpoint;
}
/**
@@ -117,8 +117,6 @@
* @see conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache
* c, boolean simple )
* @param description
- * @param sparqlEndpoint
- * @param cache
* @param simple
* @return
*/
@@ -175,10 +173,10 @@
* empty set on some endpoints. returns all direct subclasses of String
* concept
*
- * @param concept
+ * @param concept An URI string with no quotes
* @return SortedSet of direct subclasses as String
*/
- private SortedSet<String> getDirectSubClasses(final String concept) {
+ private SortedSet<String> getDirectSubClasses(String concept) {
String sparqlQueryString;
SortedSet<String> subClasses = new TreeSet<String>();
@@ -212,25 +210,31 @@
* QUALITY: buggy because role doesn't work sometimes get subject with fixed
* role and object
*
- * @param role
- * @param object
- * @param resultLimit
- * @return
+ * @param role An URI string with no quotes
+ * @param object An URI string with no quotes
+ * @param sparqlResultLimit Limits the ResultSet size
+ * @return SortedSet with the resulting subjects
*/
public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(
- String role, String object, int resultLimit) {
+ String role, String object, int sparqlResultLimit) {
String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "?subject "
+ "<" + role + "> " + "<" + object + "> \n" + "} "
- + limit(resultLimit);
+ + limit(sparqlResultLimit);
return queryAsSet(sparqlQueryString, "subject");
}
+ /**
+ * @param subject An URI string with no quotes
+ * @param role An URI string with no quotes
+ * @param sparqlResultLimit Limits the ResultSet size
+ * @return
+ */
public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject,
- String role, int resultLimit) {
+ String role, int sparqlResultLimit) {
String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" + subject
+ "> " + "<" + role + "> " + " ?object \n" + "} LIMIT "
- + resultLimit;
+ + sparqlResultLimit;
return queryAsSet(sparqlQueryString, "object");
}
@@ -238,14 +242,14 @@
/**
* all instances for a SKOS concept.
*
- * @param skosConcept
- * @param resultLimit
+ * @param skosConcept An URI string with no quotes
+ * @param sparqlResultLimit Limits the ResultSet size
* @return
*/
public SortedSet<String> retrieveInstancesForSKOSConcept(
- String skosConcept, int resultLimit) {
+ String skosConcept, int sparqlResultLimit) {
return queryPatternAsSet("?subject", "?predicate", "<" + skosConcept
- + ">", "subject", resultLimit);
+ + ">", "subject", sparqlResultLimit);
// return
// retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject",
}
@@ -253,8 +257,8 @@
/**
* get all instances for a concept.
*
- * @param conceptKBSyntax
- * @param sparqlResultLimit
+ * @param conceptKBSyntax A description string in KBSyntax
+ * @param sparqlResultLimit Limits the ResultSet size
* @return
*/
public SortedSet<String> retrieveInstancesForConcept(
@@ -273,8 +277,8 @@
/**
* get all instances for a concept including RDFS Reasoning.
*
- * @param conceptKBSyntax
- * @param sparqlResultLimit
+ * @param conceptKBSyntax A description string in KBSyntax
+ * @param sparqlResultLimit Limits the ResultSet size
* @return
*/
public SortedSet<String> retrieveInstancesForConceptIncludingSubclasses(
@@ -295,15 +299,15 @@
/**
* get all direct Classes of an instance.
*
- * @param instance
- * @param resultLimit
+ * @param instance An URI string with no quotes
+ * @param sparqlResultLimit Limits the ResultSet size
* @return
*/
public SortedSet<String> getClassesForInstance(String instance,
- int resultLimit) {
+ int sparqlResultLimit) {
String sparqlQueryString = "SELECT ?subject WHERE { \n " + "<" + instance
- + ">" + " a " + "?subject " + "\n" + "} " + limit(resultLimit);
+ + ">" + " a " + "?subject " + "\n" + "} " + limit(sparqlResultLimit);
return queryAsSet(sparqlQueryString, "subject");
}
@@ -329,13 +333,15 @@
}
/**
- * query a pattern with a standard SPARQL query usage (?subject, ?predicate,
+ * //QUALITY rethink
+ * query a pattern with a standard SPARQL query.
+ * usage (?subject, <http://something>,
* <http://something> , subject ).
*
- * @param subject
- * @param predicate
- * @param object
- * @param var
+ * @param subject An URI string with no quotes
+ * @param predicate An URI string with no quotes
+ * @param object An URI string with no quotes
+ * @param var The single
* @return
*/
public SortedSet<String> queryPatternAsSet(String subject,
@@ -349,15 +355,15 @@
/**
* little higher level, executes query ,returns all resources for a variable.
*
- * @param sparqlQueryString
- * @param var
+ * @param sparqlQueryString The query
+ * @param var The single variable used in the query
* @return
*/
public SortedSet<String> queryAsSet(String sparqlQueryString, String var) {
ResultSet rs = null;
try {
String jsonString = query(sparqlQueryString);
- rs = SparqlQuery.JSONtoResultSet(jsonString);
+ rs = SparqlQuery.convertJSONtoResultSet(jsonString);
} catch (Exception e) {
logger.warn(e.getMessage());
@@ -368,18 +374,18 @@
/**
* low level, executes query returns ResultSet.
*
- * @param sparqlQueryString
+ * @param sparqlQueryString The query
* @return jena ResultSet
*/
public ResultSet queryAsResultSet(String sparqlQueryString) {
- return SparqlQuery.JSONtoResultSet(query(sparqlQueryString));
+ return SparqlQuery.convertJSONtoResultSet(query(sparqlQueryString));
}
/**
* low level, executes query returns JSON.
*
- * @param sparqlQueryString
+ * @param sparqlQueryString The query
* @return
*/
public String query(String sparqlQueryString) {
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -25,7 +25,7 @@
/**
* One sparql endpoint configuration,
- * made to comply with Jena
+ * made to comply with Jena.
*
* @author Sebastian Hellmann
*
@@ -42,7 +42,7 @@
this.namedGraphURIs=new LinkedList<String>();
}
- public SparqlEndpoint(URL u,List<String> defaultGraphURIs,List<String> namedGraphURIs) {
+ public SparqlEndpoint(URL u, List<String> defaultGraphURIs, List<String> namedGraphURIs) {
this.url = u;
this.defaultGraphURIs=defaultGraphURIs;
this.namedGraphURIs=namedGraphURIs;
@@ -86,57 +86,59 @@
name = name.toUpperCase();
- if (name.equals("DBPEDIA"))
- return EndpointDBpedia();
- if (name.equals("LOCALDBPEDIA"))
- return EndpointLOCALDBpedia();
- if (name.equals("LOCALJOSECKI"))
- return EndpointlocalJoseki();
- if (name.equals("GOVTRACK"))
- return EndpointGovTrack();
- if (name.equals("SPARQLETTE"))
- return EndpointSparqlette();
- if (name.equals("SWCONFERENCE"))
- return EndpointSWConference();
- if (name.equals("REVYU"))
- return EndpointRevyu();
- if (name.equals("MYOPENLINK"))
- return EndpointMyOpenlink();
- if (name.equals("FACTBOOK"))
- return EndpointWorldFactBook();
- if (name.equals("DBLP"))
- return EndpointDBLP();
- if (name.equals("MUSICBRAINZ"))
- return EndpointMusicbrainz();
- return null;
+ if (name.equals("DBPEDIA")) {
+ return getEndpointDBpedia();
+ } else if (name.equals("LOCALDBPEDIA")) {
+ return getEndpointLOCALDBpedia();
+ } else if (name.equals("LOCALJOSECKI")) {
+ return getEndpointlocalJoseki();
+ } else if (name.equals("GOVTRACK")) {
+ return getEndpointGovTrack();
+ } else if (name.equals("SPARQLETTE")) {
+ return getEndpointSparqlette();
+ } else if (name.equals("SWCONFERENCE")) {
+ return getEndpointSWConference();
+ } else if (name.equals("REVYU")) {
+ return getEndpointRevyu();
+ } else if (name.equals("MYOPENLINK")) {
+ return getEndpointMyOpenlink();
+ } else if (name.equals("FACTBOOK")) {
+ return getEndpointWorldFactBook();
+ } else if (name.equals("DBLP")) {
+ return getEndpointDBLP();
+ } else if (name.equals("MUSICBRAINZ")) {
+ return getEndpointMusicbrainz();
+ } else {
+ return null;
+ }
}
- public static LinkedList<SparqlEndpoint> listEndpoints() {
+ public static List<SparqlEndpoint> listEndpoints() {
LinkedList<SparqlEndpoint> ll =new LinkedList<SparqlEndpoint>();
- ll.add(EndpointDBLP());
- ll.add(EndpointDBpedia());
- ll.add(EndpointDOAPspace());
- ll.add(EndpointGovTrack());
- ll.add(EndpointJamendo());
- ll.add(EndpointJohnPeel());
- ll.add(EndpointlocalJoseki());
- ll.add(EndpointMagnaTune());
- ll.add(EndpointMusicbrainz());
- ll.add(EndpointMyOpenlink());
- ll.add(EndpointRevyu());
- ll.add(EndpointSWConference());
- ll.add(EndpointUSCensus());
- ll.add(EndpointWorldFactBook());
- ll.add(EndpointRiese());
- ll.add(EndpointTalisBlogs());
- ll.add(EndpointSWSchool());
- ll.add(EndpointSparqlette());
- ll.add(EndpointLOCALDBpedia());
+ ll.add(getEndpointDBLP());
+ ll.add(getEndpointDBpedia());
+ ll.add(getEndpointDOAPspace());
+ ll.add(getEndpointGovTrack());
+ ll.add(getEndpointJamendo());
+ ll.add(getEndpointJohnPeel());
+ ll.add(getEndpointlocalJoseki());
+ ll.add(getEndpointMagnaTune());
+ ll.add(getEndpointMusicbrainz());
+ ll.add(getEndpointMyOpenlink());
+ ll.add(getEndpointRevyu());
+ ll.add(getEndpointSWConference());
+ ll.add(getEndpointUSCensus());
+ ll.add(getEndpointWorldFactBook());
+ ll.add(getEndpointRiese());
+ ll.add(getEndpointTalisBlogs());
+ ll.add(getEndpointSWSchool());
+ ll.add(getEndpointSparqlette());
+ ll.add(getEndpointLOCALDBpedia());
return ll;
}
- public static SparqlEndpoint EndpointDBpedia() {
+ public static SparqlEndpoint getEndpointDBpedia() {
URL u = null;
try {
u = new URL("http://dbpedia.openlinksw.com:8890/sparql");
@@ -148,7 +150,7 @@
return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
}
- public static SparqlEndpoint EndpointLOCALDBpedia() {
+ public static SparqlEndpoint getEndpointLOCALDBpedia() {
URL u = null;
try {
u = new URL("http://139.18.2.37:8890/sparql");
@@ -160,7 +162,7 @@
return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>());
}
- public static SparqlEndpoint EndpointlocalJoseki() {
+ public static SparqlEndpoint getEndpointlocalJoseki() {
URL u = null;
try {
u = new URL("http://localhost:2020/books");
@@ -170,7 +172,7 @@
return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
}
- public static SparqlEndpoint EndpointWorldFactBook() {
+ public static SparqlEndpoint getEndpointWorldFactBook() {
URL u = null;
try {
u = new URL("http://www4.wiwiss.fu-berlin.de/factbook/sparql");
@@ -181,7 +183,7 @@
}
- public static SparqlEndpoint EndpointGovTrack() {
+ public static SparqlEndpoint getEndpointGovTrack() {
URL u = null;
try {
u = new URL("http://www.rdfabout.com/sparql");
@@ -191,7 +193,7 @@
return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
}
- public static SparqlEndpoint EndpointRevyu() {
+ public static SparqlEndpoint getEndpointRevyu() {
URL u = null;
try {
u = new URL("http://revyu.com/sparql");
@@ -201,7 +203,7 @@
return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>());
}
- public static SparqlEndpoint EndpointMyOpenlink() {
+ public static SparqlEndpoint getEndpointMyOpenlink() {
URL u = null;
try {
u = new URL("http://myopenlink.net:8890/sparql/");
@@ -214,7 +216,7 @@
}
- public static SparqlEndpoint EndpointDOAPspace() {
+ public static SparqlEndpoint getEndpointDOAPspace() {
URL u = null;
try {
u = new URL("http://doapspace.org/sparql");
@@ -226,7 +228,7 @@
}
- public static SparqlEndpoint EndpointJohnPeel() {
+ public static SparqlEndpoint getEndpointJohnPeel() {
URL u = null;
try {
u = new URL("http://dbtune.org:3030/sparql/");
@@ -240,7 +242,7 @@
- public static SparqlEndpoint EndpointSWConference() {
+ public static SparqlEndpoint getEndpointSWConference() {
URL u = null;
try {
u = new URL("http://data.semanticweb.org:8080/openrdf-sesame/repositories/SWC");
@@ -275,7 +277,7 @@
return new SpecificSparqlEndpoint(u, "dbtune.org", m);
}*/
- public static SparqlEndpoint EndpointJamendo() {
+ public static SparqlEndpoint getEndpointJamendo() {
URL u = null;
try {
u = new URL("http://dbtune.org:2105/sparql/");
@@ -287,7 +289,7 @@
- public static SparqlEndpoint EndpointMagnaTune() {
+ public static SparqlEndpoint getEndpointMagnaTune() {
URL u = null;
try {
u = new URL("http://dbtune.org:2020/sparql/");
@@ -298,7 +300,7 @@
}
- public static SparqlEndpoint EndpointMusicbrainz() {
+ public static SparqlEndpoint getEndpointMusicbrainz() {
URL u = null;
try {
u = new URL("http://dbtune.org/musicbrainz/sparql");
@@ -308,7 +310,7 @@
return new SparqlEndpoint(u);
}
- public static SparqlEndpoint EndpointRiese() {
+ public static SparqlEndpoint getEndpointRiese() {
URL u = null;
try {
u = new URL("http://riese.joanneum.at:3020/");
@@ -319,7 +321,7 @@
}
- public static SparqlEndpoint EndpointUSCensus() {
+ public static SparqlEndpoint getEndpointUSCensus() {
URL u = null;
try {
u = new URL("http://www.rdfabout.com/sparql");
@@ -337,7 +339,7 @@
/*
* it only has 4 classes
*/
- public static SparqlEndpoint EndpointDBLP() {
+ public static SparqlEndpoint getEndpointDBLP() {
URL u = null;
try {
u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql");
@@ -348,7 +350,7 @@
}
- public static SparqlEndpoint EndpointTalisBlogs() {
+ public static SparqlEndpoint getEndpointTalisBlogs() {
URL u = null;
try {
u = new URL("http://api.talis.com/stores/talisians/services/sparql");
@@ -358,7 +360,7 @@
return new SparqlEndpoint(u);
}
- public static SparqlEndpoint EndpointSparqlette() {
+ public static SparqlEndpoint getEndpointSparqlette() {
URL u = null;
try {
u = new URL("http://www.wasab.dk/morten/2005/04/sparqlette/");
@@ -370,7 +372,7 @@
- public static SparqlEndpoint EndpointSWSchool() {
+ public static SparqlEndpoint getEndpointSWSchool() {
URL u = null;
try {
u = new URL("http://sparql.semantic-web.at/snorql/");
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -118,7 +118,7 @@
.getLogger(SparqlKnowledgeSource.class);
/**
- * sets the ConfigOptions for this KnowledgeSource
+ * sets the ConfigOptions for this KnowledgeSource.
*
* @return
*/
@@ -195,7 +195,7 @@
* @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry)
*/
@Override
- @SuppressWarnings( { "unchecked" })
+ @SuppressWarnings({ "unchecked" })
public <T> void applyConfigEntry(ConfigEntry<T> entry)
throws InvalidConfigOptionValueException {
String option = entry.getOptionName();
@@ -348,9 +348,10 @@
String filename = System.currentTimeMillis() + ".nt";
String basedir = "cache" + File.separator;
try {
- if (!new File(basedir).exists())
+ if (!new File(basedir).exists()) {
new File(basedir).mkdir();
-
+ }
+
FileWriter fw = new FileWriter(
new File(basedir + filename), true);
fw.write(ont);
@@ -441,7 +442,7 @@
return dumpFile;
}
- public boolean getUseCache(){
+ public boolean isUseCache(){
return useCache;
}
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -49,50 +49,48 @@
private boolean wasExecuted = false;
- private String queryString;
+ private String sparqlQueryString;
private QueryEngineHTTP queryExecution;
- private SparqlEndpoint endpoint;
+ private SparqlEndpoint sparqlEndpoint;
private String json = null;
/**
* Standard constructor.
*
- * @param queryString
- * @param endpoint
+ * @param sparqlQueryString A SPARQL query string
+ * @param sparqlEndpoint An Endpoint object
*/
- public SparqlQuery(String queryString, SparqlEndpoint endpoint) {
+ public SparqlQuery(String sparqlQueryString, SparqlEndpoint sparqlEndpoint) {
// QUALITY there seems to be a bug in ontowiki
- this.queryString = queryString.replaceAll("\n", " ");
- this.endpoint = endpoint;
+ this.sparqlQueryString = sparqlQueryString.replaceAll("\n", " ");
+ this.sparqlEndpoint = sparqlEndpoint;
}
/**
* Sends a SPARQL query using the Jena library. main format is JSON, use
* method getasjson
*
- * @return nothing
*/
-
public void send() {
wasExecuted = true;
// isRunning = true;
ResultSet rs;
writeToSparqlLog("***********\nNew Query:");
- writeToSparqlLog(queryString);
- writeToSparqlLog(endpoint.getURL().toString());
+ writeToSparqlLog(sparqlQueryString);
+ writeToSparqlLog(sparqlEndpoint.getURL().toString());
- String service = endpoint.getURL().toString();
+ String service = sparqlEndpoint.getURL().toString();
// Jena access to SPARQL endpoint
- queryExecution = new QueryEngineHTTP(service, queryString);
- for (String dgu : endpoint.getDefaultGraphURIs()) {
+ queryExecution = new QueryEngineHTTP(service, sparqlQueryString);
+ for (String dgu : sparqlEndpoint.getDefaultGraphURIs()) {
queryExecution.addDefaultGraph(dgu);
}
- for (String ngu : endpoint.getNamedGraphURIs()) {
+ for (String ngu : sparqlEndpoint.getNamedGraphURIs()) {
queryExecution.addNamedGraph(ngu);
}
@@ -108,12 +106,12 @@
rs = queryExecution.execSelect();
JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").stop();
- logger.debug("query length: " + queryString.length() + " | ENDPOINT: "
- + endpoint.getURL().toString());
+ logger.debug("query length: " + sparqlQueryString.length() + " | ENDPOINT: "
+ + sparqlEndpoint.getURL().toString());
// writeToSparqlLog("query: "+queryString+ " | ENDPOINT:
// "+endpoint.getURL().toString());
- json = SparqlQuery.getAsJSON(rs);
+ json = SparqlQuery.convertResultSetToJSON(rs);
writeToSparqlLog("JSON: " + json);
@@ -121,90 +119,129 @@
}
+ /**
+ * Stops the execution of the query.
+ */
public void stop() {
queryExecution.abort();
isRunning = false;
}
- public String getQueryString() {
- return queryString;
+ /**
+ * Gets the String representation of the SPARQL query.
+ * @return sparqlQueryString
+ */
+ public String getSparqlQueryString() {
+ return sparqlQueryString;
}
- public SparqlEndpoint getEndpoint() {
- return endpoint;
+ /**
+ * @return sparqlEndpoint object
+ */
+ public SparqlEndpoint getSparqlEndpoint() {
+ return sparqlEndpoint;
}
+ /**
+ *
+ * @return boolean
+ */
public boolean isRunning() {
return isRunning;
}
+ /**
+ * @return the Jena QueryEngineHTTP
+ */
public QueryEngineHTTP getExecution() {
return queryExecution;
}
+ /**
+ * insert a result, e.g. from the cache
+ * @param json a jsonString
+ */
public void setJson(String json) {
this.wasExecuted = true;
this.json = json;
}
+ /**
+ * @param running s.e.
+ */
public void setRunning(boolean running) {
this.isRunning = running;
}
/**
* returns the Result of the query as JSON string executes the query if it
- * wasn't executed before
+ * wasn't executed before.
*
- * @return
+ * @return a JSON string
*/
public String getJson() {
- if (wasExecuted == false) {
+ if (!wasExecuted) {
this.send();
}
return json;
}
/**
- * makes a ResultSet from the Json String, depends on getJSON
+ * makes a ResultSet from the Json String, depends on getJSON.
*
- * @return
+ * @return a Jena ResultSet
*/
public ResultSet getResultSet() {
- if (getJson() == null) {
- return null;
+ return (getJson() == null) ? null : convertJSONtoResultSet(json);
+
+ /*if (getJson() == null) {
+ return null;
} else
- return JSONtoResultSet(json);
+ return JSONtoResultSet(json);*/
}
/**
- * makes an XML String from the Json String, depends on getJSON
+ * makes an XML String from the Json String, depends on getJSON.
*
- * @return
+ * @return An XML String
*/
public String getXMLString() {
- if (getJson() == null) {
+ return (getJson() == null) ? null : convertJSONtoXML(json);
+
+ /*if (getJson() == null) {
return null;
} else
- return JSONtoXML(json);
+ return JSONtoXML(json);*/
}
+ /**
+ * Special log for debugging SPARQL query execution.
+ * It lives here: "log/sparql.txt"
+ * if the directory doesn't exist, there could be an error.
+ * @param s the String to log
+ */
public static void writeToSparqlLog(String s) {
try {
+ //
FileWriter fw = new FileWriter("log/sparql.txt", true);
fw.write(s + "\n");
fw.flush();
fw.close();
} catch (Exception e) {
e.printStackTrace();
+ // make the e object more special FileNotFound??
+ //new File("log").mkdir();
+ //writeToSparqlLog(s);
}
}
+
/**
* Converts Jena result set to XML.
- *
+ * @param resultSet a Jena ResultSet
* @return String xml
*/
- public static String getAsXMLString(ResultSet resultSet) {
+ public static String convertResultSetToXMLString(ResultSet resultSet) {
// if (rs == null)
// this.send();
return ResultSetFormatter.asXMLString(resultSet);
@@ -217,14 +254,14 @@
* The result set to transform.
* @return JSON representation of the result set.
*/
- public static String getAsJSON(ResultSet resultSet) {
+ public static String convertResultSetToJSON(ResultSet resultSet) {
// if (rs == null)
// this.send();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ResultSetFormatter.outputAsJSON(baos, resultSet);
// possible Jena bug: Jena modifies the result set during
// JSON transformation, so we need to get it back
- resultSet = JSONtoResultSet(baos.toString());
+ resultSet = convertJSONtoResultSet(baos.toString());
try {
return baos.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
@@ -240,7 +277,7 @@
* A JSON representation if a SPARQL query result.
* @return A Jena ResultSet.
*/
- public static ResultSet JSONtoResultSet(String json) {
+ public static ResultSet convertJSONtoResultSet(String json) {
ByteArrayInputStream bais = new ByteArrayInputStream(json
.getBytes(Charset.forName("UTF-8")));
// System.out.println("JSON " + json);
@@ -254,7 +291,7 @@
* A JSON representation if a SPARQL query result.
* @return A Jena ResultSet.
*/
- public static String JSONtoXML(String json) {
- return getAsXMLString(JSONtoResultSet(json));
+ public static String convertJSONtoXML(String json) {
+ return convertResultSetToXMLString(convertJSONtoResultSet(json));
}
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -111,28 +111,18 @@
// String resultString="";
// System.out.println(time());
// System.out.println(System.currentTimeMillis());
- String[] a = new String[2];
- int x1=0;
- try {
- while(true)
- a[x1++]="";
- } catch (Exception e) {
- e.printStackTrace();
-
- }
- System.exit(0);
// parameters
if (local) {
url = "http://139.18.2.37:8890/sparql";
sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),
- SparqlEndpoint.EndpointLOCALDBpedia());
+ SparqlEndpoint.getEndpointLOCALDBpedia());
} else {
url = "http://dbpedia.openlinksw.com:8890/sparql";
sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),
- SparqlEndpoint.EndpointDBpedia());
+ SparqlEndpoint.getEndpointDBpedia());
}
//System.out.println(sparqlTasks.getDomain(
Modified: trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -61,12 +61,12 @@
SimpleClock total =new SimpleClock();
String url="";
if(local){
- se = SparqlEndpoint.EndpointLOCALDBpedia();
+ se = SparqlEndpoint.getEndpointLOCALDBpedia();
url = "http://139.18.2.37:8890/sparql";
}else{
- se = SparqlEndpoint.EndpointDBpedia();
+ se = SparqlEndpoint.getEndpointDBpedia();
url= "http://dbpedia.openlinksw.com:8890/sparql";
}
@@ -187,7 +187,7 @@
" \n} LIMIT "+1000+" \n "; //
String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
- ResultSet rs =SparqlQuery.JSONtoResultSet(JSON);
+ ResultSet rs =SparqlQuery.convertJSONtoResultSet(JSON);
if(rs==null);
//JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs);
//return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number);
Modified: trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -97,7 +97,7 @@
static void roles(){
- se = SparqlEndpoint.EndpointDBpedia();
+ se = SparqlEndpoint.getEndpointDBpedia();
//se = SparqlEndpoint.EndpointUSCensus();
SortedSet<String> roles = new TreeSet<String>();
roles.add("http://dbpedia.org/property/birthPlace");
@@ -143,7 +143,7 @@
}
static void DBpedia(){
- se = SparqlEndpoint.EndpointLOCALDBpedia();
+ se = SparqlEndpoint.getEndpointLOCALDBpedia();
//concepts.add("(EXISTS \"monarch\".TOP AND EXISTS \"predecessor\".(\"Knight\" OR \"Secretary\"))");
SortedSet<String> concepts = new TreeSet<String>();
@@ -257,7 +257,7 @@
String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
- ResultSet rs =SparqlQuery.JSONtoResultSet(JSON);
+ ResultSet rs =SparqlQuery.convertJSONtoResultSet(JSON);
if(rs==null);
//JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs);
//return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number);
Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -599,7 +599,7 @@
Thread sparqlThread = new Thread() {
@Override
public void run() {
- if (ks.getUseCache()){
+ if (ks.isUseCache()){
state.getQuery(id).setRunning(true);
Cache cache=new Cache(ks.getCacheDir());
cache.executeSparqlQuery(state.getQuery(id));
@@ -623,7 +623,7 @@
Component component = state.getComponent(componentID);
SparqlKnowledgeSource ks=(SparqlKnowledgeSource)component;
SparqlQuery sparql=ks.sparqlQuery(query);
- if (ks.getUseCache()){
+ if (ks.isUseCache()){
Cache cache=new Cache(ks.getCacheDir());
return cache.executeSparqlQuery(sparql);
}
Modified: trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -50,7 +50,7 @@
public static void testJenaAsXML(int howOften, String queryString){
- SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia();
+ SparqlEndpoint sse = SparqlEndpoint.getEndpointDBpedia();
SparqlQuery sqJena = new SparqlQuery(queryString, sse);
// first query is not counted
sqJena.send();
@@ -72,7 +72,7 @@
}
public static void testJenaAsList(int howOften, String queryString){
- SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia();
+ SparqlEndpoint sse = SparqlEndpoint.getEndpointDBpedia();
SparqlQuery sqJena = new SparqlQuery(queryString, sse);
// first query is not counted
//sqJena.getAsList();
@@ -96,7 +96,7 @@
}
public static void testJenaAsJSON(int howOften, String queryString){
- SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia();
+ SparqlEndpoint sse = SparqlEndpoint.getEndpointDBpedia();
SparqlQuery sqJena = new SparqlQuery(queryString, sse);
// first query is not counted
sqJena.send();
@@ -119,7 +119,7 @@
}
public static void testJenaAsJSONandBack(int howOften, String queryString){
- SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia();
+ SparqlEndpoint sse = SparqlEndpoint.getEndpointDBpedia();
SparqlQuery sqJena = new SparqlQuery(queryString, sse);
// first query is not counted
sqJena.send();
@@ -131,7 +131,7 @@
// System.out.println(sqJena.getAsJSON());
sqJena.send();
String json = sqJena.getJson();
- SparqlQuery.JSONtoResultSet(json);
+ SparqlQuery.convertJSONtoResultSet(json);
p("Jena as JSON and back needed: "
+ (System.currentTimeMillis() - tmp));
tmp = System.currentTimeMillis();
@@ -145,7 +145,7 @@
public static void compareResults(String queryString) {
- SparqlEndpoint sse = SparqlEndpoint.EndpointDBpedia();
+ SparqlEndpoint sse = SparqlEndpoint.getEndpointDBpedia();
SparqlQuery sqJena = new SparqlQuery(queryString, sse);
// SparqlQueryConventional sqConv=new SparqlQueryConventional(sse);
Modified: trunk/src/dl-learner/org/dllearner/test/SparqlEndpointTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/SparqlEndpointTest.java 2008-07-29 14:30:25 UTC (rev 1024)
+++ trunk/src/dl-learner/org/dllearner/test/SparqlEndpointTest.java 2008-07-30 06:53:34 UTC (rev 1025)
@@ -1,7 +1,7 @@
package org.dllearner.test;
import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.List;
import java.util.Set;
import java.util.SortedSet;
@@ -36,7 +36,7 @@
//SELECT DISTINCT ?c WHERE {[] a ?c }LIMIT 100
- LinkedList<SparqlEndpoint> ll = SparqlEndpoint.listEndpoints();
+ List<SparqlEndpoint> ll = SparqlEndpoint.listEndpoints();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-07-30 09:24:51
|
Revision: 1026
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1026&view=rev
Author: kurzum
Date: 2008-07-30 09:24:46 +0000 (Wed, 30 Jul 2008)
Log Message:
-----------
more comments, code improvements
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java
trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -19,7 +19,6 @@
*/
package org.dllearner.kb.sparql;
-import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -27,19 +26,21 @@
import org.apache.log4j.Logger;
import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.ResultSetFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
+import com.hp.hpl.jena.query.ResultSetRewindable;
import com.hp.hpl.jena.sparql.core.ResultBinding;
-
/**
- * @author Sebastian Hellmann
- * Convenience class for SPARQL queries
- * initialized with a SparqlEndpoint.
- * A Cache can also be used to further improve query time.
- * Some methods allow basic reasoning
+ * @author Sebastian Hellmann Convenience class for SPARQL queries initialized
+ * with a SparqlEndpoint. A Cache can also be used to further improve
+ * query time. Some methods allow basic reasoning
*/
public class SPARQLTasks {
+ // TODO collect such things in a static class
+ private static final String SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
+
private static Logger logger = Logger.getLogger(SPARQLTasks.class);
private final Cache cache;
@@ -47,125 +48,114 @@
private final SparqlEndpoint sparqlEndpoint;
/**
- * @param cache a cache object
- * @param sparqlEndpoint the Endpoint the sparql queries will be send to
+ * @param sparqlEndpoint
+ * the Endpoint the sparql queries will be send to
*/
- public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) {
+ public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) {
super();
- this.cache = cache;
+ this.cache = null;
this.sparqlEndpoint = sparqlEndpoint;
}
/**
- * @param sparqlEndpoint the Endpoint the sparql queries will be send to
+ * @param cache
+ * a cache object
+ * @param sparqlEndpoint
+ * the Endpoint the sparql queries will be send to
*/
- public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) {
+ public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) {
super();
- this.cache = null;
+ this.cache = cache;
this.sparqlEndpoint = sparqlEndpoint;
}
/**
- * QUALITY: doesn't seem optimal, check! get all superclasses up to a
- * certain depth 1 means direct superclasses depth
+ * get all superclasses up to a certain depth, 1 means direct superclasses
+ * only.
*
- * @param oneClass the class for which the superclasses will be retrieved
- * @param maxdepth how far the RDF graph will be explored (1 means only direct SuperClasses)
- * @return a Sorted String Set of all ClassNames, including the starting class
+ * @param classURI
+ * the uri of the class with no quotes for which the superclasses
+ * will be retrieved
+ * @param maxDepth
+ * how far the RDF graph will be explored (1 means only direct
+ * SuperClasses)
+ * @return a Sorted String Set of all ClassNames, including the starting
+ * class
*/
- public SortedSet<String> getSuperClasses(final String oneClass,
- final int maxdepth) {
- int depth = maxdepth;
- SortedSet<String> superClasses = new TreeSet<String>();
- superClasses.add(oneClass);
- SortedSet<String> ret = new TreeSet<String>();
- SortedSet<String> tmpset = new TreeSet<String>();
- String sparqlQuery = "";
- // ret.addAll(superClasses);
- // logger.debug(superClasses);
+ public SortedSet<String> getSuperClasses(final String classURI,
+ final int maxDepth) {
+ // TODO check for quotes in uris
+ return getRecursiveSuperOrSubClasses(classURI, maxDepth, false);
+ }
- for (; depth != 0; depth--) {
- for (String oneSuperClass : superClasses) {
+ /**
+ * This is the underlying function to get Super and SubClasses.
+ *
+ * @param classURI
+ * the uri of the class with no quotes for which the classes will
+ * be retrieved
+ * @param maxDepth
+ * how far the RDF graph will be explored (1 means only direct
+ * related Classes)
+ * @return a Sorted String Set of all retrieved ClassNames, including the
+ * starting class
+ */
+ private SortedSet<String> getRecursiveSuperOrSubClasses(
+ final String classURI, final int maxDepth, boolean subclasses) {
+ // TODO check for quotes in uris
+ int depth = maxDepth;
- // tmp = oneSuperClass.replace("\"", "");
- sparqlQuery = "SELECT * WHERE { \n"
- + "<"
- + oneSuperClass
- + "> "
- + "<http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass. \n"
- + "}";
+ final SortedSet<String> toBeRetrieved = new TreeSet<String>();
+ toBeRetrieved.add(classURI);
- tmpset.addAll(queryAsSet(sparqlQuery, "superclass"));
+ final SortedSet<String> returnSet = new TreeSet<String>();
+ final SortedSet<String> tmpSet = new TreeSet<String>();
+ // collect super/subclasses for the depth
+ for (; depth != 0; depth--) {
+ // collect super/subclasses for each class in toBeRetrieved
+ // accumulate in tmpSet
+ for (String oneClass : toBeRetrieved) {
+ if (subclasses) {
+ tmpSet.addAll(getDirectSubClasses(oneClass));
+ } else {
+ tmpSet.addAll(getDirectSuperClasses(oneClass));
+ }
+
}// end inner for
- ret.addAll(tmpset);
- // logger.debug(ret);
- superClasses.clear();
- superClasses.addAll(tmpset);
- tmpset.clear();
+
+ // remember all queried classes to return them.
+ returnSet.addAll(toBeRetrieved);
+ // then discard them
+ toBeRetrieved.clear();
+ // all that are to be retrieved the next time.
+ toBeRetrieved.addAll(tmpSet);
+ // small optimization, remove all that have been processed already:
+ toBeRetrieved.removeAll(returnSet);
+ // reset
+ tmpSet.clear();
}// end outer for
- // logger.debug(concept);
- // logger.debug(query);
- return ret;
+
+ returnSet.addAll(toBeRetrieved);
+
+ return returnSet;
}
/**
* gets a SortedSet of all subclasses.
- * QUALITY: maybe it is better to have a
- * parameter int depth, to choose a depth of subclass interference
*
* @see conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache
* c, boolean simple )
- * @param description
- * @param simple
- * @return
+ * @param classURI
+ * @param maxDepth
+ * @return TreeSet of subclasses including classURI
*/
- public SortedSet<String> getSubClasses(final String description,
- final boolean simple) {
- // ResultSet rs = null;
- // System.out.println(description);
- SortedSet<String> alreadyQueried = new TreeSet<String>();
- try {
-
- // initialisation get direct Subclasses
- LinkedList<String> remainingClasses = new LinkedList<String>();
-
- // collect remaining classes
- remainingClasses.addAll(getDirectSubClasses(description.replaceAll(
- "\"", "")));
-
- // remainingClasses.addAll(alreadyQueried);
-
- // alreadyQueried = new TreeSet<String>();
- alreadyQueried.add(description.replaceAll("\"", ""));
-
- if (simple) {
- alreadyQueried.addAll(remainingClasses);
-
- } else {
-
- logger.warn("Retrieval auf all subclasses via SPARQL is cost intensive and might take a while");
- SortedSet<String> tmpSet = new TreeSet<String>();
- while (!remainingClasses.isEmpty()) {
-
- String tmp = remainingClasses.removeFirst();
- alreadyQueried.add(tmp);
-
- tmpSet = getDirectSubClasses(tmp);
- for (String string : tmpSet) {
- if (!(alreadyQueried.contains(string))) {
- remainingClasses.add(string);
- }// if
- }// for
- tmpSet.clear();
- }// while
- }// else
-
- } catch (Exception e) {
- logger.error(e.getStackTrace());
+ public SortedSet<String> getSubClasses(final String classURI,
+ final int maxDepth) {
+ if (classURI.contains("\"")) {
+ // TODO exception
}
-
- return alreadyQueried;
+ return getRecursiveSuperOrSubClasses(classURI, maxDepth, true);
}
/**
@@ -173,101 +163,101 @@
* empty set on some endpoints. returns all direct subclasses of String
* concept
*
- * @param concept An URI string with no quotes
+ * @param concept
+ * An URI string with no quotes
* @return SortedSet of direct subclasses as String
*/
private SortedSet<String> getDirectSubClasses(String concept) {
+ return queryPatternAsSet("?subject", "<" + SUBCLASS_OF + ">", "<"
+ + concept + ">", "subject", 0, false);
+ }
- String sparqlQueryString;
- SortedSet<String> subClasses = new TreeSet<String>();
- ResultSet resultSet;
-
- sparqlQueryString = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <"
- + concept + "> \n" + "}\n";
-
- resultSet = queryAsResultSet(sparqlQueryString);
-
- @SuppressWarnings("unchecked")
- List<ResultBinding> bindings = ResultSetFormatter.toList(resultSet);
- String subject = "";
- String predicate = "";
-
- for (ResultBinding resultBinding : bindings) {
-
- subject = ((resultBinding.get("subject").toString()));
- predicate = ((resultBinding.get("predicate").toString()));
- if (predicate
- .equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#subClassOf")) {
- subClasses.add(subject);
- }
- }
- return subClasses;
+ private SortedSet<String> getDirectSuperClasses(String concept) {
+ return queryPatternAsSet("<" + concept + ">", "<" + SUBCLASS_OF + ">",
+ "?object", "object", 0, false);
}
/**
- * Retrieves all resource for a fixed role and object.
- * These instances are distinct.
- * QUALITY: buggy because role doesn't work sometimes get subject with fixed
- * role and object
+ * Retrieves all resource for a fixed role and object. These instances are
+ * distinct. QUALITY: buggy because role doesn't work sometimes get subject
+ * with fixed role and object
*
- * @param role An URI string with no quotes
- * @param object An URI string with no quotes
- * @param sparqlResultLimit Limits the ResultSet size
+ * @param role
+ * An URI string with no quotes
+ * @param object
+ * An URI string with no quotes
+ * @param sparqlResultLimit
+ * Limits the ResultSet size
* @return SortedSet with the resulting subjects
*/
public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject(
String role, String object, int sparqlResultLimit) {
- String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "?subject "
- + "<" + role + "> " + "<" + object + "> \n" + "} "
- + limit(sparqlResultLimit);
-
- return queryAsSet(sparqlQueryString, "subject");
+ /*
+ * String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " +
+ * "?subject " + "<" + role + "> " + "<" + object + "> \n" + "} " +
+ * limit(sparqlResultLimit);
+ *
+ * return queryAsSet(sparqlQueryString, "subject");
+ */
+ return queryPatternAsSet("?subject", "<" + role + ">", "<" + object
+ + ">", "subject", sparqlResultLimit, true);
}
/**
- * @param subject An URI string with no quotes
- * @param role An URI string with no quotes
- * @param sparqlResultLimit Limits the ResultSet size
- * @return
+ * @param subject
+ * An URI string with no quotes
+ * @param role
+ * An URI string with no quotes
+ * @param sparqlResultLimit
+ * Limits the ResultSet size
+ * @return SortedSet with the resulting objects
*/
public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject,
String role, int sparqlResultLimit) {
- String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" + subject
- + "> " + "<" + role + "> " + " ?object \n" + "} LIMIT "
- + sparqlResultLimit;
-
- return queryAsSet(sparqlQueryString, "object");
+ /*
+ * String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" +
+ * subject + "> " + "<" + role + "> " + " ?object \n" + "} LIMIT " +
+ * sparqlResultLimit;
+ *
+ * return queryAsSet(sparqlQueryString, "object");
+ */
+ return queryPatternAsSet("<" + subject + ">", "<" + role + ">",
+ "?object", "object", sparqlResultLimit, true);
}
/**
* all instances for a SKOS concept.
*
- * @param skosConcept An URI string with no quotes
- * @param sparqlResultLimit Limits the ResultSet size
- * @return
+ * @param skosConcept
+ * An URI string with no quotes
+ * @param sparqlResultLimit
+ * Limits the ResultSet size
+ * @return SortedSet with the instances
*/
public SortedSet<String> retrieveInstancesForSKOSConcept(
String skosConcept, int sparqlResultLimit) {
return queryPatternAsSet("?subject", "?predicate", "<" + skosConcept
- + ">", "subject", sparqlResultLimit);
+ + ">", "subject", sparqlResultLimit, false);
// return
// retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject",
}
/**
- * get all instances for a concept.
+ * get all instances for a complex concept / class description in KBSyntax.
*
- * @param conceptKBSyntax A description string in KBSyntax
- * @param sparqlResultLimit Limits the ResultSet size
- * @return
+ * @param conceptKBSyntax
+ * A description string in KBSyntax
+ * @param sparqlResultLimit
+ * Limits the ResultSet size
+ * @return SortedSet with the instance uris
*/
- public SortedSet<String> retrieveInstancesForConcept(
+ public SortedSet<String> retrieveInstancesForClassDescription(
String conceptKBSyntax, int sparqlResultLimit) {
String sparqlQueryString = "";
try {
- sparqlQueryString = SparqlQueryDescriptionConvertVisitor.getSparqlQuery(
- conceptKBSyntax, sparqlResultLimit);
+ sparqlQueryString = SparqlQueryDescriptionConvertVisitor
+ .getSparqlQuery(conceptKBSyntax, sparqlResultLimit);
} catch (Exception e) {
logger.warn(e.getMessage());
}
@@ -275,20 +265,23 @@
}
/**
- * get all instances for a concept including RDFS Reasoning.
+ * same as <code>retrieveInstancesForClassDescription</code> including
+ * RDFS Reasoning.
*
- * @param conceptKBSyntax A description string in KBSyntax
- * @param sparqlResultLimit Limits the ResultSet size
- * @return
+ * @param conceptKBSyntax
+ * A description string in KBSyntax
+ * @param sparqlResultLimit
+ * Limits the ResultSet size
+ * @return SortedSet with the instance uris
*/
- public SortedSet<String> retrieveInstancesForConceptIncludingSubclasses(
- String conceptKBSyntax, int sparqlResultLimit) {
+ public SortedSet<String> retrieveInstancesForClassDescriptionIncludingSubclasses(
+ String conceptKBSyntax, int sparqlResultLimit, int maxDepth) {
String sparqlQueryString = "";
try {
sparqlQueryString = SparqlQueryDescriptionConvertVisitor
.getSparqlQueryIncludingSubclasses(conceptKBSyntax,
- sparqlResultLimit, this, true);
+ sparqlResultLimit, this, maxDepth);
} catch (Exception e) {
logger.warn(e.getMessage());
@@ -299,67 +292,128 @@
/**
* get all direct Classes of an instance.
*
- * @param instance An URI string with no quotes
- * @param sparqlResultLimit Limits the ResultSet size
+ * @param instance
+ * An URI string with no quotes
+ * @param sparqlResultLimit
+ * Limits the ResultSet size
* @return
*/
public SortedSet<String> getClassesForInstance(String instance,
int sparqlResultLimit) {
- String sparqlQueryString = "SELECT ?subject WHERE { \n " + "<" + instance
- + ">" + " a " + "?subject " + "\n" + "} " + limit(sparqlResultLimit);
-
- return queryAsSet(sparqlQueryString, "subject");
+ // String sparqlQueryString = "SELECT ?subject WHERE { \n " + "<" +
+ // instance
+ // + ">" + " a " + "?subject " + "\n" + "} " + limit(sparqlResultLimit);
+ return queryPatternAsSet("<" + instance + ">", "a", "?object",
+ "object", sparqlResultLimit, false);
+ // return queryAsSet(sparqlQueryString, "subject");
}
- public SortedSet<String> getDomain(String role, int resultLimit) {
+ /**
+ * Returns all instances that are in the prefield (subject) of the
+ * property/role.
+ *
+ * Cave: These have to fulfill the following requirements: 1. They are not
+ * literals 2. They have at least a Class assigned 3. DISTINCT is used in
+ * the query
+ *
+ * TODO there might be a better name for the function
+ *
+ * @param role
+ * An URI of a property/role
+ * @param sparqlResultLimit
+ * ResultSet limit
+ * @return A String Set of instances
+ */
+ public SortedSet<String> getDomainInstances(String role,
+ int sparqlResultLimit) {
String sparqlQueryString = "SELECT DISTINCT ?domain " + "WHERE { \n"
+ "?domain <" + role + "> " + " ?o. \n" + "?domain a []\n."
- + "FILTER (!isLiteral(?domain))." + "}\n" + limit(resultLimit);
+ + "FILTER (!isLiteral(?domain))." + "}\n"
+ + limit(sparqlResultLimit);
return queryAsSet(sparqlQueryString, "domain");
}
- public SortedSet<String> getRange(String role, int resultLimit) {
+ /**
+ * Returns all instances that are fillers of the property/role. Cave: These
+ * have to fulfill the following requirements: 1. The fillers are not
+ * literals 2. The fillers have at least a Class assigned 3. DISTINCT is
+ * used in the query
+ *
+ * TODO there might be a better name for the function
+ *
+ * @param role
+ * An URI of a property/role
+ * @param sparqlResultLimit
+ * ResultSet limit
+ * @return A String Set of instances
+ */
+ public SortedSet<String> getRangeInstances(String role,
+ int sparqlResultLimit) {
- String sparqlQueryString = "SELECT DISTINCT ?range " + "WHERE { \n" + "?s <"
- + role + "> " + " ?range. \n" + "?range a [].\n"
- + "FILTER (!isLiteral(?range))." + "}\n" + limit(resultLimit);
+ String sparqlQueryString = "SELECT DISTINCT ?range " + "WHERE { \n"
+ + "?s <" + role + "> " + " ?range. \n" + "?range a [].\n"
+ + "FILTER (!isLiteral(?range))." + "}\n"
+ + limit(sparqlResultLimit);
return queryAsSet(sparqlQueryString, "range");
}
/**
- * //QUALITY rethink
- * query a pattern with a standard SPARQL query.
- * usage (?subject, <http://something>,
- * <http://something> , subject ).
+ * query a pattern with a standard SPARQL query. The Query will be of the
+ * form SELECT * WHERE { subject predicate object } LIMIT X. It has a high
+ * degree of freedom, but only one variabla can be retrieved.
*
- * @param subject An URI string with no quotes
- * @param predicate An URI string with no quotes
- * @param object An URI string with no quotes
- * @param var The single
- * @return
+ * usage example 1 : queryPatternAsSet( "?subject", "<http://somerole>",
+ * "?object", "subject" ). retrieves all subjects, that have the role,
+ * somerole
+ *
+ * usage example 1 : queryPatternAsSet( "?subject", "<http://somerole>",
+ * "?object", "object" ). retrieves all objects, that have the role,
+ * somerole
+ *
+ * @param subject
+ * An URI string enclosed in <> or a SPARQL variable e.g.
+ * "?subject"
+ * @param predicate
+ * An URI string enclosed in <> or a SPARQL variable e.g.
+ * "?predicate"
+ * @param object
+ * An URI string enclosed in <> or a SPARQL variable e.g.
+ * "?object"
+ * @param variable
+ * The variable to be retrieved and put into the SortedSet
+ * @param sparqlResultLimit
+ * 0 means all
+ * @param distinct
+ * determines whether distinct is used
+ * @return a String Set with the Bindings of the variable in variable
*/
public SortedSet<String> queryPatternAsSet(String subject,
- String predicate, String object, String var, int resultLimit) {
- String sparqlQueryString = "SELECT ?subject WHERE { \n " + " " + subject
- + " " + predicate + " " + object + " \n" + "} "
- + limit(resultLimit);
- return queryAsSet(sparqlQueryString, var);
+ String predicate, String object, String variable,
+ int sparqlResultLimit, boolean distinct) {
+ String sparqlQueryString = "SELECT " + ((distinct) ? "DISTINCT" : "")
+ + " * WHERE { \n " + " " + subject + " " + predicate + " "
+ + object + " \n" + "} " + limit(sparqlResultLimit);
+ return queryAsSet(sparqlQueryString, variable);
}
/**
- * little higher level, executes query ,returns all resources for a variable.
+ * little higher level, executes query ,returns all resources for a
+ * variable.
*
- * @param sparqlQueryString The query
- * @param var The single variable used in the query
+ * @param sparqlQueryString
+ * The query
+ * @param variable
+ * The single variable used in the query
* @return
*/
- public SortedSet<String> queryAsSet(String sparqlQueryString, String var) {
+ public SortedSet<String> queryAsSet(String sparqlQueryString,
+ String variable) {
ResultSet rs = null;
try {
String jsonString = query(sparqlQueryString);
@@ -368,16 +422,18 @@
} catch (Exception e) {
logger.warn(e.getMessage());
}
- return getStringListForVariable(rs, var);
+ return getStringSetForVariableFromResultSet(ResultSetFactory
+ .makeRewindable(rs), variable);
}
/**
* low level, executes query returns ResultSet.
*
- * @param sparqlQueryString The query
+ * @param sparqlQueryString
+ * The query
* @return jena ResultSet
*/
- public ResultSet queryAsResultSet(String sparqlQueryString) {
+ public ResultSetRewindable queryAsResultSet(String sparqlQueryString) {
return SparqlQuery.convertJSONtoResultSet(query(sparqlQueryString));
}
@@ -385,7 +441,8 @@
/**
* low level, executes query returns JSON.
*
- * @param sparqlQueryString The query
+ * @param sparqlQueryString
+ * The query
* @return
*/
public String query(String sparqlQueryString) {
@@ -395,30 +452,77 @@
sq.send();
jsonString = sq.getJson();
} else {
- jsonString = cache.executeSparqlQuery(new SparqlQuery(sparqlQueryString,
- sparqlEndpoint));
+ jsonString = cache.executeSparqlQuery(new SparqlQuery(
+ sparqlQueryString, sparqlEndpoint));
}
return jsonString;
}
- private String limit(int resultLimit) {
- return (resultLimit > 0) ? (" LIMIT " + resultLimit) : "";
+ /**
+ * a String Helper which constructs the limit clause of a sparql query. if
+ * sparqlResultLimit is zero, returns nothing
+ *
+ * @param sparqlResultLimit
+ * the resultsetlimit
+ * @return LIMIT sparqlResultLimit if bigger than zero, else returns "";
+ */
+ private String limit(int sparqlResultLimit) {
+ return (sparqlResultLimit > 0) ? (" LIMIT " + sparqlResultLimit) : "";
}
- public static SortedSet<String> getStringListForVariable(ResultSet rs,
- String var) {
- SortedSet<String> result = new TreeSet<String>();
+ public static SortedSet<String> getStringSetForVariableFromResultSet(
+ ResultSetRewindable rs, String variable) {
+ final SortedSet<String> result = new TreeSet<String>();
- // String s=ResultSetFormatter.asXMLString(this.rs);
@SuppressWarnings("unchecked")
- List<ResultBinding> l = ResultSetFormatter.toList(rs);
+ final List<ResultBinding> l = ResultSetFormatter.toList(rs);
for (ResultBinding resultBinding : l) {
- result.add(resultBinding.get(var).toString());
+ result.add(resultBinding.get(variable).toString());
}
-
+ rs.reset();
return result;
}
}
+
+/*
+ * here are some old functions, which were workarounds:
+ *
+ *
+ * QUALITY: workaround for a sparql glitch {?a owl:subclassOf ?b} returns an
+ * empty set on some endpoints. returns all direct subclasses of String concept
+ *
+ * @param concept An URI string with no quotes @return SortedSet of direct
+ * subclasses as String
+ *
+ * private SortedSet<String> getDirectSubClasses(String concept) {
+ *
+ * String sparqlQueryString; SortedSet<String> subClasses = new TreeSet<String>();
+ * ResultSet resultSet;
+ *
+ * sparqlQueryString = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <" +
+ * concept + "> \n" + "}\n";
+ *
+ * resultSet = queryAsResultSet(sparqlQueryString);
+ *
+ * @SuppressWarnings("unchecked") List<ResultBinding> bindings =
+ * ResultSetFormatter.toList(resultSet); String subject = ""; String predicate =
+ * "";
+ *
+ * for (ResultBinding resultBinding : bindings) {
+ *
+ * subject = ((resultBinding.get("subject").toString())); predicate =
+ * ((resultBinding.get("predicate").toString())); if (predicate
+ * .equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#subClassOf")) {
+ * subClasses.add(subject); } } return subClasses; }
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -31,6 +31,7 @@
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
+import com.hp.hpl.jena.query.ResultSetRewindable;
import com.hp.hpl.jena.sparql.engine.http.HttpQuery;
import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP;
@@ -111,7 +112,7 @@
// writeToSparqlLog("query: "+queryString+ " | ENDPOINT:
// "+endpoint.getURL().toString());
- json = SparqlQuery.convertResultSetToJSON(rs);
+ json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs));
writeToSparqlLog("JSON: " + json);
@@ -238,30 +239,39 @@
/**
* Converts Jena result set to XML.
- * @param resultSet a Jena ResultSet
+ * To make a ResultSet rewindable use:
+ * ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet);
+ * @param resultSet The result set to transform, must be rewindable to prevent errors.
* @return String xml
*/
- public static String convertResultSetToXMLString(ResultSet resultSet) {
+ public static String convertResultSetToXMLString(ResultSetRewindable resultSet) {
// if (rs == null)
// this.send();
- return ResultSetFormatter.asXMLString(resultSet);
+ String retVal = ResultSetFormatter.asXMLString(resultSet);
+ resultSet.reset();
+ return retVal;
}
/**
* Converts Jena result set to JSON.
+ * To make a ResultSet rewindable use:
+ * ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet);
*
* @param resultSet
- * The result set to transform.
+ * The result set to transform, must be rewindable to prevent errors.
* @return JSON representation of the result set.
*/
- public static String convertResultSetToJSON(ResultSet resultSet) {
+ public static String convertResultSetToJSON(ResultSetRewindable resultSet) {
// if (rs == null)
// this.send();
+ //ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ResultSetFormatter.outputAsJSON(baos, resultSet);
// possible Jena bug: Jena modifies the result set during
// JSON transformation, so we need to get it back
- resultSet = convertJSONtoResultSet(baos.toString());
+ //rsRewind.
+ //resultSet = convertJSONtoResultSet(baos.toString());
+ resultSet.reset();
try {
return baos.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
@@ -277,11 +287,11 @@
* A JSON representation if a SPARQL query result.
* @return A Jena ResultSet.
*/
- public static ResultSet convertJSONtoResultSet(String json) {
+ public static ResultSetRewindable convertJSONtoResultSet(String json) {
ByteArrayInputStream bais = new ByteArrayInputStream(json
.getBytes(Charset.forName("UTF-8")));
// System.out.println("JSON " + json);
- return ResultSetFactory.fromJSON(bais);
+ return ResultSetFactory.makeRewindable(ResultSetFactory.fromJSON(bais));
}
/**
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -38,7 +38,7 @@
public class SparqlQueryDescriptionConvertRDFS {
//LOGGER: SparqlQueryDescriptionConvertVisitor
- static Logger logger = Logger.getLogger(SparqlQueryDescriptionConvertVisitor.class);
+ static Logger logger = Logger.getLogger(SparqlQueryDescriptionConvertRDFS.class);
/**
*
@@ -51,13 +51,13 @@
* @param c
* a cache object, makes only sense if you use this function
* often
- * @param simple
- * if true then only direct subclasses will be used (TRUE HIGHLY
- * RECOMMENDED for large hierarchies)
+ * @param maxDepth
+ * determines the depth of retrieval, if 1 classes are replaced by direct subclasses only,
+ * 1 is HIGHLY RECOMMENDED FOR LARGE HIERARCHIES)
* @return the altered String
*/
public static String conceptRewrite(String descriptionKBSyntax, SPARQLTasks st,
- boolean simple) {
+ int maxDepth) {
String quote = "\"";
String returnValue = "";
String currentconcept = "";
@@ -79,7 +79,7 @@
// System.out.println(currentconcept);
// subclasses are retrieved
- subclasses = st.getSubClasses(currentconcept, simple);
+ subclasses = st.getSubClasses(currentconcept, maxDepth);
// if only one then keep
if (subclasses.size() == 1)
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -157,13 +157,13 @@
* @param limit @see getSparqlQuery(Description description, int limit)
* @param se
* @param c
- * @param simple
+ * @param maxDepth
* @return
* @throws ParseException
*/
- public static String getSparqlQueryIncludingSubclasses(String descriptionKBSyntax, int resultLimit, SPARQLTasks st, boolean simple) throws ParseException
+ public static String getSparqlQueryIncludingSubclasses(String descriptionKBSyntax, int resultLimit, SPARQLTasks st, int maxDepth) throws ParseException
{
- String rewritten = SparqlQueryDescriptionConvertRDFS.conceptRewrite(descriptionKBSyntax, st, simple);
+ String rewritten = SparqlQueryDescriptionConvertRDFS.conceptRewrite(descriptionKBSyntax, st, maxDepth);
return getSparqlQuery(rewritten, resultLimit);
Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -112,7 +112,7 @@
// System.out.println(time());
// System.out.println(System.currentTimeMillis());
-
+
// parameters
if (local) {
@@ -125,6 +125,15 @@
SparqlEndpoint.getEndpointDBpedia());
}
+
+ String st= "http://dbpedia.org/class/yago/Person100007846";
+ st = "http://dbpedia.org/class/yago/Leader109623038";
+ System.out.println(sparqlTasks.getSuperClasses(st, 2));
+ System.out.println(sparqlTasks.getSuperClasses(st, 1));
+ System.out.println(sparqlTasks.getSubClasses(st, 0));
+
+ System.exit(0);
+
//System.out.println(sparqlTasks.getDomain(
// "http://dbpedia.org/property/predecessor", 1000));
@@ -183,8 +192,8 @@
// sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(),
// sparqlResultLimit);
SortedSet<String> instances = sparqlTasks
- .retrieveInstancesForConceptIncludingSubclasses(concept
- .toKBSyntaxString(), sparqlResultLimit);
+ .retrieveInstancesForClassDescriptionIncludingSubclasses(concept
+ .toKBSyntaxString(), sparqlResultLimit,1);
SortedSet<String> coveredInRest = new TreeSet<String>(
fullPosSetWithoutPosExamples);
@@ -210,8 +219,8 @@
// sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(),
// sparqlResultLimit);
SortedSet<String> instances = sparqlTasks
- .retrieveInstancesForConceptIncludingSubclasses(concept
- .toKBSyntaxString(), sparqlResultLimit);
+ .retrieveInstancesForClassDescriptionIncludingSubclasses(concept
+ .toKBSyntaxString(), sparqlResultLimit, 1 );
SortedSet<String> coveredInRest = new TreeSet<String>(
fullPosSetWithoutPosExamples);
Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -155,7 +155,7 @@
logger.debug(oneClass);
// rsc = new
// JenaResultSetConvenience(queryConcept("\""+oneClass+"\"",limit));
- this.fromParallelClasses.addAll(sparqltasks.retrieveInstancesForConcept("\"" + oneClass
+ this.fromParallelClasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + oneClass
+ "\"", resultLimit));
}
@@ -180,7 +180,7 @@
for (String oneSuperClass : superClasses) {
logger.debug(oneSuperClass);
- this.fromSuperclasses.addAll(sparqltasks.retrieveInstancesForConcept("\""
+ this.fromSuperclasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\""
+ oneSuperClass + "\"", resultLimit));
}
@@ -191,7 +191,7 @@
@SuppressWarnings("unused")
private void makeNegativeExamplesFromDomain(String role, int resultLimit){
logger.debug("making Negative Examples from Domain of : "+role);
- this.fromDomain.addAll(sparqltasks.getDomain(role, resultLimit));
+ this.fromDomain.addAll(sparqltasks.getDomainInstances(role, resultLimit));
this.fromDomain.removeAll(this.fullPositiveSet);
logger.debug("|-neg Example size from Domain: "+this.fromDomain.size());
}
@@ -199,7 +199,7 @@
@SuppressWarnings("unused")
private void makeNegativeExamplesFromRange(String role, int resultLimit){
logger.debug("making Negative Examples from Range of : "+role);
- this.fromRange.addAll(sparqltasks.getRange(role, resultLimit));
+ this.fromRange.addAll(sparqltasks.getRangeInstances(role, resultLimit));
this.fromRange.removeAll(this.fullPositiveSet);
logger.debug("|-neg Example size from Range: "+this.fromRange.size());
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java 2008-07-30 06:53:34 UTC (rev 1025)
+++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java 2008-07-30 09:24:46 UTC (rev 1026)
@@ -28,7 +28,7 @@
//QUALITY resultsize is not accounted for
public void makePositiveExamplesFromConcept(String conceptKBSyntax){
logger.debug("making Positive Examples from Concept: "+conceptKBSyntax);
- this.posExamples = sparqltasks.retrieveInstancesForConcept(conceptKBSyntax, 0);
+ this.posExamples = sparqltasks.retrieveInstancesForClassDescription(conceptKBSyntax, 0);
logger.debug(" pos Example size: "+posExamples.size());
}
@@ -50,14 +50,14 @@
@SuppressWarnings("unused")
public void makePositiveExamplesFromDomain(String role, int resultLimit){
logger.debug("making Positive Examples from Domain of : "+role);
- this.posExamples.addAll(sparqltasks.getDomain(role, resultLimit));
+ this.posExamples.addAll(sparqltasks.getDomainInstances(role, resultLimit));
logger.debug("pos Example size: "+posExamples.size());
}
@SuppressWarnings("unused")
public void makePositiveExamplesFromRange(String role, int resultLimit){
logger.debug("making Positive Examples from Range of : "+role);
- this.posExamples.addAll(sparqltasks.getRange(role, resultLimit));
+ this.posExamples.addAll(sparqltasks.getRangeInstances(role, resultLimit));
logger.debug("pos Example size: "+posExamples.size());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-07-30 13:34:58
|
Revision: 1027
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1027&view=rev
Author: kurzum
Date: 2008-07-30 13:34:56 +0000 (Wed, 30 Jul 2008)
Log Message:
-----------
more comments
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-30 09:24:46 UTC (rev 1026)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-30 13:34:56 UTC (rev 1027)
@@ -412,6 +412,7 @@
return algorithm.getCurrentlyBestEvaluatedDescriptions();
}
+ /** {@inheritDoc} */
@Override
public void stop() {
algorithm.stop();
@@ -421,11 +422,13 @@
return algorithm.getStartNode();
}
+ /** {@inheritDoc} */
@Override
public void pause() {
// TODO: not implemented
}
+ /** {@inheritDoc} */
@Override
public void resume() {
// TODO: not implemented
@@ -434,6 +437,7 @@
/* (non-Javadoc)
* @see org.dllearner.core.LearningAlgorithm#isRunning()
*/
+ /** {@inheritDoc} */
@Override
public boolean isRunning() {
return algorithm.isRunning();
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 09:24:46 UTC (rev 1026)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 13:34:56 UTC (rev 1027)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007, Sebastian Hellmann
+ * Copyright (C) 2007-2008, Jens Lehmann
*
* This file is part of DL-Learner.
*
Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 09:24:46 UTC (rev 1026)
+++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 13:34:56 UTC (rev 1027)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007, Jens Lehmann
+ * Copyright (C) 2007-2008, Jens Lehmann
*
* This file is part of DL-Learner.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-07-30 14:49:13
|
Revision: 1029
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1029&view=rev
Author: jenslehmann
Date: 2008-07-30 14:49:02 +0000 (Wed, 30 Jul 2008)
Log Message:
-----------
skeleton for EL learning algorithm
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java
trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/el/
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java
trunk/src/dl-learner/org/dllearner/algorithms/el/package.html
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java
trunk/src/dl-learner/org/dllearner/refinementoperators/package.html
Removed Paths:
-------------
trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+import java.util.List;
+import java.util.SortedSet;
+
+import org.dllearner.core.owl.NamedClass;
+
+/**
+ * Represents an EL description tree.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class ELDescriptionTree {
+
+ private SortedSet<NamedClass> label;
+
+ private List<Edge> edges;
+
+ /**
+ * @return the label
+ */
+ public SortedSet<NamedClass> getLabel() {
+ return label;
+ }
+
+ /**
+ * @return the edges
+ */
+ public List<Edge> getEdges() {
+ return edges;
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -0,0 +1,30 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+/**
+ * An edge in an EL description tree.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class Edge {
+
+}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/package.html
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/package.html (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/package.html 2008-07-30 14:49:02 UTC (rev 1029)
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head></head>
+<body bgcolor="white">
+<p>Learning algorithms for the EL description logic.</p>
+</body>
+</html>
\ No newline at end of file
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -32,7 +32,6 @@
import java.util.TreeSet;
import org.apache.log4j.Logger;
-import org.dllearner.algorithms.refinement.RefinementOperator;
import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasoningService;
@@ -44,6 +43,7 @@
import org.dllearner.core.owl.Union;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.learningproblems.PosOnlyDefinitionLP;
+import org.dllearner.refinementoperators.RefinementOperator;
import org.dllearner.refinementoperators.RhoDRDown;
import org.dllearner.utilities.Files;
import org.dllearner.utilities.Helper;
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -1050,6 +1050,7 @@
return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore());
}
+ @Override
public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
int count = 0;
SortedSet<Node> rev = candidatesStable.descendingSet();
Deleted: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -1,14 +0,0 @@
-package org.dllearner.algorithms.refinement;
-
-import java.util.List;
-import java.util.Set;
-
-import org.dllearner.core.owl.Description;
-
-public interface RefinementOperator {
-
- public Set<Description> refine(Description concept);
- // SortedSet zu erzwingen ist nicht so elegant
- public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements);
-
-}
Deleted: trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -1,21 +0,0 @@
-package org.dllearner.algorithms.refinement;
-
-import org.dllearner.core.owl.Description;
-
-/**
- * Soll hauptsächlich dazu dienen zu testen, ob ein Konzept im
- * Suchraum ist oder nicht.
- *
- * @author jl
- *
- */
-
-public class SearchSpace {
-
- // determines whether a concept is in the search space
- // noch nicht benutzt
- public boolean isInSearchSpace(Description concept) {
- return true;
- }
-
-}
Added: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -0,0 +1,66 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.refinementoperators;
+
+import java.util.List;
+import java.util.Set;
+
+import org.dllearner.core.owl.Description;
+
+/**
+ * EL downward refinement operator constructed by Jens Lehmann
+ * and Christoph Haase. It takes an EL description tree as input
+ * and outputs a set of EL description trees.
+ *
+ * <p>Properties:
+ * <ul>
+ * <li>complete</li>
+ * <li>proper</li>
+ * <li>finite</li>
+ * <li>uses class/property hierarchy</li>
+ * <li>takes domain/range into account</li>
+ * <li>uses disjoint classes/classes without common instances</li>
+ * </ul>
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class ELDown implements RefinementOperator {
+
+ /* (non-Javadoc)
+ * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public Set<Description> refine(Description concept) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List)
+ */
+ @Override
+ public Set<Description> refine(Description concept, int maxLength,
+ List<Description> knownRefinements) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -7,7 +7,6 @@
import java.util.Set;
import java.util.TreeSet;
-import org.dllearner.algorithms.refinement.RefinementOperator;
import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.ObjectAllRestriction;
import org.dllearner.core.owl.NamedClass;
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -7,7 +7,6 @@
import java.util.Set;
import java.util.TreeSet;
-import org.dllearner.algorithms.refinement.RefinementOperator;
import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.ObjectAllRestriction;
import org.dllearner.core.owl.NamedClass;
Copied: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java (from rev 1018, trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java)
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -0,0 +1,14 @@
+package org.dllearner.refinementoperators;
+
+import java.util.List;
+import java.util.Set;
+
+import org.dllearner.core.owl.Description;
+
+public interface RefinementOperator {
+
+ public Set<Description> refine(Description concept);
+ // SortedSet zu erzwingen ist nicht so elegant
+ public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements);
+
+}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -33,7 +33,6 @@
import java.util.Map.Entry;
import org.apache.log4j.Logger;
-import org.dllearner.algorithms.refinement.RefinementOperator;
import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.BooleanValueRestriction;
import org.dllearner.core.owl.DataRange;
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -29,7 +29,6 @@
import java.util.SortedSet;
import java.util.TreeSet;
-import org.dllearner.algorithms.refinement.RefinementOperator;
import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.BooleanValueRestriction;
import org.dllearner.core.owl.DatatypeProperty;
Added: trunk/src/dl-learner/org/dllearner/refinementoperators/package.html
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/package.html (rev 0)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/package.html 2008-07-30 14:49:02 UTC (rev 1029)
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head></head>
+<body bgcolor="white">
+<p>Refinement operator implementations.</p>
+</body>
+</html>
\ No newline at end of file
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java 2008-07-30 13:51:05 UTC (rev 1028)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java 2008-07-30 14:49:02 UTC (rev 1029)
@@ -202,7 +202,7 @@
// MoveMenuItem move = new MoveMenuItem((NamedClass)desc, nc);
// dme.add(move);
// Set<NamedClass> complements = ore.getComplements(nc, ind);
-// System.out.println("Gr\xF6\xDFe" + complements.size());
+// System.out.println("Gr��e" + complements.size());
// if(!(complements.size() <=1)){
// move.setEnabled(false);
// StringBuffer strBuf = new StringBuffer();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-07-31 11:46:03
|
Revision: 1033
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1033&view=rev
Author: jenslehmann
Date: 2008-07-31 11:45:59 +0000 (Thu, 31 Jul 2008)
Log Message:
-----------
EL description trees continued
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java
trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 10:15:31 UTC (rev 1032)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 11:45:59 UTC (rev 1033)
@@ -34,7 +34,10 @@
* of named classes and the edges are labelled with a property.
*
* In the documentation below "this node" refers to the root node
- * of this EL description (sub-)tree.
+ * of this EL description (sub-)tree. One tree cannot be reused,
+ * i.e. used as subtree in several description trees, as some of
+ * the associated variables (level, simulation) depend on the overall
+ * tree.
*
* @author Jens Lehmann
*
@@ -45,16 +48,23 @@
private List<Edge> edges;
+ private int level;
+
// parent node in the tree;
// null indicates that this node is a root node
private ELDescriptionTree parent = null;
+ // to simplify equivalence checks and minimisation, we
+ // attach a simulation relation to the description tree
+ private Simulation simulation;
+
/**
* Constructs an empty EL description tree with the empty set
* as root label and an empty set of outgoing edges.
*/
public ELDescriptionTree() {
this(new TreeSet<NamedClass>(), new LinkedList<Edge>());
+ simulation = new Simulation();
}
/**
@@ -100,11 +110,13 @@
/**
* Traverses the tree until the root node and counts how
* many edges are traversed. If this node does not have a parent,
- * zero is returned.
+ * zero is returned. This method is used for checking the integrity
+ * of the tree in unit tests. Use {@link #getLevel()} to get the
+ * level of the tree.
* @return The level of this node (or more specifically the root
* node of this subtree) within the overall EL description tree.
*/
- public int getLevel() {
+ public int computeLevel() {
ELDescriptionTree root = this;
int level = 0;
while(root.parent != null) {
@@ -127,5 +139,12 @@
public List<Edge> getEdges() {
return edges;
}
+
+ /**
+ * @return The level of the (root node of) this subtree in the overall tree.
+ */
+ public int getLevel() {
+ return level;
+ }
}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-07-31 11:45:59 UTC (rev 1033)
@@ -0,0 +1,109 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents a simulation relation between EL description trees.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class Simulation {
+
+ // the simulation relation S itself
+ private List<TreeTuple> relation;
+
+ // { w | (v,w) \in S } for all w
+ private Map<ELDescriptionTree,List<ELDescriptionTree>> in;
+
+ // { v | (v,w) \in S } for all v
+ private Map<ELDescriptionTree,List<ELDescriptionTree>> out;
+
+ public Simulation() {
+ relation = new LinkedList<TreeTuple>();
+ in = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>();
+ out = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>();
+ }
+
+ /**
+ * Adds a tuple to the simulation.
+ *
+ * @param tuple The new tuple.
+ * @see java.util.List#add(java.lang.Object)
+ */
+ public void addTuple(TreeTuple tuple) {
+ relation.add(tuple);
+
+ if(in.containsKey(tuple.getTree2())) {
+ in.get(tuple.getTree2()).add(tuple.getTree1());
+ } else {
+ List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>();
+ list.add(tuple.getTree1());
+ in.put(tuple.getTree2(), list);
+ }
+
+ if(out.containsKey(tuple.getTree1())) {
+ out.get(tuple.getTree1()).add(tuple.getTree2());
+ } else {
+ List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>();
+ list.add(tuple.getTree2());
+ out.put(tuple.getTree1(), list);
+ }
+ }
+
+ /**
+ * Removes a tuple from the simulation.
+ *
+ * @param tuple The new tuple.
+ * @see java.util.List#add(java.lang.Object)
+ */
+ public void removeTuple(TreeTuple tuple) {
+ relation.remove(tuple);
+
+ in.get(tuple.getTree2()).remove(tuple.getTree1());
+ if(in.get(tuple.getTree2()).isEmpty())
+ in.remove(tuple.getTree2());
+
+ out.get(tuple.getTree1()).remove(tuple.getTree2());
+ if(out.get(tuple.getTree1()).isEmpty())
+ out.remove(tuple.getTree1());
+ }
+
+ /**
+ * Gets the complete simulation relation.
+ * @return the relation
+ */
+ public List<TreeTuple> getRelation() {
+ return relation;
+ }
+
+ public List<ELDescriptionTree> in(ELDescriptionTree tree) {
+ return in.get(tree);
+ }
+
+ public List<ELDescriptionTree> out(ELDescriptionTree tree) {
+ return out.get(tree);
+ }
+}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-07-31 11:45:59 UTC (rev 1033)
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+/**
+ * A tuple of two EL description trees.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class TreeTuple {
+
+ private ELDescriptionTree tree1;
+
+ private ELDescriptionTree tree2;
+
+ public TreeTuple(ELDescriptionTree tree1, ELDescriptionTree tree2) {
+ this.tree1 = tree1;
+ this.tree2 = tree2;
+ }
+
+ /**
+ * Gets first tree.
+ * @return - first tree
+ */
+ public ELDescriptionTree getTree1() {
+ return tree1;
+ }
+
+ /**
+ * Gets second tree.
+ * @return - second tree
+ */
+ public ELDescriptionTree getTree2() {
+ return tree2;
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-07-31 11:45:59 UTC (rev 1033)
@@ -0,0 +1,49 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.test.junit;
+
+import static org.junit.Assert.*;
+
+import org.dllearner.algorithms.el.ELDescriptionTree;
+import org.dllearner.algorithms.el.Simulation;
+import org.dllearner.algorithms.el.TreeTuple;
+import org.junit.Test;
+
+/**
+ * Tests related to EL description tree including operations on
+ * them, simulations, equivalence checks, minimisation etc.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public final class ELDescriptionTreeTests {
+
+ @Test
+ public void simulationTest() {
+ Simulation s = new Simulation();
+ ELDescriptionTree t1 = new ELDescriptionTree();
+ ELDescriptionTree t2 = new ELDescriptionTree();
+ TreeTuple tuple1 = new TreeTuple(t1,t2);
+ s.addTuple(tuple1);
+ assertTrue(s.in(t2).size() == 1);
+ assertTrue(s.out(t2).size() == 0);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-07-31 14:30:06
|
Revision: 1034
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1034&view=rev
Author: jenslehmann
Date: 2008-07-31 14:29:56 +0000 (Thu, 31 Jul 2008)
Log Message:
-----------
- improved refinement operator interface
- continued work on EL description trees
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -24,7 +24,12 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectSomeRestriction;
+import org.dllearner.core.owl.Thing;
+import org.dllearner.core.owl.UnsupportedLanguageException;
/**
* Represents an EL description tree, which corresponds to a
@@ -86,6 +91,16 @@
}
/**
+ * Constructs an EL description tree from an EL description.
+ * @param description A description
+ */
+ public ELDescriptionTree(Description description) {
+ // TODO not implemented
+ // throw an exception if the description is not in EL
+ throw new UnsupportedLanguageException(description.toString(), "EL");
+ }
+
+ /**
* Checks whether this node has a parent. If the parent link
* is null, the node is considered to be a root node.
* @return True of this is the root node and false otherwise.
@@ -127,6 +142,33 @@
}
/**
+ * This method transform the tree to an EL description. The
+ * node labels are transformed to an {@link Intersection}
+ * of {@link NamedClass}. Each edges is transformed to an
+ * {@link ObjectSomeRestriction}, where the property is the edge
+ * label and the child description the subtree the edge points
+ * to. Edges are also added to the intersection. If the intersection
+ * is empty, {@link Thing} is returned.
+ * @return The description corresponding to this EL description tree.
+ */
+ public Description transformToDescription() {
+ if(label.size()==0 && edges.size()==0) {
+ return new Thing();
+ } else {
+ Intersection is = new Intersection();
+ for(NamedClass nc : label) {
+ is.addChild(nc);
+ }
+ for(Edge edge : edges) {
+ Description child = edge.getTree().transformToDescription();
+ ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child);
+ is.addChild(osr);
+ }
+ return is;
+ }
+ }
+
+ /**
* @return The label of root node of this subtree.
*/
public SortedSet<NamedClass> getLabel() {
Added: trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.core.owl;
+
+/**
+ * This exception is thrown if an operation does not support
+ * the required language. For instance, if a description containing
+ * a disjunction is passed to a method, which is only designed to
+ * handle EL concepts, this exception can be thrown.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class UnsupportedLanguageException extends RuntimeException {
+
+ private static final long serialVersionUID = -1271204878357422920L;
+
+ public UnsupportedLanguageException(String unsupportedConstruct, String targetLanguage) {
+ super("Unsupported construct \"" + unsupportedConstruct + "\". The target language is \"" + targetLanguage + "\".");
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -19,9 +19,10 @@
*/
package org.dllearner.refinementoperators;
-import java.util.List;
+import java.util.HashSet;
import java.util.Set;
+import org.dllearner.algorithms.el.ELDescriptionTree;
import org.dllearner.core.owl.Description;
/**
@@ -42,24 +43,31 @@
* @author Jens Lehmann
*
*/
-public class ELDown implements RefinementOperator {
+public class ELDown extends RefinementOperatorAdapter {
/* (non-Javadoc)
* @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description)
*/
@Override
public Set<Description> refine(Description concept) {
- // TODO Auto-generated method stub
- return null;
+ ELDescriptionTree tree = new ELDescriptionTree(concept);
+ Set<ELDescriptionTree> refinementTrees = refine(tree);
+ Set<Description> refinements = new HashSet<Description>();
+ for(ELDescriptionTree refinementTree : refinementTrees) {
+ refinements.add(refinementTree.transformToDescription());
+ }
+ return refinements;
}
-
- /* (non-Javadoc)
- * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List)
+
+ /**
+ * Performs downward refinement for the given tree. The operator
+ * works directly on EL description trees (which differ from the
+ * the tree structures build by descriptions).
+ *
+ * @param tree Input EL description tree.
+ * @return Set of refined EL description trees.
*/
- @Override
- public Set<Description> refine(Description concept, int maxLength,
- List<Description> knownRefinements) {
- // TODO Auto-generated method stub
+ public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
return null;
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -34,7 +34,7 @@
* @author jl
*
*/
-public class PsiDown implements RefinementOperator {
+public class PsiDown extends RefinementOperatorAdapter {
ConceptComparator conceptComparator = new ConceptComparator();
@@ -75,6 +75,7 @@
}
}
+ @Override
@SuppressWarnings("unchecked")
public Set<Description> refine(Description concept) {
@@ -236,6 +237,7 @@
}
+ @Override
public Set<Description> refine(Description concept, int maxLength,
List<Description> knownRefinements) {
throw new RuntimeException();
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -22,7 +22,7 @@
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.utilities.owl.ConceptComparator;
-public class PsiUp implements RefinementOperator {
+public class PsiUp extends RefinementOperatorAdapter {
ConceptComparator conceptComparator = new ConceptComparator();
@@ -63,6 +63,7 @@
}
}
+ @Override
@SuppressWarnings("unchecked")
public Set<Description> refine(Description concept) {
@@ -212,6 +213,7 @@
return refinements;
}
+ @Override
public Set<Description> refine(Description concept, int maxLength,
List<Description> knownRefinements) {
throw new RuntimeException();
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -1,3 +1,22 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
package org.dllearner.refinementoperators;
import java.util.List;
@@ -5,10 +24,45 @@
import org.dllearner.core.owl.Description;
+/**
+ * Interface for all refinement operators based on OWL/Description Logics.
+ * A refinement operator
+ * maps a description to a set of descriptions. For downward refinement
+ * operators those descriptions are more special. For upward refinement
+ * operators, those descriptions are more general.
+ *
+ * @author Jens Lehmann
+ *
+ */
public interface RefinementOperator {
- public Set<Description> refine(Description concept);
- // SortedSet zu erzwingen ist nicht so elegant
- public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements);
+ /**
+ * Standard refinement operation.
+ * @param description The description, which will be refined.
+ * @return A set of refinements.
+ */
+ public Set<Description> refine(Description description);
+ /**
+ * Optional refinement operation, where the learning algorithm can
+ * specify an additional bound on the length of descriptions.
+ *
+ * @param description The description, which will be refined.
+ * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}.
+ * @return A set of refinements obeying the above restrictions.
+ */
+ public Set<Description> refine(Description description, int maxLength);
+
+ /**
+ * Optional refinement operation, where the learning algorithm can
+ * specify an additional bound on the length of descriptions and
+ * a list of known refinements, which do not need to be returned.
+ *
+ * @param description The description, which will be refined.
+ * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}.
+ * @param knownRefinements A collection of known refinements, which do not need to be returned.
+ * @return A set of refinements obeying the above restrictions.
+ */
+ public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements);
+
}
Added: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.refinementoperators;
+
+import java.util.List;
+import java.util.Set;
+
+import org.dllearner.core.owl.Description;
+
+/**
+ * Adapter for {@link RefinementOperator} interface.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public abstract class RefinementOperatorAdapter implements RefinementOperator {
+
+ /* (non-Javadoc)
+ * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public abstract Set<Description> refine(Description description);
+
+ /* (non-Javadoc)
+ * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int)
+ */
+ @Override
+ public Set<Description> refine(Description description, int maxLength) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List)
+ */
+ @Override
+ public Set<Description> refine(Description description, int maxLength,
+ List<Description> knownRefinements) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -73,7 +73,7 @@
* @author Jens Lehmann
*
*/
-public class RhoDRDown implements RefinementOperator {
+public class RhoDRDown extends RefinementOperatorAdapter {
@SuppressWarnings({"unused"})
private static Logger logger = Logger
@@ -259,6 +259,7 @@
/* (non-Javadoc)
* @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description)
*/
+ @Override
public Set<Description> refine(Description concept) {
throw new RuntimeException();
}
@@ -266,6 +267,7 @@
/* (non-Javadoc)
* @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List)
*/
+ @Override
public Set<Description> refine(Description description, int maxLength,
List<Description> knownRefinements) {
return refine(description, maxLength, knownRefinements, startClass);
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-31 11:45:59 UTC (rev 1033)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-31 14:29:56 UTC (rev 1034)
@@ -59,7 +59,7 @@
* @author Jens Lehmann
*
*/
-public class RhoDown implements RefinementOperator {
+public class RhoDown extends RefinementOperatorAdapter {
// private PosNegLP learningProblem;
private ReasoningService rs;
@@ -111,6 +111,7 @@
// rs = learningProblem.getReasoningService();
}
+ @Override
public Set<Description> refine(Description concept) {
throw new RuntimeException();
// TODO Auto-generated method stub
@@ -123,6 +124,7 @@
// => als zweites wäre bei nicht ausreichendem Performancegewinn die Implementierung
// von Minimallänge eine Möglichkeit (alle Refinements, auch improper, müssten
// dann im Algorithmus gespeichert werden)
+ @Override
@SuppressWarnings("unchecked")
public SortedSet<Description> refine(Description concept, int maxLength,
List<Description> knownRefinements) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-07-31 16:27:45
|
Revision: 1042
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1042&view=rev
Author: kurzum
Date: 2008-07-31 16:27:38 +0000 (Thu, 31 Jul 2008)
Log Message:
-----------
Wikipedia Category cleaner
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java
trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparqlold.java
trunk/src/dl-learner/org/dllearner/utilities/learn/SPARQLExtractionEvaluation.java
trunk/src/dl-learner/org/dllearner/utilities/learn/SPARQLMassLearning.java
Removed Paths:
-------------
trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java
trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java
Deleted: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-31 16:23:42 UTC (rev 1041)
+++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -1,562 +0,0 @@
-/**
- * Copyright (C) 2007-2008, Jens Lehmann
- *
- * This file is part of DL-Learner.
- *
- * DL-Learner is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DL-Learner is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.dllearner.scripts;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-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.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent;
-import org.dllearner.core.ComponentManager;
-import org.dllearner.core.EvaluatedDescription;
-import org.dllearner.core.KnowledgeSource;
-import org.dllearner.core.LearningAlgorithm;
-import org.dllearner.core.LearningProblem;
-import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.ReasoningService;
-import org.dllearner.core.owl.Description;
-import org.dllearner.kb.sparql.Cache;
-import org.dllearner.kb.sparql.SPARQLTasks;
-import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlKnowledgeSource;
-import org.dllearner.learningproblems.PosNegDefinitionLP;
-import org.dllearner.learningproblems.PosNegLP;
-import org.dllearner.reasoning.FastInstanceChecker;
-import org.dllearner.utilities.Files;
-import org.dllearner.utilities.JamonMonitorLogger;
-import org.dllearner.utilities.datastructures.SetManipulation;
-import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
-import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
-
-public class SKOS7030 {
-
- public int test = 0;
-
- private static SPARQLTasks sparqlTasks;
-
- private static LearningAlgorithm la;
-
- private static final long wash = 1216800000000L;
-
- private boolean stable = true;
-
- // private static long wash = 1216901570168
-
- private static Logger logger = Logger.getRootLogger();
-
- static boolean local = true;
-
- static String url = "";
-
- // LEARNING
- static int recursiondepth = 1;
-
- static boolean closeAfterRecursion = true;
-
- static boolean randomizeCache = false;
-
- static double noise = 15;
-
- static int maxExecutionTimeInSeconds = 30;
-
- static int guaranteeXgoodDescriptions = 40;
-
- // examples
- static int sparqlResultSize = 2000;
-
- static double percentOfSKOSSet = 0.2;
-
- static double negfactor = 1.0;
-
- SortedSet<String> posExamples = new TreeSet<String>();
-
- SortedSet<String> fullPositiveSet = new TreeSet<String>();
-
- SortedSet<String> fullPosSetWithoutPosExamples = new TreeSet<String>();
-
- SortedSet<String> negExamples = new TreeSet<String>();
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- initLogger();
- logger.info("Start");
- // String resultString="";
- // System.out.println(time());
- // System.out.println(System.currentTimeMillis());
-
-
- // parameters
-
- if (local) {
- url = "http://139.18.2.37:8890/sparql";
- sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),
- SparqlEndpoint.getEndpointLOCALDBpedia());
- } else {
- url = "http://dbpedia.openlinksw.com:8890/sparql";
- sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(),
- SparqlEndpoint.getEndpointDBpedia());
- }
-
-
- String st= "http://dbpedia.org/class/yago/Person100007846";
- st = "http://dbpedia.org/class/yago/Leader109623038";
- System.out.println(sparqlTasks.getSuperClasses(st, 2));
- System.out.println(sparqlTasks.getSuperClasses(st, 1));
- System.out.println(sparqlTasks.getSubClasses(st, 0));
-
- System.exit(0);
-
- //System.out.println(sparqlTasks.getDomain(
- // "http://dbpedia.org/property/predecessor", 1000));
-
- String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
-
- // String
- // award=("http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners");
-
- SKOS7030 s = new SKOS7030();
-
- s.makeExamples(target, percentOfSKOSSet, negfactor, sparqlResultSize);
-
- // System.exit(0);
- List<Description> conceptresults = new ArrayList<Description>();
- List<EvaluatedDescription> conceptresults2 = new ArrayList<EvaluatedDescription>();
- s.learn();
-
- recordConceptClasses();
-
- System.exit(0);
-
- // EvaluatedDescription
- logger.debug("found nr of concepts: " + conceptresults.size());
- System.out.println(conceptresults);
-
- int x = 0;
-
- SortedSet<ResultMostCoveredInRest> res = new TreeSet<ResultMostCoveredInRest>();
- for (Description concept : conceptresults) {
- if (x++ == 100)
- break;
- res.add(s.evaluate(concept, 1000));
-
- }
-
- x = 0;
- for (ResultMostCoveredInRest resultMostCoveredInRest : res) {
- if (x++ == 10)
- break;
- System.out.println(resultMostCoveredInRest.concept);
- System.out.println(resultMostCoveredInRest.accuracy);
- System.out.println(resultMostCoveredInRest.retrievedInstancesSize);
-
- }
-
- s.print(res.first().concept, 1000);
-
- System.out.println("Finished");
- JamonMonitorLogger.printAllSortedByLabel();
-
- }
-
- void print(final Description concept, final int sparqlResultLimit) {
- logger.debug("evaluating concept: " + concept);
- // SortedSet<String> instances =
- // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(),
- // sparqlResultLimit);
- SortedSet<String> instances = sparqlTasks
- .retrieveInstancesForClassDescriptionIncludingSubclasses(concept
- .toKBSyntaxString(), sparqlResultLimit,1);
-
- SortedSet<String> coveredInRest = new TreeSet<String>(
- fullPosSetWithoutPosExamples);
- coveredInRest.retainAll(instances);
-
- SortedSet<String> coveredTotal = new TreeSet<String>(fullPositiveSet);
- coveredTotal.retainAll(instances);
-
- SortedSet<String> notCoveredInRest = new TreeSet<String>(
- fullPosSetWithoutPosExamples);
- notCoveredInRest.retainAll(coveredInRest);
- System.out.println(notCoveredInRest);
-
- SortedSet<String> notCoveredTotal = new TreeSet<String>(fullPositiveSet);
- notCoveredTotal.retainAll(coveredTotal);
- System.out.println(notCoveredTotal);
-
- }
-
- ResultMostCoveredInRest evaluate(Description concept, int sparqlResultLimit) {
- logger.debug("evaluating concept: " + concept);
- // SortedSet<String> instances =
- // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(),
- // sparqlResultLimit);
- SortedSet<String> instances = sparqlTasks
- .retrieveInstancesForClassDescriptionIncludingSubclasses(concept
- .toKBSyntaxString(), sparqlResultLimit, 1 );
-
- SortedSet<String> coveredInRest = new TreeSet<String>(
- fullPosSetWithoutPosExamples);
- coveredInRest.retainAll(instances);
-
- SortedSet<String> coveredTotal = new TreeSet<String>(fullPositiveSet);
- coveredTotal.retainAll(instances);
-
- SortedSet<String> notCoveredInRest = new TreeSet<String>(
- fullPosSetWithoutPosExamples);
- notCoveredInRest.retainAll(coveredInRest);
-
- SortedSet<String> notCoveredTotal = new TreeSet<String>(fullPositiveSet);
- notCoveredTotal.retainAll(coveredTotal);
- double acc = (double) (coveredInRest.size() / fullPosSetWithoutPosExamples
- .size());
- System.out.println("Accuracy: " + acc);
- return new ResultMostCoveredInRest(concept, acc, instances.size());
-
- }
-
- private static void initLogger() {
-
- SimpleLayout layout = new SimpleLayout();
- // create logger (a simple logger which outputs
- // its messages to the console)
- FileAppender fileAppender = null;
- try {
- fileAppender = new FileAppender(layout, "log/progress/skos"
- + time() + ".txt", false);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- logger.removeAllAppenders();
- logger.addAppender(consoleAppender);
- logger.addAppender(fileAppender);
- logger.setLevel(Level.DEBUG);
- Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
-
- }
-
- /*
- * public static SortedSet<String> selectDBpediaConcepts(int number){
- * String query = "SELECT DISTINCT ?concept WHERE { \n" + "[] a ?concept
- * .FILTER (regex(str(?concept),'yago'))" + " \n} \n"; //LIMIT "+number+"
- *
- * String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
- * ResultSet rs =SparqlQuery.JSONtoResultSet(JSON); JenaResultSetConvenience
- * rsc = new JenaResultSetConvenience(rs); return
- * SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number); }
- */
-
- public void makeExamples(String SKOSConcept, double percentOfSKOSSet,
- double negfactor, int sparqlResultSize) {
-
- // POSITIVES
- AutomaticPositiveExampleFinderSPARQL apos = new AutomaticPositiveExampleFinderSPARQL(
- sparqlTasks);
- apos.makePositiveExamplesFromSKOSConcept(SKOSConcept);
- fullPositiveSet = apos.getPosExamples();
-
- // System.exit(0);
-
- int poslimit = (int) Math.round(percentOfSKOSSet
- * fullPositiveSet.size());
- int neglimit = (int) Math.round(poslimit * negfactor);
-
- posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit);
-
- // NEGATIVES
-
- AutomaticNegativeExampleFinderSPARQL aneg = new AutomaticNegativeExampleFinderSPARQL(
- fullPositiveSet, sparqlTasks);
-
- aneg.makeNegativeExamplesFromParallelClasses(posExamples,
- sparqlResultSize);
- negExamples = aneg.getNegativeExamples(neglimit, stable);
-
- logger.debug("POSITIVE EXAMPLES");
- for (String pos : posExamples) {
- logger.debug("+" + pos);
- }
-
- logger.debug("NEGATIVE EXAMPLES");
- for (String negs : this.negExamples) {
- logger.debug("-" + negs);
- }
-
- fullPosSetWithoutPosExamples = fullPositiveSet;
- fullPosSetWithoutPosExamples.removeAll(posExamples);
-
- logger.debug(fullPositiveSet);
- logger.debug(fullPosSetWithoutPosExamples);
- }
-
- public void learn() {
-
- SortedSet<String> instances = new TreeSet<String>();
- instances.addAll(this.posExamples);
- instances.addAll(this.negExamples);
-
- logger.info("Start Learning with");
- logger.info("positive examples: \t" + posExamples.size());
- logger.info("negative examples: \t" + negExamples.size());
- logger.info("instances \t" + instances.size());
-
- ComponentManager cm = ComponentManager.getInstance();
- // LearningAlgorithm la = null;
- ReasoningService rs = null;
- LearningProblem lp = null;
- SparqlKnowledgeSource ks = null;
- try {
- Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>();
- ks = cm.knowledgeSource(SparqlKnowledgeSource.class);
- ReasonerComponent r = new FastInstanceChecker(sources);
- rs = new ReasoningService(r);
- // System.out.println("satisfy: "+rs.isSatisfiable());
- lp = new PosNegDefinitionLP(rs);
- ((PosNegLP) lp).setPositiveExamples(SetManipulation
- .stringToInd(this.posExamples));
- ((PosNegLP) lp).setNegativeExamples(SetManipulation
- .stringToInd(this.negExamples));
-
- la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs);
-
- logger.debug("start learning");
-
- // KNOWLEDGESOURCE
- cm.applyConfigEntry(ks, "instances", instances);
- cm.applyConfigEntry(ks, "url", url);
- cm.applyConfigEntry(ks, "recursionDepth", recursiondepth);
- cm.applyConfigEntry(ks, "closeAfterRecursion", closeAfterRecursion);
- cm.applyConfigEntry(ks, "predefinedFilter", "YAGO");
- if (local)
- cm.applyConfigEntry(ks, "predefinedEndpoint", "LOCALDBPEDIA");
- else {
- cm.applyConfigEntry(ks, "predefinedEndpoint", "DBPEDIA");
- }
- if (randomizeCache)
- cm.applyConfigEntry(ks, "cacheDir", "cache/"
- + System.currentTimeMillis() + "");
- else {
- cm.applyConfigEntry(ks, "cacheDir", Cache.getDefaultCacheDir());
- }
-
- // LEARNINGALGORITHM
- cm.applyConfigEntry(la, "useAllConstructor", false);
- cm.applyConfigEntry(la, "useExistsConstructor", true);
- cm.applyConfigEntry(la, "useCardinalityRestrictions", false);
- cm.applyConfigEntry(la, "useNegation", false);
- cm.applyConfigEntry(la, "minExecutionTimeInSeconds", 0);
- cm.applyConfigEntry(la, "maxExecutionTimeInSeconds",
- maxExecutionTimeInSeconds);
- cm.applyConfigEntry(la, "guaranteeXgoodDescriptions",
- guaranteeXgoodDescriptions);
- cm.applyConfigEntry(la, "writeSearchTree", false);
- cm.applyConfigEntry(la, "searchTreeFile", "log/SKOS.txt");
- cm.applyConfigEntry(la, "replaceSearchTree", true);
- cm.applyConfigEntry(la, "noisePercentage", noise);
- // cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",999999);
- cm.applyConfigEntry(la, "logLevel", "TRACE");
- /*
- * if(ignoredConcepts.size()>0)
- * cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts);
- */
-
- ks.init();
- sources.add(ks);
- r.init();
- lp.init();
- la.init();
-
- la.start();
- // Statistics.addTimeCollecting(sc.getTime());
- // Statistics.addTimeLearning(sc.getTime());
-
- // return la.getCurrentlyBestDescriptions();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- // return null;
-
- }
-
- // String t="\"http://dbpedia.org/class/yago/Fiction106367107\"";
- // t="(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND
- // (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND
- // \"http://dbpedia.org/class/yago/Representative110522035\"))";
- // //System.out.println(t);
- // //t="\"http://www.w3.org/2004/02/skos/core#subject\"";
- // //conceptRewrite(t);
- // //getSubClasses(t);
- //
- // AutomaticExampleFinderSKOSSPARQL ae= new
- // AutomaticExampleFinderSKOSSPARQL( se);
- // try{
- // System.out.println("oneconcept: "+t);
- // SortedSet<String> instances =
- // ae.queryConceptAsStringSet(conceptRewrite(t), 200);
- // if(instances.size()>=0)System.out.println("size of instances
- // "+instances.size());
- // if(instances.size()>=0 && instances.size()<100)
- // System.out.println("instances"+instances);
- // }catch (Exception e) {
- // e.printStackTrace();
- // }
- // SortedSet<String> concepts = new TreeSet<String>();
-
- // System.out.println(DBpediaSKOS(prim));
- // double acc1=0.0;
- // for (int i = 0; i < 5; i++) {
- // acc1+=DBpediaSKOS(prim);
- // }
- // System.out.println("accprim"+(acc1/5));
- //
- // double acc2=0.0;
- // for (int i = 0; i < 5; i++) {
- // acc2+=DBpediaSKOS(award);
- // }
- // System.out.println("accprim"+(acc2/5));
-
- // DBpediaSKOS(concepts.first());
- // DBpediaSKOS(concepts.first());
- // concepts.remove(concepts.first());
- // DBpediaSKOS(concepts.first());
- // DBpediaSKOS(concepts.first());
- // concepts.remove(concepts.first());
- // DBpediaSKOS(concepts.first());
- // DBpediaSKOS(concepts.first());
- // algorithm="refinement";
- // roles();
-
- /*
- * System.out.println(Level.DEBUG.getClass());
- * System.out.println(Level.toLevel("INFO"));
- * System.out.println(Level.INFO);
- */
- // System.exit(0);
- private class ResultCompare implements Comparable<ResultCompare> {
- Description concept;
-
- double accuracy = 0.0;
-
- int retrievedInstancesSize = 0;
-
- public int compareTo(ResultCompare o2) {
- return 0;
- }
-
-
- public boolean equals(ResultCompare o2) {
- return this.concept.equals(o2.concept);
- }
-
- public ResultCompare(Description conceptKBSyntax, double accuracy,
- int retrievedInstancesSize) {
- super();
- this.concept = conceptKBSyntax;
- this.accuracy = accuracy;
- this.retrievedInstancesSize = retrievedInstancesSize;
- }
-
- }
-
- private class ResultMostCoveredInRest extends ResultCompare {
-
- public ResultMostCoveredInRest(Description concept, double accuracy,
- int retrievedInstancesSize) {
- super(concept, accuracy, retrievedInstancesSize);
-
- }
-
- public int compareTo(ResultMostCoveredInRest o2) {
- if (this.equals(o2))
- return 0;
-
- if (this.accuracy > o2.accuracy) {
- return 1;
- } else if (this.accuracy == o2.accuracy) {
- if (this.retrievedInstancesSize < o2.retrievedInstancesSize)
- return 1;
- else if (this.retrievedInstancesSize > o2.retrievedInstancesSize) {
- return -1;
- } else
- return this.concept.toKBSyntaxString().compareTo(
- o2.concept.toKBSyntaxString());
- } else {
- return -1;
- }
-
- }
-
- }
-
- public static String time() {
- return ("" + (System.currentTimeMillis() - wash)).substring(0, 7);
-
- }
-
- /**
- *
- */
- public static void recordConceptClasses() {
- StringBuffer result =new StringBuffer();
- StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n");
- StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n");
- int result1count = 1;
- int result2count = 1;
- List<EvaluatedDescription> conceptresults = la
- .getCurrentlyBestEvaluatedDescriptions(5000, .70, true);
-
- int x = 0;
- for (EvaluatedDescription description : conceptresults) {
- if (x < 50) {
- x++;
- result.append(description + "\n");
- }
-
- if (!description.toString().contains("Entity")) {
- result1.append(description + "\n");
- result1count++;
- }
- if (!description.toString().contains("OR")) {
- result2.append(description + "\n");
- result2count++;
- }
- }
- result.append("full size: " + conceptresults.size());
- result.append(result1.toString() + " size: " + result1count + "\n");
- result.append(result2.toString() + " size: " + result2count + "\n");
-
- Files.createFile(new File("results/descriptions/concepts" + time()
- + ".txt"), result.toString());
- }
-
-}
Deleted: trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java 2008-07-31 16:23:42 UTC (rev 1041)
+++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -1,251 +0,0 @@
-package org.dllearner.scripts;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.FileAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.dllearner.kb.sparql.Cache;
-import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlQuery;
-import org.dllearner.utilities.learn.LearnSparql;
-import org.dllearner.utilities.statistics.SimpleClock;
-import org.dllearner.utilities.statistics.Statistics;
-
-import com.hp.hpl.jena.query.ResultSet;
-
-public class SPARQLExtractionEvaluation {
-
- static Cache c;
- static SparqlEndpoint se;
- private static Logger logger = Logger.getRootLogger();
-
- //static String standardSettings="";
- //static String algorithm="refexamples";
-
- //vars
- static boolean useRelated = false;
- static boolean useSuperClasses = true;
- static boolean useParallelClasses = true;
- static int poslimit = 0;
- static int neglimit = 0;
- static boolean randomizeCache = true;
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- init();
- System.out.println("Start");
- //logger.setLevel(Level.TRACE);
- logger.setLevel(Level.WARN);
- //Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN);
- //Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
- //System.out.println(Logger.getLogger(SparqlQuery.class).getLevel());
- SimpleClock sc=new SimpleClock();
- LocalDBpediaEvaluation();
-
- sc.printAndSet("Finished");
-
- }
-
-
- static void LocalDBpediaEvaluation(){
- boolean local=true;
- SimpleClock total =new SimpleClock();
- String url="";
- if(local){
- se = SparqlEndpoint.getEndpointLOCALDBpedia();
-
- url = "http://139.18.2.37:8890/sparql";
-
- }else{
- se = SparqlEndpoint.getEndpointDBpedia();
- url= "http://dbpedia.openlinksw.com:8890/sparql";
- }
-
-
- SortedSet<String> concepts = new TreeSet<String>();
- SortedSet<String> tmpSet = new TreeSet<String>();
- //System.out.println(selectDBpediaConcepts(10));
- tmpSet=initConcepts();
- int number=tmpSet.size();
- //System.out.println(number);
- //concepts.add("\"http://dbpedia.org/class/yago/Flamethrower103356559\"");
- for (String string : tmpSet) {
- //System.out.println("\""+string+"\",");
- concepts.add("\""+string+"\"");
- }
-
-
-
- SortedSet<String> posExamples = new TreeSet<String>();
- SortedSet<String> negExamples = new TreeSet<String>();
-
- for (int a = 0; a < 1; a++) {
-
- poslimit+=15;
- neglimit+=15;
- printProgress(0, concepts.size(),0, "beginning",total.getTime());
-
- int concount=0;
- for (String oneConcept : concepts) {
- concount++;
- printProgress(concount, concepts.size(),0, oneConcept,total.getTime());
- int recursiondepth=0;
- boolean closeAfterRecursion=true;
-
- System.out.println(oneConcept);
- //AutomaticExampleFinderSPARQLold ae= new AutomaticExampleFinderSPARQLold( se);
-
- //ae.initDBpedia(oneConcept, useRelated, useSuperClasses,useParallelClasses, poslimit, neglimit);
-
- //posExamples = ae.getPosExamples();
- //negExamples = ae.getNegExamples();
-
- for(recursiondepth=0;recursiondepth<4;recursiondepth++) {
-
- Statistics.setCurrentLabel(recursiondepth+"");
- printProgress(concount, concepts.size(),recursiondepth, oneConcept,total.getTime());
- /*if(i==0){;}
- else if(closeAfterRecursion) {
- closeAfterRecursion=false;
- recursiondepth++;
- }
- else {
- closeAfterRecursion=true;
- }*/
-
-
- Statistics.print(number);
-
- //System.out.println("currently at label "+Statistics.getCurrentLabel()+"||i: "+recursiondepth);
-
- LearnSparql ls = new LearnSparql();
- TreeSet<String> igno = new TreeSet<String>();
- igno.add(oneConcept.replaceAll("\"", ""));
- //igno.add("\""+oneConcept+"\"");
- //System.out.println(oneConcept);
-
- ls.learnDBpedia(posExamples, negExamples, url,igno,recursiondepth, closeAfterRecursion,randomizeCache);
-
-
- }
- }
- Statistics.print(number);
- String pre="log/gnu_";
- int examples=poslimit+neglimit;
- String comment1="# "+examples+"examples\n";
- String f1=pre+"1avgtrip_"+examples+"example"+concepts.size()+"classes";
- writeToFile(f1, comment1+Statistics.getAVGTriplesForRecursionDepth(number));
- String comment2="# "+examples+"examples\n";
- String f2=pre+"2avgTimeExtraction_"+examples+"example"+concepts.size()+"classes";
- writeToFile(f2, comment2+Statistics.getAVGTimeCollecting(number));
- String comment3="# "+examples+"examples\n";
- String f3=pre+"2avgTimeLearning_"+examples+"example"+concepts.size()+"classes";
- writeToFile(f3, comment3+Statistics.getAVGTimeLearning(number));
- String comment4="# "+examples+"examples\n";
- String f4=pre+"2avgTotalTime_"+examples+"example"+concepts.size()+"classes";
- writeToFile(f4, comment4+Statistics.getAVGtotalTime(number));
- Statistics.reset();
-
- }//outer
- }
-
-
-
- public static void init() {
-
- SimpleLayout layout = new SimpleLayout();
- // create logger (a simple logger which outputs
- // its messages to the console)
- FileAppender fileAppender =null; ;
- try{
- fileAppender = new FileAppender(layout,"log/sparqleval.txt",false);
- }catch (Exception e) {e.printStackTrace();}
-
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- logger.removeAllAppenders();
- logger.addAppender(consoleAppender);
- logger.addAppender(fileAppender);
-
- c = new Cache("cachetemp");
-
-
- }
-
- //FIXME
- public static SortedSet<String> selectDBpediaConcepts(int number){
- String query = "SELECT DISTINCT ?concept WHERE { \n" +
- "[] a ?concept .FILTER (regex(str(?concept),'yago'))" +
- " \n} LIMIT "+1000+" \n "; //
-
- String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
- ResultSet rs =SparqlQuery.convertJSONtoResultSet(JSON);
- if(rs==null);
- //JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs);
- //return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number);
- return null;
- }
-
- public static SortedSet<String> initConcepts(){
- SortedSet<String> concepts = new TreeSet<String>();
- concepts.add("http://dbpedia.org/class/yago/AirLane108492546");
- concepts.add("http://dbpedia.org/class/yago/AlphaBlocker102698769");
- concepts.add("http://dbpedia.org/class/yago/Articulation107131854");
-
- concepts.add("http://dbpedia.org/class/yago/Ceremony107450842");
- concepts.add("http://dbpedia.org/class/yago/CookingOil107673145");
- concepts.add("http://dbpedia.org/class/yago/Corticosteroid114751417");
- concepts.add("http://dbpedia.org/class/yago/Curlew102033561");
- concepts.add("http://dbpedia.org/class/yago/DataStructure105728493");
- concepts.add("http://dbpedia.org/class/yago/Disappearance100053609");
- concepts.add("http://dbpedia.org/class/yago/Flintstone114871268");
-// concepts.add("http://dbpedia.org/class/yago/Form105930736");
-// concepts.add("http://dbpedia.org/class/yago/Hypochondriac110195487");
-// concepts.add("http://dbpedia.org/class/yago/Industrialist110204177");
-// concepts.add("http://dbpedia.org/class/yago/Lifeboat103662601");
-// concepts.add("http://dbpedia.org/class/yago/Particulate114839439");
-// concepts.add("http://dbpedia.org/class/yago/Patriot110407310");
-// concepts.add("http://dbpedia.org/class/yago/Reservation108587174");
-// concepts.add("http://dbpedia.org/class/yago/Schoolteacher110560352");
-// concepts.add("http://dbpedia.org/class/yago/Singer110599806");
-// concepts.add("http://dbpedia.org/class/yago/SupremeCourt108336188");
-
- return concepts;
- }
-
- protected static void writeToFile(String filename, String content) {
- // create the file we want to use
- File file = new File( filename);
-
- try {
- file.createNewFile();
- FileOutputStream fos = new FileOutputStream(filename, false);
- // ObjectOutputStream o = new ObjectOutputStream(fos);
- fos.write(content.getBytes());
- fos.flush();
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public static void printProgress(int con, int consize,int recdepth, String conceptname, long needed){
- int ex=poslimit+neglimit;
- System.out.println("**********************STAT\n" +
- "XXX num ex : "+ex+ " \n" +
- "concept : "+con+"/"+consize+ " \n" +
- "recursion : "+recdepth+" \n" +
- "conceptname : "+conceptname+ "\n" +
- "needed total: "+needed);
- }
-
-
-}
Deleted: trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-07-31 16:23:42 UTC (rev 1041)
+++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -1,269 +0,0 @@
-package org.dllearner.scripts;
-
-import java.net.URLEncoder;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.FileAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.dllearner.kb.sparql.Cache;
-import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlKnowledgeSource;
-import org.dllearner.kb.sparql.SparqlQuery;
-import org.dllearner.utilities.learn.ConfWriter;
-import org.dllearner.utilities.learn.LearnSparql;
-import org.dllearner.utilities.statistics.SimpleClock;
-import org.dllearner.utilities.statistics.Statistics;
-
-import com.hp.hpl.jena.query.ResultSet;
-
-public class SPARQLMassLearning {
-
-
- static Cache c;
- static SparqlEndpoint se;
- private static Logger logger = Logger.getRootLogger();
-
- static String standardSettings="";
- static String algorithm="refexamples";
- static String standardSettingsRefexamples =
- "refexamples.minExecutionTimeInSeconds = 30;\n" +
- "refexamples.maxExecutionTimeInSeconds = 30;\n" +
- "//refexamples.guaranteeXgoodDescriptions = 10;\n" +
- "refexamples.logLevel=\"TRACE\";\n" +
- "refexamples.noisePercentage = 0.10;\n" +
- "refexamples.writeSearchTree = false;\n" +
- "refexamples.searchTreeFile = \"searchTree.txt\";\n" +
- "refexamples.replaceSearchTree = true;\n\n" ;
-
- static String standardSettingsRefinement =
- "refinement.minExecutionTimeInSeconds = 30;\n" +
- "refinement.maxExecutionTimeInSeconds = 30;\n" +
- "//refinement.guaranteeXgoodDescriptions = 10;\n" +
- "refinement.logLevel=\"TRACE\";\n" +
- "refinement.writeSearchTree = false;\n" +
- "refinement.searchTreeFile = \"searchTree.txt\";\n" +
- "refinement.replaceSearchTree = true;\n\n" ;
-
-
-
- static String standardDBpedia="" +
- "sparql.recursionDepth = 1;\n" +
- "sparql.predefinedFilter = \"YAGO\";\n" +
- "sparql.predefinedEndpoint = \"DBPEDIA\";\n";
- //"sparql.logLevel = \"INFO\";\n";
-
-
- //vars
- static boolean useRelated = false;
- static boolean useSuperClasses = false;
- static boolean useParallelClasses = true;
- static int poslimit = 10;
- static int neglimit = 20;
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- init();
- //logger.setLevel(Level.TRACE);
- Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.INFO);
- //System.out.println(Logger.getLogger(SparqlQuery.class).getLevel());
- SimpleClock sc=new SimpleClock();
-
- standardSettings=standardSettingsRefexamples+standardDBpedia;
- //standardSettings=standardSettingsRefinement+standardDBpedia;
-
- DBpedia();
- //algorithm="refinement";
- //roles();
-
- /*System.out.println(Level.DEBUG.getClass());
- System.out.println(Level.toLevel("INFO"));
- System.out.println(Level.INFO);*/
- //System.exit(0);
-
-
-
- sc.printAndSet("Finished");
-
- }
-
-
-
-
- static void roles(){
-
- se = SparqlEndpoint.getEndpointDBpedia();
- //se = SparqlEndpoint.EndpointUSCensus();
- SortedSet<String> roles = new TreeSet<String>();
- roles.add("http://dbpedia.org/property/birthPlace");
- //roles.add("http://www.rdfabout.com/rdf/schema/census/landArea");
- standardSettings+=algorithm+".ignoredRoles = {\""+roles.first()+"\"};\n";
-
- SortedSet<String> posExamples = new TreeSet<String>();
- SortedSet<String> negExamples = new TreeSet<String>();
- String url = "http://dbpedia.openlinksw.com:8890/sparql";
- //HashMap<String, ResultSet> result = new HashMap<String, ResultSet>();
- //HashMap<String, String> result2 = new HashMap<String, String>();
- //System.out.println(concepts.first());
- //logger.setLevel(Level.TRACE);
- //AutomaticExampleFinderRolesSPARQL ae= new AutomaticExampleFinderRolesSPARQL( se);
-
- //ae.initDomainRange(roles.first(), poslimit, neglimit);
-
- //posExamples = ae.getPosExamples();
- //negExamples = ae.getNegExamples();
-
- System.out.println(posExamples);
- System.out.println(negExamples);
- //System.exit(0);
- String tmp = roles.first().replace("http://dbpedia.org/property/", "").replace("\"","");
- String confname1 = "";
- String confname2 = "";
- try{
- confname1 = URLEncoder.encode(tmp, "UTF-8")+"_domain.conf";
- confname2 = URLEncoder.encode(tmp, "UTF-8")+"_range.conf";
- }catch (Exception e) {e.printStackTrace();}
- //
- ConfWriter cf=new ConfWriter();
- cf.addToStats("relearned role: "+roles.first());
-
- //System.exit(0);
- //"relearned concept: ";
- cf.writeSPARQL(confname1, negExamples,posExamples, url, new TreeSet<String>(),standardSettings,algorithm);
-
- cf.writeSPARQL(confname2, posExamples, negExamples, url, new TreeSet<String>(),standardSettings,algorithm);
- //new LearnSparql().learn(posExamples, negExamples, "http://dbpedia.openlinksw.com:8890/sparql", new TreeSet<String>());
-
-
- }
-
- static void DBpedia(){
- se = SparqlEndpoint.getEndpointLOCALDBpedia();
- //concepts.add("(EXISTS \"monarch\".TOP AND EXISTS \"predecessor\".(\"Knight\" OR \"Secretary\"))");
-
- SortedSet<String> concepts = new TreeSet<String>();
- SortedSet<String> tmpSet=selectDBpediaConcepts(20);
- System.out.println(concepts.size());
- for (String string : tmpSet) {
- concepts.add("\""+string+"\"");
- }
- concepts.remove(concepts.first());
- concepts.remove(concepts.first());
- concepts.remove(concepts.first());
- concepts.remove(concepts.first());
- concepts.remove(concepts.first());
- concepts.remove(concepts.first());
- concepts.remove(concepts.first());
- //concepts.remove(concepts.first());
- //concepts.add("(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND \"http://dbpedia.org/class/yago/Representative110522035\"))");
- //concepts.add("\"http://dbpedia.org/class/yago/Person100007846\"");
- //concepts.add("\"http://dbpedia.org/class/yago/FieldMarshal110086821\"");
- //concepts.add("http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom");
- //concepts.add("http://dbpedia.org/resource/Category:Grammy_Award_winners");
- //concepts.add("EXISTS \"http://dbpedia.org/property/grammyawards\".TOP");
-
- SortedSet<String> posExamples = new TreeSet<String>();
- SortedSet<String> negExamples = new TreeSet<String>();
- String url = "http://dbpedia.openlinksw.com:8890/sparql";
- url = "http://139.18.2.37:8890/sparql";
- //HashMap<String, ResultSet> result = new HashMap<String, ResultSet>();
- //HashMap<String, String> result2 = new HashMap<String, String>();
- //System.out.println(concepts.first());
- //logger.setLevel(Level.TRACE);
-
- //String concept=concepts.first();
- //int i=0;
- Statistics.setCurrentLabel("0");
- int recursiondepth=0;
- boolean closeAfterRecursion=false;
- //int numberOfTriples = 0;
- for (String oneConcept : concepts) {
- //AutomaticExampleFinderSPARQLold ae= new AutomaticExampleFinderSPARQLold( se);
- useRelated = true;
- useSuperClasses = true;
- useParallelClasses = false;
-
- poslimit=10;
- neglimit=10;
- //ae.initDBpedia(concept, useRelated, useSuperClasses,useParallelClasses, poslimit, neglimit);
- //posExamples = ae.getPosExamples();
- //negExamples = ae.getNegExamples();
-
-
- /*String tmp = concepts.first().replace("http://dbpedia.org/resource/Category:", "").replace("\"","");
- tmp = tmp.replace("http://dbpedia.org/class/yago/", "");
- tmp = tmp.replace("http://dbpedia.org/property/", "");
- String confname = "";
- try{
- confname = URLEncoder.encode(tmp, "UTF-8")+".conf";
- }catch (Exception e) {e.printStackTrace();}*/
- //
- //ConfWriter cf=new ConfWriter();
- //cf.addToStats("relearned concept: "+concepts.first());
- //System.out.println(confname);
- LearnSparql ls = new LearnSparql();
- TreeSet<String> igno = new TreeSet<String>();
- System.out.println(oneConcept);
- //igno.add(oneConcept.replaceAll("\"", ""));
-
- ls.learnDBpedia(posExamples, negExamples, url,igno,recursiondepth, closeAfterRecursion,false);
-
- //System.out.println("AAAAAAAA");
- //System.exit(0);
- //"relearned concept: ";
- //cf.writeSPARQL(confname, posExamples, negExamples, url, new TreeSet<String>(),standardSettings,algorithm);
- //
-
- }
- //Statistics.print();
- }
-
-
-
-
-
-
-
-
- public static void init() {
-
- SimpleLayout layout = new SimpleLayout();
- // create logger (a simple logger which outputs
- // its messages to the console)
- FileAppender fileAppender =null; ;
- try{
- fileAppender = new FileAppender(layout,"the_log.txt",false);
- }catch (Exception e) {e.printStackTrace();}
-
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- logger.removeAllAppenders();
- logger.addAppender(consoleAppender);
- logger.addAppender(fileAppender);
- logger.setLevel(Level.DEBUG);
- c = new Cache("cachetemp");
-
-
- }
-
- public static SortedSet<String> selectDBpediaConcepts(int number){
- String query = "SELECT DISTINCT ?concept WHERE { \n" +
- "[] a ?concept .FILTER (regex(str(?concept),'yago'))" +
- " \n} \n"; //LIMIT "+number+"
-
-
- String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se)));
- ResultSet rs =SparqlQuery.convertJSONtoResultSet(JSON);
- if(rs==null);
- //JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs);
- //return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number);
- return null;
- }
-
-
-
-}
Added: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -0,0 +1,167 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.scripts;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.KnowledgeSource;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.kb.sparql.Cache;
+import org.dllearner.kb.sparql.SPARQLTasks;
+import org.dllearner.kb.sparql.SparqlEndpoint;
+import org.dllearner.kb.sparql.SparqlQuery;
+import org.dllearner.scripts.improveWikipedia.ConceptSelector;
+import org.dllearner.scripts.improveWikipedia.WikipediaCategoryTasks;
+import org.dllearner.utilities.JamonMonitorLogger;
+import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
+import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
+
+public class WikipediaCategoryCleaner {
+
+ private static SPARQLTasks sparqlTasks;
+
+ private static Cache cache;
+
+ private static Logger logger = Logger.getRootLogger();
+
+ private static boolean local = true; // localEndpoint switch
+
+ // parameters
+ public static final int SPARQL_RESULTSET_LIMIT = 1000;
+
+ public static double PERCENT_OF_SKOSSET = 1.0; // the 70/30 strategy was
+
+ // abandoned
+
+ public static double NEGFACTOR = 1.0; // size of randomly choosen negative
+
+ // examples compared to positives
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ initLogger();
+ logger.info("Start");
+
+ // SETUP cache and sparqltasks
+ cache = Cache.getPersistentCache();
+
+ if (local) {
+ // url = "http://139.18.2.37:8890/sparql";
+ sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
+ .getEndpointLOCALDBpedia());
+ } else {
+ // url = "http://dbpedia.openlinksw.com:8890/sparql";
+ sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
+ .getEndpointDBpedia());
+ }
+
+ String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
+ // target =
+ // "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners";
+
+ WikipediaCategoryTasks s = new WikipediaCategoryTasks(sparqlTasks);
+ // TODO Optimize
+ s.calculateDefinitelyWrongIndividuals(target, PERCENT_OF_SKOSSET,
+ NEGFACTOR, SPARQL_RESULTSET_LIMIT);
+
+ logger.info("Found " + s.getDefinitelyWrongIndividuals().size()
+ + " incorrect individuals");
+ logger.debug("incorrect Individuals: "
+ + s.getDefinitelyWrongIndividuals());
+ logger.info("reevaluating " + s.getConceptresults().size()
+ + " found Concepts");
+ logger
+ .info("END OF PHASE 1 **********************************************");
+
+ s.reevaluateAndRelearn();
+ List<EvaluatedDescription> newEval = s.getConceptresults();
+ printEvaluatedDescriptionCollection(5, newEval);
+
+ System.out.println("Finished");
+ JamonMonitorLogger.printAllSortedByLabel();
+
+ }
+
+ private static void initLogger() {
+
+ SimpleLayout layout = new SimpleLayout();
+ // create logger (a simple logger which outputs
+ // its messages to the console)
+ FileAppender fileAppender = null;
+ try {
+ fileAppender = new FileAppender(layout, "log/progress/skos"
+ + ConceptSelector.time() + ".txt", false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ logger.removeAllAppenders();
+ logger.addAppender(consoleAppender);
+ logger.addAppender(fileAppender);
+ logger.setLevel(Level.DEBUG);
+ Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
+
+ Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO);
+ Logger.getLogger(Cache.class).setLevel(Level.INFO);
+ Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel(
+ Level.INFO);
+ Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel(
+ Level.INFO);
+ }
+
+ public static void printEvaluatedDescriptionCollection(int howMany,
+ Collection<EvaluatedDescription> c) {
+ int x = 0;
+ Set<Individual> first = null;
+ Set<Individual> tmp = new HashSet<Individual>();
+ for (EvaluatedDescription ed : c) {
+ if (x == 0) {
+ first = ed.getNotCoveredPositives();
+ }
+ if (x >= howMany) {
+ x++;
+ break;
+ }
+
+ tmp.addAll(ed.getNotCoveredPositives());
+ tmp.removeAll(first);
+ logger.debug("*************************");
+ logger.debug("Concept: " + ed);
+ logger.debug("accuracy: " + ed.getAccuracy());
+ logger.debug("Not Covered compared to First: " + tmp);
+ logger.debug(ed.getScore());
+ tmp.clear();
+
+ }
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -0,0 +1,200 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.scripts.improveWikipedia;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.log4j.Logger;
+import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.kb.sparql.SPARQLTasks;
+import org.dllearner.utilities.Helper;
+import org.dllearner.utilities.owl.EvaluatedDescriptionComparator;
+
+/**
+ * @author Sebastian Hellmann
+ *
+ * The EvaluatedDescriptions from a fragment are
+ * validated against the SPARQLendpoint.
+ * There are different strategies, see the methods;
+ */
+public class ConceptSPARQLReEvaluator {
+
+ private static Logger logger = Logger
+ .getLogger(ConceptSPARQLReEvaluator.class);
+
+ List<EvaluatedDescription> descToBeReevaluated;
+
+ SPARQLTasks sparqlTasks;
+
+ int sparqlResultLimit = 1000;
+
+ int depthOfRDFS = 1;
+
+ public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks,
+ List<EvaluatedDescription> descToBeReevaluated) {
+ this.descToBeReevaluated = descToBeReevaluated;
+ this.sparqlTasks = sparqlTasks;
+ }
+
+ public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks,
+ List<EvaluatedDescription> descToBeReevaluated, int depthOfRDFS,
+ int sparqlResultLimit) {
+ this(sparqlTasks, descToBeReevaluated);
+ this.depthOfRDFS = depthOfRDFS;
+ this.sparqlResultLimit = sparqlResultLimit;
+ }
+
+
+ public List<EvaluatedDescription> reevaluateConceptsByDataCoverage(
+ SortedSet<String> positiveSet, int maxNrOfConcepts) {
+ List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet);
+ List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>();
+
+ while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) {
+ returnSet.add(tmp.remove(0));
+ }
+
+ return returnSet;
+ }
+
+ /**
+ * Accuracy is calculated as correct positive classified over (correct
+ * positive classified + incorrect negative classified) "How many are
+ * correctly positive classified?" e.g. 50 individuals of a 60-individual
+ * Category (50/60)
+ *
+ * @param positiveSet
+ * @return
+ */
+ public List<EvaluatedDescription> reevaluateConceptsByDataCoverage(
+ SortedSet<String> positiveSet) {
+
+ SortedSet<EvaluatedDescription> returnSet = new TreeSet<EvaluatedDescription>(
+ new EvaluatedDescriptionComparator());
+
+ SortedSet<String> instances = new TreeSet<String>();
+ SortedSet<String> PosAsPos = new TreeSet<String>();
+ SortedSet<String> PosAsNeg = new TreeSet<String>();
+
+ // NegAsPos doesnt exist, because they are supposed to be possible
+ // candidates
+ SortedSet<Individual> NegAsPos = new TreeSet<Individual>();
+ // NegAsNeg doesnt exist, because all
+ SortedSet<Individual> NegAsNeg = new TreeSet<Individual>();
+
+ for (EvaluatedDescription ed : descToBeReevaluated) {
+ instances = retrieveInstances(ed);
+
+ // PosAsPos
+ PosAsPos.addAll(positiveSet);
+ PosAsPos.retainAll(instances);
+
+ // PosAsNeg
+ PosAsNeg.addAll(positiveSet);
+ PosAsNeg.removeAll(PosAsPos);
+
+ returnSet.add(new EvaluatedDescription(ed.getDescription(), Helper
+ .getIndividualSet(PosAsPos), Helper
+ .getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg));
+
+ PosAsPos.clear();
+ PosAsNeg.clear();
+
+ }
+
+ return new ArrayList<EvaluatedDescription>(returnSet);
+
+ }
+
+ public List<EvaluatedDescription> reevaluateConceptsByLowestRecall(
+ SortedSet<String> positiveSet, int maxNrOfConcepts) {
+ List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet);
+ List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>();
+
+ while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) {
+ returnSet.add(tmp.remove(0));
+ }
+
+ return returnSet;
+ }
+
+ /**
+ * Accuracy is calculated as correct positive classified over all retrieved
+ * e.g. 50 correct out of 400 retrieved (50/400)
+ *
+ * @param positiveSet
+ * @return
+ */
+ public List<EvaluatedDescription> reevaluateConceptsByLowestRecall(
+ SortedSet<String> positiveSet) {
+ logger.info("reevaluating by lowest recall "
+ + descToBeReevaluated.size() + " concepts");
+ SortedSet<EvaluatedDescription> returnSet = new TreeSet<EvaluatedDescription>(
+ new EvaluatedDescriptionComparator());
+
+ SortedSet<String> instances = new TreeSet<String>();
+
+ SortedSet<String> PosAsPos = new TreeSet<String>();
+ SortedSet<String> PosAsNeg = new TreeSet<String>();
+
+ SortedSet<Individual> NegAsPos = new TreeSet<Individual>();
+
+ SortedSet<Individual> NegAsNeg = new TreeSet<Individual>();
+
+ // elements are immediately removed from the list to save memory
+ while (!descToBeReevaluated.isEmpty()) {
+ EvaluatedDescription ed = descToBeReevaluated.remove(0);
+
+ instances = retrieveInstances(ed);
+
+ // PosAsPos
+ PosAsPos.addAll(positiveSet);
+ PosAsPos.retainAll(instances);
+
+ // PosAsNeg
+ PosAsNeg.addAll(instances);
+ PosAsNeg.removeAll(PosAsPos);
+
+ returnSet.add(new EvaluatedDescription(ed.getDescription(), Helper
+ .getIndividualSet(PosAsPos), Helper
+ .getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg));
+
+ PosAsPos.clear();
+ PosAsNeg.clear();
+
+ }
+ logger.info("finished reevaluating by lowest recall :"
+ + returnSet.size() + " concepts");
+ return new ArrayList<EvaluatedDescription>(returnSet);
+
+ }
+
+ private SortedSet<String> retrieveInstances(EvaluatedDescription ed) {
+ String kbsyntax = ed.getDescription().toKBSyntaxString();
+ return sparqlTasks
+ .retrieveInstancesForClassDescriptionIncludingSubclasses(
+ kbsyntax, sparqlResultLimit, depthOfRDFS);
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -0,0 +1,130 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.scripts.improveWikipedia;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.LearningAlgorithm;
+import org.dllearner.utilities.Files;
+
+/**
+ * This is a simple class, it might be worked into other classes later.
+ * filters concepts and records some results
+ *
+ * @author Sebastian Hellmann
+ *
+ */
+public class ConceptSelector {
+
+ private static final long WASH = 1216800000000L;
+
+ List<EvaluatedDescription> concepts;
+
+ public ConceptSelector(LearningAlgorithm la) {
+ super();
+ this.concepts = la.getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, 0.0, true);
+ this.recordConceptClasses();
+
+ }
+
+
+ public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts) {
+ super();
+ this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts);
+
+ }
+
+ public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts, double acctreshold) {
+ super();
+ this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts, acctreshold, true);
+ this.recordConceptClasses();
+ }
+
+ public List<EvaluatedDescription> getConceptsWithoutOR(){
+ return getConceptsNotContainingString("OR");
+ }
+
+ public List<EvaluatedDescription> getConceptsNotContainingString(String filterString, int limitSize){
+ List<EvaluatedDescription> tmp = getConceptsNotContainingString(filterString);
+ List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>();
+
+ while ((!tmp.isEmpty()) && (result.size() <= limitSize)) {
+ result.add(tmp.remove(0));
+ }
+ return result;
+ }
+
+
+ public List<EvaluatedDescription> getConceptsNotContainingString(String filterString){
+
+ List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>();
+ for (EvaluatedDescription description : concepts) {
+ if (!description.toString().contains(filterString)) {
+ result.add(description);
+ }
+
+ }
+ return result;
+ }
+
+
+
+
+ public void recordConceptClasses() {
+ StringBuffer result =new StringBuffer();
+ StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n");
+ StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n");
+ int result1count = 1;
+ int result2count = 1;
+
+
+ int x = 0;
+ for (EvaluatedDescription description : concepts) {
+ if (x < 50) {
+ x++;
+ result.append(description + "\n");
+ }
+
+ if (!description.toString().contains("Entity")) {
+ result1.append(description + "\n");
+ result1count++;
+ }
+ if (!description.toString().contains("OR")) {
+ result2.append(description + "\n");
+ result2count++;
+ }
+ }
+ result.append("full size: " + concepts.size());
+ result.append(result1.toString() + " size: " + result1count + "\n");
+ result.append(result2.toString() + " size: " + result2count + "\n");
+
+ Files.createFile(new File("results/descriptions/concepts" + time()
+ + ".txt"), result.toString());
+ }
+
+ public static String time() {
+ return ("" + (System.currentTimeMillis() - WASH)).substring(0, 7);
+
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-07-31 16:27:38 UTC (rev 1042)
@@ -0,0 +1,251 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.scripts.improveWikipedia;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.log4j.Logger;
+import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.LearningAlgorithm;
+import org.dllearner.kb.sparql.SPARQLTasks;
+import org.dllearner.scripts.WikipediaCategoryCleaner;
+import org.dllearner.utilities.Helper;
+import org.dllearner.utilities.datastructures.SetManipulation;
+import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
+import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
+import org.dllearner.utilities.learn.LearnSPARQLConfiguration;
+import org.dllearner.utilities.learn.LearnSparql;
+
+public class WikipediaCategoryTasks {
+
+ private static Logger logger = Logger
+ .getLogger(WikipediaCategoryTasks.class);
+
+ private static final boolean STABLE = true; // used for developing, same
+
+ // negExamples not random
+
+ private static final int MAXIMUM_NUMBER_OF_CONCEPTS_KEPT = Integer.MAX_VALUE;
+
+ private static final double ACCTRESHOLD = 0.0;
+
+ private SPARQLTasks sparqlTasks;
+
+ private SortedSet<String> posExamples = new TreeSet<String>();
+
+ private SortedSet<String> fullPositiveSet = new TreeSet<String>();
+
+ // private SortedSet<String> fullPosSetWithoutPosExamples = new
+ // TreeSet<String>();
+
+ private SortedSet<String> negExamples = new TreeSet<String>();
+
+ private SortedSet<String> definitelyWrongIndividuals = new TreeSet<String>();
+
+ private List<EvaluatedDescription> conceptresults = new ArrayList<EvaluatedDescription>();
+
+ public WikipediaCategoryTasks(SPARQLTasks sparqlTasks) {
+ this.sparqlTasks = sparqlTasks;
+ }
+
+ /**
+ * @param SKOSConcept
+ * @param percentOfSKOSSet
+ * @param negfactor
+ * @param sparqlResultLimit
+ */
+ public void calculateDefinitelyWrongIndividuals(String SKOSConcept,
+ double percentOfSKOSSet, double negfactor, int sparqlResultLimit) {
+
+ makeExamples(SKOSConcept, percentOfSKOSSet, negfactor,
+ sparqlResultLimit);
+
+ LearnSparql learner = new LearnSparql(
+ prepareConfigurationToFindWrongIndividuals());
+ LearningAlgorithm la = null;
+ try {
+ la = learner.learn(posExamples, negExamples);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // TODO maybe not smart here
+ ConceptSelector cs = new ConceptSelector(la,
+ MAXIMUM_NUMBER_OF_CONCEPTS_KEPT, ACCTRESHOLD);
+ conceptresults = cs.getConceptsNotContainingString("Entity",
+ MAXIMUM_NUMBER_OF_CONCEPTS_KEPT);
+ if (conceptresults.size() == 0) {
+ logger.warn("NO GOOD CONCEPTS FOUND");
+ }
+
+ definitelyWrongIndividuals = Helper.getStringSet(conceptresults.get(0)
+ .getNotCoveredPositives());
+
+ // clean the examples
+ posExamples.removeAll(definitelyWrongIndividuals);
+ fullPositiveSet.removeAll(definitelyWrongIndividuals);
+ // fullPosSetWithoutPosExamples.removeAll(definitelyWrongIndividuals);
+
+ logger.trace("posExamples" + posExamples.size());
+ logger.trace("fullPositives" + fullPositiveSet.size());
+
+ negExamples.clear();
+
+ }
+
+ public void reevaluateAndRelearn() {
+
+ ConceptSPARQLReEvaluator csparql = new ConceptSPARQLReEvaluator(
+ sparqlTasks, conceptresults);
+ List<EvaluatedDescription> reEvaluatedDesc;
+
+ // TODO Optimize here
+ reEvaluatedDesc = csparql.reevaluateConceptsByLowestRecall(
+ fullPositiveSet, 1);
+
+ // TODO add check if it is correct
+ WikipediaCategoryCleaner.printEvaluatedDescriptionCollection(10,
+ reEvaluatedDesc);
+ EvaluatedDescription newDesc = reEvaluatedDesc.get(0);
+ logger.info("Best concept: " + newDesc.getDescription());
+
+ negExamples.clear();
+ negExamples.addAll(Helper.getStringSet(newDesc.getCoveredPositives()));
+ negExamples.addAll(Helper
+ .getStringSet(newDesc.getNotCoveredPositives()));
+ negExamples....
[truncated message content] |
|
From: <jen...@us...> - 2008-07-31 16:33:38
|
Revision: 1043
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1043&view=rev
Author: jenslehmann
Date: 2008-07-31 16:33:29 +0000 (Thu, 31 Jul 2008)
Log Message:
-----------
- EL downward refinement operator started
- cleanup
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
trunk/src/dl-learner/org/dllearner/cli/Start.java
trunk/src/dl-learner/org/dllearner/core/ReasoningService.java
trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java
trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java
trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java
trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java
trunk/src/dl-learner/org/dllearner/utilities/Helper.java
trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java
trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -207,7 +207,7 @@
if(length==1) {
generatedDefinitions.get(1).add(new Thing());
generatedDefinitions.get(1).add(new Nothing());
- for(NamedClass atomicConcept : rs.getAtomicConcepts()) {
+ for(NamedClass atomicConcept : rs.getNamedClasses()) {
generatedDefinitions.get(1).add(atomicConcept);
}
}
@@ -265,7 +265,7 @@
// EXISTS and ALL
for(Description childNode : generatedDefinitions.get(length-2)) {
- for(ObjectProperty atomicRole : rs.getAtomicRoles()) {
+ for(ObjectProperty atomicRole : rs.getObjectProperties()) {
Description root1 = new ObjectSomeRestriction(atomicRole,childNode);
generatedDefinitions.get(length).add(root1);
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -61,7 +61,7 @@
// to simplify equivalence checks and minimisation, we
// attach a simulation relation to the description tree
- private Simulation simulation;
+// private Simulation simulation;
/**
* Constructs an empty EL description tree with the empty set
@@ -69,7 +69,7 @@
*/
public ELDescriptionTree() {
this(new TreeSet<NamedClass>(), new LinkedList<Edge>());
- simulation = new Simulation();
+// simulation = new Simulation();
}
/**
@@ -189,4 +189,10 @@
return level;
}
+ @Override
+ public ELDescriptionTree clone() {
+ // TODO implement efficient tree cloning
+ return null;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -492,7 +492,7 @@
private static Description pickTerminalSymbol(LearningProblem learningProblem, ReasoningService rs, boolean useADC) {
// FlatABox abox = FlatABox.getInstance();
int nr;
- int nrOfConcepts = rs.getAtomicConcepts().size();
+ int nrOfConcepts = rs.getNamedClasses().size();
// ein Blattknoten kann folgendes sein:
// Top, Bottom, Konzept => alles am Besten gleichwahrscheinlich
@@ -631,7 +631,7 @@
private static Description createFullRandomTree(LearningProblem learningProblem, ReasoningService rs, int depth, boolean useADC) {
// FlatABox abox = FlatABox.getInstance();
- int numberOfRoles = rs.getAtomicRoles().size(); // abox.roles.size();
+ int numberOfRoles = rs.getObjectProperties().size(); // abox.roles.size();
if (depth > 1) {
int nr = rand.nextInt(3+2*numberOfRoles);
@@ -725,8 +725,8 @@
*/
// FlatABox abox = FlatABox.getInstance();
- int numberOfConcepts = rs.getAtomicConcepts().size();
- int numberOfRoles = rs.getAtomicRoles().size();
+ int numberOfConcepts = rs.getNamedClasses().size();
+ int numberOfRoles = rs.getObjectProperties().size();
// TODO: ev. größere Wahrscheinlichkeit für Konjunktion/Disjunktion (?),
// mit größerer Konzept-, und Rollenanzahl kommen die sonst kaum noch vor
int numberOfAlphabetSymbols = numberOfConcepts + 2*numberOfRoles + 5; //7;// 5;
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -316,9 +316,9 @@
usedRoles = allowedRoles;
} else if(ignoredRoles != null) {
Helper.checkRoles(rs, ignoredRoles);
- usedRoles = Helper.difference(rs.getAtomicRoles(), ignoredRoles);
+ usedRoles = Helper.difference(rs.getObjectProperties(), ignoredRoles);
} else {
- usedRoles = rs.getAtomicRoles();
+ usedRoles = rs.getObjectProperties();
}
// prepare subsumption and role hierarchies, because they are needed
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -357,9 +357,9 @@
usedRoles = allowedRoles;
} else if(ignoredRoles != null) {
Helper.checkRoles(rs, ignoredRoles);
- usedRoles = Helper.difference(rs.getAtomicRoles(), ignoredRoles);
+ usedRoles = Helper.difference(rs.getObjectProperties(), ignoredRoles);
} else {
- usedRoles = rs.getAtomicRoles();
+ usedRoles = rs.getObjectProperties();
}
// prepare subsumption and role hierarchies, because they are needed
Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -512,25 +512,25 @@
}
} else if (name.equals("showConcepts")) {
if (cliOption.getStringValue().equals("true")) {
- int stringLength = rs.getAtomicConcepts().toString().length();
+ int stringLength = rs.getNamedClasses().toString().length();
if (stringLength > maxLineLength) {
- System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: ");
- for (NamedClass ac : rs.getAtomicConcepts())
+ System.out.println("concepts[" + rs.getNamedClasses().size() + "]: ");
+ for (NamedClass ac : rs.getNamedClasses())
System.out.println(" " + ac);
} else
- System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: "
- + rs.getAtomicConcepts());
+ System.out.println("concepts[" + rs.getNamedClasses().size() + "]: "
+ + rs.getNamedClasses());
}
} else if (name.equals("showRoles")) {
if (cliOption.getStringValue().equals("true")) {
- int stringLength = rs.getAtomicRoles().toString().length();
+ int stringLength = rs.getObjectProperties().toString().length();
if (stringLength > maxLineLength) {
- System.out.println("roles[" + rs.getAtomicRoles().size() + "]: ");
- for (ObjectProperty r : rs.getAtomicRoles())
+ System.out.println("roles[" + rs.getObjectProperties().size() + "]: ");
+ for (ObjectProperty r : rs.getObjectProperties())
System.out.println(" " + r);
} else
- System.out.println("roles[" + rs.getAtomicRoles().size() + "]: "
- + rs.getAtomicRoles());
+ System.out.println("roles[" + rs.getObjectProperties().size() + "]: "
+ + rs.getObjectProperties());
}
} else if (name.equals("showSubsumptionHierarchy")) {
if (cliOption.getStringValue().equals("true")) {
@@ -700,9 +700,9 @@
// (note that removeAll currently gives a different
// result here, because the comparator of the argument
// is used)
- for (NamedClass ac : rs.getAtomicConcepts())
+ for (NamedClass ac : rs.getNamedClasses())
occurringConcepts.remove(ac);
- for (ObjectProperty ar : rs.getAtomicRoles())
+ for (ObjectProperty ar : rs.getObjectProperties())
occurringRoles.remove(ar);
boolean nonExistingConstructs = false;
Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -368,7 +368,7 @@
}
public void prepareSubsumptionHierarchy() {
- reasoner.prepareSubsumptionHierarchy(getAtomicConcepts());
+ reasoner.prepareSubsumptionHierarchy(getNamedClasses());
}
public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) {
@@ -386,7 +386,7 @@
}
public void prepareRoleHierarchy() {
- prepareRoleHierarchy(getAtomicRoles());
+ prepareRoleHierarchy(getObjectProperties());
}
public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) {
@@ -499,11 +499,11 @@
}
}
- public Set<NamedClass> getAtomicConcepts() {
+ public Set<NamedClass> getNamedClasses() {
return reasoner.getAtomicConcepts();
}
- public Set<ObjectProperty> getAtomicRoles() {
+ public Set<ObjectProperty> getObjectProperties() {
return reasoner.getAtomicRoles();
}
@@ -589,13 +589,13 @@
public List<NamedClass> getAtomicConceptsList() {
if(atomicConceptsList == null)
- atomicConceptsList = new LinkedList<NamedClass>(getAtomicConcepts());
+ atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses());
return atomicConceptsList;
}
public List<ObjectProperty> getAtomicRolesList() {
if(atomicRolesList == null)
- atomicRolesList = new LinkedList<ObjectProperty>(getAtomicRoles());
+ atomicRolesList = new LinkedList<ObjectProperty>(getObjectProperties());
return atomicRolesList;
}
Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -233,7 +233,7 @@
|| configOption.getName().equalsIgnoreCase("ignoredConcepts")) {
// fill lists
Set<NamedClass> atomicsSet = config.getReasoningService()
- .getAtomicConcepts();
+ .getNamedClasses();
LinkedList<NamedClass> atomicConcepts = new LinkedList<NamedClass>(
atomicsSet);
for (NamedClass ind : atomicConcepts)
@@ -244,7 +244,7 @@
|| configOption.getName().equalsIgnoreCase("ignoredRoles")) {
// fill lists
Set<ObjectProperty> atomicsSet = config.getReasoningService()
- .getAtomicRoles();
+ .getObjectProperties();
LinkedList<ObjectProperty> atomicRoles = new LinkedList<ObjectProperty>(
atomicsSet);
for (ObjectProperty ind : atomicRoles)
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -20,10 +20,18 @@
package org.dllearner.refinementoperators;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import org.dllearner.algorithms.el.ELDescriptionTree;
+import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.core.owl.ObjectPropertyHierarchy;
+import org.dllearner.core.owl.SubsumptionHierarchy;
+import org.dllearner.core.owl.Thing;
/**
* EL downward refinement operator constructed by Jens Lehmann
@@ -43,13 +51,50 @@
* @author Jens Lehmann
*
*/
+@SuppressWarnings("unused")
public class ELDown extends RefinementOperatorAdapter {
+// private static Logger logger = Logger.getLogger(ELDown.class);
+
+ private ReasoningService rs;
+
+ // hierarchies
+ private SubsumptionHierarchy subsumptionHierarchy;
+ private ObjectPropertyHierarchy opHierarchy;
+
+ // domains and ranges
+ private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>();
+ private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>();
+
+ // app_A set of applicable properties for a given class
+ private Map<Description, Set<ObjectProperty>> app = new TreeMap<Description, Set<ObjectProperty>>();
+
+ // most general applicable properties
+ private Map<Description,Set<ObjectProperty>> mgr = new TreeMap<Description,Set<ObjectProperty>>();
+
+ // utility class
+ private Utility utility;
+
+ public ELDown(ReasoningService rs) {
+ utility = new Utility(rs);
+ subsumptionHierarchy = rs.getSubsumptionHierarchy();
+ opHierarchy = rs.getRoleHierarchy();
+
+ // 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));
+ }
+ }
+
/* (non-Javadoc)
* @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description)
*/
@Override
public Set<Description> refine(Description concept) {
+ // TODO according to the specification, we need to minimise
+ // the tree (not yet implemented)
ELDescriptionTree tree = new ELDescriptionTree(concept);
Set<ELDescriptionTree> refinementTrees = refine(tree);
Set<Description> refinements = new HashSet<Description>();
@@ -68,7 +113,41 @@
* @return Set of refined EL description trees.
*/
public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
- return null;
+ return refine(tree, new Thing());
}
+
+ private Set<ELDescriptionTree> refine(ELDescriptionTree tree, Description index) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ // option 1: label extension
+
+ // option 2: label refinement
+ // loop through all classes in label
+ for(NamedClass nc : tree.getLabel()) {
+ // find all more special classes for the given label
+ for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) {
+ // create refinements by replacing class
+ ELDescriptionTree tmp = tree.clone();
+ // TODO replace class in label
+ }
+ }
+
+ // option 3: new edge
+
+ // option 4: edge refinement
+
+ // option 5: child refinement
+
+ return refinements;
+ }
+// private void computeMg(Description index) {
+// // compute the applicable properties if this has not been done yet
+// if(app.get(index) == null)
+// app.put(index, utility.computeApplicableObjectProperties(index));
+//
+// mgr.put(index, new TreeSet<ObjectProperty>());
+//
+//
+// }
+
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -69,7 +69,7 @@
topSet.add(new Negation(c));
// EXISTS r.TOP und ALL r.TOP für alle r
- for(ObjectProperty r : reasoningService.getAtomicRoles()) {
+ for(ObjectProperty r : reasoningService.getObjectProperties()) {
topSet.add(new ObjectAllRestriction(r, new Thing()));
topSet.add(new ObjectSomeRestriction(r, new Thing()));
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -57,7 +57,7 @@
bottomSet.add(new Negation(c));
// EXISTS r.BOTTOM und ALL r.BOTTOM für alle r
- for(ObjectProperty r : reasoningService.getAtomicRoles()) {
+ for(ObjectProperty r : reasoningService.getObjectProperties()) {
bottomSet.add(new ObjectAllRestriction(r, new Nothing()));
bottomSet.add(new ObjectSomeRestriction(r, new Nothing()));
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -70,6 +70,11 @@
* domain/range restrictions. Furthermore, it makes use of disjoint
* classes in the knowledge base.
*
+ * TODO Some of the code has moved to {@link Utility} in a modified
+ * form to make it accessible for implementations of other refinement
+ * operators. These utility methods may be completed and carefully
+ * integrated back later.
+ *
* @author Jens Lehmann
*
*/
@@ -185,7 +190,7 @@
// query reasoner for domains and ranges
// (because they are used often in the operator)
- for(ObjectProperty op : rs.getAtomicRoles()) {
+ for(ObjectProperty op : rs.getObjectProperties()) {
opDomains.put(op, rs.getDomain(op));
opRanges.put(op, rs.getRange(op));
}
@@ -201,7 +206,7 @@
// determine the maximum number of fillers for each role
// (up to a specified cardinality maximum)
if(useCardinalityRestrictions) {
- for(ObjectProperty op : rs.getAtomicRoles()) {
+ for(ObjectProperty op : rs.getObjectProperties()) {
int maxFillers = 0;
Map<Individual,SortedSet<Individual>> opMembers = rs.getRoleMembers(op);
for(SortedSet<Individual> inds : opMembers.values()) {
@@ -978,7 +983,7 @@
// computes the set of applicable properties for a given class
private void computeApp(NamedClass domain) {
// object properties
- Set<ObjectProperty> mostGeneral = rs.getAtomicRoles();
+ Set<ObjectProperty> mostGeneral = rs.getObjectProperties();
Set<ObjectProperty> applicableRoles = new TreeSet<ObjectProperty>();
for(ObjectProperty role : mostGeneral) {
// TODO: currently we just rely on named classes as roles,
Added: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -0,0 +1,145 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.refinementoperators;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.dllearner.core.ReasoningService;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.Nothing;
+import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.utilities.Helper;
+import org.dllearner.utilities.owl.ConceptComparator;
+
+/**
+ * Utility methods for constructing refinement operators.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public final class Utility {
+
+ private ReasoningService rs;
+
+ // concept comparator
+ private ConceptComparator conceptComparator = new ConceptComparator();
+
+ // specifies whether to do real disjoint tests or check that
+ // two named classes do not have common instances
+ private boolean instanceBasedDisjoints = true;
+
+ // cache for reasoner queries
+ private Map<Description,Map<Description,Boolean>> cachedDisjoints = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator);
+
+
+ public Utility(ReasoningService rs) {
+ this.rs = rs;
+ }
+
+ /**
+ * Compute the set of applicable object properties for a
+ * given description.
+ *
+ * @param index The index is a description which determines
+ * which of the properties are applicable. Exactly those which
+ * where the index and property domain are not disjoint are
+ * applicable, where disjoint is defined by {@link #isDisjoint(Description, Description)}.
+ *
+ */
+ public SortedSet<ObjectProperty> computeApplicableObjectProperties(Description index) {
+ Set<ObjectProperty> objectProperties = rs.getObjectProperties();
+ SortedSet<ObjectProperty> applicableObjectProperties = new TreeSet<ObjectProperty>();
+ for(ObjectProperty op : objectProperties) {
+ Description domain = rs.getDomain(op);
+ if(!isDisjoint(index,domain))
+ applicableObjectProperties.add(op);
+ }
+ return applicableObjectProperties;
+ }
+
+ /**
+ * Given a set of applicable object properties, this method returns
+ * the most general ones, i.e. those where more general ones do not
+ * exist in the set of applicable properties. Due to the definition
+ * of "applicable", the returned set is just the intersection of the most
+ * general object properties and the applicable properties. (A non-applicable
+ * property cannot have applicable subproperties, because subproperties
+ * can only restrict, but not broaden their domain.)
+ *
+ * @param rs The underlying reasoning service.
+ * @param applicableObjectProperties The set of applicable properties.
+ * @return The most general applicable properties.
+ */
+ public SortedSet<ObjectProperty> computeMgr(SortedSet<ObjectProperty> applicableObjectProperties) {
+ return Helper.intersection(rs.getMostGeneralRoles(), applicableObjectProperties);
+ }
+
+ private boolean isDisjoint(Description d1, Description d2) {
+ // check whether we have cached this query
+ Map<Description,Boolean> tmp = cachedDisjoints.get(d1);
+ Boolean tmp2 = null;
+ if(tmp != null)
+ tmp2 = tmp.get(d2);
+
+ if(tmp2==null) {
+ Boolean result;
+ if(instanceBasedDisjoints) {
+ result = isDisjointInstanceBased(d1,d2);
+ } else {
+ Description d = new Intersection(d1, d2);
+ result = rs.subsumes(new Nothing(), d);
+ }
+ // add the result to the cache (we add it twice such that
+ // the order of access does not matter)
+
+ // create new entries if necessary
+ Map<Description,Boolean> map1 = new TreeMap<Description,Boolean>(conceptComparator);
+ Map<Description,Boolean> map2 = new TreeMap<Description,Boolean>(conceptComparator);
+ if(tmp == null)
+ cachedDisjoints.put(d1, map1);
+ if(!cachedDisjoints.containsKey(d2))
+ cachedDisjoints.put(d2, map2);
+
+ // add result symmetrically in the description matrix
+ cachedDisjoints.get(d1).put(d2, result);
+ cachedDisjoints.get(d2).put(d1, result);
+ return result;
+ } else {
+ return tmp2;
+ }
+ }
+
+ private boolean isDisjointInstanceBased(Description d1, Description d2) {
+ SortedSet<Individual> d1Instances = rs.retrieval(d1);
+ SortedSet<Individual> d2Instances = rs.retrieval(d2);
+ for(Individual d1Instance : d1Instances) {
+ if(d2Instances.contains(d1Instance))
+ return false;
+ }
+ return true;
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -497,7 +497,7 @@
@WebMethod
public String[] getAtomicConcepts(int id) throws ClientNotKnownException {
- Set<NamedClass> atomicConcepts = getState(id).getReasoningService().getAtomicConcepts();
+ Set<NamedClass> atomicConcepts = getState(id).getReasoningService().getNamedClasses();
return Datastructures.sortedSet2StringListConcepts(atomicConcepts);
}
@@ -525,7 +525,7 @@
@WebMethod
public String[] getAtomicRoles(int id) throws ClientNotKnownException {
ClientState state = getState(id);
- Set<ObjectProperty> roles = state.getReasoningService().getAtomicRoles();
+ Set<ObjectProperty> roles = state.getReasoningService().getObjectProperties();
return Datastructures.sortedSet2StringListRoles(roles);
}
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -111,7 +111,7 @@
public Set<NamedClass> doInBackground()
{
getWizardModel().getOre().detectReasoner();
- Set<NamedClass> ind = getWizardModel().getOre().getReasoningService().getAtomicConcepts();
+ Set<NamedClass> ind = getWizardModel().getOre().getReasoningService().getNamedClasses();
ClassPanelOWLDescriptor nextPanel = (ClassPanelOWLDescriptor)getWizardModel().getPanelHashMap().get(getNextPanelDescriptor());
nextPanel.panel3.getModel().clear();
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -548,7 +548,7 @@
public Set<NamedClass> getpossibleClassesMoveTo(Individual ind){
Set<NamedClass> moveClasses = new HashSet<NamedClass>();
- for(NamedClass nc : rs.getAtomicConcepts())
+ for(NamedClass nc : rs.getNamedClasses())
if(!rs.instanceCheck(nc, ind))
moveClasses.add(nc);
@@ -558,7 +558,7 @@
public Set<NamedClass> getpossibleClassesMoveFrom(Individual ind){
Set<NamedClass> moveClasses = new HashSet<NamedClass>();
- for(NamedClass nc : rs.getAtomicConcepts()){
+ for(NamedClass nc : rs.getNamedClasses()){
if(rs.instanceCheck(nc, ind))
moveClasses.add(nc);
}
Modified: trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -68,7 +68,7 @@
Object nextPanelDescriptor = descriptor.getNextPanelDescriptor();
- //TODO nochmal \xFCberdenken
+ //TODO nochmal �berdenken
if(nextPanelDescriptor.equals("CLASS_CHOOSE_OWL_PANEL")){
((ClassPanelOWLDescriptor)model.getPanelHashMap().get(nextPanelDescriptor)).panel3.getModel().clear();
new ConceptRetriever(nextPanelDescriptor).execute();
@@ -227,7 +227,7 @@
wizard.getModel().getOre().detectReasoner();
Set<NamedClass> ind = wizard.getModel().getOre()
- .getReasoningService().getAtomicConcepts();
+ .getReasoningService().getNamedClasses();
return ind;
}
Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -452,7 +452,7 @@
SortedSet<Individual> individuals = null;
if(!aktuell.getRootObject().toString().equals("Thing"))
{
- for(Iterator<NamedClass> i = rs.getAtomicConcepts().iterator(); i.hasNext();)
+ for(Iterator<NamedClass> i = rs.getNamedClasses().iterator(); i.hasNext();)
{
if(individuals==null)
{
Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -471,14 +471,14 @@
public static Set<NamedClass> computeConcepts(ReasoningService rs) {
// if there is no ignore or allowed list, we just ignore the concepts
// of uninteresting namespaces
- Set<NamedClass> concepts = rs.getAtomicConcepts();
+ Set<NamedClass> concepts = rs.getNamedClasses();
Helper.removeUninterestingConcepts(concepts);
return concepts;
}
// concepts case 2: ignore list
public static Set<NamedClass> computeConceptsUsingIgnoreList(ReasoningService rs, Set<NamedClass> ignoredConcepts) {
- Set<NamedClass> concepts = rs.getAtomicConcepts();
+ Set<NamedClass> concepts = rs.getNamedClasses();
Helper.removeUninterestingConcepts(concepts);
for (NamedClass ac : ignoredConcepts) {
boolean success = concepts.remove(ac);
@@ -512,7 +512,7 @@
*/
//
public static ObjectProperty checkRoles(ReasoningService rs, Set<ObjectProperty> roles) {
- Set<ObjectProperty> existingRoles = rs.getAtomicRoles();
+ Set<ObjectProperty> existingRoles = rs.getObjectProperties();
for (ObjectProperty ar : roles) {
if(!existingRoles.contains(ar))
return ar;
@@ -528,7 +528,7 @@
*/
//
public static NamedClass checkConcepts(ReasoningService rs, Set<NamedClass> concepts) {
- Set<NamedClass> existingConcepts = rs.getAtomicConcepts();
+ Set<NamedClass> existingConcepts = rs.getNamedClasses();
for (NamedClass ar : concepts) {
if(!existingConcepts.contains(ar))
return ar;
@@ -542,7 +542,7 @@
long dematStartTime = System.currentTimeMillis();
FlatABox aBox = new FlatABox(); // FlatABox.getInstance();
- for (NamedClass atomicConcept : rs.getAtomicConcepts()) {
+ for (NamedClass atomicConcept : rs.getNamedClasses()) {
aBox.atomicConceptsPos.put(atomicConcept.getName(), getStringSet(rs
.retrieval(atomicConcept)));
Negation negatedAtomicConcept = new Negation(atomicConcept);
@@ -551,7 +551,7 @@
aBox.concepts.add(atomicConcept.getName());
}
- for (ObjectProperty atomicRole : rs.getAtomicRoles()) {
+ for (ObjectProperty atomicRole : rs.getObjectProperties()) {
aBox.rolesPos.put(atomicRole.getName(), getStringMap(rs.getRoleMembers(atomicRole)));
aBox.roles.add(atomicRole.getName());
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -86,7 +86,7 @@
* ExactCardinalityRestriction
*/
public void applyNumberRestrictions() {
- Set<ObjectProperty> allRoles = this.rs.getAtomicRoles();
+ Set<ObjectProperty> allRoles = this.rs.getObjectProperties();
// Set<Individual> allind = this.rs.getIndividuals();
testForTransitiveProperties(true);
@@ -116,7 +116,7 @@
* ExactCardinalityRestriction
*/
public void applyNumberRestrictionsConcise() {
- Set<ObjectProperty> allRoles = this.rs.getAtomicRoles();
+ Set<ObjectProperty> allRoles = this.rs.getObjectProperties();
// Set<Individual> allind = this.rs.getIndividuals();
testForTransitiveProperties(true);
@@ -167,7 +167,7 @@
* ExactCardinalityRestriction
*/
public void applyNumberRestrictionsNamed() {
- Set<ObjectProperty> allRoles = this.rs.getAtomicRoles();
+ Set<ObjectProperty> allRoles = this.rs.getObjectProperties();
// Set<Individual> allind = this.rs.getIndividuals();
testForTransitiveProperties(true);
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java 2008-07-31 16:27:38 UTC (rev 1042)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java 2008-07-31 16:33:29 UTC (rev 1043)
@@ -53,7 +53,7 @@
*/
public void applyNumberRestrictions() {
System.out.println("apply ExactCardinalityRestriction to Individuals");
- Set<ObjectProperty> allRoles = this.rs.getAtomicRoles();
+ Set<ObjectProperty> allRoles = this.rs.getObjectProperties();
System.out.println("found: " + allRoles.size() + " roles");
testForTransitiveProperties(true);
@@ -95,7 +95,7 @@
*/
public void applyNumberRestrictionsConcise() {
- Set<ObjectProperty> allRoles = this.rs.getAtomicRoles();
+ Set<ObjectProperty> allRoles = this.rs.getObjectProperties();
testForTransitiveProperties(true);
// collect info for roles and individuals
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-08-02 18:25:46
|
Revision: 1045
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1045&view=rev
Author: kurzum
Date: 2008-08-02 18:25:33 +0000 (Sat, 02 Aug 2008)
Log Message:
-----------
working category improver.
one problem: has many parameters, which determine the outcome
it has to be tested which are the best.
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/Info.java
trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java
trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java
trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
Modified: trunk/src/dl-learner/org/dllearner/Info.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/Info.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/Info.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -3,6 +3,6 @@
package org.dllearner;
public class Info {
- public static final String build = "2008-05-15";
+ public static final String build = "2008-08-01";
}
\ No newline at end of file
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -24,7 +24,6 @@
import java.util.Vector;
import org.apache.log4j.Logger;
-import org.dllearner.core.KnowledgeSource;
/**
* This class is used to extract the information .
@@ -39,7 +38,7 @@
// private boolean getAllSuperClasses = true;
// private boolean closeAfterRecursion = true;
private static Logger logger = Logger
- .getLogger(KnowledgeSource.class);
+ .getLogger(ExtractionAlgorithm.class);
public ExtractionAlgorithm(Configuration Configuration) {
this.configuration = Configuration;
@@ -75,7 +74,7 @@
//System.out.println(this.configuration);
long time = System.currentTimeMillis();
Node n = getFirstNode(uri);
- System.out.println(n);
+ logger.info(n);
Vector<Node> v = new Vector<Node>();
v.add(n);
logger.info("StartVector: " + v);
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -25,7 +25,6 @@
import java.util.TreeSet;
import org.apache.log4j.Logger;
-import org.dllearner.core.KnowledgeSource;
import org.dllearner.kb.sparql.SparqlEndpoint;
import org.dllearner.kb.sparql.SparqlQueryType;
import org.dllearner.utilities.statistics.Statistics;
@@ -43,7 +42,7 @@
private ExtractionAlgorithm extractionAlgorithm;
private static Logger logger = Logger
- .getLogger(KnowledgeSource.class);
+ .getLogger(Manager.class);
public void useConfiguration(SparqlQueryType SparqlQueryType,
@@ -77,12 +76,14 @@
public String extract(Set<String> instances) {
// this.TypedSparqlQuery.query(uri);
// System.out.println(ExtractionAlgorithm.getFirstNode(uri));
- System.out.println("Start extracting");
+ logger.info("Start extracting");
SortedSet<String> ret = new TreeSet<String>();
int progress=0;
for (String one : instances) {
progress++;
- logger.info("Progress: "+progress+" of "+instances.size()+" finished");
+ //if(progress % 10 == 0) {
+ logger.info("Progress: "+progress+" of "+instances.size()+" finished: "+one);
+ //}
try {
Node n = extractionAlgorithm.expandNode(new URI(one),
typedSparqlQuery);
@@ -91,15 +92,15 @@
e.printStackTrace();
}
}
- System.out.println("Finished extracting, start conversion");
+ logger.info("Finished extracting, start conversion");
StringBuffer nt = new StringBuffer();
Object[] arr = ret.toArray();
for (int i = 0; i < arr.length; i++) {
nt.append((String) arr[i] + "\n");
if (i % 1000 == 0)
- System.out.println(i + " of " + arr.length + " triples done");
+ logger.info(i + " of " + arr.length + " triples done");
}
- System.out.println(arr.length + " of " + arr.length + " triples done");
+ logger.info(arr.length + " of " + arr.length + " triples done");
/*
* String tmp=""; while ( ret.size() > 0) { tmp=ret.first(); nt+=tmp;
* ret.remove(tmp); System.out.println(ret.size()); } /*for (String str :
Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -23,24 +23,33 @@
import java.util.HashSet;
import java.util.List;
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.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
+import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent;
import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.KnowledgeSource;
+import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.owl.Individual;
+import org.dllearner.kb.extraction.ExtractionAlgorithm;
+import org.dllearner.kb.extraction.Manager;
import org.dllearner.kb.sparql.Cache;
import org.dllearner.kb.sparql.SPARQLTasks;
import org.dllearner.kb.sparql.SparqlEndpoint;
+import org.dllearner.kb.sparql.SparqlKnowledgeSource;
import org.dllearner.kb.sparql.SparqlQuery;
+import org.dllearner.scripts.improveWikipedia.ConceptSPARQLReEvaluator;
import org.dllearner.scripts.improveWikipedia.ConceptSelector;
import org.dllearner.scripts.improveWikipedia.WikipediaCategoryTasks;
-import org.dllearner.utilities.JamonMonitorLogger;
import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
+import org.dllearner.utilities.learn.LearnSPARQLConfiguration;
+import org.dllearner.utilities.learn.LearnSparql;
public class WikipediaCategoryCleaner {
@@ -50,93 +59,173 @@
private static Logger logger = Logger.getRootLogger();
- private static boolean local = true; // localEndpoint switch
+ // localEndpoint switch
+ private static final boolean LOCAL = false;
// parameters
- public static final int SPARQL_RESULTSET_LIMIT = 1000;
+ // used for developing,
+ private static final boolean DEVELOP = true;
- public static double PERCENT_OF_SKOSSET = 1.0; // the 70/30 strategy was
+ public static final int SPARQL_RESULTSET_LIMIT = 500;
- // abandoned
+ // the 70/30 strategy was abandoned
+ public static double PERCENT_OF_SKOSSET = 1.0;
- public static double NEGFACTOR = 1.0; // size of randomly choosen negative
+ // size of randomly choosen negative examples compared to positives
+ public static double NEGFACTOR = 1.0;
- // examples compared to positives
+ public static int MAX_NR_CONCEPTS_TO_BE_EVALUATED = Integer.MAX_VALUE;
+ public static double ACCURACY_THRESHOLD = 0.0;
+
+ public static String FILTER_CONCEPTS_BY = "Entity";
+
/**
* @param args
*/
public static void main(String[] args) {
initLogger();
+ setup();
logger.info("Start");
- // SETUP cache and sparqltasks
- cache = Cache.getPersistentCache();
+ String test = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
+ test = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners";
+ SortedSet<String> wikipediaCategories = new TreeSet<String>();
+ wikipediaCategories.add(test);
- if (local) {
- // url = "http://139.18.2.37:8890/sparql";
- sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
- .getEndpointLOCALDBpedia());
- } else {
- // url = "http://dbpedia.openlinksw.com:8890/sparql";
- sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
- .getEndpointDBpedia());
+ for (String target : wikipediaCategories) {
+
+ doit(target);
+
}
- String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
- target = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners";
+ System.out.println("Finished");
+ // JamonMonitorLogger.printAllSortedByLabel();
- WikipediaCategoryTasks s = new WikipediaCategoryTasks(sparqlTasks);
- // TODO Optimize
- s.calculateDefinitelyWrongIndividuals(target, PERCENT_OF_SKOSSET,
- NEGFACTOR, SPARQL_RESULTSET_LIMIT);
+ }
- logger.info("Found " + s.getDefinitelyWrongIndividuals().size()
- + " incorrect individuals");
- logger.debug("incorrect Individuals: "
- + s.getDefinitelyWrongIndividuals());
- logger.info("reevaluating " + s.getConceptresults().size()
- + " found Concepts");
- logger
- .info("END OF PHASE 1 **********************************************");
+ private static void doit(String target) {
+ List<EvaluatedDescription> conceptresults;
+ SortedSet<String> currentPOSITIVEex = new TreeSet<String>();
+ SortedSet<String> currentNEGATIVEex = new TreeSet<String>();
+ SortedSet<String> wrongIndividuals;
- s.reevaluateAndRelearn();
- List<EvaluatedDescription> newEval = s.getConceptresults();
- printEvaluatedDescriptionCollection(5, newEval);
+ WikipediaCategoryTasks wikiTasks;
+ ConceptSPARQLReEvaluator csparql;
- System.out.println("Finished");
- JamonMonitorLogger.printAllSortedByLabel();
+ wikiTasks = new WikipediaCategoryTasks(sparqlTasks);
+ csparql = new ConceptSPARQLReEvaluator(sparqlTasks);
+ // PHASE 1 *************
+
+ wikiTasks.makeInitialExamples(target, PERCENT_OF_SKOSSET, NEGFACTOR,
+ SPARQL_RESULTSET_LIMIT, DEVELOP);
+ currentPOSITIVEex.addAll(wikiTasks.getPosExamples());
+ currentNEGATIVEex.addAll(wikiTasks.getNegExamples());
+ // get wrong individuals and reevaluate concepts
+ conceptresults = learn(getConfToFindWrongIndividuals(),
+ currentPOSITIVEex, currentNEGATIVEex);
+ // TODO select concepts
+ conceptresults = selectConcepts(conceptresults);
+ wrongIndividuals = wikiTasks.calculateWrongIndividualsAndNewPosEx(
+ conceptresults, currentPOSITIVEex);
+ currentPOSITIVEex.clear();
+ currentPOSITIVEex.addAll(wikiTasks.getCleanedPositiveSet());
+
+ // reevaluate versus the Endpoint
+ conceptresults = csparql.reevaluateConceptsByLowestRecall(
+ conceptresults, currentPOSITIVEex);
+
+ WikipediaCategoryCleaner.printEvaluatedDescriptionCollection(2,
+ conceptresults);
+
+ printIntermediateResults(wikiTasks.getFullPositiveSet(),
+ wikiTasks.getCleanedPositiveSet(),
+ wrongIndividuals, conceptresults.size());
+
+ // PHASE 2 ***********************
+ logger.info("PHASE 2 ***********************");
+ logger.info("making new Negative Examples");
+ currentNEGATIVEex = wikiTasks.makeNewNegativeExamples(conceptresults,
+ currentPOSITIVEex, NEGFACTOR);
+
+ logger.info("learning");
+ conceptresults = learn(getConfToRelearn(), currentPOSITIVEex,
+ currentNEGATIVEex);
+ // TODO select concepts
+ logger.info("reducing concept size before evaluating");
+ conceptresults = selectConcepts(conceptresults);
+ // reevaluate versus the Endpoint
+ conceptresults = csparql.reevaluateConceptsByLowestRecall(
+ conceptresults, currentPOSITIVEex);
+
+ printEvaluatedDescriptionCollection(2, conceptresults);
+ collectResults(wikiTasks);
+
}
- private static void initLogger() {
+ private static void collectResults(WikipediaCategoryTasks wikiTasks) {
+ System.out.println(wikiTasks.getFullPositiveSet());
+ System.out.println(wikiTasks.getCleanedPositiveSet());
+ System.out.println(wikiTasks.getDefinitelyWrongIndividuals());
+ }
- SimpleLayout layout = new SimpleLayout();
- // create logger (a simple logger which outputs
- // its messages to the console)
- FileAppender fileAppender = null;
+ private static List<EvaluatedDescription> selectConcepts(
+ List<EvaluatedDescription> concepts) {
+ // TODO maybe not smart here
+ ConceptSelector cs = new ConceptSelector();
+ concepts = cs.getConceptsNotContainingString(concepts,
+ FILTER_CONCEPTS_BY, MAX_NR_CONCEPTS_TO_BE_EVALUATED);
+ if (concepts.size() == 0) {
+ logger.warn("NO GOOD CONCEPTS FOUND");
+ // TODO if this happens there has to be a fallback
+ }
+ return concepts;
+ }
+
+ /**
+ * All Concepts are returned, filtering these are done separately
+ *
+ * @param conf
+ * @param posExamples
+ * @param negExamples
+ * @return
+ */
+ private static List<EvaluatedDescription> learn(
+ LearnSPARQLConfiguration conf, SortedSet<String> posExamples,
+ SortedSet<String> negExamples) {
+ LearnSparql learner = new LearnSparql(getConfToRelearn());
+ LearningAlgorithm la = null;
try {
- fileAppender = new FileAppender(layout, "log/progress/skos"
- + ConceptSelector.time() + ".txt", false);
+ la = learner.learn(posExamples, negExamples);
} catch (Exception e) {
e.printStackTrace();
}
+ List<EvaluatedDescription> conceptresults = la
+ .getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, 0.0,
+ true);
+ return conceptresults;
+ }
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- logger.removeAllAppenders();
- logger.addAppender(consoleAppender);
- logger.addAppender(fileAppender);
- logger.setLevel(Level.DEBUG);
- Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
+ private static LearnSPARQLConfiguration getConfToFindWrongIndividuals() {
+ LearnSPARQLConfiguration lsc = new LearnSPARQLConfiguration();
+ lsc.sparqlEndpoint = sparqlTasks.getSparqlEndpoint();
- Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO);
- Logger.getLogger(Cache.class).setLevel(Level.INFO);
- Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel(
- Level.INFO);
- Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel(
- Level.INFO);
+ lsc.noisePercentage = 15;
+ lsc.guaranteeXgoodDescriptions = 200;
+ lsc.maxExecutionTimeInSeconds = 50;
+ lsc.logLevel = "INFO";
+ // lsc.searchTreeFile = "log/WikipediaCleaner.txt";
+
+ return lsc;
+
}
+ private static LearnSPARQLConfiguration getConfToRelearn() {
+ return getConfToFindWrongIndividuals();
+
+ }
+
public static void printEvaluatedDescriptionCollection(int howMany,
Collection<EvaluatedDescription> c) {
int x = 0;
@@ -147,10 +236,10 @@
first = ed.getNotCoveredPositives();
}
if (x >= howMany) {
- x++;
+
break;
}
-
+ x++;
tmp.addAll(ed.getNotCoveredPositives());
tmp.removeAll(first);
logger.debug("*************************");
@@ -163,4 +252,74 @@
}
}
+
+
+ private static void printIntermediateResults(
+ SortedSet fullSet,
+ SortedSet correctIndividuals,
+ SortedSet wrongIndividuals,
+ int numberOfConcepts) {
+ printSet("full Individual set: ", fullSet);
+
+ printSet("correct Individuals: ", correctIndividuals);
+ printSet("incorrect Individuals: ", wrongIndividuals);
+ logger.info("reevaluated " + numberOfConcepts + " found Concepts");
+ logger.info("END OF PHASE 1 **********************");
+ }
+ private static void printSet(String s, SortedSet set) {
+ if(logger.getLevel().equals(Level.DEBUG)){
+ logger.info(s +" ["+ set.size()+"]: "+set);
+ }else{
+ logger.info(s +" ["+ set.size()+"]");
+ }
+
+ }
+
+ private static void setup() {
+ // SETUP cache and sparqltasks
+ cache = Cache.getPersistentCache();
+
+ if (LOCAL) {
+ // url = "http://139.18.2.37:8890/sparql";
+ sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
+ .getEndpointLOCALDBpedia());
+ } else {
+ // url = "http://dbpedia.openlinksw.com:8890/sparql";
+ sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
+ .getEndpointDBpedia());
+ }
+ }
+
+ private static void initLogger() {
+
+ SimpleLayout layout = new SimpleLayout();
+ // create logger (a simple logger which outputs
+ // its messages to the console)
+ FileAppender fileAppender = null;
+ try {
+ fileAppender = new FileAppender(layout, "log/progress/skos"
+ + ConceptSelector.time() + ".txt", false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ logger.removeAllAppenders();
+ logger.addAppender(consoleAppender);
+ logger.addAppender(fileAppender);
+ logger.setLevel(Level.DEBUG);
+ Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
+ Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN);
+ Logger.getLogger(Manager.class).setLevel(Level.INFO);
+ Logger.getLogger(ExtractionAlgorithm.class).setLevel(Level.WARN);
+ Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel(
+ Level.WARN);
+ Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel(
+ Level.WARN);
+ Logger.getLogger(ExampleBasedROLComponent.class).setLevel(Level.WARN);
+ Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO);
+ Logger.getLogger(Cache.class).setLevel(Level.INFO);
+
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -32,11 +32,10 @@
import org.dllearner.utilities.owl.EvaluatedDescriptionComparator;
/**
- * @author Sebastian Hellmann
+ * @author Sebastian Hellmann
*
- * The EvaluatedDescriptions from a fragment are
- * validated against the SPARQLendpoint.
- * There are different strategies, see the methods;
+ * The EvaluatedDescriptions from a fragment are validated against the
+ * SPARQLendpoint. There are different strategies, see the methods;
*/
public class ConceptSPARQLReEvaluator {
@@ -51,33 +50,29 @@
int depthOfRDFS = 1;
- public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks,
- List<EvaluatedDescription> descToBeReevaluated) {
- this.descToBeReevaluated = descToBeReevaluated;
+ /**
+ * Constructor using default settings
+ *
+ * @param sparqlTasks
+ */
+ public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks) {
this.sparqlTasks = sparqlTasks;
}
- public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks,
- List<EvaluatedDescription> descToBeReevaluated, int depthOfRDFS,
+ /**
+ * constructor to manually set parameters
+ *
+ * @param sparqlTasks
+ * @param depthOfRDFS
+ * @param sparqlResultLimit
+ */
+ public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks, int depthOfRDFS,
int sparqlResultLimit) {
- this(sparqlTasks, descToBeReevaluated);
+ this(sparqlTasks);
this.depthOfRDFS = depthOfRDFS;
this.sparqlResultLimit = sparqlResultLimit;
}
-
- public List<EvaluatedDescription> reevaluateConceptsByDataCoverage(
- SortedSet<String> positiveSet, int maxNrOfConcepts) {
- List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet);
- List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>();
-
- while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) {
- returnSet.add(tmp.remove(0));
- }
-
- return returnSet;
- }
-
/**
* Accuracy is calculated as correct positive classified over (correct
* positive classified + incorrect negative classified) "How many are
@@ -88,6 +83,7 @@
* @return
*/
public List<EvaluatedDescription> reevaluateConceptsByDataCoverage(
+ List<EvaluatedDescription> descToBeReevaluated,
SortedSet<String> positiveSet) {
SortedSet<EvaluatedDescription> returnSet = new TreeSet<EvaluatedDescription>(
@@ -127,18 +123,6 @@
}
- public List<EvaluatedDescription> reevaluateConceptsByLowestRecall(
- SortedSet<String> positiveSet, int maxNrOfConcepts) {
- List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet);
- List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>();
-
- while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) {
- returnSet.add(tmp.remove(0));
- }
-
- return returnSet;
- }
-
/**
* Accuracy is calculated as correct positive classified over all retrieved
* e.g. 50 correct out of 400 retrieved (50/400)
@@ -147,6 +131,7 @@
* @return
*/
public List<EvaluatedDescription> reevaluateConceptsByLowestRecall(
+ List<EvaluatedDescription> descToBeReevaluated,
SortedSet<String> positiveSet) {
logger.info("reevaluating by lowest recall "
+ descToBeReevaluated.size() + " concepts");
@@ -159,7 +144,6 @@
SortedSet<String> PosAsNeg = new TreeSet<String>();
SortedSet<Individual> NegAsPos = new TreeSet<Individual>();
-
SortedSet<Individual> NegAsNeg = new TreeSet<Individual>();
// elements are immediately removed from the list to save memory
@@ -197,4 +181,30 @@
kbsyntax, sparqlResultLimit, depthOfRDFS);
}
+ /*
+ * public List<EvaluatedDescription> reevaluateConceptsByLowestRecall( List<EvaluatedDescription>
+ * descToBeReevaluated, SortedSet<String> positiveSet, int maxNrOfConcepts) {
+ * List<EvaluatedDescription> tmp =
+ * reevaluateConceptsByLowestRecall(descToBeReevaluated, positiveSet); List<EvaluatedDescription>
+ * returnSet = new ArrayList<EvaluatedDescription>();
+ *
+ * while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) {
+ * returnSet.add(tmp.remove(0)); }
+ *
+ * return returnSet; }
+ */
+
+ /*
+ * public List<EvaluatedDescription> reevaluateConceptsByDataCoverage( List<EvaluatedDescription>
+ * descToBeReevaluated, SortedSet<String> positiveSet, int maxNrOfConcepts) {
+ * List<EvaluatedDescription> tmp =
+ * reevaluateConceptsByLowestRecall(descToBeReevaluated, positiveSet); List<EvaluatedDescription>
+ * returnSet = new ArrayList<EvaluatedDescription>();
+ *
+ * while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) {
+ * returnSet.add(tmp.remove(0)); }
+ *
+ * return returnSet; }
+ */
+
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -24,79 +24,69 @@
import java.util.List;
import org.dllearner.core.EvaluatedDescription;
-import org.dllearner.core.LearningAlgorithm;
import org.dllearner.utilities.Files;
+import org.dllearner.utilities.datastructures.SetManipulation;
/**
- * This is a simple class, it might be worked into other classes later.
- * filters concepts and records some results
+ * This is a simple class, it might be worked into other classes later. filters
+ * concepts and records some results
*
* @author Sebastian Hellmann
- *
+ *
*/
public class ConceptSelector {
private static final long WASH = 1216800000000L;
-
- List<EvaluatedDescription> concepts;
-
- public ConceptSelector(LearningAlgorithm la) {
+
+ // List<EvaluatedDescription> concepts;
+
+ public ConceptSelector() {
super();
- this.concepts = la.getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, 0.0, true);
- this.recordConceptClasses();
-
+ // this.concepts = concepts;
+ // this.recordConceptClasses();
+
}
-
-
- public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts) {
- super();
- this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts);
-
+
+ public List<EvaluatedDescription> getAllConceptsWithoutOR(
+ List<EvaluatedDescription> concepts) {
+ return getConceptsNotContainingString(concepts, "OR");
}
-
- public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts, double acctreshold) {
- super();
- this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts, acctreshold, true);
- this.recordConceptClasses();
+
+ @SuppressWarnings("unchecked")
+ public List<EvaluatedDescription> getConceptsNotContainingString(
+ List<EvaluatedDescription> concepts, String filterString,
+ int limitSize) {
+ // List<EvaluatedDescription> tmp =
+ // getConceptsNotContainingString(filterString);
+ // List<EvaluatedDescription> result = new
+ // ArrayList<EvaluatedDescription>();
+ return SetManipulation.getFirst(getConceptsNotContainingString(
+ concepts, filterString), limitSize);
+ /*
+ * while ((!tmp.isEmpty()) && (result.size() <= limitSize)) {
+ * result.add(tmp.remove(0)); } return result;
+ */
}
-
- public List<EvaluatedDescription> getConceptsWithoutOR(){
- return getConceptsNotContainingString("OR");
- }
-
- public List<EvaluatedDescription> getConceptsNotContainingString(String filterString, int limitSize){
- List<EvaluatedDescription> tmp = getConceptsNotContainingString(filterString);
- List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>();
-
- while ((!tmp.isEmpty()) && (result.size() <= limitSize)) {
- result.add(tmp.remove(0));
- }
- return result;
- }
-
-
- public List<EvaluatedDescription> getConceptsNotContainingString(String filterString){
-
+
+ public List<EvaluatedDescription> getConceptsNotContainingString(
+ List<EvaluatedDescription> concepts, String filterString) {
+
List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>();
for (EvaluatedDescription description : concepts) {
if (!description.toString().contains(filterString)) {
- result.add(description);
+ result.add(description);
}
-
+
}
return result;
}
-
-
-
- public void recordConceptClasses() {
- StringBuffer result =new StringBuffer();
- StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n");
- StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n");
+ public void recordConceptClasses(List<EvaluatedDescription> concepts) {
+ StringBuffer result = new StringBuffer();
+ StringBuffer result1 = new StringBuffer("\n\n ***********Entity*****\n");
+ StringBuffer result2 = new StringBuffer("\n\n ***********OR*****\n");
int result1count = 1;
int result2count = 1;
-
int x = 0;
for (EvaluatedDescription description : concepts) {
@@ -121,7 +111,7 @@
Files.createFile(new File("results/descriptions/concepts" + time()
+ ".txt"), result.toString());
}
-
+
public static String time() {
return ("" + (System.currentTimeMillis() - WASH)).substring(0, 7);
Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -19,90 +19,62 @@
*/
package org.dllearner.scripts.improveWikipedia;
-import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.log4j.Logger;
import org.dllearner.core.EvaluatedDescription;
-import org.dllearner.core.LearningAlgorithm;
import org.dllearner.kb.sparql.SPARQLTasks;
-import org.dllearner.scripts.WikipediaCategoryCleaner;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.datastructures.SetManipulation;
import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
-import org.dllearner.utilities.learn.LearnSPARQLConfiguration;
-import org.dllearner.utilities.learn.LearnSparql;
public class WikipediaCategoryTasks {
private static Logger logger = Logger
.getLogger(WikipediaCategoryTasks.class);
- private static final boolean STABLE = true; // used for developing, same
-
- // negExamples not random
-
- private static final int MAXIMUM_NUMBER_OF_CONCEPTS_KEPT = Integer.MAX_VALUE;
-
- private static final double ACCTRESHOLD = 0.0;
-
private SPARQLTasks sparqlTasks;
+ // these cahnge all the time
private SortedSet<String> posExamples = new TreeSet<String>();
- private SortedSet<String> fullPositiveSet = new TreeSet<String>();
+ private SortedSet<String> negExamples = new TreeSet<String>();
- // private SortedSet<String> fullPosSetWithoutPosExamples = new
- // TreeSet<String>();
+ // these dont change, they are for collecting
+ private SortedSet<String> cleanedPositiveSet = new TreeSet<String>();
- private SortedSet<String> negExamples = new TreeSet<String>();
+ private SortedSet<String> fullPositiveSet = new TreeSet<String>();
private SortedSet<String> definitelyWrongIndividuals = new TreeSet<String>();
- private List<EvaluatedDescription> conceptresults = new ArrayList<EvaluatedDescription>();
-
public WikipediaCategoryTasks(SPARQLTasks sparqlTasks) {
this.sparqlTasks = sparqlTasks;
}
/**
- * @param SKOSConcept
- * @param percentOfSKOSSet
- * @param negfactor
- * @param sparqlResultLimit
+ * The strategy is yet really simple. //TODO take the best concept and the
+ * notCoveredPositives are the ones definitely wrong these are removed from
+ * the positives examples.
+ *
+ * @param conceptresults
+ * @param posExamples
+ * @return
*/
- public void calculateDefinitelyWrongIndividuals(String SKOSConcept,
- double percentOfSKOSSet, double negfactor, int sparqlResultLimit) {
+ public SortedSet<String> calculateWrongIndividualsAndNewPosEx(
+ List<EvaluatedDescription> conceptresults,
+ SortedSet<String> posExamples) {
- makeExamples(SKOSConcept, percentOfSKOSSet, negfactor,
- sparqlResultLimit);
-
- LearnSparql learner = new LearnSparql(
- prepareConfigurationToFindWrongIndividuals());
- LearningAlgorithm la = null;
- try {
- la = learner.learn(posExamples, negExamples);
- } catch (Exception e) {
- e.printStackTrace();
- }
- // TODO maybe not smart here
- ConceptSelector cs = new ConceptSelector(la,
- MAXIMUM_NUMBER_OF_CONCEPTS_KEPT, ACCTRESHOLD);
- conceptresults = cs.getConceptsNotContainingString("Entity",
- MAXIMUM_NUMBER_OF_CONCEPTS_KEPT);
- if (conceptresults.size() == 0) {
- logger.warn("NO GOOD CONCEPTS FOUND");
- }
-
definitelyWrongIndividuals = Helper.getStringSet(conceptresults.get(0)
.getNotCoveredPositives());
// clean the examples
posExamples.removeAll(definitelyWrongIndividuals);
- fullPositiveSet.removeAll(definitelyWrongIndividuals);
+ this.posExamples.clear();
+ this.posExamples.addAll(posExamples);
+ this.cleanedPositiveSet.addAll(posExamples);
// fullPosSetWithoutPosExamples.removeAll(definitelyWrongIndividuals);
logger.trace("posExamples" + posExamples.size());
@@ -110,25 +82,24 @@
negExamples.clear();
+ return definitelyWrongIndividuals;
+
}
- public void reevaluateAndRelearn() {
+ /**
+ * TODO could be more sophisticated
+ *
+ * @param reEvaluatedDesc
+ * @return
+ */
+ public SortedSet<String> makeNewNegativeExamples(
+ List<EvaluatedDescription> reEvaluatedDesc,
+ SortedSet<String> posExamples, double negFactor) {
+ negExamples.clear();
- ConceptSPARQLReEvaluator csparql = new ConceptSPARQLReEvaluator(
- sparqlTasks, conceptresults);
- List<EvaluatedDescription> reEvaluatedDesc;
-
- // TODO Optimize here
- reEvaluatedDesc = csparql.reevaluateConceptsByLowestRecall(
- fullPositiveSet, 1);
-
- // TODO add check if it is correct
- WikipediaCategoryCleaner.printEvaluatedDescriptionCollection(10,
- reEvaluatedDesc);
EvaluatedDescription newDesc = reEvaluatedDesc.get(0);
logger.info("Best concept: " + newDesc.getDescription());
- negExamples.clear();
negExamples.addAll(Helper.getStringSet(newDesc.getCoveredPositives()));
negExamples.addAll(Helper
.getStringSet(newDesc.getNotCoveredPositives()));
@@ -137,33 +108,28 @@
.getStringSet(newDesc.getNotCoveredNegatives()));
negExamples.removeAll(posExamples);
- // TODO could be more negatives
- negExamples = SetManipulation.fuzzyShrink(negExamples, posExamples
- .size());
- LearnSparql learner = new LearnSparql(prepareConfigurationToRelearn());
- LearningAlgorithm la = null;
- try {
- la = learner.learn(posExamples, negExamples);
- } catch (Exception e) {
- e.printStackTrace();
- }
- conceptresults = la.getCurrentlyBestEvaluatedDescriptions(500,
- ACCTRESHOLD, true);
+ int neglimit = (int) Math.round(posExamples.size() * negFactor);
+ negExamples = SetManipulation.fuzzyShrink(negExamples, neglimit);
+ return negExamples;
}
/**
- * @param SKOSConcept
+ * makes positive and negative Examples. positives are a simple retrieval of
+ * the category. negatives are made from parallelclasses.
+ *
+ * @param targetCategory
* @param percentOfSKOSSet
* percentage used from the SKOSSet for training
- * @param negfactor
+ * @param negFactor
* size of the negative Examples compared to the posExample size
* (1.0 means equal size)
* @param sparqlResultLimit
*/
- public void makeExamples(String SKOSConcept, double percentOfSKOSSet,
- double negfactor, int sparqlResultLimit) {
+ public void makeInitialExamples(String targetCategory,
+ double percentOfSKOSSet, double negFactor, int sparqlResultLimit,
+ boolean develop) {
fullPositiveSet.clear();
// fullPosSetWithoutPosExamples.clear();
posExamples.clear();
@@ -172,12 +138,12 @@
// POSITIVES
AutomaticPositiveExampleFinderSPARQL apos = new AutomaticPositiveExampleFinderSPARQL(
sparqlTasks);
- apos.makePositiveExamplesFromSKOSConcept(SKOSConcept);
- fullPositiveSet = apos.getPosExamples();
+ apos.makePositiveExamplesFromSKOSConcept(targetCategory);
+ fullPositiveSet.addAll(apos.getPosExamples());
int poslimit = (int) Math.round(percentOfSKOSSet
* fullPositiveSet.size());
- int neglimit = (int) Math.round(poslimit * negfactor);
+ int neglimit = (int) Math.round(poslimit * negFactor);
posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit);
@@ -188,7 +154,7 @@
aneg.makeNegativeExamplesFromParallelClasses(posExamples,
sparqlResultLimit);
- negExamples = aneg.getNegativeExamples(neglimit, STABLE);
+ negExamples = aneg.getNegativeExamples(neglimit, develop);
logger.debug("POSITIVE EXAMPLES");
for (String pos : posExamples) {
@@ -209,25 +175,6 @@
}
- private LearnSPARQLConfiguration prepareConfigurationToFindWrongIndividuals() {
- LearnSPARQLConfiguration lsc = new LearnSPARQLConfiguration();
- lsc.sparqlEndpoint = sparqlTasks.getSparqlEndpoint();
-
- lsc.noisePercentage = 15;
- lsc.guaranteeXgoodDescriptions = 200;
- lsc.maxExecutionTimeInSeconds = 50;
- lsc.logLevel = "INFO";
- // lsc.searchTreeFile = "log/WikipediaCleaner.txt";
-
- return lsc;
-
- }
-
- private LearnSPARQLConfiguration prepareConfigurationToRelearn() {
- return prepareConfigurationToFindWrongIndividuals();
-
- }
-
public SortedSet<String> getPosExamples() {
return posExamples;
}
@@ -244,8 +191,8 @@
return definitelyWrongIndividuals;
}
- public List<EvaluatedDescription> getConceptresults() {
- return conceptresults;
+ public SortedSet<String> getCleanedPositiveSet() {
+ return cleanedPositiveSet;
}
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -1,5 +1,6 @@
package org.dllearner.utilities.datastructures;
+import java.util.List;
import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -8,57 +9,75 @@
public class SetManipulation {
-
/**
- * shrinks a set to the limit
- * fuzzy here means the elements will be randomly picked
+ * shrinks a set to the limit fuzzy here means the elements will be randomly
+ * picked
+ *
* @param set
* @param limit
* @return
*/
public static SortedSet<String> fuzzyShrink(SortedSet<String> set, int limit) {
- if (set.size()<=limit)return set;
+ if (set.size() <= limit)
+ return set;
SortedSet<String> ret = new TreeSet<String>();
Random r = new Random();
- double treshold = ((double)limit)/set.size();
- //System.out.println("treshold"+howmany);
- //System.out.println("treshold"+allRetrieved.size());
- //System.out.println("treshold"+treshold);
-
-
- while(ret.size()< limit){
+ double treshold = ((double) limit) / set.size();
+ // System.out.println("treshold"+howmany);
+ // System.out.println("treshold"+allRetrieved.size());
+ // System.out.println("treshold"+treshold);
+
+ while (ret.size() < limit) {
for (String oneInd : set) {
- if(r.nextDouble()<treshold) {
+ if (r.nextDouble() < treshold) {
ret.add(oneInd);
- if(ret.size()>= limit)break;
+ if (ret.size() >= limit)
+ break;
}
}
}
return ret;
}
-
+
/**
- * shrinks a set to the limit
- * takes the first elements up to limit
+ * shrinks a set to the limit takes the first elements up to limit
+ *
* @param set
* @param limit
* @return
*/
- public static SortedSet<String> stableShrink(SortedSet<String> set, int limit) {
- if (set.size()<=limit)return set;
+ public static SortedSet<String> stableShrink(SortedSet<String> set,
+ int limit) {
+ if (set.size() <= limit)
+ return set;
SortedSet<String> ret = new TreeSet<String>();
-
-
+
for (String oneInd : set) {
ret.add(oneInd);
- if(ret.size()>= limit)break;
-
+ if (ret.size() >= limit)
+ break;
+
}
-
+
return ret;
}
-
- public static SortedSet<Individual> stringToInd(SortedSet<String> set ){
+
+ /**
+ * getFirst n Elements from list.
+ *
+ * @param list
+ * @param nrElements
+ * @return returns the list shrunken to size. it is an ARRAYLIST now
+ */
+ public static List getFirst(List list, int nrElements) {
+ int size;
+ while ((size = list.size()) > nrElements) {
+ list.remove(size - 1);
+ }
+ return list;
+ }
+
+ public static SortedSet<Individual> stringToInd(SortedSet<String> set) {
SortedSet<Individual> ret = new TreeSet<Individual>();
for (String ind : set) {
ret.add(new Individual(ind));
Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-31 16:37:22 UTC (rev 1044)
+++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-02 18:25:33 UTC (rev 1045)
@@ -129,16 +129,17 @@
}*/
/**
- * makes neg ex from classes, the pos ex belong to
+ * makes negEx from classes, the posEx belong to.
+ * Gets all Classes from PosEx, gets Instances from these Classes, returns all
* @param positiveSet
- * @param resultLimit
+ * @param sparqlResultLimit
*/
- public void makeNegativeExamplesFromParallelClasses(SortedSet<String> positiveSet, int resultLimit){
- makeNegativeExamplesFromClassesOfInstances(positiveSet, resultLimit);
+ public void makeNegativeExamplesFromParallelClasses(SortedSet<String> positiveSet, int sparqlResultLimit){
+ makeNegativeExamplesFromClassesOfInstances(positiveSet, sparqlResultLimit);
}
private void makeNegativeExamplesFromClassesOfInstances(SortedSet<String> positiveSet,
- int resultLimit) {
+ int sparqlResultLimit) {
logger.debug("making neg Examples from parallel classes");
SortedSet<String> classes = new TreeSet<String>();
// superClasses.add(concept.replace("\"", ""));
@@ -148,7 +149,7 @@
// superclasses");
for (String instance : positiveSet) {
- classes.addAll(sparqltasks.getClassesForInstance(instance, resultLimit));
+ classes.addAll(sparqltasks.getClassesForInstance(instance, sparqlResultLimit));
}
logger.debug("getting negExamples from " + classes.size() + " parallel classes");
for (String oneClass : classes) {
@@ -156,7 +157,7 @@
// rsc = new
// JenaResultSetConvenience(queryConcept("\""+oneClass+"\"",limit));
this.fromParallelClasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + oneClass
- + "\"", resultLimit));
+ + "\"", sparqlResultLimit));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-08-04 08:43:32
|
Revision: 1046
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1046&view=rev
Author: kurzum
Date: 2008-08-04 08:43:26 +0000 (Mon, 04 Aug 2008)
Log Message:
-----------
latest changes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/FilterTest.java
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -112,7 +112,7 @@
final SortedSet<String> tmpSet = new TreeSet<String>();
// collect super/subclasses for the depth
- for (; (depth != 0) && (!toBeRetrieved.isEmpty()); depth--) {
+ for (; (depth > 0) && (!toBeRetrieved.isEmpty()); depth--) {
// collect super/subclasses for each class in toBeRetrieved
// accumulate in tmpSet
for (String oneClass : toBeRetrieved) {
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -94,13 +94,14 @@
// Jena access to SPARQL endpoint
queryExecution = new QueryEngineHTTP(service, sparqlQueryString);
+ //System.out.println(sparqlEndpoint.getDefaultGraphURIs());
+
for (String dgu : sparqlEndpoint.getDefaultGraphURIs()) {
queryExecution.addDefaultGraph(dgu);
}
for (String ngu : sparqlEndpoint.getNamedGraphURIs()) {
queryExecution.addNamedGraph(ngu);
}
-
// TODO remove after overnext Jena release
HttpQuery.urlLimit = 3 * 1024;
JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime")
Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -50,6 +50,7 @@
import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
import org.dllearner.utilities.learn.LearnSPARQLConfiguration;
import org.dllearner.utilities.learn.LearnSparql;
+import org.dllearner.utilities.statistics.SimpleClock;
public class WikipediaCategoryCleaner {
@@ -67,6 +68,8 @@
private static final boolean DEVELOP = true;
public static final int SPARQL_RESULTSET_LIMIT = 500;
+
+ private static final int DEPTH_OF_RDFS = 0;
// the 70/30 strategy was abandoned
public static double PERCENT_OF_SKOSSET = 1.0;
@@ -84,13 +87,16 @@
* @param args
*/
public static void main(String[] args) {
+ SimpleClock sc = new SimpleClock();
initLogger();
setup();
logger.info("Start");
-
+ SortedSet<String> wikipediaCategories = new TreeSet<String>();
+
+
String test = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom";
+ wikipediaCategories.add(test);
test = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners";
- SortedSet<String> wikipediaCategories = new TreeSet<String>();
wikipediaCategories.add(test);
for (String target : wikipediaCategories) {
@@ -99,7 +105,7 @@
}
- System.out.println("Finished");
+ sc.printAndSet("Finished");
// JamonMonitorLogger.printAllSortedByLabel();
}
@@ -114,7 +120,7 @@
ConceptSPARQLReEvaluator csparql;
wikiTasks = new WikipediaCategoryTasks(sparqlTasks);
- csparql = new ConceptSPARQLReEvaluator(sparqlTasks);
+ csparql = new ConceptSPARQLReEvaluator(sparqlTasks, DEPTH_OF_RDFS, SPARQL_RESULTSET_LIMIT);
// PHASE 1 *************
@@ -153,9 +159,9 @@
conceptresults = learn(getConfToRelearn(), currentPOSITIVEex,
currentNEGATIVEex);
// TODO select concepts
- logger.info("reducing concept size before evaluating");
+ logger.info("reducing concept size before evaluating from "+conceptresults.size());
conceptresults = selectConcepts(conceptresults);
- // reevaluate versus the Endpoint
+ // reevaluate versus the Endpoint
conceptresults = csparql.reevaluateConceptsByLowestRecall(
conceptresults, currentPOSITIVEex);
@@ -165,9 +171,13 @@
}
private static void collectResults(WikipediaCategoryTasks wikiTasks) {
- System.out.println(wikiTasks.getFullPositiveSet());
- System.out.println(wikiTasks.getCleanedPositiveSet());
- System.out.println(wikiTasks.getDefinitelyWrongIndividuals());
+ //logger.setLevel(Level.DEBUG);
+ printSet("fullpos", wikiTasks.getFullPositiveSet());
+
+ printSet("cleanedpos", wikiTasks.getCleanedPositiveSet());
+
+ printSet("wrongindividuals", wikiTasks.getDefinitelyWrongIndividuals());
+
}
private static List<EvaluatedDescription> selectConcepts(
@@ -287,6 +297,7 @@
// url = "http://dbpedia.openlinksw.com:8890/sparql";
sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint
.getEndpointDBpedia());
+
}
}
@@ -308,17 +319,19 @@
logger.addAppender(consoleAppender);
logger.addAppender(fileAppender);
logger.setLevel(Level.DEBUG);
- Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN);
- Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN);
Logger.getLogger(Manager.class).setLevel(Level.INFO);
- Logger.getLogger(ExtractionAlgorithm.class).setLevel(Level.WARN);
+ Level lwarn = Level.WARN;
+ Logger.getLogger(KnowledgeSource.class).setLevel(lwarn);
+ Logger.getLogger(SparqlKnowledgeSource.class).setLevel(lwarn);
+
+ Logger.getLogger(ExtractionAlgorithm.class).setLevel(lwarn);
Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel(
- Level.WARN);
+ lwarn);
Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel(
- Level.WARN);
- Logger.getLogger(ExampleBasedROLComponent.class).setLevel(Level.WARN);
- Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO);
- Logger.getLogger(Cache.class).setLevel(Level.INFO);
+ lwarn);
+ Logger.getLogger(ExampleBasedROLComponent.class).setLevel(lwarn);
+ Logger.getLogger(SparqlQuery.class).setLevel(lwarn);
+ Logger.getLogger(Cache.class).setLevel(lwarn);
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -99,7 +99,10 @@
// NegAsNeg doesnt exist, because all
SortedSet<Individual> NegAsNeg = new TreeSet<Individual>();
- for (EvaluatedDescription ed : descToBeReevaluated) {
+ // elements are immediately removed from the list to save memory
+ while (!descToBeReevaluated.isEmpty()) {
+ EvaluatedDescription ed = descToBeReevaluated.remove(0);
+ try {
instances = retrieveInstances(ed);
// PosAsPos
@@ -114,8 +117,13 @@
.getIndividualSet(PosAsPos), Helper
.getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg));
- PosAsPos.clear();
- PosAsNeg.clear();
+ }catch(Exception e){
+ logger.warn("ERROR occured, while evaluating, I'm ignoring it : "+e.toString());
+ logger.warn("Concept was: "+ed.getDescription().toKBSyntaxString());
+ }finally{
+ PosAsPos.clear();
+ PosAsNeg.clear();
+ }
}
@@ -145,11 +153,11 @@
SortedSet<Individual> NegAsPos = new TreeSet<Individual>();
SortedSet<Individual> NegAsNeg = new TreeSet<Individual>();
-
+
// elements are immediately removed from the list to save memory
while (!descToBeReevaluated.isEmpty()) {
EvaluatedDescription ed = descToBeReevaluated.remove(0);
-
+ try {
instances = retrieveInstances(ed);
// PosAsPos
@@ -163,10 +171,13 @@
returnSet.add(new EvaluatedDescription(ed.getDescription(), Helper
.getIndividualSet(PosAsPos), Helper
.getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg));
-
- PosAsPos.clear();
- PosAsNeg.clear();
-
+ }catch(Exception e){
+ logger.warn("ERROR occured, while evaluating, I'm ignoring it :"+e.toString());
+ logger.warn("Concept was: "+ed.getDescription().toKBSyntaxString());
+ }finally{
+ PosAsPos.clear();
+ PosAsNeg.clear();
+ }
}
logger.info("finished reevaluating by lowest recall :"
+ returnSet.size() + " concepts");
Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -67,8 +67,9 @@
List<EvaluatedDescription> conceptresults,
SortedSet<String> posExamples) {
- definitelyWrongIndividuals = Helper.getStringSet(conceptresults.get(0)
- .getNotCoveredPositives());
+ definitelyWrongIndividuals.clear();
+ definitelyWrongIndividuals.addAll(Helper.getStringSet(conceptresults.get(0)
+ .getNotCoveredPositives()));
// clean the examples
posExamples.removeAll(definitelyWrongIndividuals);
@@ -145,7 +146,7 @@
* fullPositiveSet.size());
int neglimit = (int) Math.round(poslimit * negFactor);
- posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit);
+ posExamples.addAll(SetManipulation.fuzzyShrink(fullPositiveSet, poslimit));
// NEGATIVES
Added: trunk/src/dl-learner/org/dllearner/test/FilterTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/FilterTest.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -0,0 +1,35 @@
+package org.dllearner.test;
+
+import org.dllearner.kb.sparql.Cache;
+import org.dllearner.kb.sparql.SPARQLTasks;
+import org.dllearner.kb.sparql.SparqlEndpoint;
+import org.dllearner.utilities.statistics.SimpleClock;
+
+public class FilterTest {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}";
+ String qshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER (!isLiteral(?object)).}";
+
+ SimpleClock sc = new SimpleClock();
+ SPARQLTasks st = new SPARQLTasks(Cache.getPersistentCache(), SparqlEndpoint.getEndpointDBpedia());
+
+ for (int i = 0; i < 10; i++) {
+ st.query(qshort);
+ }
+ sc.printAndSet("long ");
+
+
+
+ for (int i = 0; i < 10; i++) {
+ st.query(qlong);
+ }
+
+ sc.printAndSet("short ");
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -18,8 +18,9 @@
* @return
*/
public static SortedSet<String> fuzzyShrink(SortedSet<String> set, int limit) {
- if (set.size() <= limit)
+ if (set.size() <= limit) {
return set;
+ }
SortedSet<String> ret = new TreeSet<String>();
Random r = new Random();
double treshold = ((double) limit) / set.size();
@@ -48,8 +49,9 @@
*/
public static SortedSet<String> stableShrink(SortedSet<String> set,
int limit) {
- if (set.size() <= limit)
+ if (set.size() <= limit) {
return set;
+ }
SortedSet<String> ret = new TreeSet<String>();
for (String oneInd : set) {
@@ -63,8 +65,9 @@
}
/**
+ * XXX
* getFirst n Elements from list.
- *
+ * changes the list!!!
* @param list
* @param nrElements
* @return returns the list shrunken to size. it is an ARRAYLIST now
Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -111,8 +111,8 @@
String SPARQLquery = "SELECT * WHERE { \n" + "<" + oneInstance + "> " + "?p ?object. \n"
+ "FILTER (REGEX(str(?object), '" + objectnamespace + "')).\n" + "}";
- this.fromRelated.addAll(sparqltasks.queryAsSet(SPARQLquery, "object"));
- this.fromRelated.removeAll(this.fullPositiveSet);
+ fromRelated.addAll(sparqltasks.queryAsSet(SPARQLquery, "object"));
+ fromRelated.removeAll(fullPositiveSet);
}
@@ -161,7 +161,7 @@
}
- this.fromParallelClasses.removeAll(this.fullPositiveSet);
+ fromParallelClasses.removeAll(fullPositiveSet);
logger.debug("|-neg Example size from parallelclass: " + fromParallelClasses.size());
}
@@ -181,27 +181,27 @@
for (String oneSuperClass : superClasses) {
logger.debug(oneSuperClass);
- this.fromSuperclasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\""
+ fromSuperclasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\""
+ oneSuperClass + "\"", resultLimit));
}
- this.fromSuperclasses.removeAll(this.fullPositiveSet);
+ this.fromSuperclasses.removeAll(fullPositiveSet);
logger.debug("|-neg Example from superclass: " + fromSuperclasses.size());
}
@SuppressWarnings("unused")
private void makeNegativeExamplesFromDomain(String role, int resultLimit){
logger.debug("making Negative Examples from Domain of : "+role);
- this.fromDomain.addAll(sparqltasks.getDomainInstances(role, resultLimit));
- this.fromDomain.removeAll(this.fullPositiveSet);
+ fromDomain.addAll(sparqltasks.getDomainInstances(role, resultLimit));
+ fromDomain.removeAll(fullPositiveSet);
logger.debug("|-neg Example size from Domain: "+this.fromDomain.size());
}
@SuppressWarnings("unused")
private void makeNegativeExamplesFromRange(String role, int resultLimit){
logger.debug("making Negative Examples from Range of : "+role);
- this.fromRange.addAll(sparqltasks.getRangeInstances(role, resultLimit));
- this.fromRange.removeAll(this.fullPositiveSet);
- logger.debug("|-neg Example size from Range: "+this.fromRange.size());
+ fromRange.addAll(sparqltasks.getRangeInstances(role, resultLimit));
+ fromRange.removeAll(fullPositiveSet);
+ logger.debug("|-neg Example size from Range: "+fromRange.size());
}
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java 2008-08-02 18:25:33 UTC (rev 1045)
+++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java 2008-08-04 08:43:26 UTC (rev 1046)
@@ -42,6 +42,7 @@
// KNOWLEDGESOURCE
cm.applyConfigEntry(ks, "url", sparqlEndpoint.getURL().toString());
+ cm.applyConfigEntry(ks, "predefinedEndpoint", "DBPEDIA");
cm.applyConfigEntry(ks, "recursionDepth", recursiondepth);
cm.applyConfigEntry(ks, "closeAfterRecursion", closeAfterRecursion);
cm.applyConfigEntry(ks, "predefinedFilter", predefinedFilter);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-08-04 09:01:48
|
Revision: 1047
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1047&view=rev
Author: jenslehmann
Date: 2008-08-04 09:01:44 +0000 (Mon, 04 Aug 2008)
Log Message:
-----------
structural change in EL trees
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java
trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
Removed Paths:
-------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java
Copied: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java (from rev 1046, trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java)
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+import org.dllearner.core.owl.ObjectProperty;
+
+/**
+ * A (directed) edge in an EL description tree. It consists of an edge
+ * label, which is an object property, and the EL description tree
+ * the edge points to.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class ELDescriptionEdge {
+
+ private ObjectProperty label;
+
+ private ELDescriptionNode tree;
+
+ /**
+ * Constructs and edge given a label and an EL description tree.
+ * @param label The label of this edge.
+ * @param tree The tree the edge points to (edges are directed).
+ */
+ public ELDescriptionEdge(ObjectProperty label, ELDescriptionNode tree) {
+ this.label = label;
+ this.tree = tree;
+ }
+
+ /**
+ * @return The label of this edge.
+ */
+ public ObjectProperty getLabel() {
+ return label;
+ }
+
+ /**
+ * @return The EL description tree
+ */
+ public ELDescriptionNode getTree() {
+ return tree;
+ }
+
+}
Copied: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java (from rev 1046, trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java)
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -0,0 +1,198 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectSomeRestriction;
+import org.dllearner.core.owl.Thing;
+import org.dllearner.core.owl.UnsupportedLanguageException;
+
+/**
+ * Represents an EL description tree, which corresponds to a
+ * description in the EL description logic. Note that an EL description tree
+ * can be a subtree of another EL description tree. In general,
+ * an EL description tree is a tree where the node label is a set
+ * of named classes and the edges are labelled with a property.
+ *
+ * In the documentation below "this node" refers to the root node
+ * of this EL description (sub-)tree. One tree cannot be reused,
+ * i.e. used as subtree in several description trees, as some of
+ * the associated variables (level, simulation) depend on the overall
+ * tree.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class ELDescriptionNode {
+
+ private SortedSet<NamedClass> label;
+
+ private List<ELDescriptionEdge> edges;
+
+ private int level;
+
+ // parent node in the tree;
+ // null indicates that this node is a root node
+ private ELDescriptionNode parent = null;
+
+ // to simplify equivalence checks and minimisation, we
+ // attach a simulation relation to the description tree
+// private Simulation simulation;
+
+ /**
+ * Constructs an empty EL description tree with the empty set
+ * as root label and an empty set of outgoing edges.
+ */
+ public ELDescriptionNode() {
+ this(new TreeSet<NamedClass>(), new LinkedList<ELDescriptionEdge>());
+// simulation = new Simulation();
+ }
+
+ /**
+ * Constructs an EL description tree given its root label.
+ * @param label Label of the root node.
+ */
+ public ELDescriptionNode(SortedSet<NamedClass> label) {
+ this(label, new LinkedList<ELDescriptionEdge>());
+ }
+
+ /**
+ * Constructs an EL description tree given its root label and edges.
+ * @param label Label of the root node.
+ * @param edges Edges connected to the root node.
+ */
+ public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) {
+ this.label = label;
+ this.edges = edges;
+ }
+
+ /**
+ * Constructs an EL description tree from an EL description.
+ * @param description A description
+ */
+ public ELDescriptionNode(Description description) {
+ // TODO not implemented
+ // throw an exception if the description is not in EL
+ throw new UnsupportedLanguageException(description.toString(), "EL");
+ }
+
+ /**
+ * Checks whether this node has a parent. If the parent link
+ * is null, the node is considered to be a root node.
+ * @return True of this is the root node and false otherwise.
+ */
+ public boolean isRoot() {
+ return parent == null;
+ }
+
+ /**
+ * Traverses the EL description tree upwards until it finds
+ * the root and returns it.
+ * @return The root node of this EL description tree.
+ */
+ public ELDescriptionNode getRoot() {
+ ELDescriptionNode root = this;
+ while(root.parent != null) {
+ root = parent;
+ }
+ return root;
+ }
+
+ /**
+ * Traverses the tree until the root node and counts how
+ * many edges are traversed. If this node does not have a parent,
+ * zero is returned. This method is used for checking the integrity
+ * of the tree in unit tests. Use {@link #getLevel()} to get the
+ * level of the tree.
+ * @return The level of this node (or more specifically the root
+ * node of this subtree) within the overall EL description tree.
+ */
+ public int computeLevel() {
+ ELDescriptionNode root = this;
+ int level = 0;
+ while(root.parent != null) {
+ root = parent;
+ level++;
+ }
+ return level;
+ }
+
+ /**
+ * This method transform the tree to an EL description. The
+ * node labels are transformed to an {@link Intersection}
+ * of {@link NamedClass}. Each edges is transformed to an
+ * {@link ObjectSomeRestriction}, where the property is the edge
+ * label and the child description the subtree the edge points
+ * to. Edges are also added to the intersection. If the intersection
+ * is empty, {@link Thing} is returned.
+ * @return The description corresponding to this EL description tree.
+ */
+ public Description transformToDescription() {
+ if(label.size()==0 && edges.size()==0) {
+ return new Thing();
+ } else {
+ Intersection is = new Intersection();
+ for(NamedClass nc : label) {
+ is.addChild(nc);
+ }
+ for(ELDescriptionEdge edge : edges) {
+ Description child = edge.getTree().transformToDescription();
+ ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child);
+ is.addChild(osr);
+ }
+ return is;
+ }
+ }
+
+ /**
+ * @return The label of root node of this subtree.
+ */
+ public SortedSet<NamedClass> getLabel() {
+ return label;
+ }
+
+ /**
+ * @return The outgoing edges of this subtree.
+ */
+ public List<ELDescriptionEdge> getEdges() {
+ return edges;
+ }
+
+ /**
+ * @return The level of the (root node of) this subtree in the overall tree.
+ */
+ public int getLevel() {
+ return level;
+ }
+
+ @Override
+ public ELDescriptionNode clone() {
+ // TODO implement efficient tree cloning
+ return null;
+ }
+
+}
Deleted: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-04 08:43:26 UTC (rev 1046)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -1,198 +0,0 @@
-/**
- * Copyright (C) 2007-2008, Jens Lehmann
- *
- * This file is part of DL-Learner.
- *
- * DL-Learner is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DL-Learner is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.dllearner.algorithms.el;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.dllearner.core.owl.Description;
-import org.dllearner.core.owl.Intersection;
-import org.dllearner.core.owl.NamedClass;
-import org.dllearner.core.owl.ObjectSomeRestriction;
-import org.dllearner.core.owl.Thing;
-import org.dllearner.core.owl.UnsupportedLanguageException;
-
-/**
- * Represents an EL description tree, which corresponds to a
- * description in the EL description logic. Note that an EL description tree
- * can be a subtree of another EL description tree. In general,
- * an EL description tree is a tree where the node label is a set
- * of named classes and the edges are labelled with a property.
- *
- * In the documentation below "this node" refers to the root node
- * of this EL description (sub-)tree. One tree cannot be reused,
- * i.e. used as subtree in several description trees, as some of
- * the associated variables (level, simulation) depend on the overall
- * tree.
- *
- * @author Jens Lehmann
- *
- */
-public class ELDescriptionTree {
-
- private SortedSet<NamedClass> label;
-
- private List<Edge> edges;
-
- private int level;
-
- // parent node in the tree;
- // null indicates that this node is a root node
- private ELDescriptionTree parent = null;
-
- // to simplify equivalence checks and minimisation, we
- // attach a simulation relation to the description tree
-// private Simulation simulation;
-
- /**
- * Constructs an empty EL description tree with the empty set
- * as root label and an empty set of outgoing edges.
- */
- public ELDescriptionTree() {
- this(new TreeSet<NamedClass>(), new LinkedList<Edge>());
-// simulation = new Simulation();
- }
-
- /**
- * Constructs an EL description tree given its root label.
- * @param label Label of the root node.
- */
- public ELDescriptionTree(SortedSet<NamedClass> label) {
- this(label, new LinkedList<Edge>());
- }
-
- /**
- * Constructs an EL description tree given its root label and edges.
- * @param label Label of the root node.
- * @param edges Edges connected to the root node.
- */
- public ELDescriptionTree(SortedSet<NamedClass> label, List<Edge> edges) {
- this.label = label;
- this.edges = edges;
- }
-
- /**
- * Constructs an EL description tree from an EL description.
- * @param description A description
- */
- public ELDescriptionTree(Description description) {
- // TODO not implemented
- // throw an exception if the description is not in EL
- throw new UnsupportedLanguageException(description.toString(), "EL");
- }
-
- /**
- * Checks whether this node has a parent. If the parent link
- * is null, the node is considered to be a root node.
- * @return True of this is the root node and false otherwise.
- */
- public boolean isRoot() {
- return parent == null;
- }
-
- /**
- * Traverses the EL description tree upwards until it finds
- * the root and returns it.
- * @return The root node of this EL description tree.
- */
- public ELDescriptionTree getRoot() {
- ELDescriptionTree root = this;
- while(root.parent != null) {
- root = parent;
- }
- return root;
- }
-
- /**
- * Traverses the tree until the root node and counts how
- * many edges are traversed. If this node does not have a parent,
- * zero is returned. This method is used for checking the integrity
- * of the tree in unit tests. Use {@link #getLevel()} to get the
- * level of the tree.
- * @return The level of this node (or more specifically the root
- * node of this subtree) within the overall EL description tree.
- */
- public int computeLevel() {
- ELDescriptionTree root = this;
- int level = 0;
- while(root.parent != null) {
- root = parent;
- level++;
- }
- return level;
- }
-
- /**
- * This method transform the tree to an EL description. The
- * node labels are transformed to an {@link Intersection}
- * of {@link NamedClass}. Each edges is transformed to an
- * {@link ObjectSomeRestriction}, where the property is the edge
- * label and the child description the subtree the edge points
- * to. Edges are also added to the intersection. If the intersection
- * is empty, {@link Thing} is returned.
- * @return The description corresponding to this EL description tree.
- */
- public Description transformToDescription() {
- if(label.size()==0 && edges.size()==0) {
- return new Thing();
- } else {
- Intersection is = new Intersection();
- for(NamedClass nc : label) {
- is.addChild(nc);
- }
- for(Edge edge : edges) {
- Description child = edge.getTree().transformToDescription();
- ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child);
- is.addChild(osr);
- }
- return is;
- }
- }
-
- /**
- * @return The label of root node of this subtree.
- */
- public SortedSet<NamedClass> getLabel() {
- return label;
- }
-
- /**
- * @return The outgoing edges of this subtree.
- */
- public List<Edge> getEdges() {
- return edges;
- }
-
- /**
- * @return The level of the (root node of) this subtree in the overall tree.
- */
- public int getLevel() {
- return level;
- }
-
- @Override
- public ELDescriptionTree clone() {
- // TODO implement efficient tree cloning
- return null;
- }
-
-}
Deleted: trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-08-04 08:43:26 UTC (rev 1046)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -1,62 +0,0 @@
-/**
- * Copyright (C) 2007-2008, Jens Lehmann
- *
- * This file is part of DL-Learner.
- *
- * DL-Learner is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DL-Learner is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.dllearner.algorithms.el;
-
-import org.dllearner.core.owl.ObjectProperty;
-
-/**
- * A (directed) edge in an EL description tree. It consists of an edge
- * label, which is an object property, and the EL description tree
- * the edge points to.
- *
- * @author Jens Lehmann
- *
- */
-public class Edge {
-
- private ObjectProperty label;
-
- private ELDescriptionTree tree;
-
- /**
- * Constructs and edge given a label and an EL description tree.
- * @param label The label of this edge.
- * @param tree The tree the edge points to (edges are directed).
- */
- public Edge(ObjectProperty label, ELDescriptionTree tree) {
- this.label = label;
- this.tree = tree;
- }
-
- /**
- * @return The label of this edge.
- */
- public ObjectProperty getLabel() {
- return label;
- }
-
- /**
- * @return The EL description tree
- */
- public ELDescriptionTree getTree() {
- return tree;
- }
-
-}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-08-04 08:43:26 UTC (rev 1046)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -36,15 +36,15 @@
private List<TreeTuple> relation;
// { w | (v,w) \in S } for all w
- private Map<ELDescriptionTree,List<ELDescriptionTree>> in;
+ private Map<ELDescriptionNode,List<ELDescriptionNode>> in;
// { v | (v,w) \in S } for all v
- private Map<ELDescriptionTree,List<ELDescriptionTree>> out;
+ private Map<ELDescriptionNode,List<ELDescriptionNode>> out;
public Simulation() {
relation = new LinkedList<TreeTuple>();
- in = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>();
- out = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>();
+ in = new HashMap<ELDescriptionNode,List<ELDescriptionNode>>();
+ out = new HashMap<ELDescriptionNode,List<ELDescriptionNode>>();
}
/**
@@ -59,7 +59,7 @@
if(in.containsKey(tuple.getTree2())) {
in.get(tuple.getTree2()).add(tuple.getTree1());
} else {
- List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>();
+ List<ELDescriptionNode> list = new LinkedList<ELDescriptionNode>();
list.add(tuple.getTree1());
in.put(tuple.getTree2(), list);
}
@@ -67,7 +67,7 @@
if(out.containsKey(tuple.getTree1())) {
out.get(tuple.getTree1()).add(tuple.getTree2());
} else {
- List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>();
+ List<ELDescriptionNode> list = new LinkedList<ELDescriptionNode>();
list.add(tuple.getTree2());
out.put(tuple.getTree1(), list);
}
@@ -99,11 +99,11 @@
return relation;
}
- public List<ELDescriptionTree> in(ELDescriptionTree tree) {
+ public List<ELDescriptionNode> in(ELDescriptionNode tree) {
return in.get(tree);
}
- public List<ELDescriptionTree> out(ELDescriptionTree tree) {
+ public List<ELDescriptionNode> out(ELDescriptionNode tree) {
return out.get(tree);
}
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-08-04 08:43:26 UTC (rev 1046)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -27,11 +27,11 @@
*/
public class TreeTuple {
- private ELDescriptionTree tree1;
+ private ELDescriptionNode tree1;
- private ELDescriptionTree tree2;
+ private ELDescriptionNode tree2;
- public TreeTuple(ELDescriptionTree tree1, ELDescriptionTree tree2) {
+ public TreeTuple(ELDescriptionNode tree1, ELDescriptionNode tree2) {
this.tree1 = tree1;
this.tree2 = tree2;
}
@@ -40,7 +40,7 @@
* Gets first tree.
* @return - first tree
*/
- public ELDescriptionTree getTree1() {
+ public ELDescriptionNode getTree1() {
return tree1;
}
@@ -48,7 +48,7 @@
* Gets second tree.
* @return - second tree
*/
- public ELDescriptionTree getTree2() {
+ public ELDescriptionNode getTree2() {
return tree2;
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 08:43:26 UTC (rev 1046)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -24,7 +24,7 @@
import java.util.Set;
import java.util.TreeMap;
-import org.dllearner.algorithms.el.ELDescriptionTree;
+import org.dllearner.algorithms.el.ELDescriptionNode;
import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.NamedClass;
@@ -95,10 +95,10 @@
public Set<Description> refine(Description concept) {
// TODO according to the specification, we need to minimise
// the tree (not yet implemented)
- ELDescriptionTree tree = new ELDescriptionTree(concept);
- Set<ELDescriptionTree> refinementTrees = refine(tree);
+ ELDescriptionNode tree = new ELDescriptionNode(concept);
+ Set<ELDescriptionNode> refinementTrees = refine(tree);
Set<Description> refinements = new HashSet<Description>();
- for(ELDescriptionTree refinementTree : refinementTrees) {
+ for(ELDescriptionNode refinementTree : refinementTrees) {
refinements.add(refinementTree.transformToDescription());
}
return refinements;
@@ -112,12 +112,12 @@
* @param tree Input EL description tree.
* @return Set of refined EL description trees.
*/
- public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
+ public Set<ELDescriptionNode> refine(ELDescriptionNode tree) {
return refine(tree, new Thing());
}
- private Set<ELDescriptionTree> refine(ELDescriptionTree tree, Description index) {
- Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ private Set<ELDescriptionNode> refine(ELDescriptionNode tree, Description index) {
+ Set<ELDescriptionNode> refinements = new HashSet<ELDescriptionNode>();
// option 1: label extension
// option 2: label refinement
@@ -126,7 +126,7 @@
// find all more special classes for the given label
for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) {
// create refinements by replacing class
- ELDescriptionTree tmp = tree.clone();
+ ELDescriptionNode tmp = tree.clone();
// TODO replace class in label
}
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 08:43:26 UTC (rev 1046)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 09:01:44 UTC (rev 1047)
@@ -21,7 +21,7 @@
import static org.junit.Assert.*;
-import org.dllearner.algorithms.el.ELDescriptionTree;
+import org.dllearner.algorithms.el.ELDescriptionNode;
import org.dllearner.algorithms.el.Simulation;
import org.dllearner.algorithms.el.TreeTuple;
import org.junit.Test;
@@ -38,8 +38,8 @@
@Test
public void simulationTest() {
Simulation s = new Simulation();
- ELDescriptionTree t1 = new ELDescriptionTree();
- ELDescriptionTree t2 = new ELDescriptionTree();
+ ELDescriptionNode t1 = new ELDescriptionNode();
+ ELDescriptionNode t2 = new ELDescriptionNode();
TreeTuple tuple1 = new TreeTuple(t1,t2);
s.addTuple(tuple1);
assertTrue(s.in(t2).size() == 1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-08-04 11:34:30
|
Revision: 1048
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1048&view=rev
Author: jenslehmann
Date: 2008-08-04 11:34:25 +0000 (Mon, 04 Aug 2008)
Log Message:
-----------
- implemented cache for getting all nodes on a particular level of a tree
- one of five operator steps in EL downward refinement done
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/core/owl/Description.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-04 09:01:44 UTC (rev 1047)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-04 11:34:25 UTC (rev 1048)
@@ -27,6 +27,7 @@
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Thing;
import org.dllearner.core.owl.UnsupportedLanguageException;
@@ -49,6 +50,9 @@
*/
public class ELDescriptionNode {
+ // the reference tree for storing values, must not be null
+ private ELDescriptionTree tree;
+
private SortedSet<NamedClass> label;
private List<ELDescriptionEdge> edges;
@@ -58,37 +62,52 @@
// parent node in the tree;
// null indicates that this node is a root node
private ELDescriptionNode parent = null;
-
- // to simplify equivalence checks and minimisation, we
- // attach a simulation relation to the description tree
-// private Simulation simulation;
-
+
/**
- * Constructs an empty EL description tree with the empty set
- * as root label and an empty set of outgoing edges.
+ * Constructs an EL description tree with empty root label.
*/
- public ELDescriptionNode() {
- this(new TreeSet<NamedClass>(), new LinkedList<ELDescriptionEdge>());
-// simulation = new Simulation();
- }
+ public ELDescriptionNode(ELDescriptionTree tree) {
+ this(tree, new TreeSet<NamedClass>());
+ }
/**
* Constructs an EL description tree given its root label.
* @param label Label of the root node.
*/
- public ELDescriptionNode(SortedSet<NamedClass> label) {
- this(label, new LinkedList<ELDescriptionEdge>());
+ public ELDescriptionNode(ELDescriptionTree tree, SortedSet<NamedClass> label) {
+ this.label = label;
+ this.edges = new LinkedList<ELDescriptionEdge>();
+ this.tree = tree;
+ level = 1;
+ parent = null;
}
+ public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, SortedSet<NamedClass> label) {
+ this.label = label;
+ this.edges = new LinkedList<ELDescriptionEdge>();
+ parent = parentNode;
+ // the reference tree is the same as for the parent tree
+ tree = parentNode.tree;
+ // level increases by 1
+ level = parentNode.level + 1;
+ // we add an edge from the parent to this node
+ ELDescriptionEdge edge = new ELDescriptionEdge(parentProperty, this);
+ parent.edges.add(edge);
+ // we need to update the set of nodes on a particular level
+ tree.addNodeToLevel(this, level);
+ }
+
/**
* Constructs an EL description tree given its root label and edges.
* @param label Label of the root node.
* @param edges Edges connected to the root node.
*/
- public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) {
- this.label = label;
- this.edges = edges;
- }
+// TODO: probably delete as this constructor is not straightforward to
+// implement within the new structure
+// public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) {
+// this.label = label;
+// this.edges = edges;
+// }
/**
* Constructs an EL description tree from an EL description.
@@ -167,8 +186,19 @@
return is;
}
}
+
+ /**
+ * Replaces an entry in the node label.
+ * @param oldClass Class to remove from label.
+ * @param newClass Class to add to label.
+ */
+ public void replaceInLabel(NamedClass oldClass, NamedClass newClass) {
+ label.remove(oldClass);
+ label.add(newClass);
+ }
/**
+ * Gets the label of this node. Do not modify the returned object.
* @return The label of root node of this subtree.
*/
public SortedSet<NamedClass> getLabel() {
@@ -176,7 +206,8 @@
}
/**
- * @return The outgoing edges of this subtree.
+ * @return The outgoing edges of this subtree. Do not modify the
+ * returned object.
*/
public List<ELDescriptionEdge> getEdges() {
return edges;
@@ -191,8 +222,22 @@
@Override
public ELDescriptionNode clone() {
- // TODO implement efficient tree cloning
- return null;
+ ELDescriptionNode node = null;
+ try {
+ node = (ELDescriptionNode) super.clone();
+ } catch (CloneNotSupportedException e) {
+ // should never happen
+ throw new InternalError(e.toString());
+ }
+/*
+ // create a deep copy
+ node.children = new LinkedList<Description>();
+ for(Description child : children) {
+ Description clonedChild = (Description) child.clone();
+ node.addChild(clonedChild);
+ }
+*/
+ return node;
}
}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-04 11:34:25 UTC (rev 1048)
@@ -0,0 +1,118 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.algorithms.el;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.dllearner.core.owl.NamedClass;
+
+/**
+ * Represents an EL description tree. Unlike {@link ELDescriptionNode},
+ * this is a tree-wide structure, i.e. it does not implement the tree
+ * structure itself, but is used to store information about the tree.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class ELDescriptionTree implements Cloneable {
+
+ // to simplify equivalence checks and minimisation, we
+ // attach a simulation relation to the description tree
+// private Simulation simulation;
+
+ private int maxLevel = 1;
+
+ private ELDescriptionNode rootNode;
+
+ private Map<Integer,Set<ELDescriptionNode>> levelNodeMapping = new HashMap<Integer,Set<ELDescriptionNode>>();
+
+ public ELDescriptionTree() {
+
+ }
+
+ /**
+ * Gets the nodes on a specific level of the tree.
+ * This information is cached here for performance
+ * reasons.
+ * @param level The level (distance from root node).
+ * @return The set of all nodes on the specified level within
+ * this tree.
+ */
+ public Set<ELDescriptionNode> getNodesOnLevel(int level) {
+ return levelNodeMapping.get(level);
+ }
+
+ /**
+ * Internal method for updating the level node mapping.
+ * It is called when a new node is added to the tree.
+ * @param node The new node.
+ * @param level Level of the new node.
+ */
+ protected void addNodeToLevel(ELDescriptionNode node, int level) {
+ if(level <= maxLevel) {
+ levelNodeMapping.get(level).add(node);
+ } else if (level == maxLevel + 1) {
+ Set<ELDescriptionNode> set = new HashSet<ELDescriptionNode>();
+ set.add(node);
+ levelNodeMapping.put(level, set);
+ maxLevel++;
+ } else {
+ throw new RuntimeException("Inconsistent EL description tree structure.");
+ }
+ }
+
+ /**
+ * @return the maxLevel
+ */
+ public int getMaxLevel() {
+ return maxLevel;
+ }
+
+ /**
+ * @return the rootNode
+ */
+ public ELDescriptionNode getRootNode() {
+ return rootNode;
+ }
+
+ @Override
+ public ELDescriptionTree clone() {
+ // create a new reference tree
+ ELDescriptionTree treeClone = new ELDescriptionTree();
+ // create a root node attached to this reference tree
+ ELDescriptionNode rootNodeClone = new ELDescriptionNode(treeClone, new TreeSet<NamedClass>(rootNode.getLabel()));
+ cloneRecursively(rootNode, rootNodeClone);
+ return treeClone;
+ }
+
+ // we read from the original structure and write to the new structure
+ private void cloneRecursively(ELDescriptionNode node, ELDescriptionNode nodeClone) {
+ // loop through all edges and clone the subtrees
+ for(ELDescriptionEdge edge : node.getEdges()) {
+ ELDescriptionNode tmp = new ELDescriptionNode(nodeClone, edge.getLabel(), new TreeSet<NamedClass>(edge.getTree().getLabel()));
+ cloneRecursively(edge.getTree(), tmp);
+ }
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/core/owl/Description.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2008-08-04 09:01:44 UTC (rev 1047)
+++ trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2008-08-04 11:34:25 UTC (rev 1048)
@@ -101,9 +101,8 @@
/**
* Returns a clone of this description.
*/
- @SuppressWarnings("unchecked")
@Override
- public Object clone() {
+ public Description clone() {
Description node = null;
try {
node = (Description) super.clone();
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 09:01:44 UTC (rev 1047)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 11:34:25 UTC (rev 1048)
@@ -125,9 +125,12 @@
for(NamedClass nc : tree.getLabel()) {
// find all more special classes for the given label
for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) {
- // create refinements by replacing class
- ELDescriptionNode tmp = tree.clone();
- // TODO replace class in label
+ if(moreSpecial instanceof NamedClass) {
+ // create refinements by replacing class
+ ELDescriptionNode tmp = tree.clone();
+ tmp.replaceInLabel(nc, (NamedClass) moreSpecial);
+ refinements.add(tmp);
+ }
}
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 09:01:44 UTC (rev 1047)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 11:34:25 UTC (rev 1048)
@@ -21,9 +21,14 @@
import static org.junit.Assert.*;
+import java.util.TreeSet;
+
import org.dllearner.algorithms.el.ELDescriptionNode;
+import org.dllearner.algorithms.el.ELDescriptionTree;
import org.dllearner.algorithms.el.Simulation;
import org.dllearner.algorithms.el.TreeTuple;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
import org.junit.Test;
/**
@@ -38,12 +43,19 @@
@Test
public void simulationTest() {
Simulation s = new Simulation();
- ELDescriptionNode t1 = new ELDescriptionNode();
- ELDescriptionNode t2 = new ELDescriptionNode();
+ ELDescriptionTree tree1 = new ELDescriptionTree();
+ ELDescriptionTree tree2 = new ELDescriptionTree();
+ ELDescriptionNode t1 = new ELDescriptionNode(tree1);
+ ELDescriptionNode t2 = new ELDescriptionNode(tree2);
TreeTuple tuple1 = new TreeTuple(t1,t2);
s.addTuple(tuple1);
assertTrue(s.in(t2).size() == 1);
- assertTrue(s.out(t2).size() == 0);
+// assertTrue(s.out(t2).size() == 0);
+ ObjectProperty p = new ObjectProperty("p");
+ TreeSet<NamedClass> l3 = new TreeSet<NamedClass>();
+ ELDescriptionNode t3 = new ELDescriptionNode(t1,p,l3);
+ assertTrue(t3.getLevel() == 2);
+ assertTrue(tree1.getMaxLevel() == 2);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-08-04 17:18:13
|
Revision: 1049
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1049&view=rev
Author: kurzum
Date: 2008-08-04 17:17:58 +0000 (Mon, 04 Aug 2008)
Log Message:
-----------
tested some new improvements, which showed that further experimentation is necessary
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
trunk/src/dl-learner/org/dllearner/test/FilterTest.java
trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java
trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/rules/
trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java
trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java
trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java
trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java
trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -24,6 +24,7 @@
import java.util.TreeSet;
import org.apache.log4j.Logger;
+import org.dllearner.utilities.datastructures.StringTuple;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFactory;
@@ -381,7 +382,29 @@
+ object + " \n" + "} " + limit(sparqlResultLimit);
return queryAsSet(sparqlQueryString, variable);
}
+
+
+ public SortedSet<StringTuple> queryAsTuple(String subject, boolean filterLiterals) {
+ ResultSetRewindable rs = null;
+ String p = "predicate";
+ String o = "object";
+ String lits = (filterLiterals)? ".FILTER (!isLiteral(?"+o+"))." : "";
+ String sparqlQueryString = "SELECT * WHERE { <"+subject+"> ?"+p+" ?"+o+" "+lits+" } ";
+
+ try {
+ String jsonString = query(sparqlQueryString);
+ rs = SparqlQuery.convertJSONtoResultSet(jsonString);
+ } catch (Exception e) {
+ logger.warn(e.getMessage());
+ }
+
+ //SimpleClock sc = new SimpleClock();
+ //rw = ResultSetFactory.makeRewindable(rs);
+ //sc.printAndSet("rewindable");
+ return getTuplesFromResultSet(rs, p, o);
+ }
+
/**
* little higher level, executes query ,returns all resources for a
* variable.
@@ -428,9 +451,13 @@
public String query(String sparqlQueryString) {
String jsonString;
if (cache == null) {
+
SparqlQuery sq = new SparqlQuery(sparqlQueryString, sparqlEndpoint);
+ //SimpleClock sc = new SimpleClock();
sq.send();
+ //sc.printAndSet("querysend");
jsonString = sq.getJson();
+
} else {
jsonString = cache.executeSparqlQuery(new SparqlQuery(
sparqlQueryString, sparqlEndpoint));
@@ -464,7 +491,23 @@
return result;
}
+
+ private static SortedSet<StringTuple> getTuplesFromResultSet(
+ ResultSetRewindable rs, String predicate, String object) {
+ final SortedSet<StringTuple> returnSet = new TreeSet<StringTuple>();
+ //SimpleClock sc = new SimpleClock();
+ @SuppressWarnings("unchecked")
+ final List<ResultBinding> l = ResultSetFormatter.toList(rs);
+ for (ResultBinding resultBinding : l) {
+ returnSet.add(new StringTuple(resultBinding.get(predicate).toString(),resultBinding.get(object).toString()));
+ }
+ //sc.printAndSet("allTuples");
+ rs.reset();
+ //sc.printAndSet("reset");
+ return returnSet;
+ }
+
public SparqlEndpoint getSparqlEndpoint() {
return sparqlEndpoint;
}
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -278,15 +278,8 @@
* @return JSON representation of the result set.
*/
public static String convertResultSetToJSON(ResultSetRewindable resultSet) {
- // if (rs == null)
- // this.send();
- //ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ResultSetFormatter.outputAsJSON(baos, resultSet);
- // possible Jena bug: Jena modifies the result set during
- // JSON transformation, so we need to get it back
- //rsRewind.
- //resultSet = convertJSONtoResultSet(baos.toString());
resultSet.reset();
try {
return baos.toString("UTF-8");
Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -46,6 +46,7 @@
import org.dllearner.scripts.improveWikipedia.ConceptSPARQLReEvaluator;
import org.dllearner.scripts.improveWikipedia.ConceptSelector;
import org.dllearner.scripts.improveWikipedia.WikipediaCategoryTasks;
+import org.dllearner.utilities.datastructures.SetManipulation;
import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL;
import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL;
import org.dllearner.utilities.learn.LearnSPARQLConfiguration;
@@ -172,11 +173,11 @@
private static void collectResults(WikipediaCategoryTasks wikiTasks) {
//logger.setLevel(Level.DEBUG);
- printSet("fullpos", wikiTasks.getFullPositiveSet());
+ SetManipulation.printSet("fullpos", wikiTasks.getFullPositiveSet(), logger);
- printSet("cleanedpos", wikiTasks.getCleanedPositiveSet());
+ SetManipulation.printSet("cleanedpos", wikiTasks.getCleanedPositiveSet(), logger);
- printSet("wrongindividuals", wikiTasks.getDefinitelyWrongIndividuals());
+ SetManipulation.printSet("wrongindividuals", wikiTasks.getDefinitelyWrongIndividuals(), logger);
}
@@ -269,21 +270,15 @@
SortedSet correctIndividuals,
SortedSet wrongIndividuals,
int numberOfConcepts) {
- printSet("full Individual set: ", fullSet);
+ SetManipulation.printSet("full Individual set: ", fullSet, logger);
- printSet("correct Individuals: ", correctIndividuals);
- printSet("incorrect Individuals: ", wrongIndividuals);
+ SetManipulation.printSet("correct Individuals: ", correctIndividuals, logger);
+ SetManipulation.printSet("incorrect Individuals: ", wrongIndividuals, logger);
logger.info("reevaluated " + numberOfConcepts + " found Concepts");
logger.info("END OF PHASE 1 **********************");
}
- private static void printSet(String s, SortedSet set) {
- if(logger.getLevel().equals(Level.DEBUG)){
- logger.info(s +" ["+ set.size()+"]: "+set);
- }else{
- logger.info(s +" ["+ set.size()+"]");
- }
-
- }
+
+
private static void setup() {
// SETUP cache and sparqltasks
Modified: trunk/src/dl-learner/org/dllearner/test/FilterTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -1,35 +1,158 @@
package org.dllearner.test;
-import org.dllearner.kb.sparql.Cache;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
import org.dllearner.kb.sparql.SPARQLTasks;
import org.dllearner.kb.sparql.SparqlEndpoint;
+import org.dllearner.test.rules.RuleExecutor;
+import org.dllearner.test.rules.SimpleObjectFilterRule;
+import org.dllearner.test.rules.SimplePredicateFilterRule;
+import org.dllearner.utilities.datastructures.SetManipulation;
+import org.dllearner.utilities.datastructures.StringTuple;
import org.dllearner.utilities.statistics.SimpleClock;
public class FilterTest {
+
+ private static SPARQLTasks st;
+ private static String subject = "http://dbpedia.org/resource/%22Big%22_Ron";
+ static int howmany = 150;
+ static SimpleClock sc = new SimpleClock();
+
+ static String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}";
+ /*static String qextralong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') )))." +
+ "OPTIONAL { ?object ?p2 ?o2. FILTER( (!isLiteral(?o2))&&( ( !regex(str(?p2), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/website') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?p2), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?p2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?p2), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?o2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?o2), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?o2), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?o2), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?o2), 'http://www.geonames.org') ))).}}";
+ */
+ static String qextralong="SELECT * WHERE { { <http://dbpedia.org/resource/Angela_Merkel> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}" +
+ "OPTIONAL { ?object ?p2 ?o2. FILTER( (!isLiteral(?o2))&&( ( !regex(str(?p2), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/website') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?p2), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?p2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?p2), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?o2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?o2), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?o2), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?o2), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?o2), 'http://www.geonames.org') ))).}}";
+
+
+ static String qshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER (!isLiteral(?object)).}";
+ static String sshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object }";
+ static String qextrashort="SELECT * WHERE { <http://dbpedia.org/resource/Angela_Merkel> ?predicate ?object. FILTER (!isLiteral(?object)). OPTIONAL { ?object ?p2 ?o2 FILTER (!isLiteral(?o2))}}";
+
+
/**
* @param args
*/
public static void main(String[] args) {
- // TODO Auto-generated method stub
- String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}";
- String qshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER (!isLiteral(?object)).}";
+ // System.out.println(qextralong);
+
+ // System.out.println(qextrashort);
- SimpleClock sc = new SimpleClock();
- SPARQLTasks st = new SPARQLTasks(Cache.getPersistentCache(), SparqlEndpoint.getEndpointDBpedia());
+ st = new SPARQLTasks( SparqlEndpoint.getEndpointDBpedia());
+ st.queryAsTuple(subject, true);
+ st.query(qlong);
+ st.query(qextralong);
+ st.query(sshort);
+ // st.query(qextrashort);
+ System.out.println(qextrashort);
+ System.exit(0);
+ // st.query(qextrashort);
+ //System.out.println(qextralong);
- for (int i = 0; i < 10; i++) {
- st.query(qshort);
+ //String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) )).}";
+
+
+ //testLong();
+
+ //testShortWithFilter();
+ //testShort();
+ testLong();
+ testExtraLong();
+ //testExtraShort();
+ //testShort();
+ //testLong();
+ //testShortWithFilter();
+
+
+ /*sc.reset();
+ for (int i = 0; i < howmany; i++) {
+ st.query(sshort);
}
- sc.printAndSet("long ");
+ sc.printAndSet("supershort ");
+ */
- for (int i = 0; i < 10; i++) {
+ }
+
+ static void testShort(){
+ SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>();
+ sc.reset();
+ for (int i = 0; i < howmany; i++) {
+
+ tupleset = st.queryAsTuple(subject, true);
+
+ }
+ SetManipulation.printSet("before", tupleset);
+
+ sc.printAndSet("SHORT ");
+
+ }
+
+ static void testLong(){
+ sc.reset();
+ for (int i = 0; i < howmany; i++) {
st.query(qlong);
}
+ sc.printAndSet("long ");
+ }
+
+ static void testExtraLong(){
+ sc.reset();
+ for (int i = 0; i < howmany; i++) {
+ st.query(qextralong);
+ }
+ sc.printAndSet("extraLong ");
+ }
+
+ static void testExtraShort(){
+ sc.reset();
+ for (int i = 0; i < howmany; i++) {
+ st.query(qextrashort);
+ }
+ sc.printAndSet("qextrashort ");
+ }
+
+ static void testShortWithFilter(){
+ SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>();
+ SortedSet<StringTuple> afterfilter= new TreeSet<StringTuple>();
+ RuleExecutor re = new RuleExecutor();
- sc.printAndSet("short ");
+
+ re.addFilterRule(new SimplePredicateFilterRule( "http://dbpedia.org/property/relatedInstance" ));
+ re.addFilterRule(new SimplePredicateFilterRule( "http://dbpedia.org/property/website"));
+ re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/owner" ));
+ re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/wikiPageUsesTemplate" ));
+ re.addFilterRule(new SimplePredicateFilterRule("http://www.w3.org/2002/07/owl#sameAs" ));
+ re.addFilterRule(new SimplePredicateFilterRule("http://xmlns.com/foaf/0.1/" ));
+ re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/standard"));
+ re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/wikipage"));
+ re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/reference"));
+ re.addFilterRule(new SimplePredicateFilterRule("http://www.w3.org/2004/02/skos/core"));
+ re.addFilterRule(new SimpleObjectFilterRule("http://xmlns.com/foaf/0.1/" ));
+ re.addFilterRule(new SimpleObjectFilterRule( "http://upload.wikimedia.org/wikipedia"));
+ re.addFilterRule(new SimpleObjectFilterRule( "http://www4.wiwiss.fu-berlin.de/flickrwrappr"));
+ re.addFilterRule(new SimpleObjectFilterRule("http://dbpedia.org/resource/Template" ));
+ re.addFilterRule(new SimpleObjectFilterRule( "http://upload.wikimedia.org/wikipedia/commons"));
+ re.addFilterRule(new SimpleObjectFilterRule("http://www.w3.org/2006/03/wn/wn20/instances/synset" ));
+ re.addFilterRule(new SimpleObjectFilterRule("http://dbpedia.org/resource/Category:" ));
+ re.addFilterRule(new SimpleObjectFilterRule( "http://www.w3.org/2004/02/skos/core" ));
+ re.addFilterRule(new SimpleObjectFilterRule("http://www.geonames.org"));
+
+
+
+ sc.reset();
+ for (int i = 0; i < howmany; i++) {
+
+ tupleset = st.queryAsTuple(subject, true);
+ afterfilter = re.filterTuples(subject,tupleset);
+ }
+ sc.printAndSet("SHORT with filter");
+ SetManipulation.printSet("before", tupleset);
+ SetManipulation.printSet("after", afterfilter);
}
}
Added: trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -0,0 +1,10 @@
+package org.dllearner.test.rules;
+
+import org.dllearner.utilities.datastructures.StringTuple;
+
+public abstract class FilterRule {
+
+
+ public abstract boolean keepTuple(String subject, StringTuple tuple);
+
+}
Added: trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -0,0 +1,8 @@
+package org.dllearner.test.rules;
+
+import org.dllearner.utilities.datastructures.StringTuple;
+
+public abstract class ReplacementRule {
+
+ public abstract StringTuple applyRule(String subject, StringTuple tuple);
+}
Added: trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -0,0 +1,45 @@
+package org.dllearner.test.rules;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.dllearner.utilities.datastructures.StringTuple;
+
+public class RuleExecutor {
+
+ List<ReplacementRule> replacementRules = new ArrayList<ReplacementRule>();
+ List<FilterRule> filterRule = new ArrayList<FilterRule>();
+
+ public RuleExecutor() {
+ super();
+ }
+
+ private boolean keepTuple(String subject, StringTuple tuple) {
+
+ for (int i = 0; i < filterRule.size(); i++) {
+ FilterRule fr = filterRule.get(i);
+ if (!(fr.keepTuple(subject, tuple))) {
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ public SortedSet<StringTuple> filterTuples(String subject, SortedSet<StringTuple> tuples){
+ SortedSet<StringTuple> returnSet = new TreeSet<StringTuple>();
+ for (StringTuple tuple : tuples) {
+ if(keepTuple(subject, tuple)) {
+ returnSet.add(tuple);
+ }
+ }
+ return returnSet;
+ }
+
+ public void addFilterRule(FilterRule fr){
+ filterRule.add(fr);
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -0,0 +1,23 @@
+package org.dllearner.test.rules;
+
+import org.dllearner.utilities.datastructures.StringTuple;
+
+public class SimpleObjectFilterRule extends FilterRule{
+
+ String objectFilter;
+
+ public SimpleObjectFilterRule(String objectFilter) {
+ super();
+ this.objectFilter = objectFilter;
+ }
+
+
+ @Override
+ public boolean keepTuple(String subject, StringTuple tuple) {
+ return !(tuple.b.contains(objectFilter));
+ }
+
+
+
+
+}
Added: trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -0,0 +1,23 @@
+package org.dllearner.test.rules;
+
+import org.dllearner.utilities.datastructures.StringTuple;
+
+public class SimplePredicateFilterRule extends FilterRule{
+
+ String predicateFilter;
+
+
+ public SimplePredicateFilterRule(String predicateFilter) {
+ super();
+ this.predicateFilter = predicateFilter;
+ }
+
+ @Override
+ public boolean keepTuple(String subject, StringTuple tuple) {
+ return !(tuple.a.contains(predicateFilter));
+ }
+
+
+
+
+}
Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -5,6 +5,8 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.dllearner.core.owl.Individual;
public class SetManipulation {
@@ -87,4 +89,18 @@
}
return ret;
}
+
+ public static void printSet(String s, SortedSet set, Logger logger) {
+ if(logger.getLevel().equals(Level.DEBUG)){
+ logger.info(s +" ["+ set.size()+"]: "+set);
+ }else{
+ logger.info(s +" ["+ set.size()+"]");
+ }
+
+ }
+
+ public static void printSet(String s, SortedSet set) {
+ System.out.println(s +" ["+ set.size()+"]: "+set);
+
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -24,7 +24,7 @@
* Also used as pre form, if you want to create triple, that have the same subject
* @author Sebastian Hellmann
*/
-public class StringTuple {
+public class StringTuple implements Comparable<StringTuple>{
public String a;
public String b;
@@ -40,10 +40,14 @@
}
public boolean equals(StringTuple t) {
- if (a.equals(t.a) && b.equals(t.b))
- return true;
- else
- return false;
+ return ((b.equals(t.b)) && (a.equals(t.a)));
}
+
+ public int compareTo(StringTuple t){
+ int comp = a.compareTo(t.a);
+ if( comp == 0 ){
+ return b.compareTo(t.b);
+ }else return comp;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java 2008-08-04 11:34:25 UTC (rev 1048)
+++ trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java 2008-08-04 17:17:58 UTC (rev 1049)
@@ -57,9 +57,19 @@
}
+ /**
+ * resets the clock
+ */
public void setTime() {
time=System.currentTimeMillis();
}
+ /**
+ * resets the clock
+ */
+ public void reset() {
+ setTime();
+ }
+
public long getTime() {
long now=System.currentTimeMillis();
return now-time;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-08-05 09:50:44
|
Revision: 1050
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1050&view=rev
Author: kurzum
Date: 2008-08-05 09:50:39 +0000 (Tue, 05 Aug 2008)
Log Message:
-----------
small changes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java
Property Changed:
----------------
trunk/src/dl-learner/org/dllearner/test/
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 17:17:58 UTC (rev 1049)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-05 09:50:39 UTC (rev 1050)
@@ -85,13 +85,14 @@
// isRunning = true;
ResultSet rs;
-
+ String service = sparqlEndpoint.getURL().toString();
+
writeToSparqlLog("***********\nNew Query:");
writeToSparqlLog(sparqlQueryString);
- writeToSparqlLog(sparqlEndpoint.getURL().toString());
+ writeToSparqlLog(service);
- String service = sparqlEndpoint.getURL().toString();
-
+
+ logger.trace("making queryExecution Object");
// Jena access to SPARQL endpoint
queryExecution = new QueryEngineHTTP(service, sparqlQueryString);
//System.out.println(sparqlEndpoint.getDefaultGraphURIs());
@@ -117,7 +118,7 @@
+ sparqlEndpoint.getURL().toString());
rs = queryExecution.execSelect();
-
+ logger.trace("query executed, converting to json");
json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs));
//writeToSparqlLog("JSON: " + json);
@@ -132,6 +133,7 @@
logger.warn("RuntimeException in SparqlQuery"+ e.toString());
writeToSparqlLog("ERROR: HTTPException occured"+ e.toString());
writeToSparqlLog("ERROR: query was: "+sparqlQueryString);
+ writeToSparqlLog("wget -S -O test.txt '"+service+"?query="+sparqlQueryString+"'");
//}
throw e;
}
Property changes on: trunk/src/dl-learner/org/dllearner/test
___________________________________________________________________
Modified: svn:ignore
- JamonTest.java
+ JamonTest.java
JenaAmpBug.java
Added: trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 09:50:39 UTC (rev 1050)
@@ -0,0 +1,35 @@
+package org.dllearner.test;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.dllearner.kb.sparql.SparqlEndpoint;
+import org.dllearner.kb.sparql.SparqlQuery;
+
+public class TestOneQueryForMusicRecommender {
+
+ private static Logger logger = Logger.getRootLogger();
+
+ public static void main(String[] args) {
+ Logger.getLogger(SparqlQuery.class).setLevel(Level.TRACE);
+ logger.info("Start");
+ String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> ";
+ p1 += "PREFIX mo: <http://purl.org/ontology/mo/> ";
+ String query1 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10";
+ //String query2 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name 'Allison Crowe' .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10";
+
+
+ SparqlEndpoint se = SparqlEndpoint.getEndpointJamendo();
+ System.out.println(se.getURL());
+ System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query1+"'");
+ //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query2+"'");
+ System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query1+"'");
+ //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query2+"'");
+ System.out.println(se.getURL()+"?query="+query1);
+ SparqlQuery s = new SparqlQuery(p1+query1, se);
+ s.send();
+ System.out.println(s.getJson());
+
+
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-08-05 14:57:01
|
Revision: 1054
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1054&view=rev
Author: kurzum
Date: 2008-08-05 14:56:56 +0000 (Tue, 05 Aug 2008)
Log Message:
-----------
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-05 10:45:13 UTC (rev 1053)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-05 14:56:56 UTC (rev 1054)
@@ -122,12 +122,14 @@
json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs));
//writeToSparqlLog("JSON: " + json);
- }catch (HTTPException e) {
+ //}catch (ResultSetException e) {
+ } catch (HTTPException e) {
logger.warn("Exception in SparqlQuery\n"+ e.toString());
logger.warn("query was "+ sparqlQueryString);
writeToSparqlLog("ERROR: HTTPException occured"+ e.toString());
writeToSparqlLog("ERROR: query was: "+sparqlQueryString);
throw e;
+
}catch (RuntimeException e) {
//if (!(e instanceof HTTPException)) {
logger.warn("RuntimeException in SparqlQuery"+ e.toString());
@@ -317,4 +319,70 @@
}
+ /***
+ public static String sendGetRequest(String urlStr)
+ {
+ String result = null;
+
+
+ try
+ {
+ StringBuffer data = new StringBuffer();
+
+ //String urlStr = endpoint;
+ // if (requestParameters != null && requestParameters.length () > 0)
+ //{
+ //urlStr += "?" + requestParameters;
+ //}
+ //urlStr = "http://www.klappstuhlclub.de";
+ URL url = new URL(urlStr);
+ System.out.println(urlStr);
+ URLConnection conn = url.openConnection ();
+
+ // Get the response
+ BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ StringBuffer sb = new StringBuffer();
+ String line="";
+ System.out.println("aa"+line);
+ while ((line = rd.readLine()) != null)
+ {
+ System.out.println("aa"+line);
+ sb.append(line);
+ }
+ rd.close();
+ result = sb.toString();
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ public String fallback(){
+ System.out.println("TEST");
+ try{
+ String urlStr = (sparqlEndpoint.getURL().toString()+"?query="+sparqlQueryString);
+ //URLConnection con = url.openConnection();
+ System.out.println(sendGetRequest(urlStr));
+ System.out.println("f");
+ //System.out.println(con.getContentLength());
+ //con.connect();
+ System.out.println("sdf");
+ String a = "12345";
+ byte[] b = a.getBytes();
+ //con.getInputStream().read(b);
+ System.out.println(new String (b));
+ //Object o = con.getContent();
+ //System.out.println(o+o.getClass().getCanonicalName());
+ }catch (Exception ea) {
+ // TODO: handle exception
+ }
+ return "";
+ }
+
+
+
+ */
+
}
Modified: trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 10:45:13 UTC (rev 1053)
+++ trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 14:56:56 UTC (rev 1054)
@@ -2,8 +2,6 @@
import java.util.List;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
import org.dllearner.kb.sparql.SparqlEndpoint;
import org.dllearner.kb.sparql.SparqlQuery;
@@ -14,62 +12,84 @@
public class TestOneQueryForMusicRecommender {
- private static Logger logger = Logger.getRootLogger();
+
+static String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
+"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\">"+
+"<head> "+
+"<variable name=\"artist\"/>"+
+"<variable name=\"name\"/>"+
+"<variable name=\"image\"/>"+
+"<variable name=\"homepage\"/>"+
+"</head>"+
+"<results ordered=\"false\" distinct=\"false\">"+
+"<result>"+
+ "<binding name=\"artist\">"+
+ "<uri>http://dbtune.org/jamendo/artist/6108</uri>"+
+ "</binding>"+
+ "<binding name=\"name\">"+
+ "<literal datatype=\"http://www.w3.org/2001/XMLSchema#string\">Allison Crowe</literal>"+
+ "</binding>"+
+ "<binding name=\"image\">"+
+ "<uri>http://img.jamendo.com/artists/a/allison.crowe.jpg</uri>"+
+ "</binding>"+
+ "<binding name=\"homepage\">"+
+ "<uri>http://www.allisoncrowe.com</uri>"+
+ "</binding>"+
+"</result>"+
+"</results>"+
+"</sparql>";
+
+
public static void main(String[] args) {
- Logger.getLogger(SparqlQuery.class).setLevel(Level.TRACE);
- logger.info("Start");
- String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> ";
- p1 += "PREFIX mo: <http://purl.org/ontology/mo/> ";
- String query1 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10";
- //String query2 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name 'Allison Crowe' .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10";
+
+ String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
+ "PREFIX mo: <http://purl.org/ontology/mo/> ";
+ String sparqlQueryString = p1+ "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10";
+ System.out.println("SparqlQuery: ");
+ System.out.println(sparqlQueryString);
+ System.out.println("wget -S -O test.txt "+"'http://dbtune.org:2105/sparql/?query="+sparqlQueryString+"'");
+
- SparqlEndpoint se = SparqlEndpoint.getEndpointJamendo();
- System.out.println(se.getURL());
- System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query1+"'");
- //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query2+"'");
- System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query1+"'");
- //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query2+"'");
- //System.out.println(se.getURL()+"?query="+query1);
- //SparqlQuery s = new SparqlQuery(query1, se);
- //s.send();
- //System.out.println(s.getJson());
-
-
- String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
-"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\">"+
- "<head>"+
- "<variable name=\"artist\"/>"+
- "<variable name=\"name\"/>"+
- "<variable name=\"image\"/>"+
- "<variable name=\"homepage\"/>"+
- "</head>"+
- "<results ordered=\"false\" distinct=\"false\">"+
- "<result>"+
- "<binding name=\"artist\">"+
- "<uri>http://dbtune.org/jamendo/artist/6108</uri>"+
- "</binding>"+
- "<binding name=\"name\">"+
- "<literal datatype=\"http://www.w3.org/2001/XMLSchema#string\">Allison Crowe</literal>"+
- "</binding>"+
- "<binding name=\"image\">"+
- "<uri>http://img.jamendo.com/artists/a/allison.crowe.jpg</uri>"+
- "</binding>"+
- "<binding name=\"homepage\">"+
- "<uri>http://www.allisoncrowe.com</uri>"+
- "</binding>"+
- "</result>"+
- "</results>"+
-"</sparql>";
-
ResultSet rs = ResultSetFactory.fromXML(xml);
List<ResultBinding> l = ResultSetFormatter.toList(rs);
for (ResultBinding binding : l) {
System.out.println(binding.toString());
}
+
+ System.out.println("Executing query");
+ rs = null;
+ //String service = "http://dbtune.org:2105/sparql/";
+ //QueryEngineHTTP queryExecution = new QueryEngineHTTP(service, sparqlQueryString);
+
+ try{
+ SparqlQuery s = new SparqlQuery(sparqlQueryString, SparqlEndpoint.getEndpointJamendo());
+ s.send();
+ //rs = queryExecution.execSelect();
+
+ //ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ //ResultSetFormatter.outputAsJSON(baos, rs);
+
+
+ //System.out.println( baos.toString("UTF-8"));
+ } catch (Exception e) {
+ // should never happen as UTF-8 is supported
+ e.printStackTrace();
+
+ }
+
+
+
+
+
+
+
}
+
+
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-08-06 17:54:33
|
Revision: 1056
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1056&view=rev
Author: jenslehmann
Date: 2008-08-06 17:54:29 +0000 (Wed, 06 Aug 2008)
Log Message:
-----------
EL refinement operator continued
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java
trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
Modified: trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java 2008-08-06 09:53:31 UTC (rev 1055)
+++ trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java 2008-08-06 17:54:29 UTC (rev 1056)
@@ -94,6 +94,35 @@
subsumptionHierarchyUp = hierarchyUpNew;
}
+ /**
+ * Implements a subsumption check using the hierarchy (no further
+ * reasoning checks are used).
+ * @param subClass The (supposedly) more special class.
+ * @param superClass The (supposedly) more general class.
+ * @return True if <code>subClass</code> is a subclass of <code>superclass</code>.
+ */
+ public boolean isSubclassOf(NamedClass subClass, NamedClass superClass) {
+ if(subClass.equals(superClass)) {
+ return true;
+ } else {
+ for(Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) {
+ // search the upper classes of the subclass
+ if(moreGeneralClass instanceof NamedClass) {
+ if(isSubclassOf((NamedClass)moreGeneralClass, superClass)) {
+ return true;
+ }
+ // we reached top, so we can return false (if top is a direct upper
+ // class, then no other upper classes can exist)
+ } else {
+ return false;
+ }
+ }
+ // we cannot reach the class via any of the upper classes,
+ // so it is not a super class
+ return false;
+ }
+ }
+
@Override
public String toString() {
return toString(false);
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-06 09:53:31 UTC (rev 1055)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-06 17:54:29 UTC (rev 1056)
@@ -29,8 +29,12 @@
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Individual;
import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.Negation;
import org.dllearner.core.owl.Nothing;
import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.core.owl.SubsumptionHierarchy;
+import org.dllearner.core.owl.Thing;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptComparator;
@@ -97,6 +101,27 @@
return Helper.intersection(rs.getMostGeneralRoles(), applicableObjectProperties);
}
+ public Set<NamedClass> getClassCandidates(Description index, Set<NamedClass> existingClasses) {
+ return getClassCandidatesRecursive(index, existingClasses, Thing.instance);
+ }
+
+ private Set<NamedClass> getClassCandidatesRecursive(Description index, Set<NamedClass> existingClasses, Description upperClass) {
+ Set<NamedClass> candidates = new TreeSet<NamedClass>();
+ SubsumptionHierarchy sh = rs.getSubsumptionHierarchy();
+ for(Description d : sh.getMoreSpecialConcepts(upperClass)) {
+ // check disjointness with index
+ if(isDisjoint(d,index)) {
+ // check whether the class is meaningful, i.e. adds something to the index
+ // to do this, we need to make sure that the class is not a superclass of the
+ // index (otherwise we get nothing new)
+ if(isDisjoint(new Negation(d),index)) {
+ // TODO further checks
+ }
+ }
+ }
+ return candidates;
+ }
+
private boolean isDisjoint(Description d1, Description d2) {
// check whether we have cached this query
Map<Description,Boolean> tmp = cachedDisjoints.get(d1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-08-07 11:06:58
|
Revision: 1057
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1057&view=rev
Author: jenslehmann
Date: 2008-08-07 11:06:52 +0000 (Thu, 07 Aug 2008)
Log Message:
-----------
implemented selection of candidate class in label extension in EL downward refinement operator
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-06 17:54:29 UTC (rev 1056)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-07 11:06:52 UTC (rev 1057)
@@ -30,7 +30,6 @@
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Thing;
-import org.dllearner.core.owl.UnsupportedLanguageException;
/**
* Represents an EL description tree, which corresponds to a
@@ -110,16 +109,6 @@
// }
/**
- * Constructs an EL description tree from an EL description.
- * @param description A description
- */
- public ELDescriptionNode(Description description) {
- // TODO not implemented
- // throw an exception if the description is not in EL
- throw new UnsupportedLanguageException(description.toString(), "EL");
- }
-
- /**
* Checks whether this node has a parent. If the parent link
* is null, the node is considered to be a root node.
* @return True of this is the root node and false otherwise.
@@ -188,6 +177,15 @@
}
/**
+ * Each node is assigned a number within the tree.
+ * TODO add explanation how this is done
+ * @return The position number of this node within the tree as described above.
+ */
+ public int getCurrentPositionNumber() {
+ return 0;
+ }
+
+ /**
* Replaces an entry in the node label.
* @param oldClass Class to remove from label.
* @param newClass Class to add to label.
@@ -220,24 +218,4 @@
return level;
}
- @Override
- public ELDescriptionNode clone() {
- ELDescriptionNode node = null;
- try {
- node = (ELDescriptionNode) super.clone();
- } catch (CloneNotSupportedException e) {
- // should never happen
- throw new InternalError(e.toString());
- }
-/*
- // create a deep copy
- node.children = new LinkedList<Description>();
- for(Description child : children) {
- Description clonedChild = (Description) child.clone();
- node.addChild(clonedChild);
- }
-*/
- return node;
- }
-
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-06 17:54:29 UTC (rev 1056)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-07 11:06:52 UTC (rev 1057)
@@ -25,7 +25,9 @@
import java.util.Set;
import java.util.TreeSet;
+import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.UnsupportedLanguageException;
/**
* Represents an EL description tree. Unlike {@link ELDescriptionNode},
@@ -50,6 +52,16 @@
public ELDescriptionTree() {
}
+
+ /**
+ * Constructs an EL description tree from an EL description.
+ * @param description A description
+ */
+ public ELDescriptionTree(Description description) {
+ // TODO not implemented
+ // throw an exception if the description is not in EL
+ throw new UnsupportedLanguageException(description.toString(), "EL");
+ }
/**
* Gets the nodes on a specific level of the tree.
@@ -63,6 +75,10 @@
return levelNodeMapping.get(level);
}
+ public Description transformToDescription() {
+ return rootNode.transformToDescription();
+ }
+
/**
* Internal method for updating the level node mapping.
* It is called when a new node is added to the tree.
@@ -96,6 +112,39 @@
return rootNode;
}
+ /**
+ * Selects a sub tree.
+ * @param positionNumber A position in the tree. Positions are iteratively given to nodes
+ * by leftmost depth-first search. This allows efficient selection of subtrees.
+ * (TODO: Implementation does not work if any node has more than two children
+ * like conjunction and disjunction.)
+ * @return The selected subtree.
+ */
+ public Description getNode(int positionNumber) {
+// if (children.size() == 0)
+// return this;
+// else if (children.size() == 1) {
+// if (positionNumber == 0)
+// return this;
+// else
+// return children.get(0).getSubtree(positionNumber - 1);
+// }
+// // arity 2
+// else {
+// // we have found it
+// if (positionNumber == 0)
+// return this;
+// // left subtree
+// int leftTreeNodes = children.get(0).getNumberOfNodes();
+// if (positionNumber <= leftTreeNodes)
+// return children.get(0).getSubtree(positionNumber - 1);
+// // right subtree
+// else
+// return children.get(1).getSubtree(positionNumber - leftTreeNodes - 1);
+// }
+ return null;
+ }
+
@Override
public ELDescriptionTree clone() {
// create a new reference tree
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-06 17:54:29 UTC (rev 1056)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-07 11:06:52 UTC (rev 1057)
@@ -25,6 +25,7 @@
import java.util.TreeMap;
import org.dllearner.algorithms.el.ELDescriptionNode;
+import org.dllearner.algorithms.el.ELDescriptionTree;
import org.dllearner.core.ReasoningService;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.NamedClass;
@@ -95,10 +96,10 @@
public Set<Description> refine(Description concept) {
// TODO according to the specification, we need to minimise
// the tree (not yet implemented)
- ELDescriptionNode tree = new ELDescriptionNode(concept);
- Set<ELDescriptionNode> refinementTrees = refine(tree);
+ ELDescriptionTree tree = new ELDescriptionTree(concept);
+ Set<ELDescriptionTree> refinementTrees = refine(tree);
Set<Description> refinements = new HashSet<Description>();
- for(ELDescriptionNode refinementTree : refinementTrees) {
+ for(ELDescriptionTree refinementTree : refinementTrees) {
refinements.add(refinementTree.transformToDescription());
}
return refinements;
@@ -112,23 +113,28 @@
* @param tree Input EL description tree.
* @return Set of refined EL description trees.
*/
- public Set<ELDescriptionNode> refine(ELDescriptionNode tree) {
- return refine(tree, new Thing());
+ public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
+ return refine(tree, tree.getRootNode(), new Thing());
}
- private Set<ELDescriptionNode> refine(ELDescriptionNode tree, Description index) {
- Set<ELDescriptionNode> refinements = new HashSet<ELDescriptionNode>();
+ private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// option 1: label extension
-
+ Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel());
+ for(NamedClass nc : candidates) {
+
+ }
// option 2: label refinement
// loop through all classes in label
- for(NamedClass nc : tree.getLabel()) {
+ for(NamedClass nc : node.getLabel()) {
// find all more special classes for the given label
for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) {
if(moreSpecial instanceof NamedClass) {
// create refinements by replacing class
- ELDescriptionNode tmp = tree.clone();
- tmp.replaceInLabel(nc, (NamedClass) moreSpecial);
+ ELDescriptionTree tmp = tree.clone();
+ // TODO we need to find a way to get this node in
+ // the cloned tree
+// tmp.replaceInLabel(nc, (NamedClass) moreSpecial);
refinements.add(tmp);
}
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-06 17:54:29 UTC (rev 1056)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-07 11:06:52 UTC (rev 1057)
@@ -47,6 +47,7 @@
public final class Utility {
private ReasoningService rs;
+ SubsumptionHierarchy sh;
// concept comparator
private ConceptComparator conceptComparator = new ConceptComparator();
@@ -61,6 +62,7 @@
public Utility(ReasoningService rs) {
this.rs = rs;
+ sh = rs.getSubsumptionHierarchy();
}
/**
@@ -107,21 +109,58 @@
private Set<NamedClass> getClassCandidatesRecursive(Description index, Set<NamedClass> existingClasses, Description upperClass) {
Set<NamedClass> candidates = new TreeSet<NamedClass>();
- SubsumptionHierarchy sh = rs.getSubsumptionHierarchy();
+
+ // we descend the subsumption hierarchy to ensure that we get
+ // the most general concepts satisfying the criteria
+ // there are 4 checks a class has to satisfy to get into the set;
+ // for 2 of them we can stop further traversal in the subsumption
+ // hierarchy
for(Description d : sh.getMoreSpecialConcepts(upperClass)) {
- // check disjointness with index
- if(isDisjoint(d,index)) {
- // check whether the class is meaningful, i.e. adds something to the index
- // to do this, we need to make sure that the class is not a superclass of the
- // index (otherwise we get nothing new)
- if(isDisjoint(new Negation(d),index)) {
- // TODO further checks
+ // owl:Nothing is never a candidate (not in EL)
+ if(!(d instanceof Nothing)) {
+ NamedClass candidate = (NamedClass) d;
+ // we first do those checks where we know that we do not
+ // need to traverse the subsumption hierarchy if they are
+ // not satisfied
+ // check1: disjointness with index
+ // check3: no superclass exists already
+ if(!isDisjoint(candidate,index) || !checkSubClasses(existingClasses,candidate)) {
+ // check whether the class is meaningful, i.e. adds something to the index
+ // to do this, we need to make sure that the class is not a superclass of the
+ // index (otherwise we get nothing new)
+ if(!isDisjoint(new Negation(candidate),index) || !checkSuperClasses(existingClasses,candidate)) {
+ // candidate went successfully through all checks
+ candidates.add(candidate);
+ } else {
+ // descend subsumption hierarchy to find candidates
+ candidates.addAll(getClassCandidatesRecursive(index, existingClasses, candidate));
+ }
}
}
}
return candidates;
}
+ // returns true of the candidate is not subclass of an existing class,
+ // false otherwise (check 3)
+ private boolean checkSubClasses(Set<NamedClass> existingClasses, NamedClass candidate) {
+ for(NamedClass nc : existingClasses) {
+ if(sh.isSubclassOf(candidate, nc))
+ return false;
+ }
+ return true;
+ }
+
+ // returns true of the candidate is not superclass of an existing class,
+ // false otherwise (check 4)
+ private boolean checkSuperClasses(Set<NamedClass> existingClasses, NamedClass candidate) {
+ for(NamedClass nc : existingClasses) {
+ if(sh.isSubclassOf(nc, candidate))
+ return false;
+ }
+ return true;
+ }
+
private boolean isDisjoint(Description d1, Description d2) {
// check whether we have cached this query
Map<Description,Boolean> tmp = cachedDisjoints.get(d1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-08-08 14:02:50
|
Revision: 1059
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1059&view=rev
Author: jenslehmann
Date: 2008-08-08 14:02:47 +0000 (Fri, 08 Aug 2008)
Log Message:
-----------
EL downward refinement operator continued
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-08 11:38:27 UTC (rev 1058)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-08 14:02:47 UTC (rev 1059)
@@ -46,6 +46,13 @@
}
/**
+ * @param label the label to set
+ */
+ public void setLabel(ObjectProperty label) {
+ this.label = label;
+ }
+
+ /**
* @return The label of this edge.
*/
public ObjectProperty getLabel() {
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-08 11:38:27 UTC (rev 1058)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-08 14:02:47 UTC (rev 1059)
@@ -177,14 +177,35 @@
}
/**
- * Each node is assigned a number within the tree.
- * TODO add explanation how this is done
+ * Gets a list describing the position of this node within the
+ * tree. If the list is e.g. [2,5,1], then the node can be reached
+ * by picking the second child of the root node, then picking the
+ * 5th child of this node and finally selecting the first child of
+ * the previous node.
* @return The position number of this node within the tree as described above.
*/
- public int getCurrentPositionNumber() {
- return 0;
+ public int[] getCurrentPosition() {
+ int[] position = new int[level];
+ ELDescriptionNode root = this;
+ while(root.parent != null) {
+ position[root.level-1] = getChildNumber();
+ root = parent;
+ }
+ return position;
}
+ // returns the child number of this node, i.e. whether it is
+ // the first, second, third etc. child
+ private int getChildNumber() {
+ int count = 0;
+ for(ELDescriptionEdge edge : parent.edges) {
+ if(edge.getTree() == this) {
+ return count;
+ }
+ }
+ throw new RuntimeException("Inconsistent tree. Child tree not reachable from parent.");
+ }
+
/**
* Replaces an entry in the node label.
* @param oldClass Class to remove from label.
@@ -196,7 +217,16 @@
}
/**
- * Gets the label of this node. Do not modify the returned object.
+ * Adds an entry to the node label.
+ * @param newClass Class to add to label.
+ */
+ public void extendLabel(NamedClass newClass) {
+ label.add(newClass);
+ }
+
+ /**
+ * Gets the label of this node. Do not modify the returned object,
+ * but use the provided methods instead!
* @return The label of root node of this subtree.
*/
public SortedSet<NamedClass> getLabel() {
@@ -204,14 +234,16 @@
}
/**
- * @return The outgoing edges of this subtree. Do not modify the
- * returned object.
+ * Gets the edges of this node. Do not modify the
+ * returned object, but use the provided methods instead!
+ * @return The outgoing edges of this subtree.
*/
public List<ELDescriptionEdge> getEdges() {
return edges;
}
/**
+ * Gets the level (distance from root) of this node.
* @return The level of the (root node of) this subtree in the overall tree.
*/
public int getLevel() {
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-08 11:38:27 UTC (rev 1058)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-08 14:02:47 UTC (rev 1059)
@@ -113,36 +113,20 @@
}
/**
- * Selects a sub tree.
- * @param positionNumber A position in the tree. Positions are iteratively given to nodes
- * by leftmost depth-first search. This allows efficient selection of subtrees.
- * (TODO: Implementation does not work if any node has more than two children
- * like conjunction and disjunction.)
- * @return The selected subtree.
+ * Gets the node at the given position. The list is processed
+ * as follows: Starting with the root node, the first element i of
+ * list is read and the i-th child of root node is selected. This
+ * node is set as current node and the next element j of the list
+ * is read and the j-th child of the i-th child of the root node
+ * selected etc.
+ * @return The node at the specified position.
*/
- public Description getNode(int positionNumber) {
-// if (children.size() == 0)
-// return this;
-// else if (children.size() == 1) {
-// if (positionNumber == 0)
-// return this;
-// else
-// return children.get(0).getSubtree(positionNumber - 1);
-// }
-// // arity 2
-// else {
-// // we have found it
-// if (positionNumber == 0)
-// return this;
-// // left subtree
-// int leftTreeNodes = children.get(0).getNumberOfNodes();
-// if (positionNumber <= leftTreeNodes)
-// return children.get(0).getSubtree(positionNumber - 1);
-// // right subtree
-// else
-// return children.get(1).getSubtree(positionNumber - leftTreeNodes - 1);
-// }
- return null;
+ public ELDescriptionNode getNode(int[] position) {
+ ELDescriptionNode currentNode = rootNode;
+ for(int i=0; i<position.length; i++) {
+ currentNode = currentNode.getEdges().get(position[i]).getTree();
+ }
+ return currentNode;
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-08 11:38:27 UTC (rev 1058)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-08 14:02:47 UTC (rev 1059)
@@ -22,8 +22,11 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.SortedSet;
import java.util.TreeMap;
+import java.util.TreeSet;
+import org.dllearner.algorithms.el.ELDescriptionEdge;
import org.dllearner.algorithms.el.ELDescriptionNode;
import org.dllearner.algorithms.el.ELDescriptionTree;
import org.dllearner.core.ReasoningService;
@@ -118,11 +121,21 @@
}
private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) {
- Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ // the set of all refinements, which we will return
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ // the position of the node within the tree (needed for getting
+ // the corresponding node in a cloned tree)
+ int[] position = node.getCurrentPosition();
+
// option 1: label extension
Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel());
for(NamedClass nc : candidates) {
-
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ ELDescriptionNode clonedNode = clonedTree.getNode(position);
+ // extend label
+ clonedNode.extendLabel(nc);
+ refinements.add(clonedTree);
}
// option 2: label refinement
// loop through all classes in label
@@ -130,22 +143,50 @@
// find all more special classes for the given label
for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) {
if(moreSpecial instanceof NamedClass) {
- // create refinements by replacing class
- ELDescriptionTree tmp = tree.clone();
- // TODO we need to find a way to get this node in
- // the cloned tree
-// tmp.replaceInLabel(nc, (NamedClass) moreSpecial);
- refinements.add(tmp);
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ ELDescriptionNode clonedNode = clonedTree.getNode(position);
+ // create refinements by replacing class
+ clonedNode.replaceInLabel(nc, (NamedClass) moreSpecial);
+ refinements.add(clonedTree);
}
}
}
// option 3: new edge
+ // TODO incomplete, it is still open how to construct this refinement !!
+ SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index);
+ Set<ObjectProperty> mgr = utility.computeMgr(appOPs);
+ for(ObjectProperty op : mgr) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ ELDescriptionNode clonedNode = clonedTree.getNode(position);
+ // add a new node and edge
+ ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>());
+ refinements.add(clonedTree);
+ }
// option 4: edge refinement
+ for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) {
+ ELDescriptionEdge edge = node.getEdges().get(edgeNumber);
+ ObjectProperty op = edge.getLabel();
+ // find all more special properties
+ for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ // find cloned edge and replace its label
+ ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber);
+ clonedEdge.setLabel(op2);
+ }
+ }
// option 5: child refinement
-
+ for(ELDescriptionEdge edge : node.getEdges()) {
+ // recursive call on child node and property range as index
+ Description range = rs.getRange(edge.getLabel());
+ refinements.addAll(refine(tree, edge.getTree(), range));
+ }
+
return refinements;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2008-08-13 17:39:28
|
Revision: 1065
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1065&view=rev
Author: kurzum
Date: 2008-08-13 17:39:19 +0000 (Wed, 13 Aug 2008)
Log Message:
-----------
removed some unnecessary classes, complete refactoring of SparqlQueryMaker
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java
trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java
trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java
trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java
trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java
trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java
trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java
trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java
Removed Paths:
-------------
trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -19,8 +19,9 @@
*/
package org.dllearner.kb.extraction;
+import org.dllearner.kb.sparql.SPARQLTasks;
import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlQueryType;
+import org.dllearner.kb.sparql.SparqlQueryMaker;
/**
* Stores all configuration settings. this class collects all configuration
@@ -30,8 +31,10 @@
*/
public class Configuration {
+ private SPARQLTasks sparqlTasks;
+
private SparqlEndpoint endpoint;
- private SparqlQueryType sparqlQueryType;
+ private SparqlQueryMaker sparqlQueryMaker;
private Manipulators manipulator;
// the following needs to be moved to
// class extraction algorithm or manipulator
@@ -43,11 +46,11 @@
public String cacheDir="cache";
public Configuration(SparqlEndpoint specificSparqlEndpoint,
- SparqlQueryType sparqlQueryType, Manipulators manipulator,
+ SparqlQueryMaker sparqlQueryMaker, Manipulators manipulator,
int recursiondepth, boolean getAllSuperClasses,
boolean closeAfterRecursion, String cacheDir) {
this.endpoint = specificSparqlEndpoint;
- this.sparqlQueryType = sparqlQueryType;
+ this.sparqlQueryMaker = sparqlQueryMaker;
this.manipulator = manipulator;
this.recursiondepth = recursiondepth;
this.getAllSuperClasses = getAllSuperClasses;
@@ -56,9 +59,9 @@
}
- public Configuration changeQueryType(SparqlQueryType sqt) {
+ public Configuration changeQueryType(SparqlQueryMaker sqm) {
// TODO must clone here
- return new Configuration(this.endpoint, sqt, this.manipulator,
+ return new Configuration(this.endpoint, sqm, this.manipulator,
this.recursiondepth, this.getAllSuperClasses,
this.closeAfterRecursion, this.cacheDir);
@@ -72,8 +75,8 @@
return endpoint;
}
- public SparqlQueryType getSparqlQueryType() {
- return sparqlQueryType;
+ public SparqlQueryMaker getSparqlQueryMaker() {
+ return sparqlQueryMaker;
}
public boolean isGetAllSuperClasses() {
@@ -87,13 +90,18 @@
public int getRecursiondepth() {
return recursiondepth;
}
+
+ public SPARQLTasks getSparqlTasks() {
+ return sparqlTasks;
+ }
- public void increaseNumberOfuncachedSparqlQueries() {
+
+ /*public void increaseNumberOfuncachedSparqlQueries() {
numberOfUncachedSparqlQueries++;
}
public void increaseNumberOfCachedSparqlQueries() {
numberOfCachedSparqlQueries++;
- }
+ }*/
}
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -61,7 +61,8 @@
}
/**
- * most important function expands one example cave: the recursion is not a
+ * most important function expands one example
+ * CAVE: the recursion is not a
* recursion anymore, it was transformed to an iteration
*
* @param uri
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -26,7 +26,7 @@
import org.apache.log4j.Logger;
import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlQueryType;
+import org.dllearner.kb.sparql.SparqlQueryMaker;
import org.dllearner.utilities.statistics.Statistics;
/**
@@ -45,12 +45,12 @@
.getLogger(Manager.class);
- public void useConfiguration(SparqlQueryType SparqlQueryType,
+ public void useConfiguration(SparqlQueryMaker sparqlQueryMaker,
SparqlEndpoint SparqlEndpoint, Manipulators manipulator,
int recursiondepth, boolean getAllSuperClasses,
boolean closeAfterRecursion, String cacheDir) {
- this.configuration = new Configuration(SparqlEndpoint, SparqlQueryType,
+ this.configuration = new Configuration(SparqlEndpoint, sparqlQueryMaker,
manipulator, recursiondepth, getAllSuperClasses,
closeAfterRecursion, cacheDir);
//System.out.println(this.configuration);
@@ -111,7 +111,7 @@
}
public void addPredicateFilter(String str) {
- this.configuration.getSparqlQueryType().addPredicateFilter(str);
+ this.configuration.getSparqlQueryMaker().addPredicateFilter(str);
}
Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -0,0 +1,112 @@
+package org.dllearner.kb.extraction;
+
+/**
+ * this class collects old source code and will be removed after refactoring
+ * @author Sebastian Hellmann
+ *
+ */
+public class Scrap {
+
+ /*
+ public String makeRoleQueryUsingFilters(String role) {
+
+ String Filter = internalFilterAssemblyRole();
+ String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role
+ + "> ?object. " + lineend + "FILTER( " + lineend + "(" + Filter
+ + ").}";
+ // System.out.println(ret);
+
+ return ret;
+ }
+ */
+
+ /*
+ public String makeRoleQueryUsingFilters(String role, boolean domain) {
+
+ String Filter = internalFilterAssemblyRole();
+ String ret = "";
+ if (domain) {
+ ret = "SELECT * WHERE { " + lineend + "?subject <" + role
+ + "> ?object; a []. " + lineend + "FILTER( " + lineend
+ + "(" + Filter + ").}";
+ // "ORDER BY ?subject";
+ // System.out.println(ret);
+ } else {
+ ret = "SELECT * WHERE { " + lineend + "?object a [] . "
+ + "?subject <" + role + "> ?object . " + lineend
+ + "FILTER( " + lineend + "(" + Filter + ").}";
+ // "ORDER BY ?object";
+
+ }
+ // System.out.println(ret);
+
+ return ret;
+ }*/
+
+
+ /*
+ *
+ private String internalFilterAssemblyRole() {
+
+ String Filter = "";
+ if (!this.sparqlQueryType.isLiterals())
+ Filter += "!isLiteral(?object))";
+ for (String s : sparqlQueryType.getObjectfilterlist()) {
+ Filter += lineend + filterSubject(s);
+ }
+ for (String o : sparqlQueryType.getObjectfilterlist()) {
+ Filter += lineend + filterObject(o);
+ }
+ return Filter;
+ }*/
+
+
+ /*
+ * creates a query with the specified filters for all triples with subject
+ *
+ * @param subject
+ * the searched subject
+ * @param sf
+ * special object encapsulating all options
+ * @return sparql query
+
+ /*
+ * public static String makeQueryFilter(String subject, oldSparqlFilter sf) {
+ *
+ * String Filter = ""; if (!sf.useLiterals) Filter += "!isLiteral(?object)";
+ * for (String p : sf.getPredFilter()) { Filter += "\n" +
+ * filterPredicate(p); } for (String o : sf.getObjFilter()) { Filter += "\n" +
+ * filterObject(o); }
+ *
+ * String ret = "SELECT * WHERE { \n" + "<" + subject + "> ?predicate
+ * ?object.\n"; if (!(Filter.length() == 0)) ret += "FILTER( \n" + "(" +
+ * Filter + "))."; ret += "}"; // System.out.println(ret); return ret; }
+ */
+
+ /*
+ * moved to SparqlQuery remove here creates a query for subjects with
+ * the specified label @param label a phrase that is part of the label of a
+ * subject @param limit this limits the amount of results @return
+ *
+ * @Deprecated public static String makeLabelQuery(String label,int limit){
+ * // maybe use http://xmlns:com/foaf/0.1/page return
+ * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject
+ * <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object
+ * bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; }
+ *
+ *
+ * creates a query for all subjects that are of the type concept @param
+ * concept the type that subjects are searched for @return
+ *
+ *
+ * moved to SparqlQuery remove here
+ * @Deprecated public static String makeConceptQuery(String concept){ return
+ * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject a
+ * <"+concept+">}\n"; } moved to SparqlQuery remove here
+ * @Deprecated public static String makeArticleQuery(String subject){ return
+ * "SELECT ?predicate,?object\n"+ "WHERE { <"+subject+">
+ * ?predicate ?object}\n"; }
+ */
+
+
+}
Added: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -0,0 +1,124 @@
+/**
+ * Copyright (C) 2007, Sebastian Hellmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.kb.extraction;
+
+import java.net.URI;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.log4j.Logger;
+import org.dllearner.kb.sparql.Cache;
+import org.dllearner.kb.sparql.SparqlQuery;
+import org.dllearner.kb.sparql.SparqlQueryMaker;
+import org.dllearner.utilities.datastructures.StringTuple;
+
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.query.ResultSetFormatter;
+import com.hp.hpl.jena.sparql.core.ResultBinding;
+
+/**
+ * Can execute different queries.
+ *
+ * @author Sebastian Hellmann
+ *
+ */
+public class SparqlTupelAquisitor extends TupelAquisitor {
+
+ private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class);
+
+
+ //boolean print_flag = false;
+ private Configuration configuration;
+ private SparqlQueryMaker sparqlQueryMaker;
+ Cache cache;
+
+ // boolean debug_no_cache = false;// true means no cache is used
+ // private SparqlHTTPRequest SparqlHTTPRequest;
+ // private SparqlQuery sparqlQuery;
+ // private CachedSparqlQuery cachedSparqlQuery;
+
+ public SparqlTupelAquisitor(Configuration Configuration) {
+ this.configuration = Configuration;
+ /*this.sparqlQueryMaker = new SparqlQueryMaker(Configuration
+ .getSparqlQueryType());
+ */
+ this.cache = new Cache(configuration.cacheDir);
+ // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint());
+ // this.cachedSparqlQuery=new
+ // CachedSparqlQuery(this.sparqlQuery,this.cache);
+ }
+
+ // standard query get a tupels (p,o) for subject s
+ /**
+ * uses a cache and gets the result tuples for a resource u
+ *
+ * @param uri
+ * the resource
+ * @param sparqlQueryString
+ * @param a
+ * the name of the first bound variable for xml parsing, normally
+ * predicate
+ * @param b
+ * the name of the second bound variable for xml parsing,
+ * normally object
+ * @return
+ */
+ @Override
+ @SuppressWarnings({"unchecked"})
+ public SortedSet<StringTuple> getTupelForResource(URI uri) {
+ SortedSet<StringTuple> s = new TreeSet<StringTuple>();
+
+ String a = "predicate";
+ String b = "object";
+ // getQuery
+ String sparqlQueryString = sparqlQueryMaker
+ .makeSubjectQueryUsingFilters(uri.toString());
+
+// CachedSparqlQuery csq = new CachedSparqlQuery(configuration
+// .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString);
+
+ SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint());
+// query.extraDebugInfo=uri.toString();
+ String JSON = cache.executeSparqlQuery(query);
+
+ ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON);
+
+ List<ResultBinding> l = ResultSetFormatter.toList(rs);
+
+ logger.trace(l.toString());
+ for (ResultBinding resultBinding : l) {
+
+ s.add(new StringTuple(resultBinding.get(a).toString(),
+ resultBinding.get(b).toString()));
+ }
+ return s;
+ }
+
+
+
+
+
+
+
+
+
+
+}
Added: trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -0,0 +1,41 @@
+/**
+ * Copyright (C) 2007, Sebastian Hellmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.kb.extraction;
+
+import java.net.URI;
+import java.util.SortedSet;
+
+import org.dllearner.utilities.datastructures.StringTuple;
+
+/**
+ *
+ * Typed SPARQL query interface. The typing means that they all have the same
+ * input and the same output: They are fn: resource -> ( a | b ) where a
+ * normally is a predicate and b an object
+ *
+ * @author Sebastian Hellmann
+ *
+ */
+public abstract class TupelAquisitor {
+
+ public abstract SortedSet<StringTuple> getTupelForResource(URI u);
+}
+
+
Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -58,8 +58,7 @@
public TypedSparqlQuery(Configuration Configuration) {
this.configuration = Configuration;
- this.sparqlQueryMaker = new SparqlQueryMaker(Configuration
- .getSparqlQueryType());
+ this.sparqlQueryMaker =Configuration.getSparqlQueryMaker();
this.cache = new Cache(configuration.cacheDir);
// this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint());
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -29,6 +29,8 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.apache.log4j.Logger;
import org.dllearner.core.KnowledgeSource;
@@ -75,8 +77,8 @@
private String predefinedFilter = null;
private String predefinedEndpoint = null;
private String predefinedManipulator = "STANDARD";
- private Set<String> predList = new HashSet<String>();
- private Set<String> objList = new HashSet<String>();
+ private SortedSet<String> predList = new TreeSet<String>();
+ private SortedSet<String> objList = new TreeSet<String>();
// private Set<String> classList;
private String format = "N-TRIPLES";
private boolean dumpToFile = true;
@@ -216,9 +218,9 @@
} else if (option.equals("recursionDepth")) {
recursionDepth = (Integer) entry.getValue();
} else if (option.equals("predList")) {
- predList = (Set<String>) entry.getValue();
+ predList = (SortedSet<String>) entry.getValue();
} else if (option.equals("objList")) {
- objList = (Set<String>) entry.getValue();
+ objList = (SortedSet<String>) entry.getValue();
// } else if (option.equals("classList")) {
// classList = (Set<String>) entry.getValue();
} else if (option.equals("predefinedEndpoint")) {
@@ -299,7 +301,7 @@
*/
Manager m = new Manager();
- SparqlQueryType sparqlQueryType = null;
+ SparqlQueryMaker sparqlQueryMaker = null;
// get Options for Manipulator
Manipulators manipulator = ManipulatorType.getManipulatorByName(predefinedManipulator, blankNodeIdentifier,
breakSuperClassRetrievalAfter, replacePredicate, replaceObject);
@@ -317,16 +319,15 @@
// get Options for Filters
if (predefinedFilter != null) {
- sparqlQueryType = SparqlQueryType
- .getFilterByName(predefinedFilter);
+ sparqlQueryMaker = SparqlQueryMaker.getSparqlQueryMakerByName(predefinedFilter);
} else {
- sparqlQueryType = new SparqlQueryType("forbid", objList, predList,
+ sparqlQueryMaker = new SparqlQueryMaker("forbid", objList, predList,
useLits);
}
// give everything to the manager
- m.useConfiguration(sparqlQueryType, endpoint, manipulator,
+ m.useConfiguration(sparqlQueryMaker, endpoint, manipulator,
recursionDepth, getAllSuperClasses, closeAfterRecursion, cacheDir);
String ont = "";
Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -19,7 +19,12 @@
*/
package org.dllearner.kb.sparql;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
/**
* Can assemble sparql queries. can make queries for subject, predicate, object
* according to the filter settings object SparqlQueryType, which gives the
@@ -29,135 +34,376 @@
*
*/
public class SparqlQueryMaker {
- String lineend = "\n";
- boolean print_flag = false;
- private SparqlQueryType sparqlQueryType;
+
+ private static final String MODE_ALLOW = "allow";
+ private static final String MODE_FORBID = "forbid";
+ private static final String lineend = "\n";
+
+ //allow false is forbid
+ private boolean allowMode = false;
+ private boolean assembled = false;
+ private String filter = "";
+ private SortedSet<String> objectFilterList;
+ private SortedSet<String> predicateFilterList;
+ private boolean literals = false;
+
+
+ public SparqlQueryMaker(SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList,
+ boolean literals) {
+ super();
+ this.objectFilterList = objectFilterList;
+ this.predicateFilterList = predicateFilterList;
+ this.literals = literals;
+ }
+
+
+ public SparqlQueryMaker(boolean allowMode, SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList,
+ boolean literals) {
- public SparqlQueryMaker(SparqlQueryType SparqlQueryType) {
- this.sparqlQueryType = SparqlQueryType;
+ this(objectFilterList,predicateFilterList,literals);
+ this.allowMode = allowMode;
}
+
+ public SparqlQueryMaker(String mode, SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList,
+ boolean literals) {
+ this(objectFilterList,predicateFilterList,literals);
+ if( mode.equalsIgnoreCase(MODE_ALLOW)) {
+ this.allowMode = true;
+ } else if(mode.equalsIgnoreCase(MODE_FORBID)) {
+ this.allowMode = false;
+ } else {
+ this.allowMode = false;
+ }
+ }
+
public String makeSubjectQueryUsingFilters(String subject) {
- String Filter = internalFilterAssemblySubject();
- String ret="";
- if (Filter.length()>0) ret = "SELECT * WHERE { " + lineend + "<" + subject
- + "> ?predicate ?object. " + lineend + "FILTER( " + lineend
- + Filter + ").}";
- else ret="SELECT * WHERE { " + lineend + "<" + subject
- + "> ?predicate ?object}";
- // System.out.println("Query: "+ret);
- // System.out.println(sparqlQueryType.getPredicatefilterlist().length);
- return ret;
+ //String filter = internalFilterAssemblySubject();
+ if (!assembled) {
+ filter = internalFilterAssemblySubject("predicate", "object");
+ filter = (filter.length()>0) ? "FILTER( " + lineend + filter + "). " : " ";
+ assembled = true;
+ }
+
+ String returnString="SELECT * WHERE { " + lineend + "<" + subject
+ + "> ?predicate ?object. " + lineend + filter +" } ";
+
+ return returnString;
}
+
+ private String internalFilterAssemblySubject(String predicateVariable, String objectVariable) {
+ predicateVariable = (predicateVariable.startsWith("?")) ? predicateVariable : "?"+predicateVariable ;
+ objectVariable = (objectVariable.startsWith("?")) ? objectVariable : "?"+objectVariable ;
+
+ List<String> terms = new ArrayList<String>();
+ if(!isLiterals()) { terms.add("!isLiteral("+objectVariable+")"); }
+ String not = (isAllowMode())? "" : "!" ;
+ for (String pred : getPredicateFilterList()) {
+ terms.add( not + "regex(str("+predicateVariable+"), '" + pred + "')" );
+ }
+ for (String obj : getObjectFilterList()) {
+ terms.add( not + "regex(str("+objectVariable+"), '" + obj + "')" );
+ }
+
+ return assembleTerms( terms);
+
+ }
+
+ private String assembleTerms(List<String> terms){
+ if(terms.isEmpty()) return "";
+ else if(terms.size() == 1 ) return brackets(terms.get(0));
+ else {
+ StringBuffer sbuf = new StringBuffer(1400);
+ String operator = (isAllowMode()) ? "||" : "&&";
+ String first = terms.remove(0);
+ sbuf.append(brackets(first));
+ for (String term : terms) {
+ sbuf.append(lineend+operator);
+ sbuf.append(brackets(term));
+ }
+ return brackets(sbuf.toString());
+ }
+
+ }
+
+ private static String brackets(String s){
+ return "("+s+")";
+ }
+
- /**
- *
- * @param role
- * @return
- */
- public String makeRoleQueryUsingFilters(String role) {
- String Filter = internalFilterAssemblyRole();
- String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role
- + "> ?object. " + lineend + "FILTER( " + lineend + "(" + Filter
- + ").}";
- // System.out.println(ret);
+
+ public boolean isLiterals() {
+ return literals;
+ }
- return ret;
+ public boolean isAllowMode() {
+ return allowMode;
}
- public String makeRoleQueryUsingFilters(String role, boolean domain) {
+ public SortedSet<String> getObjectFilterList() {
+ return objectFilterList;
+ }
- String Filter = internalFilterAssemblyRole();
- String ret = "";
- if (domain) {
- ret = "SELECT * WHERE { " + lineend + "?subject <" + role
- + "> ?object; a []. " + lineend + "FILTER( " + lineend
- + "(" + Filter + ").}";
- // "ORDER BY ?subject";
- // System.out.println(ret);
- } else {
- ret = "SELECT * WHERE { " + lineend + "?object a [] . "
- + "?subject <" + role + "> ?object . " + lineend
- + "FILTER( " + lineend + "(" + Filter + ").}";
- // "ORDER BY ?object";
+ public SortedSet<String> getPredicateFilterList() {
+ return predicateFilterList;
+ }
+ public void addPredicateFilter(String newFilter) {
+ assembled = false;
+ predicateFilterList.add(newFilter);
+ }
+
+
+
+public static SparqlQueryMaker getSparqlQueryMakerByName(String name) {
+
+ if (name.equalsIgnoreCase("YAGO"))
+ return getYAGOFilter();
+ else if (name.equalsIgnoreCase("SKOS"))
+ return getSKOSFilter();
+ else if (name.equalsIgnoreCase("YAGOSKOS"))
+ return getYAGOSKOS();
+ else if (name.equalsIgnoreCase("YAGOSPECIALHIERARCHY"))
+ return getYagoSpecialHierarchyFilter();
+ else if (name.equalsIgnoreCase("TEST"))
+ return test();
+ else if (name.equalsIgnoreCase("DBPEDIA-NAVIGATOR"))
+ return getDBpediaNavigatorFilter();
+ else return null;
+ }
+
+
+ public static SparqlQueryMaker getYAGOFilter(){
+ SortedSet<String> pred = new TreeSet<String>();
+ pred.add("http://www.w3.org/2004/02/skos/core");
+ pred.add("http://www.w3.org/2002/07/owl#sameAs");
+ pred.add("http://xmlns.com/foaf/0.1/");
+ pred.add("http://dbpedia.org/property/reference");
+ pred.add("http://dbpedia.org/property/website");
+ pred.add("http://dbpedia.org/property/wikipage");
+ pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
+ pred.add("http://dbpedia.org/property/relatedInstance");
+ pred.add("http://dbpedia.org/property/owner");
+ pred.add("http://dbpedia.org/property/standard");
+
+ SortedSet<String> obj = new TreeSet<String>();
+ //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
+ //obj.add("http://dbpedia.org/resource/Category:Articles_");
+ obj.add("http://dbpedia.org/resource/Category:");
+ obj.add("http://dbpedia.org/resource/Template");
+ obj.add("http://xmlns.com/foaf/0.1/");
+ obj.add("http://upload.wikimedia.org/wikipedia/commons");
+ obj.add("http://upload.wikimedia.org/wikipedia");
+ obj.add("http://www.geonames.org");
+ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
+ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
+ obj.add("http://www.w3.org/2004/02/skos/core");
+
+ return new SparqlQueryMaker("forbid", obj, pred, false);
+ }
+
+ public static SparqlQueryMaker getDBpediaNavigatorFilter(){
+ SortedSet<String> pred = new TreeSet<String>();
+ pred.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
+ pred.add("http://www.w3.org/2000/01/rdf-schema#subClassOf");
+ pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat");
+ pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#long");
+ //pred.add("http://dbpedia.org/property/wikipage");
+ //pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
+ //pred.add("http://dbpedia.org/property/relatedInstance");
+ //pred.add("http://dbpedia.org/property/owner");
+ //pred.add("http://dbpedia.org/property/standard");
+ return new SparqlQueryMaker("allow", new TreeSet<String>(), pred , true);
}
- // System.out.println(ret);
+
+ public static SparqlQueryMaker getYagoSpecialHierarchyFilter(){
+ SortedSet<String> pred = new TreeSet<String>();
+ pred.add("http://www.w3.org/2004/02/skos/core");
+ pred.add("http://www.w3.org/2002/07/owl#sameAs");
+ pred.add("http://xmlns.com/foaf/0.1/");
+
+ pred.add("http://dbpedia.org/property/reference");
+ pred.add("http://dbpedia.org/property/website");
+ pred.add("http://dbpedia.org/property/wikipage");
+ pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
+ pred.add("http://dbpedia.org/property/relatedInstance");
+ pred.add("http://dbpedia.org/property/monarch");
+
- return ret;
- }
+ SortedSet<String> obj = new TreeSet<String>();
+ obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
+ obj.add("http://dbpedia.org/resource/Category:Articles_");
+ obj.add("http://dbpedia.org/resource/Template");
+ obj.add("http://xmlns.com/foaf/0.1/");
+ obj.add("http://upload.wikimedia.org/wikipedia/commons");
+ obj.add("http://upload.wikimedia.org/wikipedia");
+ obj.add("http://www.geonames.org");
+ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
+ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
+ obj.add("http://www.w3.org/2004/02/skos/core");
- private String internalFilterAssemblySubject() {
+ return new SparqlQueryMaker("forbid", obj, pred, false);
+ }
+
+
+ public static SparqlQueryMaker getSKOSFilter(){
+ SortedSet<String> pred = new TreeSet<String>();
+ //pred.add("http://www.w3.org/2004/02/skos/core");
+ pred.add("http://www.w3.org/2002/07/owl#sameAs");
+ pred.add("http://xmlns.com/foaf/0.1/");
+
+ pred.add("http://dbpedia.org/property/reference");
+ pred.add("http://dbpedia.org/property/website");
+ pred.add("http://dbpedia.org/property/wikipage");
+ pred.add("http://www.w3.org/2004/02/skos/core#narrower");
+ pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
- String Filter = "";
- if (!this.sparqlQueryType.isLiterals()){
- Filter += "(!isLiteral(?object))";
- if (sparqlQueryType.getPredicatefilterlist().size()>0)
- Filter += "&&(";
+ SortedSet<String> obj = new TreeSet<String>();
+ //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
+ //obj.add("http://dbpedia.org/resource/Category:Articles_");
+ obj.add("http://xmlns.com/foaf/0.1/");
+ obj.add("http://upload.wikimedia.org/wikipedia/commons");
+ obj.add("http://upload.wikimedia.org/wikipedia");
+
+ obj.add("http://www.geonames.org");
+ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
+ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
+
+
+ obj.add("http://dbpedia.org/class/yago");
+ obj.add("http://dbpedia.org/resource/Template");
+
+
+ return new SparqlQueryMaker("forbid", obj, pred, false);
}
- else if (sparqlQueryType.getPredicatefilterlist().size()>0)
- Filter += "(";
- int i=1;
- for (String p : sparqlQueryType.getPredicatefilterlist()) {
- if (this.sparqlQueryType.getMode()=="forbid")
- if (i!=1)
- Filter += lineend + filterPredicate(p);
- else
- Filter += lineend + filterPredicate(p).substring(2);
- else if (this.sparqlQueryType.getMode()=="allow")
- if (i!=1)
- Filter += lineend + allowPredicate(p);
- else
- Filter += lineend + allowPredicate(p).substring(2);
- i++;
- }
- if (sparqlQueryType.getPredicatefilterlist().size()>0)
- Filter += ")";
+ public static SparqlQueryMaker getYAGOSKOS(){
+ SortedSet<String> pred = new TreeSet<String>();
+ //pred.add("http://www.w3.org/2004/02/skos/core");
+ pred.add("http://www.w3.org/2002/07/owl#sameAs");
+ pred.add("http://xmlns.com/foaf/0.1/");
- if ((sparqlQueryType.getPredicatefilterlist().size()>0||!this.sparqlQueryType.isLiterals())&&sparqlQueryType.getObjectfilterlist().size()>0)
- Filter += "&&(";
- else if (sparqlQueryType.getObjectfilterlist().size()>0)
- Filter += "(";
- i=1;
- for (String o : sparqlQueryType.getObjectfilterlist()) {
- if (this.sparqlQueryType.getMode()=="forbid")
- if (i!=1)
- Filter += lineend + filterObject(o);
- else
- Filter += lineend + filterObject(o).substring(2);
- else if (this.sparqlQueryType.getMode()=="allow")
- if (i!=1)
- Filter += lineend + allowObject(o);
- else
- Filter += lineend + allowObject(o).substring(2);
- i++;
+ pred.add("http://dbpedia.org/property/reference");
+ pred.add("http://dbpedia.org/property/website");
+ pred.add("http://dbpedia.org/property/wikipage");
+ //pred.add("http://www.w3.org/2004/02/skos/core#narrower");
+ pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
+
+ SortedSet<String> obj = new TreeSet<String>();
+ //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
+ //obj.add("http://dbpedia.org/resource/Category:Articles_");
+ obj.add("http://xmlns.com/foaf/0.1/");
+ obj.add("http://upload.wikimedia.org/wikipedia/commons");
+ obj.add("http://upload.wikimedia.org/wikipedia");
+
+ obj.add("http://www.geonames.org");
+ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
+ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
+
+
+ //obj.add("http://dbpedia.org/class/yago");
+ obj.add("http://dbpedia.org/resource/Template");
+
+
+ return new SparqlQueryMaker("forbid", obj, pred, false);
+ }
+
+ public static SparqlQueryMaker test(){
+ SortedSet<String> pred = new TreeSet<String>();
+ pred.add("http://www.w3.org/2004/02/skos/core");
+ pred.add("http://www.w3.org/2002/07/owl#sameAs");
+ pred.add("http://xmlns.com/foaf/0.1/");
+ //pred.add("http://dbpedia.org/property/reference");
+ //pred.add("http://dbpedia.org/property/website");
+ //pred.add("http://dbpedia.org/property/wikipage");
+ pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
+ pred.add("http://dbpedia.org/property/relatedInstance");
+
+ SortedSet<String> obj = new TreeSet<String>();
+ //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
+ //obj.add("http://dbpedia.org/resource/Category:Articles_");
+ obj.add("http://dbpedia.org/resource/Category:");
+ obj.add("http://dbpedia.org/resource/Template");
+ obj.add("http://xmlns.com/foaf/0.1/");
+ obj.add("http://upload.wikimedia.org/wikipedia/commons");
+ obj.add("http://upload.wikimedia.org/wikipedia");
+ obj.add("http://www.geonames.org");
+ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
+ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
+ obj.add("http://www.w3.org/2004/02/skos/core");
+ return new SparqlQueryMaker("forbid", obj, pred, false);
}
- if (sparqlQueryType.getObjectfilterlist().size()>0)
- Filter += ")";
+
+
+ public static void main(String[] args){
- return Filter;
+ String uri = "http://dbpedia.org/resource/Angela_Merkel";
+ System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri));
+ System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri).length());
+ System.out.println(getDBpediaNavigatorFilter().makeSubjectQueryUsingFilters(uri));
+
+
}
+
+ /*
+ private String internalFilterAssemblySubject() {
- private String internalFilterAssemblyRole() {
-
- String Filter = "";
- if (!this.sparqlQueryType.isLiterals())
- Filter += "!isLiteral(?object))";
- for (String s : sparqlQueryType.getObjectfilterlist()) {
- Filter += lineend + filterSubject(s);
+ boolean emptyPredicateFilter = getPredicateFilterList().isEmpty();
+ boolean emptyObjectFilter = getObjectFilterList().isEmpty();
+
+ String filterString = "";
+ if (!isLiterals()) {
+ filterString += "(!isLiteral(?object))";
+ if (!getPredicateFilterList().isEmpty()) {
+ filterString += "&&(";
+ }
+
+ } else if (!emptyPredicateFilter) {
+ filterString += "(";
}
- for (String o : sparqlQueryType.getObjectfilterlist()) {
- Filter += lineend + filterObject(o);
+ boolean firstRun = true;
+ for (String p : getPredicateFilterList()) {
+ filterString += lineend;
+ filterString += (firstRun) ? handlePredicate(p).substring(2) : handlePredicate(p);
+ firstRun = false;
}
- return Filter;
- }
+ if (!emptyPredicateFilter) {
+ filterString += ")";
+ }
+ if ((!emptyPredicateFilter || !isLiterals()) && !emptyObjectFilter) {
+ filterString += "&&(";
+ }else if (!emptyObjectFilter) {
+ filterString += "(";
+ }
+
+ firstRun = true;
+ for (String o : getObjectFilterList()) {
+ filterString += lineend;
+ filterString += (firstRun) ? handleObject(o).substring(2) : handleObject(o) ;
+ firstRun = false;
+ }
+ if (!emptyObjectFilter){
+ filterString += ")";
+ }
+
+ return filterString;
+ }*/
+ /*
private String filterSubject(String ns) {
return "&&( !regex(str(?subject), '" + ns + "') )";
}
+
+ private String handlePredicate (String ns) {
+ return (isAllowMode()) ? allowPredicate(ns) : filterPredicate(ns) ;
+ }
+
+ private String handleObject (String ns) {
+ return (isAllowMode()) ? allowObject(ns) : filterObject(ns) ;
+ }
+
private static String filterPredicate(String ns) {
return "&&( !regex(str(?predicate), '" + ns + "') )";
}
@@ -173,57 +419,6 @@
private static String allowObject(String ns) {
return "||( regex(str(?object), '" + ns + "') )";
}
+*/
- /*private void p(String str) {
- if (print_flag) {
- System.out.println(str);
- }
- }*/
-
- /**
- * creates a query with the specified filters for all triples with subject
- *
- * @param subject
- * the searched subject
- * @param sf
- * special object encapsulating all options
- * @return sparql query
- */
- /*
- * public static String makeQueryFilter(String subject, oldSparqlFilter sf) {
- *
- * String Filter = ""; if (!sf.useLiterals) Filter += "!isLiteral(?object)";
- * for (String p : sf.getPredFilter()) { Filter += "\n" +
- * filterPredicate(p); } for (String o : sf.getObjFilter()) { Filter += "\n" +
- * filterObject(o); }
- *
- * String ret = "SELECT * WHERE { \n" + "<" + subject + "> ?predicate
- * ?object.\n"; if (!(Filter.length() == 0)) ret += "FILTER( \n" + "(" +
- * Filter + "))."; ret += "}"; // System.out.println(ret); return ret; }
- */
-
- /*
- * moved to SparqlQuery TODO remove here creates a query for subjects with
- * the specified label @param label a phrase that is part of the label of a
- * subject @param limit this limits the amount of results @return
- *
- * @Deprecated public static String makeLabelQuery(String label,int limit){
- * //TODO maybe use http://xmlns:com/foaf/0.1/page return
- * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject
- * <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object
- * bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; }
- *
- *
- * creates a query for all subjects that are of the type concept @param
- * concept the type that subjects are searched for @return
- *
- *
- * moved to SparqlQuery TODO remove here
- * @Deprecated public static String makeConceptQuery(String concept){ return
- * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject a
- * <"+concept+">}\n"; } moved to SparqlQuery TODO remove here
- * @Deprecated public static String makeArticleQuery(String subject){ return
- * "SELECT ?predicate,?object\n"+ "WHERE { <"+subject+">
- * ?predicate ?object}\n"; }
- */
-}
+ }
Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -1,254 +0,0 @@
-/**
- * Copyright (C) 2007, Sebastian Hellmann
- *
- * This file is part of DL-Learner.
- *
- * DL-Learner is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * DL-Learner is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.dllearner.kb.sparql;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Is used to set the filter: configuration.
- *
- * @author Sebastian Hellmann
- *
- */
-public class SparqlQueryType {
-
- private String mode = "forbid";
- private Set<String> objectfilterlist;
- private Set<String> predicatefilterlist;
- private boolean literals = false;
-
- public SparqlQueryType(String mode, Set<String> obectfilterlist, Set<String> predicatefilterlist,
- boolean literals) {
- super();
- this.mode = mode;
- this.objectfilterlist = obectfilterlist;
- this.predicatefilterlist = predicatefilterlist;
- this.literals = literals;
- }
-
- public boolean isLiterals() {
- return literals;
- }
-
- public String getMode() {
- return mode;
- }
-
- public Set<String> getObjectfilterlist() {
- return objectfilterlist;
- }
-
- public Set<String> getPredicatefilterlist() {
- return predicatefilterlist;
- }
-
- public void addPredicateFilter(String filter) {
- predicatefilterlist.add(filter);
- //System.out.println("added filter: "+filter);
- }
-
- public static SparqlQueryType getFilterByName(String name) {
-
-
- if (name.equals("YAGO"))
- return YagoFilter();
- if (name.equals("SKOS"))
- return SKOS();
- if (name.equals("YAGOSKOS"))
- return YAGOSKOS();
- if (name.equals("YAGOSPECIALHIERARCHY"))
- return YagoSpecialHierarchy();
- if (name.equals("TEST"))
- return test();
- if (name.equals("DBPEDIA-NAVIGATOR"))
- return DBpediaNavigatorFilter();
-
- return null;
- }
-
-
- public static SparqlQueryType YagoFilter(){
- Set<String> pred = new HashSet<String>();
- pred.add("http://www.w3.org/2004/02/skos/core");
- pred.add("http://www.w3.org/2002/07/owl#sameAs");
- pred.add("http://xmlns.com/foaf/0.1/");
- pred.add("http://dbpedia.org/property/reference");
- pred.add("http://dbpedia.org/property/website");
- pred.add("http://dbpedia.org/property/wikipage");
- pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
- pred.add("http://dbpedia.org/property/relatedInstance");
- pred.add("http://dbpedia.org/property/owner");
- pred.add("http://dbpedia.org/property/standard");
-
- Set<String> obj = new HashSet<String>();
- //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
- //obj.add("http://dbpedia.org/resource/Category:Articles_");
- obj.add("http://dbpedia.org/resource/Category:");
- obj.add("http://dbpedia.org/resource/Template");
- obj.add("http://xmlns.com/foaf/0.1/");
- obj.add("http://upload.wikimedia.org/wikipedia/commons");
- obj.add("http://upload.wikimedia.org/wikipedia");
- obj.add("http://www.geonames.org");
- obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
- obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
- obj.add("http://www.w3.org/2004/02/skos/core");
-
- return new SparqlQueryType("forbid", obj, pred, false);
- }
-
- public static SparqlQueryType DBpediaNavigatorFilter(){
- Set<String> pred = new HashSet<String>();
- pred.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
- pred.add("http://www.w3.org/2000/01/rdf-schema#subClassOf");
- pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat");
- pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#long");
- //pred.add("http://dbpedia.org/property/wikipage");
- //pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
- //pred.add("http://dbpedia.org/property/relatedInstance");
- //pred.add("http://dbpedia.org/property/owner");
- //pred.add("http://dbpedia.org/property/standard");
-
- Set<String> obj = new HashSet<String>();
-
- return new SparqlQueryType("allow", obj, pred, true);
- }
-
- public static SparqlQueryType YagoSpecialHierarchy(){
- Set<String> pred = new HashSet<String>();
- pred.add("http://www.w3.org/2004/02/skos/core");
- pred.add("http://www.w3.org/2002/07/owl#sameAs");
- pred.add("http://xmlns.com/foaf/0.1/");
-
- pred.add("http://dbpedia.org/property/reference");
- pred.add("http://dbpedia.org/property/website");
- pred.add("http://dbpedia.org/property/wikipage");
- pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
- pred.add("http://dbpedia.org/property/relatedInstance");
- pred.add("http://dbpedia.org/property/monarch");
-
-
- Set<String> obj = new HashSet<String>();
- obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
- obj.add("http://dbpedia.org/resource/Category:Articles_");
- obj.add("http://dbpedia.org/resource/Template");
- obj.add("http://xmlns.com/foaf/0.1/");
- obj.add("http://upload.wikimedia.org/wikipedia/commons");
- obj.add("http://upload.wikimedia.org/wikipedia");
- obj.add("http://www.geonames.org");
- obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
- obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
- obj.add("http://www.w3.org/2004/02/skos/core");
-
- return new SparqlQueryType("forbid", obj, pred, false);
- }
-
-
- public static SparqlQueryType SKOS(){
- Set<String> pred = new HashSet<String>();
- //pred.add("http://www.w3.org/2004/02/skos/core");
- pred.add("http://www.w3.org/2002/07/owl#sameAs");
- pred.add("http://xmlns.com/foaf/0.1/");
-
- pred.add("http://dbpedia.org/property/reference");
- pred.add("http://dbpedia.org/property/website");
- pred.add("http://dbpedia.org/property/wikipage");
- pred.add("http://www.w3.org/2004/02/skos/core#narrower");
- pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
-
- Set<String> obj = new HashSet<String>();
- //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
- //obj.add("http://dbpedia.org/resource/Category:Articles_");
- obj.add("http://xmlns.com/foaf/0.1/");
- obj.add("http://upload.wikimedia.org/wikipedia/commons");
- obj.add("http://upload.wikimedia.org/wikipedia");
-
- obj.add("http://www.geonames.org");
- obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
- obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
-
-
- obj.add("http://dbpedia.org/class/yago");
- obj.add("http://dbpedia.org/resource/Template");
-
-
- return new SparqlQueryType("forbid", obj, pred, false);
- }
- public static SparqlQueryType YAGOSKOS(){
- Set<String> pred = new HashSet<String>();
- //pred.add("http://www.w3.org/2004/02/skos/core");
- pred.add("http://www.w3.org/2002/07/owl#sameAs");
- pred.add("http://xmlns.com/foaf/0.1/");
-
- pred.add("http://dbpedia.org/property/reference");
- pred.add("http://dbpedia.org/property/website");
- pred.add("http://dbpedia.org/property/wikipage");
- //pred.add("http://www.w3.org/2004/02/skos/core#narrower");
- pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
-
- Set<String> obj = new HashSet<String>();
- //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
- //obj.add("http://dbpedia.org/resource/Category:Articles_");
- obj.add("http://xmlns.com/foaf/0.1/");
- obj.add("http://upload.wikimedia.org/wikipedia/commons");
- obj.add("http://upload.wikimedia.org/wikipedia");
-
- obj.add("http://www.geonames.org");
- obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
- obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
-
-
- //obj.add("http://dbpedia.org/class/yago");
- obj.add("http://dbpedia.org/resource/Template");
-
-
- return new SparqlQueryType("forbid", obj, pred, false);
- }
-
- public static SparqlQueryType test(){
- Set<String> pred = new HashSet<String>();
- pred.add("http://www.w3.org/2004/02/skos/core");
- pred.add("http://www.w3.org/2002/07/owl#sameAs");
- pred.add("http://xmlns.com/foaf/0.1/");
- //pred.add("http://dbpedia.org/property/reference");
- //pred.add("http://dbpedia.org/property/website");
- //pred.add("http://dbpedia.org/property/wikipage");
- pred.add("http://dbpedia.org/property/wikiPageUsesTemplate");
- pred.add("http://dbpedia.org/property/relatedInstance");
-
- Set<String> obj = new HashSet<String>();
- //obj.add("http://dbpedia.org/resource/Category:Wikipedia_");
- //obj.add("http://dbpedia.org/resource/Category:Articles_");
- obj.add("http://dbpedia.org/resource/Category:");
- obj.add("http://dbpedia.org/resource/Template");
- obj.add("http://xmlns.com/foaf/0.1/");
- obj.add("http://upload.wikimedia.org/wikipedia/commons");
- obj.add("http://upload.wikimedia.org/wikipedia");
- obj.add("http://www.geonames.org");
- obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset");
- obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr");
- obj.add("http://www.w3.org/2004/02/skos/core");
- return new SparqlQueryType("forbid", obj, pred, false);
- }
-
-
-
-
-}
Modified: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-08-13 13:12:03 UTC (rev 1064)
+++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -27,7 +27,7 @@
import org.dllearner.kb.extraction.Manager;
import org.dllearner.kb.extraction.Manipulator;
import org.dllearner.kb.sparql.SparqlEndpoint;
-import org.dllearner.kb.sparql.SparqlQueryType;
+import org.dllearner.kb.sparql.SparqlQueryMaker;
import org.dllearner.utilities.datastructures.StringTuple;
/**
@@ -48,8 +48,7 @@
// m.usePredefinedConfiguration(u);
URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel");
- m.useConfiguration(
- SparqlQueryType.getFilterByName("DBPEDIA"),SparqlEndpoint.getEndpointByName("YAGO"),
+ m.useConfiguration(SparqlQueryMaker.getSparqlQueryMakerByName("DBPEDIA"),SparqlEndpoint.getEndpointByName("YAGO"),
new Manipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()),
1,true,true,"cache");
//, ,
Added: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-13 17:39:19 UTC (rev 1065)
@@ -0,0 +1,17 @@
+package org.dllearner.utilities.owl;
+
+public class OWLVocabulary {
+
+ public static final String RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
+
+ public static final String RDFS_SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
+
+
+ public static final String OWL_SAME_AS = "http://www.w3.org/2002/07/owl#sameAs";
+// public static final String RDF_TYPE = "";
+// public static final String RDF_TYPE = "";
+// public static final String RDF_TYPE = "";
+// public static final String RDF_TYPE = "";
+// public static final String RDF_TYPE = "";
+// public static final String RDF_TYPE = "";
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-08-14 08:52:02
|
Revision: 1068
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1068&view=rev
Author: jenslehmann
Date: 2008-08-14 08:51:57 +0000 (Thu, 14 Aug 2008)
Log Message:
-----------
continued EL downward refinement; implemented unit test by Christoph; minor parser change
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/parser/KBParser.java
trunk/src/dl-learner/org/dllearner/parser/kb.jj
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-08-14 08:47:34 UTC (rev 1067)
+++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-08-14 08:51:57 UTC (rev 1068)
@@ -36,7 +36,7 @@
return parseConcept(string);
}
- public static KB parseKBFile(String content) throws IOException, ParseException {
+ public static KB parseKBFile(String content) throws ParseException {
KBParser parser = new KBParser(new StringReader(content));
return parser.KB();
}
Modified: trunk/src/dl-learner/org/dllearner/parser/kb.jj
===================================================================
--- trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-08-14 08:47:34 UTC (rev 1067)
+++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-08-14 08:51:57 UTC (rev 1068)
@@ -65,7 +65,7 @@
return parseConcept(string);
}
- public static KB parseKBFile(String content) throws IOException, ParseException {
+ public static KB parseKBFile(String content) throws ParseException {
KBParser parser = new KBParser(new StringReader(content));
return parser.KB();
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-14 08:47:34 UTC (rev 1067)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-14 08:51:57 UTC (rev 1068)
@@ -19,10 +19,14 @@
*/
package org.dllearner.refinementoperators;
+import java.util.Collection;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
+import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -117,10 +121,10 @@
* @return Set of refined EL description trees.
*/
public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
- return refine(tree, tree.getRootNode(), new Thing());
+ return refine(tree, tree.getRootNode(), new Thing(), true);
}
- private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) {
+ private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index, boolean minimize) {
// the set of all refinements, which we will return
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// the position of the node within the tree (needed for getting
@@ -157,39 +161,73 @@
// TODO incomplete, it is still open how to construct this refinement !!
SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index);
Set<ObjectProperty> mgr = utility.computeMgr(appOPs);
+ // temporary set of all concepts, which still have to pass the equivalence check
+ Stack<ELDescriptionTree> stack = new Stack<ELDescriptionTree>();
for(ObjectProperty op : mgr) {
// clone operation
ELDescriptionTree clonedTree = tree.clone();
ELDescriptionNode clonedNode = clonedTree.getNode(position);
// add a new node and edge
ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>());
- refinements.add(clonedTree);
+// refinements.add(clonedTree);
+ stack.add(clonedTree);
+
+ // recurse if concept is equivalent
+ // TODO: efficient equivalence check needs to be implemented !!
+ while(stack.size() != 0) {
+ // we pick an arbitrary tree and remove it from the stack
+ ELDescriptionTree testTree = stack.pop();
+ // test equivalence
+ boolean equivalent = false;
+ // TODO equivalence check
+ if(equivalent) {
+ // edge refinement
+ // we know that the edge we added is the last one for this node
+ int edgeNr = node.getEdges().size() - 1;
+ // all refinements of this edge are added to the stack
+ refineEdge(stack, tree, node, position, edgeNr);
+ // perform node refinements in non-minimize-mode
+ refinements.addAll(refineEdges(tree, newNode, position));
+ }
+ }
}
-
+
// option 4: edge refinement
- for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) {
- ELDescriptionEdge edge = node.getEdges().get(edgeNumber);
- ObjectProperty op = edge.getLabel();
- // find all more special properties
- for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) {
- // clone operation
- ELDescriptionTree clonedTree = tree.clone();
- // find cloned edge and replace its label
- ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber);
- clonedEdge.setLabel(op2);
- }
- }
-
+ refinements.addAll(refineEdges(tree, node, position));
+
// option 5: child refinement
for(ELDescriptionEdge edge : node.getEdges()) {
// recursive call on child node and property range as index
Description range = rs.getRange(edge.getLabel());
- refinements.addAll(refine(tree, edge.getTree(), range));
+ refinements.addAll(refine(tree, edge.getTree(), range, minimize));
}
return refinements;
}
+ private Set<ELDescriptionTree> refineEdges(ELDescriptionTree tree, ELDescriptionNode node, int[] position) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) {
+ refineEdge(refinements, tree, node, position, edgeNumber);
+ }
+ return refinements;
+ }
+
+ private void refineEdge(Collection<ELDescriptionTree> refinements, ELDescriptionTree tree, ELDescriptionNode node, int[] position, int edgeNumber) {
+ ELDescriptionEdge edge = node.getEdges().get(edgeNumber);
+ ObjectProperty op = edge.getLabel();
+ // find all more special properties
+ for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ // find cloned edge and replace its label
+ ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber);
+ clonedEdge.setLabel(op2);
+ refinements.add(clonedTree);
+ }
+ }
+
+
// private void computeMg(Description index) {
// // compute the applicable properties if this has not been done yet
// if(app.get(index) == null)
Added: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-08-14 08:51:57 UTC (rev 1068)
@@ -0,0 +1,115 @@
+/**
+ * Copyright (C) 2007-2008, Jens Lehmann
+ *
+ * This file is part of DL-Learner.
+ *
+ * DL-Learner is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DL-Learner is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package org.dllearner.test.junit;
+
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.dllearner.core.ComponentManager;
+import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.ReasoningService;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.KB;
+import org.dllearner.kb.KBFile;
+import org.dllearner.parser.KBParser;
+import org.dllearner.parser.ParseException;
+import org.dllearner.reasoning.FastInstanceChecker;
+import org.dllearner.refinementoperators.ELDown;
+import org.dllearner.utilities.owl.ConceptComparator;
+import org.dllearner.utilities.owl.ConceptTransformation;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests related to the EL downward refinement operator.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class ELDownTests {
+
+ /**
+ * Implementation of test case created by Christoph Haase for
+ * new operator.
+ *
+ * @throws ParseException Thrown if concept syntax does not correspond
+ * to current KB syntax.
+ */
+ @Test
+ public void refinementTest() throws ParseException {
+ ComponentManager cm = ComponentManager.getInstance();
+
+ // background knowledge
+ String kbString = "";
+ kbString += "OP_DOMAIN(hasChild) = human.";
+ kbString += "OP_RANGE(hasChild) = human.";
+ kbString += "OP_DOMAIN(hasPet) = human.";
+ kbString += "OP_RANGE(hasPet) = animal.";
+ kbString += "Subrole(hasChild, has).";
+ kbString += "Subrole(hasPet, has).";
+ kbString += "bird SUB animal.";
+ kbString += "cat SUB animal.";
+ kbString += "cat SUB animal.";
+ KB kb = KBParser.parseKBFile(kbString);
+
+ // input description
+ Description input = KBParser.parseConcept("human AND EXISTS has.animal");
+
+ // create reasoner
+ KBFile source = new KBFile(kb);
+ ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source);
+ ReasoningService rs = cm.reasoningService(rc);
+ ELDown operator = new ELDown(rs);
+
+ // desired refinements as strings
+ Set<String> desiredString = new TreeSet<String>();
+ desiredString.add("human AND EXISTS hasPet.animal");
+ desiredString.add("human AND EXISTS has.bird");
+ desiredString.add("human AND EXISTS has.cat");
+ desiredString.add("(human AND EXISTS hasPet.TOP) AND EXISTS has.animal");
+ desiredString.add("(human AND EXISTS hasChild.TOP) AND EXISTS has.animal");
+ desiredString.add("(human AND EXISTS hasPet.TOP) AND EXISTS has.animal");
+ desiredString.add("(human AND EXISTS has.person) AND EXISTS has.animal");
+ desiredString.add("(human AND EXISTS has.EXISTS has.TOP) AND EXISTS has.animal");
+ desiredString.add("human AND EXISTS has.(animal AND EXISTS has.TOP)");
+
+ ConceptComparator cc = new ConceptComparator();
+ SortedSet<Description> desired = new TreeSet<Description>(cc);
+ for(String str : desiredString) {
+ Description tmp = KBParser.parseConcept(str);
+ // eliminate conjunctions nested in other conjunctions
+ ConceptTransformation.cleanConcept(tmp);
+ desired.add(tmp);
+ }
+
+ // perform refinement and compare solutions
+ Set<Description> refinements = operator.refine(input);
+
+ // number of refinements has to be correct and each produced
+ // refinement must be in the set of desired refinements
+ assertTrue(refinements.size() == desired.size());
+ for(Description refinement : refinements) {
+ assertTrue(desired.contains(refinement));
+ }
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-08-14 08:47:34 UTC (rev 1067)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-08-14 08:51:57 UTC (rev 1068)
@@ -19,7 +19,6 @@
*/
package org.dllearner.test.junit;
-import java.io.IOException;
import java.util.List;
import org.apache.log4j.Logger;
@@ -61,8 +60,6 @@
KB kbObject = null;
try {
kbObject = KBParser.parseKBFile(kb);
- } catch (IOException e) {
- e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|