From: <ku...@us...> - 2008-08-15 12:21:08
|
Revision: 1084 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1084&view=rev Author: kurzum Date: 2008-08-15 12:21:00 +0000 (Fri, 15 Aug 2008) Log Message: ----------- looks like the new structure is working like the old one, next step testing, new features and code improvements Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.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/Manager.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.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/scripts/NT2RDF.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java trunk/src/dl-learner/org/dllearner/kb/old/Node.java trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/old/Scrap.java trunk/src/dl-learner/org/dllearner/kb/old/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/old/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/old/TypedSparqlQueryInterface.java Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -24,8 +24,6 @@ import org.apache.log4j.Logger; import org.dllearner.kb.extraction.Configuration; -import org.dllearner.kb.sparql.SPARQLTasks; -import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.RDFNodeTuple; /** @@ -38,30 +36,21 @@ @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(LinkedDataTupelAquisitor.class); - + @SuppressWarnings("unused") private Configuration configuration; - protected SparqlQueryMaker sparqlQueryMaker; - protected SPARQLTasks sparqlTasks; + - public LinkedDataTupelAquisitor(Configuration Configuration) { - this.configuration = Configuration; - this.sparqlQueryMaker = configuration.getSparqlQueryMaker(); - this.sparqlTasks = configuration.sparqlTasks; + public LinkedDataTupelAquisitor(Configuration configuration) { + this.configuration = configuration; } // standard query get a tupels (p,o) for subject s @Override public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { + throw new RuntimeException("Not Implemented yet"); - String pred = "predicate"; - String obj = "object"; - // getQuery - String sparqlQueryString = sparqlQueryMaker - .makeSubjectQueryUsingFilters(uri.toString()); - return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); - } Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -23,7 +23,6 @@ import java.util.SortedSet; import org.apache.log4j.Logger; -import org.dllearner.kb.extraction.Configuration; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.RDFNodeTuple; @@ -39,15 +38,17 @@ @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class); - private Configuration configuration; protected SparqlQueryMaker sparqlQueryMaker; protected SPARQLTasks sparqlTasks; + + - public SparqlTupelAquisitor(Configuration Configuration) { - this.configuration = Configuration; - this.sparqlQueryMaker = configuration.getSparqlQueryMaker(); - this.sparqlTasks = configuration.sparqlTasks; + public SparqlTupelAquisitor(SparqlQueryMaker sparqlQueryMaker, SPARQLTasks sparqlTasks) { + + this.sparqlQueryMaker = sparqlQueryMaker; + this.sparqlTasks = sparqlTasks; } + // standard query get a tupels (p,o) for subject s @Override @@ -56,16 +57,25 @@ String pred = "predicate"; String obj = "object"; + String sparqlQueryString = ""; // getQuery - String sparqlQueryString = sparqlQueryMaker - .makeSubjectQueryUsingFilters(uri.toString()); + if (classMode) { + sparqlQueryString = sparqlQueryMaker.makeClassQueryUsingFilters(uri.toString()); + }else { + sparqlQueryString = sparqlQueryMaker.makeSubjectQueryUsingFilters(uri.toString()); + } + return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); } + + + + } Deleted: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,61 +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.kb.aquisitors; - -import java.net.URI; -import java.util.SortedSet; - -import org.apache.log4j.Logger; -import org.dllearner.kb.extraction.Configuration; -import org.dllearner.utilities.datastructures.RDFNodeTuple; - -/** - * Can execute different queries. - * - * @author Sebastian Hellmann - * - */ -public class SparqlTupelAquisitorClasses extends SparqlTupelAquisitor { - - @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class); - - public SparqlTupelAquisitorClasses(Configuration configuration) { - super(configuration); - } - - /* - * Special TypedSparqlQuery which returns superclasses of classes - * (non-Javadoc) - * - * @see org.dllearner.kb.sparql.TypedSparqlQuery#getTupelForResource(java.net.URI) - */ - @Override - @SuppressWarnings({"unchecked"}) - public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { - //Set<RDFNodeTuple> s = new TreeSet<RDFNodeTuple>(); - String pred = "predicate"; - String obj = "object"; - // getQuery - String sparqlQueryString = sparqlQueryMaker.makeClassQueryUsingFilters(uri.toString()); - return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -23,7 +23,6 @@ import java.util.SortedSet; import org.apache.log4j.Logger; -import org.dllearner.kb.extraction.Configuration; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.RDFNodeTuple; @@ -34,33 +33,22 @@ * @author Sebastian Hellmann * */ -public class SparqlTupelAquisitorImproved extends TupelAquisitor { +public class SparqlTupelAquisitorImproved extends SparqlTupelAquisitor { @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(SparqlTupelAquisitorImproved.class); - private Configuration configuration; - protected SparqlQueryMaker sparqlQueryMaker; - protected SPARQLTasks sparqlTasks; - public SparqlTupelAquisitorImproved(Configuration Configuration) { - this.configuration = Configuration; - this.sparqlQueryMaker = configuration.getSparqlQueryMaker(); - this.sparqlTasks = configuration.sparqlTasks; + public SparqlTupelAquisitorImproved(SparqlQueryMaker sparqlQueryMaker, SPARQLTasks sparqlTasks) { + super(sparqlQueryMaker, sparqlTasks); + } // standard query get a tupels (p,o) for subject s @Override public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { - - String pred = "predicate"; - String obj = "object"; - // getQuery - String sparqlQueryString = sparqlQueryMaker - .makeSubjectQueryUsingFilters(uri.toString()); - - return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); + throw new RuntimeException("not implemented yet"); } Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -34,8 +34,18 @@ * */ public abstract class TupelAquisitor { + + protected boolean classMode = false; public abstract SortedSet<RDFNodeTuple> getTupelForResource(URI u); + + public void setClassMode(boolean classMode) { + this.classMode = classMode; + } + + public boolean isClassMode() { + return classMode; + } } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -19,10 +19,8 @@ */ package org.dllearner.kb.extraction; -import org.dllearner.kb.old.Manipulators; -import org.dllearner.kb.sparql.SPARQLTasks; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQueryMaker; +import org.dllearner.kb.aquisitors.TupelAquisitor; +import org.dllearner.kb.manipulator.Manipulator; /** * Stores all configuration settings. this class collects all configuration @@ -32,78 +30,79 @@ */ public class Configuration { - public SPARQLTasks sparqlTasks; + //public SPARQLTasks sparqlTasks; - private SparqlEndpoint endpoint; - private SparqlQueryMaker sparqlQueryMaker; + //private SparqlEndpoint endpoint; + //private SparqlQueryMaker sparqlQueryMaker; + private Manipulator manipulator; + private TupelAquisitor tupelAquisitor; - private Manipulators manipulator; // the following needs to be moved to // class extraction algorithm or manipulator private int recursiondepth; private boolean getAllSuperClasses = true; private boolean closeAfterRecursion = true; - public int numberOfUncachedSparqlQueries = 0; - public int numberOfCachedSparqlQueries = 0; - public String cacheDir="cache"; + private int breakSuperClassesAfter = 200; - public Configuration(SparqlEndpoint specificSparqlEndpoint, - SparqlQueryMaker sparqlQueryMaker, Manipulators manipulator, - int recursiondepth, boolean getAllSuperClasses, - boolean closeAfterRecursion, String cacheDir) { - this.endpoint = specificSparqlEndpoint; - this.sparqlQueryMaker = sparqlQueryMaker; + + public Configuration( + TupelAquisitor tupelAquisitor, + Manipulator manipulator, + int recursiondepth, + boolean getAllSuperClasses, + boolean closeAfterRecursion, + int breakSuperClassesAfter) { + + this.tupelAquisitor = tupelAquisitor; this.manipulator = manipulator; this.recursiondepth = recursiondepth; this.getAllSuperClasses = getAllSuperClasses; this.closeAfterRecursion = closeAfterRecursion; - this.cacheDir=cacheDir; + this.breakSuperClassesAfter = breakSuperClassesAfter; + } - public Configuration changeQueryType(SparqlQueryMaker sqm) { - // TODO must clone here - return new Configuration(this.endpoint, sqm, this.manipulator, - this.recursiondepth, this.getAllSuperClasses, - this.closeAfterRecursion, this.cacheDir); + public int getBreakSuperClassesAfter() { + return breakSuperClassesAfter; } - public Manipulators getManipulator() { - return this.manipulator; - } - public SparqlEndpoint getSparqlEndpoint() { - return endpoint; + public boolean isCloseAfterRecursion() { + return closeAfterRecursion; } - public SparqlQueryMaker getSparqlQueryMaker() { - return sparqlQueryMaker; - } public boolean isGetAllSuperClasses() { return getAllSuperClasses; } - public boolean isCloseAfterRecursion() { - return closeAfterRecursion; + + public Manipulator getManipulator() { + return manipulator; } + public int getRecursiondepth() { return recursiondepth; } - - public SPARQLTasks getSparqlTasks() { - return sparqlTasks; - } - - /*public void increaseNumberOfuncachedSparqlQueries() { - numberOfUncachedSparqlQueries++; + + public TupelAquisitor getTupelAquisitor() { + return tupelAquisitor; } - public void increaseNumberOfCachedSparqlQueries() { - numberOfCachedSparqlQueries++; + /* + public Configuration changeQueryType(SparqlQueryMaker sqm) { + // TODO must clone here + return new Configuration(this.endpoint, sqm, this.manipulator, + this.recursiondepth, this.getAllSuperClasses, + this.closeAfterRecursion, this.cacheDir); + }*/ + + + } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -20,16 +20,13 @@ package org.dllearner.kb.extraction; import java.net.URI; -import java.util.HashSet; -import java.util.Vector; +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.kb.old.ClassNode; -import org.dllearner.kb.old.InstanceNode; -import org.dllearner.kb.old.Manipulators; -import org.dllearner.kb.old.Node; -import org.dllearner.kb.old.TypedSparqlQuery; -import org.dllearner.kb.old.TypedSparqlQueryClasses; +import org.dllearner.kb.aquisitors.TupelAquisitor; /** * This class is used to extract the information . @@ -39,8 +36,8 @@ public class ExtractionAlgorithm { private Configuration configuration; - private Manipulators manipulator; - private int recursionDepth = 1; + //private Manipulators manipulator; + //private int recursionDepth = 1; // private boolean getAllSuperClasses = true; // private boolean closeAfterRecursion = true; private static Logger logger = Logger @@ -48,8 +45,8 @@ public ExtractionAlgorithm(Configuration Configuration) { this.configuration = Configuration; - this.manipulator = Configuration.getManipulator(); - this.recursionDepth = Configuration.getRecursiondepth(); + //this.manipulator = Configuration.getManipulator(); + //this.recursionDepth = Configuration.getRecursiondepth(); // this.getAllSuperClasses = Configuration.isGetAllSuperClasses(); // this.closeAfterRecursion=Configuration.isCloseAfterRecursion(); } @@ -58,10 +55,10 @@ return new InstanceNode(u); } - public Vector<Node> expandAll(URI[] u, TypedSparqlQuery tsp) { - Vector<Node> v = new Vector<Node>(); - for (URI one : u) { - v.add(expandNode(one, tsp)); + public List<Node> expandAll(URI[] uris, TupelAquisitor tupelAquisitor) { + List<Node> v = new ArrayList<Node>(); + for (URI oneURI : uris) { + v.add(expandNode(oneURI, tupelAquisitor)); } return v; } @@ -75,50 +72,52 @@ * @param typedSparqlQuery * @return */ - public Node expandNode(URI uri, TypedSparqlQuery typedSparqlQuery) { + public Node expandNode(URI uri, TupelAquisitor tupelAquisitor) { //System.out.println(uri.toString()); //System.out.println(manipulator); //System.out.println(this.configuration); long time = System.currentTimeMillis(); + Node n = getFirstNode(uri); logger.info(n); - Vector<Node> v = new Vector<Node>(); - v.add(n); - logger.info("StartVector: " + v); + List<Node> initialNodes = new ArrayList<Node>(); + initialNodes.add(n); + logger.info("StartVector: " + initialNodes); // n.expand(tsp, this.Manipulator); // Vector<Node> second= - for (int x = 1; x <= recursionDepth; x++) { + for (int x = 1; x <= configuration.getRecursiondepth(); x++) { - Vector<Node> tmp = new Vector<Node>(); - while (v.size() > 0) { - Node tmpNode = v.remove(0); + List<Node> tmp = new ArrayList<Node>(); + while (!initialNodes.isEmpty()) { + Node tmpNode = initialNodes.remove(0); logger.info("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(typedSparqlQuery, - manipulator); + List<Node> tmpNodeList = tmpNode.expand(tupelAquisitor, + configuration.getManipulator()); //System.out.println(tmpVec); - tmp.addAll(tmpVec); + tmp.addAll(tmpNodeList); } - v = tmp; - logger.info("Recursion counter: " + x + " with " + v.size() + //CAVE: possible error here + initialNodes = tmp; + logger.info("Recursion counter: " + x + " with " + initialNodes.size() + " Nodes remaining, needed: " + (System.currentTimeMillis() - time) + "ms"); time = System.currentTimeMillis(); } - HashSet<String> hadAlready = new HashSet<String>(); + SortedSet<String> hadAlready = new TreeSet<String>(); //p(configuration.toString()); // gets All Class Nodes and expands them further - if (this.configuration.isGetAllSuperClasses()) { + if (configuration.isGetAllSuperClasses()) { logger.info("Get all superclasses"); // Set<Node> classes = new TreeSet<Node>(); - Vector<Node> classes = new Vector<Node>(); + List<Node> classes = new ArrayList<Node>(); + List<Node> instances = new ArrayList<Node>(); - Vector<Node> instances = new Vector<Node>(); - for (Node one : v) { + for (Node one : initialNodes) { if (one instanceof ClassNode) { classes.add(one); } @@ -128,23 +127,28 @@ } // System.out.println(instances.size()); - TypedSparqlQueryClasses tsqc = new TypedSparqlQueryClasses( - configuration); - if (this.configuration.isCloseAfterRecursion()) { - while (instances.size() > 0) { + //TODO LinkedData incompatibility + //TupelAquisitor tupelAquisitorClasses = configuration.sparqlTupelAquisitorClasses; + //XXX this should be solved in a better way + tupelAquisitor.setClassMode(true); + if (configuration.isCloseAfterRecursion()) { + while (!instances.isEmpty()) { logger.trace("Getting classes for remaining instances: " + instances.size()); Node next = instances.remove(0); logger.trace("Getting classes for: " + next); - classes.addAll(next.expand(tsqc, manipulator)); - if (classes.size() >= Manipulators.breakSuperClassRetrievalAfter) { + classes.addAll(next.expand(tupelAquisitor, configuration.getManipulator())); + if (classes.size() >= configuration.getBreakSuperClassesAfter()) { break; } } } - Vector<Node> tmp = new Vector<Node>(); + //XXX this should be solved in a better way + tupelAquisitor.setClassMode(false); + + List<Node> tmp = new ArrayList<Node>(); int i = 0; - while (classes.size() > 0) { + while (!classes.isEmpty()) { logger.trace("Remaining classes: " + classes.size()); // Iterator<Node> it=classes.iterator(); // Node next =(Node) it.next(); @@ -155,13 +159,13 @@ logger.trace("Getting SuperClass for: " + next); // System.out.println(hadAlready.size()); hadAlready.add(next.getURI().toString()); - tmp = next.expand(typedSparqlQuery, manipulator); + tmp = next.expand(tupelAquisitor, configuration.getManipulator()); classes.addAll(tmp); - tmp = new Vector<Node>(); + tmp = new ArrayList<Node>(); // if(i % 50==0)System.out.println("got "+i+" extra classes, // max: "+manipulator.breakSuperClassRetrievalAfter); i++; - if (i >= Manipulators.breakSuperClassRetrievalAfter) { + if (i >= configuration.getBreakSuperClassesAfter()) { break; } } Added: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -0,0 +1,125 @@ +/** + * 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.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.aquisitors.TupelAquisitor; +import org.dllearner.kb.manipulator.Manipulator; +import org.dllearner.utilities.datastructures.RDFNodeTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +/** + * A node in the graph that is an instance. + * + * @author Sebastian Hellmann + * + */ +public class InstanceNode extends Node { + + private SortedSet<ClassNode> classes = new TreeSet<ClassNode>(); + //SortedSet<StringTuple> datatypes = new TreeSet<StringTuple>(); + private SortedSet<PropertyNode> properties = new TreeSet<PropertyNode>(); + + public InstanceNode(URI u) { + super(u); + // this.type = "instance"; + + } + + // expands all directly connected nodes + @Override + public List<Node> expand(TupelAquisitor tupelAquisitor, Manipulator manipulator) { + + SortedSet<RDFNodeTuple> newTuples = tupelAquisitor.getTupelForResource(uri); + // see Manipulator + newTuples = manipulator.manipulate(this, newTuples); + //s=m.check(s, this); + // System.out.println("fffffff"+m); + List<Node> newNodes = new ArrayList<Node>(); + + for (RDFNodeTuple tuple : newTuples) { + //QUALITY: needs proper handling of ressource, could be done one step lower in the onion + if(!tuple.b.toString().startsWith("http:"))continue; + +// basically : if p is rdf:type then o is a class + // else it is an instance + try { + if (tuple.a.toString().equals(OWLVocabulary.RDF_TYPE)) { + ClassNode tmp = new ClassNode(new URI(tuple.b.toString())); + classes.add(tmp); + newNodes.add(tmp); + } else { + InstanceNode tmp = new InstanceNode(new URI(tuple.b.toString())); + properties.add(new PropertyNode(new URI(tuple.a.toString()), this, tmp)); + newNodes.add(tmp); + + } + } catch (Exception e) { + System.out.println("Problem with: " + tuple); + e.printStackTrace(); + } + + + + }//endfor + expanded = true; + return newNodes; + + } + + // gets the types for properties recursively + @Override + public void expandProperties(TupelAquisitor tupelAquisitor, Manipulator manipulator) { + for (PropertyNode one : properties) { + one.expandProperties(tupelAquisitor, manipulator); + } + + } + + @Override + public SortedSet<String> toNTriple() { + SortedSet<String> returnSet = new TreeSet<String>(); + returnSet.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_THING + ">."); + for (ClassNode one : classes) { + returnSet.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + one.getURI() + ">."); + returnSet.addAll(one.toNTriple()); + } + for (PropertyNode one : properties) { + returnSet.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() + + ">."); + returnSet.addAll(one.toNTriple()); + returnSet.addAll(one.getB().toNTriple()); + } + + return returnSet; + } + + @Override + public int compareTo(Node n) { + return super.compareTo(n); + // + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -25,12 +25,6 @@ import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.kb.old.Manipulators; -import org.dllearner.kb.old.Node; -import org.dllearner.kb.old.TypedSparqlQuery; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQueryMaker; -import org.dllearner.utilities.statistics.Statistics; /** * An object of this class encapsulates everything. @@ -41,23 +35,17 @@ public class Manager { private Configuration configuration; - private TypedSparqlQuery typedSparqlQuery; private ExtractionAlgorithm extractionAlgorithm; private static Logger logger = Logger .getLogger(Manager.class); - public void useConfiguration(SparqlQueryMaker sparqlQueryMaker, - SparqlEndpoint SparqlEndpoint, Manipulators manipulator, - int recursiondepth, boolean getAllSuperClasses, - boolean closeAfterRecursion, String cacheDir) { + public void useConfiguration(Configuration configuration) { - this.configuration = new Configuration(SparqlEndpoint, sparqlQueryMaker, - manipulator, recursiondepth, getAllSuperClasses, - closeAfterRecursion, cacheDir); + this.configuration = configuration; //System.out.println(this.configuration); - this.typedSparqlQuery = new TypedSparqlQuery(configuration); + this.extractionAlgorithm = new ExtractionAlgorithm(configuration); } @@ -67,20 +55,21 @@ // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); System.out.println("Start extracting"); - Node n = extractionAlgorithm.expandNode(uri, typedSparqlQuery); + Node n = extractionAlgorithm.expandNode(uri, configuration.getTupelAquisitor()); SortedSet<String> s = n.toNTriple(); - String nt = ""; + StringBuffer nt = new StringBuffer(33000); for (String str : s) { - nt += str + "\n"; + nt.append(str + "\n"); } - return nt; + System.out.println("sizeofStringBuffer"+nt.length()); + return nt.toString(); } public String extract(Set<String> instances) { // this.TypedSparqlQuery.query(uri); // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); logger.info("Start extracting"); - SortedSet<String> ret = new TreeSet<String>(); + SortedSet<String> tripleCollector = new TreeSet<String>(); int progress=0; for (String one : instances) { progress++; @@ -89,15 +78,15 @@ //} try { Node n = extractionAlgorithm.expandNode(new URI(one), - typedSparqlQuery); - ret.addAll(n.toNTriple()); + configuration.getTupelAquisitor()); + tripleCollector.addAll(n.toNTriple()); } catch (Exception e) { e.printStackTrace(); } } logger.info("Finished extracting, start conversion"); - StringBuffer nt = new StringBuffer(); - Object[] arr = ret.toArray(); + StringBuffer nt = new StringBuffer(100000); + Object[] arr = tripleCollector.toArray(); for (int i = 0; i < arr.length; i++) { nt.append((String) arr[i] + "\n"); if (i % 1000 == 0) @@ -109,15 +98,15 @@ * ret.remove(tmp); System.out.println(ret.size()); } /*for (String str : * ret) { nt += str + "\n"; } */ - Statistics.addTriples(ret.size()); + logger.info("Ontology String size = " + nt.length()); return nt.toString(); } - public void addPredicateFilter(String str) { +/* public void addPredicateFilter(String str) { this.configuration.getSparqlQueryMaker().addPredicateFilter(str); } - +*/ public Configuration getConfiguration() { return configuration; } Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -24,9 +24,9 @@ import java.util.SortedSet; import org.dllearner.kb.extraction.ClassNode; +import org.dllearner.kb.extraction.InstanceNode; import org.dllearner.kb.extraction.Node; import org.dllearner.kb.manipulator.Rule.Months; -import org.dllearner.kb.old.InstanceNode; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; @@ -38,24 +38,15 @@ */ public class Manipulator { - List<Rule> rules = new ArrayList<Rule>(); - //List<ReplacementRule> replacementRules = new ArrayList<ReplacementRule>(); - - - //public int breakSuperClassRetrievalAfter = 200; - //public LinkedList<StringTuple> replacePredicate; - //public LinkedList<StringTuple> replaceObject; - - // Set<String> classproperties; - + private List<Rule> rules = new ArrayList<Rule>(); + private Manipulator() { - - //this.replaceObject = replaceObject; - //this.replacePredicate = replacePredicate; - //this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; - // Set<String> classproperties = new HashSet<String>(); - // classproperties.add(subclass); + } + public Manipulator(List<Rule> rules) { + for (Rule rule : rules) { + addRule(rule); + } } /** @@ -64,51 +55,32 @@ */ public SortedSet<RDFNodeTuple> manipulate( Node node, SortedSet<RDFNodeTuple> tuples) { - for (Months month : Rule.MONTHS) { - tuples = applyRulesOfTheMonth(month, node, tuples); - } - return tuples; - /*SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); - - for (RDFNodeTuple currentTuple : tuples) { - currentTuple = manipulateTuple(node.getURI().toString(), currentTuple); - if(keepTuple(node, currentTuple)) { - keep.add(currentTuple); - } - - } - return keep;*/ - } - - public SortedSet<RDFNodeTuple> applyRulesOfTheMonth(Months month, Node subject, SortedSet<RDFNodeTuple> tuples){ for (Rule rule : rules) { - if(rule.month.equals(month)) { - tuples = rule.applyRule(subject, tuples); - } + tuples = rule.applyRule(node, tuples); } return tuples; } + + public static Manipulator getManipulatorByName(String predefinedManipulator) { if (predefinedManipulator.equalsIgnoreCase("DBPEDIA-NAVIGATOR")) { return getDBpediaNavigatorManipulator(); -// return new DBpediaNavigatorManipulator(blankNodeIdentifier, - //breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - + } else if(predefinedManipulator.equalsIgnoreCase("DEFAULT")){ return getDefaultManipulator(); } else { - //QUALITY maybe not the best, should be Default - return new Manipulator(); + //QUALITY maybe not the best, + return getDefaultManipulator(); } } public static Manipulator getDBpediaNavigatorManipulator(){ Manipulator m = new Manipulator(); - m.rules.add(new DBPediaNavigatorCityLocatorRule(Months.JANUARY)); - m.rules.add(new DBpediaNavigatorOtherRule(Months.DECEMBER)); + m.addRule(new DBPediaNavigatorCityLocatorRule(Months.JANUARY)); + m.addRule(new DBpediaNavigatorOtherRule(Months.DECEMBER)); return m; } @@ -137,13 +109,28 @@ private void addDefaultRules(Months month){ - rules.add(new TypeFilterRule(month, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_CLASS,ClassNode.class.getCanonicalName() )) ; - rules.add(new TypeFilterRule(month, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_THING,InstanceNode.class.getCanonicalName() )) ; - rules.add(new TypeFilterRule(month, "", OWLVocabulary.OWL_CLASS, ClassNode.class.getCanonicalName()) ) ; + addRule(new TypeFilterRule(month, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_CLASS,ClassNode.class.getCanonicalName() )) ; + addRule(new TypeFilterRule(month, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_THING,InstanceNode.class.getCanonicalName() )) ; + addRule(new TypeFilterRule(month, "", OWLVocabulary.OWL_CLASS, ClassNode.class.getCanonicalName()) ) ; } + public synchronized void addRule(Rule newRule){ + rules.add(newRule); + List<Rule> l = new ArrayList<Rule>(); + + for (Months month : Rule.MONTHS) { + for (Rule rule : rules) { + if(rule.month.equals(month)) { + l.add(rule); + } + } + + } + rules = l; + } + /* private RDFNodeTuple manipulateTuple(String subject, RDFNodeTuple tuple) { Deleted: trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,117 +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.old; - -import java.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.Vector; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * Is a node in the graph, that is a class. - * - * @author Sebastian Hellmann - */ -public class ClassNode extends Node { - Set<PropertyNode> properties = new HashSet<PropertyNode>(); - - public ClassNode(URI u) { - super(u); - } - - // expands all directly connected nodes - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { - - Set<StringTuple> s = tsq.getTupelForResource(this.uri); - // see manipulator - s = m.check(s, this); - Vector<Node> Nodes = new Vector<Node>(); - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - try { - // substitute rdf:type with owl:subclassof - if (t.a.equals(Manipulators.type) || t.a.equals(Manipulators.subclass)) { - ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(Manipulators.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 - // TODO this needs a lot more work - if (t.b.startsWith(Manipulators.blankNodeIdentifier)) { - tmp.expand(tsq, m); - System.out.println(Manipulators.blankNodeIdentifier); - System.out.println("XXXXX" + t.b); - } - // Nodes.add(tmp); - } - } catch (Exception e) { - System.out.println(t); - e.printStackTrace(); - } - - } - return Nodes; - } - - // gets the types for properties recursively - @Override - public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.kb.sparql.datastructure.Node#toNTriple() - */ - @Override - public SortedSet<String> toNTriple() { - SortedSet<String> s = new TreeSet<String>(); - s.add("<" + this.uri + "><" + rdftype + "><" + classns + ">."); - - for (PropertyNode one : properties) { - s.add("<" + this.uri + "><" + one.getURI() + "><" - + one.getB().getURI() + ">."); - s.addAll(one.getB().toNTriple()); - } - - return s; - } - - @Override - public int compareTo(Node n) { - return super.compareTo(n); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,58 +0,0 @@ -package org.dllearner.kb.old; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -public class DBpediaNavigatorCityLocator { - - public static String getTypeToCoordinates(float lat, float lng){ - if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ - if (lat>50&&lat<52&&lng>12&&lng<13){ - return "http://dbpedia.org/class/custom/City_in_Saxony"; - } - else return "http://dbpedia.org/class/custom/City_in_Europe"; - } - else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ - if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ - return "http://dbpedia.org/class/custom/City_in_Egypt"; - } - else return "http://dbpedia.org/class/custom/City_in_Africa"; - } - else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ - return "http://dbpedia.org/class/custom/City_in_Asia"; - } - else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ - return "http://dbpedia.org/class/custom/City_in_Australia"; - } - else if (lng>-168.4&&lng<-19.7&&lat>6.6){ - return "http://dbpedia.org/class/custom/City_in_North_America"; - } - else if (lng>-81.56&&lng<-34.1&&lat<6.6){ - return "http://dbpedia.org/class/custom/City_in_South_America"; - } - else return "http://dbpedia.org/class/custom/City_in_World"; - } - - public static Set<StringTuple> getTuplesToAdd(String uri){ - String subClass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - - HashMap<String,String> map=new HashMap<String,String>(); - map.put("http://dbpedia.org/class/custom/City_in_Saxony", "http://dbpedia.org/class/custom/City_in_Europe"); - map.put("http://dbpedia.org/class/custom/City_in_Egypt", "http://dbpedia.org/class/custom/City_in_Africa"); - map.put("http://dbpedia.org/class/custom/City_in_Europe", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Asia", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Australia", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_North_America", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_South_America", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Africa", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_World", "http://dbpedia.org/class/yago/City108524735"); - Set<StringTuple> toAdd = new HashSet<StringTuple>(); - if (map.containsKey(uri)){ - toAdd.add(new StringTuple(subClass,map.get(uri))); - } - return toAdd; - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,139 +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.old; - -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(); - float lat=0; - float lng=0; - String clas=""; - StringTuple typeTupel=null; - tuples.addAll(DBpediaNavigatorCityLocator.getTuplesToAdd(node.getURI().toString())); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - - if (t.a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")){ - clas=t.b; - typeTupel=t; - } - - if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")) - lat=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); - if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) - lng=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); - - /*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); - }*/ - - } - if (clas.equals("http://dbpedia.org/class/yago/City108524735")){ - String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); - tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); - tuples.remove(typeTupel); - } - //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; - } - } - }*/ -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,122 +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.old; - -import java.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.Vector; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * A node in the graph that is an instance. - * - * @author Sebastian Hellmann - * - */ -public class InstanceNode extends Node { - - Set<ClassNode> classes = new HashSet<ClassNode>(); - Set<StringTuple> datatypes = new HashSet<StringTuple>(); - Set<PropertyNode> properties = new HashSet<PropertyNode>(); - - public InstanceNode(URI u) { - super(u); - // this.type = "instance"; - - } - - // expands all directly connected nodes - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { - - Set<StringTuple> s = tsq.getTupelForResource(uri); - // see Manipulator - s=m.check(s, this); - // System.out.println("fffffff"+m); - Vector<Node> Nodes = new Vector<Node>(); - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - //QUALITY: needs proper handling of ressource, could be done one step lower in the onion - if(!t.b.startsWith("http:"))continue; - - // basically : if p is rdf:type then o is a class - // else it is an instance - try { - if (t.a.equals(Manipulators.type)) { - ClassNode tmp = new ClassNode(new URI(t.b)); - classes.add(tmp); - Nodes.add(tmp); - } else { - InstanceNode tmp = new InstanceNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(t.a), this, tmp)); - Nodes.add(tmp); - - } - } catch (Exception e) { - System.out.println("Problem with: " + t); - e.printStackTrace(); - } - - } - expanded = true; - return Nodes; - } - - // gets the types for properties recursively - @Override - public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { - for (PropertyNode one : properties) { - one.expandProperties(tsq, m); - } - - } - - @Override - public SortedSet<String> toNTriple() { - SortedSet<String> s = new TreeSet<String>(); - s.add("<" + uri + "><" + rdftype + "><" + thing + ">."); - for (ClassNode one : classes) { - s.add("<" + uri + "><" + rdftype + "><" + one.getURI() + ">."); - s.addAll(one.toNTriple()); - } - for (PropertyNode one : properties) { - s.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() - + ">."); - s.addAll(one.toNTriple()); - s.addAll(one.getB().toNTriple()); - } - - return s; - } - - @Override - public int compareTo(Node n) { - return super.compareTo(n); - // - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,23 +0,0 @@ -package org.dllearner.kb.old; - -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 OldManipulator(blankNodeIdentifier, - breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,15 +0,0 @@ -package org.dllearner.kb.old; - -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); -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/Node.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/Node.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,99 +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.old; - -import java.net.URI; -import java.util.SortedSet; -import java.util.Vector; - - - -/** - * Abstract class. defines functions to expand the nodes - * - * @author Sebastian Hellmann - * - */ -public abstract class Node implements Comparable<Node> { - - final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - final String rdftype = "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"; - - URI uri; - // protected String type; - protected boolean expanded = false; - - public Node(URI u) { - this.uri = u; - } - - /** - * Nodes are expanded with a certain context, given by the typedSparqlQuery - * and the manipulator - * - * @param typedSparqlQuery - * @param manipulator - * @return Vector<Node> all Nodes that are new because of expansion - */ - public abstract Vector<Node> expand( - TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); - - /** - * gets type defs for properties like rdf:type SymmetricProperties - * - * @param typedSparqlQuery - * @param manipulator - * @return Vector<Node> - */ - public abstract void expandProperties( - TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); - - /** - * output - * - * @return a set of n-triple - */ - public abstract SortedSet<String> toNTriple(); - - @Override - public String toString() { - return "Node: " + uri + ":" + this.getClass().getSimpleName(); - - } - - public URI getURI() { - return uri; - } - - public boolean equals(Node n) { - if (this.uri.equals(n.uri)) - return true; - else - return false; - } - - public int compareTo(Node n) { - return this.uri.toString().compareTo(n.uri.toString()); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java 2008-08-15 12:03:42 UTC (rev 1083) +++ trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java 2008-08-15 12:21:00 UTC (rev 1084) @@ -1,158 +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.old; - -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 - * - */ -@Deprecated -public class OldManipulator 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 OldManipulator(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(); - - //HACK -// if(t.a.equals("http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag")) { -// //hackGetLabel(t.b); -// -// } - - // GovTrack hack - // => we convert a string literal to a URI - // => TODO: introduce an option for converting literals for certain - // properties into URIs -// String sp = "http://purl.org/dc/elements/1.1/subject"; -// if(t.a.equals(sp)) { -// System.out.println(t); -// System.exit(0); -// } - - 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; - } - } - } - - - /*private String hackGetLabel(String resname){ - String query="" + - "SELECT ?o \n" + - "WHERE { \n" + - "<"+resname+"> "+ " <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o " + - "}"; - - System.out.println(query); - //http://dbtune.org/musicbrainz/sparql?query= - //SELECT ?o WHERE { <http://dbtune.org/musicbrainz/resource/tag/1391> <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o } - SparqlQuery s=new SparqlQuery(query,SparqlEndpoint.EndpointMusicbrainz()); - ResultSet rs=s.send(); - while (rs.hasNext()){ - rs.nextBinding(); - } - //System.out.println("AAA"+s.getAsXMLString(s.send()) ); - return ""; - }*/ - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java 2008-08-15 12:03:42 UTC (rev 1083... [truncated message content] |