From: <lor...@us...> - 2011-06-14 20:10:37
|
Revision: 2875 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2875&view=rev Author: lorenz_b Date: 2011-06-14 20:10:31 +0000 (Tue, 14 Jun 2011) Log Message: ----------- Updated methods to select appropriate cache/index for new SLOT types. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-06-14 19:26:51 UTC (rev 2874) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-06-14 20:10:31 UTC (rev 2875) @@ -529,11 +529,12 @@ private SolrSearch getIndexBySlotType(Slot slot){ SolrSearch index = null; - if(slot.getSlotType() == SlotType.CLASS){ + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ index = class_index; - } else if(slot.getSlotType() == SlotType.PROPERTY){ + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ index = property_index; - } else if(slot.getSlotType() == SlotType.RESOURCE){ + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ index = resource_index; } return index; @@ -541,11 +542,12 @@ private Map<String, List<String>> getCacheBySlotType(Slot slot){ Map<String, List<String>> cache = null; - if(slot.getSlotType() == SlotType.CLASS){ + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ cache = classesURICache; - } else if(slot.getSlotType() == SlotType.PROPERTY){ + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ cache = propertiesURICache; - } else if(slot.getSlotType() == SlotType.RESOURCE){ + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ cache = resourcesURICache; } return cache; @@ -641,7 +643,6 @@ } private List<String> getResultFromRemoteEndpoint(String query){ - System.out.println(query); List<String> resources = new ArrayList<String>(); try { ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query + " LIMIT 10")); @@ -680,7 +681,7 @@ // Logger.getLogger(DefaultHttpParams.class).setLevel(Level.OFF); // Logger.getLogger(HttpClient.class).setLevel(Level.OFF); // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); - String question = "Who are the presidents of the United States?"; + String question = "Give me all actors starring in Batman Begins."; // String question = "Give me all films starring Brad Pitt"; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner(); SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://live.dbpedia.org/sparql"), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-04 10:53:05
|
Revision: 2988 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2988&view=rev Author: lorenz_b Date: 2011-08-04 10:52:59 +0000 (Thu, 04 Aug 2011) Log Message: ----------- Added needed method init() caused by refactoring of core module. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-08-04 10:04:56 UTC (rev 2987) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-08-04 10:52:59 UTC (rev 2988) @@ -35,6 +35,7 @@ import org.dllearner.algorithm.tbsl.templator.Templator; import org.dllearner.algorithm.tbsl.util.Prefixes; import org.dllearner.algorithm.tbsl.util.Similarity; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.Oracle; import org.dllearner.core.SparqlQueryLearningAlgorithm; import org.dllearner.kb.sparql.ExtractionDBCache; @@ -768,6 +769,12 @@ } } + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-01 13:48:42
|
Revision: 3349 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3349&view=rev Author: lorenz_b Date: 2011-11-01 13:48:33 +0000 (Tue, 01 Nov 2011) Log Message: ----------- fixed problem. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-01 13:31:55 UTC (rev 3348) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-01 13:48:33 UTC (rev 3349) @@ -407,6 +407,11 @@ q.setScore(q.getScore()/t.getSlots().size()); } allQueries.addAll(queries); + List<Query> qList = new ArrayList<Query>(); + for(WeightedQuery wQ : queries){ + qList.add(wQ.getQuery()); + } + template2Queries.put(t, qList); } return allQueries; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-01 14:08:19
|
Revision: 3350 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3350&view=rev Author: lorenz_b Date: 2011-11-01 14:08:09 +0000 (Tue, 01 Nov 2011) Log Message: ----------- Added limit for max tested queries. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-01 13:48:33 UTC (rev 3349) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-01 14:08:09 UTC (rev 3350) @@ -79,6 +79,8 @@ private int maxTestedQueriesPerTemplate = 50; private int maxQueryExecutionTimeInSeconds; + private int maxTestedQueries = 200; + private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); private ExtractionDBCache cache = new ExtractionDBCache("cache"); @@ -248,8 +250,12 @@ //get the weighted query candidates Set<WeightedQuery> weightedQueries = getWeightedSPARQLQueries(templates); sparqlQueryCandidates = new ArrayList<Query>(); + int i = 0; for(WeightedQuery wQ : weightedQueries){ sparqlQueryCandidates.add(wQ.getQuery()); + if(i == maxTestedQueries){ + break; + } } //test candidates This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-01 14:55:51
|
Revision: 3351 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3351&view=rev Author: lorenz_b Date: 2011-11-01 14:55:44 +0000 (Tue, 01 Nov 2011) Log Message: ----------- Fixed problem. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-01 14:08:09 UTC (rev 3350) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-01 14:55:44 UTC (rev 3351) @@ -256,6 +256,7 @@ if(i == maxTestedQueries){ break; } + i++; } //test candidates @@ -386,28 +387,31 @@ Set<WeightedQuery> tmp = new HashSet<WeightedQuery>(); for(Slot slot : t.getSlots()){ - for(Allocation a : slot2Allocations.get(slot)){ - for(WeightedQuery query : queries){ - if(slot.getSlotType() == SlotType.SYMPROPERTY){ - Query reversedQuery = new Query(query.getQuery()); - reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); - reversedQuery.replaceVarWithURI(slot.getAnchor(), a.getUri()); - WeightedQuery w = new WeightedQuery(reversedQuery); + if(!slot2Allocations.get(slot).isEmpty()){ + for(Allocation a : slot2Allocations.get(slot)){ + for(WeightedQuery query : queries){ + if(slot.getSlotType() == SlotType.SYMPROPERTY){ + Query reversedQuery = new Query(query.getQuery()); + reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + reversedQuery.replaceVarWithURI(slot.getAnchor(), a.getUri()); + WeightedQuery w = new WeightedQuery(reversedQuery); + double newScore = query.getScore() + a.getScore(); + w.setScore(newScore); + tmp.add(w); + } + Query q = new Query(query.getQuery()); + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + WeightedQuery w = new WeightedQuery(q); double newScore = query.getScore() + a.getScore(); w.setScore(newScore); tmp.add(w); } - Query q = new Query(query.getQuery()); - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - WeightedQuery w = new WeightedQuery(q); - double newScore = query.getScore() + a.getScore(); - w.setScore(newScore); - tmp.add(w); } + queries.clear(); + queries.addAll(tmp); + tmp.clear(); } - queries.clear(); - queries.addAll(tmp); - tmp.clear(); + } for(WeightedQuery q : queries){ q.setScore(q.getScore()/t.getSlots().size()); @@ -465,6 +469,7 @@ return cnt; } + private Map<Template, Collection<? extends Query>> getSPARQLQueryCandidates(Set<Template> templates){ logger.info("Generating candidate SPARQL queries..."); mon.start(); @@ -926,10 +931,11 @@ // Logger.getLogger(DefaultHttpParams.class).setLevel(Level.OFF); // Logger.getLogger(HttpClient.class).setLevel(Level.OFF); // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); - String question = "Give me all films produced by Hal Roach?"; +// String question = "In which programming language is GIMP written?"; + String question = "Who/WP are/VBP the/DT presidents/NNS of/IN the/DT United/NNP States/NNPS"; // String question = "Give me all books written by authors influenced by Ernest Hemingway."; - SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner(); + SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), // Collections.<String>singletonList(""), Collections.<String>emptyList()); SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), @@ -939,7 +945,7 @@ learner.learnSPARQLQueries(); System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); - + } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-04 15:03:18
|
Revision: 3373 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3373&view=rev Author: lorenz_b Date: 2011-11-04 15:03:03 +0000 (Fri, 04 Nov 2011) Log Message: ----------- Some small changes. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-04 12:51:33 UTC (rev 3372) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-04 15:03:03 UTC (rev 3373) @@ -627,7 +627,7 @@ Set<Allocation> allocations; for(Template t : templates){ - allocations = new HashSet<Allocation>(); + allocations = new TreeSet<Allocation>(); for(Slot slot : t.getSlots()){ allocations = computeAllocations(slot); @@ -639,6 +639,7 @@ slot2Allocations.put(slot, allocations); //for tests add the property URI with http://dbpedia.org/property/ namespace + //TODO should be replaced by usage of a separate SOLR index Set<Allocation> tmp = new HashSet<Allocation>(); if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ for(Allocation a : allocations){ @@ -690,9 +691,7 @@ for(Allocation a : slot2Allocations.get(slot)){ for(WeightedQuery query : queries){ Query q = new Query(query.getQuery()); - if(a.getUri().equals("http://dbpedia.org/ontology/developer") && q.toString().contains("/Organisation>") && q.toString().contains("/Software>")){ - System.out.println("YES:\n" + query); - } + boolean drop = false; if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ @@ -713,17 +712,21 @@ allRanges.remove("http://www.w3.org/2002/07/owl#Thing"); String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); Set<String> allTypes = getSuperClasses(typeURI); - allTypes.add(typeTriple.getValue().getName()); - if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")){ - System.out.println("RANGES: " + allRanges); - System.out.println("TYPES: " + allTypes); - } + allTypes.add(typeURI); +// if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")){ +// System.out.println("RANGES: " + allRanges); +// System.out.println("TYPES: " + allTypes); +// } if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ drop = true; +// if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer") && q.toString().contains("/Software>")){ +// System.out.println("RANGES: " + allRanges); +// System.out.println("TYPES: " + allTypes); +// System.out.println("DROPPING: \n" + q.toString()); +// } } else { - if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")) - System.out.println("DROPPING: \n" + q.toString()); + } } } else { @@ -745,16 +748,16 @@ String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); Set<String> allTypes = getSuperClasses(typeURI); allTypes.add(typeTriple.getValue().getName()); - if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")){ - System.out.println("DOMAINS: " + allDomains); - System.out.println("TYPES: " + allTypes); - } +// if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")){ +// System.out.println("DOMAINS: " + allDomains); +// System.out.println("TYPES: " + allTypes); +// } if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ drop = true; +// System.out.println("DROPPING: \n" + q.toString()); } else { - if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")) - System.out.println("DROPPING: \n" + q.toString()); + } } } @@ -816,13 +819,13 @@ */ private Set<Allocation> computeAllocations(Slot slot){ - Set<Allocation> allocations = new HashSet<Allocation>(); + Set<Allocation> allocations = new TreeSet<Allocation>(); SolrSearch index = getIndexBySlotType(slot); SolrQueryResultSet rs; for(String word : slot.getWords()){ - rs = index.getResourcesWithScores(word, 10); + rs = index.getResourcesWithScores(word, 30); //debugging // for(Iterator<SolrQueryResultItem> iter = rs.getItems().iterator();iter.hasNext();){ @@ -832,7 +835,7 @@ // } // } -// System.out.println(word + "->" + rs); + System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); double similarity = Similarity.getSimilarity(word, item.getLabel()); @@ -1397,7 +1400,8 @@ // String question = "Who/WP was/VBD the/DT wife/NN of/IN president/NN Lincoln/NNP"; // String question = "Who/WP produced/VBD the/DT most/JJS films/NNS"; // String question = "Which/WDT country/NN does/VBZ the/DT Airedale/NNP Terrier/NNP come/VBP from/IN"; - String question = "Which/WDT software/NN has/VBZ been/VBN developed/VBN by/IN organizations/NNS founded/VBN in/IN California/NNP"; + String question = "When/WRB was/VBD Capcom/NNP founded/VBD"; +// String question = "Which/WDT software/NN has/VBZ been/VBN developed/VBN by/IN organizations/NNS founded/VBN in/IN California/NNP"; // String question = "How/WRB many/JJ films/NNS did/VBD Leonardo/NNP DiCaprio/NNP star/VB in/IN"; // String question = "Which/WDT music/NN albums/NNS contain/VBP the/DT song/NN Last/NNP Christmas/NNP"; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-07 17:24:02
|
Revision: 3386 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3386&view=rev Author: lorenz_b Date: 2011-11-07 17:23:56 +0000 (Mon, 07 Nov 2011) Log Message: ----------- Small fix. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-07 16:07:31 UTC (rev 3385) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-07 17:23:56 UTC (rev 3386) @@ -1402,7 +1402,10 @@ } public int getLearnedPosition() { - return learnedPos+1; + if(learnedPos >= 0){ + return learnedPos+1; + } + return learnedPos; } private List<String> getResultFromLocalModel(String query, Model model){ @@ -1493,10 +1496,10 @@ // String question = "Which/WDT organizations/NNS were/VBD founded/VBN in/IN 1950/CD"; // String question = "Is/VBZ there/RB a/DT video/NN game/NN called/VBN Battle/NNP Chess/NNP"; // String question = "Which/WDT software/NN has/VBZ been/VBN developed/VBN by/IN organizations/NNS founded/VBN in/IN California/NNP"; - String question = "How/WRB many/JJ films/NNS did/VBD Leonardo/NNP DiCaprio/NNP star/VB in/IN"; +// String question = "How/WRB many/JJ films/NNS did/VBD Leonardo/NNP DiCaprio/NNP star/VB in/IN"; // String question = "Which/WDT music/NN albums/NNS contain/VBP the/DT song/NN Last/NNP Christmas/NNP"; // String question = "Which/WDT companies/NNS are/VBP located/VBN in/IN California/NNP USA/NNP"; -// String question = "Who/WP wrote/VBD the/DT book/NN The/NNP pillars/NNP of/NNP the/NNP Earth/NNP"; + String question = "Who/WP wrote/VBD the/DT book/NN The/NNP pillars/NNP of/NNP the/NNP Earth/NNP"; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), // Collections.<String>singletonList(""), Collections.<String>emptyList()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-08 13:59:20
|
Revision: 3389 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3389&view=rev Author: lorenz_b Date: 2011-11-08 13:59:11 +0000 (Tue, 08 Nov 2011) Log Message: ----------- Added cacheDir parameter to constructor. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-08 12:47:55 UTC (rev 3388) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-08 13:59:11 UTC (rev 3389) @@ -24,6 +24,7 @@ import org.dllearner.algorithm.tbsl.nlp.Lemmatizer; import org.dllearner.algorithm.tbsl.nlp.LingPipeLemmatizer; import org.dllearner.algorithm.tbsl.nlp.PartOfSpeechTagger; +import org.dllearner.algorithm.tbsl.nlp.StanfordPartOfSpeechTagger; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.search.HierarchicalSolrSearch; import org.dllearner.algorithm.tbsl.search.SolrQueryResultItem; @@ -137,34 +138,18 @@ } public SPARQLTemplateBasedLearner(Options options){ - init(options); - - Set<String> predicateFilters = new HashSet<String>(); - predicateFilters.add("http://dbpedia.org/ontology/wikiPageWikiLink"); - predicateFilters.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - prefixMap = Prefixes.getPrefixes(); - - modelGenenerator = new ModelGenerator(endpoint, predicateFilters); - - templateGenerator = new Templator(); + this(options, new StanfordPartOfSpeechTagger()); } public SPARQLTemplateBasedLearner(Options options, PartOfSpeechTagger tagger){ - init(options); - - Set<String> predicateFilters = new HashSet<String>(); - predicateFilters.add("http://dbpedia.org/ontology/wikiPageWikiLink"); - predicateFilters.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - prefixMap = Prefixes.getPrefixes(); - - modelGenenerator = new ModelGenerator(endpoint, predicateFilters); - - templateGenerator = new Templator(tagger); + this(options, tagger, new WordNet()); } public SPARQLTemplateBasedLearner(Options options, PartOfSpeechTagger tagger, WordNet wordNet){ + this(options, tagger, wordNet, "cache"); + } + + public SPARQLTemplateBasedLearner(Options options, PartOfSpeechTagger tagger, WordNet wordNet, String cacheDir){ init(options); Set<String> predicateFilters = new HashSet<String>(); @@ -176,6 +161,7 @@ modelGenenerator = new ModelGenerator(endpoint, predicateFilters); templateGenerator = new Templator(tagger, wordNet); + cache = new ExtractionDBCache(cacheDir); } /* @@ -1519,8 +1505,8 @@ // String question = "Which/WDT music/NN albums/NNS contain/VBP the/DT song/NN Last/NNP Christmas/NNP"; // String question = "Which/WDT companies/NNS are/VBP located/VBN in/IN California/NNP USA/NNP"; // String question = "Who/WP wrote/VBD the/DT book/NN The/NNP pillars/NNP of/NNP the/NNP Earth/NNP"; - String question = "Who/WP is/VBZ called/VBN Dana/NNP"; - SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); + String question = "Give me all books written by Dan Brown"; + SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();//learner.setUseIdealTagger(true); // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), // Collections.<String>singletonList(""), Collections.<String>emptyList()); SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-14 15:44:32
|
Revision: 3581 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3581&view=rev Author: lorenz_b Date: 2012-02-14 15:44:21 +0000 (Tue, 14 Feb 2012) Log Message: ----------- Somes updates needed because of new SOLR BOA index. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2012-02-14 10:14:06 UTC (rev 3580) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2012-02-14 15:44:21 UTC (rev 3581) @@ -16,6 +16,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import org.apache.log4j.Logger; @@ -193,7 +194,7 @@ String boaPatternIndexUrl = options.fetch("solr.boa.properties.url"); String boaPatternIndexSearchField = options.fetch("solr.boa.properties.searchfield"); - SolrSearch patternBasedPropertyIndex = new SolrSearch(boaPatternIndexUrl, boaPatternIndexSearchField, "nlr"); + SolrSearch patternBasedPropertyIndex = new SolrSearch(boaPatternIndexUrl, boaPatternIndexSearchField, "nlr-no-var"); //first BOA pattern then label based // property_index = new HierarchicalSolrSearch(patternBasedPropertyIndex, labelBasedPropertyIndex); @@ -641,18 +642,37 @@ } private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + logger.info("Generating SPARQL query candidates..."); + Map<Slot, Set<Allocation>> slot2Allocations2 = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { + + @Override + public int compare(Slot o1, Slot o2) { + if(o1.getSlotType() == o2.getSlotType()){ + return o1.getToken().compareTo(o2.getToken()); + } else { + return -1; + } + } + }); + + Map<Slot, Set<Allocation>> slot2Allocations = new HashMap<Slot, Set<Allocation>>(); Set<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); Set<Allocation> allocations; + for(Template t : templates){ + logger.info("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); for(Slot slot : t.getSlots()){ - allocations = computeAllocations(slot, 50); - + allocations = slot2Allocations2.get(slot); + if(allocations == null){ + allocations = computeAllocations(slot, 20); + slot2Allocations2.put(slot, allocations); + } slot2Allocations.put(slot, allocations); //for tests add the property URI with http://dbpedia.org/property/ namespace @@ -702,14 +722,14 @@ queries.addAll(tmp); tmp.clear(); } - + for(Slot slot : sortedSlots){ - if(!slot2Allocations.get(slot).isEmpty()){System.out.println(slot2Allocations.get(slot)); + if(!slot2Allocations.get(slot).isEmpty()){ for(Allocation a : slot2Allocations.get(slot)){ for(WeightedQuery query : queries){ Query q = new Query(query.getQuery()); - boolean drop = false; + boolean drop = false;/* if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ String objectVar = triple.getValue().getName(); @@ -779,7 +799,7 @@ } } } - } + }*/ if(!drop){ @@ -811,6 +831,7 @@ } template2Queries.put(t, qList); } + logger.info("...done in "); return allQueries; } @@ -859,7 +880,6 @@ // } // } - System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ double similarity = Similarity.getSimilarity(word, item.getLabel()); //get the labels of the redirects and compute the highest similarity @@ -885,9 +905,11 @@ } private Set<Allocation> computeAllocations(Slot slot, int limit){ + logger.info("Computing allocations for " + slot); SortedSet<Allocation> allocations = computeAllocations(slot); if(allocations.isEmpty()){ + logger.info("...done."); return allocations; } @@ -906,7 +928,7 @@ } } }); - + logger.info("...done."); return new TreeSet<Allocation>(l.subList(0, Math.min(limit, allocations.size()))); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |