From: <ku...@us...> - 2008-08-14 17:35:57
|
Revision: 1076 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1076&view=rev Author: kurzum Date: 2008-08-14 17:35:50 +0000 (Thu, 14 Aug 2008) Log Message: ----------- more movements Modified Paths: -------------- 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/DBPediaNavigatorCityLocatorRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/old/Node.java trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -1,119 +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.extraction; - -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.kb.old.Manipulators; -import org.dllearner.kb.old.TypedSparqlQueryInterface; -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); - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -24,7 +24,10 @@ import java.util.Vector; 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; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -1,124 +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.extraction; - -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.kb.old.Manipulators; -import org.dllearner.kb.old.TypedSparqlQueryInterface; -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); - // - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -26,6 +26,7 @@ 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; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -1,101 +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.extraction; - -import java.net.URI; -import java.util.SortedSet; -import java.util.Vector; - -import org.dllearner.kb.old.Manipulators; -import org.dllearner.kb.old.TypedSparqlQueryInterface; - - -/** - * 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/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -1,123 +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.extraction; - -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.kb.old.Manipulators; -import org.dllearner.kb.old.TypedSparqlQueryInterface; -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * Property node, has connection to a and b part - * - * @author Sebastian Hellmann - * - */ - -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, Node a, Node b) { - super(u); - // this.type = "property"; - this.a = a; - this.b = b; - this.specialTypes = new HashSet<String>(); - } - - // Property Nodes are normally not expanded, - // this function is never called - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { - return null; - } - - // gets the types for properties recursively - @Override - public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { - b.expandProperties(tsq, m); - Set<StringTuple> s = tsq.getTupelForResource(uri); - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - try { - if (t.a.equals(Manipulators.type)) { - specialTypes.add(t.b); - } - } catch (Exception e) { - System.out.println(t); - e.printStackTrace(); - } - - } - - } - - public Node getA() { - return a; - } - - public Node getB() { - return b; - } - - @Override - public SortedSet<String> toNTriple() { - SortedSet<String> s = new TreeSet<String>(); - s.add("<" + uri + "><" - + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#ObjectProperty" + ">."); - for (String one : specialTypes) { - s.add("<" + uri + "><" - + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + one + ">."); - - } - - return s; - } - - @Override - public boolean equals(Node n) { - if (this.uri.equals(n.uri)) - return true; - else - return false; - } - - @Override - public int compareTo(Node n) { - return super.compareTo(n); - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -4,7 +4,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -21,8 +21,8 @@ import java.util.SortedSet; -import org.dllearner.kb.extraction.Node; import org.dllearner.kb.old.DBpediaNavigatorCityLocator; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -23,10 +23,10 @@ import java.util.List; 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.ClassNode; +import org.dllearner.kb.old.InstanceNode; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -5,7 +5,7 @@ import java.util.List; import java.util.SortedSet; -import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; public abstract class Rule { Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -3,7 +3,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; public class SimpleObjectFilterRule extends Rule{ Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -3,7 +3,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; public class SimplePredicateFilterRule extends Rule{ Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -3,7 +3,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.old.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; public class TypeFilterRule extends Rule{ Copied: trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java (from rev 1075, trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -0,0 +1,117 @@ +/** + * 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); + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/old/ClassNode.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -23,7 +23,6 @@ import java.util.LinkedList; import java.util.Set; -import org.dllearner.kb.extraction.Node; import org.dllearner.utilities.datastructures.StringTuple; /** Copied: trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java (from rev 1075, trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -0,0 +1,122 @@ +/** + * 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); + // + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/old/InstanceNode.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -2,7 +2,6 @@ import java.util.Set; -import org.dllearner.kb.extraction.Node; import org.dllearner.utilities.datastructures.StringTuple; public interface Manipulators { Copied: trunk/src/dl-learner/org/dllearner/kb/old/Node.java (from rev 1075, trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/Node.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/Node.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -0,0 +1,99 @@ +/** + * 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()); + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java 2008-08-14 17:33:24 UTC (rev 1075) +++ trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -24,9 +24,6 @@ import java.util.LinkedList; import java.util.Set; -import org.dllearner.kb.extraction.ClassNode; -import org.dllearner.kb.extraction.InstanceNode; -import org.dllearner.kb.extraction.Node; import org.dllearner.utilities.datastructures.StringTuple; /** Copied: trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java (from rev 1075, trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java 2008-08-14 17:35:50 UTC (rev 1076) @@ -0,0 +1,121 @@ +/** + * 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; + +/** + * Property node, has connection to a and b part + * + * @author Sebastian Hellmann + * + */ + +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, Node a, Node b) { + super(u); + // this.type = "property"; + this.a = a; + this.b = b; + this.specialTypes = new HashSet<String>(); + } + + // Property Nodes are normally not expanded, + // this function is never called + @Override + public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulators m) { + return null; + } + + // gets the types for properties recursively + @Override + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulators m) { + b.expandProperties(tsq, m); + Set<StringTuple> s = tsq.getTupelForResource(uri); + + Iterator<StringTuple> it = s.iterator(); + while (it.hasNext()) { + StringTuple t = (StringTuple) it.next(); + try { + if (t.a.equals(Manipulators.type)) { + specialTypes.add(t.b); + } + } catch (Exception e) { + System.out.println(t); + e.printStackTrace(); + } + + } + + } + + public Node getA() { + return a; + } + + public Node getB() { + return b; + } + + @Override + public SortedSet<String> toNTriple() { + SortedSet<String> s = new TreeSet<String>(); + s.add("<" + uri + "><" + + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + "http://www.w3.org/2002/07/owl#ObjectProperty" + ">."); + for (String one : specialTypes) { + s.add("<" + uri + "><" + + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + one + ">."); + + } + + return s; + } + + @Override + public boolean equals(Node n) { + if (this.uri.equals(n.uri)) + return true; + else + return false; + } + + @Override + public int compareTo(Node n) { + return super.compareTo(n); + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/old/PropertyNode.java ___________________________________________________________________ Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |