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. |
From: <ku...@us...> - 2008-08-18 20:36:05
|
Revision: 1097 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1097&view=rev Author: kurzum Date: 2008-08-18 20:35:55 +0000 (Mon, 18 Aug 2008) Log Message: ----------- improved sparql aquisition almost there Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-18 15:42:55 UTC (rev 1096) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-18 20:35:55 UTC (rev 1097) @@ -19,13 +19,22 @@ */ package org.dllearner.kb.aquisitors; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.SortedSet; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.RDFNodeTuple; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.sparql.core.ResultBinding; +import com.hp.hpl.jena.sparql.resultset.ResultSetRewindable; + /** * Can execute different queries. * @@ -36,23 +45,81 @@ @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(SparqlTupelAquisitorImproved.class); + private Map<String,SortedSet<RDFNodeTuple>> resources = new HashMap<String, SortedSet<RDFNodeTuple>>(); + int recursionDepth; - public SparqlTupelAquisitorImproved(SparqlQueryMaker sparqlQueryMaker, SPARQLTasks sparqlTasks) { + public SparqlTupelAquisitorImproved(SparqlQueryMaker sparqlQueryMaker, SPARQLTasks sparqlTasks, int recursionDepth) { super(sparqlQueryMaker, sparqlTasks); + this.recursionDepth = recursionDepth; } // standard query get a tupels (p,o) for subject s +// standard query get a tupels (p,o) for subject s @Override public SortedSet<RDFNodeTuple> getTupelForResource(String uri) { + checkURIforValidity(uri); + String sparqlQueryString = ""; + String pred = "predicate"; + String obj = "object"; - throw new RuntimeException("not implemented yet"); - + // getQuery + if (classMode) { + + + sparqlQueryString = sparqlQueryMaker.makeClassQueryUsingFilters(uri); + return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); + } + + SortedSet<RDFNodeTuple> cachedSet = resources.get(uri); + if(cachedSet!=null) { + return cachedSet; + } + + //SortedSet<RDFNodeTuple> tmp = new TreeSet<RDFNodeTuple>(); + sparqlQueryString = sparqlQueryMaker.makeSubjectQueryLevel(uri, recursionDepth); + ResultSetRewindable rsw= sparqlTasks.queryAsResultSet(sparqlQueryString); + @SuppressWarnings("unchecked") + List<ResultBinding> l = ResultSetFormatter.toList(rsw); + rsw.reset(); + + int resultsetcount = 0; + int i = 0; + for (ResultBinding binding : l) { + i=0; + RDFNode nextURI = binding.get(obj+i); + add(uri, new RDFNodeTuple(binding.get(pred+i), nextURI )); + + for (i=1; i < recursionDepth; i++) { + RDFNode tmpURI = binding.get(obj+i); + add(nextURI.toString(), new RDFNodeTuple(binding.get(pred+i),tmpURI)); + logger.trace("For: "+nextURI.toString()+ " added :"+resources.get(nextURI.toString())); + nextURI = tmpURI; + } + + resultsetcount++; + } + + if(resultsetcount>999) { + logger.warn("SparqlTupelAquisitor retrieved more than 1000 results, there might some be missing"); + } + return resources.get(uri); + + //return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); } - - + private void add(String uri, RDFNodeTuple tuple){ + SortedSet<RDFNodeTuple> set = resources.get(uri); + if(set==null){ + set = new TreeSet<RDFNodeTuple>(); + set.add(tuple); + resources.put(uri, set ); + }else { + set.add(tuple); + } + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-18 15:42:55 UTC (rev 1096) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-18 20:35:55 UTC (rev 1097) @@ -59,7 +59,7 @@ for (String str : s) { nt.append(str + "\n"); } - System.out.println("sizeofStringBuffer"+nt.length()); + logger.info("sizeofStringBuffer"+nt.length()); return nt.toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-19 15:41:48
|
Revision: 1103 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1103&view=rev Author: kurzum Date: 2008-08-19 15:41:45 +0000 (Tue, 19 Aug 2008) Log Message: ----------- small changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java Modified: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-19 15:35:22 UTC (rev 1102) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-19 15:41:45 UTC (rev 1103) @@ -70,13 +70,9 @@ @SuppressWarnings("unchecked") List<ResultBinding> l = ResultSetFormatter.toList(rsw); rsw.reset(); - int count = 0; - - for (ResultBinding binding : l) { - count++; - } + int resultsetcount = 0; int i = 0; for (ResultBinding binding : l) { @@ -95,14 +91,14 @@ }else if (tmpOBJURI.isLiteral()) { tmptuple = new RDFNodeTuple(tmpPREDURI, tmpOBJURI ); add(nextOBJ.toString(), tmptuple); - logger.trace(tmptuple); - logger.trace("For: "+nextOBJ.toString()+ " added :"+resources.get(nextOBJ.toString())); + //logger.trace(tmptuple); + //logger.trace("For: "+nextOBJ.toString()+ " added :"+resources.get(nextOBJ.toString())); cont=false; }else { tmptuple = new RDFNodeTuple(tmpPREDURI, tmpOBJURI ); add(nextOBJ.toString(), tmptuple); - logger.trace(tmptuple); - logger.trace("For: "+nextOBJ.toString()+ " added :"+resources.get(nextOBJ.toString())); + //logger.trace(tmptuple); + //logger.trace("For: "+nextOBJ.toString()+ " added :"+resources.get(nextOBJ.toString())); nextOBJ = tmpOBJURI; cont = true; } @@ -112,7 +108,7 @@ } //System.out.println("original count "+count); - logger.warn("SparqlTupelAquisitor retrieved : "+resultsetcount); + //logger.warn("SparqlTupelAquisitor retrieved : "+resultsetcount); if(resultsetcount>999) { logger.warn("SparqlTupelAquisitor retrieved more than 1000 results, there might some be missing"); } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-19 15:35:22 UTC (rev 1102) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-19 15:41:45 UTC (rev 1103) @@ -78,12 +78,12 @@ List<Node> tmp = new ArrayList<Node>(); - logger.info(seedNode); + logger.info("Seed Node: "+seedNode); newNodes.add(seedNode); - logger.info("Starting Nodes: " + newNodes); + - for (int x = 0; x < configuration.getRecursiondepth(); x++) { + for (int x = 1; x <= configuration.getRecursiondepth(); x++) { sc.reset(); while (!newNodes.isEmpty()) { Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-19 15:35:22 UTC (rev 1102) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-19 15:41:45 UTC (rev 1103) @@ -58,11 +58,11 @@ */ public SortedSet<RDFNodeTuple> manipulate( Node node, SortedSet<RDFNodeTuple> tuples) { JamonMonitorLogger.getTimeMonitor(Manipulator.class, "Time for Rules").start(); - logger.warn("before: "+tuples.size()); + //logger.warn("before: "+tuples.size()); for (Rule rule : rules) { tuples = rule.applyRule(node, tuples); } - logger.warn("after: "+tuples.size()); + //logger.warn("after: "+tuples.size()); JamonMonitorLogger.getTimeMonitor(Manipulator.class, "Time for Rules").stop(); return tuples; } Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java 2008-08-19 15:35:22 UTC (rev 1102) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java 2008-08-19 15:41:45 UTC (rev 1103) @@ -48,8 +48,8 @@ public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); for (RDFNodeTuple tuple : tuples) { - String a = tuple.a.toString(); - String b = tuple.b.toString(); + //String a = tuple.a.toString(); + //String b = tuple.b.toString(); //System.out.println(a+b); boolean remove = (tuple.aPartContains(predicateFilter) && tuple.bPartContains(objectFilter) && This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2009-05-19 17:51:56
|
Revision: 1760 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1760&view=rev Author: kurzum Date: 2009-05-19 17:51:46 +0000 (Tue, 19 May 2009) Log Message: ----------- fix Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/StringToResource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2009-05-19 17:23:45 UTC (rev 1759) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2009-05-19 17:51:46 UTC (rev 1760) @@ -80,7 +80,7 @@ } else if(predefinedManipulator.equalsIgnoreCase("DEFAULT") ||predefinedManipulator.equalsIgnoreCase("STANDARD")){ return getDefaultManipulator(); - } + } else { //QUALITY maybe not the best, return getDefaultManipulator(); Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/StringToResource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/StringToResource.java 2009-05-19 17:23:45 UTC (rev 1759) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/StringToResource.java 2009-05-19 17:51:46 UTC (rev 1760) @@ -48,7 +48,7 @@ slash="/"; } - this.namespace = slash+resourceNamespace; + this.namespace = resourceNamespace+slash; this.limit = limit; } @@ -57,20 +57,26 @@ public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); for (RDFNodeTuple tuple : tuples) { + // do nothing if the object contains http:// - if(!tuple.b.isResource()){ + if(!tuple.b.isURIResource()){ boolean replace = true; + //check for numbers - if(((Literal) tuple.b).getDatatypeURI().contains("decimal")){ + if(((Literal) tuple.b).getDatatypeURI()!= null){ replace = false; } - // do nothing if limit is exceeded if(limit != 0 && tuple.b.toString().length()>limit){ replace = false; } + if(tuple.b.toString().startsWith("http://")){ + replace= false; + } + + if (replace){ String tmp = tuple.b.toString(); @@ -78,7 +84,8 @@ //encode tmp = URLEncoder.encode(tmp, "UTF-8"); }catch (Exception e) { - // TODO: handle exception + e.printStackTrace(); + System.exit(0); } tuple.b = new ResourceImpl(namespace+tmp); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2009-05-19 17:23:45 UTC (rev 1759) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2009-05-19 17:51:46 UTC (rev 1760) @@ -111,7 +111,9 @@ private OWLOntology fragment; + private Manipulator manipulator = null; + // received ontology as array, used if format=Array(an element of the // array consists of the subject, predicate and object separated by '<' @@ -435,6 +437,11 @@ } public Manipulator getManipulator() { + + if(this.manipulator!=null){ + return this.manipulator; + } + // get Options for Filters if (configurator.getPredefinedManipulator() != null) { return Manipulator.getManipulatorByName(configurator @@ -452,6 +459,11 @@ } } + + public void setManipulator(Manipulator m ){ + this.manipulator = m; + + } public TupleAquisitor getTupleAquisitor() { TupleAquisitor ret = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2009-08-24 13:27:55
|
Revision: 1830 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1830&view=rev Author: lorenz_b Date: 2009-08-24 13:27:45 +0000 (Mon, 24 Aug 2009) Log Message: ----------- some changes for simple Sparql progress monitor Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2009-08-24 09:19:17 UTC (rev 1829) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2009-08-24 13:27:45 UTC (rev 1830) @@ -27,6 +27,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import javax.swing.ProgressMonitor; + import org.apache.log4j.Logger; import org.dllearner.utilities.JamonMonitorLogger; import org.semanticweb.owl.model.OWLOntology; @@ -46,6 +48,8 @@ private int nrOfExtractedTriples = 0; private List<Node> seedNodes = new ArrayList<Node>(); + private ProgressMonitor mon; + private static Logger logger = Logger .getLogger(Manager.class); @@ -69,9 +73,16 @@ public List<Node> extract(Set<String> instances) { List<Node> allExtractedNodes = new ArrayList<Node>(); logger.info("Start extracting "+instances.size() + " instances "); + if(mon != null){ + mon.setNote("Start extracting "+instances.size() + " instances "); + mon.setMaximum(instances.size()); + } int progress=0; for (String one : instances) { progress++; + if(mon != null){ + mon.setProgress(progress); + } logger.info("Progress: "+progress+" of "+instances.size()+" finished: "+one); try { Node n = extractionAlgorithm.expandNode(one, configuration.getTupelAquisitor()); @@ -144,4 +155,7 @@ return nrOfExtractedTriples; } + public void addProgressMonitor(ProgressMonitor mon){ + this.mon = mon; + } } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2009-08-24 09:19:17 UTC (rev 1829) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2009-08-24 13:27:45 UTC (rev 1830) @@ -28,6 +28,8 @@ import java.util.List; import java.util.TreeSet; +import javax.swing.ProgressMonitor; + import org.apache.log4j.Logger; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.OntologyFormat; @@ -59,6 +61,7 @@ import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.datastructures.StringTuple; import org.dllearner.utilities.statistics.SimpleClock; +import org.mindswap.pellet.utils.progress.SilentProgressMonitor; import org.semanticweb.owl.model.OWLOntology; import com.jamonapi.Monitor; @@ -73,6 +76,7 @@ */ public class SparqlKnowledgeSource extends KnowledgeSource { + private ProgressMonitor mon; private static final boolean debug = false; @@ -236,11 +240,14 @@ logger.info("SparqlModul: Collecting Ontology"); SimpleClock totalTime = new SimpleClock(); //SimpleClock extractionTime = new SimpleClock(); - + if(mon != null){ + mon.setNote("Collecting Ontology"); + } logger.trace(getURL()); logger.trace(getSparqlEndpoint()); logger.trace(configurator.getInstances()); Manager m = new Manager(); + m.addProgressMonitor(mon); // get Options for Manipulator Manipulator manipulator = getManipulator(); @@ -509,6 +516,10 @@ public int getNrOfExtractedAxioms() { return nrOfExtractedAxioms; } + + public void addProgressMonitor(ProgressMonitor mon){ + this.mon = mon; + } /* * public static void main(String[] args) throws MalformedURLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |