From: <ku...@us...> - 2010-03-16 17:55:32
|
Revision: 2123 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2123&view=rev Author: kurzum Date: 2010-03-16 17:55:25 +0000 (Tue, 16 Mar 2010) Log Message: ----------- fixed a sparql conversion bug Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/SparqlQueryConverter.java Property Changed: ---------------- trunk/ Property changes on: trunk ___________________________________________________________________ Modified: svn:ignore - .lastUsedExample .settings .project .classpath classes log cache cachePersistant reports results local rdbtoonto the_log.txt tmp fragmentOntology.owl output ling osmdata matching stanley dllearner.jar father.inp lgd.nt files errorDescription bin + .lastUsedExample .settings .project .classpath classes log cache cachePersistant reports results local rdbtoonto the_log.txt tmp fragmentOntology.owl output ling osmdata matching stanley dllearner.jar father.inp lgd.nt files errorDescription bin tigerResults dbpedia_3.4.owl dbpedia_3.4.owl.count dbpedia_3.4.owl.expanded.count dbpedia_3.4.owl.purged.ser dbpedia_3.4.owl.sub.ser dbpedia_3.4.owl.super.ser dbpedia_3.4.owl.tar.gz skoscategories_en.nt skoscategories_en.nt.count skoscategories_en.nt.expanded.count skoscategories_en.nt.purged.ser skoscategories_en.nt.sub.ser skoscategories_en.nt.super.ser skoscategories_en.nt.tar.gz yagoclasses_links.nt yagoclasses_links.nt.count yagoclasses_links.nt.expanded.count yagoclasses_links.nt.purged.ser yagoclasses_links.nt.sub.ser yagoclasses_links.nt.super.ser yagoclasses_links.nt.tar.gz Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2010-03-16 09:01:43 UTC (rev 2122) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2010-03-16 17:55:25 UTC (rev 2123) @@ -58,6 +58,7 @@ import org.dllearner.core.owl.Union; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; +import org.dllearner.test.SparqlQueryConverter; /** * Converter from DL-Learner descriptions to a corresponding SPARQL query to get @@ -251,6 +252,7 @@ * @param args */ public static void main(String[] args) { + SparqlQueryConverter.test(); try { SortedSet<String> s = new TreeSet<String>(); HashMap<String, String> result = new HashMap<String, String>(); @@ -301,7 +303,6 @@ if (true) { System.exit(0); } - // <http://nlp2rdf.org/ontology/sentencefinalpunctuation_tag> String query = ""; SparqlQueryDescriptionConvertVisitor visit = new SparqlQueryDescriptionConvertVisitor(); @@ -362,11 +363,18 @@ if(transitiveProperties!= null && transitiveProperties.contains(description.getRole().toString()) ){ option =" OPTION (TRANSITIVE , t_in(?" + stack.peek()+"), t_out(?object" + currentObject + "), T_MIN(0), T_MAX(6), T_DIRECTION 1 , T_NO_CYCLES) "; } - query += "\n?" + stack.peek() + " <" + description.getRole() + "> ?object" + currentObject + option + ". "; - stack.push("object" + currentObject); - currentObject++; - description.getChild(0).accept(this); - stack.pop(); + + if(description.getChild(0) instanceof Thing){ + //I removed a point here at the end + query += "\n?" + stack.peek() + " <" + description.getRole() + "> [] " + option + " "; + }else{ + query += "\n?" + stack.peek() + " <" + description.getRole() + "> ?object" + currentObject + option + " . "; + stack.push("object" + currentObject); + currentObject++; + description.getChild(0).accept(this); + stack.pop(); + } + logger.trace(description.getRole().toString()); logger.trace(description.getChild(0).toString()); } @@ -402,10 +410,18 @@ * .Intersection) */ public void visit(Intersection description) { - logger.trace("Intersection"); - description.getChild(0).accept(this); - query += ". "; - description.getChild(1).accept(this); + if(description.getChild(0) instanceof Thing ){ + logger.trace("Intersection with TOP"); + description.getChild(1).accept(this); + }else if(description.getChild(1) instanceof Thing ){ + logger.trace("Intersection with TOP"); + description.getChild(0).accept(this); + }else{ + logger.trace("Intersection"); + description.getChild(0).accept(this); + query += ". "; + description.getChild(1).accept(this); + } } /* @@ -416,13 +432,23 @@ * .Union) */ public void visit(Union description) { - // HACK see replace hacks in other functions - logger.trace("Union"); - query += "{"; - description.getChild(0).accept(this); - query += "} UNION {"; - description.getChild(1).accept(this); - query += "}"; + + if(description.getChild(0) instanceof Thing ){ + logger.trace("Union with TOP"); + description.getChild(1).accept(this); + }else if(description.getChild(1) instanceof Thing ){ + logger.trace("Union with TOP"); + description.getChild(0).accept(this); + }else{ + logger.trace("Union"); + query += "{"; + description.getChild(0).accept(this); + query += "} UNION {"; + description.getChild(1).accept(this); + query += "}"; + } + + } /* Added: trunk/src/dl-learner/org/dllearner/test/SparqlQueryConverter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SparqlQueryConverter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/SparqlQueryConverter.java 2010-03-16 17:55:25 UTC (rev 2123) @@ -0,0 +1,55 @@ +package org.dllearner.test; + +import java.util.HashMap; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; +import org.dllearner.parser.ParseException; +import org.junit.Test; + +public class SparqlQueryConverter { + + @Test + public static void test(){ + SortedSet<String> s = new TreeSet<String>(); + s.add("(\"http://dbpedia.org/ontology/Work\" AND (EXISTS \"http://dbpedia.org/property/hasPhotoCollection\".TOP AND (\"http://dbpedia.org/ontology/TelevisionEpisode\" OR EXISTS \"http://xmlns.com/foaf/0.1/depiction\".TOP)))"); + s.add("(\"http://dbpedia.org/ontology/Work\" AND (EXISTS \"http://dbpedia.org/property/hasPhotoCollection\".TOP AND \"http://dbpedia.org/ontology/TelevisionEpisode\"))"); + s.add(" ( EXISTS \"http://dbpedia.org/property/hasPhotoCollection\".TOP AND \"http://dbpedia.org/ontology/TelevisionEpisode\")"); + s.add(" EXISTS \"http://dbpedia.org/property/hasPhotoCollection\".TOP "); + s.add(" EXISTS \"http://dbpedia.org/property/hasPhotoCollection\".(TOP OR \"http://dbpedia.org/ontology/TelevisionEpisode\") "); + s.add(" EXISTS \"http://dbpedia.org/property/hasPhotoCollection\".(TOP AND \"http://dbpedia.org/ontology/TelevisionEpisode\") "); + convert(s); + if (true) { + System.exit(0); + } + } + + private static void convert(Set<String> s){ + try{ + HashMap<String, String> result = new HashMap<String, String>(); + String query = ""; + SparqlQueryDescriptionConvertVisitor visit = new SparqlQueryDescriptionConvertVisitor(); + visit.setLabels(false); + visit.setDistinct(false); +// visit.setClassToSubclassesVirtuoso(subclassMap); + + + + for (String kbsyntax : s) { + query = visit.getSparqlQuery(kbsyntax); + result.put(kbsyntax, query); + } + System.out.println("************************"); + for (String string : result.keySet()) { + System.out.println("KBSyntayString: " + string); + System.out.println("Query:\n" + result.get(string)); + System.out.println("************************"); + } + System.out.println("Finished"); + } catch (ParseException e) { + e.printStackTrace(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |