From: <sk...@us...> - 2008-06-10 15:52:33
|
Revision: 954 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=954&view=rev Author: sknappe Date: 2008-06-10 08:51:54 -0700 (Tue, 10 Jun 2008) Log Message: ----------- Added Manipulator Interface and changed classes accordingly Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 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/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2008-06-10 15:51:54 UTC (rev 954) @@ -152,6 +152,5 @@ @Override public Score getSolutionScore() { return learner.getSolutionScore(); - } - + } } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-06-10 15:51:54 UTC (rev 954) @@ -41,7 +41,7 @@ // expands all directly connected nodes @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { + public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { Set<StringTuple> s = tsq.getTupelForResource(this.uri); // see manipulator @@ -85,7 +85,7 @@ // gets the types for properties recursively @Override - public void expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { } /* Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-06-10 15:51:54 UTC (rev 954) @@ -32,7 +32,7 @@ private SparqlEndpoint endpoint; private SparqlQueryType sparqlQueryType; - private Manipulator manipulator; + private Manipulators manipulator; // the following needs to be moved to // class extraction algorithm or manipulator private int recursiondepth; @@ -43,7 +43,7 @@ public String cacheDir="cache"; public Configuration(SparqlEndpoint specificSparqlEndpoint, - SparqlQueryType sparqlQueryType, Manipulator manipulator, + SparqlQueryType sparqlQueryType, Manipulators manipulator, int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion, String cacheDir) { this.endpoint = specificSparqlEndpoint; @@ -64,7 +64,7 @@ } - public Manipulator getManipulator() { + public Manipulators getManipulator() { return this.manipulator; } Added: trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java 2008-06-10 15:51:54 UTC (rev 954) @@ -0,0 +1,120 @@ +/** + * 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.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * Used to manipulate retrieved tupels, identify blanknodes, etc. + * + * @author Sebastian Hellmann + * + */ +public class DBpediaNavigatorManipulator implements Manipulators{ + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + + public String blankNodeIdentifier = "bnode"; + public int breakSuperClassRetrievalAfter = 200; + public LinkedList<StringTuple> replacePredicate; + public LinkedList<StringTuple> replaceObject; + + // Set<String> classproperties; + + public DBpediaNavigatorManipulator(String blankNodeIdentifier, + int breakSuperClassRetrievalAfter, + LinkedList<StringTuple> replacePredicate, + LinkedList<StringTuple> replaceObject) { + this.blankNodeIdentifier = blankNodeIdentifier; + this.replaceObject = replaceObject; + this.replacePredicate = replacePredicate; + this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; + // Set<String> classproperties = new HashSet<String>(); + // classproperties.add(subclass); + + } + + /** + * this checks for consistency and manipulates the tuples, before they get + * triple + * + * @param tuples + * tuples for the node + * @param node + * @return + */ + public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { + Set<StringTuple> toRemove = new HashSet<StringTuple>(); + Iterator<StringTuple> it = tuples.iterator(); + while (it.hasNext()) { + StringTuple t = (StringTuple) it.next(); + + replacePredicate(t); + replaceObject(t); + + + // remove <rdf:type, owl:class> + // this is done to avoid transformation to owl:subclassof + if (t.a.equals(type) && t.b.equals(classns) + && node instanceof ClassNode) { + toRemove.add(t); + } + + // all with type class + if (t.b.equals(classns) && node instanceof ClassNode) { + toRemove.add(t); + } + + // remove all instances with owl:type thing + if (t.a.equals(type) && t.b.equals(thing) + && node instanceof InstanceNode) { + toRemove.add(t); + } + + } + tuples.removeAll(toRemove); + + return tuples; + } + + private void replacePredicate(StringTuple t) { + for (StringTuple rep : replacePredicate) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + } + + private void replaceObject(StringTuple t) { + for (StringTuple rep : replaceObject) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + } +} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-06-10 15:51:54 UTC (rev 954) @@ -34,7 +34,7 @@ public class ExtractionAlgorithm { private Configuration configuration; - private Manipulator manipulator; + private Manipulators manipulator; private int recursionDepth = 1; // private boolean getAllSuperClasses = true; // private boolean closeAfterRecursion = true; Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-06-10 15:51:54 UTC (rev 954) @@ -47,7 +47,7 @@ // expands all directly connected nodes @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { + public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { Set<StringTuple> s = tsq.getTupelForResource(uri); // see Manipulator @@ -86,7 +86,7 @@ // gets the types for properties recursively @Override - public void expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { for (PropertyNode one : properties) { one.expandProperties(tsq, m); } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-06-10 15:51:54 UTC (rev 954) @@ -47,7 +47,7 @@ public void useConfiguration(SparqlQueryType SparqlQueryType, - SparqlEndpoint SparqlEndpoint, Manipulator manipulator, + SparqlEndpoint SparqlEndpoint, Manipulators manipulator, int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion, String cacheDir) { Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2008-06-10 15:51:54 UTC (rev 954) @@ -32,7 +32,7 @@ * @author Sebastian Hellmann * */ -public class Manipulator { +public class Manipulator implements Manipulators{ public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; Added: trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java 2008-06-10 15:51:54 UTC (rev 954) @@ -0,0 +1,23 @@ +package org.dllearner.kb.extraction; + +import java.util.LinkedList; + +import org.dllearner.utilities.datastructures.StringTuple; + + +/** + * Used to get the right manipulator + * + * @author Sebastian Knappe + * + */ +public class ManipulatorType { + + public static Manipulators getManipulatorByName(String predefinedManipulator,String blankNodeIdentifier, int breakSuperClassRetrievalAfter, LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) + { + if (predefinedManipulator.equals("DBPEDIA-NAVIGATOR")) return new DBpediaNavigatorManipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + else return new Manipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + } +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java 2008-06-10 15:51:54 UTC (rev 954) @@ -0,0 +1,15 @@ +package org.dllearner.kb.extraction; + +import java.util.Set; + +import org.dllearner.utilities.datastructures.StringTuple; + +public interface Manipulators { + + public int breakSuperClassRetrievalAfter = 200; + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + public String blankNodeIdentifier = "bnode"; + + public Set<StringTuple> check(Set<StringTuple> tuples, Node node); +} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-06-10 15:51:54 UTC (rev 954) @@ -55,7 +55,7 @@ * @return Vector<Node> all Nodes that are new because of expansion */ public abstract Vector<Node> expand( - TypedSparqlQueryInterface typedSparqlQuery, Manipulator manipulator); + TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); /** * gets type defs for properties like rdf:type SymmetricProperties @@ -65,7 +65,7 @@ * @return Vector<Node> */ public abstract void expandProperties( - TypedSparqlQueryInterface typedSparqlQuery, Manipulator manipulator); + TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); /** * output Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-06-10 15:51:54 UTC (rev 954) @@ -53,13 +53,13 @@ // Property Nodes are normally not expanded, // this function is never called @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { + public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { return null; } // gets the types for properties recursively @Override - public void expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { b.expandProperties(tsq, m); Set<StringTuple> s = tsq.getTupelForResource(uri); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-06-10 15:51:54 UTC (rev 954) @@ -46,6 +46,8 @@ import org.dllearner.core.owl.KB; import org.dllearner.kb.extraction.Manager; import org.dllearner.kb.extraction.Manipulator; +import org.dllearner.kb.extraction.ManipulatorType; +import org.dllearner.kb.extraction.Manipulators; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; @@ -73,6 +75,7 @@ private int recursionDepth = recursionDepthDefault; 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 Set<String> classList; @@ -136,7 +139,8 @@ "the mode of the SPARQL Filter, use one of YAGO,SKOS,YAGOSKOS , YAGOSPECIALHIERARCHY, TEST")); options.add(new StringConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter, use one of DBPEDIA, LOCAL, GOVTRACK, REVYU, MYOPENLINK, FACTBOOK")); - + options.add(new StringConfigOption("predefinedManipulator", + "the mode of the Manipulator, use one of STANDARD, DBPEDIA-NAVIGATOR")); options.add(new StringSetConfigOption("predList", "list of all ignored roles")); options.add(new StringSetConfigOption("objList", @@ -220,6 +224,8 @@ predefinedEndpoint = ((String) entry.getValue()).toUpperCase(); } else if (option.equals("predefinedFilter")) { predefinedFilter = ((String) entry.getValue()).toUpperCase(); + } else if (option.equals("predefinedManipulator")) { + predefinedManipulator = ((String) entry.getValue()).toUpperCase(); } else if (option.equals("format")) { format = (String) entry.getValue(); } else if (option.equals("dumpToFile")) { @@ -292,7 +298,7 @@ Manager m = new Manager(); SparqlQueryType sparqlQueryType = null; // get Options for Manipulator - Manipulator manipulator = new Manipulator(blankNodeIdentifier, + Manipulators manipulator = ManipulatorType.getManipulatorByName(predefinedManipulator, blankNodeIdentifier, breakSuperClassRetrievalAfter, replacePredicate, replaceObject); // get Options for endpoints Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-10 15:48:27 UTC (rev 953) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-06-10 15:51:54 UTC (rev 954) @@ -23,6 +23,7 @@ import java.util.Set; import java.util.TreeSet; +import org.dllearner.algorithms.DBpediaNavigationSuggestor; import org.dllearner.algorithms.RandomGuesser; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; @@ -35,6 +36,7 @@ import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.reasoning.OWLAPIReasoner; /** * Test for component based design. @@ -55,12 +57,12 @@ // create knowledge source KnowledgeSource source = cm.knowledgeSource(OWLFile.class); - String example = "examples/family/father.owl"; + String example = "examples/family/uncle.owl"; cm.applyConfigEntry(source, "url", new File(example).toURI().toString()); source.init(); // create DIG reasoning service with standard settings - ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); + ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source); // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); reasoner.init(); ReasoningService rs = cm.reasoningService(reasoner); @@ -68,29 +70,31 @@ // create a learning problem and set positive and negative examples LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Set<String> positiveExamples = new TreeSet<String>(); - positiveExamples.add("http://example.com/father#stefan"); - positiveExamples.add("http://example.com/father#markus"); - positiveExamples.add("http://example.com/father#martin"); + positiveExamples.add("http://localhost/foo#heinz"); + positiveExamples.add("http://localhost/foo#alex"); Set<String> negativeExamples = new TreeSet<String>(); - negativeExamples.add("http://example.com/father#heinz"); - negativeExamples.add("http://example.com/father#anna"); - negativeExamples.add("http://example.com/father#michelle"); + negativeExamples.add("http://localhost/foo#jan"); + negativeExamples.add("http://localhost/foo#anna"); + negativeExamples.add("http://localhost/foo#hanna"); cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); + lp.init(); + // create the learning algorithm LearningAlgorithm la = null; try { - la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + la = cm.learningAlgorithm(DBpediaNavigationSuggestor.class, lp, rs); } catch (LearningProblemUnsupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } - cm.applyConfigEntry(la, "numberOfTrees", 100); - cm.applyConfigEntry(la, "maxDepth", 5); - la.init(); - + try{ + la.init(); + }catch (Exception e){ + } + // start the algorithm and print the best concept found la.start(); System.out.println(la.getBestSolution()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |