From: <jen...@us...> - 2008-02-04 14:54:12
|
Revision: 489 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=489&view=rev Author: jenslehmann Date: 2008-02-04 06:54:07 -0800 (Mon, 04 Feb 2008) Log Message: ----------- - moved all tests to org.dllearner.test - some cleanup, fixed warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/server/ClientState.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java trunk/src/dl-learner/org/dllearner/test/junit/ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java trunk/src/dl-learner/org/dllearner/test/junit/package.html Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/ trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java trunk/src/dl-learner/org/dllearner/test/ComponentTests.java trunk/src/dl-learner/org/dllearner/test/package.html Deleted: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,84 +0,0 @@ -/** - * 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; - -import java.io.File; -import java.util.Set; -import java.util.TreeSet; - -import org.dllearner.algorithms.RandomGuesser; -import org.dllearner.kb.OWLFile; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.reasoning.DIGReasoner; - -/** - * Test for component based design. - * - * @author Jens Lehmann - * - */ -public class ComponentTest { - - /** - * @param args - */ - public static void main(String[] args) { - - // get singleton instance of component manager - ComponentManager cm = ComponentManager.getInstance(); - - // create knowledge source - KnowledgeSource source = cm.knowledgeSource(OWLFile.class); - String example = "examples/father.owl"; - cm.applyConfigEntry(source, "url", new File(example).toURI().toString()); - source.init(); - - // create DIG reasoning service with standard settings - ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); - // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); - reasoner.init(); - ReasoningService rs = cm.reasoningService(reasoner); - - // create a learning problem and set positive and negative examples - LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); - Set<String> positiveExamples = new TreeSet<String>(); - positiveExamples.add("http://example.com/father#stefan"); - positiveExamples.add("http://example.com/father#markus"); - positiveExamples.add("http://example.com/father#martin"); - Set<String> negativeExamples = new TreeSet<String>(); - negativeExamples.add("http://example.com/father#heinz"); - negativeExamples.add("http://example.com/father#anna"); - negativeExamples.add("http://example.com/father#michelle"); - cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); - cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); - lp.init(); - - // create the learning algorithm - LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); - cm.applyConfigEntry(la, "numberOfTrees", 100); - cm.applyConfigEntry(la, "maxDepth", 5); - la.init(); - - // start the algorithm and print the best concept found - la.start(); - System.out.println(la.getBestSolution()); - } - -} Modified: trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-02-04 14:54:07 UTC (rev 489) @@ -34,6 +34,7 @@ } // method to start thread + @Override public void run() { if (config.getLearningAlgorithm() != null) config.getLearningAlgorithm().start(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-02-04 14:54:07 UTC (rev 489) @@ -160,20 +160,6 @@ } /** - * sends a query and returns complicated Jena List with ResultBindings - * - * - * @return jena List<ResultBinding> - */ - @Deprecated - @SuppressWarnings( { "unchecked" }) - public List<ResultBinding> getAsList() { - if (rs == null) - this.send(); - return ResultSetFormatter.toList(rs); - } - - /** * Converts Jena result set to JSON. * * @param resultSet The result set to transform. Deleted: trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,65 +0,0 @@ -package org.dllearner.reasoning; - -import org.semanticweb.owl.model.*; -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.inference.OWLReasoner; -import org.semanticweb.owl.inference.OWLReasonerException; - -import java.net.URI; -import java.util.HashSet; -import java.util.Set; -import java.io.File; - -public class FaCTBugDemo { - - public static void main(String[] args) { - - try { - URI uri = new File("examples/father.owl").toURI(); - - // Create our ontology manager in the usual way. - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - - // Load a copy of the pizza ontology. We'll load the ontology from the web. - OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri); - - OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); - // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); - - // seems to be needed for some reason although no ontology is imported - Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); - reasoner.loadOntologies(importsClosure); - - reasoner.classify(); - reasoner.realise(); - - OWLDataFactory factory = manager.getOWLDataFactory(); - - OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male")); - OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild")); - OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing()); - Set<OWLDescription> set = new HashSet<OWLDescription>(); - set.add(male); - set.add(hasSomeChild); - OWLDescription father = factory.getOWLObjectIntersectionOf(set); - OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin")); - - if(reasoner.hasType(martin, father, false)) - System.out.println("positive result"); // Pellet 1.5.1 (correct) - else - System.out.println("negative result"); // FaCT++ 1.10 - - } - catch(UnsupportedOperationException exception) { - System.out.println("Unsupported reasoner operation."); - } - catch(OWLReasonerException ex) { - System.out.println("Reasoner error: " + ex.getMessage()); - } - catch (OWLOntologyCreationException e) { - System.out.println("Could not load the pizza ontology: " + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - } - } -} Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-02-04 14:54:07 UTC (rev 489) @@ -34,7 +34,6 @@ import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryThreaded; /** Deleted: trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.test; - -import org.junit.runner.JUnitCore; - -/** - * Class designed to run all DL-Learner component tests. Note, - * that in Eclipse (and similar in other IDEs) you can run - * JUnit tests by clicking on a file containing methods annotated - * with @Test and "Run As JUnit Test". - * - * @author Jens Lehmann - * - */ -public class AllTestsRunner { - - public static void main(String[] args) { - JUnitCore.main("org.dllearner.test.ComponentTests"); - } - -} Copied: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java (from rev 488, trunk/src/dl-learner/org/dllearner/core/ComponentTest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,90 @@ +/** + * 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.test; + +import java.io.File; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.algorithms.RandomGuesser; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.reasoning.DIGReasoner; + +/** + * Test for component based design. + * + * @author Jens Lehmann + * + */ +public class ComponentTest { + + /** + * @param args + */ + public static void main(String[] args) { + + // get singleton instance of component manager + ComponentManager cm = ComponentManager.getInstance(); + + // create knowledge source + KnowledgeSource source = cm.knowledgeSource(OWLFile.class); + String example = "examples/father.owl"; + cm.applyConfigEntry(source, "url", new File(example).toURI().toString()); + source.init(); + + // create DIG reasoning service with standard settings + ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); + // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); + reasoner.init(); + ReasoningService rs = cm.reasoningService(reasoner); + + // create a learning problem and set positive and negative examples + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + Set<String> positiveExamples = new TreeSet<String>(); + positiveExamples.add("http://example.com/father#stefan"); + positiveExamples.add("http://example.com/father#markus"); + positiveExamples.add("http://example.com/father#martin"); + Set<String> negativeExamples = new TreeSet<String>(); + negativeExamples.add("http://example.com/father#heinz"); + negativeExamples.add("http://example.com/father#anna"); + negativeExamples.add("http://example.com/father#michelle"); + cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); + cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); + lp.init(); + + // create the learning algorithm + LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + cm.applyConfigEntry(la, "numberOfTrees", 100); + cm.applyConfigEntry(la, "maxDepth", 5); + la.init(); + + // start the algorithm and print the best concept found + la.start(); + System.out.println(la.getBestSolution()); + } + +} Deleted: trunk/src/dl-learner/org/dllearner/test/ComponentTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTests.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTests.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.test; - -import java.util.List; - -import org.dllearner.core.Component; -import org.dllearner.core.ComponentManager; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * A suite of JUnit tests related to the DL-Learner component architecture. - * - * @author Jens Lehmann - * - */ -public class ComponentTests { - - /** - * Checks whether all components implement the getName() method. While it - * cannot be enforced to implement a static method, it should be done (e.g. - * to be used as label for the component in GUIs). - */ - @Test - public void nameTest() { - String defaultName = Component.getName(); - ComponentManager cm = ComponentManager.getInstance(); - List<Class<? extends Component>> components = cm.getComponents(); - for (Class<? extends Component> component : components) { - String componentName = cm.getComponentName(component); - assertFalse(component + " does not overwrite getName().", componentName - .equals(defaultName)); - } - } - -} Copied: trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java (from rev 488, trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,65 @@ +package org.dllearner.test; + +import org.semanticweb.owl.model.*; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; +import org.semanticweb.owl.inference.OWLReasonerException; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; +import java.io.File; + +public class FaCTBugDemo { + + public static void main(String[] args) { + + try { + URI uri = new File("examples/father.owl").toURI(); + + // Create our ontology manager in the usual way. + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + // Load a copy of the pizza ontology. We'll load the ontology from the web. + OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri); + + OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); + // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); + + // seems to be needed for some reason although no ontology is imported + Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); + reasoner.loadOntologies(importsClosure); + + reasoner.classify(); + reasoner.realise(); + + OWLDataFactory factory = manager.getOWLDataFactory(); + + OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male")); + OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild")); + OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing()); + Set<OWLDescription> set = new HashSet<OWLDescription>(); + set.add(male); + set.add(hasSomeChild); + OWLDescription father = factory.getOWLObjectIntersectionOf(set); + OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin")); + + if(reasoner.hasType(martin, father, false)) + System.out.println("positive result"); // Pellet 1.5.1 (correct) + else + System.out.println("negative result"); // FaCT++ 1.10 + + } + catch(UnsupportedOperationException exception) { + System.out.println("Unsupported reasoner operation."); + } + catch(OWLReasonerException ex) { + System.out.println("Reasoner error: " + ex.getMessage()); + } + catch (OWLOntologyCreationException e) { + System.out.println("Could not load the pizza ontology: " + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Added: trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,102 @@ +package org.dllearner.test; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URLEncoder; + +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +public class JenaHTTPTest { + public static void main(String[] args) throws Exception{ + + String query="SELECT DISTINCT ?object\n"+ + "FROM <http://dbpedia.org>\n"+ + "WHERE { <http://dbpedia.org/resource/Leipzig> <http://www.w3.org/2000/01/rdf-schema#label> ?object}\n"; + + double time=0; + for (int i=0; i<101; i++) + { + if (i!=0) time+=JenaHTTPTest.httpQuery(query); + } + time=time/100; + System.out.println("Durchschnittliche Zeit f�r eine Anfrage per Http-Methode: "+time); + + time=0; + for (int i=0; i<101; i++) + { + if (i!=0) time+=JenaHTTPTest.jenaQuery(query); + } + time=time/100; + System.out.println("Durchschnittliche Zeit f�r eine Anfrage per Jena-Methode: "+time); + } + + private static double jenaQuery(String query) + { + double start=System.currentTimeMillis(); + QueryEngineHTTP queryExecution=new QueryEngineHTTP("http://localhost:8890/sparql",query); + queryExecution.addDefaultGraph("http://dbpedia.org"); + // Jena access to DBpedia SPARQL endpoint + // ResultSet rs = + queryExecution.execSelect(); + double end=System.currentTimeMillis(); + return ((end-start)/1000); + } + + private static double httpQuery(String query) throws Exception + { + char value[]={13,10}; + String cut=new String(value); + String test="GET /sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + URLEncoder.encode(query, "UTF-8")+ + "&format=application%2Fsparql-results%2Bxml HTTP/1.1"+cut+ + "Host: localhost"+cut+ + "Connection: close"+cut+ + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"+cut+ + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"+cut+ + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"+cut+ + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"+cut+ + cut; + String retval=""; + // + double start=System.currentTimeMillis(); + byte resp[]=null; + + try{ + Socket SparqlServer=new Socket(InetAddress.getByName("localhost"),8890); + String request=test; + // send request + (SparqlServer.getOutputStream()).write(request.getBytes()); + + //get Response + resp=readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); + retval=new String(resp); + retval=retval.substring(retval.indexOf(cut+""+cut)+4); + + SparqlServer.close(); + } catch (Exception e){} + double end=System.currentTimeMillis(); + return (end-start)/1000; + } + + private static byte[] readBuffer(InputStream IS) + throws IOException{ + byte buffer[] = new byte[0xffff]; + int nbytes=0; + byte resp[]=new byte[0]; + while ((nbytes=IS.read(buffer))!=-1) { + byte tmp[]=new byte[resp.length+nbytes]; + int i=0; + for (;i<resp.length;i++){ + tmp[i]=resp[i]; + } + for(int a=0;a<nbytes;a++,i++){ + tmp[i]=buffer[a]; + } + resp=tmp; + } + return resp; + } +} Copied: trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java (from rev 488, trunk/src/dl-learner/org/dllearner/kb/sparql/test/JenaQueryToResultSpeedTest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,163 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.test; + +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; + + +public class JenaQueryToResultSpeedTest { + static boolean print_flag=false; + + public static void main(String[] args) { + + String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " + + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" + + "SELECT ?episode ?chalkboard_gag WHERE { ?episode skos:subject" + + " <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>." + + " ?episode dbpedia2:blackboard ?chalkboard_gag }"; + + int howOften=20; + testJenaAsXML(howOften, queryString); + testJenaAsList(howOften, queryString); + testJenaAsJSON(howOften, queryString); + testJenaAsJSONandBack(howOften, queryString); + + + + // compareResults( queryString); + + } + + + public static void testJenaAsXML(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + ResultSet rs = sqJena.send(); + SparqlQuery.getAsXMLString(rs); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + rs = sqJena.send(); + SparqlQuery.getAsXMLString(rs); + p("Jena as XML needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as XML total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + public static void testJenaAsList(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + //sqJena.getAsList(); + sqJena.send(); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + // sqJena.getAsList(); + ResultSet rs = sqJena.send(); + ResultSetFormatter.toList(rs); + p("Jena as List needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as List total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + public static void testJenaAsJSON(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + ResultSet rs = sqJena.send(); + SparqlQuery.getAsJSON(rs); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + rs = sqJena.send(); + SparqlQuery.getAsJSON(rs); + p("Jena as JSON needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as JSON total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + public static void testJenaAsJSONandBack(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + ResultSet rs = sqJena.send(); + SparqlQuery.getAsJSON(rs); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + // System.out.println(sqJena.getAsJSON()); + rs = sqJena.send(); + String json = SparqlQuery.getAsJSON(rs); + SparqlQuery.JSONtoResultSet(json); + p("Jena as JSON and back needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as JSON and back total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + + public static void compareResults(String queryString) { + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); + + ResultSet rs = sqJena.send(); + System.out.println(SparqlQuery.getAsXMLString(rs)); + // System.out.println(sqConv.getAsXMLString("")); + + } + + static void p(String s) { + if (print_flag) + System.out.println(s); + } +} Added: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,69 @@ +/** + * 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.test; + +import java.io.File; +import java.io.FileWriter; +import java.net.URI; +import java.util.LinkedList; + +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.Manipulator; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.utilities.StringTuple; + +/** + * Test class, uses the whole thing + * + * @author Sebastian Hellmann + * + */ +public class SparqlExtractionTest { + + public static void main(String[] args) { + System.out.println("Start"); + // String test2 = "http://www.extraction.org/config#dbpediatest"; + // String test = "http://www.extraction.org/config#localjoseki"; + try { + // URI u = new URI(test); + Manager m = new Manager(); + // m.usePredefinedConfiguration(u); + + URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); + m.useConfiguration( + SparqlQueryType.getFilterByNumber(1),SparqlEndpoint.getEndpointByNumber(1), + new Manipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()), + 1,true,true); + //, , + //manipulator, recursiondepth, getAllSuperClasses, closeAfterRecursion) + + String filename = System.currentTimeMillis() + ".nt"; + FileWriter fw = new FileWriter(new File(filename), true); + fw.write(m.extract(u2)); + fw.flush(); + fw.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} Copied: trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java (from rev 488, trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.test.junit; + +import org.junit.runner.JUnitCore; + +/** + * Class designed to run all DL-Learner component tests. Note, + * that in Eclipse (and similar in other IDEs) you can run + * JUnit tests by clicking on a file containing methods annotated + * with @Test and "Run As JUnit Test". + * + * @author Jens Lehmann + * + */ +public class AllTestsRunner { + + public static void main(String[] args) { + JUnitCore.main("org.dllearner.test.ComponentTests"); + } + +} Copied: trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java (from rev 488, trunk/src/dl-learner/org/dllearner/test/ComponentTests.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.test.junit; + +import java.util.List; + +import org.dllearner.core.Component; +import org.dllearner.core.ComponentManager; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * A suite of JUnit tests related to the DL-Learner component architecture. + * + * @author Jens Lehmann + * + */ +public class ComponentTests { + + /** + * Checks whether all components implement the getName() method. While it + * cannot be enforced to implement a static method, it should be done (e.g. + * to be used as label for the component in GUIs). + */ + @Test + public void nameTest() { + String defaultName = Component.getName(); + ComponentManager cm = ComponentManager.getInstance(); + List<Class<? extends Component>> components = cm.getComponents(); + for (Class<? extends Component> component : components) { + String componentName = cm.getComponentName(component); + assertFalse(component + " does not overwrite getName().", componentName + .equals(defaultName)); + } + } + +} Copied: trunk/src/dl-learner/org/dllearner/test/junit/package.html (from rev 488, trunk/src/dl-learner/org/dllearner/test/package.html) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/package.html 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>DL-Learner JUnit tests.</p> +</body> +</html> \ No newline at end of file Deleted: trunk/src/dl-learner/org/dllearner/test/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/test/package.html 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/test/package.html 2008-02-04 14:54:07 UTC (rev 489) @@ -1,7 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> -<html> -<head></head> -<body bgcolor="white"> -<p>DL-Learner JUnit tests.</p> -</body> -</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |