From: <lor...@us...> - 2012-06-11 12:19:40
|
Revision: 3729 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3729&view=rev Author: lorenz_b Date: 2012-06-11 12:19:30 +0000 (Mon, 11 Jun 2012) Log Message: ----------- Added method to test on remote endpoint. Modified Paths: -------------- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-09 10:46:58 UTC (rev 3728) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-11 12:19:30 UTC (rev 3729) @@ -20,6 +20,7 @@ import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -27,18 +28,31 @@ public class TBSLTest extends TestCase{ private Model model; + private SparqlEndpoint endpoint; @Override protected void setUp() throws Exception { super.setUp(); - + endpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); model = ModelFactory.createOntologyModel(); try { model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/ontology.ttl")), null, "TURTLE"); - model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/finders.ttl")), "http://diadem.cs.ox.ac.uk/ontologies/real-estate#", "TURTLE"); + model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/data/wwagency-letting-triple.ttl")), "http://diadem.cs.ox.ac.uk/ontologies/real-estate#", "TURTLE"); } catch (FileNotFoundException e) { e.printStackTrace(); } + System.out.println(model.size()); + String queryStr = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?uri WHERE {" + +// "?s ?uri ?o." + + "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.}" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label." + + "FILTER(REGEX(STR(?label), 'bathroom', 'i'))" + + "}" + + "LIMIT 20 OFFSET 0"; + System.out.println( + ResultSetFormatter.asText( + QueryExecutionFactory.create( + QueryFactory.create(queryStr, Syntax.syntaxARQ), model).execSelect())); } @Test @@ -62,7 +76,7 @@ } @Test - public void testOxford() throws Exception{ + public void testOxfordLocal() throws Exception{ Index resourcesIndex = new SPARQLIndex(model); Index classesIndex = new SPARQLClassesIndex(model); @@ -71,7 +85,7 @@ SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(model, resourcesIndex, classesIndex, propertiesIndex); learner.init(); - String question = "Give me all flats where pets are allowed"; + String question = "Give me all houses with more than 2 bedrooms."; learner.setQuestion(question); learner.learnSPARQLQueries(); @@ -81,10 +95,30 @@ } @Test + public void testOxfordRemote() throws Exception{ + + Index resourcesIndex = new SPARQLIndex(endpoint); + Index classesIndex = new SPARQLClassesIndex(endpoint); + Index propertiesIndex = new SPARQLPropertiesIndex(endpoint); + + SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); + learner.init(); + + String question = "Give me all houses with more than 2 bedrooms and more than 3 bathrooms."; + + learner.setQuestion(question); + learner.learnSPARQLQueries(); + System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); + System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); + System.out.println(learner.getLearnedPosition()); + } + + @Test public void testSPARQLIndex(){ Index classesIndex = new SPARQLClassesIndex(model); System.out.println(classesIndex.getResources("flat")); + } @Test This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |