From: <lor...@us...> - 2012-06-14 14:55:06
|
Revision: 3740 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3740&view=rev Author: lorenz_b Date: 2012-06-14 14:54:54 +0000 (Thu, 14 Jun 2012) Log Message: ----------- Tried some to answer some more questions. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Pair.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex trunk/components-ext/src/main/resources/tbsl/oxford_objectproperty_mappings.txt trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/OxfordEvaluation.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoClassesIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoDatatypePropertiesIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoObjectPropertiesIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoResourcesIndex.java trunk/components-ext/src/main/resources/tbsl/evaluation.txt Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -34,9 +34,11 @@ import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Value; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -51,6 +53,9 @@ import org.dllearner.common.index.SPARQLDatatypePropertiesIndex; import org.dllearner.common.index.SPARQLObjectPropertiesIndex; import org.dllearner.common.index.SPARQLPropertiesIndex; +import org.dllearner.common.index.VirtuosoDatatypePropertiesIndex; +import org.dllearner.common.index.VirtuosoObjectPropertiesIndex; +import org.dllearner.common.index.VirtuosoPropertiesIndex; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; @@ -150,8 +155,13 @@ setOptions(options); if(propertiesIndex instanceof SPARQLPropertiesIndex){ - datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); - objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } } else { datatypePropertiesIndex = propertiesIndex; objectPropertiesIndex = propertiesIndex; @@ -186,8 +196,13 @@ setOptions(options); if(propertiesIndex instanceof SPARQLPropertiesIndex){ - datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); - objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } } else { datatypePropertiesIndex = propertiesIndex; objectPropertiesIndex = propertiesIndex; @@ -419,7 +434,9 @@ } } + executor.shutdown(); + /*for(Slot slot : t.getSlots()){ allocations = slot2Allocations2.get(slot); if(allocations == null){ @@ -559,9 +576,30 @@ } }*/ - if(!drop){ - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } WeightedQuery w = new WeightedQuery(q); double newScore = query.getScore() + a.getScore(); w.setScore(newScore); @@ -581,14 +619,50 @@ for(WeightedQuery query : queries){ Query q = query.getQuery(); for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - String objectVar = triple.getValue().getName(); - q.addFilter(new SPARQL_Filter(new SPARQL_Pair( - new SPARQL_Term(objectVar), "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); - + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + String objectVar = triple.getValue().getName(); + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + new SPARQL_Term(objectVar), "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } + } + } } } + } else if(slot.getSlotType() == SlotType.CLASS){ + String token = slot.getWords().get(0); + if(slot.getToken().contains("house")){ + String regexToken = token.replace("houses", "").replace("house", "").trim(); + try { + Map<Slot, SortedSet<Allocation>> ret = new SlotProcessor(new Slot(null, SlotType.CLASS, Collections.singletonList("house"))).call(); + SortedSet<Allocation> alloc = ret.entrySet().iterator().next().getValue(); + if(alloc != null && !alloc.isEmpty()){ + String uri = alloc.first().getUri(); + for(WeightedQuery query : queries){ + Query q = query.getQuery(); + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Term subject = triple.getVariable(); + SPARQL_Term object = new SPARQL_Term("desc"); + object.setIsVariable(true); + object.setIsURI(false); + q.addCondition(new SPARQL_Triple(subject, new SPARQL_Property("<http://purl.org/goodrelations/v1#description>"), object)); + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + regexToken + "'", SPARQL_PairType.REGEX))); + } + q.replaceVarWithURI(slot.getAnchor(), uri); + + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } } @@ -733,7 +807,10 @@ if(queryType == SPARQL_QueryType.SELECT){ for(String query : queries){ logger.info("Testing query:\n" + query); - ResultSet rs = executeSelect(query); + com.hp.hpl.jena.query.Query q = QueryFactory.create(query, Syntax.syntaxARQ); + q.setLimit(1); + ResultSet rs = executeSelect(q.toString());//executeSelect(query); + List<String> results = new ArrayList<String>(); QuerySolution qs; String projectionVar; @@ -927,9 +1004,16 @@ } - private boolean isDatatypePropeprty(String uri){ - String query = "ASK {<%s> a <http://www.w3.org/2002/07/owl#DatatypeProperty>}."; - return executeAskQuery(query); + private boolean isDatatypeProperty(String uri){ + Boolean isDatatypeProperty = null; + if(mappingIndex != null){ + isDatatypeProperty = mappingIndex.isDataProperty(uri); + } + if(isDatatypeProperty == null){ + String query = String.format("ASK {<%s> a <http://www.w3.org/2002/07/owl#DatatypeProperty> .}", uri); + isDatatypeProperty = executeAskQuery(query); + } + return isDatatypeProperty; } /** Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -378,6 +378,8 @@ object.setIsVariable(false); if(object instanceof SPARQL_Term){ ((SPARQL_Term) object).setIsURI(true); + } else if(object instanceof SPARQL_Property){ + ((SPARQL_Property) object).setIsVariable(false); } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Pair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Pair.java 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Pair.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -6,12 +6,12 @@ { private static final long serialVersionUID = -1255754209857823420L; - public SPARQL_Term a; + public SPARQL_Value a; public Object b; public SPARQL_PairType type; - public SPARQL_Pair(SPARQL_Term a, Object b, SPARQL_PairType type) + public SPARQL_Pair(SPARQL_Value a, Object b, SPARQL_PairType type) { super(); this.a = a; @@ -19,7 +19,7 @@ this.type = type; } - public SPARQL_Pair(SPARQL_Term a, SPARQL_PairType type) + public SPARQL_Pair(SPARQL_Value a, SPARQL_PairType type) { super(); this.a = a; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -103,7 +103,7 @@ if (isString()) { return name.replaceAll("_"," "); } - else if (isURI) { + else if (isURI || !isVariable()) { return name; } else return "?"+name.toLowerCase(); Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -127,7 +127,7 @@ return irs; } - private ResultSet executeSelect(String query){//System.out.println(query); + private ResultSet executeSelect(String query){System.out.println(query); ResultSet rs; if(model == null){ if(cache == null){ Added: trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoClassesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoClassesIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoClassesIndex.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1,38 @@ +package org.dllearner.common.index; + +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; + +import com.hp.hpl.jena.rdf.model.Model; + +public class VirtuosoClassesIndex extends SPARQLIndex{ + + public VirtuosoClassesIndex(SparqlEndpoint endpoint) { + super(endpoint); + init(); + } + + public VirtuosoClassesIndex(SparqlEndpoint endpoint, ExtractionDBCache cache) { + super(endpoint, cache); + init(); + } + + public VirtuosoClassesIndex(Model model) { + super(model); + init(); + } + + private void init(){ + super.queryTemplate = "SELECT DISTINCT ?uri WHERE {\n" + + "?s a ?uri.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + + super.queryWithLabelTemplate = "SELECT DISTINCT * WHERE {\n" + + "?s a ?uri.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + } +} Added: trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoDatatypePropertiesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoDatatypePropertiesIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoDatatypePropertiesIndex.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1,41 @@ +package org.dllearner.common.index; + +import org.dllearner.kb.sparql.SparqlEndpoint; + +import com.hp.hpl.jena.rdf.model.Model; + +public class VirtuosoDatatypePropertiesIndex extends SPARQLPropertiesIndex{ + + public VirtuosoDatatypePropertiesIndex(SparqlEndpoint endpoint) { + super(endpoint); + init(); + } + + public VirtuosoDatatypePropertiesIndex(Model model) { + super(model); + init(); + } + + public VirtuosoDatatypePropertiesIndex(SPARQLIndex index) { + super(index); + init(); + } + + private void init(){ + super.queryTemplate = "SELECT ?uri WHERE {\n" + + "?s ?uri ?o.\n" + + "?uri a owl:DatatypeProperty.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + + super.queryWithLabelTemplate = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT * WHERE {\n" + + "?s ?uri ?o.\n" + + "?uri a owl:DatatypeProperty.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + } + + +} Added: trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoObjectPropertiesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoObjectPropertiesIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoObjectPropertiesIndex.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1,42 @@ +package org.dllearner.common.index; + +import org.dllearner.kb.sparql.SparqlEndpoint; + +import com.hp.hpl.jena.rdf.model.Model; + +public class VirtuosoObjectPropertiesIndex extends SPARQLPropertiesIndex{ + + public VirtuosoObjectPropertiesIndex(SparqlEndpoint endpoint) { + super(endpoint); + init(); + } + + public VirtuosoObjectPropertiesIndex(Model model) { + super(model); + init(); + } + + public VirtuosoObjectPropertiesIndex(SPARQLIndex index) { + super(index); + init(); + } + + private void init(){ + super.queryTemplate = "SELECT ?uri WHERE {\n" + + "?s ?uri ?o.\n" + + "?uri a owl:ObjectProperty.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label." + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + + super.queryWithLabelTemplate = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT * WHERE {\n" + + "?s ?uri ?o.\n" + + "?uri a owl:ObjectProperty.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + } + + + +} Added: trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1,46 @@ +package org.dllearner.common.index; + +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; + +import com.hp.hpl.jena.rdf.model.Model; + +public class VirtuosoPropertiesIndex extends SPARQLIndex{ + + public VirtuosoPropertiesIndex(SparqlEndpoint endpoint) { + super(endpoint); + init(); + } + + public VirtuosoPropertiesIndex(SparqlEndpoint endpoint, ExtractionDBCache cache) { + super(endpoint, cache); + init(); + } + + public VirtuosoPropertiesIndex(Model model) { + super(model); + init(); + } + + public VirtuosoPropertiesIndex(SPARQLIndex index) { + super(index); + init(); + } + + private void init(){ + super.queryTemplate = "SELECT DISTINCT ?uri WHERE {\n" + + "?s ?uri ?o.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + + super.queryWithLabelTemplate = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?uri ?label WHERE {\n" + + "?s ?uri ?o.\n" + +// "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.} " + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + } + + +} Added: trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoResourcesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoResourcesIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoResourcesIndex.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1,43 @@ +package org.dllearner.common.index; + +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; + +import com.hp.hpl.jena.rdf.model.Model; + +public class VirtuosoResourcesIndex extends SPARQLIndex{ + + public VirtuosoResourcesIndex(SparqlEndpoint endpoint) { + this(endpoint, null); + } + + public VirtuosoResourcesIndex(Model model) { + super(model); + init(); + } + + public VirtuosoResourcesIndex(VirtuosoResourcesIndex index) { + super(index); + } + + public VirtuosoResourcesIndex(SparqlEndpoint endpoint, ExtractionDBCache cache) { + super(endpoint, cache); + init(); + } + + private void init(){ + super.queryTemplate = "SELECT DISTINCT ?uri WHERE {\n" + + "?uri a ?type.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + + super.queryWithLabelTemplate = "SELECT DISTINCT * WHERE {\n" + + "?uri a ?type.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label.\n" + + "?label bif:contains '\"%s\"'}\n" + + "LIMIT %d OFFSET %d"; + } + + +} Added: trunk/components-ext/src/main/resources/tbsl/evaluation.txt =================================================================== --- trunk/components-ext/src/main/resources/tbsl/evaluation.txt (rev 0) +++ trunk/components-ext/src/main/resources/tbsl/evaluation.txt 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1,149 @@ +question: houses in Headington + +question: houses in Abingdon with more than 2 bedrooms + +question: houses with garden in Wheatley + +question: detached houses in Oxford + +question: Victorian houses in Oxfordshire + +question: Edwardian house in Oxfordshire for less than 1000000 + +question: houses with double garage + +question: houses with large garden and equipped kitchen + +question: houses with more than 1 reception room + +question: houses in Didcot furnished to a high standard + +question: houses with conservatory room and less than 900000 pounds + +question: detached bungalows in Oxfordshire + +question: houses in Old Marston + +question: family houses with more than 2 bathrooms and more than 4 bedrooms + +question: houses close to Iffley Sport Centre + +question: houses in Oxford close to the train station + +question: houses in Summertown for less than 400000 pounds + +question: two floors houses in East Oxford + +question: brand new houses in Oxford for less than 500000 pounds + +question: houses close to Brookes University + +question: houses in Jericho area + +question: house close to Headington hospitals + +question: modern houses with gas central heating + +question: houses with electric heating + +question: houses less than 500000 within area OX16 + +question: houses close to an Italian restaurant + +question: houses at walking distance from a pharmacy + +question: houses at walking distance from Tesco or Sainsburys shops + +question: houses nearby Sheldonian Theatre + +question: houses with underfloor heating + +question: houses with wood floor + +question: houses close to The King's Arms pub + +question: houses with garden large at least 2 acres + +question: houses with many reception rooms + +question: houses built around 1950 + +question: houses with balcony + +question: houses with double glazed windows + +question: houses far from city centre + +question: 2 bedroom houses near oxford train station + +question: 4 bedroom detached houses in oxford + +question: studio apartments in summertown, Oxford + +question: freehold houses with 2 bedrooms and a living room in banbury + +question: houses in Oxford city centre with at most 2 bedrooms + +question: houses with garage within minutes of Oxford schools and in a quiet road + +question: victorian town houses in north Oxford + +question: terrace houses with west facing garden + +question: modernised end terrace houses with private parking + +question: three bedroom houses with open fireplace + +question: houses available from June 15th. + +question: houses on rawlinson road + +question: flats near supermarket + +question: flats with bill included + + + +question: give me flats in central Oxford with at least one bedroom below 1000 GBP a month? + +question: Give me all 2 bedroom flats in walking distance from the computer science departement! + +question: Give me all houses with 3 bedrooms or more, close to the train station with good shopping opportunities. + +question: find a property with 2 bedrooms close to some park. + +question: Give me all flats at roughly 1300 GBP the month, equally close to the computer science department and Christ Church College. + +question: Give me all flats in the area around Cowley Road with 2 bedrooms. + +question: Give me all furnished places with one bedroom close to the Radcliffe Camera. + +question: Give me all unfurnished houses with at least 2 bedrooms in Summertown. + +question: Give me all furnished flats with one bedroom for smokers. + +question: Give me all flats with parking in central Oxford. + +question: Give me all cheap places in Cowley. + +question: Give me all representative houses in Summertown. + +question: find a property for sale, with 2 bedrooms, parking, close to shops. + +question: Give me all flats with a garden, one bedroom, in walking distance to the computer science departement + +question: Give me all places offered close to the train station? + +question: Give me all retirement houses for sale near Oxford. + +question: Give me all houses that I can BBQ. + +question: Give me all flats which are far from the river. + +question: Give me all flats which are close to three bars. + +question: What is the average price of furnished 1 bedroom apartments in Heddington? + +question: How many flats are offered in central Oxford below 1000 GBP a month? + +question: Which area in Oxford has the cheapest offers close to the Keble college [or some other landmark]? Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-06-14 14:54:54 UTC (rev 3740) @@ -2,7 +2,7 @@ // PREPOSITIONS close to || (NP NP* (PP P:'close' P:'to' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_closeto(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_closeto/OBJECTPROPERTY/near ]> - in || (NP NP* (PP P:'in' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_location(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_location/PROPERTY/location^city^postal_code^address ]> + in || (NP NP* (PP P:'in' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_location(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_location/PROPERTY/location^city^postal_code^address^street ]> since || (NP NP* (PP P:'since' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_since(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_since/PROPERTY/since ]> for . pounds || (NP NP* (PP P:'for' (NP NUM[num] N:'pounds'))) || <x,l1,<e,t>, [ l1:[ | SLOT_price(x,y) ] ], [ (l2,y,num,e) ], [ l2=l1 ],[ SLOT_price/DATATYPEPROPERTY/price ]> Modified: trunk/components-ext/src/main/resources/tbsl/oxford_objectproperty_mappings.txt =================================================================== --- trunk/components-ext/src/main/resources/tbsl/oxford_objectproperty_mappings.txt 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/main/resources/tbsl/oxford_objectproperty_mappings.txt 2012-06-14 14:54:54 UTC (rev 3740) @@ -0,0 +1 @@ +http://dbpedia.org/property/near|close, near \ No newline at end of file Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/OxfordEvaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/OxfordEvaluation.java 2012-06-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/OxfordEvaluation.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -1,20 +1,21 @@ package org.dllearner.algorithm.tbsl; import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; +import java.io.FileWriter; import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import org.dllearner.algorithm.tbsl.learning.SPARQLTemplateBasedLearner2; -import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; -import org.dllearner.common.index.SPARQLClassesIndex; import org.dllearner.common.index.SPARQLIndex; -import org.dllearner.common.index.SPARQLPropertiesIndex; +import org.dllearner.common.index.VirtuosoClassesIndex; +import org.dllearner.common.index.VirtuosoPropertiesIndex; +import org.dllearner.common.index.VirtuosoResourcesIndex; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -26,14 +27,15 @@ SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); ExtractionDBCache cache = new ExtractionDBCache("cache"); - SPARQLIndex resourcesIndex = new SPARQLIndex(endpoint, cache); - SPARQLIndex classesIndex = new SPARQLClassesIndex(endpoint, cache); - SPARQLIndex propertiesIndex = new SPARQLPropertiesIndex(endpoint, cache); + SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); + SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); + SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); MappingBasedIndex mappingIndex= new MappingBasedIndex( OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), - OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath(), - OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath()); + OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), + OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() + ); SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); learner.setMappingIndex(mappingIndex); @@ -42,11 +44,14 @@ int learnedQuestions = 0; Map<String, String> question2QueryMap = new HashMap<String, String>(); - BufferedReader br = new BufferedReader(new FileReader(new File(QUERIES_FILE))); + BufferedReader in = new BufferedReader(new FileReader(new File(QUERIES_FILE))); + BufferedWriter out = new BufferedWriter(new FileWriter(new File("log/oxford_eval.txt"))); int questionNr = 0; + int errorCnt = 0; + int noQueryCnt = 0; String question = null; - while((question = br.readLine()) != null){ + while((question = in.readLine()) != null){ question = question.replace("question:", "").trim(); if(question.isEmpty()) continue; if(!question.toLowerCase().contains("Give me all") && Character.isLowerCase(question.charAt(0))){ @@ -62,17 +67,27 @@ if(learnedQuery != null){ question2QueryMap.put(question, learnedQuery); learnedQuestions++; + out.write("****************************************\n" + question + "\n" + learnedQuery + "\n****************************************"); + } else { + noQueryCnt++; + out.write("****************************************\n" + question + "\nNO QUERY WITH NON-EMPTY RESULTSET FOUND\n****************************************"); } } catch (Exception e) { e.printStackTrace(); + errorCnt++; + out.write("****************************************\n" + question + "\nERROR: " + e.getClass() + "\n****************************************"); } + out.flush(); } - System.out.println("Generated SPARQL queries for " + learnedQuestions + " questions."); - for(Entry<String, String> entry : question2QueryMap.entrySet()){ - System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - System.out.println(entry.getKey()); - System.out.println(entry.getValue()); - } + out.write("################################\n"); + out.write("Questions with answer: " + learnedQuestions + "\n"); + out.write("Questions with no answer (and no error): " + noQueryCnt + "\n"); + out.write("Questions with error: " + errorCnt + "\n"); + + in.close(); + out.close(); + + } } 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-13 20:51:06 UTC (rev 3739) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-14 14:54:54 UTC (rev 3740) @@ -10,10 +10,15 @@ import org.dllearner.algorithm.tbsl.learning.SPARQLTemplateBasedLearner2; import org.dllearner.common.index.Index; +import org.dllearner.common.index.MappingBasedIndex; import org.dllearner.common.index.SOLRIndex; import org.dllearner.common.index.SPARQLClassesIndex; import org.dllearner.common.index.SPARQLIndex; import org.dllearner.common.index.SPARQLPropertiesIndex; +import org.dllearner.common.index.VirtuosoClassesIndex; +import org.dllearner.common.index.VirtuosoPropertiesIndex; +import org.dllearner.common.index.VirtuosoResourcesIndex; +import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.junit.Test; @@ -34,24 +39,24 @@ 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(); - File dir = new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/data"); - try { - for(File f : dir.listFiles()){ - if(f.isFile()){ - System.out.println("Loading file " + f.getName()); - try { - model.read(new FileInputStream(f), null, "TURTLE"); - } catch (Exception e) { - System.err.println("Parsing failed."); - e.printStackTrace(); - } - } - } - model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/ontology.ttl")), null, "TURTLE"); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } +// model = ModelFactory.createOntologyModel(); +// File dir = new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/data"); +// try { +// for(File f : dir.listFiles()){ +// if(f.isFile()){ +// System.out.println("Loading file " + f.getName()); +// try { +// model.read(new FileInputStream(f), null, "TURTLE"); +// } catch (Exception e) { +// System.err.println("Parsing failed."); +// e.printStackTrace(); +// } +// } +// } +// model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/ontology.ttl")), null, "TURTLE"); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } } @Test @@ -95,17 +100,24 @@ @Test public void testOxfordRemote() throws Exception{ + ExtractionDBCache cache = new ExtractionDBCache("cache"); + SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); + SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); + SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); + MappingBasedIndex mappingIndex= new MappingBasedIndex( + OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), + OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), + OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), + OxfordEvaluation.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() + ); - Index resourcesIndex = new SPARQLIndex(endpoint); - Index classesIndex = new SPARQLClassesIndex(endpoint); - Index propertiesIndex = new SPARQLPropertiesIndex(endpoint); - SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); + learner.setMappingIndex(mappingIndex); learner.init(); String question = "Give me all houses near a school."; question = "Give me all houses with more than 3 bathrooms and more than 2 bedrooms."; - question = "Give me all houses with large garden and equipped kitchen"; + question = "Give me all Victorian houses in Oxfordshire"; learner.setQuestion(question); learner.learnSPARQLQueries(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |