You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <lor...@us...> - 2011-11-06 21:28:54
|
Revision: 3382 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3382&view=rev Author: lorenz_b Date: 2011-11-06 21:28:47 +0000 (Sun, 06 Nov 2011) Log Message: ----------- Added new method to use redirects. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.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-06 20:15:33 UTC (rev 3381) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-06 21:28:47 UTC (rev 3382) @@ -8,9 +8,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -18,7 +18,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.algorithm.qtl.util.ModelGenerator; import org.dllearner.algorithm.qtl.util.ModelGenerator.Strategy; @@ -287,7 +286,8 @@ generatedQueries = getWeightedSPARQLQueries(templates); sparqlQueryCandidates = new ArrayList<Query>(); int i = 0; - for(WeightedQuery wQ : generatedQueries){System.out.println(wQ); + for(WeightedQuery wQ : generatedQueries){ + System.out.println(wQ.explain()); sparqlQueryCandidates.add(wQ.getQuery()); if(i == maxTestedQueries){ break; @@ -648,12 +648,8 @@ allocations = new TreeSet<Allocation>(); for(Slot slot : t.getSlots()){ - allocations = computeAllocations(slot); + allocations = computeAllocations(slot, 50); - normProminenceValues(allocations); - - computeScore(allocations); - slot2Allocations.put(slot, allocations); //for tests add the property URI with http://dbpedia.org/property/ namespace @@ -788,6 +784,8 @@ WeightedQuery w = new WeightedQuery(q); double newScore = query.getScore() + a.getScore(); w.setScore(newScore); + w.addAllocations(query.getAllocations()); + w.addAllocation(a); tmp.add(w); } @@ -836,15 +834,20 @@ } */ - private Set<Allocation> computeAllocations(Slot slot){ - Set<Allocation> allocations = new TreeSet<Allocation>(); + private SortedSet<Allocation> computeAllocations(Slot slot){ + SortedSet<Allocation> allocations = new TreeSet<Allocation>(); SolrSearch index = getIndexBySlotType(slot); SolrQueryResultSet rs; for(String word : slot.getWords()){ - rs = index.getResourcesWithScores(word, 30); + if(slot.getSlotType() == SlotType.RESOURCE){ + rs = index.getResourcesWithScores(word, 250); + } else { + rs = index.getResourcesWithScores(word, 30); + } + //debugging // for(Iterator<SolrQueryResultItem> iter = rs.getItems().iterator();iter.hasNext();){ // SolrQueryResultItem item = iter.next(); @@ -855,16 +858,68 @@ 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 + if(slot.getSlotType() == SlotType.RESOURCE){ + Set<String> labels = getRedirectLabels(item.getUri()); + for(String label : labels){ + double tmp = Similarity.getSimilarity(word, label); + if(tmp > similarity){ + similarity = tmp; + } + } + } int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); - double similarity = Similarity.getSimilarity(word, item.getLabel()); allocations.add(new Allocation(item.getUri(), prominence, similarity)); } } - return allocations; + normProminenceValues(allocations); + + computeScore(allocations); + return new TreeSet<Allocation>(allocations); } + private Set<Allocation> computeAllocations(Slot slot, int limit){ + SortedSet<Allocation> allocations = computeAllocations(slot); + + if(allocations.isEmpty()){ + return allocations; + } + + ArrayList<Allocation> l = new ArrayList<Allocation>(allocations); + Collections.sort(l, new Comparator<Allocation>() { + + @Override + public int compare(Allocation o1, Allocation o2) { + double dif = o1.getScore() - o2.getScore(); + if(dif < 0){ + return 1; + } else if(dif > 0){ + return -1; + } else { + return o1.getUri().compareTo(o2.getUri()); + } + } + }); + + return new TreeSet<Allocation>(l.subList(0, Math.min(limit, allocations.size()))); + } + + 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 int getProminenceValue(String uri, SlotType type){ int cnt = 1; String query = null; @@ -1417,15 +1472,17 @@ // Logger.getLogger(DefaultHttpParams.class).setLevel(Level.OFF); // Logger.getLogger(HttpClient.class).setLevel(Level.OFF); // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); -// String question = "In which programming language is GIMP written?"; // 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 = "When/WRB was/VBD Capcom/NNP founded/VBD"; - String question = "Is/VBZ there/RB a/DT video/NN game/NN called/VBN Battle/NNP Chess/NNP"; +// 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 = "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"; 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()); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-06 20:15:33 UTC (rev 3381) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-06 21:28:47 UTC (rev 3382) @@ -78,9 +78,9 @@ @Override public int compareTo(Allocation o) { if(o.getScore() < this.score){ + return 1; + } else if(o.getScore() > this.score){ return -1; - } else if(o.getScore() > this.score){ - return 1; } else { return this.uri.compareTo(o.getUri()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-06 20:15:40
|
Revision: 3381 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3381&view=rev Author: jenslehmann Date: 2011-11-06 20:15:33 +0000 (Sun, 06 Nov 2011) Log Message: ----------- small fixes Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-11-06 14:16:46 UTC (rev 3380) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2011-11-06 20:15:33 UTC (rev 3381) @@ -249,6 +249,9 @@ // System.out.println("FIC: " + description + " " + individual); if (description instanceof NamedClass) { + if(!atomicConcepts.contains(description)) { + throw new ReasoningMethodUnsupportedException("Class " + description + " is not contained in knowledge base."); + } return classInstancesPos.get((NamedClass) description).contains(individual); } else if (description instanceof Negation) { Description child = description.getChild(0); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java 2011-11-06 14:16:46 UTC (rev 3380) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java 2011-11-06 20:15:33 UTC (rev 3381) @@ -96,7 +96,7 @@ PosNegLP lp = context.getBean(PosNegLP.class); AbstractCELA la = context.getBean(AbstractCELA.class); CrossValidation cv = new CrossValidation(la,lp,rs,nrOfFolds,false); - content += cv.getfMeasure().getMean(); + content += Math.round(cv.getfMeasure().getMean())+","; } content += "\n"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-06 14:16:53
|
Revision: 3380 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3380&view=rev Author: jenslehmann Date: 2011-11-06 14:16:46 +0000 (Sun, 06 Nov 2011) Log Message: ----------- NLP2RDF evaluation script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java Added Paths: ----------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-05 19:21:09 UTC (rev 3379) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-06 14:16:46 UTC (rev 3380) @@ -60,6 +60,7 @@ private static Logger rootLogger = Logger.getRootLogger(); private ApplicationContext context; + private IConfiguration configuration; private File confFile; // some CLI options @@ -76,10 +77,9 @@ this.confFile = confFile; } - public void run() throws IOException { // ApplicationContext context, String algorithmBeanName){ - - IConfiguration configuration = null; - + // separate init methods, because some scripts may want to just get the application + // context from a conf file without actually running it + public void init() throws IOException { if(context == null) { Resource confFileR = new FileSystemResource(confFile); List<Resource> springConfigResources = new ArrayList<Resource>(); @@ -88,7 +88,10 @@ ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); context = builder.buildApplicationContext(configuration,springConfigResources); } - + } + + public void run() throws IOException { + if(writeSpringConfiguration) { SpringConfigurationXMLBeanConverter converter = new SpringConfigurationXMLBeanConverter(); XmlObject xml; Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2011-11-05 19:21:09 UTC (rev 3379) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2011-11-06 14:16:46 UTC (rev 3380) @@ -283,4 +283,12 @@ } + public Stat getfMeasure() { + return fMeasure; + } + + public Stat getfMeasureTraining() { + return fMeasureTraining; + } + } Added: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/NLP2RDFEval.java 2011-11-06 14:16:46 UTC (rev 3380) @@ -0,0 +1,108 @@ +/** + * Copyright (C) 2011, 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.scripts.evaluation; + +import java.io.File; +import java.io.IOException; + +import org.dllearner.cli.CLI; +import org.dllearner.cli.CrossValidation; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.utilities.Files; +import org.springframework.context.ApplicationContext; + +/** + * Currently, the script is NLP2RDF evaluation specific, but may be generalised later. + * + * - take array of conf files as arguments + * - run cross val over them and get basic stats + * - output to a CSV file + * - run through gnumeric + * + * @author Jens Lehmann + * + */ +public class NLP2RDFEval { + + public static void main(String args[]) throws IOException { + + // TODO: convert those things into command line arguments to make the script generic + int nrOfFolds = 5; + +// String confs[] = new String[] { +// "../examples/nlp2rdf/learning_7_components/stanford/gas9_vs_nat-gas26.conf", +// "../examples/nlp2rdf/learning_7_components/opennlp/gas9_vs_nat-gas26.conf", +// "../examples/nlp2rdf/learning_7_components/gateannie/gas9_vs_nat-gas26.conf", +// "../examples/nlp2rdf/learning_7_components/dbpedia_spotlight/gas9_vs_nat-gas26.conf", +// "../examples/nlp2rdf/learning_7_components/dbpedia_spotlight_plus/gas9_vs_nat-gas26.conf", +// }; +// + String baseDir = "../examples/nlp2rdf/learning_7_components/"; + + String outputFile = "results.csv"; + String content = ""; + + String[] tools = new String[] { + "stanford", "opennlp", "gateannie", "dbpedia_spotlight", "dbpedia_spotlight_plus" //, "combined" + }; + + String topics[] = new String[] { + "gas9_vs_nat-gas26", "copper17_vs_gold35", "oilseed11_vs_soybean35", "veg-oil18_vs_palm-oil17" + }; + // shorter labels for diagram + String topiclabels[] = new String[] { + "gas", "copper", "oilseed", "veg-oil" + }; + + for(String tool : tools) { + content += "," + tool; + } + content += "\n"; + + // loop through topics + for(int i=0; i<topics.length; i++) { + content += topiclabels[i] + ","; + + for(String tool : tools) { + String conf = baseDir + tool + "/" + topics[i] + ".conf"; + File confFile = new File(conf); + System.out.print("Next file: " + confFile); + CLI cli = new CLI(confFile); + cli.init(); + System.out.println("File " + confFile + " initialised."); + + // perform cross validation + ApplicationContext context = cli.getContext(); + AbstractReasonerComponent rs = context.getBean(AbstractReasonerComponent.class); + PosNegLP lp = context.getBean(PosNegLP.class); + AbstractCELA la = context.getBean(AbstractCELA.class); + CrossValidation cv = new CrossValidation(la,lp,rs,nrOfFolds,false); + content += cv.getfMeasure().getMean(); + } + content += "\n"; + } + + Files.createFile(new File(baseDir + outputFile), content); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-05 19:21:15
|
Revision: 3379 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3379&view=rev Author: lorenz_b Date: 2011-11-05 19:21:09 +0000 (Sat, 05 Nov 2011) Log Message: ----------- Fixed compiler errors caused by missing imports. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java 2011-11-05 14:55:12 UTC (rev 3378) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java 2011-11-05 19:21:09 UTC (rev 3379) @@ -1,4 +1,9 @@ package org.dllearner.examples.pdb; + +import java.io.File; +import java.io.IOException; + +import org.apache.log4j.Logger; /* import java.io.File; import java.io.FileWriter; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-11-05 14:55:19
|
Revision: 3378 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3378&view=rev Author: sebastianwtr Date: 2011-11-05 14:55:12 +0000 (Sat, 05 Nov 2011) Log Message: ----------- [tbsl] fixed some bugs Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-11-05 13:03:30 UTC (rev 3377) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-11-05 14:55:12 UTC (rev 3378) @@ -117,7 +117,7 @@ String s = null; BufferedReader in = null; - // Lies Textzeilen aus der Datei in einen Vector: + // Liest Textzeilen aus der Datei in einen Vector: try { in = new BufferedReader( new InputStreamReader( @@ -182,9 +182,9 @@ } String answer; answer=sendServerQuestionRequest(query); - //System.out.println(query); + System.out.println(query); System.out.println("Antwort: " + answer); - String out=tmp + "\n" + question + ":\n"+answer+"\n"; + String out=tmp + "\n" + "Question: "+question + "\n"+"Query: " + query +"\n Anwer: "+answer+"\n\n##############################"; BufferedWriter outfile = new BufferedWriter( new OutputStreamWriter( @@ -242,8 +242,31 @@ for(SPARQL_Filter tmp : temp.getFilters()) filters=filters+tmp+" "; //System.out.println("\n"); System.out.println("\n"); - query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" { "+ conditions.replace("--","") + "}"+filters; + query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE { "+ conditions.replace("--","") + "}"+filters; + String conditions_new = ""; + for(Path condition: temp.getConditions()){ + //make conditions up-side-down + String[] tmp_upside = condition.toString().split(" -- "); + String tmp_conditions_new=""; + for(String con : tmp_upside) tmp_conditions_new = con +" "+tmp_conditions_new; + //remove all dots befor end + tmp_conditions_new=tmp_conditions_new.replace(".", ""); + //at the end ein . + tmp_conditions_new = tmp_conditions_new + "."; + + //conditions_new=tmp_conditions_new; + + conditions_new=conditions_new + tmp_conditions_new; + } + + + + System.out.println("Conditions: " + conditions); + System.out.println("Conditions_new: " + conditions_new); + + + String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE { "+ conditions_new.replace("--","") + "}"+filters; String[] slots= null; for(Slot slot : temp.getSlots()){ @@ -262,11 +285,24 @@ else replace="?"+array[0]; //System.out.println("replace: " + replace); //hier dann den hm wert von array[1] eintragen - query=query.replace(replace, "<"+hm.get(array[1].toLowerCase())+">"); + String hm_result=hm.get(array[1].toLowerCase()); + try + { + if(hm_result.contains("Category:")) hm_result=hm_result.replace("Category:",""); + } + catch ( Exception e ) + { + //System.out.println( "Das war keine Zahl!" ); + } + + query=query.replace(replace, "<"+hm_result+">"); + query_upside_down=query_upside_down.replace(replace, "<"+hm_result+">"); + } //System.out.println("Query: "+query); lstquery.add(query); + lstquery.add(query_upside_down); } @@ -418,6 +454,7 @@ string=string.replace("</td>",""); string=string.replace("<td>",""); string=string.replace("<th>callret-0</th>", ""); + string=string.replace("<th>y</th>",""); return string; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-05 13:03:37
|
Revision: 3377 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3377&view=rev Author: jenslehmann Date: 2011-11-05 13:03:30 +0000 (Sat, 05 Nov 2011) Log Message: ----------- short test for NLP2RDF Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/test/java/org/dllearner/cli/NLP2RDFCLITest.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-05 07:57:16 UTC (rev 3376) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-05 13:03:30 UTC (rev 3377) @@ -86,7 +86,7 @@ configuration = new ConfParserConfiguration(confFileR); ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); - ApplicationContext context = builder.buildApplicationContext(configuration,springConfigResources); + context = builder.buildApplicationContext(configuration,springConfigResources); } if(writeSpringConfiguration) { Modified: trunk/interfaces/src/test/java/org/dllearner/cli/NLP2RDFCLITest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/NLP2RDFCLITest.java 2011-11-05 07:57:16 UTC (rev 3376) +++ trunk/interfaces/src/test/java/org/dllearner/cli/NLP2RDFCLITest.java 2011-11-05 13:03:30 UTC (rev 3377) @@ -5,6 +5,8 @@ import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.ObjectProperty; import org.junit.Test; import org.springframework.context.ApplicationContext; @@ -12,10 +14,22 @@ @Test public void sampleTest() throws IOException { - File f = new File("../examples/nlp2rdf/sample/sample1.conf"); +// File f = new File("../examples/nlp2rdf/sample/sample1.conf"); + File f = new File("../examples/nlp2rdf/learning_initial_6/dbpedia_spotlight_plus/copper17_vs_gold35.conf"); CLI cli = new CLI(f); cli.run(); ApplicationContext context = cli.getContext(); AbstractReasonerComponent rc = context.getBean(AbstractReasonerComponent.class); + + Individual i = new Individual("http://test.de/TOPICS/copper/COPPER+MEETING+AGREES+GOALS+OF+STUDY+GROUP#offset_592_596_U.S."); + System.out.println("all information about " + i + ": "); + System.out.println(rc.getObjectPropertyRelationships(i)); + + ObjectProperty op = new ObjectProperty("http://ns.aksw.org/scms/means"); + System.out.println("all relationships with scms:means:"); + System.out.println(rc.getPropertyMembers(op)); + + System.out.println("all object properties:"); + System.out.println(rc.getObjectProperties()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-05 07:57:23
|
Revision: 3376 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3376&view=rev Author: lorenz_b Date: 2011-11-05 07:57:16 +0000 (Sat, 05 Nov 2011) Log Message: ----------- Added GROUP BY to query syntax, to be SPARQL 1.1 conform. Modified Paths: -------------- 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_Term.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 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 2011-11-05 07:05:23 UTC (rev 3375) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2011-11-05 07:57:16 UTC (rev 3376) @@ -143,6 +143,8 @@ public String toString() { + String groupBy = null; + String retVal = ""; for (SPARQL_Prefix prefix : prefixes) { @@ -153,9 +155,14 @@ { retVal += "\nSELECT "; + String lastSelectTerm = null; for (SPARQL_Term term : selTerms) { retVal += term.toString() + " "; + if(selTerms.size() > 1 && term.toString().contains("COUNT")){ + groupBy = lastSelectTerm; + } + lastSelectTerm = term.toString(); } } else retVal += "\nASK "; @@ -175,6 +182,10 @@ } retVal += "}\n"; + + if(groupBy != null){ + retVal += "GROUP BY (" + groupBy + ")\n"; + } if (orderBy != null && !orderBy.isEmpty()) { 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 2011-11-05 07:05:23 UTC (rev 3375) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java 2011-11-05 07:57:16 UTC (rev 3376) @@ -87,7 +87,7 @@ // System.err.println("SPARQL_Term: name="+name+",alias="+alias+",agg="+aggregate+",orderBy="+orderBy); // DEBUG if (aggregate != SPARQL_Aggregate.NONE) { if (alias != null && !alias.equals(name)) - return aggregate+"(?"+name.toLowerCase()+") AS ?" + alias; + return "(" + aggregate+"(?"+name.toLowerCase()+") AS ?" + alias + ")"; else return aggregate+"(?"+name.toLowerCase()+")"; } Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-05 07:05:23 UTC (rev 3375) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-05 07:57:16 UTC (rev 3376) @@ -381,7 +381,7 @@ latex.beginEnumeration(); for(WeightedQuery wQ : generatedQueries){ latex.beginEnumerationItem(); - com.hp.hpl.jena.query.Query q = QueryFactory.create(wQ.getQuery().toString()); + com.hp.hpl.jena.query.Query q = QueryFactory.create(wQ.getQuery().toString(), Syntax.syntaxARQ); if(q.toString().contains("http://dbpedia.org/property/")){ q.setPrefix("dbp", "http://dbpedia.org/property/"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-05 07:05:30
|
Revision: 3375 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3375&view=rev Author: lorenz_b Date: 2011-11-05 07:05:23 +0000 (Sat, 05 Nov 2011) Log Message: ----------- Some changes in eval output. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.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 15:22:54 UTC (rev 3374) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-05 07:05:23 UTC (rev 3375) @@ -119,6 +119,8 @@ private Map<Template, Collection<? extends Query>> template2Queries; private Map<Slot, List<String>> slot2URI; + private Set<WeightedQuery> generatedQueries; + private Map<String, String> prefixMap; private Lemmatizer lemmatizer = new LingPipeLemmatizer();// StanfordLemmatizer(); @@ -282,10 +284,10 @@ // sparqlQueryCandidates = getNBestQueryCandidatesForTemplates(template2Queries); //get the weighted query candidates - Set<WeightedQuery> weightedQueries = getWeightedSPARQLQueries(templates); + generatedQueries = getWeightedSPARQLQueries(templates); sparqlQueryCandidates = new ArrayList<Query>(); int i = 0; - for(WeightedQuery wQ : weightedQueries){System.out.println(wQ); + for(WeightedQuery wQ : generatedQueries){System.out.println(wQ); sparqlQueryCandidates.add(wQ.getQuery()); if(i == maxTestedQueries){ break; @@ -302,6 +304,22 @@ } + public Set<WeightedQuery> getGeneratedQueries() { + return generatedQueries; + } + + public Set<WeightedQuery> getGeneratedQueries(int topN) { + Set<WeightedQuery> topNQueries = new TreeSet<WeightedQuery>(); + int max = Math.min(topN, generatedQueries.size()); + for(WeightedQuery wQ : generatedQueries){ + topNQueries.add(wQ); + if(topNQueries.size() == max){ + break; + } + } + return topNQueries; + } + public List<String> getSPARQLQueries() throws NoTemplateFoundException{ logger.info("Generating SPARQL query templates..."); mon.start(); @@ -1253,7 +1271,10 @@ logger.info("Testing query:\n" + query); boolean result = executeAskQuery(query); learnedSPARQLQueries.put(query, result); - if(stopIfQueryResultNotEmpty && result){ +// if(stopIfQueryResultNotEmpty && result){ +// return; +// } + if(stopIfQueryResultNotEmpty){ return; } logger.info("Result: " + result); @@ -1400,7 +1421,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 = "When/WRB was/VBD Capcom/NNP founded/VBD"; +// String question = "When/WRB was/VBD Capcom/NNP founded/VBD"; + 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 = "Which/WDT music/NN albums/NNS contain/VBP the/DT song/NN Last/NNP Christmas/NNP"; Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-04 15:22:54 UTC (rev 3374) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-05 07:05:23 UTC (rev 3375) @@ -37,8 +37,10 @@ import org.dllearner.algorithm.tbsl.learning.NoTemplateFoundException; import org.dllearner.algorithm.tbsl.learning.SPARQLTemplateBasedLearner; import org.dllearner.algorithm.tbsl.sparql.Query; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Prefix; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.Template; +import org.dllearner.algorithm.tbsl.sparql.WeightedQuery; import org.dllearner.algorithm.tbsl.util.LatexWriter; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -49,8 +51,10 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +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.RDFNode; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.sparql.vocabulary.FOAF; @@ -369,32 +373,34 @@ latex.endEnumeration(); //get the generated SPARQL query candidates - Map<Template, Collection<? extends Query>> template2Queries = stbl.getTemplates2SPARQLQueries(); + Set<WeightedQuery> generatedQueries = stbl.getGeneratedQueries(15); //write generated queries subsection - latex.beginSubsection("Top " + topN2Print + " generated queries per template"); - int k = 1; - List<Query> queries; - for(Template t : templates){ - latex.beginSubSubsection("Template " + k); - queries = new ArrayList<Query>(template2Queries.get(t)); - if(!queries.isEmpty()){ - latex.beginEnumeration(); - } - //print top n queries to latex file - int max = Math.min(topN2Print, queries.size()); - for(int j = 0; j < max; j++){ + latex.beginSubsection("Top " + 15 + " generated queries"); + if(!generatedQueries.isEmpty()){ + latex.beginEnumeration(); + for(WeightedQuery wQ : generatedQueries){ latex.beginEnumerationItem(); - latex.addListing(queries.get(j).toString()); + com.hp.hpl.jena.query.Query q = QueryFactory.create(wQ.getQuery().toString()); + if(q.toString().contains("http://dbpedia.org/property/")){ + q.setPrefix("dbp", "http://dbpedia.org/property/"); + } + if(q.toString().contains("http://dbpedia.org/ontology/")){ + q.setPrefix("dbo", "http://dbpedia.org/ontology/"); + } + if(q.toString().contains("http://dbpedia.org/resource/")){ + q.setPrefix("dbr", "http://dbpedia.org/resource/"); + } + String queryString = q.toString(); + String requestURL = new QueryEngineHTTP(endpoint.getURL().toString(), queryString).toString(); +// System.out.println(requestURL); + queryString = queryString + "\n" + "Score(" + wQ.getScore() + ")"; + latex.addListing(queryString); latex.endEnumerationItem(); } - if(!queries.isEmpty()){ - latex.endEnumeration(); - } - k++; + latex.endEnumeration(); } - //get the URIs for each template slot latex.beginSubsection("Covered entities"); Map<Slot, List<String>> slot2URIsMap = stbl.getSlot2URIs(); 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:23:00
|
Revision: 3374 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3374&view=rev Author: lorenz_b Date: 2011-11-04 15:22:54 +0000 (Fri, 04 Nov 2011) Log Message: ----------- Added comparable interface. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-04 15:03:03 UTC (rev 3373) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-04 15:22:54 UTC (rev 3374) @@ -1,7 +1,7 @@ package org.dllearner.algorithm.tbsl.sparql; -public class Allocation { +public class Allocation implements Comparable<Allocation>{ private String uri; @@ -74,6 +74,17 @@ return false; return true; } + + @Override + public int compareTo(Allocation o) { + if(o.getScore() < this.score){ + return -1; + } else if(o.getScore() > this.score){ + return 1; + } else { + return this.uri.compareTo(o.getUri()); + } + } 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-04 12:51:40
|
Revision: 3372 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3372&view=rev Author: lorenz_b Date: 2011-11-04 12:51:33 +0000 (Fri, 04 Nov 2011) Log Message: ----------- Added constructors with POS tagger. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.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-03 19:32:25 UTC (rev 3371) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-04 12:51:33 UTC (rev 3372) @@ -5,10 +5,12 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -22,6 +24,7 @@ import org.dllearner.algorithm.qtl.util.ModelGenerator.Strategy; 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.search.HierarchicalSolrSearch; import org.dllearner.algorithm.tbsl.search.SolrQueryResultItem; import org.dllearner.algorithm.tbsl.search.SolrQueryResultSet; @@ -68,6 +71,10 @@ public class SPARQLTemplateBasedLearner implements SparqlQueryLearningAlgorithm{ + //for debugging + List<String> exclusions = Arrays.asList(new String[]{"http://dbpedia.org/ontology/GeopoliticalOrganisation", + "http://dbpedia.org/ontology/Non-ProfitOrganisation"}); + enum Ranking{ LUCENE, SIMILARITY, NONE } @@ -140,6 +147,20 @@ templateGenerator = new Templator(); } + 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); + } + /* * Only for Evaluation useful. */ @@ -635,7 +656,7 @@ Query cleanQuery = t.getQuery(); queries.add(new WeightedQuery(cleanQuery)); - Set<WeightedQuery> tmp = new HashSet<WeightedQuery>(); + Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); List<Slot> sortedSlots = new ArrayList<Slot>(); Set<Slot> classSlots = new HashSet<Slot>(); for(Slot slot : t.getSlots()){ @@ -669,8 +690,8 @@ 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>")){ - System.out.println("YES"); + 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){ @@ -701,7 +722,8 @@ if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ drop = true; } else { -// System.out.println("DROPPING: \n" + q.toString()); + if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")) + System.out.println("DROPPING: \n" + q.toString()); } } } else { @@ -731,7 +753,8 @@ if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ drop = true; } else { -// System.out.println("DROPPING: \n" + q.toString()); + if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")) + System.out.println("DROPPING: \n" + q.toString()); } } } @@ -801,6 +824,14 @@ for(String word : slot.getWords()){ rs = index.getResourcesWithScores(word, 10); + //debugging +// for(Iterator<SolrQueryResultItem> iter = rs.getItems().iterator();iter.hasNext();){ +// SolrQueryResultItem item = iter.next(); +// if(exclusions.contains(item.getUri())){ +// iter.remove(); +// } +// } + // System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); @@ -1364,12 +1395,11 @@ // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); // String question = "In which programming language is GIMP written?"; // 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 = "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 = "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 = "Give me all books written by authors influenced by Ernest Hemingway."; +// 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); // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), // Collections.<String>singletonList(""), Collections.<String>emptyList()); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2011-11-03 19:32:25 UTC (rev 3371) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2011-11-04 12:51:33 UTC (rev 3372) @@ -41,6 +41,7 @@ PartOfSpeechTagger tagger; LTAGLexicon g; LTAG_Lexicon_Constructor LTAG_Constructor = new LTAG_Lexicon_Constructor(); + Parser p; Preprocessor pp; @@ -53,9 +54,14 @@ boolean ONE_SCOPE_ONLY = true; boolean UNTAGGED_INPUT = true; - boolean USE_NER = false; + boolean USE_NER = true; public Templator() { + this(new StanfordPartOfSpeechTagger()); + } + + public Templator(final PartOfSpeechTagger tagger) { + this.tagger = tagger; List<InputStream> grammarFiles = new ArrayList<InputStream>(); for(int i = 0; i < GRAMMAR_FILES.length; i++){ @@ -64,8 +70,6 @@ g = LTAG_Constructor.construct(grammarFiles); - tagger = new StanfordPartOfSpeechTagger(); -// tagger = new ApachePartOfSpeechTagger(); p = new Parser(); p.SHOW_GRAMMAR = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2011-11-03 19:32:31
|
Revision: 3371 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3371&view=rev Author: christinaunger Date: 2011-11-03 19:32:25 +0000 (Thu, 03 Nov 2011) Log Message: ----------- [tbsl] yet another two bug fixes (template generation) Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java 2011-11-03 17:28:10 UTC (rev 3370) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java 2011-11-03 19:32:25 UTC (rev 3371) @@ -298,11 +298,11 @@ } semName = semName.substring(1); - out.add(new Pair<String,String>("(NP NP* ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<e,t>,[ l1:[ y | SLOT_title(x,y), regex(y,'" + semName + "') ] ], [],[],[ SLOT_title/PROPERTY/title^name ]>")); + out.add(new Pair<String,String>("(NP NP* ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<e,t>,[ l1:[ y | SLOT_title(x,y), regex(y,'" + semName + "') ] ], [],[],[ SLOT_title/PROPERTY/title^name^label ]>")); out.add(new Pair<String,String>("(NP NP* ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<e,t>,[ l1:[|] ],[],[],[ x/RESOURCE/"+semName+"]>")); - out.add(new Pair<String,String>("(DP DP* ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<<e,t>,t>,[ l1:[ y | SLOT_title(x,y), regex(y,'" + semName + "') ] ], [],[],[ SLOT_title/PROPERTY/title^name ]>")); + out.add(new Pair<String,String>("(DP DP* ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<<e,t>,t>,[ l1:[ y | SLOT_title(x,y), regex(y,'" + semName + "') ] ], [],[],[ SLOT_title/PROPERTY/title^name^label ]>")); out.add(new Pair<String,String>("(DP DP* ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<<e,t>,t>,[ l1:[|] ],[],[],[ x/RESOURCE/"+semName+"]>")); - out.add(new Pair<String,String>("(ADJ ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<e,t>,[ l1:[ y | SLOT_title(x,y), regex(y,'" + semName + "') ] ], [],[],[ SLOT_title/PROPERTY/title^name ]>")); + out.add(new Pair<String,String>("(ADJ ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<e,t>,[ l1:[ y | SLOT_title(x,y), regex(y,'" + semName + "') ] ], [],[],[ SLOT_title/PROPERTY/title^name^label ]>")); out.add(new Pair<String,String>("(ADJ ADJ:'"+ w +"' " + rawNames + ")", "<x,l1,<e,t>,[ l1:[|] ],[],[],[ x/RESOURCE/"+semName+"]>")); return out; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java 2011-11-03 17:28:10 UTC (rev 3370) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java 2011-11-03 19:32:25 UTC (rev 3371) @@ -261,7 +261,8 @@ String[] vEntry = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", "<x,l1,t,[ l1:[|], l4:[ | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + symslot + "]>" + - " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>" + + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; result.add(vEntry); } else if (pos.equals("VB")) { Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2011-11-03 17:28:10 UTC (rev 3370) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2011-11-03 19:32:25 UTC (rev 3371) @@ -69,7 +69,6 @@ at least || (DP DET:'at' DET:'least' NUM[num] NP[noun]) || <y,l1,<<e,t>,t>,[l1:[ y,j |count(a,y,j), greaterorequal(j,x) ]],[(l2,y,noun,<e,t>),(l3,x,num,e)],[ l1=l2, l2=l3 ],[]> at most || (DP DET:'at' DET:'most' NUM[num] NP[noun]) || <y,l1,<<e,t>,t>,[l1:[ y,j | count(a,y,j), smallerorequal(j,x) ]],[(l2,y,noun,<e,t>),(l3,x,num,e)],[ l1=l2, l2=l3 ],[]> exactly || (DP DET:'exactly' NUM[num] NP[noun]) || <y,l1,<<e,t>,t>,[l1:[ y,j | count(y,j), equals(j,x) ]],[(l2,y,noun,<e,t>),(l3,x,num,e)],[ l1=l2, l2=l3 ],[]> - s || (DP DP* DET:'s' NP[noun]) || - other || (NP ADJ:'other' NP*) || <x,l1,<e,t>,[ l1:[ | ] ], [],[],[]> total || (NP ADJ:'total' NP[np]) || <s,l1,<e,t>,[ l1:[ ?s | sum(a,x,s) ] ], [ (l2,x,np,<e,t>) ],[ l2=l1 ],[]> @@ -86,7 +85,7 @@ the least || (DET DET:'the' DET:'least') || <y, l1, e, [ l1:[ | l2:[ y | ] THELEAST y l3:[|] ] ], [], [],[]> // CHEAT! - highest || (NP ADJ:'highest' NP*) || <x, l1, e, [ l1:[ | maximum(a,x,x) ] ], [], [],[]> ;; <x, l1, e, [ l1:[ j | SLOT_high(x,j), maximum(a,j,j) ] ],[],[],[ SLOT_high/PROPERTY/height^elevation ]> + highest || (NP ADJ:'highest' NP*) || <x, l1, e, [ l1:[ | maximum(x) ] ], [], [],[]> ;; <x, l1, e, [ l1:[ j | SLOT_high(x,j), maximum(j) ] ],[],[],[ SLOT_high/PROPERTY/height^elevation ]> // COUNT more than || (DP DET:'more' DET:'than' NUM[num] NP[np]) || <y,l1,<<e,t>,t>,[ l1:[ y,c | count(y,c), greater(c,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[]> ;; <y,l1,<<e,t>,t>,[ l1:[ y | greater(y,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[]> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <km...@us...> - 2011-11-03 17:28:21
|
Revision: 3370 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3370&view=rev Author: kmpf Date: 2011-11-03 17:28:10 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Changed *.conf format. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-11-03 15:02:37 UTC (rev 3369) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-11-03 17:28:10 UTC (rev 3370) @@ -90,6 +90,33 @@ return resprint; } + public static HashMap<Resource, StringBuffer> getAminoAcidStringBufferMap(String init){ + // put all amino acid resources and the their conf-files together + HashMap<Resource, StringBuffer> resourceString = new HashMap<Resource, StringBuffer>(30); + resourceString.put(ALA, new StringBuffer(init)); + resourceString.put(CYS, new StringBuffer(init)); + resourceString.put(ASP, new StringBuffer(init)); + resourceString.put(GLU, new StringBuffer(init)); + resourceString.put(PHE, new StringBuffer(init)); + resourceString.put(GLY, new StringBuffer(init)); + resourceString.put(HIS, new StringBuffer(init)); + resourceString.put(ILE, new StringBuffer(init)); + resourceString.put(LYS, new StringBuffer(init)); + resourceString.put(LEU, new StringBuffer(init)); + resourceString.put(MET, new StringBuffer(init)); + resourceString.put(ASN, new StringBuffer(init)); + resourceString.put(PRO, new StringBuffer(init)); + resourceString.put(GLN, new StringBuffer(init)); + resourceString.put(ARG, new StringBuffer(init)); + resourceString.put(SER, new StringBuffer(init)); + resourceString.put(THR, new StringBuffer(init)); + resourceString.put(VAL, new StringBuffer(init)); + resourceString.put(TRP, new StringBuffer(init)); + resourceString.put(TYR, new StringBuffer(init)); + resourceString.put(SEL, new StringBuffer(init)); + return resourceString; + } + public static HashMap<Resource, String> getAminoAcidArffAttributeMap(){ HashMap<Resource, String> resdata = new HashMap<Resource, String>(30); resdata.put(ALA, new String("2,0,0.5,?,?")); Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-11-03 15:02:37 UTC (rev 3369) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-11-03 17:28:10 UTC (rev 3370) @@ -101,16 +101,16 @@ * load = true -> load alle .rdf, .conf and .arff Files that can be found within the directory dataDir * load = false -> don't load anything */ - Boolean dlLearn = true; - Boolean wekaLearn = true; + Boolean dlLearn = false; + Boolean wekaLearn = false; int dataSet = 5; /* * data for test purpose */ -// PdbProtein testProtein = new PdbProtein("1XFF"); - PDBProtein testProtein = new PDBProtein("1XFF", "A"); + PDBProtein testProtein = new PDBProtein("1XFF"); +// PDBProtein testProtein = new PDBProtein("1LMB", "3"); /* * create a training data set @@ -233,14 +233,14 @@ try { String line = protein.getPdbID() + "." + protein.getChainID() + "." + protein.getSpecies() + "\n"; FileWriter out = new FileWriter(speciesProteins, true); - _logger.debug("Write " + line + "to file " + speciesProteins.getPath() + speciesProteins.getName()); + _logger.debug("Write " + line + "to file " + speciesProteins.getPath()); out.write(line); out.close(); } catch (FileNotFoundException e) { - _logger.error("Could not find file " + speciesProteins.getPath() + speciesProteins.getName()); + _logger.error("Could not find file " + speciesProteins.getPath() ); e.printStackTrace(); } catch (IOException e) { - _logger.error("Something went wrong while trying to write to " + speciesProteins.getPath() + speciesProteins.getName()); + _logger.error("Something went wrong while trying to write to " + speciesProteins.getPath() ); e.printStackTrace(); } } @@ -325,33 +325,53 @@ try { PDBProtein protein = model.getProtein(); - // the file with all amino acids + + // the .conf file that contains all positives and negatives String confFilePath = pdbDir + protein.getConfFileName(); PrintStream confFile = new PrintStream (new File(confFilePath)); - // add import statements to confFile - String importStmt = new String("import(\"../AA_properties.owl\");\n" + - "import(\"" + protein.getRdfFileName() + "\");\n"); - confFile.println(importStmt); - - HashMap<Resource, File> confFilePerResidue = AminoAcids.getAllConfFiles(pdbDir, protein.getConfFileName()); - HashMap<Resource, PrintStream> resprint = AminoAcids.getAminoAcidPrintStreamMap(confFilePerResidue); - Property type = ResourceFactory.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "type"); + // knowledge source definition + String ks = new String ("// knowledge source definition\n" + + "ks.type = \"OWL File\"\n" + + "ks.fileName = \"AA_properties.owl\"\n" + + "\n" + + "ks.type = \"OWL File\"\n" + + "ks.fileName = \"" + protein.getRdfFileName() + "\"\n"); + // learning problem + StringBuffer lp = new StringBuffer ("// learning problem\n" + + "lp.type = \"posNegStandard\"" + + "\n" + + "lp.positiveExamples = { "); - // add import statements to <PDB ID>_<Amino Acid>.conf files - Iterator<Resource> keys = resprint.keySet().iterator(); - while (keys.hasNext()){ - resprint.get(keys.next()).println(importStmt); + // separate files that contain only positives and negatives of a distinct type + HashMap<Resource, File> confFilePerResidue = + AminoAcids.getAllConfFiles(pdbDir, protein.getConfFileName()); + HashMap<Resource, PrintStream> resprint = + AminoAcids.getAminoAcidPrintStreamMap(confFilePerResidue); + HashMap<Resource, StringBuffer> resourceStringBuffer = + AminoAcids.getAminoAcidStringBufferMap(lp.toString()); + + // add knowledge source definition to <PDB ID>.conf files + confFile.println(ks); + + // add knowledge source definition to <PDB ID>_<Amino Acid>.conf files + Iterator<Resource> resources = resprint.keySet().iterator(); + while (resources.hasNext()){ + resprint.get(resources.next()).println(ks); } - // add every amino acid in positive list to <PDB ID>.conf and its corresponding <PDB ID>_<Amino Acid>.conf + ArrayList<Resource> positives = model.getPositives(); + + Property type = ResourceFactory.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "type"); + + // add positive examples to <PDB ID>.conf and corresponding <PDB ID>_<Amino Acid>.conf files for (int i = 0 ; i < positives.size() ; i++ ) { - confFile.println("+\"" + positives.get(i).getURI() + "\""); + lp.append("\"" + positives.get(i).getURI() + "\", "); try{ Statement spo = model.getModel().getProperty(positives.get(i), type); - resprint.get(spo.getResource()).println("+\"" + positives.get(i).getURI() + "\""); + resourceStringBuffer.get(spo.getResource()).append("\"" + positives.get(i).getURI() + "\", "); } catch (NullPointerException e) { // What was the Object that probably caused the pain? _logger.error("Object probably not in our HashMap: " + @@ -360,13 +380,29 @@ } } + if (lp.toString().contains(",")) + lp.deleteCharAt(lp.lastIndexOf(",")); + lp.append("}\n" + + "lp.negativeExamples = { "); + + resources = resourceStringBuffer.keySet().iterator(); + while (resources.hasNext()){ + Resource residue = resources.next(); + if (resourceStringBuffer.get(residue).toString().contains(",")) + resourceStringBuffer.get(residue).deleteCharAt( + resourceStringBuffer.get(residue).lastIndexOf(",")); + resourceStringBuffer.get(residue).append("}\n" + + "lp.negativeExamples = { "); + } + + // add every amino acid in negative list to <PDB ID>.conf and its corresponding <PDB ID>_<Amino Acid>.conf ArrayList<Resource> negatives = model.getNegatives(); for (int i = 0 ; i < negatives.size() ; i++ ) { - confFile.println("-\"" + negatives.get(i).getURI() + "\""); + lp.append("\"" + negatives.get(i).getURI() + "\", "); try{ Statement spo = model.getModel().getProperty(negatives.get(i), type); - resprint.get(spo.getResource()).println("-\"" + negatives.get(i).getURI() + "\""); + resourceStringBuffer.get(spo.getResource()).append("\"" + negatives.get(i).getURI() + "\", "); } catch (NullPointerException e) { // What was the Object that probably caused the pain? _logger.error("Object probably not in our HashMap: " + @@ -374,7 +410,26 @@ e.printStackTrace(); } } + + // add learning problem to <PDB ID>.conf file + // and write learning problem to file + if (lp.toString().contains(",")) + lp.deleteCharAt(lp.lastIndexOf(",")); + lp.append("}\n"); + confFile.println(lp); + // add learning problem to <PDB ID>_<Amino Acid>.conf files + // and write learning problem to file + resources = resourceStringBuffer.keySet().iterator(); + while (resources.hasNext()){ + Resource residue = resources.next(); + if (resourceStringBuffer.get(residue).toString().contains(",")) + resourceStringBuffer.get(residue).deleteCharAt( + resourceStringBuffer.get(residue).lastIndexOf(",")); + resourceStringBuffer.get(residue).append("}\n"); + resprint.get(residue).println(resourceStringBuffer.get(residue)); + } + // Important - free up resources used running the query confFile.close(); @@ -382,7 +437,6 @@ while ( newkeys.hasNext() ){ resprint.get(newkeys.next()).close(); } - } catch (IOException e) { @@ -409,16 +463,16 @@ * ATTRIBUTES */ // Integer declaring Position in chain - String attributes = "@ATTRIBUTE hydrophob NUMERIC\n" + // Hydrophilic = 0; Hydrophobic = 1; Very_hydrophobic = 2 + StringBuffer attributes = new StringBuffer("@ATTRIBUTE hydrophob NUMERIC\n" + // Hydrophilic = 0; Hydrophobic = 1; Very_hydrophobic = 2 "@ATTRIBUTE charge NUMERIC\n" + // Negative = -1; Neutral = 0; Positive = 1 "@ATTRIBUTE size NUMERIC\n" + // Large = 2; Small = 1; Tiny = 0.5 "@ATTRIBUTE aromaticity NUMERIC\n" + // Aliphatic = 0; Aromatic = 1 - "@ATTRIBUTE hydrogen_bonding NUMERIC\n"; // Donor = 1; Donor/Acceptor = 0; Acceptor = -1 + "@ATTRIBUTE hydrogen_bonding NUMERIC\n"); // Donor = 1; Donor/Acceptor = 0; Acceptor = -1 for (int i = -8; i <= 8; i++) { - attributes += "@ATTRIBUTE aa_position_" + i + " {A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y}\n"; // amino acid at position $i from current amino acid + attributes.append("@ATTRIBUTE aa_position_" + i + " {A,C,D,E,F,G,H,I,K,L,M,N,P,Q,R,S,T,V,W,Y}\n"); // amino acid at position $i from current amino acid } - attributes += "@ATTRIBUTE in_helix NUMERIC\n"; // Helix = 1 Other = 0 + attributes.append("@ATTRIBUTE in_helix NUMERIC\n"); // Helix = 1 Other = 0 _logger.debug(attributes); out.println(attributes); @@ -443,32 +497,32 @@ Resource currentAA = firstAA; Resource nextAA = firstAA; - int i = 0; - String dataLine; - do { - dataLine = ""; + + + for ( int i = 0; currentAA.hasProperty(iib); i++ ) { + StringBuffer dataLine = new StringBuffer(""); currentAA = nextAA; NodeIterator niter = model.getModel().listObjectsOfProperty(currentAA, type); while (niter.hasNext()){ Resource key = niter.next().asResource(); if (resdata.containsKey(key)){ - dataLine += resdata.get(key) +","; + dataLine.append( resdata.get(key) + "," ); } } for (int j = (i - 8); j <= (i + 8) ; j++){ try { - dataLine += protein.getSequence().charAt(j) + ","; + dataLine.append( protein.getSequence().charAt(j) + "," ); } catch (IndexOutOfBoundsException e) { - dataLine += "?,"; + dataLine.append( "?," ); } } if (positives.contains(currentAA)){ - dataLine += "1"; + dataLine.append( "1" ); } else if (negatives.contains(currentAA)){ - dataLine += "0"; + dataLine.append( "0" ); } @@ -479,8 +533,7 @@ } _logger.info(dataLine); out.println(dataLine); - i++; - } while (currentAA.hasProperty(iib)) ; + } } } catch (FileNotFoundException e){ e.printStackTrace(); Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-11-03 15:02:37 UTC (rev 3369) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-11-03 17:28:10 UTC (rev 3370) @@ -37,7 +37,9 @@ this._protein = protein; this._pdbIdModel = this.getPdbRdfModel(); this.getProtein().setSequence(extractSequence(_pdbIdModel)); + System.out.println("Sequence: " + this.getProtein().getSequence()); this.getProtein().setSpecies(extractSpecies(_pdbIdModel)); + System.out.println("Species: " + this.getProtein().getSpecies()); createPositivesAndNegatives(); } @@ -98,11 +100,12 @@ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> " + - "CONSTRUCT {<http://bio2rdf.org/pdb:" + this.getProtein().getPdbID() + "/extraction/source/gene/organism> rdfs:label ?species. }" + - "WHERE { ?x1 <http://purl.org/dc/terms/isPartOf> ?x2 ." + - " ?x1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?x3 ." + - " ?x1 <http://bio2rdf.org/pdb:isImmediatelyBefore> ?x4 ." + - " ?x5 rdfs:label ?species FILTER (str(?x5) = fn:concat(str(?x2), '/extraction/source/gene/organism')) . }"; + "CONSTRUCT { pdb:" + this.getProtein().getPdbID() + "/extraction/source/gene/organism rdfs:label ?species. }" + + "WHERE { ?x1 dcterms:isPartOf ?x2 ." + + " ?x1 rdf:type> ?x3 ." + + " ?x1 pdb:isImmediatelyBefore ?x4 ." + + " ?x5 rdfs:label ?species " + + " FILTER (str(?x5) = fn:concat(str(?x2), '/extraction/source/gene/organism')) . }"; // System.out.println(queryString); @@ -189,36 +192,37 @@ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> " + - "CONSTRUCT { ?x1 <http://bio2rdf.org/pdb:beginsAt> ?x2 ." + - " ?x1 <http://bio2rdf.org/pdb:endsAt> ?x3 . " + - " ?x5 <http://purl.org/dc/terms/isPartOf> ?x4 . " + - " ?x5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?x6 ." + - " ?x5 <http://bio2rdf.org/pdb:isImmediatelyBefore> ?x7 ." + + "CONSTRUCT { ?x1 pdb:beginsAt ?x2 ." + + " ?x1 pdb:endsAt ?x3 . " + + " ?x5 dcterms:isPartOf ?x4 . " + + " ?x5 rdf:type ?x6 ." + + " ?x5 pdb:isImmediatelyBefore ?x7 ." + " ?organism rdfs:label ?organismName ." + - " ?seq <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://bio2rdf.org/pdb:PolymerSequence> ." + + " ?seq rdf:type pdb:PolymerSequence ." + " ?seq pdb:hasValue ?sequence. } " + - "WHERE { ?x1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://bio2rdf.org/pdb:Helix> ." + - " ?x1 <http://bio2rdf.org/pdb:beginsAt> ?x2 ." + - " ?x1 <http://bio2rdf.org/pdb:endsAt> ?x3 ." + - " ?x3 <http://purl.org/dc/terms/isPartOf> ?x4 ." + - " ?x4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://bio2rdf.org/pdb:Polypeptide(L)> ." + - " ?x5 <http://purl.org/dc/terms/isPartOf> ?x4 ." + - " ?x5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?x6 ."; + "WHERE { ?x1 rdf:type pdb:Helix ." + + " ?x1 pdb:beginsAt ?x2 ." + + " ?x1 pdb:endsAt ?x3 ." + + " ?x3 dcterms:isPartOf ?x4 ." + + " ?x4 rdf:type <http://bio2rdf.org/pdb:Polypeptide(L)> ." + + " ?x5 dcterms:isPartOf ?x4 ." + + " ?x5 rdf:type ?x6 ."; if (chainID.length() == 1 && pdbID.length() == 4) { queryString += - " ?x5 <http://bio2rdf.org/pdb:hasChainPosition> ?x8 ." + - " ?x8 <http://purl.org/dc/terms/isPartOf> <http://bio2rdf.org/pdb:" + + " ?x5 pdb:hasChainPosition ?x8 ." + + " ?x8 dcterms:isPartOf pdb:" + pdbID.toUpperCase() + "/chain_" + chainID.toUpperCase() + "> ."; } queryString += - " ?organism rdfs:label ?organismName FILTER (str(?organism) = fn:concat(str(?x4), '/extraction/source/gene/organism')) . " + - " ?seq <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://bio2rdf.org/pdb:PolymerSequence> . " + + " ?organism rdfs:label ?organismName " + + "FILTER (str(?organism) = fn:concat(str(?x4), '/extraction/source/gene/organism')) . " + + " ?seq rdf:type pdb:PolymerSequence . " + " ?seq pdb:hasValue ?sequence ." + // with the Optional clause i get the information by which amino acid // a amino acid is followed - " OPTIONAL { ?x5 <http://bio2rdf.org/pdb:isImmediatelyBefore> ?x7 . } .}"; + " OPTIONAL { ?x5 pdb:isImmediatelyBefore ?x7 . } .}"; System.out.println(queryString); Query query = QueryFactory.create(queryString); Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java 2011-11-03 15:02:37 UTC (rev 3369) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBWekaLearner.java 2011-11-03 17:28:10 UTC (rev 3370) @@ -1,5 +1,5 @@ package org.dllearner.examples.pdb; - +/* import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -10,7 +10,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; -/* + import weka.classifiers.Evaluation; import weka.classifiers.bayes.NaiveBayes; import weka.core.Instances; @@ -22,7 +22,7 @@ private static Logger logger = Logger.getRootLogger(); public PDBWekaLearner (File arffFile) throws IOException{ - /* + /* // create logger (configure this to your needs) SimpleLayout layout = new SimpleLayout(); FileAppender fileAppender = new FileAppender(layout, "log/sample_log.txt", false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-03 15:02:43
|
Revision: 3369 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3369&view=rev Author: lorenz_b Date: 2011-11-03 15:02:37 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Changed eval output. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LatexWriter.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LatexWriter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LatexWriter.java 2011-11-03 14:29:32 UTC (rev 3368) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LatexWriter.java 2011-11-03 15:02:37 UTC (rev 3369) @@ -61,8 +61,8 @@ sb.append("\\end{document}"); } - public void beginSection(String title){ - sb.append("\\section{").append(title).append("}").append("\\label{" + cnt++ + "}\n"); + public void beginSection(String title, int id){ + sb.append("\\section{").append(title).append("}").append("\\label{" + id + "}\n"); } public void beginSubsection(String title){ Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-03 14:29:32 UTC (rev 3368) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-03 15:02:37 UTC (rev 3369) @@ -317,7 +317,7 @@ String errorCode = ""; LatexWriter latex = new LatexWriter(); int i = 0; - for(Entry<Integer, String> entry : id2Question.entrySet()){if(entry.getKey()==50)continue; + for(Entry<Integer, String> entry : id2Question.entrySet()){//if(entry.getKey()==50)continue; if((testID != -1 && entry.getKey() != testID) || (yagoExclusions.contains(entry.getKey())))continue; try { questionId = entry.getKey(); @@ -333,7 +333,7 @@ //write new section for query - latex.beginSection(extractSentence(question)); + latex.beginSection(extractSentence(question), questionId); //write subsection for target latex.beginSubsection("Target"); //write subsubsection for target query @@ -616,7 +616,7 @@ //write new section for query - latex.beginSection(question); + latex.beginSection(question, questionId); //write subsection for target latex.beginSubsection("Target"); //write subsubsection for target query This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-03 14:29:38
|
Revision: 3368 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3368&view=rev Author: lorenz_b Date: 2011-11-03 14:29:32 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Small changes in dbprop handling. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.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-03 14:04:11 UTC (rev 3367) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-03 14:29:32 UTC (rev 3368) @@ -595,6 +595,7 @@ double score = alpha * a.getSimilarity() + beta * a.getProminence(); a.setScore(score); } + } private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ @@ -615,6 +616,18 @@ computeScore(allocations); slot2Allocations.put(slot, allocations); + + //for tests add the property URI with http://dbpedia.org/property/ namespace + Set<Allocation> tmp = new HashSet<Allocation>(); + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(Allocation a : allocations){ + String uri = "http://dbpedia.org/property/" + a.getUri().substring(a.getUri().lastIndexOf("/")+1); + Allocation newA = new Allocation(uri, a.getSimilarity(), a.getProminence()); + newA.setScore(a.getScore()-0.000001); + tmp.add(newA); + } + } + allocations.addAll(tmp); } @@ -787,15 +800,7 @@ SolrQueryResultSet rs; for(String word : slot.getWords()){ rs = index.getResourcesWithScores(word, 10); - //for tests add the property URI with http://dbpedia.org/property/ namespace - Set<SolrQueryResultItem> tmp = new HashSet<SolrQueryResultItem>(); - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ - for(SolrQueryResultItem i : rs.getItems()){ - String uri = "http://dbpedia.org/property/" + i.getUri().substring(i.getUri().lastIndexOf("/")+1); - tmp.add(new SolrQueryResultItem(i.getLabel(), uri)); - } - } - rs.addItems(tmp); + // System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); @@ -1359,9 +1364,10 @@ // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); // String question = "In which programming language is GIMP written?"; // 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 = "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 = "How/WRB many/JJ films/NNS did/VBD Leonardo/NNP DiCaprio/NNP star/VB in/IN"; // String question = "Give me all books written by authors influenced by Ernest Hemingway."; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-03 14:04:11 UTC (rev 3367) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-03 14:29:32 UTC (rev 3368) @@ -10,7 +10,7 @@ private double score; - public Allocation(String uri, int prominence, double similarity) { + public Allocation(String uri, double prominence, double similarity) { this.uri = uri; this.prominence = prominence; this.similarity = similarity; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-03 14:04:18
|
Revision: 3367 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3367&view=rev Author: lorenz_b Date: 2011-11-03 14:04:11 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Omit YAGO question in eval. Modified Paths: -------------- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-03 14:02:03 UTC (rev 3366) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2011-11-03 14:04:11 UTC (rev 3367) @@ -60,6 +60,9 @@ public class Evaluation{ + List<Integer> yagoExclusions = Arrays.asList(new Integer[]{1, 3, 6, 11, 15, 22, 23, 46}); + Map<Integer, String> evalCodes = new HashMap<Integer, String>(); + private static Logger logger = Logger.getLogger(Evaluation.class); private static String PROPERTIES_PATH = "tbsl/evaluation/evaluation.properties"; private static final boolean USE_IDEAL_TAGGER = true; @@ -95,6 +98,8 @@ prefixMap.put("res", "http://dbpedia.org/resource/"); prefixMap.put("foaf", FOAF.getURI()); prefixMap.put("yago", "http://dbpedia.org/class/yago/"); + + } public void init() throws FileNotFoundException, IOException{ @@ -312,8 +317,8 @@ String errorCode = ""; LatexWriter latex = new LatexWriter(); int i = 0; - for(Entry<Integer, String> entry : id2Question.entrySet()){//if(entry.getKey()==50)continue; - if(testID != -1 && entry.getKey() != testID)continue; + for(Entry<Integer, String> entry : id2Question.entrySet()){if(entry.getKey()==50)continue; + if((testID != -1 && entry.getKey() != testID) || (yagoExclusions.contains(entry.getKey())))continue; try { questionId = entry.getKey(); question = entry.getValue(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-03 14:02:10
|
Revision: 3366 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3366&view=rev Author: lorenz_b Date: 2011-11-03 14:02:03 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Added dbprop: hack. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.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-03 08:26:17 UTC (rev 3365) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-03 14:02:03 UTC (rev 3366) @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -17,7 +16,7 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.apache.commons.collections.SetUtils; +import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.algorithm.qtl.util.ModelGenerator; import org.dllearner.algorithm.qtl.util.ModelGenerator.Strategy; @@ -42,7 +41,6 @@ import org.dllearner.algorithm.tbsl.util.Prefixes; import org.dllearner.algorithm.tbsl.util.Similarity; import org.dllearner.algorithm.tbsl.util.SolrQueryResultStringSimilarityComparator; -import org.dllearner.algorithm.tbsl.util.StringSimilarityComparator; import org.dllearner.core.ComponentInitException; import org.dllearner.core.Oracle; import org.dllearner.core.SparqlQueryLearningAlgorithm; @@ -63,6 +61,7 @@ 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.OWL; import com.hp.hpl.jena.vocabulary.RDFS; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -571,43 +570,54 @@ } */ - private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + private void normProminenceValues(Set<Allocation> allocations){ + double min = 0; + double max = 0; + for(Allocation a : allocations){ + if(a.getProminence() < min){ + min = a.getProminence(); + } + if(a.getProminence() > max){ + max = a.getProminence(); + } + } + for(Allocation a : allocations){ + double prominence = a.getProminence()/(max-min); + a.setProminence(prominence); + } + } + + private void computeScore(Set<Allocation> allocations){ double alpha = 0.8; double beta = 1 - alpha; + + for(Allocation a : allocations){ + double score = alpha * a.getSimilarity() + beta * a.getProminence(); + a.setScore(score); + } + } + + private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + Map<Slot, Set<Allocation>> slot2Allocations = new HashMap<Slot, Set<Allocation>>(); Set<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); - Set<Allocation> allAllocations; + Set<Allocation> allocations; for(Template t : templates){ - allAllocations = new HashSet<Allocation>(); + allocations = new HashSet<Allocation>(); for(Slot slot : t.getSlots()){ - Set<Allocation> allocations = computeAllocation(slot); - allAllocations.addAll(allocations); - slot2Allocations.put(slot, allocations); - } - - int min = Integer.MAX_VALUE; - int max = Integer.MIN_VALUE; - for(Allocation a : allAllocations){ - if(a.getInDegree() < min){ - min = a.getInDegree(); - } - if(a.getInDegree() > max){ - max = a.getInDegree(); - } - } - for(Allocation a : allAllocations){ - double prominence = a.getInDegree()/(max-min); - a.setProminence(prominence); + allocations = computeAllocations(slot); - double score = alpha * a.getSimilarity() + beta * a.getProminence(); - a.setScore(score); + normProminenceValues(allocations); + computeScore(allocations); + + slot2Allocations.put(slot, allocations); } -// System.out.println(allAllocations); + Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); Query cleanQuery = t.getQuery(); queries.add(new WeightedQuery(cleanQuery)); @@ -642,11 +652,13 @@ } for(Slot slot : sortedSlots){ - if(!slot2Allocations.get(slot).isEmpty()){ + if(!slot2Allocations.get(slot).isEmpty()){System.out.println(slot2Allocations.get(slot)); 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>")){ + System.out.println("YES"); + } boolean drop = false; if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ @@ -655,33 +667,38 @@ // System.out.println(triple); for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ // System.out.println(typeTriple); - Set<String> ranges = getRanges(a.getUri()); -// System.out.println(a); - if(!ranges.isEmpty()){ - Set<String> allRanges = new HashSet<String>(); - for(String range : ranges){ - allRanges.addAll(getSuperClasses(range)); + if(isObjectProperty(a.getUri())){ + Set<String> ranges = getRanges(a.getUri()); +// System.out.println(a); + if(!ranges.isEmpty()){ + Set<String> allRanges = new HashSet<String>(); + for(String range : ranges){ + allRanges.addAll(getSuperClasses(range)); + } + allRanges.addAll(ranges); + 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); + } + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } else { +// System.out.println("DROPPING: \n" + q.toString()); + } } - allRanges.addAll(ranges); - 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/Actor") && a.getUri().equals("http://dbpedia.org/ontology/birthPlace")){ -// System.out.println("RANGES: " + allRanges); -// System.out.println("TYPES: " + allTypes); -// } - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ - drop = true; - } else { - System.out.println("DROPPING: \n" + q.toString()); - } + } else { + drop = true; } + } for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ // System.out.println(typeTriple); - Set<String> domains = getDomains(a.getUri());System.out.println(a.getUri() + ":" + domains); + Set<String> domains = getDomains(a.getUri()); // System.out.println(a); if(!domains.isEmpty()){ Set<String> allDomains = new HashSet<String>(); @@ -693,15 +710,15 @@ 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/Actor") && a.getUri().equals("http://dbpedia.org/ontology/birthPlace")){ -// 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; } else { - System.out.println("DROPPING: \n" + q.toString()); +// System.out.println("DROPPING: \n" + q.toString()); } } } @@ -762,15 +779,24 @@ } */ - private Set<Allocation> computeAllocation(Slot slot){ + private Set<Allocation> computeAllocations(Slot slot){ Set<Allocation> allocations = new HashSet<Allocation>(); SolrSearch index = getIndexBySlotType(slot); SolrQueryResultSet rs; for(String word : slot.getWords()){ - rs = index.getResourcesWithScores(word, 10);System.out.println(word + "->" + rs); - + rs = index.getResourcesWithScores(word, 10); + //for tests add the property URI with http://dbpedia.org/property/ namespace + Set<SolrQueryResultItem> tmp = new HashSet<SolrQueryResultItem>(); + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(SolrQueryResultItem i : rs.getItems()){ + String uri = "http://dbpedia.org/property/" + i.getUri().substring(i.getUri().lastIndexOf("/")+1); + tmp.add(new SolrQueryResultItem(i.getLabel(), uri)); + } + } + rs.addItems(tmp); +// System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); double similarity = Similarity.getSimilarity(word, item.getLabel()); @@ -1295,6 +1321,15 @@ return domains; } + private boolean isObjectProperty(String property){ + String query = String.format("SELECT * WHERE {<%s> a <%s>}", property, OWL.ObjectProperty.getURI()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + if(rs.hasNext()){ + return true; + } + return false; + } + private Set<String> getSuperClasses(String cls){ Set<String> superClasses = new HashSet<String>(); @@ -1325,7 +1360,8 @@ // String question = "In which programming language is GIMP written?"; // 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 actors/NNS were/VBD born/VBN in/IN Germany/NNP"; + 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 = "Give me all books written by authors influenced by Ernest Hemingway."; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-03 08:26:17 UTC (rev 3365) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-03 14:02:03 UTC (rev 3366) @@ -4,16 +4,15 @@ public class Allocation { private String uri; - private int inDegree; private double similarity; private double prominence; private double score; - public Allocation(String uri, int inDegree, double similarity) { + public Allocation(String uri, int prominence, double similarity) { this.uri = uri; - this.inDegree = inDegree; + this.prominence = prominence; this.similarity = similarity; } @@ -21,10 +20,6 @@ return uri; } - public int getInDegree() { - return inDegree; - } - public double getSimilarity() { return similarity; } @@ -47,7 +42,7 @@ @Override public String toString() { - return uri + "(similarity: " + similarity + "; prominence: " + inDegree + ")"; + return uri + "(score: " + score + "; similarity: " + similarity + "; prominence: " + prominence + ")"; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-03 08:26:23
|
Revision: 3365 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3365&view=rev Author: lorenz_b Date: 2011-11-03 08:26:17 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Continued type checking. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrQueryResultSet.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-02 22:28:33 UTC (rev 3364) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-03 08:26:17 UTC (rev 3365) @@ -667,7 +667,7 @@ 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/Film") && a.getUri().equals("http://dbpedia.org/ontology/starring")){ +// if(typeURI.equals("http://dbpedia.org/ontology/Actor") && a.getUri().equals("http://dbpedia.org/ontology/birthPlace")){ // System.out.println("RANGES: " + allRanges); // System.out.println("TYPES: " + allTypes); // } @@ -693,7 +693,7 @@ 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/Film") && a.getUri().equals("http://dbpedia.org/ontology/starring")){ +// if(typeURI.equals("http://dbpedia.org/ontology/Actor") && a.getUri().equals("http://dbpedia.org/ontology/birthPlace")){ // System.out.println("DOMAINS: " + allDomains); // System.out.println("TYPES: " + allTypes); // } @@ -769,7 +769,7 @@ SolrQueryResultSet rs; for(String word : slot.getWords()){ - rs = index.getResourcesWithScores(word, 3); + rs = index.getResourcesWithScores(word, 10);System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); @@ -1297,8 +1297,13 @@ private Set<String> getSuperClasses(String cls){ Set<String> superClasses = new HashSet<String>(); - for(Description d : reasoner.getClassHierarchy().getSuperClasses(new NamedClass(cls))){ + + for(Description d : reasoner.getClassHierarchy().getSuperClasses((new NamedClass(cls)))){ superClasses.add(((NamedClass)d).getName()); + for(Description sup : reasoner.getClassHierarchy().getSuperClasses(d)){ + superClasses.add(((NamedClass)sup).getName()); + } + } return superClasses; } @@ -1319,8 +1324,8 @@ // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); // String question = "In which programming language is GIMP written?"; // 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 = "Give/VB me/PRP all/DT soccer/NN clubs/NNS in/IN the/DT Premier/NNP League/NNP"; +// String question = "Who/WP produced/VBD the/DT most/JJS films/NNS"; + String question = "Which/WDT actors/NNS were/VBD born/VBN in/IN Germany/NNP"; // String question = "Give me all books written by authors influenced by Ernest Hemingway."; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrQueryResultSet.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrQueryResultSet.java 2011-11-02 22:28:33 UTC (rev 3364) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrQueryResultSet.java 2011-11-03 08:26:17 UTC (rev 3365) @@ -27,6 +27,9 @@ this.items.addAll(rs.getItems()); } - + @Override + public String toString() { + return items.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-02 22:28:40
|
Revision: 3364 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3364&view=rev Author: lorenz_b Date: 2011-11-02 22:28:33 +0000 (Wed, 02 Nov 2011) Log Message: ----------- Added simple type restriction to ignore invalid queries. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.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-02 19:32:53 UTC (rev 3363) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-02 22:28:33 UTC (rev 3364) @@ -200,6 +200,7 @@ modelGenenerator = new ModelGenerator(endpoint, predicateFilters); reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + reasoner.setCache(cache); reasoner.prepareSubsumptionHierarchy(); } @@ -358,6 +359,7 @@ } } + /* private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ double alpha = 0.8; double beta = 1 - alpha; @@ -417,17 +419,20 @@ if(!slot2Allocations.get(slot).isEmpty()){ for(Allocation a : slot2Allocations.get(slot)){ for(WeightedQuery query : queries){ - Query reversedQuery = new Query(query.getQuery()); - reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); //check if the query is possible if(slot.getSlotType() == SlotType.SYMPROPERTY){ + Query reversedQuery = new Query(query.getQuery()); + reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + boolean drop = false; - for(SPARQL_Triple triple : query.getQuery().getTriplesWithVar(slot.getAnchor())){ - System.out.println(triple); - for(SPARQL_Triple typeTriple : query.getQuery().getRDFTypeTriples(triple.getValue().getName())){ - System.out.println(typeTriple); + for(SPARQL_Triple triple : reversedQuery.getTriplesWithVar(slot.getAnchor())){ + String objectVar = triple.getValue().getName(); + String subjectVar = triple.getVariable().getName(); +// System.out.println(triple); + for(SPARQL_Triple typeTriple : reversedQuery.getRDFTypeTriples(objectVar)){ +// System.out.println(typeTriple); Set<String> ranges = getRanges(a.getUri()); - System.out.println(a); +// System.out.println(a); if(!ranges.isEmpty()){ Set<String> allRanges = new HashSet<String>(); for(String range : ranges){ @@ -436,14 +441,38 @@ String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); Set<String> allTypes = getSuperClasses(typeURI); allTypes.add(typeTriple.getValue().getName()); - System.out.println("RANGES: " + ranges); - System.out.println("TYPES: " + allTypes); +// System.out.println("RANGES: " + ranges); +// System.out.println("TYPES: " + allTypes); if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ drop = true; + } else { + System.out.println("DROPPING: \n" + reversedQuery.toString()); } } } + for(SPARQL_Triple typeTriple : reversedQuery.getRDFTypeTriples(subjectVar)){ +// System.out.println(typeTriple); + Set<String> domains = getDomains(a.getUri()); +// System.out.println(a); + if(!domains.isEmpty()){ + Set<String> allDomains = new HashSet<String>(); + for(String domain : domains){ + allDomains.addAll(getSuperClasses(domain)); + } + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Set<String> allTypes = getSuperClasses(typeURI); + allTypes.add(typeTriple.getValue().getName()); +// System.out.println("DOMAINS: " + domains); +// System.out.println("TYPES: " + allTypes); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ + drop = true; + } else { + System.out.println("DROPPING: \n" + reversedQuery.toString()); + } + } + } } if(!drop){ @@ -454,21 +483,245 @@ tmp.add(w); } - + } + Query q = new Query(query.getQuery()); + 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(); + String subjectVar = triple.getVariable().getName(); +// System.out.println(triple); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ +// System.out.println(typeTriple); + Set<String> ranges = getRanges(a.getUri()); +// System.out.println(a); + if(!ranges.isEmpty()){ + Set<String> allRanges = new HashSet<String>(); + for(String range : ranges){ + allRanges.addAll(getSuperClasses(range)); + } + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Set<String> allTypes = getSuperClasses(typeURI); + allTypes.add(typeTriple.getValue().getName()); +// System.out.println("RANGES: " + ranges); +// System.out.println("TYPES: " + allTypes); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } else { + System.out.println("DROPPING: \n" + q.toString()); + } + } + } + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ +// System.out.println(typeTriple); + Set<String> domains = getDomains(a.getUri()); +// System.out.println(a); + if(!domains.isEmpty()){ + Set<String> allDomains = new HashSet<String>(); + for(String domain : domains){ + allDomains.addAll(getSuperClasses(domain)); + } + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Set<String> allTypes = getSuperClasses(typeURI); + allTypes.add(typeTriple.getValue().getName()); +// System.out.println("DOMAINS: " + domains); +// System.out.println("TYPES: " + allTypes); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ + drop = true; + } else { + System.out.println("DROPPING: \n" + q.toString()); + } + } + } + } + } - } + + if(!drop){ + 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);System.out.println(tmp); + tmp.clear(); + } + + } + for(WeightedQuery q : queries){ + q.setScore(q.getScore()/t.getSlots().size()); + } + allQueries.addAll(queries); + List<Query> qList = new ArrayList<Query>(); + for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); + qList.add(wQ.getQuery()); + } + template2Queries.put(t, qList); + } + return allQueries; + } + */ + + private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + double alpha = 0.8; + double beta = 1 - alpha; + Map<Slot, Set<Allocation>> slot2Allocations = new HashMap<Slot, Set<Allocation>>(); + + Set<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); + + Set<Allocation> allAllocations; + for(Template t : templates){ + allAllocations = new HashSet<Allocation>(); + + for(Slot slot : t.getSlots()){ + Set<Allocation> allocations = computeAllocation(slot); + allAllocations.addAll(allocations); + slot2Allocations.put(slot, allocations); + } + + int min = Integer.MAX_VALUE; + int max = Integer.MIN_VALUE; + for(Allocation a : allAllocations){ + if(a.getInDegree() < min){ + min = a.getInDegree(); + } + if(a.getInDegree() > max){ + max = a.getInDegree(); + } + } + for(Allocation a : allAllocations){ + double prominence = a.getInDegree()/(max-min); + a.setProminence(prominence); + + double score = alpha * a.getSimilarity() + beta * a.getProminence(); + a.setScore(score); + + } +// System.out.println(allAllocations); + + Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); + Query cleanQuery = t.getQuery(); + queries.add(new WeightedQuery(cleanQuery)); + + Set<WeightedQuery> tmp = new HashSet<WeightedQuery>(); + List<Slot> sortedSlots = new ArrayList<Slot>(); + Set<Slot> classSlots = new HashSet<Slot>(); + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.CLASS){ + sortedSlots.add(slot); + classSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ + if(!sortedSlots.contains(slot)){ + sortedSlots.add(slot); + } + } + //add for each SYMPROPERTY Slot the reversed query + for(Slot slot : sortedSlots){ + for(WeightedQuery wQ : queries){ + if(slot.getSlotType() == SlotType.SYMPROPERTY){ + Query reversedQuery = new Query(wQ.getQuery()); + reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + tmp.add(new WeightedQuery(reversedQuery)); + } + tmp.add(wQ); + } + queries.clear(); + queries.addAll(tmp); + tmp.clear(); + } + + for(Slot slot : sortedSlots){ + if(!slot2Allocations.get(slot).isEmpty()){ + for(Allocation a : slot2Allocations.get(slot)){ + for(WeightedQuery query : queries){ 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); + + 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(); + String subjectVar = triple.getVariable().getName(); +// System.out.println(triple); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ +// System.out.println(typeTriple); + Set<String> ranges = getRanges(a.getUri()); +// System.out.println(a); + if(!ranges.isEmpty()){ + Set<String> allRanges = new HashSet<String>(); + for(String range : ranges){ + allRanges.addAll(getSuperClasses(range)); + } + allRanges.addAll(ranges); + 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/Film") && a.getUri().equals("http://dbpedia.org/ontology/starring")){ +// System.out.println("RANGES: " + allRanges); +// System.out.println("TYPES: " + allTypes); +// } + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } else { + System.out.println("DROPPING: \n" + q.toString()); + } + } + } + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ +// System.out.println(typeTriple); + Set<String> domains = getDomains(a.getUri());System.out.println(a.getUri() + ":" + domains); +// System.out.println(a); + if(!domains.isEmpty()){ + Set<String> allDomains = new HashSet<String>(); + for(String domain : domains){ + allDomains.addAll(getSuperClasses(domain)); + } + allDomains.addAll(domains); + allDomains.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/Film") && a.getUri().equals("http://dbpedia.org/ontology/starring")){ +// System.out.println("DOMAINS: " + allDomains); +// System.out.println("TYPES: " + allTypes); +// } + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ + drop = true; + } else { + System.out.println("DROPPING: \n" + q.toString()); + } + } + } + } + } + + + if(!drop){ + 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); + queries.addAll(tmp);//System.out.println(tmp); tmp.clear(); } @@ -478,7 +731,7 @@ } allQueries.addAll(queries); List<Query> qList = new ArrayList<Query>(); - for(WeightedQuery wQ : queries){ + for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); qList.add(wQ.getQuery()); } template2Queries.put(t, qList); @@ -516,7 +769,7 @@ SolrQueryResultSet rs; for(String word : slot.getWords()){ - rs = index.getResourcesWithScores(word, 10); + rs = index.getResourcesWithScores(word, 3); for(SolrQueryResultItem item : rs.getItems()){ int prominence = getProminenceValue(item.getUri(), slot.getSlotType()); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-02 19:32:53 UTC (rev 3363) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Allocation.java 2011-11-02 22:28:33 UTC (rev 3364) @@ -49,6 +49,36 @@ public String toString() { return uri + "(similarity: " + similarity + "; prominence: " + inDegree + ")"; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(score); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Allocation other = (Allocation) obj; + if (Double.doubleToLongBits(score) != Double.doubleToLongBits(other.score)) + return false; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-02 19:33:00
|
Revision: 3363 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3363&view=rev Author: jenslehmann Date: 2011-11-02 19:32:53 +0000 (Wed, 02 Nov 2011) Log Message: ----------- cross validation for the new command line interface Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java Added Paths: ----------- trunk/examples/cross-validation/ trunk/examples/cross-validation/father.conf trunk/examples/cross-validation/father.owl trunk/examples/cross-validation/father.xml trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java Added: trunk/examples/cross-validation/father.conf =================================================================== --- trunk/examples/cross-validation/father.conf (rev 0) +++ trunk/examples/cross-validation/father.conf 2011-11-02 19:32:53 UTC (rev 3363) @@ -0,0 +1,33 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +// perform cross validation +cli.type = "org.dllearner.cli.CLI" +cli.writeSpringConfiguration = true +cli.performCrossValidation = true +cli.nrOfFolds = 3 + +// declare some prefixes to use as abbreviations +prefixes = [ ("ex","http://example.com/father#") ] + +// knowledge source definition +ks.type = "OWL File" +ks.fileName = "father.owl" + +// reasoner +reasoner.type = "fast instance checker" +reasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = { "ex:stefan", "ex:markus", "ex:martin" } +lp.negativeExamples = { "ex:heinz", "ex:anna", "ex:michelle" } + +// create learning algorithm to run +alg.type = "ocel" Added: trunk/examples/cross-validation/father.owl =================================================================== --- trunk/examples/cross-validation/father.owl (rev 0) +++ trunk/examples/cross-validation/father.owl 2011-11-02 19:32:53 UTC (rev 3363) @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns="http://example.com/father#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xml:base="http://example.com/father"> + <owl:Ontology rdf:about=""/> + <owl:Class rdf:ID="female"/> + <owl:Class rdf:ID="male"> + <owl:equivalentClass> + <owl:Class> + <owl:complementOf rdf:resource="#female"/> + </owl:Class> + </owl:equivalentClass> + </owl:Class> + <owl:ObjectProperty rdf:ID="hasChild"/> + <male rdf:ID="markus"> + <hasChild> + <female rdf:ID="anna"> + <hasChild> + <male rdf:ID="heinz"/> + </hasChild> + </female> + </hasChild> + </male> + <male rdf:ID="stefan"> + <hasChild rdf:resource="#markus"/> + </male> + <female rdf:ID="michelle"/> + <male rdf:ID="martin"> + <hasChild rdf:resource="#heinz"/> + </male> +</rdf:RDF> Added: trunk/examples/cross-validation/father.xml =================================================================== --- trunk/examples/cross-validation/father.xml (rev 0) +++ trunk/examples/cross-validation/father.xml 2011-11-02 19:32:53 UTC (rev 3363) @@ -0,0 +1,32 @@ +<beans xmlns="http://www.springframework.org/schema/beans"> + <bean class="org.dllearner.algorithms.ocel.OCEL" name="alg"/> + <bean class="org.dllearner.kb.OWLFile" name="ks"> + <property name="fileName" value="father.owl"/> + </bean> + <bean class="org.dllearner.learningproblems.PosNegLPStandard" name="lp"> + <property name="positiveExamples"> + <set> + <value>http://example.com/father#markus</value> + <value>http://example.com/father#stefan</value> + <value>http://example.com/father#martin</value> + </set> + </property> + <property name="negativeExamples"> + <set> + <value>http://example.com/father#heinz</value> + <value>http://example.com/father#anna</value> + <value>http://example.com/father#michelle</value> + </set> + </property> + </bean> + <bean class="org.dllearner.cli.CLI" name="cli"> + <property name="writeSpringConfiguration"/> + </bean> + <bean class="org.dllearner.reasoning.FastInstanceChecker" name="reasoner"> + <property name="sources"> + <set> + <ref bean="ks"/> + </set> + </property> + </bean> +</beans> \ No newline at end of file Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-02 14:37:35 UTC (rev 3362) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-11-02 19:32:53 UTC (rev 3363) @@ -38,8 +38,10 @@ import org.dllearner.confparser3.ConfParserConfiguration; import org.dllearner.confparser3.ParseException; import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Files; import org.springframework.context.ApplicationContext; import org.springframework.core.io.FileSystemResource; @@ -57,59 +59,65 @@ private static Logger logger = Logger.getLogger(CLI.class); private static Logger rootLogger = Logger.getRootLogger(); - private boolean writeSpringConfiguration = false; private ApplicationContext context; + private File confFile; - public CLI(File file) throws IOException{ - Resource confFile = new FileSystemResource(file); + // some CLI options + private boolean writeSpringConfiguration = false; + private boolean performCrossValidation = false; + private int nrOfFolds = 10; + + public CLI() { - List<Resource> springConfigResources = new ArrayList<Resource>(); + } + + public CLI(File confFile) { + this(); + this.confFile = confFile; + } + + public void run() throws IOException { // ApplicationContext context, String algorithmBeanName){ + + IConfiguration configuration = null; + + if(context == null) { + Resource confFileR = new FileSystemResource(confFile); + List<Resource> springConfigResources = new ArrayList<Resource>(); + configuration = new ConfParserConfiguration(confFileR); - //DL-Learner Configuration Object - IConfiguration configuration = new ConfParserConfiguration(confFile); - - ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); - context = builder.buildApplicationContext(configuration,springConfigResources); - - // a lot of debugging stuff -// FastInstanceChecker fi = context.getBean("reasoner", FastInstanceChecker.class); -// System.out.println(fi.getClassHierarchy()); -// NamedClass male = new NamedClass("http://localhost/foo#male"); -// System.out.println(fi.getIndividuals(new NamedClass("http://localhost/foo#male"))); -// System.out.println(fi.getIndividuals().size()); -// System.out.println("has type: " + fi.hasTypeImpl(male, new Individual("http://localhost/foo#bernd"))); -// -// PosNegLPStandard lp = context.getBean("lp", PosNegLPStandard.class); -// System.out.println(lp.getPositiveExamples()); -// System.out.println(lp.getNegativeExamples()); -// System.out.println(lp.getAccuracy(new NamedClass("http://localhost/foo#male"))); - - // get a CLI bean if it exists - CLI cli = null; - if(context.getBeansOfType(CLI.class).size()>0) { - System.out.println(); - cli = context.getBean(CLI.class); + ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); + ApplicationContext context = builder.buildApplicationContext(configuration,springConfigResources); + } + + if(writeSpringConfiguration) { SpringConfigurationXMLBeanConverter converter = new SpringConfigurationXMLBeanConverter(); - XmlObject xml = converter.convert(configuration); - String springFilename = file.getCanonicalPath().replace(".conf", ".xml"); + XmlObject xml; + if(configuration == null) { + Resource confFileR = new FileSystemResource(confFile); + configuration = new ConfParserConfiguration(confFileR); + xml = converter.convert(configuration); + } else { + xml = converter.convert(configuration); + } + String springFilename = confFile.getCanonicalPath().replace(".conf", ".xml"); File springFile = new File(springFilename); if(springFile.exists()) { logger.warn("Cannot write Spring configuration, because " + springFilename + " already exists."); } else { Files.createFile(springFile, xml.toString()); - } -// SpringConfigurationXMLBeanConverter converter; - } - - // start algorithm in conf file -// LearningAlgorithm algorithm = context.getBean("alg",LearningAlgorithm.class); -// algorithm.start(); - } + } + } + + if(performCrossValidation) { + AbstractReasonerComponent rs = context.getBean(AbstractReasonerComponent.class); + PosNegLP lp = context.getBean(PosNegLP.class); + AbstractCELA la = context.getBean(AbstractCELA.class); + new CrossValidation(la,lp,rs,nrOfFolds,false); + } else { + LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); + algorithm.start(); + } - public void run() { // ApplicationContext context, String algorithmBeanName){ - LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); -// LearningAlgorithm algorithm = context.getBean(algorithmBeanName, LearningAlgorithm.class); - algorithm.start(); } public boolean isWriteSpringConfiguration() { @@ -150,12 +158,61 @@ System.exit(0); } - CLI cli = new CLI(file); + Resource confFile = new FileSystemResource(file); + + List<Resource> springConfigResources = new ArrayList<Resource>(); + + //DL-Learner Configuration Object + IConfiguration configuration = new ConfParserConfiguration(confFile); + + ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); + ApplicationContext context = builder.buildApplicationContext(configuration,springConfigResources); + + // TODO: later we could check which command line interface is specified in the conf file + // for now we just use the default one + + CLI cli; + if(context.containsBean("cli")) { + cli = (CLI) context.getBean("cli"); + } else { + cli = new CLI(); + } + cli.setContext(context); + cli.setConfFile(file); cli.run(); + } + public void setContext(ApplicationContext context) { + this.context = context; + } + public ApplicationContext getContext() { return context; } + public File getConfFile() { + return confFile; + } + + public void setConfFile(File confFile) { + this.confFile = confFile; + } + + public boolean isPerformCrossValidation() { + return performCrossValidation; + } + + public void setPerformCrossValidation(boolean performCrossValiation) { + this.performCrossValidation = performCrossValiation; + } + + public int getNrOfFolds() { + return nrOfFolds; + } + + public void setNrOfFolds(int nrOfFolds) { + this.nrOfFolds = nrOfFolds; + } + } Added: trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2011-11-02 19:32:53 UTC (rev 3363) @@ -0,0 +1,286 @@ +/** + * 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.cli; + +import java.io.File; +import java.io.FileNotFoundException; +import java.text.DecimalFormat; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.Heuristics; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.statistics.Stat; +import org.dllearner.utilities.Files; + +/** + * Performs cross validation for the given problem. Supports + * k-fold cross-validation and leave-one-out cross-validation. + * + * @author Jens Lehmann + * + */ +public class CrossValidation { + + private static Logger logger = Logger.getRootLogger(); + + // statistical values + private Stat runtime = new Stat(); + private Stat accuracy = new Stat(); + private Stat length = new Stat(); + private Stat accuracyTraining = new Stat(); + private Stat fMeasure = new Stat(); + private Stat fMeasureTraining = new Stat(); + private static boolean writeToFile = false; + private static File outputFile; + + public CrossValidation(AbstractCELA la, PosNegLP lp, AbstractReasonerComponent rs, int folds, boolean leaveOneOut) { + + DecimalFormat df = new DecimalFormat(); + + // the training and test sets used later on + List<Set<Individual>> trainingSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> trainingSetsNeg = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); + + // get examples and shuffle them too + Set<Individual> posExamples = ((PosNegLP)lp).getPositiveExamples(); + List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); + Collections.shuffle(posExamplesList, new Random(1)); + Set<Individual> negExamples = ((PosNegLP)lp).getNegativeExamples(); + List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); + Collections.shuffle(negExamplesList, new Random(2)); + + // sanity check whether nr. of folds makes sense for this benchmark + if(!leaveOneOut && (posExamples.size()<folds && negExamples.size()<folds)) { + System.out.println("The number of folds is higher than the number of " + + "positive/negative examples. This can result in empty test sets. Exiting."); + System.exit(0); + } + + if(leaveOneOut) { + // note that leave-one-out is not identical to k-fold with + // k = nr. of examples in the current implementation, because + // with n folds and n examples there is no guarantee that a fold + // is never empty (this is an implementation issue) + int nrOfExamples = posExamples.size() + negExamples.size(); + for(int i = 0; i < nrOfExamples; i++) { + // ... + } + System.out.println("Leave-one-out not supported yet."); + System.exit(1); + } else { + // calculating where to split the sets, ; note that we split + // positive and negative examples separately such that the + // distribution of positive and negative examples remains similar + // (note that there are better but more complex ways to implement this, + // which guarantee that the sum of the elements of a fold for pos + // and neg differs by at most 1 - it can differ by 2 in our implementation, + // e.g. with 3 folds, 4 pos. examples, 4 neg. examples) + int[] splitsPos = calculateSplits(posExamples.size(),folds); + int[] splitsNeg = calculateSplits(negExamples.size(),folds); + +// System.out.println(splitsPos[0]); +// System.out.println(splitsNeg[0]); + + // calculating training and test sets + for(int i=0; i<folds; i++) { + Set<Individual> testPos = getTestingSet(posExamplesList, splitsPos, i); + Set<Individual> testNeg = getTestingSet(negExamplesList, splitsNeg, i); + testSetsPos.add(i, testPos); + testSetsNeg.add(i, testNeg); + trainingSetsPos.add(i, getTrainingSet(posExamples, testPos)); + trainingSetsNeg.add(i, getTrainingSet(negExamples, testNeg)); + } + + } + + // run the algorithm + for(int currFold=0; currFold<folds; currFold++) { + + Set<String> pos = Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); + Set<String> neg = Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); + lp.setPositiveExamples(trainingSetsPos.get(currFold)); + lp.setNegativeExamples(trainingSetsNeg.get(currFold)); + + try { + lp.init(); + la.init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + long algorithmStartTime = System.nanoTime(); + la.start(); + long algorithmDuration = System.nanoTime() - algorithmStartTime; + runtime.addNumber(algorithmDuration/(double)1000000000); + + Description concept = la.getCurrentlyBestDescription(); + + Set<Individual> tmp = rs.hasType(concept, testSetsPos.get(currFold)); + Set<Individual> tmp2 = Helper.difference(testSetsPos.get(currFold), tmp); + Set<Individual> tmp3 = rs.hasType(concept, testSetsNeg.get(currFold)); + + outputWriter("test set errors pos: " + tmp2); + outputWriter("test set errors neg: " + tmp3); + + // calculate training accuracies + int trainingCorrectPosClassified = getCorrectPosClassified(rs, concept, trainingSetsPos.get(currFold)); + int trainingCorrectNegClassified = getCorrectNegClassified(rs, concept, trainingSetsNeg.get(currFold)); + int trainingCorrectExamples = trainingCorrectPosClassified + trainingCorrectNegClassified; + double trainingAccuracy = 100*((double)trainingCorrectExamples/(trainingSetsPos.get(currFold).size()+ + trainingSetsNeg.get(currFold).size())); + accuracyTraining.addNumber(trainingAccuracy); + // calculate test accuracies + int correctPosClassified = getCorrectPosClassified(rs, concept, testSetsPos.get(currFold)); + int correctNegClassified = getCorrectNegClassified(rs, concept, testSetsNeg.get(currFold)); + int correctExamples = correctPosClassified + correctNegClassified; + double currAccuracy = 100*((double)correctExamples/(testSetsPos.get(currFold).size()+ + testSetsNeg.get(currFold).size())); + accuracy.addNumber(currAccuracy); + // calculate training F-Score + int negAsPosTraining = rs.hasType(concept, trainingSetsNeg.get(currFold)).size(); + double precisionTraining = trainingCorrectPosClassified + negAsPosTraining == 0 ? 0 : trainingCorrectPosClassified / (double) (trainingCorrectPosClassified + negAsPosTraining); + double recallTraining = trainingCorrectPosClassified / (double) trainingSetsPos.get(currFold).size(); + fMeasureTraining.addNumber(100*Heuristics.getFScore(recallTraining, precisionTraining)); + // calculate test F-Score + int negAsPos = rs.hasType(concept, testSetsNeg.get(currFold)).size(); + double precision = correctPosClassified + negAsPos == 0 ? 0 : correctPosClassified / (double) (correctPosClassified + negAsPos); + double recall = correctPosClassified / (double) testSetsPos.get(currFold).size(); +// System.out.println(precision);System.out.println(recall); + fMeasure.addNumber(100*Heuristics.getFScore(recall, precision)); + + length.addNumber(concept.getLength()); + + outputWriter("fold " + currFold + ":"); + outputWriter(" training: " + pos.size() + " positive and " + neg.size() + " negative examples"); + outputWriter(" testing: " + correctPosClassified + "/" + testSetsPos.get(currFold).size() + " correct positives, " + + correctNegClassified + "/" + testSetsNeg.get(currFold).size() + " correct negatives"); + outputWriter(" concept: " + concept); + outputWriter(" accuracy: " + df.format(currAccuracy) + "% (" + df.format(trainingAccuracy) + "% on training set)"); + outputWriter(" length: " + df.format(concept.getLength())); + outputWriter(" runtime: " + df.format(algorithmDuration/(double)1000000000) + "s"); + + } + + outputWriter(""); + outputWriter("Finished " + folds + "-folds cross-validation."); + outputWriter("runtime: " + statOutput(df, runtime, "s")); + outputWriter("length: " + statOutput(df, length, "")); + outputWriter("F-Measure on training set: " + statOutput(df, fMeasureTraining, "%")); + outputWriter("F-Measure: " + statOutput(df, fMeasure, "%")); + outputWriter("predictive accuracy on training set: " + statOutput(df, accuracyTraining, "%")); + outputWriter("predictive accuracy: " + statOutput(df, accuracy, "%")); + + } + + private int getCorrectPosClassified(AbstractReasonerComponent rs, Description concept, Set<Individual> testSetPos) { + return rs.hasType(concept, testSetPos).size(); + } + + private int getCorrectNegClassified(AbstractReasonerComponent rs, Description concept, Set<Individual> testSetNeg) { + return testSetNeg.size() - rs.hasType(concept, testSetNeg).size(); + } + + public static Set<Individual> getTestingSet(List<Individual> examples, int[] splits, int fold) { + int fromIndex; + // we either start from 0 or after the last fold ended + if(fold == 0) + fromIndex = 0; + else + fromIndex = splits[fold-1]; + // the split corresponds to the ends of the folds + int toIndex = splits[fold]; + +// System.out.println("from " + fromIndex + " to " + toIndex); + + Set<Individual> testingSet = new HashSet<Individual>(); + // +1 because 2nd element is exclusive in subList method + testingSet.addAll(examples.subList(fromIndex, toIndex)); + return testingSet; + } + + public static Set<Individual> getTrainingSet(Set<Individual> examples, Set<Individual> testingSet) { + return Helper.difference(examples, testingSet); + } + + // takes nr. of examples and the nr. of folds for this examples; + // returns an array which says where each fold ends, i.e. + // splits[i] is the index of the last element of fold i in the examples + public static int[] calculateSplits(int nrOfExamples, int folds) { + int[] splits = new int[folds]; + for(int i=1; i<=folds; i++) { + // we always round up to the next integer + splits[i-1] = (int)Math.ceil(i*nrOfExamples/(double)folds); + } + return splits; + } + + public static String statOutput(DecimalFormat df, Stat stat, String unit) { + String str = "av. " + df.format(stat.getMean()) + unit; + str += " (deviation " + df.format(stat.getStandardDeviation()) + unit + "; "; + str += "min " + df.format(stat.getMin()) + unit + "; "; + str += "max " + df.format(stat.getMax()) + unit + ")"; + return str; + } + + public Stat getAccuracy() { + return accuracy; + } + + public Stat getLength() { + return length; + } + + public Stat getRuntime() { + return runtime; + } + + private void outputWriter(String output) { + if(writeToFile) { + Files.appendFile(outputFile, output +"\n"); + System.out.println(output); + } else { + System.out.println(output); + } + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-02 14:37:45
|
Revision: 3362 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3362&view=rev Author: lorenz_b Date: 2011-11-02 14:37:35 +0000 (Wed, 02 Nov 2011) Log Message: ----------- Changed handling of count results with value 0. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.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/WeightedQuery.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-02 14:07:30 UTC (rev 3361) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2011-11-02 14:37:35 UTC (rev 3362) @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -16,6 +17,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.commons.collections.SetUtils; import org.apache.log4j.Logger; import org.dllearner.algorithm.qtl.util.ModelGenerator; import org.dllearner.algorithm.qtl.util.ModelGenerator.Strategy; @@ -31,6 +33,7 @@ import org.dllearner.algorithm.tbsl.sparql.RatedQuery; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Prefix; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; +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; @@ -43,9 +46,13 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.Oracle; import org.dllearner.core.SparqlQueryLearningAlgorithm; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.reasoning.SPARQLReasoner; import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; @@ -56,6 +63,7 @@ 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.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -109,6 +117,8 @@ private Lemmatizer lemmatizer = new LingPipeLemmatizer();// StanfordLemmatizer(); + private SPARQLReasoner reasoner; + public SPARQLTemplateBasedLearner() throws InvalidFileFormatException, FileNotFoundException, IOException{ this(OPTIONS_FILE); } @@ -188,6 +198,9 @@ predicateFilters.add("http://dbpedia.org/ontology/wikiPageWikiLink"); predicateFilters.add("http://dbpedia.org/property/wikiPageUsesTemplate"); modelGenenerator = new ModelGenerator(endpoint, predicateFilters); + + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + reasoner.prepareSubsumptionHierarchy(); } public void setQuestion(String question){ @@ -251,7 +264,7 @@ Set<WeightedQuery> weightedQueries = getWeightedSPARQLQueries(templates); sparqlQueryCandidates = new ArrayList<Query>(); int i = 0; - for(WeightedQuery wQ : weightedQueries){ + for(WeightedQuery wQ : weightedQueries){System.out.println(wQ); sparqlQueryCandidates.add(wQ.getQuery()); if(i == maxTestedQueries){ break; @@ -346,7 +359,7 @@ } private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ - double alpha = 0.7; + double alpha = 0.8; double beta = 1 - alpha; Map<Slot, Set<Allocation>> slot2Allocations = new HashMap<Slot, Set<Allocation>>(); @@ -355,6 +368,7 @@ Set<Allocation> allAllocations; for(Template t : templates){ allAllocations = new HashSet<Allocation>(); + for(Slot slot : t.getSlots()){ Set<Allocation> allocations = computeAllocation(slot); allAllocations.addAll(allocations); @@ -386,25 +400,71 @@ queries.add(new WeightedQuery(cleanQuery)); Set<WeightedQuery> tmp = new HashSet<WeightedQuery>(); + List<Slot> sortedSlots = new ArrayList<Slot>(); + Set<Slot> classSlots = new HashSet<Slot>(); for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.CLASS){ + sortedSlots.add(slot); + classSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ + if(!sortedSlots.contains(slot)){ + sortedSlots.add(slot); + } + } + for(Slot slot : sortedSlots){ 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); + //check if the query is possible + if(slot.getSlotType() == SlotType.SYMPROPERTY){ + boolean drop = false; + for(SPARQL_Triple triple : query.getQuery().getTriplesWithVar(slot.getAnchor())){ + System.out.println(triple); + for(SPARQL_Triple typeTriple : query.getQuery().getRDFTypeTriples(triple.getValue().getName())){ + System.out.println(typeTriple); + Set<String> ranges = getRanges(a.getUri()); + System.out.println(a); + if(!ranges.isEmpty()){ + Set<String> allRanges = new HashSet<String>(); + for(String range : ranges){ + allRanges.addAll(getSuperClasses(range)); + } + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Set<String> allTypes = getSuperClasses(typeURI); + allTypes.add(typeTriple.getValue().getName()); + System.out.println("RANGES: " + ranges); + System.out.println("TYPES: " + allTypes); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } + } + } + } + + if(!drop){ + 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(); @@ -425,6 +485,29 @@ } return allQueries; } + +/* + * for(SPARQL_Triple triple : t.getQuery().getTriplesWithVar(slot.getAnchor())){System.out.println(triple); + for(SPARQL_Triple typeTriple : t.getQuery().getRDFTypeTriples(triple.getVariable().getName())){ + System.out.println(typeTriple); + for(Allocation a : allocations){ + Set<String> domains = getDomains(a.getUri()); + System.out.println(a); + System.out.println(domains); + for(Slot s : classSlots){ + if(s.getAnchor().equals(triple.getVariable().getName())){ + for(Allocation all : slot2Allocations.get(s)){ + if(!domains.contains(all.getUri())){ + System.out.println("DROP " + a); + } + } + } + } + } + + + } + */ private Set<Allocation> computeAllocation(Slot slot){ Set<Allocation> allocations = new HashSet<Allocation>(); @@ -829,10 +912,21 @@ logger.info("Testing query:\n" + query); List<String> results = getResultFromRemoteEndpoint(query); if(!results.isEmpty()){ - learnedSPARQLQueries.put(query, results); - if(stopIfQueryResultNotEmpty){ - return; + try{ + int cnt = Integer.parseInt(results.get(0)); + if(cnt > 0){ + learnedSPARQLQueries.put(query, results); + if(stopIfQueryResultNotEmpty){ + return; + } + } + } catch (NumberFormatException e){ + learnedSPARQLQueries.put(query, results); + if(stopIfQueryResultNotEmpty){ + return; + } } + } logger.info("Result: " + results); } @@ -884,7 +978,7 @@ logger.info("Done in " + mon.getLastValue() + "ms."); } - private List<String> getResultFromRemoteEndpoint(String query){System.out.println(query); + private List<String> getResultFromRemoteEndpoint(String query){ List<String> resources = new ArrayList<String>(); try { String queryString = query; @@ -897,7 +991,12 @@ while(rs.hasNext()){ qs = rs.next(); projectionVar = qs.varNames().next(); - resources.add(qs.get(projectionVar).toString()); + if(qs.get(projectionVar).isLiteral()){ + resources.add(qs.get(projectionVar).asLiteral().getLexicalForm()); + } else if(qs.get(projectionVar).isURIResource()){ + resources.add(qs.get(projectionVar).asResource().getURI()); + } + } } catch (Exception e) { logger.error("Query execution failed.", e); @@ -917,8 +1016,42 @@ return resources; } + private Set<String> getDomains(String property){ + Set<String> domains = new HashSet<String>(); + String query = String.format("SELECT ?domain WHERE {<%s> <%s> ?domain}", property, RDFS.domain.getURI()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + domains.add(qs.getResource("domain").getURI()); + } + + return domains; + } + private Set<String> getRanges(String property){ + Set<String> domains = new HashSet<String>(); + String query = String.format("SELECT ?range WHERE {<%s> <%s> ?range}", property, RDFS.range.getURI()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + domains.add(qs.getResource("range").getURI()); + } + + return domains; + } + private Set<String> getSuperClasses(String cls){ + Set<String> superClasses = new HashSet<String>(); + for(Description d : reasoner.getClassHierarchy().getSuperClasses(new NamedClass(cls))){ + superClasses.add(((NamedClass)d).getName()); + } + return superClasses; + } + + + /** * @param args @@ -932,7 +1065,9 @@ // Logger.getLogger(HttpClient.class).setLevel(Level.OFF); // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); // 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 = "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 = "Give/VB me/PRP all/DT soccer/NN clubs/NNS in/IN the/DT Premier/NNP League/NNP"; // String question = "Give me all books written by authors influenced by Ernest Hemingway."; SPARQLTemplateBasedLearner learner = new SPARQLTemplateBasedLearner();learner.setUseIdealTagger(true); 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 2011-11-02 14:07:30 UTC (rev 3361) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2011-11-02 14:37:35 UTC (rev 3362) @@ -423,6 +423,28 @@ } return triples; } + + public List<SPARQL_Triple> getRDFTypeTriples(){ + List<SPARQL_Triple> triples = new ArrayList<SPARQL_Triple>(); + + for(SPARQL_Triple triple : conditions){ + if(triple.getProperty().equals("rdf:type")){ + triples.add(triple); + } + } + return triples; + } + + public List<SPARQL_Triple> getRDFTypeTriples(String var){ + List<SPARQL_Triple> triples = new ArrayList<SPARQL_Triple>(); + + for(SPARQL_Triple triple : conditions){ + if(triple.getProperty().toString().equals("rdf:type") && triple.getVariable().getName().equals(var)){ + triples.add(triple); + } + } + return triples; + } @Override public int hashCode() { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/WeightedQuery.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/WeightedQuery.java 2011-11-02 14:07:30 UTC (rev 3361) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/WeightedQuery.java 2011-11-02 14:37:35 UTC (rev 3362) @@ -33,7 +33,16 @@ return -1; } else if(o.getScore() > this.score){ return 1; - } else return query.toString().compareTo(o.getQuery().toString()); + } else { + int filter = Boolean.valueOf(query.getFilters().isEmpty()).compareTo(Boolean.valueOf(o.getQuery().getFilters().isEmpty())); + if(filter == 0){ + return query.toString().compareTo(o.getQuery().toString()); + } else { + return filter; + } + } + + } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-02 14:07:37
|
Revision: 3361 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3361&view=rev Author: jenslehmann Date: 2011-11-02 14:07:30 +0000 (Wed, 02 Nov 2011) Log Message: ----------- - fixed a difficult to find bug in the refinement operator for string datatypes (related to an optimisation using property ranges) - added support for single quoted strings in manchester parser (allows to use strings in conf files) Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-02 14:07:30 UTC (rev 3361) @@ -453,7 +453,7 @@ // for(Description refinement : refinements) { // System.out.println("refinement: " + refinement); // } -// if(loop % 100 == 0) { +// if((loop+1) % 500 == 0) { // System.out.println(getMinimumHorizontalExpansion() + " - " + getMaximumHorizontalExpansion()); // System.exit(0); // } Modified: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-11-02 14:07:30 UTC (rev 3361) @@ -190,11 +190,6 @@ finally { jj_save(5, xla); } } - private boolean jj_3R_3() { - if (jj_scan_token(STRING)) return true; - return false; - } - private boolean jj_3R_8() { if (jj_scan_token(21)) return true; if (jj_3R_2()) return true; @@ -366,6 +361,11 @@ return false; } + private boolean jj_3R_3() { + if (jj_scan_token(STRING)) return true; + return false; + } + /** Generated Token Manager. */ public ManchesterSyntaxParserTokenManager token_source; SimpleCharStream jj_input_stream; Modified: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java 2011-11-02 14:07:30 UTC (rev 3361) @@ -18,11 +18,11 @@ { case 0: if ((active0 & 0x40000L) != 0L) - return 31; + return 34; return -1; case 1: if ((active0 & 0x40000L) != 0L) - return 31; + return 34; return -1; default : return -1; @@ -83,7 +83,7 @@ if ((active0 & 0x20000L) != 0L) return jjStopAtPos(1, 17); else if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(1, 18, 31); + return jjStartNfaWithStates_0(1, 18, 34); break; case 79: return jjMoveStringLiteralDfa2_0(active0, 0xc00L); @@ -220,7 +220,7 @@ private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 31; + jjnewStateCnt = 34; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -235,15 +235,6 @@ { switch(jjstateSet[--i]) { - case 31: - if ((0xbfffffffffffdbffL & l) != 0L) - jjCheckNAddTwoStates(4, 5); - else if (curChar == 62) - { - if (kind > 20) - kind = 20; - } - break; case 0: if ((0x3fe000000000000L & l) != 0L) { @@ -255,15 +246,26 @@ { if (kind > 8) kind = 8; - jjCheckNAdd(28); + jjCheckNAdd(31); } else if (curChar == 47) jjAddStates(3, 5); else if (curChar == 60) + jjCheckNAddTwoStates(7, 8); + else if (curChar == 39) jjCheckNAddTwoStates(4, 5); else if (curChar == 34) jjCheckNAddTwoStates(1, 2); break; + case 34: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(7, 8); + else if (curChar == 62) + { + if (kind > 20) + kind = 20; + } + break; case 1: if ((0xfffffffbffffdbffL & l) != 0L) jjCheckNAddTwoStates(1, 2); @@ -273,131 +275,143 @@ kind = 19; break; case 3: - if (curChar == 60) + if (curChar == 39) jjCheckNAddTwoStates(4, 5); break; case 4: - if ((0xbfffffffffffdbffL & l) != 0L) + if ((0xfffffffbffffdbffL & l) != 0L) jjCheckNAddTwoStates(4, 5); break; case 5: + if (curChar == 39 && kind > 19) + kind = 19; + break; + case 6: + if (curChar == 60) + jjCheckNAddTwoStates(7, 8); + break; + case 7: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(7, 8); + break; + case 8: if (curChar == 62 && kind > 20) kind = 20; break; - case 6: + case 9: if (curChar == 47) jjAddStates(3, 5); break; - case 7: + case 10: if (curChar == 47) jjCheckNAddStates(6, 8); break; - case 8: + case 11: if ((0xffffffffffffdbffL & l) != 0L) jjCheckNAddStates(6, 8); break; - case 9: + case 12: if ((0x2400L & l) != 0L && kind > 5) kind = 5; break; - case 10: + case 13: if (curChar == 10 && kind > 5) kind = 5; break; - case 11: + case 14: if (curChar == 13) - jjstateSet[jjnewStateCnt++] = 10; + jjstateSet[jjnewStateCnt++] = 13; break; - case 12: + case 15: if (curChar == 42) - jjCheckNAddTwoStates(13, 14); + jjCheckNAddTwoStates(16, 17); break; - case 13: + case 16: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(13, 14); + jjCheckNAddTwoStates(16, 17); break; - case 14: + case 17: if (curChar == 42) jjCheckNAddStates(9, 11); break; - case 15: + case 18: if ((0xffff7bffffffffffL & l) != 0L) - jjCheckNAddTwoStates(16, 14); + jjCheckNAddTwoStates(19, 17); break; - case 16: + case 19: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(16, 14); + jjCheckNAddTwoStates(19, 17); break; - case 17: + case 20: if (curChar == 47 && kind > 6) kind = 6; break; - case 18: + case 21: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 12; + jjstateSet[jjnewStateCnt++] = 15; break; - case 19: + case 22: if (curChar == 42) - jjCheckNAddTwoStates(20, 21); + jjCheckNAddTwoStates(23, 24); break; - case 20: + case 23: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(20, 21); + jjCheckNAddTwoStates(23, 24); break; - case 21: + case 24: if (curChar == 42) jjCheckNAddStates(12, 14); break; - case 22: + case 25: if ((0xffff7bffffffffffL & l) != 0L) - jjCheckNAddTwoStates(23, 21); + jjCheckNAddTwoStates(26, 24); break; - case 23: + case 26: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddTwoStates(23, 21); + jjCheckNAddTwoStates(26, 24); break; - case 24: + case 27: if (curChar == 47 && kind > 7) kind = 7; break; - case 25: + case 28: if ((0x3fe000000000000L & l) == 0L) break; if (kind > 8) kind = 8; jjCheckNAddStates(0, 2); break; - case 26: + case 29: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 8) kind = 8; - jjCheckNAdd(26); + jjCheckNAdd(29); break; - case 27: + case 30: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(27, 28); + jjCheckNAddTwoStates(30, 31); break; - case 28: + case 31: if (curChar != 46) break; if (kind > 9) kind = 9; - jjCheckNAdd(29); + jjCheckNAdd(32); break; - case 29: + case 32: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 9) kind = 9; - jjCheckNAdd(29); + jjCheckNAdd(32); break; - case 30: + case 33: if (curChar != 48) break; if (kind > 8) kind = 8; - jjCheckNAdd(28); + jjCheckNAdd(31); break; default : break; } @@ -410,32 +424,36 @@ { switch(jjstateSet[--i]) { - case 31: - case 4: + case 34: + case 7: if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddTwoStates(4, 5); + jjCheckNAddTwoStates(7, 8); break; case 1: if ((0xffffffffefffffffL & l) != 0L) jjAddStates(15, 16); break; - case 8: + case 4: + if ((0xffffffffefffffffL & l) != 0L) + jjAddStates(17, 18); + break; + case 11: jjAddStates(6, 8); break; - case 13: - jjCheckNAddTwoStates(13, 14); - break; - case 15: case 16: - jjCheckNAddTwoStates(16, 14); + jjCheckNAddTwoStates(16, 17); break; - case 20: - jjCheckNAddTwoStates(20, 21); + case 18: + case 19: + jjCheckNAddTwoStates(19, 17); break; - case 22: case 23: - jjCheckNAddTwoStates(23, 21); + jjCheckNAddTwoStates(23, 24); break; + case 25: + case 26: + jjCheckNAddTwoStates(26, 24); + break; default : break; } } while(i != startsAt); @@ -448,37 +466,41 @@ { switch(jjstateSet[--i]) { - case 31: - case 4: + case 34: + case 7: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(4, 5); + jjCheckNAddTwoStates(7, 8); break; case 1: if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(15, 16); break; - case 8: + case 4: if ((jjbitVec0[i2] & l2) != 0L) - jjAddStates(6, 8); + jjAddStates(17, 18); break; - case 13: + case 11: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(13, 14); + jjAddStates(6, 8); break; - case 15: case 16: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(16, 14); + jjCheckNAddTwoStates(16, 17); break; - case 20: + case 18: + case 19: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(20, 21); + jjCheckNAddTwoStates(19, 17); break; - case 22: case 23: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddTwoStates(23, 21); + jjCheckNAddTwoStates(23, 24); break; + case 25: + case 26: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(26, 24); + break; default : break; } } while(i != startsAt); @@ -490,15 +512,15 @@ kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 31 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 34 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 26, 27, 28, 7, 18, 19, 8, 9, 11, 14, 15, 17, 21, 22, 24, 1, - 2, + 29, 30, 31, 10, 21, 22, 11, 12, 14, 17, 18, 20, 24, 25, 27, 1, + 2, 4, 5, }; /** Token literal values. */ @@ -518,8 +540,8 @@ 0xfeL, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[31]; -private final int[] jjstateSet = new int[62]; +private final int[] jjrounds = new int[34]; +private final int[] jjstateSet = new int[68]; protected char curChar; /** Constructor. */ public ManchesterSyntaxParserTokenManager(SimpleCharStream stream){ @@ -546,7 +568,7 @@ { int i; jjround = 0x80000001; - for (i = 31; i-- > 0;) + for (i = 34; i-- > 0;) jjrounds[i] = 0x80000000; } Modified: trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-11-02 14:07:30 UTC (rev 3361) @@ -64,7 +64,8 @@ | < NOT: "not" > | < GE: ">=" > | < LE: "<=" > - | < STRING: "\"" (~["\"","\\","\n","\r"])* "\"" > + // support single quotes and double quotes + | < STRING: "\"" (~["\"","\\","\n","\r"])* "\"" | "'" (~["\"","\\","\n","\r"])* "'"> | < URI: "<" (~[">","\\","\n","\r"])* ">" > } Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-11-02 14:07:30 UTC (rev 3361) @@ -145,6 +145,7 @@ private Map<NamedClass, Set<ObjectProperty>> appOP = new TreeMap<NamedClass, Set<ObjectProperty>>(); private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appSD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); // most general applicable properties private Map<NamedClass,Set<ObjectProperty>> mgr = new TreeMap<NamedClass,Set<ObjectProperty>>(); @@ -838,6 +839,7 @@ private void computeTopRefinements(int maxLength, NamedClass domain) { long topComputationTimeStartNs = System.nanoTime(); +// System.out.println("computing top refinements for " + domain + " up to length " + maxLength); if(domain == null && m.size() == 0) computeM(); @@ -957,6 +959,12 @@ topARefinementsLength.put(domain,maxLength); topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; + +// if(domain == null) { +// System.out.println("computed top refinements: " + topRefinementsCumulative.get(maxLength)); +// } else { +// System.out.println("computed top refinements: " + topARefinementsCumulative.get(domain).get(maxLength)); +// } } // compute M_\top @@ -1046,6 +1054,8 @@ } m.put(4,m4); +// System.out.println("m: " + m); + mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } @@ -1183,7 +1193,7 @@ } mA.get(nc).put(4,m4); -// System.out.println(mA.get(nc)); +// System.out.println("m for " + nc + ": " + mA.get(nc)); mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } @@ -1330,7 +1340,7 @@ private void computeMgsdRecursive(NamedClass domain, Set<DatatypeProperty> currProperties, Set<DatatypeProperty> mgsdTmp) { for(DatatypeProperty prop : currProperties) { - if(appDD.get(domain).contains(prop)) + if(appSD.get(domain).contains(prop)) mgsdTmp.add(prop); else computeMgsdRecursive(domain, reasoner.getSubProperties(prop), mgsdTmp); @@ -1372,7 +1382,19 @@ if(!isDisjoint(domain,d)) applicableDDPs.add(role); } - appDD.put(domain, applicableDDPs); + appDD.put(domain, applicableDDPs); + + // string datatype properties + Set<DatatypeProperty> mostGeneralSDPs = reasoner.getStringDatatypeProperties(); + Set<DatatypeProperty> applicableSDPs = new TreeSet<DatatypeProperty>(); + for(DatatypeProperty role : mostGeneralSDPs) { +// Description d = (NamedClass) rs.getDomain(role); + Description d = reasoner.getDomain(role); +// System.out.println("domain: " + d); + if(!isDisjoint(domain,d)) + applicableSDPs.add(role); + } + appSD.put(domain, applicableSDPs); } // returns true of the intersection contains elements disjoint Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java 2011-11-02 14:07:30 UTC (rev 3361) @@ -68,6 +68,8 @@ "(<http://example.com/prop> some (<http://example.com/class1> and <http://example.com/class2>))", // another nested expression "(<http://nlp2rdf.lod2.eu/schema/string/Document> and (<http://nlp2rdf.lod2.eu/schema/string/subStringTrans> some <http://www.w3.org/2002/07/owl#Thing>))", + // a test with a single quoted string + "(<http://nlp2rdf.lod2.eu/schema/string/Document> and (<http://nlp2rdf.lod2.eu/schema/string/subStringTrans> some ( <http://nlp2rdf.lod2.eu/schema/sso/lemma> value 'copper')))" }; // loop through all test cases Modified: trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf =================================================================== --- trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf 2011-11-02 12:46:04 UTC (rev 3360) +++ trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf 2011-11-02 14:07:30 UTC (rev 3361) @@ -36,9 +36,10 @@ alg.type = "celoe" // alg.writeSearchTree = true alg.replaceSearchTree = true -alg.maxExecutionTimeInSeconds = 100 +alg.maxExecutionTimeInSeconds = 10 alg.maxNrOfResults = 10 alg.startClass = "(<http://nlp2rdf.lod2.eu/schema/string/Document> and (<http://nlp2rdf.lod2.eu/schema/string/subStringTrans> some <http://www.w3.org/2002/07/owl#Thing>))" +// solution: +// alg.startClass = "(<http://nlp2rdf.lod2.eu/schema/string/Document> and (<http://nlp2rdf.lod2.eu/schema/string/subStringTrans> some ( <http://nlp2rdf.lod2.eu/schema/sso/lemma> value 'copper')))" - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-02 12:46:10
|
Revision: 3360 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3360&view=rev Author: jenslehmann Date: 2011-11-02 12:46:04 +0000 (Wed, 02 Nov 2011) Log Message: ----------- improvements of Manchester syntax parser Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf Modified: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-11-02 12:26:53 UTC (rev 3359) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-11-02 12:46:04 UTC (rev 3360) @@ -42,14 +42,18 @@ jj_consume_token(22); {if (true) return new Union(c1,c2);} } else if (jj_2_3(2147483647)) { + jj_consume_token(21); s = URI(); jj_consume_token(SOME); c = ClassExpression(); + jj_consume_token(22); {if (true) return new ObjectSomeRestriction(new ObjectProperty(s),c);} } else if (jj_2_4(2147483647)) { + jj_consume_token(21); s = URI(); jj_consume_token(ONLY); c = ClassExpression(); + jj_consume_token(22); {if (true) return new ObjectAllRestriction(new ObjectProperty(s),c);} } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -192,9 +196,11 @@ } private boolean jj_3R_8() { + if (jj_scan_token(21)) return true; if (jj_3R_2()) return true; if (jj_scan_token(SOME)) return true; if (jj_3R_1()) return true; + if (jj_scan_token(22)) return true; return false; } @@ -291,6 +297,7 @@ } private boolean jj_3_4() { + if (jj_scan_token(21)) return true; if (jj_3R_2()) return true; if (jj_scan_token(ONLY)) return true; return false; @@ -306,6 +313,7 @@ } private boolean jj_3_3() { + if (jj_scan_token(21)) return true; if (jj_3R_2()) return true; if (jj_scan_token(SOME)) return true; return false; @@ -350,9 +358,11 @@ } private boolean jj_3R_9() { + if (jj_scan_token(21)) return true; if (jj_3R_2()) return true; if (jj_scan_token(ONLY)) return true; if (jj_3R_1()) return true; + if (jj_scan_token(22)) return true; return false; } Modified: trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-11-02 12:26:53 UTC (rev 3359) +++ trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-11-02 12:46:04 UTC (rev 3360) @@ -84,11 +84,11 @@ | LOOKAHEAD( "(" ClassExpression() <OR>) "(" c1=ClassExpression() <OR> c2=ClassExpression() ")" {return new Union(c1,c2);} - | LOOKAHEAD( URI() <SOME>) - s=URI() <SOME> c=ClassExpression() + | LOOKAHEAD( "(" URI() <SOME>) + "(" s=URI() <SOME> c=ClassExpression() ")" {return new ObjectSomeRestriction(new ObjectProperty(s),c); } - | LOOKAHEAD( URI() <ONLY>) - s=URI() <ONLY> c=ClassExpression() + | LOOKAHEAD( "(" URI() <ONLY>) + "(" s=URI() <ONLY> c=ClassExpression() ")" {return new ObjectAllRestriction(new ObjectProperty(s),c); } | <NOT> c=ClassExpression() {return new Negation(c); } Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java 2011-11-02 12:26:53 UTC (rev 3359) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java 2011-11-02 12:46:04 UTC (rev 3360) @@ -53,9 +53,9 @@ // simple URI "<http://example.com/foo>", // existential restriction - "<http://example.com/prop> some <http://example.com/class>", + "(<http://example.com/prop> some <http://example.com/class>)", // universal restriction - "<http://example.com/prop> only <http://example.com/class>", + "(<http://example.com/prop> only <http://example.com/class>)", // intersection "(<http://example.com/class1> and <http://example.com/class2>)", // disjunction @@ -65,7 +65,9 @@ // has value with string "(<http://example.com/prop> value \"string\")", // nested expression - "<http://example.com/prop> some (<http://example.com/class1> and <http://example.com/class2>)", + "(<http://example.com/prop> some (<http://example.com/class1> and <http://example.com/class2>))", + // another nested expression + "(<http://nlp2rdf.lod2.eu/schema/string/Document> and (<http://nlp2rdf.lod2.eu/schema/string/subStringTrans> some <http://www.w3.org/2002/07/owl#Thing>))", }; // loop through all test cases Modified: trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf =================================================================== --- trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf 2011-11-02 12:26:53 UTC (rev 3359) +++ trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf 2011-11-02 12:46:04 UTC (rev 3360) @@ -34,11 +34,11 @@ op.useStringDatatypes = true //op.frequencyThreshold = 1 alg.type = "celoe" -alg.writeSearchTree = true +// alg.writeSearchTree = true alg.replaceSearchTree = true alg.maxExecutionTimeInSeconds = 100 alg.maxNrOfResults = 10 +alg.startClass = "(<http://nlp2rdf.lod2.eu/schema/string/Document> and (<http://nlp2rdf.lod2.eu/schema/string/subStringTrans> some <http://www.w3.org/2002/07/owl#Thing>))" - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-02 12:27:00
|
Revision: 3359 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3359&view=rev Author: jenslehmann Date: 2011-11-02 12:26:53 +0000 (Wed, 02 Nov 2011) Log Message: ----------- - wrote Manchester syntax parser - added a unit test for it - integrated support for using class expressions in conf files (via property editor) Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java trunk/components-core/src/main/java/org/dllearner/core/owl/StringValueRestriction.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/ManchesterOWLSyntaxParser.java trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java trunk/examples/father.conf Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -49,6 +49,8 @@ import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.ClassLearningProblem; @@ -262,7 +264,10 @@ minimizer = new DescriptionMinimizer(reasoner); - startClass = Thing.instance; + // start at owl:Thing by default + if(startClass == null) { + startClass = Thing.instance; + } // singleSuggestionMode = configurator.getSingleSuggestionMode(); Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -7,6 +7,8 @@ import java.beans.PropertyEditor; import org.dllearner.core.owl.Description; +import org.dllearner.parser.ManchesterSyntaxParser; +import org.dllearner.parser.ParseException; import org.dllearner.utilities.owl.ManchesterOWLSyntaxParser; import org.semanticweb.owlapi.expression.ParserException; @@ -68,14 +70,12 @@ @Override public void setAsText(String arg0) throws IllegalArgumentException { - System.out.println(arg0); // we assume that the start class string is given in Manchester syntax try { - description = ManchesterOWLSyntaxParser.getDescription(arg0); - } catch (ParserException e) { + description = ManchesterSyntaxParser.parseClassExpression(arg0); + } catch (ParseException e) { throw new IllegalArgumentException(e); } - System.out.println(description); } @Override Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/StringValueRestriction.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/StringValueRestriction.java 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/StringValueRestriction.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -42,7 +42,7 @@ @Override public String toManchesterSyntaxString(String baseURI, Map<String,String> prefixes) { - return restrictedPropertyExpression.toString(baseURI, prefixes) + " value " +"\"" +value.toManchesterSyntaxString(baseURI, prefixes)+"\""; + return restrictedPropertyExpression.toString(baseURI, prefixes) + " value " + value.toManchesterSyntaxString(baseURI, prefixes); } @Override Added: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParser.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -0,0 +1,641 @@ +/* Generated By:JavaCC: Do not edit this line. ManchesterSyntaxParser.java */ +package org.dllearner.parser; + +import org.dllearner.core.owl.*; +import java.io.*; +import java.net.URL; + +public class ManchesterSyntaxParser implements ManchesterSyntaxParserConstants { + + public static Description parseClassExpression(String classExpression) throws ParseException { + ManchesterSyntaxParser parser = new ManchesterSyntaxParser(new StringReader(classExpression)); + return parser.ClassExpression(); + } + + final public Description ClassExpression() throws ParseException { + Description c,c1,c2; + String s,s1,s2; + int i; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TOP: + jj_consume_token(TOP); + {if (true) return new Thing();} + break; + case BOTTOM: + jj_consume_token(BOTTOM); + {if (true) return new Nothing();} + break; + default: + jj_la1[0] = jj_gen; + if (jj_2_1(2147483647)) { + jj_consume_token(21); + c1 = ClassExpression(); + jj_consume_token(AND); + c2 = ClassExpression(); + jj_consume_token(22); + {if (true) return new Intersection(c1,c2);} + } else if (jj_2_2(2147483647)) { + jj_consume_token(21); + c1 = ClassExpression(); + jj_consume_token(OR); + c2 = ClassExpression(); + jj_consume_token(22); + {if (true) return new Union(c1,c2);} + } else if (jj_2_3(2147483647)) { + s = URI(); + jj_consume_token(SOME); + c = ClassExpression(); + {if (true) return new ObjectSomeRestriction(new ObjectProperty(s),c);} + } else if (jj_2_4(2147483647)) { + s = URI(); + jj_consume_token(ONLY); + c = ClassExpression(); + {if (true) return new ObjectAllRestriction(new ObjectProperty(s),c);} + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case NOT: + jj_consume_token(NOT); + c = ClassExpression(); + {if (true) return new Negation(c);} + break; + case GE: + jj_consume_token(GE); + i = Integer(); + s = URI(); + jj_consume_token(23); + c = ClassExpression(); + {if (true) return new ObjectMinCardinalityRestriction(i,new ObjectProperty(s),c);} + break; + case LE: + jj_consume_token(LE); + i = Integer(); + s = URI(); + jj_consume_token(23); + c = ClassExpression(); + {if (true) return new ObjectMaxCardinalityRestriction(i,new ObjectProperty(s),c);} + break; + default: + jj_la1[1] = jj_gen; + if (jj_2_5(4)) { + jj_consume_token(21); + s1 = URI(); + jj_consume_token(24); + s2 = URI(); + jj_consume_token(22); + {if (true) return new ObjectValueRestriction(new ObjectProperty(s1), new Individual(s2));} + } else if (jj_2_6(4)) { + jj_consume_token(21); + s1 = URI(); + jj_consume_token(24); + s2 = String(); + jj_consume_token(22); + {if (true) return new StringValueRestriction(new DatatypeProperty(s1), s2);} + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case URI: + s = URI(); + {if (true) return new NamedClass(s);} + break; + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + } + throw new Error("Missing return statement in function"); + } + + final public double Double() throws ParseException { + Token t; + t = jj_consume_token(DOUBLE); + {if (true) return new Double(t.image);} + throw new Error("Missing return statement in function"); + } + + final public int Integer() throws ParseException { + Token t; + t = jj_consume_token(NUMBER); + {if (true) return new Integer(t.image);} + throw new Error("Missing return statement in function"); + } + + final public String String() throws ParseException { + Token t; + String s; + t = jj_consume_token(STRING); + // cut quotes + s = t.image; + s = s.substring(1, s.length() - 1); + {if (true) return s;} + throw new Error("Missing return statement in function"); + } + + final public String URI() throws ParseException { + Token t; + String s; + t = jj_consume_token(URI); + // cut "<" and ">" + s = t.image; + s = s.substring(1, s.length() - 1); + {if (true) return s;} + throw new Error("Missing return statement in function"); + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + private boolean jj_2_4(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + private boolean jj_2_5(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + private boolean jj_2_6(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + private boolean jj_3R_3() { + if (jj_scan_token(STRING)) return true; + return false; + } + + private boolean jj_3R_8() { + if (jj_3R_2()) return true; + if (jj_scan_token(SOME)) return true; + if (jj_3R_1()) return true; + return false; + } + + private boolean jj_3R_7() { + if (jj_scan_token(21)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(OR)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(22)) return true; + return false; + } + + private boolean jj_3R_6() { + if (jj_scan_token(21)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(AND)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(22)) return true; + return false; + } + + private boolean jj_3R_5() { + if (jj_scan_token(BOTTOM)) return true; + return false; + } + + private boolean jj_3R_1() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_4()) { + jj_scanpos = xsp; + if (jj_3R_5()) { + jj_scanpos = xsp; + if (jj_3R_6()) { + jj_scanpos = xsp; + if (jj_3R_7()) { + jj_scanpos = xsp; + if (jj_3R_8()) { + jj_scanpos = xsp; + if (jj_3R_9()) { + jj_scanpos = xsp; + if (jj_3R_10()) { + jj_scanpos = xsp; + if (jj_3R_11()) { + jj_scanpos = xsp; + if (jj_3R_12()) { + jj_scanpos = xsp; + if (jj_3_5()) { + jj_scanpos = xsp; + if (jj_3_6()) { + jj_scanpos = xsp; + if (jj_3R_13()) return true; + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_4() { + if (jj_scan_token(TOP)) return true; + return false; + } + + private boolean jj_3R_14() { + if (jj_scan_token(NUMBER)) return true; + return false; + } + + private boolean jj_3R_13() { + if (jj_3R_2()) return true; + return false; + } + + private boolean jj_3R_2() { + if (jj_scan_token(URI)) return true; + return false; + } + + private boolean jj_3_6() { + if (jj_scan_token(21)) return true; + if (jj_3R_2()) return true; + if (jj_scan_token(24)) return true; + if (jj_3R_3()) return true; + if (jj_scan_token(22)) return true; + return false; + } + + private boolean jj_3_4() { + if (jj_3R_2()) return true; + if (jj_scan_token(ONLY)) return true; + return false; + } + + private boolean jj_3_5() { + if (jj_scan_token(21)) return true; + if (jj_3R_2()) return true; + if (jj_scan_token(24)) return true; + if (jj_3R_2()) return true; + if (jj_scan_token(22)) return true; + return false; + } + + private boolean jj_3_3() { + if (jj_3R_2()) return true; + if (jj_scan_token(SOME)) return true; + return false; + } + + private boolean jj_3R_12() { + if (jj_scan_token(LE)) return true; + if (jj_3R_14()) return true; + if (jj_3R_2()) return true; + if (jj_scan_token(23)) return true; + if (jj_3R_1()) return true; + return false; + } + + private boolean jj_3_2() { + if (jj_scan_token(21)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(OR)) return true; + return false; + } + + private boolean jj_3R_11() { + if (jj_scan_token(GE)) return true; + if (jj_3R_14()) return true; + if (jj_3R_2()) return true; + if (jj_scan_token(23)) return true; + if (jj_3R_1()) return true; + return false; + } + + private boolean jj_3R_10() { + if (jj_scan_token(NOT)) return true; + if (jj_3R_1()) return true; + return false; + } + + private boolean jj_3_1() { + if (jj_scan_token(21)) return true; + if (jj_3R_1()) return true; + if (jj_scan_token(AND)) return true; + return false; + } + + private boolean jj_3R_9() { + if (jj_3R_2()) return true; + if (jj_scan_token(ONLY)) return true; + if (jj_3R_1()) return true; + return false; + } + + /** Generated Token Manager. */ + public ManchesterSyntaxParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[3]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0xc00,0x70000,0x100000,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[6]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public ManchesterSyntaxParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public ManchesterSyntaxParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ManchesterSyntaxParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public ManchesterSyntaxParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ManchesterSyntaxParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public ManchesterSyntaxParser(ManchesterSyntaxParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(ManchesterSyntaxParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[25]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 3; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<<j)) != 0) { + la1tokens[j] = true; + } + } + } + } + for (int i = 0; i < 25; i++) { + if (la1tokens[i]) { + jj_expentry = new int[1]; + jj_expentry[0] = i; + jj_expentries.add(jj_expentry); + } + } + jj_endpos = 0; + jj_rescan_token(); + jj_add_error_token(0, 0); + int[][] exptokseq = new int[jj_expentries.size()][]; + for (int i = 0; i < jj_expentries.size(); i++) { + exptokseq[i] = jj_expentries.get(i); + } + return new ParseException(token, exptokseq, tokenImage); + } + + /** Enable tracing. */ + final public void enable_tracing() { + } + + /** Disable tracing. */ + final public void disable_tracing() { + } + + private void jj_rescan_token() { + jj_rescan = true; + for (int i = 0; i < 6; i++) { + try { + JJCalls p = jj_2_rtns[i]; + do { + if (p.gen > jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserConstants.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -0,0 +1,78 @@ +/* Generated By:JavaCC: Do not edit this line. ManchesterSyntaxParserConstants.java */ +package org.dllearner.parser; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface ManchesterSyntaxParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int SINGLE_LINE_COMMENT = 5; + /** RegularExpression Id. */ + int FORMAL_COMMENT = 6; + /** RegularExpression Id. */ + int MULTI_LINE_COMMENT = 7; + /** RegularExpression Id. */ + int NUMBER = 8; + /** RegularExpression Id. */ + int DOUBLE = 9; + /** RegularExpression Id. */ + int TOP = 10; + /** RegularExpression Id. */ + int BOTTOM = 11; + /** RegularExpression Id. */ + int AND = 12; + /** RegularExpression Id. */ + int OR = 13; + /** RegularExpression Id. */ + int SOME = 14; + /** RegularExpression Id. */ + int ONLY = 15; + /** RegularExpression Id. */ + int NOT = 16; + /** RegularExpression Id. */ + int GE = 17; + /** RegularExpression Id. */ + int LE = 18; + /** RegularExpression Id. */ + int STRING = 19; + /** RegularExpression Id. */ + int URI = 20; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "<EOF>", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "<SINGLE_LINE_COMMENT>", + "<FORMAL_COMMENT>", + "<MULTI_LINE_COMMENT>", + "<NUMBER>", + "<DOUBLE>", + "\"TOP\"", + "\"BOTTOM\"", + "\"and\"", + "\"or\"", + "\"some\"", + "\"only\"", + "\"not\"", + "\">=\"", + "\"<=\"", + "<STRING>", + "<URI>", + "\"(\"", + "\")\"", + "\".\"", + "\"value\"", + }; + +} Added: trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/parser/ManchesterSyntaxParserTokenManager.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -0,0 +1,692 @@ +/* Generated By:JavaCC: Do not edit this line. ManchesterSyntaxParserTokenManager.java */ +package org.dllearner.parser; +import org.dllearner.core.owl.*; +import java.io.*; +import java.net.URL; + +/** Token Manager. */ +public class ManchesterSyntaxParserTokenManager implements ManchesterSyntaxParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) +{ + switch (pos) + { + case 0: + if ((active0 & 0x40000L) != 0L) + return 31; + return -1; + case 1: + if ((active0 & 0x40000L) != 0L) + return 31; + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 21); + case 41: + return jjStopAtPos(0, 22); + case 46: + return jjStopAtPos(0, 23); + case 60: + return jjMoveStringLiteralDfa1_0(0x40000L); + case 62: + return jjMoveStringLiteralDfa1_0(0x20000L); + case 66: + return jjMoveStringLiteralDfa1_0(0x800L); + case 84: + return jjMoveStringLiteralDfa1_0(0x400L); + case 97: + return jjMoveStringLiteralDfa1_0(0x1000L); + case 110: + return jjMoveStringLiteralDfa1_0(0x10000L); + case 111: + return jjMoveStringLiteralDfa1_0(0xa000L); + case 115: + return jjMoveStringLiteralDfa1_0(0x4000L); + case 118: + return jjMoveStringLiteralDfa1_0(0x1000000L); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 61: + if ((active0 & 0x20000L) != 0L) + return jjStopAtPos(1, 17); + else if ((active0 & 0x40000L) != 0L) + return jjStartNfaWithStates_0(1, 18, 31); + break; + case 79: + return jjMoveStringLiteralDfa2_0(active0, 0xc00L); + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x1000000L); + case 110: + return jjMoveStringLiteralDfa2_0(active0, 0x9000L); + case 111: + return jjMoveStringLiteralDfa2_0(active0, 0x14000L); + case 114: + if ((active0 & 0x2000L) != 0L) + return jjStopAtPos(1, 13); + break; + default : + break; + } + return jjStartNfa_0(0, active0); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0); + return 2; + } + switch(curChar) + { + case 80: + if ((active0 & 0x400L) != 0L) + return jjStopAtPos(2, 10); + break; + case 84: + return jjMoveStringLiteralDfa3_0(active0, 0x800L); + case 100: + if ((active0 & 0x1000L) != 0L) + return jjStopAtPos(2, 12); + break; + case 108: + return jjMoveStringLiteralDfa3_0(active0, 0x1008000L); + case 109: + return jjMoveStringLiteralDfa3_0(active0, 0x4000L); + case 116: + if ((active0 & 0x10000L) != 0L) + return jjStopAtPos(2, 16); + break; + default : + break; + } + return jjStartNfa_0(1, active0); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0); + return 3; + } + switch(curChar) + { + case 84: + return jjMoveStringLiteralDfa4_0(active0, 0x800L); + case 101: + if ((active0 & 0x4000L) != 0L) + return jjStopAtPos(3, 14); + break; + case 117: + return jjMoveStringLiteralDfa4_0(active0, 0x1000000L); + case 121: + if ((active0 & 0x8000L) != 0L) + return jjStopAtPos(3, 15); + break; + default : + break; + } + return jjStartNfa_0(2, active0); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0); + return 4; + } + switch(curChar) + { + case 79: + return jjMoveStringLiteralDfa5_0(active0, 0x800L); + case 101: + if ((active0 & 0x1000000L) != 0L) + return jjStopAtPos(4, 24); + break; + default : + break; + } + return jjStartNfa_0(3, active0); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0); + return 5; + } + switch(curChar) + { + case 77: + if ((active0 & 0x800L) != 0L) + return jjStopAtPos(5, 11); + break; + default : + break; + } + return jjStartNfa_0(4, active0); +} +private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 31; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 31: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(4, 5); + else if (curChar == 62) + { + if (kind > 20) + kind = 20; + } + break; + case 0: + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 8) + kind = 8; + jjCheckNAddStates(0, 2); + } + else if (curChar == 48) + { + if (kind > 8) + kind = 8; + jjCheckNAdd(28); + } + else if (curChar == 47) + jjAddStates(3, 5); + else if (curChar == 60) + jjCheckNAddTwoStates(4, 5); + else if (curChar == 34) + jjCheckNAddTwoStates(1, 2); + break; + case 1: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddTwoStates(1, 2); + break; + case 2: + if (curChar == 34 && kind > 19) + kind = 19; + break; + case 3: + if (curChar == 60) + jjCheckNAddTwoStates(4, 5); + break; + case 4: + if ((0xbfffffffffffdbffL & l) != 0L) + jjCheckNAddTwoStates(4, 5); + break; + case 5: + if (curChar == 62 && kind > 20) + kind = 20; + break; + case 6: + if (curChar == 47) + jjAddStates(3, 5); + break; + case 7: + if (curChar == 47) + jjCheckNAddStates(6, 8); + break; + case 8: + if ((0xffffffffffffdbffL & l) != 0L) + jjCheckNAddStates(6, 8); + break; + case 9: + if ((0x2400L & l) != 0L && kind > 5) + kind = 5; + break; + case 10: + if (curChar == 10 && kind > 5) + kind = 5; + break; + case 11: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 12: + if (curChar == 42) + jjCheckNAddTwoStates(13, 14); + break; + case 13: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(13, 14); + break; + case 14: + if (curChar == 42) + jjCheckNAddStates(9, 11); + break; + case 15: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(16, 14); + break; + case 16: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(16, 14); + break; + case 17: + if (curChar == 47 && kind > 6) + kind = 6; + break; + case 18: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 12; + break; + case 19: + if (curChar == 42) + jjCheckNAddTwoStates(20, 21); + break; + case 20: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(20, 21); + break; + case 21: + if (curChar == 42) + jjCheckNAddStates(12, 14); + break; + case 22: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(23, 21); + break; + case 23: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(23, 21); + break; + case 24: + if (curChar == 47 && kind > 7) + kind = 7; + break; + case 25: + if ((0x3fe000000000000L & l) == 0L) + break; + if (kind > 8) + kind = 8; + jjCheckNAddStates(0, 2); + break; + case 26: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 8) + kind = 8; + jjCheckNAdd(26); + break; + case 27: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(27, 28); + break; + case 28: + if (curChar != 46) + break; + if (kind > 9) + kind = 9; + jjCheckNAdd(29); + break; + case 29: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 9) + kind = 9; + jjCheckNAdd(29); + break; + case 30: + if (curChar != 48) + break; + if (kind > 8) + kind = 8; + jjCheckNAdd(28); + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 31: + case 4: + if ((0xffffffffefffffffL & l) != 0L) + jjCheckNAddTwoStates(4, 5); + break; + case 1: + if ((0xffffffffefffffffL & l) != 0L) + jjAddStates(15, 16); + break; + case 8: + jjAddStates(6, 8); + break; + case 13: + jjCheckNAddTwoStates(13, 14); + break; + case 15: + case 16: + jjCheckNAddTwoStates(16, 14); + break; + case 20: + jjCheckNAddTwoStates(20, 21); + break; + case 22: + case 23: + jjCheckNAddTwoStates(23, 21); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 31: + case 4: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(4, 5); + break; + case 1: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(15, 16); + break; + case 8: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(6, 8); + break; + case 13: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(13, 14); + break; + case 15: + case 16: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(16, 14); + break; + case 20: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(20, 21); + break; + case 22: + case 23: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(23, 21); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 31 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 26, 27, 28, 7, 18, 19, 8, 9, 11, 14, 15, 17, 21, 22, 24, 1, + 2, +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, null, null, "\124\117\120", +"\102\117\124\124\117\115", "\141\156\144", "\157\162", "\163\157\155\145", "\157\156\154\171", +"\156\157\164", "\76\75", "\74\75", null, null, "\50", "\51", "\56", "\166\141\154\165\145", }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0x1ffff01L, +}; +static final long[] jjtoSkip = { + 0xfeL, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[31]; +private final int[] jjstateSet = new int[62]; +protected char curChar; +/** Constructor. */ +public ManchesterSyntaxParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public ManchesterSyntaxParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 31; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} Added: trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/parser/manchester.jj 2011-11-02 12:26:53 UTC (rev 3359) @@ -0,0 +1,159 @@ +/** + * Copyright (C) 2011, 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/>. + * + */ + +options { + JDK_VERSION = "1.5"; + STATIC = false; +} + +PARSER_BEGIN(ManchesterSyntaxParser) +package org.dllearner.parser; + +import org.dllearner.core.owl.*; +import java.io.*; +import java.net.URL; + +public class ManchesterSyntaxParser { + + public static Description parseClassExpression(String classExpression) throws ParseException { + ManchesterSyntaxParser parser = new ManchesterSyntaxParser(new StringReader(classExpression)); + return parser.ClassExpression(); + } + +} +PARSER_END(ManchesterSyntaxParser) + +SKIP : +{ + " " +| "\t" +| "\n" +| "\r" +| <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> +| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> +| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/"> +} + +TOKEN : +{ + < NUMBER: (["1"-"9"] (["0"-"9"])* | "0") > + | < DOUBLE: (["1"-"9"] (["0"-"9"])* | "0") "." (["0"-"9"])* > + | < TOP: "TOP" > + | < BOTTOM: "BOTTOM" > + | < AND: "and" > + | < OR: "or" > + | < SOME: "some" > + | < ONLY: "only" > + | < NOT: "not" > + | < GE: ">=" > + | < LE: "<=" > + | < STRING: "\"" (~["\"","\\","\n","\r"])* "\"" > + | < URI: "<" (~[">","\\","\n","\r"])* ">" > +} + +Description ClassExpression() : +{ + Description c,c1,c2; + String s,s1,s2; + int i; +} +{ + <TOP> {return new Thing();} + | <BOTTOM> {return new Nothing();} + // parse until next AND or OR + | LOOKAHEAD( "(" ClassExpression() <AND>) + "(" c1=ClassExpression() <AND> c2=ClassExpression() ")" + {return new Intersection(c1,c2);} + | LOOKAHEAD( "(" ClassExpression() <OR>) + "(" c1=ClassExpression() <OR> c2=ClassExpression() ")" + {return new Union(c1,c2);} + | LOOKAHEAD( URI() <SOME>) + s=URI() <SOME> c=ClassExpression() + {return new ObjectSomeRestriction(new ObjectProperty(s),c); } + | LOOKAHEAD( URI() <ONLY>) + s=URI() <ONLY> c=ClassExpression() + {return new ObjectAllRestriction(new ObjectProperty(s),c); } + | <NOT> c=ClassExpression() + {return new Negation(c); } + | <GE> i=Integer() s=URI() "." c=ClassExpression() + {return new ObjectMinCardinalityRestriction(i,new ObjectProperty(s),c);} + | <LE> i=Integer() s=URI() "." c=ClassExpression() + {return new ObjectMaxCardinalityRestriction(i,new ObjectProperty(s),c);} + | LOOKAHEAD(4) + "(" s1=URI() "value" s2=URI() ")" + { return new ObjectValueRestriction(new ObjectProperty(s1), new Individual(s2)); } + | LOOKAHEAD(4) + "(" s1=URI() "value" s2=String() ")" + { return new StringValueRestriction(new DatatypeProperty(s1), s2); } + // if none of the other cases matches, it is just a named class + | s = URI() {return new NamedClass(s);} +} + +double Double() : +{ + Token t; +} +{ + t=<DOUBLE> + { + return new Double(t.image); + } +} + +int Integer() : +{ + Token t; +} +{ + t=<NUMBER> + { + return new Integer(t.image); + } +} + +String String() : +{ + Token t; + String s; +} +{ + t=<STRING> + { + // cut quotes + s = t.image; + s = s.substring(1, s.length() - 1); + return s; + } +} + +String URI() : +{ + Token t; + String s; +} +{ + t=<URI> + { + // cut "<" and ">" + s = t.image; + s = s.substring(1, s.length() - 1); + return s; + } +} \ No newline at end of file Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/ManchesterOWLSyntaxParser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/ManchesterOWLSyntaxParser.java 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/ManchesterOWLSyntaxParser.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -22,6 +22,8 @@ import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxEditorParser; import org.dllearner.core.owl.Description; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; +import org.dllearner.parser.ManchesterSyntaxParser; +import org.dllearner.parser.ParseException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.expression.ParserException; import org.semanticweb.owlapi.model.OWLClassExpression; @@ -42,14 +44,16 @@ return parser.parseClassExpression(); } - public static Description getDescription(String manchesterSyntaxDescription) throws ParserException { - OWLClassExpression d = getOWLAPIDescription(manchesterSyntaxDescription); - return DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(d); + public static Description getDescription(String manchesterSyntaxDescription) throws ParseException { +// OWLClassExpression d = getOWLAPIDescription(manchesterSyntaxDescription); +// return DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(d); + return ManchesterSyntaxParser.parseClassExpression(manchesterSyntaxDescription); } + - public static void main(String args[]) throws ParserException { - Description d = ManchesterOWLSyntaxParser.getDescription("hasP SOME A"); - SparqlQueryDescriptionConvertVisitor.getSparqlQuery(d, 10, false, false); - } +// public static void main(String args[]) throws ParserException { +// Description d = ManchesterOWLSyntaxParser.getDescription("hasP SOME A"); +// SparqlQueryDescriptionConvertVisitor.getSparqlQuery(d, 10, false, false); +// } } Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -20,9 +20,9 @@ package org.dllearner.test.junit; import org.dllearner.core.owl.Description; +import org.dllearner.parser.ParseException; import org.dllearner.utilities.owl.ManchesterOWLSyntaxParser; import org.junit.Test; -import org.semanticweb.owlapi.expression.ParserException; /** * @@ -34,7 +34,7 @@ public class OWLAPITests { @Test - public void testManchesterSyntaxParser() throws ParserException { + public void testManchesterSyntaxParser() throws ParseException { // String s = "BIGPROP SOME smallclass"; // String s = "<http://test.de/prop> some <http://test.de/Class>"; String s = "<http://test.de/Class>"; Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/ParserTests.java 2011-11-02 12:26:53 UTC (rev 3359) @@ -24,6 +24,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.parser.KBParser; +import org.dllearner.parser.ManchesterSyntaxParser; import org.dllearner.parser.ParseException; import org.junit.Test; @@ -47,6 +48,36 @@ } @Test + public void ManchesterParserTest() throws ParseException { + String[] tests = new String[] { + // simple URI + "<http://example.com/foo>", + // existential restriction + "<http://example.com/prop> some <http://example.com/class>", + // universal restriction + "<http://example.com/prop> only <http://example.com/class>", + // intersection + "(<http://example.com/class1> and <http://example.com/class2>)", + // disjunction + "(<http://example.com/class1> or <http://example.com/class2>)", + // has value + "(<http://example.com/prop> value <http://example.com/ind>)", + // has value with string + "(<http://example.com/prop> value \"string\")", + // nested expression + "<http://example.com/prop> some (<http://example.com/class1> and <http://example.com/class2>)", + }; + + // loop through all test cases + for(String test : tests) { + System.out.print(test + " --> "); + Description d = ManchesterSyntaxParser.parseClassExpression(test); + System.out.println(d.toManchesterSyntaxString(null, null)); + } + + } + + @Test public void ParseAndSPARQLConvertTest() throws ParseException { // add your test strings here (do not use prefixes) String[] kbArray = new String[] { Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2011-11-02 09:08:56 UTC (rev 3358) +++ trunk/examples/father.conf 2011-11-02 12:26:53 UTC (rev 3359) @@ -25,4 +25,3 @@ // create learning algorithm to run alg.type = "ocel" - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-11-02 09:09:03
|
Revision: 3358 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3358&view=rev Author: jenslehmann Date: 2011-11-02 09:08:56 +0000 (Wed, 02 Nov 2011) Log Message: ----------- registered editor for class expressions (not working yet) Modified Paths: -------------- trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java Added: trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ClassExpressionPropertyEditor.java 2011-11-02 09:08:56 UTC (rev 3358) @@ -0,0 +1,92 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +import org.dllearner.core.owl.Description; +import org.dllearner.utilities.owl.ManchesterOWLSyntaxParser; +import org.semanticweb.owlapi.expression.ParserException; + +public class ClassExpressionPropertyEditor implements PropertyEditor { + + private Description description; + + @Override + public void addPropertyChangeListener(PropertyChangeListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public String getAsText() { + return description.toManchesterSyntaxString(null, null); + } + + @Override + public Component getCustomEditor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getJavaInitializationString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getTags() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValue() { + return description; + } + + @Override + public boolean isPaintable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void paintValue(Graphics arg0, Rectangle arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setAsText(String arg0) throws IllegalArgumentException { + System.out.println(arg0); + // we assume that the start class string is given in Manchester syntax + try { + description = ManchesterOWLSyntaxParser.getDescription(arg0); + } catch (ParserException e) { + throw new IllegalArgumentException(e); + } + System.out.println(description); + } + + @Override + public void setValue(Object arg0) { + description = (Description) arg0; + } + + @Override + public boolean supportsCustomEditor() { + // TODO Auto-generated method stub + return false; + } + +} Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java 2011-11-02 08:43:43 UTC (rev 3357) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/OWLAPITests.java 2011-11-02 09:08:56 UTC (rev 3358) @@ -21,6 +21,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.utilities.owl.ManchesterOWLSyntaxParser; +import org.junit.Test; import org.semanticweb.owlapi.expression.ParserException; /** @@ -32,7 +33,7 @@ */ public class OWLAPITests { -// @Test + @Test public void testManchesterSyntaxParser() throws ParserException { // String s = "BIGPROP SOME smallclass"; // String s = "<http://test.de/prop> some <http://test.de/Class>"; Modified: trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf =================================================================== --- trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf 2011-11-02 08:43:43 UTC (rev 3357) +++ trunk/examples/nlp2rdf/reuters_gold_vs_copper/learn.conf 2011-11-02 09:08:56 UTC (rev 3358) @@ -34,9 +34,9 @@ op.useStringDatatypes = true //op.frequencyThreshold = 1 alg.type = "celoe" -// alg.writeSearchTree = true +alg.writeSearchTree = true alg.replaceSearchTree = true -alg.maxExecutionTimeInSeconds = 10 +alg.maxExecutionTimeInSeconds = 100 alg.maxNrOfResults = 10 Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java 2011-11-02 08:43:43 UTC (rev 3357) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java 2011-11-02 09:08:56 UTC (rev 3358) @@ -1,5 +1,7 @@ package org.dllearner.configuration.spring; +import org.dllearner.core.config.ClassExpressionPropertyEditor; +import org.dllearner.core.owl.Description; import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.beans.PropertyEditorRegistry; @@ -17,6 +19,7 @@ @Override public void registerCustomEditors(PropertyEditorRegistry registry) { //Register any custom editors here. - + ClassExpressionPropertyEditor ce = new ClassExpressionPropertyEditor(); + registry.registerCustomEditor(Description.class, ce); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |