From: <jen...@us...> - 2007-12-03 18:13:21
|
Revision: 318 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=318&view=rev Author: jenslehmann Date: 2007-12-03 10:13:19 -0800 (Mon, 03 Dec 2007) Log Message: ----------- started list of string tuples as config option Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Tupel.java Modified: trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/core/config/StringSetConfigOption.java 2007-12-03 18:13:19 UTC (rev 318) @@ -23,6 +23,8 @@ /** + * A set of strings. + * * @author Jens Lehmann * */ Added: trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/config/StringTupleListConfigOption.java 2007-12-03 18:13:19 UTC (rev 318) @@ -0,0 +1,67 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core.config; + +import java.util.List; + +import org.dllearner.utilities.StringTuple; + +/** + * A list if string tuples, for instance for specifying several + * parameters or replacement rules. + * + * @author Jens Lehmann + */ +public class StringTupleListConfigOption extends ConfigOption<List<StringTuple>> { + + public StringTupleListConfigOption(String name, String description) { + this(name, description, null); + } + + public StringTupleListConfigOption(String name, String description, List<StringTuple> defaultValue) { + super(name, description, defaultValue); + } + + /* (non-Javadoc) + * @see org.dllearner.core.config.ConfigOption#checkType(java.lang.Object) + */ + @Override + public boolean checkType(Object object) { + if(!(object instanceof List)) + return false; + + List<?> set = (List<?>) object; + for(Object element : set) { + if(!(element instanceof StringTuple)) + return false; + } + + return true; + } + + /* (non-Javadoc) + * @see org.dllearner.core.config.ConfigOption#isValidValue(java.lang.Object) + */ + @Override + public boolean isValidValue(List<StringTuple> value) { + return true; + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-03 18:13:19 UTC (rev 318) @@ -25,6 +25,8 @@ import java.util.Set; import java.util.Vector; +import org.dllearner.utilities.StringTuple; + // is a node in the graph that is a class public class ClassNode extends Node { Set<PropertyNode> properties = new HashSet<PropertyNode>(); @@ -36,14 +38,14 @@ @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { - Set<Tupel> s = tsq.query(this.uri); + Set<StringTuple> s = tsq.query(this.uri); s = m.check(s, this); Vector<Node> Nodes = new Vector<Node>(); // Manipulation - Iterator<Tupel> it = s.iterator(); + Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { - Tupel t = (Tupel) it.next(); + StringTuple t = (StringTuple) it.next(); try { if (t.a.equals(m.type) || t.a.equals(m.subclass)) { ClassNode tmp = new ClassNode(new URI(t.b)); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-03 18:13:19 UTC (rev 318) @@ -25,11 +25,13 @@ import java.util.Set; import java.util.Vector; +import org.dllearner.utilities.StringTuple; + // a node in the graph that is an instance public class InstanceNode extends Node { Set<ClassNode> classes = new HashSet<ClassNode>(); - Set<Tupel> datatypes = new HashSet<Tupel>(); + Set<StringTuple> datatypes = new HashSet<StringTuple>(); Set<PropertyNode> properties = new HashSet<PropertyNode>(); public InstanceNode(URI u) { @@ -41,15 +43,15 @@ @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { - Set<Tupel> s = tsq.query(uri); + Set<StringTuple> s = tsq.query(uri); // Manipulation m.check(s, this); // System.out.println("fffffff"+m); Vector<Node> Nodes = new Vector<Node>(); - Iterator<Tupel> it = s.iterator(); + Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { - Tupel t = (Tupel) it.next(); + StringTuple t = (StringTuple) it.next(); try { if (t.a.equals(m.type)) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-03 18:13:19 UTC (rev 318) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Set; +import org.dllearner.utilities.StringTuple; + // an object of this class encapsulates everything public class Manager { @@ -47,9 +49,9 @@ } catch (Exception e) { e.printStackTrace(); } - Set<Tupel> t = this.typedSparqlQuery.getTupelsForRole(u); + Set<StringTuple> t = this.typedSparqlQuery.getTupelsForRole(u); Set<String> ret = new HashSet<String>(); - for (Tupel one : t) { + for (StringTuple one : t) { ret.add(one.a); } return ret; @@ -62,9 +64,9 @@ } catch (Exception e) { e.printStackTrace(); } - Set<Tupel> t = this.typedSparqlQuery.getTupelsForRole(u); + Set<StringTuple> t = this.typedSparqlQuery.getTupelsForRole(u); Set<String> ret = new HashSet<String>(); - for (Tupel one : t) { + for (StringTuple one : t) { ret.add(one.b); } return ret; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2007-12-03 18:13:19 UTC (rev 318) @@ -23,6 +23,8 @@ import java.util.Iterator; import java.util.Set; +import org.dllearner.utilities.StringTuple; + // used to manipulate retrieved tupels, identify blanknodes, etc. public class Manipulator { public String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; @@ -46,11 +48,11 @@ } - public Set<Tupel> check(Set<Tupel> s, Node node) { - Set<Tupel> toRemove = new HashSet<Tupel>(); - Iterator<Tupel> it = s.iterator(); + public Set<StringTuple> check(Set<StringTuple> s, Node node) { + Set<StringTuple> toRemove = new HashSet<StringTuple>(); + Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { - Tupel t = (Tupel) it.next(); + StringTuple t = (StringTuple) it.next(); // System.out.println(t); // all classes with owl:type class if (t.a.equals(type) && t.b.equals(classns) && node instanceof ClassNode) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-03 18:13:19 UTC (rev 318) @@ -25,6 +25,8 @@ import java.util.Set; import java.util.Vector; +import org.dllearner.utilities.StringTuple; + public class PropertyNode extends Node { private Node a; @@ -47,13 +49,13 @@ @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { - Set<Tupel> s = tsq.query(uri); + Set<StringTuple> s = tsq.query(uri); Vector<Node> Nodes = new Vector<Node>(); // Manipulation - Iterator<Tupel> it = s.iterator(); + Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { - Tupel t = (Tupel) it.next(); + StringTuple t = (StringTuple) it.next(); try { if (t.a.equals(m.type)) { specialTypes.add(t.b); Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Tupel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Tupel.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Tupel.java 2007-12-03 18:13:19 UTC (rev 318) @@ -1,45 +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.sparql; - -// a container which can hold two Strings, mainly used as a helper -public class Tupel { - - public String a; - public String b; - - public Tupel(String a, String b) { - this.a = a; - this.b = b; - } - - @Override - public String toString() { - return "<" + a + "|" + b + ">"; - } - - public boolean equals(Tupel t) { - if (a.equals(t.a) && b.equals(t.b)) - return true; - else - return false; - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-03 17:58:20 UTC (rev 317) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-03 18:13:19 UTC (rev 318) @@ -32,6 +32,8 @@ import java.util.Iterator; import java.util.Set; +import org.dllearner.utilities.StringTuple; + // can execute different queries public class TypedSparqlQuery { private Configuration configuration; @@ -47,7 +49,7 @@ this.cache = new Cache("cache"); } - public Set<Tupel> query(URI u) { + public Set<StringTuple> query(URI u) { // getQuery String sparql = sparqlQueryMaker.makeSubjectQueryUsingFilters(u.toString()); @@ -55,18 +57,18 @@ } - public Set<Tupel> getTupelsForRole(URI u) { + public Set<StringTuple> getTupelsForRole(URI u) { // getQuery String sparql = sparqlQueryMaker.makeRoleQueryUsingFilters(u.toString()); - Set<Tupel> s = cachedSparql(u, sparql, "subject", "object"); + Set<StringTuple> s = cachedSparql(u, sparql, "subject", "object"); // System.out.println(s); return s; } - private Set<Tupel> cachedSparql(URI u, String sparql, String a, String b) { + private Set<StringTuple> cachedSparql(URI u, String sparql, String a, String b) { // check cache String FromCache = cache.get(u.toString(), sparql); @@ -91,7 +93,7 @@ // System.out.println(sparql); // System.out.println(xml); // process XML - Set<Tupel> s = processResult(xml, a, b); + Set<StringTuple> s = processResult(xml, a, b); try { System.out.println("retrieved " + s.size() + " tupels\n"); } catch (Exception e) { @@ -99,9 +101,9 @@ return s; } - public Set<Tupel> processResult(String xml, String a, String b) { + public Set<StringTuple> processResult(String xml, String a, String b) { - Set<Tupel> ret = new HashSet<Tupel>(); + Set<StringTuple> ret = new HashSet<StringTuple>(); // TODO if result is empty, catch exceptions String one = "<binding name=\"" + a + "\">"; String two = "<binding name=\"" + b + "\">"; @@ -120,7 +122,7 @@ xml = xml.substring(xml.indexOf(two) + two.length()); xml = xml.substring(xml.indexOf(uridel) + uridel.length()); objtmp = xml.substring(0, xml.indexOf(end)); - ret.add(new Tupel(predtmp, objtmp)); + ret.add(new StringTuple(predtmp, objtmp)); // System.out.println(new Tupel(predtmp,objtmp)); } Added: trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/StringTuple.java 2007-12-03 18:13:19 UTC (rev 318) @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.utilities; + +/** + * A container which can hold two Strings, mainly used as a helper. + * + * @author Sebastian Hellmann + */ +public class StringTuple { + + public String a; + public String b; + + public StringTuple(String a, String b) { + this.a = a; + this.b = b; + } + + @Override + public String toString() { + return "<" + a + "|" + b + ">"; + } + + public boolean equals(StringTuple t) { + if (a.equals(t.a) && b.equals(t.b)) + return true; + else + return false; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |