From: <lor...@us...> - 2012-06-13 20:51:12
|
Revision: 3739 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3739&view=rev Author: lorenz_b Date: 2012-06-13 20:51:06 +0000 (Wed, 13 Jun 2012) Log Message: ----------- Added hack for REGEX filter when resource slot is empty and predicate is dataproperty - has to be tested. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 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 14:56:37 UTC (rev 3738) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-06-13 20:51:06 UTC (rev 3739) @@ -31,7 +31,12 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.Allocation; import org.dllearner.algorithm.tbsl.sparql.Query; +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_QueryType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -452,6 +457,11 @@ } } for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ + sortedSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ if(!sortedSlots.contains(slot)){ sortedSlots.add(slot); } @@ -566,6 +576,22 @@ queries.clear(); queries.addAll(tmp);//System.out.println(tmp); tmp.clear(); + } else {//Add REGEX FILTER if resource slot is empty and predicate is datatype property + if(slot.getSlotType() == SlotType.RESOURCE){ + 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))); + + } + + } + + } + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-06-14 18:36:57
|
Revision: 3744 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3744&view=rev Author: lorenz_b Date: 2012-06-14 18:36:51 +0000 (Thu, 14 Jun 2012) Log Message: ----------- Removed own description hack, because now templates are generated for this case. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 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-14 18:35:22 UTC (rev 3743) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-06-14 18:36:51 UTC (rev 3744) @@ -625,9 +625,8 @@ 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))); + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); } } } @@ -635,35 +634,36 @@ } - } 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(); - } - } - } + } +// 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(); +// } +// } +// } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-13 13:21:39
|
Revision: 3790 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3790&view=rev Author: lorenz_b Date: 2012-07-13 13:21:30 +0000 (Fri, 13 Jul 2012) Log Message: ----------- Lowering score for queries with REGEX. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 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-07-13 13:20:45 UTC (rev 3789) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-13 13:21:30 UTC (rev 3790) @@ -496,6 +496,7 @@ for(Template t : templates){ logger.info("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); + boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); @@ -701,6 +702,13 @@ } } + //lower queries with FILTER-REGEX + if(containsRegex){ + for(WeightedQuery wQ : tmp){ + wQ.setScore(wQ.getScore() - 0.01); + } + } + queries.clear(); queries.addAll(tmp);//System.out.println(tmp); tmp.clear(); @@ -1134,6 +1142,23 @@ return new TreeSet<Allocation>(allocations); } + private Index getIndexBySlotType(Slot slot){ + Index index = null; + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + index = classesIndex; + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + index = propertiesIndex; + } else if(type == SlotType.DATATYPEPROPERTY){ + index = datatypePropertiesIndex; + } else if(type == SlotType.OBJECTPROPERTY){ + index = objectPropertiesIndex; + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + index = resourcesIndex; + } + return index; + } + } public String getTaggedInput(){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-08-22 13:40:22
|
Revision: 3827 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3827&view=rev Author: lorenz_b Date: 2012-08-22 13:40:11 +0000 (Wed, 22 Aug 2012) Log Message: ----------- Added missing init method in UNIT test. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 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-08-22 13:15:47 UTC (rev 3826) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-08-22 13:40:11 UTC (rev 3827) @@ -47,7 +47,6 @@ import org.dllearner.algorithm.tbsl.util.PopularityMap; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; import org.dllearner.algorithm.tbsl.util.Similarity; -import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper; import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; import org.dllearner.common.index.Index; import org.dllearner.common.index.IndexResultItem; @@ -68,6 +67,7 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.Thing; +import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -76,14 +76,19 @@ import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; +import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -import com.hp.hpl.jena.vocabulary.RDFS; +import com.hp.hpl.jena.sparql.expr.ExprAggregator; +import com.hp.hpl.jena.sparql.expr.ExprVar; +import com.hp.hpl.jena.sparql.expr.aggregate.AggCount; +import com.hp.hpl.jena.sparql.expr.aggregate.Aggregator; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -272,6 +277,7 @@ datatypePropertiesIndex = propertiesIndex; objectPropertiesIndex = propertiesIndex; } + reasoner = new SPARQLReasoner(new LocalModelBasedSparqlEndpointKS(ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM, model)), cache); } public void setGrammarFiles(String[] grammarFiles){ @@ -529,7 +535,8 @@ Set<Allocation> allocations; for(Template t : templates){ - logger.debug("Processing template:\n" + t.toString()); + logger.info("Processing template:\n" + t.toString()); + System.err.println(QueryFactory.create(t.getQuery().toString(), Syntax.syntaxSPARQL_11)); allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); @@ -859,19 +866,6 @@ logger.debug("...done in "); return allQueries; } - - private Set<String> getRedirectLabels(String uri){ - Set<String> labels = new HashSet<String>(); - String query = String.format("SELECT ?label WHERE {?s <http://dbpedia.org/ontology/wikiPageRedirects> <%s>. ?s <%s> ?label.}", uri, RDFS.label.getURI()); - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - QuerySolution qs; - while(rs.hasNext()){ - qs = rs.next(); - labels.add(qs.getLiteral("label").getLexicalForm()); - - } - return labels; - } private double getProminenceValue(String uri, SlotType type){ Integer popularity = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |