From: <ku...@us...> - 2008-08-14 18:09:25
|
Revision: 1077 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1077&view=rev Author: kurzum Date: 2008-08-14 18:09:20 +0000 (Thu, 14 Aug 2008) Log Message: ----------- more movements Modified Paths: -------------- 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/utilities/owl/OWLVocabulary.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java Added: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -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.extraction; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.aquisitors.TupelAquisitor; +import org.dllearner.kb.manipulator.Manipulator; +import org.dllearner.utilities.datastructures.RDFNodeTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +/** + * Is a node in the graph, that is a class. + * + * @author Sebastian Hellmann + */ +public class ClassNode extends Node { + SortedSet<PropertyNode> properties = new TreeSet<PropertyNode>(); + + public ClassNode(URI u) { + super(u); + } + + // expands all directly connected nodes + @Override + public List<Node> expand(TupelAquisitor tupelAquisitor, Manipulator manipulator) { + + SortedSet<RDFNodeTuple> newTuples = tupelAquisitor.getTupelForResource(this.uri); + // see manipulator + newTuples = manipulator.manipulate(this, newTuples); + + List<Node> newNodes = new ArrayList<Node>(); + for (RDFNodeTuple tuple : newTuples) { + try { + String property = tuple.a.toString(); + // substitute rdf:type with owl:subclassof + if (property.equals(OWLVocabulary.RDF_TYPE) || property.equals(OWLVocabulary.RDFS_SUBCLASS_OF)) { + ClassNode tmp = new ClassNode(new URI(tuple.b.toString())); + properties.add(new PropertyNode(new URI( OWLVocabulary.RDFS_SUBCLASS_OF), this, + tmp)); + newNodes.add(tmp); + } else { + // further expansion stops here + // Nodes.add(tmp); is missing on purpose + ClassNode tmp = new ClassNode(new URI(tuple.b.toString())); + properties.add(new PropertyNode(new URI(tuple.a.toString()), 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 + + // Nodes.add(tmp); + } + + + + + } catch (Exception e) { + System.out.println("ClassNode"); + e.printStackTrace(); + } + } + return newNodes; + } + + // gets the types for properties recursively + @Override + public void expandProperties(TupelAquisitor tupelAquisitor, Manipulator manipulator) { + } + + /* + * (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 + "><" + OWLVocabulary.RDF_TYPE + "><" + OWLVocabulary.OWL_CLASS + ">."); + + 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); + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -0,0 +1,98 @@ +/** + * 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.List; +import java.util.SortedSet; + +import org.dllearner.kb.aquisitors.TupelAquisitor; +import org.dllearner.kb.manipulator.Manipulator; + + + +/** + * Abstract class. defines functions to expand the nodes + * + * @author Sebastian Hellmann + * + */ +public abstract class Node implements Comparable<Node> { + + + + protected URI uri; + // protected String type; + protected boolean expanded = false; + + public Node(URI uri) { + this.uri = uri; + } + + /** + * 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 List<Node> expand( + TupelAquisitor TupelAquisitor, Manipulator manipulator); + + /** + * gets type defs for properties like rdf:type SymmetricProperties + * + * @param typedSparqlQuery + * @param manipulator + * @return Vector<Node> + */ + public abstract void expandProperties( + TupelAquisitor TupelAquisitor, Manipulator 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()); + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -0,0 +1,116 @@ +/** + * 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.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.aquisitors.TupelAquisitor; +import org.dllearner.kb.manipulator.Manipulator; +import org.dllearner.utilities.datastructures.RDFNodeTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +/** + * 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 SortedSet<String> specialTypes; + + public PropertyNode(URI uri, Node a, Node b) { + super(uri); + // this.type = "property"; + this.a = a; + this.b = b; + this.specialTypes = new TreeSet<String>(); + } + + // Property Nodes are normally not expanded, + // this function is never called + @Override + public List<Node> expand(TupelAquisitor tupelAquisitor, Manipulator manipulator) { + return null; + } + + // gets the types for properties recursively + @Override + public void expandProperties(TupelAquisitor tupelAquisitor, Manipulator manipulator) { + b.expandProperties(tupelAquisitor, manipulator); + SortedSet<RDFNodeTuple> newTypes = tupelAquisitor.getTupelForResource(uri); + for (RDFNodeTuple tuple : newTypes) { + try { + if (tuple.a.equals(OWLVocabulary.RDF_TYPE)) { + specialTypes.add(tuple.b.toString()); + } + } catch (Exception e) { + System.out.println(tuple); + 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 + "><" + OWLVocabulary.RDF_TYPE + "><" + + OWLVocabulary.OWL_OBJECTPROPERTY + ">."); + for (String one : specialTypes) { + s.add("<" + uri + "><" + OWLVocabulary.RDF_TYPE + "><" + + one + ">."); + } + + return s; + } + + //TODO check + @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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -4,7 +4,7 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.kb.old.Node; +import org.dllearner.kb.extraction.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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -21,8 +21,8 @@ import java.util.SortedSet; -import org.dllearner.kb.old.DBpediaNavigatorCityLocator; -import org.dllearner.kb.old.Node; + +import org.dllearner.kb.extraction.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.owl.OWLVocabulary; @@ -62,7 +62,7 @@ } if (clazz.toString().equals("http://dbpedia.org/class/yago/City108524735")){ - String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); + String newType = getTypeToCoordinates(lat, lng); tuples.add(new RDFNodeTuple(new ResourceImpl(OWLVocabulary.RDF_TYPE),new ResourceImpl(newType))); //tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); tuples.remove(typeTuple); 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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -23,10 +23,10 @@ import java.util.List; import java.util.SortedSet; +import org.dllearner.kb.extraction.ClassNode; +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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -5,7 +5,7 @@ import java.util.List; import java.util.SortedSet; -import org.dllearner.kb.old.Node; +import org.dllearner.kb.extraction.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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -3,7 +3,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.kb.old.Node; +import org.dllearner.kb.extraction.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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -3,7 +3,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.kb.old.Node; +import org.dllearner.kb.extraction.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:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -3,7 +3,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.kb.old.Node; +import org.dllearner.kb.extraction.Node; import org.dllearner.utilities.datastructures.RDFNodeTuple; public class TypeFilterRule extends Rule{ Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-14 17:35:50 UTC (rev 1076) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-14 18:09:20 UTC (rev 1077) @@ -12,6 +12,7 @@ public static final String OWL_CLASS = "http://www.w3.org/2002/07/owl#Class"; public static final String OWL_THING = "http://www.w3.org/2002/07/owl#Thing"; + // public static final String RDF_TYPE = ""; // public static final String RDF_TYPE = ""; // public static final String RDF_TYPE = ""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |