From: <ku...@us...> - 2007-12-04 17:08:51
|
Revision: 322 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=322&view=rev Author: kurzum Date: 2007-12-04 09:08:42 -0800 (Tue, 04 Dec 2007) Log Message: ----------- commented everything with a few lines, implemented replacement of skos, example will follow Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-04 17:08:42 UTC (rev 322) @@ -26,8 +26,10 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.Set; @@ -52,6 +54,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; +import org.dllearner.utilities.StringTuple; /** * Represents a SPARQL Endpoint. @@ -65,13 +68,13 @@ // ConfigOptions private URL url; String host; - private Set<String> instances; + private Set<String> instances=new HashSet<String>();; private URL dumpFile; private int recursionDepth = 2; private int predefinedFilter = 0; private int predefinedEndpoint = 0; - private Set<String> predList; - private Set<String> objList; + private Set<String> predList=new HashSet<String>(); + private Set<String> objList=new HashSet<String>(); private Set<String> classList; private String format = "N-TRIPLES"; private boolean dumpToFile = true; @@ -81,6 +84,10 @@ private boolean learnDomain = false; private String role; private String blankNodeIdentifier = "bnode"; + + LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); /** * Holds the results of the calculateSubjects method @@ -157,7 +164,10 @@ "used to identify blanknodes in Tripels")); options.add(new StringTupleListConfigOption("example", "example")); + options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); + options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); + return options; } @@ -208,6 +218,11 @@ blankNodeIdentifier = (String) entry.getValue(); } else if (option.equals("example")) { System.out.println(entry.getValue()); + }else if (option.equals("replacePredicate")) { + replacePredicate = (LinkedList)entry.getValue(); + }else if (option.equals("replaceObject")) { + replaceObject = (LinkedList)entry.getValue(); + } } @@ -229,7 +244,7 @@ SpecificSparqlEndpoint sse = null; SparqlQueryType sqt = null; // get Options for Manipulator - Manipulator man = new Manipulator(blankNodeIdentifier); + Manipulator man = new Manipulator(blankNodeIdentifier,replacePredicate,replaceObject); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("default-graph-uri", "http://dbpedia.org"); parameters.put("format", "application/sparql-results.xml"); @@ -242,11 +257,13 @@ } // get Options for Filters + System.out.println("aaa"+predefinedFilter); if (predefinedFilter >= 1) { sqt = PredefinedFilter.getFilter(predefinedFilter); } else { sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); + System.out.println(sqt); } // give everything to the manager m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses); @@ -255,10 +272,14 @@ // used to learn a domain of a role if (learnDomain) { instances = m.getDomainInstancesForRole(role); - // ad the role to the filter(a solution is always EXISTS + // add the role to the filter(a solution is always EXISTS // role.TOP) m.addPredicateFilter(role); - System.out.println(instances); + //System.out.println(instances); + // THIS is a workaround + for(String one:instances){ + System.out.println("+\""+one+"\""); + } } // the actual extraction is started here ont = m.extract(instances); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-04 17:08:42 UTC (rev 322) @@ -36,26 +36,33 @@ this.type = "class"; } + //expands all directly connected nodes @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { Set<StringTuple> s = tsq.query(this.uri); + // see manipulator s = m.check(s, this); Vector<Node> Nodes = new Vector<Node>(); - // Manipulation + Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { StringTuple t = (StringTuple) it.next(); try { + // substitute rdf:type with owl:subclassof if (t.a.equals(m.type) || t.a.equals(m.subclass)) { ClassNode tmp = new ClassNode(new URI(t.b)); properties.add(new PropertyNode(new URI(m.subclass), this, tmp)); Nodes.add(tmp); } else { + // further expansion stops here + // Nodes.add(tmp); is missing on purpose ClassNode tmp = new ClassNode(new URI(t.b)); properties.add(new PropertyNode(new URI(t.a), this, tmp)); // System.out.println(m.blankNodeIdentifier); // System.out.println("XXXXX"+t.b); + + // if o is a blank node expand further if (t.b.startsWith(m.blankNodeIdentifier)) { tmp.expand(tsq, m); System.out.println(m.blankNodeIdentifier); @@ -72,6 +79,7 @@ return Nodes; } + // gets the types for properties recursively @Override public Vector<Node> expandProperties(TypedSparqlQuery tsq, Manipulator m) { // TODO return type doesn't make sense Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2007-12-04 17:08:42 UTC (rev 322) @@ -21,9 +21,17 @@ //stores all configuration settings public class Configuration { + + /* + * this class colects all configuration information + * see the other classes, which are used as attributes here + * */ + private SpecificSparqlEndpoint specificSparqlEndpoint; private SparqlQueryType sparqlQueryType; private Manipulator manipulator; + // the following needs to be moved to + // class extraction algorithm or manipulator private int recursiondepth = 2; private boolean getAllBackground = true; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-04 17:08:42 UTC (rev 322) @@ -50,6 +50,11 @@ return v; } + /*most important function + expands one example + cave: the recursion is not a recursion anymore, + it was transformed to an iteration + */ public Node expandNode(URI u, TypedSparqlQuery tsp) { Node n = getFirstNode(u); Vector<Node> v = new Vector<Node>(); @@ -64,6 +69,9 @@ Node tmpNode = v.remove(0); System.out.println("Expanding " + tmpNode); // System.out.println(this.Manipulator); + + // these are the new not expanded nodes + // the others are saved in connection with the original node Vector<Node> tmpVec = tmpNode.expand(tsp, manipulator); tmp.addAll(tmpVec); @@ -72,6 +80,8 @@ System.out .println("Recursion counter: " + x + " with " + v.size() + " Nodes remaining"); } + + // gets All Class Nodes and expands them further if (this.getAllBackground) { Vector<Node> classes = new Vector<Node>(); for (Node one : v) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-04 17:08:42 UTC (rev 322) @@ -40,11 +40,12 @@ } + //expands all directly connected nodes @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { Set<StringTuple> s = tsq.query(uri); - // Manipulation + // see Manipulator m.check(s, this); // System.out.println("fffffff"+m); Vector<Node> Nodes = new Vector<Node>(); @@ -52,7 +53,8 @@ Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { StringTuple t = (StringTuple) it.next(); - + // basically : if p is rdf:type then o is a class + // else it is an instance try { if (t.a.equals(m.type)) { ClassNode tmp = new ClassNode(new URI(t.b)); @@ -74,6 +76,7 @@ return Nodes; } + // gets the types for properties recursively @Override public Vector<Node> expandProperties(TypedSparqlQuery tsq, Manipulator m) { for (PropertyNode one : properties) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-04 17:08:42 UTC (rev 322) @@ -40,6 +40,7 @@ recursiondepth, getAllBackground); this.typedSparqlQuery = new TypedSparqlQuery(configuration); this.extractionAlgorithm = new ExtractionAlgorithm(configuration); + } public Set<String> getDomainInstancesForRole(String role) { @@ -76,6 +77,7 @@ // this.TypedSparqlQuery.query(uri); // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); System.out.println("Start extracting"); + Node n = extractionAlgorithm.expandNode(uri, typedSparqlQuery); Set<String> s = n.toNTriple(); String nt = ""; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2007-12-04 17:08:42 UTC (rev 322) @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.Set; import org.dllearner.utilities.StringTuple; @@ -30,6 +31,8 @@ public String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; public String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; public String blankNodeIdentifier = "bnode"; + public LinkedList<StringTuple> replacePredicate; + public LinkedList<StringTuple> replaceObject; String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; String classns = "http://www.w3.org/2002/07/owl#Class"; @@ -41,20 +44,27 @@ "http://dbpedia.org/resource/Category:", "http://dbpedia.org/resource/Template:", "http://www.w3.org/2004/02/skos/core", "http://dbpedia.org/class/" }; - public Manipulator(String blankNodeIdentifier) { + public Manipulator(String blankNodeIdentifier,LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) { this.blankNodeIdentifier = blankNodeIdentifier; + this.replaceObject=replaceObject; + this.replacePredicate=replacePredicate; + Set<String> classproperties = new HashSet<String>(); classproperties.add(subclass); } + // TODO user defined rules missing public Set<StringTuple> check(Set<StringTuple> s, Node node) { Set<StringTuple> toRemove = new HashSet<StringTuple>(); Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { StringTuple t = (StringTuple) it.next(); - // System.out.println(t); - // all classes with owl:type class + 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); } @@ -64,7 +74,7 @@ toRemove.add(t); } - // all instances with owl:type thing + // remove all instances with owl:type thing if (t.a.equals(type) && t.b.equals(thing) && node instanceof InstanceNode) { toRemove.add(t); } @@ -74,5 +84,20 @@ return s; } + + 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/sparql/PredefinedFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2007-12-04 17:08:42 UTC (rev 322) @@ -46,10 +46,13 @@ 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"); + 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"); @@ -70,10 +73,11 @@ 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"); 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: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"); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-04 17:08:42 UTC (rev 322) @@ -29,8 +29,10 @@ public class PropertyNode extends Node { + // the a and b part of a property private Node a; private Node b; + // specialtypes like owl:symmetricproperty private Set<String> specialTypes; public PropertyNode(URI u) { @@ -68,6 +70,8 @@ } return Nodes; } + + // gets the types for properties recursively @Override public Vector<Node> expandProperties(TypedSparqlQuery tsq, Manipulator m) { b.expandProperties(tsq, m); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2007-12-04 17:08:42 UTC (rev 322) @@ -22,6 +22,12 @@ // can assemble sparql queries public class SparqlQueryMaker { + /* can make queries for subject, predicate, object + * according to the filter settings + * object not yet implemented + * + * */ + private SparqlQueryType sparqlQueryType; public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2007-12-04 17:08:42 UTC (rev 322) @@ -24,6 +24,8 @@ // is used to set the filter: configuration public class SparqlQueryType { // TODO make sets out of them + + private String mode = "forbid"; private String[] objectfilterlist = { "http://dbpedia.org/resource/Category:Articles_", "http://dbpedia.org/resource/Category:Wikipedia_", "http://xmlns.com/foaf/0.1/", Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-04 17:08:42 UTC (rev 322) @@ -48,7 +48,7 @@ this.sparqlQueryMaker = new SparqlQueryMaker(Configuration.getSparqlQueryType()); this.cache = new Cache("cache"); } - + // standard query get a tupels (p,o) for subject s public Set<StringTuple> query(URI u) { // getQuery @@ -57,6 +57,7 @@ } + // query get a tupels (s,o) for role p public Set<StringTuple> getTupelsForRole(URI u) { // getQuery @@ -68,6 +69,8 @@ } + + // uses a cache private Set<StringTuple> cachedSparql(URI u, String sparql, String a, String b) { // check cache String FromCache = cache.get(u.toString(), sparql); Modified: trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java 2007-12-03 22:06:30 UTC (rev 321) +++ trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java 2007-12-04 17:08:42 UTC (rev 322) @@ -21,7 +21,7 @@ /** * A container which can hold two Strings, mainly used as a helper. - * + * Also used as pre form, if you want to create triple, that have the same subject * @author Sebastian Hellmann */ public class StringTuple { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |