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: <ku...@us...> - 2008-08-05 09:50:44
|
Revision: 1050 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1050&view=rev Author: kurzum Date: 2008-08-05 09:50:39 +0000 (Tue, 05 Aug 2008) Log Message: ----------- small changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java Property Changed: ---------------- trunk/src/dl-learner/org/dllearner/test/ Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 17:17:58 UTC (rev 1049) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-05 09:50:39 UTC (rev 1050) @@ -85,13 +85,14 @@ // isRunning = true; ResultSet rs; - + String service = sparqlEndpoint.getURL().toString(); + writeToSparqlLog("***********\nNew Query:"); writeToSparqlLog(sparqlQueryString); - writeToSparqlLog(sparqlEndpoint.getURL().toString()); + writeToSparqlLog(service); - String service = sparqlEndpoint.getURL().toString(); - + + logger.trace("making queryExecution Object"); // Jena access to SPARQL endpoint queryExecution = new QueryEngineHTTP(service, sparqlQueryString); //System.out.println(sparqlEndpoint.getDefaultGraphURIs()); @@ -117,7 +118,7 @@ + sparqlEndpoint.getURL().toString()); rs = queryExecution.execSelect(); - + logger.trace("query executed, converting to json"); json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs)); //writeToSparqlLog("JSON: " + json); @@ -132,6 +133,7 @@ logger.warn("RuntimeException in SparqlQuery"+ e.toString()); writeToSparqlLog("ERROR: HTTPException occured"+ e.toString()); writeToSparqlLog("ERROR: query was: "+sparqlQueryString); + writeToSparqlLog("wget -S -O test.txt '"+service+"?query="+sparqlQueryString+"'"); //} throw e; } Property changes on: trunk/src/dl-learner/org/dllearner/test ___________________________________________________________________ Modified: svn:ignore - JamonTest.java + JamonTest.java JenaAmpBug.java Added: trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 09:50:39 UTC (rev 1050) @@ -0,0 +1,35 @@ +package org.dllearner.test; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; + +public class TestOneQueryForMusicRecommender { + + private static Logger logger = Logger.getRootLogger(); + + public static void main(String[] args) { + Logger.getLogger(SparqlQuery.class).setLevel(Level.TRACE); + logger.info("Start"); + String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "; + p1 += "PREFIX mo: <http://purl.org/ontology/mo/> "; + String query1 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10"; + //String query2 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name 'Allison Crowe' .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10"; + + + SparqlEndpoint se = SparqlEndpoint.getEndpointJamendo(); + System.out.println(se.getURL()); + System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query1+"'"); + //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query2+"'"); + System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query1+"'"); + //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query2+"'"); + System.out.println(se.getURL()+"?query="+query1); + SparqlQuery s = new SparqlQuery(p1+query1, se); + s.send(); + System.out.println(s.getJson()); + + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-04 17:18:13
|
Revision: 1049 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1049&view=rev Author: kurzum Date: 2008-08-04 17:17:58 +0000 (Mon, 04 Aug 2008) Log Message: ----------- tested some new improvements, which showed that further experimentation is necessary Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/test/FilterTest.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/rules/ trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -24,6 +24,7 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.utilities.datastructures.StringTuple; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFactory; @@ -381,7 +382,29 @@ + object + " \n" + "} " + limit(sparqlResultLimit); return queryAsSet(sparqlQueryString, variable); } + + + public SortedSet<StringTuple> queryAsTuple(String subject, boolean filterLiterals) { + ResultSetRewindable rs = null; + String p = "predicate"; + String o = "object"; + String lits = (filterLiterals)? ".FILTER (!isLiteral(?"+o+"))." : ""; + String sparqlQueryString = "SELECT * WHERE { <"+subject+"> ?"+p+" ?"+o+" "+lits+" } "; + + try { + String jsonString = query(sparqlQueryString); + rs = SparqlQuery.convertJSONtoResultSet(jsonString); + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + //SimpleClock sc = new SimpleClock(); + //rw = ResultSetFactory.makeRewindable(rs); + //sc.printAndSet("rewindable"); + return getTuplesFromResultSet(rs, p, o); + } + /** * little higher level, executes query ,returns all resources for a * variable. @@ -428,9 +451,13 @@ public String query(String sparqlQueryString) { String jsonString; if (cache == null) { + SparqlQuery sq = new SparqlQuery(sparqlQueryString, sparqlEndpoint); + //SimpleClock sc = new SimpleClock(); sq.send(); + //sc.printAndSet("querysend"); jsonString = sq.getJson(); + } else { jsonString = cache.executeSparqlQuery(new SparqlQuery( sparqlQueryString, sparqlEndpoint)); @@ -464,7 +491,23 @@ return result; } + + private static SortedSet<StringTuple> getTuplesFromResultSet( + ResultSetRewindable rs, String predicate, String object) { + final SortedSet<StringTuple> returnSet = new TreeSet<StringTuple>(); + //SimpleClock sc = new SimpleClock(); + @SuppressWarnings("unchecked") + final List<ResultBinding> l = ResultSetFormatter.toList(rs); + for (ResultBinding resultBinding : l) { + returnSet.add(new StringTuple(resultBinding.get(predicate).toString(),resultBinding.get(object).toString())); + } + //sc.printAndSet("allTuples"); + rs.reset(); + //sc.printAndSet("reset"); + return returnSet; + } + public SparqlEndpoint getSparqlEndpoint() { return sparqlEndpoint; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -278,15 +278,8 @@ * @return JSON representation of the result set. */ public static String convertResultSetToJSON(ResultSetRewindable resultSet) { - // if (rs == null) - // this.send(); - //ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ResultSetFormatter.outputAsJSON(baos, resultSet); - // possible Jena bug: Jena modifies the result set during - // JSON transformation, so we need to get it back - //rsRewind. - //resultSet = convertJSONtoResultSet(baos.toString()); resultSet.reset(); try { return baos.toString("UTF-8"); Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -46,6 +46,7 @@ import org.dllearner.scripts.improveWikipedia.ConceptSPARQLReEvaluator; import org.dllearner.scripts.improveWikipedia.ConceptSelector; import org.dllearner.scripts.improveWikipedia.WikipediaCategoryTasks; +import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; import org.dllearner.utilities.learn.LearnSPARQLConfiguration; @@ -172,11 +173,11 @@ private static void collectResults(WikipediaCategoryTasks wikiTasks) { //logger.setLevel(Level.DEBUG); - printSet("fullpos", wikiTasks.getFullPositiveSet()); + SetManipulation.printSet("fullpos", wikiTasks.getFullPositiveSet(), logger); - printSet("cleanedpos", wikiTasks.getCleanedPositiveSet()); + SetManipulation.printSet("cleanedpos", wikiTasks.getCleanedPositiveSet(), logger); - printSet("wrongindividuals", wikiTasks.getDefinitelyWrongIndividuals()); + SetManipulation.printSet("wrongindividuals", wikiTasks.getDefinitelyWrongIndividuals(), logger); } @@ -269,21 +270,15 @@ SortedSet correctIndividuals, SortedSet wrongIndividuals, int numberOfConcepts) { - printSet("full Individual set: ", fullSet); + SetManipulation.printSet("full Individual set: ", fullSet, logger); - printSet("correct Individuals: ", correctIndividuals); - printSet("incorrect Individuals: ", wrongIndividuals); + SetManipulation.printSet("correct Individuals: ", correctIndividuals, logger); + SetManipulation.printSet("incorrect Individuals: ", wrongIndividuals, logger); logger.info("reevaluated " + numberOfConcepts + " found Concepts"); logger.info("END OF PHASE 1 **********************"); } - private static void printSet(String s, SortedSet set) { - if(logger.getLevel().equals(Level.DEBUG)){ - logger.info(s +" ["+ set.size()+"]: "+set); - }else{ - logger.info(s +" ["+ set.size()+"]"); - } - - } + + private static void setup() { // SETUP cache and sparqltasks Modified: trunk/src/dl-learner/org/dllearner/test/FilterTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -1,35 +1,158 @@ package org.dllearner.test; -import org.dllearner.kb.sparql.Cache; +import java.util.SortedSet; +import java.util.TreeSet; + import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.test.rules.RuleExecutor; +import org.dllearner.test.rules.SimpleObjectFilterRule; +import org.dllearner.test.rules.SimplePredicateFilterRule; +import org.dllearner.utilities.datastructures.SetManipulation; +import org.dllearner.utilities.datastructures.StringTuple; import org.dllearner.utilities.statistics.SimpleClock; public class FilterTest { + + private static SPARQLTasks st; + private static String subject = "http://dbpedia.org/resource/%22Big%22_Ron"; + static int howmany = 150; + static SimpleClock sc = new SimpleClock(); + + static String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}"; + /*static String qextralong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') )))." + + "OPTIONAL { ?object ?p2 ?o2. FILTER( (!isLiteral(?o2))&&( ( !regex(str(?p2), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/website') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?p2), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?p2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?p2), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?o2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?o2), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?o2), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?o2), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?o2), 'http://www.geonames.org') ))).}}"; + */ + static String qextralong="SELECT * WHERE { { <http://dbpedia.org/resource/Angela_Merkel> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}" + + "OPTIONAL { ?object ?p2 ?o2. FILTER( (!isLiteral(?o2))&&( ( !regex(str(?p2), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/website') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?p2), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?p2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?p2), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?p2), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?o2), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?o2), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?o2), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?o2), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?o2), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?o2), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?o2), 'http://www.geonames.org') ))).}}"; + + + static String qshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER (!isLiteral(?object)).}"; + static String sshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object }"; + static String qextrashort="SELECT * WHERE { <http://dbpedia.org/resource/Angela_Merkel> ?predicate ?object. FILTER (!isLiteral(?object)). OPTIONAL { ?object ?p2 ?o2 FILTER (!isLiteral(?o2))}}"; + + /** * @param args */ public static void main(String[] args) { - // TODO Auto-generated method stub - String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}"; - String qshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER (!isLiteral(?object)).}"; + // System.out.println(qextralong); + + // System.out.println(qextrashort); - SimpleClock sc = new SimpleClock(); - SPARQLTasks st = new SPARQLTasks(Cache.getPersistentCache(), SparqlEndpoint.getEndpointDBpedia()); + st = new SPARQLTasks( SparqlEndpoint.getEndpointDBpedia()); + st.queryAsTuple(subject, true); + st.query(qlong); + st.query(qextralong); + st.query(sshort); + // st.query(qextrashort); + System.out.println(qextrashort); + System.exit(0); + // st.query(qextrashort); + //System.out.println(qextralong); - for (int i = 0; i < 10; i++) { - st.query(qshort); + //String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) )).}"; + + + //testLong(); + + //testShortWithFilter(); + //testShort(); + testLong(); + testExtraLong(); + //testExtraShort(); + //testShort(); + //testLong(); + //testShortWithFilter(); + + + /*sc.reset(); + for (int i = 0; i < howmany; i++) { + st.query(sshort); } - sc.printAndSet("long "); + sc.printAndSet("supershort "); + */ - for (int i = 0; i < 10; i++) { + } + + static void testShort(){ + SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>(); + sc.reset(); + for (int i = 0; i < howmany; i++) { + + tupleset = st.queryAsTuple(subject, true); + + } + SetManipulation.printSet("before", tupleset); + + sc.printAndSet("SHORT "); + + } + + static void testLong(){ + sc.reset(); + for (int i = 0; i < howmany; i++) { st.query(qlong); } + sc.printAndSet("long "); + } + + static void testExtraLong(){ + sc.reset(); + for (int i = 0; i < howmany; i++) { + st.query(qextralong); + } + sc.printAndSet("extraLong "); + } + + static void testExtraShort(){ + sc.reset(); + for (int i = 0; i < howmany; i++) { + st.query(qextrashort); + } + sc.printAndSet("qextrashort "); + } + + static void testShortWithFilter(){ + SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>(); + SortedSet<StringTuple> afterfilter= new TreeSet<StringTuple>(); + RuleExecutor re = new RuleExecutor(); - sc.printAndSet("short "); + + re.addFilterRule(new SimplePredicateFilterRule( "http://dbpedia.org/property/relatedInstance" )); + re.addFilterRule(new SimplePredicateFilterRule( "http://dbpedia.org/property/website")); + re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/owner" )); + re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/wikiPageUsesTemplate" )); + re.addFilterRule(new SimplePredicateFilterRule("http://www.w3.org/2002/07/owl#sameAs" )); + re.addFilterRule(new SimplePredicateFilterRule("http://xmlns.com/foaf/0.1/" )); + re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/standard")); + re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/wikipage")); + re.addFilterRule(new SimplePredicateFilterRule("http://dbpedia.org/property/reference")); + re.addFilterRule(new SimplePredicateFilterRule("http://www.w3.org/2004/02/skos/core")); + re.addFilterRule(new SimpleObjectFilterRule("http://xmlns.com/foaf/0.1/" )); + re.addFilterRule(new SimpleObjectFilterRule( "http://upload.wikimedia.org/wikipedia")); + re.addFilterRule(new SimpleObjectFilterRule( "http://www4.wiwiss.fu-berlin.de/flickrwrappr")); + re.addFilterRule(new SimpleObjectFilterRule("http://dbpedia.org/resource/Template" )); + re.addFilterRule(new SimpleObjectFilterRule( "http://upload.wikimedia.org/wikipedia/commons")); + re.addFilterRule(new SimpleObjectFilterRule("http://www.w3.org/2006/03/wn/wn20/instances/synset" )); + re.addFilterRule(new SimpleObjectFilterRule("http://dbpedia.org/resource/Category:" )); + re.addFilterRule(new SimpleObjectFilterRule( "http://www.w3.org/2004/02/skos/core" )); + re.addFilterRule(new SimpleObjectFilterRule("http://www.geonames.org")); + + + + sc.reset(); + for (int i = 0; i < howmany; i++) { + + tupleset = st.queryAsTuple(subject, true); + afterfilter = re.filterTuples(subject,tupleset); + } + sc.printAndSet("SHORT with filter"); + SetManipulation.printSet("before", tupleset); + SetManipulation.printSet("after", afterfilter); } } Added: trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -0,0 +1,10 @@ +package org.dllearner.test.rules; + +import org.dllearner.utilities.datastructures.StringTuple; + +public abstract class FilterRule { + + + public abstract boolean keepTuple(String subject, StringTuple tuple); + +} Added: trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/rules/ReplacementRule.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -0,0 +1,8 @@ +package org.dllearner.test.rules; + +import org.dllearner.utilities.datastructures.StringTuple; + +public abstract class ReplacementRule { + + public abstract StringTuple applyRule(String subject, StringTuple tuple); +} Added: trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/rules/RuleExecutor.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -0,0 +1,45 @@ +package org.dllearner.test.rules; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.utilities.datastructures.StringTuple; + +public class RuleExecutor { + + List<ReplacementRule> replacementRules = new ArrayList<ReplacementRule>(); + List<FilterRule> filterRule = new ArrayList<FilterRule>(); + + public RuleExecutor() { + super(); + } + + private boolean keepTuple(String subject, StringTuple tuple) { + + for (int i = 0; i < filterRule.size(); i++) { + FilterRule fr = filterRule.get(i); + if (!(fr.keepTuple(subject, tuple))) { + return false; + } + + } + return true; + } + + public SortedSet<StringTuple> filterTuples(String subject, SortedSet<StringTuple> tuples){ + SortedSet<StringTuple> returnSet = new TreeSet<StringTuple>(); + for (StringTuple tuple : tuples) { + if(keepTuple(subject, tuple)) { + returnSet.add(tuple); + } + } + return returnSet; + } + + public void addFilterRule(FilterRule fr){ + filterRule.add(fr); + } + +} Added: trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -0,0 +1,23 @@ +package org.dllearner.test.rules; + +import org.dllearner.utilities.datastructures.StringTuple; + +public class SimpleObjectFilterRule extends FilterRule{ + + String objectFilter; + + public SimpleObjectFilterRule(String objectFilter) { + super(); + this.objectFilter = objectFilter; + } + + + @Override + public boolean keepTuple(String subject, StringTuple tuple) { + return !(tuple.b.contains(objectFilter)); + } + + + + +} Added: trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -0,0 +1,23 @@ +package org.dllearner.test.rules; + +import org.dllearner.utilities.datastructures.StringTuple; + +public class SimplePredicateFilterRule extends FilterRule{ + + String predicateFilter; + + + public SimplePredicateFilterRule(String predicateFilter) { + super(); + this.predicateFilter = predicateFilter; + } + + @Override + public boolean keepTuple(String subject, StringTuple tuple) { + return !(tuple.a.contains(predicateFilter)); + } + + + + +} Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -5,6 +5,8 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; import org.dllearner.core.owl.Individual; public class SetManipulation { @@ -87,4 +89,18 @@ } return ret; } + + public static void printSet(String s, SortedSet set, Logger logger) { + if(logger.getLevel().equals(Level.DEBUG)){ + logger.info(s +" ["+ set.size()+"]: "+set); + }else{ + logger.info(s +" ["+ set.size()+"]"); + } + + } + + public static void printSet(String s, SortedSet set) { + System.out.println(s +" ["+ set.size()+"]: "+set); + + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/StringTuple.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -24,7 +24,7 @@ * Also used as pre form, if you want to create triple, that have the same subject * @author Sebastian Hellmann */ -public class StringTuple { +public class StringTuple implements Comparable<StringTuple>{ public String a; public String b; @@ -40,10 +40,14 @@ } public boolean equals(StringTuple t) { - if (a.equals(t.a) && b.equals(t.b)) - return true; - else - return false; + return ((b.equals(t.b)) && (a.equals(t.a))); } + + public int compareTo(StringTuple t){ + int comp = a.compareTo(t.a); + if( comp == 0 ){ + return b.compareTo(t.b); + }else return comp; + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java 2008-08-04 11:34:25 UTC (rev 1048) +++ trunk/src/dl-learner/org/dllearner/utilities/statistics/SimpleClock.java 2008-08-04 17:17:58 UTC (rev 1049) @@ -57,9 +57,19 @@ } + /** + * resets the clock + */ public void setTime() { time=System.currentTimeMillis(); } + /** + * resets the clock + */ + public void reset() { + setTime(); + } + public long getTime() { long now=System.currentTimeMillis(); return now-time; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-04 11:34:30
|
Revision: 1048 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1048&view=rev Author: jenslehmann Date: 2008-08-04 11:34:25 +0000 (Mon, 04 Aug 2008) Log Message: ----------- - implemented cache for getting all nodes on a particular level of a tree - one of five operator steps in EL downward refinement done Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/core/owl/Description.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-04 09:01:44 UTC (rev 1047) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-04 11:34:25 UTC (rev 1048) @@ -27,6 +27,7 @@ import org.dllearner.core.owl.Description; 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.Thing; import org.dllearner.core.owl.UnsupportedLanguageException; @@ -49,6 +50,9 @@ */ public class ELDescriptionNode { + // the reference tree for storing values, must not be null + private ELDescriptionTree tree; + private SortedSet<NamedClass> label; private List<ELDescriptionEdge> edges; @@ -58,37 +62,52 @@ // parent node in the tree; // null indicates that this node is a root node private ELDescriptionNode parent = null; - - // to simplify equivalence checks and minimisation, we - // attach a simulation relation to the description tree -// private Simulation simulation; - + /** - * Constructs an empty EL description tree with the empty set - * as root label and an empty set of outgoing edges. + * Constructs an EL description tree with empty root label. */ - public ELDescriptionNode() { - this(new TreeSet<NamedClass>(), new LinkedList<ELDescriptionEdge>()); -// simulation = new Simulation(); - } + public ELDescriptionNode(ELDescriptionTree tree) { + this(tree, new TreeSet<NamedClass>()); + } /** * Constructs an EL description tree given its root label. * @param label Label of the root node. */ - public ELDescriptionNode(SortedSet<NamedClass> label) { - this(label, new LinkedList<ELDescriptionEdge>()); + public ELDescriptionNode(ELDescriptionTree tree, SortedSet<NamedClass> label) { + this.label = label; + this.edges = new LinkedList<ELDescriptionEdge>(); + this.tree = tree; + level = 1; + parent = null; } + public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, SortedSet<NamedClass> label) { + this.label = label; + this.edges = new LinkedList<ELDescriptionEdge>(); + parent = parentNode; + // the reference tree is the same as for the parent tree + tree = parentNode.tree; + // level increases by 1 + level = parentNode.level + 1; + // we add an edge from the parent to this node + ELDescriptionEdge edge = new ELDescriptionEdge(parentProperty, this); + parent.edges.add(edge); + // we need to update the set of nodes on a particular level + tree.addNodeToLevel(this, level); + } + /** * Constructs an EL description tree given its root label and edges. * @param label Label of the root node. * @param edges Edges connected to the root node. */ - public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) { - this.label = label; - this.edges = edges; - } +// TODO: probably delete as this constructor is not straightforward to +// implement within the new structure +// public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) { +// this.label = label; +// this.edges = edges; +// } /** * Constructs an EL description tree from an EL description. @@ -167,8 +186,19 @@ return is; } } + + /** + * Replaces an entry in the node label. + * @param oldClass Class to remove from label. + * @param newClass Class to add to label. + */ + public void replaceInLabel(NamedClass oldClass, NamedClass newClass) { + label.remove(oldClass); + label.add(newClass); + } /** + * Gets the label of this node. Do not modify the returned object. * @return The label of root node of this subtree. */ public SortedSet<NamedClass> getLabel() { @@ -176,7 +206,8 @@ } /** - * @return The outgoing edges of this subtree. + * @return The outgoing edges of this subtree. Do not modify the + * returned object. */ public List<ELDescriptionEdge> getEdges() { return edges; @@ -191,8 +222,22 @@ @Override public ELDescriptionNode clone() { - // TODO implement efficient tree cloning - return null; + ELDescriptionNode node = null; + try { + node = (ELDescriptionNode) super.clone(); + } catch (CloneNotSupportedException e) { + // should never happen + throw new InternalError(e.toString()); + } +/* + // create a deep copy + node.children = new LinkedList<Description>(); + for(Description child : children) { + Description clonedChild = (Description) child.clone(); + node.addChild(clonedChild); + } +*/ + return node; } } Added: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-04 11:34:25 UTC (rev 1048) @@ -0,0 +1,118 @@ +/** + * 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.algorithms.el; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.core.owl.NamedClass; + +/** + * Represents an EL description tree. Unlike {@link ELDescriptionNode}, + * this is a tree-wide structure, i.e. it does not implement the tree + * structure itself, but is used to store information about the tree. + * + * @author Jens Lehmann + * + */ +public class ELDescriptionTree implements Cloneable { + + // to simplify equivalence checks and minimisation, we + // attach a simulation relation to the description tree +// private Simulation simulation; + + private int maxLevel = 1; + + private ELDescriptionNode rootNode; + + private Map<Integer,Set<ELDescriptionNode>> levelNodeMapping = new HashMap<Integer,Set<ELDescriptionNode>>(); + + public ELDescriptionTree() { + + } + + /** + * Gets the nodes on a specific level of the tree. + * This information is cached here for performance + * reasons. + * @param level The level (distance from root node). + * @return The set of all nodes on the specified level within + * this tree. + */ + public Set<ELDescriptionNode> getNodesOnLevel(int level) { + return levelNodeMapping.get(level); + } + + /** + * Internal method for updating the level node mapping. + * It is called when a new node is added to the tree. + * @param node The new node. + * @param level Level of the new node. + */ + protected void addNodeToLevel(ELDescriptionNode node, int level) { + if(level <= maxLevel) { + levelNodeMapping.get(level).add(node); + } else if (level == maxLevel + 1) { + Set<ELDescriptionNode> set = new HashSet<ELDescriptionNode>(); + set.add(node); + levelNodeMapping.put(level, set); + maxLevel++; + } else { + throw new RuntimeException("Inconsistent EL description tree structure."); + } + } + + /** + * @return the maxLevel + */ + public int getMaxLevel() { + return maxLevel; + } + + /** + * @return the rootNode + */ + public ELDescriptionNode getRootNode() { + return rootNode; + } + + @Override + public ELDescriptionTree clone() { + // create a new reference tree + ELDescriptionTree treeClone = new ELDescriptionTree(); + // create a root node attached to this reference tree + ELDescriptionNode rootNodeClone = new ELDescriptionNode(treeClone, new TreeSet<NamedClass>(rootNode.getLabel())); + cloneRecursively(rootNode, rootNodeClone); + return treeClone; + } + + // we read from the original structure and write to the new structure + private void cloneRecursively(ELDescriptionNode node, ELDescriptionNode nodeClone) { + // loop through all edges and clone the subtrees + for(ELDescriptionEdge edge : node.getEdges()) { + ELDescriptionNode tmp = new ELDescriptionNode(nodeClone, edge.getLabel(), new TreeSet<NamedClass>(edge.getTree().getLabel())); + cloneRecursively(edge.getTree(), tmp); + } + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/Description.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2008-08-04 09:01:44 UTC (rev 1047) +++ trunk/src/dl-learner/org/dllearner/core/owl/Description.java 2008-08-04 11:34:25 UTC (rev 1048) @@ -101,9 +101,8 @@ /** * Returns a clone of this description. */ - @SuppressWarnings("unchecked") @Override - public Object clone() { + public Description clone() { Description node = null; try { node = (Description) super.clone(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 09:01:44 UTC (rev 1047) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 11:34:25 UTC (rev 1048) @@ -125,9 +125,12 @@ for(NamedClass nc : tree.getLabel()) { // find all more special classes for the given label for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) { - // create refinements by replacing class - ELDescriptionNode tmp = tree.clone(); - // TODO replace class in label + if(moreSpecial instanceof NamedClass) { + // create refinements by replacing class + ELDescriptionNode tmp = tree.clone(); + tmp.replaceInLabel(nc, (NamedClass) moreSpecial); + refinements.add(tmp); + } } } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 09:01:44 UTC (rev 1047) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 11:34:25 UTC (rev 1048) @@ -21,9 +21,14 @@ import static org.junit.Assert.*; +import java.util.TreeSet; + import org.dllearner.algorithms.el.ELDescriptionNode; +import org.dllearner.algorithms.el.ELDescriptionTree; import org.dllearner.algorithms.el.Simulation; import org.dllearner.algorithms.el.TreeTuple; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; import org.junit.Test; /** @@ -38,12 +43,19 @@ @Test public void simulationTest() { Simulation s = new Simulation(); - ELDescriptionNode t1 = new ELDescriptionNode(); - ELDescriptionNode t2 = new ELDescriptionNode(); + ELDescriptionTree tree1 = new ELDescriptionTree(); + ELDescriptionTree tree2 = new ELDescriptionTree(); + ELDescriptionNode t1 = new ELDescriptionNode(tree1); + ELDescriptionNode t2 = new ELDescriptionNode(tree2); TreeTuple tuple1 = new TreeTuple(t1,t2); s.addTuple(tuple1); assertTrue(s.in(t2).size() == 1); - assertTrue(s.out(t2).size() == 0); +// assertTrue(s.out(t2).size() == 0); + ObjectProperty p = new ObjectProperty("p"); + TreeSet<NamedClass> l3 = new TreeSet<NamedClass>(); + ELDescriptionNode t3 = new ELDescriptionNode(t1,p,l3); + assertTrue(t3.getLevel() == 2); + assertTrue(tree1.getMaxLevel() == 2); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-04 09:01:48
|
Revision: 1047 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1047&view=rev Author: jenslehmann Date: 2008-08-04 09:01:44 +0000 (Mon, 04 Aug 2008) Log Message: ----------- structural change in EL trees Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java Copied: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java (from rev 1046, trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -0,0 +1,62 @@ +/** + * 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.algorithms.el; + +import org.dllearner.core.owl.ObjectProperty; + +/** + * A (directed) edge in an EL description tree. It consists of an edge + * label, which is an object property, and the EL description tree + * the edge points to. + * + * @author Jens Lehmann + * + */ +public class ELDescriptionEdge { + + private ObjectProperty label; + + private ELDescriptionNode tree; + + /** + * Constructs and edge given a label and an EL description tree. + * @param label The label of this edge. + * @param tree The tree the edge points to (edges are directed). + */ + public ELDescriptionEdge(ObjectProperty label, ELDescriptionNode tree) { + this.label = label; + this.tree = tree; + } + + /** + * @return The label of this edge. + */ + public ObjectProperty getLabel() { + return label; + } + + /** + * @return The EL description tree + */ + public ELDescriptionNode getTree() { + return tree; + } + +} Copied: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java (from rev 1046, trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -0,0 +1,198 @@ +/** + * 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.algorithms.el; + +import java.util.LinkedList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.UnsupportedLanguageException; + +/** + * Represents an EL description tree, which corresponds to a + * description in the EL description logic. Note that an EL description tree + * can be a subtree of another EL description tree. In general, + * an EL description tree is a tree where the node label is a set + * of named classes and the edges are labelled with a property. + * + * In the documentation below "this node" refers to the root node + * of this EL description (sub-)tree. One tree cannot be reused, + * i.e. used as subtree in several description trees, as some of + * the associated variables (level, simulation) depend on the overall + * tree. + * + * @author Jens Lehmann + * + */ +public class ELDescriptionNode { + + private SortedSet<NamedClass> label; + + private List<ELDescriptionEdge> edges; + + private int level; + + // parent node in the tree; + // null indicates that this node is a root node + private ELDescriptionNode parent = null; + + // to simplify equivalence checks and minimisation, we + // attach a simulation relation to the description tree +// private Simulation simulation; + + /** + * Constructs an empty EL description tree with the empty set + * as root label and an empty set of outgoing edges. + */ + public ELDescriptionNode() { + this(new TreeSet<NamedClass>(), new LinkedList<ELDescriptionEdge>()); +// simulation = new Simulation(); + } + + /** + * Constructs an EL description tree given its root label. + * @param label Label of the root node. + */ + public ELDescriptionNode(SortedSet<NamedClass> label) { + this(label, new LinkedList<ELDescriptionEdge>()); + } + + /** + * Constructs an EL description tree given its root label and edges. + * @param label Label of the root node. + * @param edges Edges connected to the root node. + */ + public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) { + this.label = label; + this.edges = edges; + } + + /** + * Constructs an EL description tree from an EL description. + * @param description A description + */ + public ELDescriptionNode(Description description) { + // TODO not implemented + // throw an exception if the description is not in EL + throw new UnsupportedLanguageException(description.toString(), "EL"); + } + + /** + * Checks whether this node has a parent. If the parent link + * is null, the node is considered to be a root node. + * @return True of this is the root node and false otherwise. + */ + public boolean isRoot() { + return parent == null; + } + + /** + * Traverses the EL description tree upwards until it finds + * the root and returns it. + * @return The root node of this EL description tree. + */ + public ELDescriptionNode getRoot() { + ELDescriptionNode root = this; + while(root.parent != null) { + root = parent; + } + return root; + } + + /** + * Traverses the tree until the root node and counts how + * many edges are traversed. If this node does not have a parent, + * zero is returned. This method is used for checking the integrity + * of the tree in unit tests. Use {@link #getLevel()} to get the + * level of the tree. + * @return The level of this node (or more specifically the root + * node of this subtree) within the overall EL description tree. + */ + public int computeLevel() { + ELDescriptionNode root = this; + int level = 0; + while(root.parent != null) { + root = parent; + level++; + } + return level; + } + + /** + * This method transform the tree to an EL description. The + * node labels are transformed to an {@link Intersection} + * of {@link NamedClass}. Each edges is transformed to an + * {@link ObjectSomeRestriction}, where the property is the edge + * label and the child description the subtree the edge points + * to. Edges are also added to the intersection. If the intersection + * is empty, {@link Thing} is returned. + * @return The description corresponding to this EL description tree. + */ + public Description transformToDescription() { + if(label.size()==0 && edges.size()==0) { + return new Thing(); + } else { + Intersection is = new Intersection(); + for(NamedClass nc : label) { + is.addChild(nc); + } + for(ELDescriptionEdge edge : edges) { + Description child = edge.getTree().transformToDescription(); + ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child); + is.addChild(osr); + } + return is; + } + } + + /** + * @return The label of root node of this subtree. + */ + public SortedSet<NamedClass> getLabel() { + return label; + } + + /** + * @return The outgoing edges of this subtree. + */ + public List<ELDescriptionEdge> getEdges() { + return edges; + } + + /** + * @return The level of the (root node of) this subtree in the overall tree. + */ + public int getLevel() { + return level; + } + + @Override + public ELDescriptionNode clone() { + // TODO implement efficient tree cloning + return null; + } + +} Deleted: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-04 08:43:26 UTC (rev 1046) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -1,198 +0,0 @@ -/** - * 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.algorithms.el; - -import java.util.LinkedList; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectSomeRestriction; -import org.dllearner.core.owl.Thing; -import org.dllearner.core.owl.UnsupportedLanguageException; - -/** - * Represents an EL description tree, which corresponds to a - * description in the EL description logic. Note that an EL description tree - * can be a subtree of another EL description tree. In general, - * an EL description tree is a tree where the node label is a set - * of named classes and the edges are labelled with a property. - * - * In the documentation below "this node" refers to the root node - * of this EL description (sub-)tree. One tree cannot be reused, - * i.e. used as subtree in several description trees, as some of - * the associated variables (level, simulation) depend on the overall - * tree. - * - * @author Jens Lehmann - * - */ -public class ELDescriptionTree { - - private SortedSet<NamedClass> label; - - private List<Edge> edges; - - private int level; - - // parent node in the tree; - // null indicates that this node is a root node - private ELDescriptionTree parent = null; - - // to simplify equivalence checks and minimisation, we - // attach a simulation relation to the description tree -// private Simulation simulation; - - /** - * Constructs an empty EL description tree with the empty set - * as root label and an empty set of outgoing edges. - */ - public ELDescriptionTree() { - this(new TreeSet<NamedClass>(), new LinkedList<Edge>()); -// simulation = new Simulation(); - } - - /** - * Constructs an EL description tree given its root label. - * @param label Label of the root node. - */ - public ELDescriptionTree(SortedSet<NamedClass> label) { - this(label, new LinkedList<Edge>()); - } - - /** - * Constructs an EL description tree given its root label and edges. - * @param label Label of the root node. - * @param edges Edges connected to the root node. - */ - public ELDescriptionTree(SortedSet<NamedClass> label, List<Edge> edges) { - this.label = label; - this.edges = edges; - } - - /** - * Constructs an EL description tree from an EL description. - * @param description A description - */ - public ELDescriptionTree(Description description) { - // TODO not implemented - // throw an exception if the description is not in EL - throw new UnsupportedLanguageException(description.toString(), "EL"); - } - - /** - * Checks whether this node has a parent. If the parent link - * is null, the node is considered to be a root node. - * @return True of this is the root node and false otherwise. - */ - public boolean isRoot() { - return parent == null; - } - - /** - * Traverses the EL description tree upwards until it finds - * the root and returns it. - * @return The root node of this EL description tree. - */ - public ELDescriptionTree getRoot() { - ELDescriptionTree root = this; - while(root.parent != null) { - root = parent; - } - return root; - } - - /** - * Traverses the tree until the root node and counts how - * many edges are traversed. If this node does not have a parent, - * zero is returned. This method is used for checking the integrity - * of the tree in unit tests. Use {@link #getLevel()} to get the - * level of the tree. - * @return The level of this node (or more specifically the root - * node of this subtree) within the overall EL description tree. - */ - public int computeLevel() { - ELDescriptionTree root = this; - int level = 0; - while(root.parent != null) { - root = parent; - level++; - } - return level; - } - - /** - * This method transform the tree to an EL description. The - * node labels are transformed to an {@link Intersection} - * of {@link NamedClass}. Each edges is transformed to an - * {@link ObjectSomeRestriction}, where the property is the edge - * label and the child description the subtree the edge points - * to. Edges are also added to the intersection. If the intersection - * is empty, {@link Thing} is returned. - * @return The description corresponding to this EL description tree. - */ - public Description transformToDescription() { - if(label.size()==0 && edges.size()==0) { - return new Thing(); - } else { - Intersection is = new Intersection(); - for(NamedClass nc : label) { - is.addChild(nc); - } - for(Edge edge : edges) { - Description child = edge.getTree().transformToDescription(); - ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child); - is.addChild(osr); - } - return is; - } - } - - /** - * @return The label of root node of this subtree. - */ - public SortedSet<NamedClass> getLabel() { - return label; - } - - /** - * @return The outgoing edges of this subtree. - */ - public List<Edge> getEdges() { - return edges; - } - - /** - * @return The level of the (root node of) this subtree in the overall tree. - */ - public int getLevel() { - return level; - } - - @Override - public ELDescriptionTree clone() { - // TODO implement efficient tree cloning - return null; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-08-04 08:43:26 UTC (rev 1046) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -1,62 +0,0 @@ -/** - * 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.algorithms.el; - -import org.dllearner.core.owl.ObjectProperty; - -/** - * A (directed) edge in an EL description tree. It consists of an edge - * label, which is an object property, and the EL description tree - * the edge points to. - * - * @author Jens Lehmann - * - */ -public class Edge { - - private ObjectProperty label; - - private ELDescriptionTree tree; - - /** - * Constructs and edge given a label and an EL description tree. - * @param label The label of this edge. - * @param tree The tree the edge points to (edges are directed). - */ - public Edge(ObjectProperty label, ELDescriptionTree tree) { - this.label = label; - this.tree = tree; - } - - /** - * @return The label of this edge. - */ - public ObjectProperty getLabel() { - return label; - } - - /** - * @return The EL description tree - */ - public ELDescriptionTree getTree() { - return tree; - } - -} Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-08-04 08:43:26 UTC (rev 1046) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -36,15 +36,15 @@ private List<TreeTuple> relation; // { w | (v,w) \in S } for all w - private Map<ELDescriptionTree,List<ELDescriptionTree>> in; + private Map<ELDescriptionNode,List<ELDescriptionNode>> in; // { v | (v,w) \in S } for all v - private Map<ELDescriptionTree,List<ELDescriptionTree>> out; + private Map<ELDescriptionNode,List<ELDescriptionNode>> out; public Simulation() { relation = new LinkedList<TreeTuple>(); - in = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>(); - out = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>(); + in = new HashMap<ELDescriptionNode,List<ELDescriptionNode>>(); + out = new HashMap<ELDescriptionNode,List<ELDescriptionNode>>(); } /** @@ -59,7 +59,7 @@ if(in.containsKey(tuple.getTree2())) { in.get(tuple.getTree2()).add(tuple.getTree1()); } else { - List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>(); + List<ELDescriptionNode> list = new LinkedList<ELDescriptionNode>(); list.add(tuple.getTree1()); in.put(tuple.getTree2(), list); } @@ -67,7 +67,7 @@ if(out.containsKey(tuple.getTree1())) { out.get(tuple.getTree1()).add(tuple.getTree2()); } else { - List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>(); + List<ELDescriptionNode> list = new LinkedList<ELDescriptionNode>(); list.add(tuple.getTree2()); out.put(tuple.getTree1(), list); } @@ -99,11 +99,11 @@ return relation; } - public List<ELDescriptionTree> in(ELDescriptionTree tree) { + public List<ELDescriptionNode> in(ELDescriptionNode tree) { return in.get(tree); } - public List<ELDescriptionTree> out(ELDescriptionTree tree) { + public List<ELDescriptionNode> out(ELDescriptionNode tree) { return out.get(tree); } } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-08-04 08:43:26 UTC (rev 1046) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -27,11 +27,11 @@ */ public class TreeTuple { - private ELDescriptionTree tree1; + private ELDescriptionNode tree1; - private ELDescriptionTree tree2; + private ELDescriptionNode tree2; - public TreeTuple(ELDescriptionTree tree1, ELDescriptionTree tree2) { + public TreeTuple(ELDescriptionNode tree1, ELDescriptionNode tree2) { this.tree1 = tree1; this.tree2 = tree2; } @@ -40,7 +40,7 @@ * Gets first tree. * @return - first tree */ - public ELDescriptionTree getTree1() { + public ELDescriptionNode getTree1() { return tree1; } @@ -48,7 +48,7 @@ * Gets second tree. * @return - second tree */ - public ELDescriptionTree getTree2() { + public ELDescriptionNode getTree2() { return tree2; } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 08:43:26 UTC (rev 1046) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -24,7 +24,7 @@ import java.util.Set; import java.util.TreeMap; -import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.algorithms.el.ELDescriptionNode; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; @@ -95,10 +95,10 @@ public Set<Description> refine(Description concept) { // TODO according to the specification, we need to minimise // the tree (not yet implemented) - ELDescriptionTree tree = new ELDescriptionTree(concept); - Set<ELDescriptionTree> refinementTrees = refine(tree); + ELDescriptionNode tree = new ELDescriptionNode(concept); + Set<ELDescriptionNode> refinementTrees = refine(tree); Set<Description> refinements = new HashSet<Description>(); - for(ELDescriptionTree refinementTree : refinementTrees) { + for(ELDescriptionNode refinementTree : refinementTrees) { refinements.add(refinementTree.transformToDescription()); } return refinements; @@ -112,12 +112,12 @@ * @param tree Input EL description tree. * @return Set of refined EL description trees. */ - public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { + public Set<ELDescriptionNode> refine(ELDescriptionNode tree) { return refine(tree, new Thing()); } - private Set<ELDescriptionTree> refine(ELDescriptionTree tree, Description index) { - Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + private Set<ELDescriptionNode> refine(ELDescriptionNode tree, Description index) { + Set<ELDescriptionNode> refinements = new HashSet<ELDescriptionNode>(); // option 1: label extension // option 2: label refinement @@ -126,7 +126,7 @@ // find all more special classes for the given label for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) { // create refinements by replacing class - ELDescriptionTree tmp = tree.clone(); + ELDescriptionNode tmp = tree.clone(); // TODO replace class in label } } Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 08:43:26 UTC (rev 1046) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-08-04 09:01:44 UTC (rev 1047) @@ -21,7 +21,7 @@ import static org.junit.Assert.*; -import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.algorithms.el.ELDescriptionNode; import org.dllearner.algorithms.el.Simulation; import org.dllearner.algorithms.el.TreeTuple; import org.junit.Test; @@ -38,8 +38,8 @@ @Test public void simulationTest() { Simulation s = new Simulation(); - ELDescriptionTree t1 = new ELDescriptionTree(); - ELDescriptionTree t2 = new ELDescriptionTree(); + ELDescriptionNode t1 = new ELDescriptionNode(); + ELDescriptionNode t2 = new ELDescriptionNode(); TreeTuple tuple1 = new TreeTuple(t1,t2); s.addTuple(tuple1); assertTrue(s.in(t2).size() == 1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-04 08:43:32
|
Revision: 1046 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1046&view=rev Author: kurzum Date: 2008-08-04 08:43:26 +0000 (Mon, 04 Aug 2008) Log Message: ----------- latest changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/FilterTest.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -112,7 +112,7 @@ final SortedSet<String> tmpSet = new TreeSet<String>(); // collect super/subclasses for the depth - for (; (depth != 0) && (!toBeRetrieved.isEmpty()); depth--) { + for (; (depth > 0) && (!toBeRetrieved.isEmpty()); depth--) { // collect super/subclasses for each class in toBeRetrieved // accumulate in tmpSet for (String oneClass : toBeRetrieved) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -94,13 +94,14 @@ // Jena access to SPARQL endpoint queryExecution = new QueryEngineHTTP(service, sparqlQueryString); + //System.out.println(sparqlEndpoint.getDefaultGraphURIs()); + for (String dgu : sparqlEndpoint.getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } for (String ngu : sparqlEndpoint.getNamedGraphURIs()) { queryExecution.addNamedGraph(ngu); } - // TODO remove after overnext Jena release HttpQuery.urlLimit = 3 * 1024; JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime") Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -50,6 +50,7 @@ import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; import org.dllearner.utilities.learn.LearnSPARQLConfiguration; import org.dllearner.utilities.learn.LearnSparql; +import org.dllearner.utilities.statistics.SimpleClock; public class WikipediaCategoryCleaner { @@ -67,6 +68,8 @@ private static final boolean DEVELOP = true; public static final int SPARQL_RESULTSET_LIMIT = 500; + + private static final int DEPTH_OF_RDFS = 0; // the 70/30 strategy was abandoned public static double PERCENT_OF_SKOSSET = 1.0; @@ -84,13 +87,16 @@ * @param args */ public static void main(String[] args) { + SimpleClock sc = new SimpleClock(); initLogger(); setup(); logger.info("Start"); - + SortedSet<String> wikipediaCategories = new TreeSet<String>(); + + String test = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; + wikipediaCategories.add(test); test = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"; - SortedSet<String> wikipediaCategories = new TreeSet<String>(); wikipediaCategories.add(test); for (String target : wikipediaCategories) { @@ -99,7 +105,7 @@ } - System.out.println("Finished"); + sc.printAndSet("Finished"); // JamonMonitorLogger.printAllSortedByLabel(); } @@ -114,7 +120,7 @@ ConceptSPARQLReEvaluator csparql; wikiTasks = new WikipediaCategoryTasks(sparqlTasks); - csparql = new ConceptSPARQLReEvaluator(sparqlTasks); + csparql = new ConceptSPARQLReEvaluator(sparqlTasks, DEPTH_OF_RDFS, SPARQL_RESULTSET_LIMIT); // PHASE 1 ************* @@ -153,9 +159,9 @@ conceptresults = learn(getConfToRelearn(), currentPOSITIVEex, currentNEGATIVEex); // TODO select concepts - logger.info("reducing concept size before evaluating"); + logger.info("reducing concept size before evaluating from "+conceptresults.size()); conceptresults = selectConcepts(conceptresults); - // reevaluate versus the Endpoint + // reevaluate versus the Endpoint conceptresults = csparql.reevaluateConceptsByLowestRecall( conceptresults, currentPOSITIVEex); @@ -165,9 +171,13 @@ } private static void collectResults(WikipediaCategoryTasks wikiTasks) { - System.out.println(wikiTasks.getFullPositiveSet()); - System.out.println(wikiTasks.getCleanedPositiveSet()); - System.out.println(wikiTasks.getDefinitelyWrongIndividuals()); + //logger.setLevel(Level.DEBUG); + printSet("fullpos", wikiTasks.getFullPositiveSet()); + + printSet("cleanedpos", wikiTasks.getCleanedPositiveSet()); + + printSet("wrongindividuals", wikiTasks.getDefinitelyWrongIndividuals()); + } private static List<EvaluatedDescription> selectConcepts( @@ -287,6 +297,7 @@ // url = "http://dbpedia.openlinksw.com:8890/sparql"; sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint .getEndpointDBpedia()); + } } @@ -308,17 +319,19 @@ logger.addAppender(consoleAppender); logger.addAppender(fileAppender); logger.setLevel(Level.DEBUG); - Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); - Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN); Logger.getLogger(Manager.class).setLevel(Level.INFO); - Logger.getLogger(ExtractionAlgorithm.class).setLevel(Level.WARN); + Level lwarn = Level.WARN; + Logger.getLogger(KnowledgeSource.class).setLevel(lwarn); + Logger.getLogger(SparqlKnowledgeSource.class).setLevel(lwarn); + + Logger.getLogger(ExtractionAlgorithm.class).setLevel(lwarn); Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel( - Level.WARN); + lwarn); Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel( - Level.WARN); - Logger.getLogger(ExampleBasedROLComponent.class).setLevel(Level.WARN); - Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO); - Logger.getLogger(Cache.class).setLevel(Level.INFO); + lwarn); + Logger.getLogger(ExampleBasedROLComponent.class).setLevel(lwarn); + Logger.getLogger(SparqlQuery.class).setLevel(lwarn); + Logger.getLogger(Cache.class).setLevel(lwarn); } Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -99,7 +99,10 @@ // NegAsNeg doesnt exist, because all SortedSet<Individual> NegAsNeg = new TreeSet<Individual>(); - for (EvaluatedDescription ed : descToBeReevaluated) { + // elements are immediately removed from the list to save memory + while (!descToBeReevaluated.isEmpty()) { + EvaluatedDescription ed = descToBeReevaluated.remove(0); + try { instances = retrieveInstances(ed); // PosAsPos @@ -114,8 +117,13 @@ .getIndividualSet(PosAsPos), Helper .getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg)); - PosAsPos.clear(); - PosAsNeg.clear(); + }catch(Exception e){ + logger.warn("ERROR occured, while evaluating, I'm ignoring it : "+e.toString()); + logger.warn("Concept was: "+ed.getDescription().toKBSyntaxString()); + }finally{ + PosAsPos.clear(); + PosAsNeg.clear(); + } } @@ -145,11 +153,11 @@ SortedSet<Individual> NegAsPos = new TreeSet<Individual>(); SortedSet<Individual> NegAsNeg = new TreeSet<Individual>(); - + // elements are immediately removed from the list to save memory while (!descToBeReevaluated.isEmpty()) { EvaluatedDescription ed = descToBeReevaluated.remove(0); - + try { instances = retrieveInstances(ed); // PosAsPos @@ -163,10 +171,13 @@ returnSet.add(new EvaluatedDescription(ed.getDescription(), Helper .getIndividualSet(PosAsPos), Helper .getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg)); - - PosAsPos.clear(); - PosAsNeg.clear(); - + }catch(Exception e){ + logger.warn("ERROR occured, while evaluating, I'm ignoring it :"+e.toString()); + logger.warn("Concept was: "+ed.getDescription().toKBSyntaxString()); + }finally{ + PosAsPos.clear(); + PosAsNeg.clear(); + } } logger.info("finished reevaluating by lowest recall :" + returnSet.size() + " concepts"); Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -67,8 +67,9 @@ List<EvaluatedDescription> conceptresults, SortedSet<String> posExamples) { - definitelyWrongIndividuals = Helper.getStringSet(conceptresults.get(0) - .getNotCoveredPositives()); + definitelyWrongIndividuals.clear(); + definitelyWrongIndividuals.addAll(Helper.getStringSet(conceptresults.get(0) + .getNotCoveredPositives())); // clean the examples posExamples.removeAll(definitelyWrongIndividuals); @@ -145,7 +146,7 @@ * fullPositiveSet.size()); int neglimit = (int) Math.round(poslimit * negFactor); - posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit); + posExamples.addAll(SetManipulation.fuzzyShrink(fullPositiveSet, poslimit)); // NEGATIVES Added: trunk/src/dl-learner/org/dllearner/test/FilterTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/FilterTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -0,0 +1,35 @@ +package org.dllearner.test; + +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.utilities.statistics.SimpleClock; + +public class FilterTest { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + String qlong="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER( (!isLiteral(?object))&&( ( !regex(str(?predicate), 'http://dbpedia.org/property/relatedInstance') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/website') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/owner') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikiPageUsesTemplate') ) &&( !regex(str(?predicate), 'http://www.w3.org/2002/07/owl#sameAs') ) &&( !regex(str(?predicate), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/standard') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/wikipage') ) &&( !regex(str(?predicate), 'http://dbpedia.org/property/reference') ) &&( !regex(str(?predicate), 'http://www.w3.org/2004/02/skos/core') ))&&( ( !regex(str(?object), 'http://xmlns.com/foaf/0.1/') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia') ) &&( !regex(str(?object), 'http://www4.wiwiss.fu-berlin.de/flickrwrappr') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Template') ) &&( !regex(str(?object), 'http://upload.wikimedia.org/wikipedia/commons') ) &&( !regex(str(?object), 'http://www.w3.org/2006/03/wn/wn20/instances/synset') ) &&( !regex(str(?object), 'http://dbpedia.org/resource/Category:') ) &&( !regex(str(?object), 'http://www.w3.org/2004/02/skos/core') ) &&( !regex(str(?object), 'http://www.geonames.org') ))).}"; + String qshort="SELECT * WHERE { <http://dbpedia.org/resource/%22Big%22_Ron> ?predicate ?object. FILTER (!isLiteral(?object)).}"; + + SimpleClock sc = new SimpleClock(); + SPARQLTasks st = new SPARQLTasks(Cache.getPersistentCache(), SparqlEndpoint.getEndpointDBpedia()); + + for (int i = 0; i < 10; i++) { + st.query(qshort); + } + sc.printAndSet("long "); + + + + for (int i = 0; i < 10; i++) { + st.query(qlong); + } + + sc.printAndSet("short "); + } + +} Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -18,8 +18,9 @@ * @return */ public static SortedSet<String> fuzzyShrink(SortedSet<String> set, int limit) { - if (set.size() <= limit) + if (set.size() <= limit) { return set; + } SortedSet<String> ret = new TreeSet<String>(); Random r = new Random(); double treshold = ((double) limit) / set.size(); @@ -48,8 +49,9 @@ */ public static SortedSet<String> stableShrink(SortedSet<String> set, int limit) { - if (set.size() <= limit) + if (set.size() <= limit) { return set; + } SortedSet<String> ret = new TreeSet<String>(); for (String oneInd : set) { @@ -63,8 +65,9 @@ } /** + * XXX * getFirst n Elements from list. - * + * changes the list!!! * @param list * @param nrElements * @return returns the list shrunken to size. it is an ARRAYLIST now Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -111,8 +111,8 @@ String SPARQLquery = "SELECT * WHERE { \n" + "<" + oneInstance + "> " + "?p ?object. \n" + "FILTER (REGEX(str(?object), '" + objectnamespace + "')).\n" + "}"; - this.fromRelated.addAll(sparqltasks.queryAsSet(SPARQLquery, "object")); - this.fromRelated.removeAll(this.fullPositiveSet); + fromRelated.addAll(sparqltasks.queryAsSet(SPARQLquery, "object")); + fromRelated.removeAll(fullPositiveSet); } @@ -161,7 +161,7 @@ } - this.fromParallelClasses.removeAll(this.fullPositiveSet); + fromParallelClasses.removeAll(fullPositiveSet); logger.debug("|-neg Example size from parallelclass: " + fromParallelClasses.size()); } @@ -181,27 +181,27 @@ for (String oneSuperClass : superClasses) { logger.debug(oneSuperClass); - this.fromSuperclasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + fromSuperclasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + oneSuperClass + "\"", resultLimit)); } - this.fromSuperclasses.removeAll(this.fullPositiveSet); + this.fromSuperclasses.removeAll(fullPositiveSet); logger.debug("|-neg Example from superclass: " + fromSuperclasses.size()); } @SuppressWarnings("unused") private void makeNegativeExamplesFromDomain(String role, int resultLimit){ logger.debug("making Negative Examples from Domain of : "+role); - this.fromDomain.addAll(sparqltasks.getDomainInstances(role, resultLimit)); - this.fromDomain.removeAll(this.fullPositiveSet); + fromDomain.addAll(sparqltasks.getDomainInstances(role, resultLimit)); + fromDomain.removeAll(fullPositiveSet); logger.debug("|-neg Example size from Domain: "+this.fromDomain.size()); } @SuppressWarnings("unused") private void makeNegativeExamplesFromRange(String role, int resultLimit){ logger.debug("making Negative Examples from Range of : "+role); - this.fromRange.addAll(sparqltasks.getRangeInstances(role, resultLimit)); - this.fromRange.removeAll(this.fullPositiveSet); - logger.debug("|-neg Example size from Range: "+this.fromRange.size()); + fromRange.addAll(sparqltasks.getRangeInstances(role, resultLimit)); + fromRange.removeAll(fullPositiveSet); + logger.debug("|-neg Example size from Range: "+fromRange.size()); } } Modified: trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java 2008-08-02 18:25:33 UTC (rev 1045) +++ trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java 2008-08-04 08:43:26 UTC (rev 1046) @@ -42,6 +42,7 @@ // KNOWLEDGESOURCE cm.applyConfigEntry(ks, "url", sparqlEndpoint.getURL().toString()); + cm.applyConfigEntry(ks, "predefinedEndpoint", "DBPEDIA"); cm.applyConfigEntry(ks, "recursionDepth", recursiondepth); cm.applyConfigEntry(ks, "closeAfterRecursion", closeAfterRecursion); cm.applyConfigEntry(ks, "predefinedFilter", predefinedFilter); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-02 18:25:46
|
Revision: 1045 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1045&view=rev Author: kurzum Date: 2008-08-02 18:25:33 +0000 (Sat, 02 Aug 2008) Log Message: ----------- working category improver. one problem: has many parameters, which determine the outcome it has to be tested which are the best. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Info.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java Modified: trunk/src/dl-learner/org/dllearner/Info.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Info.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/Info.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -3,6 +3,6 @@ package org.dllearner; public class Info { - public static final String build = "2008-05-15"; + public static final String build = "2008-08-01"; } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -24,7 +24,6 @@ import java.util.Vector; import org.apache.log4j.Logger; -import org.dllearner.core.KnowledgeSource; /** * This class is used to extract the information . @@ -39,7 +38,7 @@ // private boolean getAllSuperClasses = true; // private boolean closeAfterRecursion = true; private static Logger logger = Logger - .getLogger(KnowledgeSource.class); + .getLogger(ExtractionAlgorithm.class); public ExtractionAlgorithm(Configuration Configuration) { this.configuration = Configuration; @@ -75,7 +74,7 @@ //System.out.println(this.configuration); long time = System.currentTimeMillis(); Node n = getFirstNode(uri); - System.out.println(n); + logger.info(n); Vector<Node> v = new Vector<Node>(); v.add(n); logger.info("StartVector: " + v); Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -25,7 +25,6 @@ import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.core.KnowledgeSource; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryType; import org.dllearner.utilities.statistics.Statistics; @@ -43,7 +42,7 @@ private ExtractionAlgorithm extractionAlgorithm; private static Logger logger = Logger - .getLogger(KnowledgeSource.class); + .getLogger(Manager.class); public void useConfiguration(SparqlQueryType SparqlQueryType, @@ -77,12 +76,14 @@ public String extract(Set<String> instances) { // this.TypedSparqlQuery.query(uri); // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); - System.out.println("Start extracting"); + logger.info("Start extracting"); SortedSet<String> ret = new TreeSet<String>(); int progress=0; for (String one : instances) { progress++; - logger.info("Progress: "+progress+" of "+instances.size()+" finished"); + //if(progress % 10 == 0) { + logger.info("Progress: "+progress+" of "+instances.size()+" finished: "+one); + //} try { Node n = extractionAlgorithm.expandNode(new URI(one), typedSparqlQuery); @@ -91,15 +92,15 @@ e.printStackTrace(); } } - System.out.println("Finished extracting, start conversion"); + logger.info("Finished extracting, start conversion"); StringBuffer nt = new StringBuffer(); Object[] arr = ret.toArray(); for (int i = 0; i < arr.length; i++) { nt.append((String) arr[i] + "\n"); if (i % 1000 == 0) - System.out.println(i + " of " + arr.length + " triples done"); + logger.info(i + " of " + arr.length + " triples done"); } - System.out.println(arr.length + " of " + arr.length + " triples done"); + logger.info(arr.length + " of " + arr.length + " triples done"); /* * String tmp=""; while ( ret.size() > 0) { tmp=ret.first(); nt+=tmp; * ret.remove(tmp); System.out.println(ret.size()); } /*for (String str : Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -23,24 +23,33 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.owl.Individual; +import org.dllearner.kb.extraction.ExtractionAlgorithm; +import org.dllearner.kb.extraction.Manager; import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.scripts.improveWikipedia.ConceptSPARQLReEvaluator; import org.dllearner.scripts.improveWikipedia.ConceptSelector; import org.dllearner.scripts.improveWikipedia.WikipediaCategoryTasks; -import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; +import org.dllearner.utilities.learn.LearnSPARQLConfiguration; +import org.dllearner.utilities.learn.LearnSparql; public class WikipediaCategoryCleaner { @@ -50,93 +59,173 @@ private static Logger logger = Logger.getRootLogger(); - private static boolean local = true; // localEndpoint switch + // localEndpoint switch + private static final boolean LOCAL = false; // parameters - public static final int SPARQL_RESULTSET_LIMIT = 1000; + // used for developing, + private static final boolean DEVELOP = true; - public static double PERCENT_OF_SKOSSET = 1.0; // the 70/30 strategy was + public static final int SPARQL_RESULTSET_LIMIT = 500; - // abandoned + // the 70/30 strategy was abandoned + public static double PERCENT_OF_SKOSSET = 1.0; - public static double NEGFACTOR = 1.0; // size of randomly choosen negative + // size of randomly choosen negative examples compared to positives + public static double NEGFACTOR = 1.0; - // examples compared to positives + public static int MAX_NR_CONCEPTS_TO_BE_EVALUATED = Integer.MAX_VALUE; + public static double ACCURACY_THRESHOLD = 0.0; + + public static String FILTER_CONCEPTS_BY = "Entity"; + /** * @param args */ public static void main(String[] args) { initLogger(); + setup(); logger.info("Start"); - // SETUP cache and sparqltasks - cache = Cache.getPersistentCache(); + String test = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; + test = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"; + SortedSet<String> wikipediaCategories = new TreeSet<String>(); + wikipediaCategories.add(test); - if (local) { - // url = "http://139.18.2.37:8890/sparql"; - sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint - .getEndpointLOCALDBpedia()); - } else { - // url = "http://dbpedia.openlinksw.com:8890/sparql"; - sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint - .getEndpointDBpedia()); + for (String target : wikipediaCategories) { + + doit(target); + } - String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; - target = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"; + System.out.println("Finished"); + // JamonMonitorLogger.printAllSortedByLabel(); - WikipediaCategoryTasks s = new WikipediaCategoryTasks(sparqlTasks); - // TODO Optimize - s.calculateDefinitelyWrongIndividuals(target, PERCENT_OF_SKOSSET, - NEGFACTOR, SPARQL_RESULTSET_LIMIT); + } - logger.info("Found " + s.getDefinitelyWrongIndividuals().size() - + " incorrect individuals"); - logger.debug("incorrect Individuals: " - + s.getDefinitelyWrongIndividuals()); - logger.info("reevaluating " + s.getConceptresults().size() - + " found Concepts"); - logger - .info("END OF PHASE 1 **********************************************"); + private static void doit(String target) { + List<EvaluatedDescription> conceptresults; + SortedSet<String> currentPOSITIVEex = new TreeSet<String>(); + SortedSet<String> currentNEGATIVEex = new TreeSet<String>(); + SortedSet<String> wrongIndividuals; - s.reevaluateAndRelearn(); - List<EvaluatedDescription> newEval = s.getConceptresults(); - printEvaluatedDescriptionCollection(5, newEval); + WikipediaCategoryTasks wikiTasks; + ConceptSPARQLReEvaluator csparql; - System.out.println("Finished"); - JamonMonitorLogger.printAllSortedByLabel(); + wikiTasks = new WikipediaCategoryTasks(sparqlTasks); + csparql = new ConceptSPARQLReEvaluator(sparqlTasks); + // PHASE 1 ************* + + wikiTasks.makeInitialExamples(target, PERCENT_OF_SKOSSET, NEGFACTOR, + SPARQL_RESULTSET_LIMIT, DEVELOP); + currentPOSITIVEex.addAll(wikiTasks.getPosExamples()); + currentNEGATIVEex.addAll(wikiTasks.getNegExamples()); + // get wrong individuals and reevaluate concepts + conceptresults = learn(getConfToFindWrongIndividuals(), + currentPOSITIVEex, currentNEGATIVEex); + // TODO select concepts + conceptresults = selectConcepts(conceptresults); + wrongIndividuals = wikiTasks.calculateWrongIndividualsAndNewPosEx( + conceptresults, currentPOSITIVEex); + currentPOSITIVEex.clear(); + currentPOSITIVEex.addAll(wikiTasks.getCleanedPositiveSet()); + + // reevaluate versus the Endpoint + conceptresults = csparql.reevaluateConceptsByLowestRecall( + conceptresults, currentPOSITIVEex); + + WikipediaCategoryCleaner.printEvaluatedDescriptionCollection(2, + conceptresults); + + printIntermediateResults(wikiTasks.getFullPositiveSet(), + wikiTasks.getCleanedPositiveSet(), + wrongIndividuals, conceptresults.size()); + + // PHASE 2 *********************** + logger.info("PHASE 2 ***********************"); + logger.info("making new Negative Examples"); + currentNEGATIVEex = wikiTasks.makeNewNegativeExamples(conceptresults, + currentPOSITIVEex, NEGFACTOR); + + logger.info("learning"); + conceptresults = learn(getConfToRelearn(), currentPOSITIVEex, + currentNEGATIVEex); + // TODO select concepts + logger.info("reducing concept size before evaluating"); + conceptresults = selectConcepts(conceptresults); + // reevaluate versus the Endpoint + conceptresults = csparql.reevaluateConceptsByLowestRecall( + conceptresults, currentPOSITIVEex); + + printEvaluatedDescriptionCollection(2, conceptresults); + collectResults(wikiTasks); + } - private static void initLogger() { + private static void collectResults(WikipediaCategoryTasks wikiTasks) { + System.out.println(wikiTasks.getFullPositiveSet()); + System.out.println(wikiTasks.getCleanedPositiveSet()); + System.out.println(wikiTasks.getDefinitelyWrongIndividuals()); + } - SimpleLayout layout = new SimpleLayout(); - // create logger (a simple logger which outputs - // its messages to the console) - FileAppender fileAppender = null; + private static List<EvaluatedDescription> selectConcepts( + List<EvaluatedDescription> concepts) { + // TODO maybe not smart here + ConceptSelector cs = new ConceptSelector(); + concepts = cs.getConceptsNotContainingString(concepts, + FILTER_CONCEPTS_BY, MAX_NR_CONCEPTS_TO_BE_EVALUATED); + if (concepts.size() == 0) { + logger.warn("NO GOOD CONCEPTS FOUND"); + // TODO if this happens there has to be a fallback + } + return concepts; + } + + /** + * All Concepts are returned, filtering these are done separately + * + * @param conf + * @param posExamples + * @param negExamples + * @return + */ + private static List<EvaluatedDescription> learn( + LearnSPARQLConfiguration conf, SortedSet<String> posExamples, + SortedSet<String> negExamples) { + LearnSparql learner = new LearnSparql(getConfToRelearn()); + LearningAlgorithm la = null; try { - fileAppender = new FileAppender(layout, "log/progress/skos" - + ConceptSelector.time() + ".txt", false); + la = learner.learn(posExamples, negExamples); } catch (Exception e) { e.printStackTrace(); } + List<EvaluatedDescription> conceptresults = la + .getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, 0.0, + true); + return conceptresults; + } - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.addAppender(fileAppender); - logger.setLevel(Level.DEBUG); - Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); + private static LearnSPARQLConfiguration getConfToFindWrongIndividuals() { + LearnSPARQLConfiguration lsc = new LearnSPARQLConfiguration(); + lsc.sparqlEndpoint = sparqlTasks.getSparqlEndpoint(); - Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO); - Logger.getLogger(Cache.class).setLevel(Level.INFO); - Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel( - Level.INFO); - Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel( - Level.INFO); + lsc.noisePercentage = 15; + lsc.guaranteeXgoodDescriptions = 200; + lsc.maxExecutionTimeInSeconds = 50; + lsc.logLevel = "INFO"; + // lsc.searchTreeFile = "log/WikipediaCleaner.txt"; + + return lsc; + } + private static LearnSPARQLConfiguration getConfToRelearn() { + return getConfToFindWrongIndividuals(); + + } + public static void printEvaluatedDescriptionCollection(int howMany, Collection<EvaluatedDescription> c) { int x = 0; @@ -147,10 +236,10 @@ first = ed.getNotCoveredPositives(); } if (x >= howMany) { - x++; + break; } - + x++; tmp.addAll(ed.getNotCoveredPositives()); tmp.removeAll(first); logger.debug("*************************"); @@ -163,4 +252,74 @@ } } + + + private static void printIntermediateResults( + SortedSet fullSet, + SortedSet correctIndividuals, + SortedSet wrongIndividuals, + int numberOfConcepts) { + printSet("full Individual set: ", fullSet); + + printSet("correct Individuals: ", correctIndividuals); + printSet("incorrect Individuals: ", wrongIndividuals); + logger.info("reevaluated " + numberOfConcepts + " found Concepts"); + logger.info("END OF PHASE 1 **********************"); + } + private static void printSet(String s, SortedSet set) { + if(logger.getLevel().equals(Level.DEBUG)){ + logger.info(s +" ["+ set.size()+"]: "+set); + }else{ + logger.info(s +" ["+ set.size()+"]"); + } + + } + + private static void setup() { + // SETUP cache and sparqltasks + cache = Cache.getPersistentCache(); + + if (LOCAL) { + // url = "http://139.18.2.37:8890/sparql"; + sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint + .getEndpointLOCALDBpedia()); + } else { + // url = "http://dbpedia.openlinksw.com:8890/sparql"; + sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint + .getEndpointDBpedia()); + } + } + + private static void initLogger() { + + SimpleLayout layout = new SimpleLayout(); + // create logger (a simple logger which outputs + // its messages to the console) + FileAppender fileAppender = null; + try { + fileAppender = new FileAppender(layout, "log/progress/skos" + + ConceptSelector.time() + ".txt", false); + } catch (Exception e) { + e.printStackTrace(); + } + + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.addAppender(fileAppender); + logger.setLevel(Level.DEBUG); + Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); + Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN); + Logger.getLogger(Manager.class).setLevel(Level.INFO); + Logger.getLogger(ExtractionAlgorithm.class).setLevel(Level.WARN); + Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel( + Level.WARN); + Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel( + Level.WARN); + Logger.getLogger(ExampleBasedROLComponent.class).setLevel(Level.WARN); + Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO); + Logger.getLogger(Cache.class).setLevel(Level.INFO); + + } + } Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -32,11 +32,10 @@ import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; /** - * @author Sebastian Hellmann + * @author Sebastian Hellmann * - * The EvaluatedDescriptions from a fragment are - * validated against the SPARQLendpoint. - * There are different strategies, see the methods; + * The EvaluatedDescriptions from a fragment are validated against the + * SPARQLendpoint. There are different strategies, see the methods; */ public class ConceptSPARQLReEvaluator { @@ -51,33 +50,29 @@ int depthOfRDFS = 1; - public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks, - List<EvaluatedDescription> descToBeReevaluated) { - this.descToBeReevaluated = descToBeReevaluated; + /** + * Constructor using default settings + * + * @param sparqlTasks + */ + public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks) { this.sparqlTasks = sparqlTasks; } - public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks, - List<EvaluatedDescription> descToBeReevaluated, int depthOfRDFS, + /** + * constructor to manually set parameters + * + * @param sparqlTasks + * @param depthOfRDFS + * @param sparqlResultLimit + */ + public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks, int depthOfRDFS, int sparqlResultLimit) { - this(sparqlTasks, descToBeReevaluated); + this(sparqlTasks); this.depthOfRDFS = depthOfRDFS; this.sparqlResultLimit = sparqlResultLimit; } - - public List<EvaluatedDescription> reevaluateConceptsByDataCoverage( - SortedSet<String> positiveSet, int maxNrOfConcepts) { - List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet); - List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>(); - - while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) { - returnSet.add(tmp.remove(0)); - } - - return returnSet; - } - /** * Accuracy is calculated as correct positive classified over (correct * positive classified + incorrect negative classified) "How many are @@ -88,6 +83,7 @@ * @return */ public List<EvaluatedDescription> reevaluateConceptsByDataCoverage( + List<EvaluatedDescription> descToBeReevaluated, SortedSet<String> positiveSet) { SortedSet<EvaluatedDescription> returnSet = new TreeSet<EvaluatedDescription>( @@ -127,18 +123,6 @@ } - public List<EvaluatedDescription> reevaluateConceptsByLowestRecall( - SortedSet<String> positiveSet, int maxNrOfConcepts) { - List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet); - List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>(); - - while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) { - returnSet.add(tmp.remove(0)); - } - - return returnSet; - } - /** * Accuracy is calculated as correct positive classified over all retrieved * e.g. 50 correct out of 400 retrieved (50/400) @@ -147,6 +131,7 @@ * @return */ public List<EvaluatedDescription> reevaluateConceptsByLowestRecall( + List<EvaluatedDescription> descToBeReevaluated, SortedSet<String> positiveSet) { logger.info("reevaluating by lowest recall " + descToBeReevaluated.size() + " concepts"); @@ -159,7 +144,6 @@ SortedSet<String> PosAsNeg = new TreeSet<String>(); SortedSet<Individual> NegAsPos = new TreeSet<Individual>(); - SortedSet<Individual> NegAsNeg = new TreeSet<Individual>(); // elements are immediately removed from the list to save memory @@ -197,4 +181,30 @@ kbsyntax, sparqlResultLimit, depthOfRDFS); } + /* + * public List<EvaluatedDescription> reevaluateConceptsByLowestRecall( List<EvaluatedDescription> + * descToBeReevaluated, SortedSet<String> positiveSet, int maxNrOfConcepts) { + * List<EvaluatedDescription> tmp = + * reevaluateConceptsByLowestRecall(descToBeReevaluated, positiveSet); List<EvaluatedDescription> + * returnSet = new ArrayList<EvaluatedDescription>(); + * + * while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) { + * returnSet.add(tmp.remove(0)); } + * + * return returnSet; } + */ + + /* + * public List<EvaluatedDescription> reevaluateConceptsByDataCoverage( List<EvaluatedDescription> + * descToBeReevaluated, SortedSet<String> positiveSet, int maxNrOfConcepts) { + * List<EvaluatedDescription> tmp = + * reevaluateConceptsByLowestRecall(descToBeReevaluated, positiveSet); List<EvaluatedDescription> + * returnSet = new ArrayList<EvaluatedDescription>(); + * + * while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) { + * returnSet.add(tmp.remove(0)); } + * + * return returnSet; } + */ + } Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -24,79 +24,69 @@ import java.util.List; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.LearningAlgorithm; import org.dllearner.utilities.Files; +import org.dllearner.utilities.datastructures.SetManipulation; /** - * This is a simple class, it might be worked into other classes later. - * filters concepts and records some results + * This is a simple class, it might be worked into other classes later. filters + * concepts and records some results * * @author Sebastian Hellmann - * + * */ public class ConceptSelector { private static final long WASH = 1216800000000L; - - List<EvaluatedDescription> concepts; - - public ConceptSelector(LearningAlgorithm la) { + + // List<EvaluatedDescription> concepts; + + public ConceptSelector() { super(); - this.concepts = la.getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, 0.0, true); - this.recordConceptClasses(); - + // this.concepts = concepts; + // this.recordConceptClasses(); + } - - - public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts) { - super(); - this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts); - + + public List<EvaluatedDescription> getAllConceptsWithoutOR( + List<EvaluatedDescription> concepts) { + return getConceptsNotContainingString(concepts, "OR"); } - - public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts, double acctreshold) { - super(); - this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts, acctreshold, true); - this.recordConceptClasses(); + + @SuppressWarnings("unchecked") + public List<EvaluatedDescription> getConceptsNotContainingString( + List<EvaluatedDescription> concepts, String filterString, + int limitSize) { + // List<EvaluatedDescription> tmp = + // getConceptsNotContainingString(filterString); + // List<EvaluatedDescription> result = new + // ArrayList<EvaluatedDescription>(); + return SetManipulation.getFirst(getConceptsNotContainingString( + concepts, filterString), limitSize); + /* + * while ((!tmp.isEmpty()) && (result.size() <= limitSize)) { + * result.add(tmp.remove(0)); } return result; + */ } - - public List<EvaluatedDescription> getConceptsWithoutOR(){ - return getConceptsNotContainingString("OR"); - } - - public List<EvaluatedDescription> getConceptsNotContainingString(String filterString, int limitSize){ - List<EvaluatedDescription> tmp = getConceptsNotContainingString(filterString); - List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>(); - - while ((!tmp.isEmpty()) && (result.size() <= limitSize)) { - result.add(tmp.remove(0)); - } - return result; - } - - - public List<EvaluatedDescription> getConceptsNotContainingString(String filterString){ - + + public List<EvaluatedDescription> getConceptsNotContainingString( + List<EvaluatedDescription> concepts, String filterString) { + List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>(); for (EvaluatedDescription description : concepts) { if (!description.toString().contains(filterString)) { - result.add(description); + result.add(description); } - + } return result; } - - - - public void recordConceptClasses() { - StringBuffer result =new StringBuffer(); - StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n"); - StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n"); + public void recordConceptClasses(List<EvaluatedDescription> concepts) { + StringBuffer result = new StringBuffer(); + StringBuffer result1 = new StringBuffer("\n\n ***********Entity*****\n"); + StringBuffer result2 = new StringBuffer("\n\n ***********OR*****\n"); int result1count = 1; int result2count = 1; - int x = 0; for (EvaluatedDescription description : concepts) { @@ -121,7 +111,7 @@ Files.createFile(new File("results/descriptions/concepts" + time() + ".txt"), result.toString()); } - + public static String time() { return ("" + (System.currentTimeMillis() - WASH)).substring(0, 7); Modified: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -19,90 +19,62 @@ */ package org.dllearner.scripts.improveWikipedia; -import java.util.ArrayList; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.LearningAlgorithm; import org.dllearner.kb.sparql.SPARQLTasks; -import org.dllearner.scripts.WikipediaCategoryCleaner; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; -import org.dllearner.utilities.learn.LearnSPARQLConfiguration; -import org.dllearner.utilities.learn.LearnSparql; public class WikipediaCategoryTasks { private static Logger logger = Logger .getLogger(WikipediaCategoryTasks.class); - private static final boolean STABLE = true; // used for developing, same - - // negExamples not random - - private static final int MAXIMUM_NUMBER_OF_CONCEPTS_KEPT = Integer.MAX_VALUE; - - private static final double ACCTRESHOLD = 0.0; - private SPARQLTasks sparqlTasks; + // these cahnge all the time private SortedSet<String> posExamples = new TreeSet<String>(); - private SortedSet<String> fullPositiveSet = new TreeSet<String>(); + private SortedSet<String> negExamples = new TreeSet<String>(); - // private SortedSet<String> fullPosSetWithoutPosExamples = new - // TreeSet<String>(); + // these dont change, they are for collecting + private SortedSet<String> cleanedPositiveSet = new TreeSet<String>(); - private SortedSet<String> negExamples = new TreeSet<String>(); + private SortedSet<String> fullPositiveSet = new TreeSet<String>(); private SortedSet<String> definitelyWrongIndividuals = new TreeSet<String>(); - private List<EvaluatedDescription> conceptresults = new ArrayList<EvaluatedDescription>(); - public WikipediaCategoryTasks(SPARQLTasks sparqlTasks) { this.sparqlTasks = sparqlTasks; } /** - * @param SKOSConcept - * @param percentOfSKOSSet - * @param negfactor - * @param sparqlResultLimit + * The strategy is yet really simple. //TODO take the best concept and the + * notCoveredPositives are the ones definitely wrong these are removed from + * the positives examples. + * + * @param conceptresults + * @param posExamples + * @return */ - public void calculateDefinitelyWrongIndividuals(String SKOSConcept, - double percentOfSKOSSet, double negfactor, int sparqlResultLimit) { + public SortedSet<String> calculateWrongIndividualsAndNewPosEx( + List<EvaluatedDescription> conceptresults, + SortedSet<String> posExamples) { - makeExamples(SKOSConcept, percentOfSKOSSet, negfactor, - sparqlResultLimit); - - LearnSparql learner = new LearnSparql( - prepareConfigurationToFindWrongIndividuals()); - LearningAlgorithm la = null; - try { - la = learner.learn(posExamples, negExamples); - } catch (Exception e) { - e.printStackTrace(); - } - // TODO maybe not smart here - ConceptSelector cs = new ConceptSelector(la, - MAXIMUM_NUMBER_OF_CONCEPTS_KEPT, ACCTRESHOLD); - conceptresults = cs.getConceptsNotContainingString("Entity", - MAXIMUM_NUMBER_OF_CONCEPTS_KEPT); - if (conceptresults.size() == 0) { - logger.warn("NO GOOD CONCEPTS FOUND"); - } - definitelyWrongIndividuals = Helper.getStringSet(conceptresults.get(0) .getNotCoveredPositives()); // clean the examples posExamples.removeAll(definitelyWrongIndividuals); - fullPositiveSet.removeAll(definitelyWrongIndividuals); + this.posExamples.clear(); + this.posExamples.addAll(posExamples); + this.cleanedPositiveSet.addAll(posExamples); // fullPosSetWithoutPosExamples.removeAll(definitelyWrongIndividuals); logger.trace("posExamples" + posExamples.size()); @@ -110,25 +82,24 @@ negExamples.clear(); + return definitelyWrongIndividuals; + } - public void reevaluateAndRelearn() { + /** + * TODO could be more sophisticated + * + * @param reEvaluatedDesc + * @return + */ + public SortedSet<String> makeNewNegativeExamples( + List<EvaluatedDescription> reEvaluatedDesc, + SortedSet<String> posExamples, double negFactor) { + negExamples.clear(); - ConceptSPARQLReEvaluator csparql = new ConceptSPARQLReEvaluator( - sparqlTasks, conceptresults); - List<EvaluatedDescription> reEvaluatedDesc; - - // TODO Optimize here - reEvaluatedDesc = csparql.reevaluateConceptsByLowestRecall( - fullPositiveSet, 1); - - // TODO add check if it is correct - WikipediaCategoryCleaner.printEvaluatedDescriptionCollection(10, - reEvaluatedDesc); EvaluatedDescription newDesc = reEvaluatedDesc.get(0); logger.info("Best concept: " + newDesc.getDescription()); - negExamples.clear(); negExamples.addAll(Helper.getStringSet(newDesc.getCoveredPositives())); negExamples.addAll(Helper .getStringSet(newDesc.getNotCoveredPositives())); @@ -137,33 +108,28 @@ .getStringSet(newDesc.getNotCoveredNegatives())); negExamples.removeAll(posExamples); - // TODO could be more negatives - negExamples = SetManipulation.fuzzyShrink(negExamples, posExamples - .size()); - LearnSparql learner = new LearnSparql(prepareConfigurationToRelearn()); - LearningAlgorithm la = null; - try { - la = learner.learn(posExamples, negExamples); - } catch (Exception e) { - e.printStackTrace(); - } - conceptresults = la.getCurrentlyBestEvaluatedDescriptions(500, - ACCTRESHOLD, true); + int neglimit = (int) Math.round(posExamples.size() * negFactor); + negExamples = SetManipulation.fuzzyShrink(negExamples, neglimit); + return negExamples; } /** - * @param SKOSConcept + * makes positive and negative Examples. positives are a simple retrieval of + * the category. negatives are made from parallelclasses. + * + * @param targetCategory * @param percentOfSKOSSet * percentage used from the SKOSSet for training - * @param negfactor + * @param negFactor * size of the negative Examples compared to the posExample size * (1.0 means equal size) * @param sparqlResultLimit */ - public void makeExamples(String SKOSConcept, double percentOfSKOSSet, - double negfactor, int sparqlResultLimit) { + public void makeInitialExamples(String targetCategory, + double percentOfSKOSSet, double negFactor, int sparqlResultLimit, + boolean develop) { fullPositiveSet.clear(); // fullPosSetWithoutPosExamples.clear(); posExamples.clear(); @@ -172,12 +138,12 @@ // POSITIVES AutomaticPositiveExampleFinderSPARQL apos = new AutomaticPositiveExampleFinderSPARQL( sparqlTasks); - apos.makePositiveExamplesFromSKOSConcept(SKOSConcept); - fullPositiveSet = apos.getPosExamples(); + apos.makePositiveExamplesFromSKOSConcept(targetCategory); + fullPositiveSet.addAll(apos.getPosExamples()); int poslimit = (int) Math.round(percentOfSKOSSet * fullPositiveSet.size()); - int neglimit = (int) Math.round(poslimit * negfactor); + int neglimit = (int) Math.round(poslimit * negFactor); posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit); @@ -188,7 +154,7 @@ aneg.makeNegativeExamplesFromParallelClasses(posExamples, sparqlResultLimit); - negExamples = aneg.getNegativeExamples(neglimit, STABLE); + negExamples = aneg.getNegativeExamples(neglimit, develop); logger.debug("POSITIVE EXAMPLES"); for (String pos : posExamples) { @@ -209,25 +175,6 @@ } - private LearnSPARQLConfiguration prepareConfigurationToFindWrongIndividuals() { - LearnSPARQLConfiguration lsc = new LearnSPARQLConfiguration(); - lsc.sparqlEndpoint = sparqlTasks.getSparqlEndpoint(); - - lsc.noisePercentage = 15; - lsc.guaranteeXgoodDescriptions = 200; - lsc.maxExecutionTimeInSeconds = 50; - lsc.logLevel = "INFO"; - // lsc.searchTreeFile = "log/WikipediaCleaner.txt"; - - return lsc; - - } - - private LearnSPARQLConfiguration prepareConfigurationToRelearn() { - return prepareConfigurationToFindWrongIndividuals(); - - } - public SortedSet<String> getPosExamples() { return posExamples; } @@ -244,8 +191,8 @@ return definitelyWrongIndividuals; } - public List<EvaluatedDescription> getConceptresults() { - return conceptresults; + public SortedSet<String> getCleanedPositiveSet() { + return cleanedPositiveSet; } } Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/SetManipulation.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -1,5 +1,6 @@ package org.dllearner.utilities.datastructures; +import java.util.List; import java.util.Random; import java.util.SortedSet; import java.util.TreeSet; @@ -8,57 +9,75 @@ public class SetManipulation { - /** - * shrinks a set to the limit - * fuzzy here means the elements will be randomly picked + * shrinks a set to the limit fuzzy here means the elements will be randomly + * picked + * * @param set * @param limit * @return */ public static SortedSet<String> fuzzyShrink(SortedSet<String> set, int limit) { - if (set.size()<=limit)return set; + if (set.size() <= limit) + return set; SortedSet<String> ret = new TreeSet<String>(); Random r = new Random(); - double treshold = ((double)limit)/set.size(); - //System.out.println("treshold"+howmany); - //System.out.println("treshold"+allRetrieved.size()); - //System.out.println("treshold"+treshold); - - - while(ret.size()< limit){ + double treshold = ((double) limit) / set.size(); + // System.out.println("treshold"+howmany); + // System.out.println("treshold"+allRetrieved.size()); + // System.out.println("treshold"+treshold); + + while (ret.size() < limit) { for (String oneInd : set) { - if(r.nextDouble()<treshold) { + if (r.nextDouble() < treshold) { ret.add(oneInd); - if(ret.size()>= limit)break; + if (ret.size() >= limit) + break; } } } return ret; } - + /** - * shrinks a set to the limit - * takes the first elements up to limit + * shrinks a set to the limit takes the first elements up to limit + * * @param set * @param limit * @return */ - public static SortedSet<String> stableShrink(SortedSet<String> set, int limit) { - if (set.size()<=limit)return set; + public static SortedSet<String> stableShrink(SortedSet<String> set, + int limit) { + if (set.size() <= limit) + return set; SortedSet<String> ret = new TreeSet<String>(); - - + for (String oneInd : set) { ret.add(oneInd); - if(ret.size()>= limit)break; - + if (ret.size() >= limit) + break; + } - + return ret; } - - public static SortedSet<Individual> stringToInd(SortedSet<String> set ){ + + /** + * getFirst n Elements from list. + * + * @param list + * @param nrElements + * @return returns the list shrunken to size. it is an ARRAYLIST now + */ + public static List getFirst(List list, int nrElements) { + int size; + while ((size = list.size()) > nrElements) { + list.remove(size - 1); + } + return list; + } + + public static SortedSet<Individual> stringToInd(SortedSet<String> set) { SortedSet<Individual> ret = new TreeSet<Individual>(); for (String ind : set) { ret.add(new Individual(ind)); Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-31 16:37:22 UTC (rev 1044) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-08-02 18:25:33 UTC (rev 1045) @@ -129,16 +129,17 @@ }*/ /** - * makes neg ex from classes, the pos ex belong to + * makes negEx from classes, the posEx belong to. + * Gets all Classes from PosEx, gets Instances from these Classes, returns all * @param positiveSet - * @param resultLimit + * @param sparqlResultLimit */ - public void makeNegativeExamplesFromParallelClasses(SortedSet<String> positiveSet, int resultLimit){ - makeNegativeExamplesFromClassesOfInstances(positiveSet, resultLimit); + public void makeNegativeExamplesFromParallelClasses(SortedSet<String> positiveSet, int sparqlResultLimit){ + makeNegativeExamplesFromClassesOfInstances(positiveSet, sparqlResultLimit); } private void makeNegativeExamplesFromClassesOfInstances(SortedSet<String> positiveSet, - int resultLimit) { + int sparqlResultLimit) { logger.debug("making neg Examples from parallel classes"); SortedSet<String> classes = new TreeSet<String>(); // superClasses.add(concept.replace("\"", "")); @@ -148,7 +149,7 @@ // superclasses"); for (String instance : positiveSet) { - classes.addAll(sparqltasks.getClassesForInstance(instance, resultLimit)); + classes.addAll(sparqltasks.getClassesForInstance(instance, sparqlResultLimit)); } logger.debug("getting negExamples from " + classes.size() + " parallel classes"); for (String oneClass : classes) { @@ -156,7 +157,7 @@ // rsc = new // JenaResultSetConvenience(queryConcept("\""+oneClass+"\"",limit)); this.fromParallelClasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + oneClass - + "\"", resultLimit)); + + "\"", sparqlResultLimit)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:37:25
|
Revision: 1044 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1044&view=rev Author: kurzum Date: 2008-07-31 16:37:22 +0000 (Thu, 31 Jul 2008) Log Message: ----------- small changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-07-31 16:33:29 UTC (rev 1043) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-07-31 16:37:22 UTC (rev 1044) @@ -84,8 +84,7 @@ } String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; - // target = - // "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"; + target = "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"; WikipediaCategoryTasks s = new WikipediaCategoryTasks(sparqlTasks); // TODO Optimize This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-31 16:33:38
|
Revision: 1043 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1043&view=rev Author: jenslehmann Date: 2008-07-31 16:33:29 +0000 (Thu, 31 Jul 2008) Log Message: ----------- - EL downward refinement operator started - cleanup Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/utilities/Helper.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -207,7 +207,7 @@ if(length==1) { generatedDefinitions.get(1).add(new Thing()); generatedDefinitions.get(1).add(new Nothing()); - for(NamedClass atomicConcept : rs.getAtomicConcepts()) { + for(NamedClass atomicConcept : rs.getNamedClasses()) { generatedDefinitions.get(1).add(atomicConcept); } } @@ -265,7 +265,7 @@ // EXISTS and ALL for(Description childNode : generatedDefinitions.get(length-2)) { - for(ObjectProperty atomicRole : rs.getAtomicRoles()) { + for(ObjectProperty atomicRole : rs.getObjectProperties()) { Description root1 = new ObjectSomeRestriction(atomicRole,childNode); generatedDefinitions.get(length).add(root1); Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -61,7 +61,7 @@ // to simplify equivalence checks and minimisation, we // attach a simulation relation to the description tree - private Simulation simulation; +// private Simulation simulation; /** * Constructs an empty EL description tree with the empty set @@ -69,7 +69,7 @@ */ public ELDescriptionTree() { this(new TreeSet<NamedClass>(), new LinkedList<Edge>()); - simulation = new Simulation(); +// simulation = new Simulation(); } /** @@ -189,4 +189,10 @@ return level; } + @Override + public ELDescriptionTree clone() { + // TODO implement efficient tree cloning + return null; + } + } Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -492,7 +492,7 @@ private static Description pickTerminalSymbol(LearningProblem learningProblem, ReasoningService rs, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); int nr; - int nrOfConcepts = rs.getAtomicConcepts().size(); + int nrOfConcepts = rs.getNamedClasses().size(); // ein Blattknoten kann folgendes sein: // Top, Bottom, Konzept => alles am Besten gleichwahrscheinlich @@ -631,7 +631,7 @@ private static Description createFullRandomTree(LearningProblem learningProblem, ReasoningService rs, int depth, boolean useADC) { // FlatABox abox = FlatABox.getInstance(); - int numberOfRoles = rs.getAtomicRoles().size(); // abox.roles.size(); + int numberOfRoles = rs.getObjectProperties().size(); // abox.roles.size(); if (depth > 1) { int nr = rand.nextInt(3+2*numberOfRoles); @@ -725,8 +725,8 @@ */ // FlatABox abox = FlatABox.getInstance(); - int numberOfConcepts = rs.getAtomicConcepts().size(); - int numberOfRoles = rs.getAtomicRoles().size(); + int numberOfConcepts = rs.getNamedClasses().size(); + int numberOfRoles = rs.getObjectProperties().size(); // TODO: ev. größere Wahrscheinlichkeit für Konjunktion/Disjunktion (?), // mit größerer Konzept-, und Rollenanzahl kommen die sonst kaum noch vor int numberOfAlphabetSymbols = numberOfConcepts + 2*numberOfRoles + 5; //7;// 5; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -316,9 +316,9 @@ usedRoles = allowedRoles; } else if(ignoredRoles != null) { Helper.checkRoles(rs, ignoredRoles); - usedRoles = Helper.difference(rs.getAtomicRoles(), ignoredRoles); + usedRoles = Helper.difference(rs.getObjectProperties(), ignoredRoles); } else { - usedRoles = rs.getAtomicRoles(); + usedRoles = rs.getObjectProperties(); } // prepare subsumption and role hierarchies, because they are needed Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -357,9 +357,9 @@ usedRoles = allowedRoles; } else if(ignoredRoles != null) { Helper.checkRoles(rs, ignoredRoles); - usedRoles = Helper.difference(rs.getAtomicRoles(), ignoredRoles); + usedRoles = Helper.difference(rs.getObjectProperties(), ignoredRoles); } else { - usedRoles = rs.getAtomicRoles(); + usedRoles = rs.getObjectProperties(); } // prepare subsumption and role hierarchies, because they are needed Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -512,25 +512,25 @@ } } else if (name.equals("showConcepts")) { if (cliOption.getStringValue().equals("true")) { - int stringLength = rs.getAtomicConcepts().toString().length(); + int stringLength = rs.getNamedClasses().toString().length(); if (stringLength > maxLineLength) { - System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: "); - for (NamedClass ac : rs.getAtomicConcepts()) + System.out.println("concepts[" + rs.getNamedClasses().size() + "]: "); + for (NamedClass ac : rs.getNamedClasses()) System.out.println(" " + ac); } else - System.out.println("concepts[" + rs.getAtomicConcepts().size() + "]: " - + rs.getAtomicConcepts()); + System.out.println("concepts[" + rs.getNamedClasses().size() + "]: " + + rs.getNamedClasses()); } } else if (name.equals("showRoles")) { if (cliOption.getStringValue().equals("true")) { - int stringLength = rs.getAtomicRoles().toString().length(); + int stringLength = rs.getObjectProperties().toString().length(); if (stringLength > maxLineLength) { - System.out.println("roles[" + rs.getAtomicRoles().size() + "]: "); - for (ObjectProperty r : rs.getAtomicRoles()) + System.out.println("roles[" + rs.getObjectProperties().size() + "]: "); + for (ObjectProperty r : rs.getObjectProperties()) System.out.println(" " + r); } else - System.out.println("roles[" + rs.getAtomicRoles().size() + "]: " - + rs.getAtomicRoles()); + System.out.println("roles[" + rs.getObjectProperties().size() + "]: " + + rs.getObjectProperties()); } } else if (name.equals("showSubsumptionHierarchy")) { if (cliOption.getStringValue().equals("true")) { @@ -700,9 +700,9 @@ // (note that removeAll currently gives a different // result here, because the comparator of the argument // is used) - for (NamedClass ac : rs.getAtomicConcepts()) + for (NamedClass ac : rs.getNamedClasses()) occurringConcepts.remove(ac); - for (ObjectProperty ar : rs.getAtomicRoles()) + for (ObjectProperty ar : rs.getObjectProperties()) occurringRoles.remove(ar); boolean nonExistingConstructs = false; Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -368,7 +368,7 @@ } public void prepareSubsumptionHierarchy() { - reasoner.prepareSubsumptionHierarchy(getAtomicConcepts()); + reasoner.prepareSubsumptionHierarchy(getNamedClasses()); } public void prepareSubsumptionHierarchy(Set<NamedClass> allowedConcepts) { @@ -386,7 +386,7 @@ } public void prepareRoleHierarchy() { - prepareRoleHierarchy(getAtomicRoles()); + prepareRoleHierarchy(getObjectProperties()); } public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { @@ -499,11 +499,11 @@ } } - public Set<NamedClass> getAtomicConcepts() { + public Set<NamedClass> getNamedClasses() { return reasoner.getAtomicConcepts(); } - public Set<ObjectProperty> getAtomicRoles() { + public Set<ObjectProperty> getObjectProperties() { return reasoner.getAtomicRoles(); } @@ -589,13 +589,13 @@ public List<NamedClass> getAtomicConceptsList() { if(atomicConceptsList == null) - atomicConceptsList = new LinkedList<NamedClass>(getAtomicConcepts()); + atomicConceptsList = new LinkedList<NamedClass>(getNamedClasses()); return atomicConceptsList; } public List<ObjectProperty> getAtomicRolesList() { if(atomicRolesList == null) - atomicRolesList = new LinkedList<ObjectProperty>(getAtomicRoles()); + atomicRolesList = new LinkedList<ObjectProperty>(getObjectProperties()); return atomicRolesList; } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -233,7 +233,7 @@ || configOption.getName().equalsIgnoreCase("ignoredConcepts")) { // fill lists Set<NamedClass> atomicsSet = config.getReasoningService() - .getAtomicConcepts(); + .getNamedClasses(); LinkedList<NamedClass> atomicConcepts = new LinkedList<NamedClass>( atomicsSet); for (NamedClass ind : atomicConcepts) @@ -244,7 +244,7 @@ || configOption.getName().equalsIgnoreCase("ignoredRoles")) { // fill lists Set<ObjectProperty> atomicsSet = config.getReasoningService() - .getAtomicRoles(); + .getObjectProperties(); LinkedList<ObjectProperty> atomicRoles = new LinkedList<ObjectProperty>( atomicsSet); for (ObjectProperty ind : atomicRoles) Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -20,10 +20,18 @@ package org.dllearner.refinementoperators; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyHierarchy; +import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.core.owl.Thing; /** * EL downward refinement operator constructed by Jens Lehmann @@ -43,13 +51,50 @@ * @author Jens Lehmann * */ +@SuppressWarnings("unused") public class ELDown extends RefinementOperatorAdapter { +// private static Logger logger = Logger.getLogger(ELDown.class); + + private ReasoningService rs; + + // hierarchies + private SubsumptionHierarchy subsumptionHierarchy; + private ObjectPropertyHierarchy opHierarchy; + + // domains and ranges + private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>(); + private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>(); + + // app_A set of applicable properties for a given class + private Map<Description, Set<ObjectProperty>> app = new TreeMap<Description, Set<ObjectProperty>>(); + + // most general applicable properties + private Map<Description,Set<ObjectProperty>> mgr = new TreeMap<Description,Set<ObjectProperty>>(); + + // utility class + private Utility utility; + + public ELDown(ReasoningService rs) { + utility = new Utility(rs); + subsumptionHierarchy = rs.getSubsumptionHierarchy(); + opHierarchy = rs.getRoleHierarchy(); + + // query reasoner for domains and ranges + // (because they are used often in the operator) + for(ObjectProperty op : rs.getObjectProperties()) { + opDomains.put(op, rs.getDomain(op)); + opRanges.put(op, rs.getRange(op)); + } + } + /* (non-Javadoc) * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) */ @Override public Set<Description> refine(Description concept) { + // TODO according to the specification, we need to minimise + // the tree (not yet implemented) ELDescriptionTree tree = new ELDescriptionTree(concept); Set<ELDescriptionTree> refinementTrees = refine(tree); Set<Description> refinements = new HashSet<Description>(); @@ -68,7 +113,41 @@ * @return Set of refined EL description trees. */ public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { - return null; + return refine(tree, new Thing()); } + + private Set<ELDescriptionTree> refine(ELDescriptionTree tree, Description index) { + Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + // option 1: label extension + + // option 2: label refinement + // loop through all classes in label + for(NamedClass nc : tree.getLabel()) { + // find all more special classes for the given label + for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) { + // create refinements by replacing class + ELDescriptionTree tmp = tree.clone(); + // TODO replace class in label + } + } + + // option 3: new edge + + // option 4: edge refinement + + // option 5: child refinement + + return refinements; + } +// private void computeMg(Description index) { +// // compute the applicable properties if this has not been done yet +// if(app.get(index) == null) +// app.put(index, utility.computeApplicableObjectProperties(index)); +// +// mgr.put(index, new TreeSet<ObjectProperty>()); +// +// +// } + } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -69,7 +69,7 @@ topSet.add(new Negation(c)); // EXISTS r.TOP und ALL r.TOP für alle r - for(ObjectProperty r : reasoningService.getAtomicRoles()) { + for(ObjectProperty r : reasoningService.getObjectProperties()) { topSet.add(new ObjectAllRestriction(r, new Thing())); topSet.add(new ObjectSomeRestriction(r, new Thing())); } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -57,7 +57,7 @@ bottomSet.add(new Negation(c)); // EXISTS r.BOTTOM und ALL r.BOTTOM für alle r - for(ObjectProperty r : reasoningService.getAtomicRoles()) { + for(ObjectProperty r : reasoningService.getObjectProperties()) { bottomSet.add(new ObjectAllRestriction(r, new Nothing())); bottomSet.add(new ObjectSomeRestriction(r, new Nothing())); } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -70,6 +70,11 @@ * domain/range restrictions. Furthermore, it makes use of disjoint * classes in the knowledge base. * + * TODO Some of the code has moved to {@link Utility} in a modified + * form to make it accessible for implementations of other refinement + * operators. These utility methods may be completed and carefully + * integrated back later. + * * @author Jens Lehmann * */ @@ -185,7 +190,7 @@ // query reasoner for domains and ranges // (because they are used often in the operator) - for(ObjectProperty op : rs.getAtomicRoles()) { + for(ObjectProperty op : rs.getObjectProperties()) { opDomains.put(op, rs.getDomain(op)); opRanges.put(op, rs.getRange(op)); } @@ -201,7 +206,7 @@ // determine the maximum number of fillers for each role // (up to a specified cardinality maximum) if(useCardinalityRestrictions) { - for(ObjectProperty op : rs.getAtomicRoles()) { + for(ObjectProperty op : rs.getObjectProperties()) { int maxFillers = 0; Map<Individual,SortedSet<Individual>> opMembers = rs.getRoleMembers(op); for(SortedSet<Individual> inds : opMembers.values()) { @@ -978,7 +983,7 @@ // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { // object properties - Set<ObjectProperty> mostGeneral = rs.getAtomicRoles(); + Set<ObjectProperty> mostGeneral = rs.getObjectProperties(); Set<ObjectProperty> applicableRoles = new TreeSet<ObjectProperty>(); for(ObjectProperty role : mostGeneral) { // TODO: currently we just rely on named classes as roles, Added: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -0,0 +1,145 @@ +/** + * 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.refinementoperators; + +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.owl.ConceptComparator; + +/** + * Utility methods for constructing refinement operators. + * + * @author Jens Lehmann + * + */ +public final class Utility { + + private ReasoningService rs; + + // concept comparator + private ConceptComparator conceptComparator = new ConceptComparator(); + + // specifies whether to do real disjoint tests or check that + // two named classes do not have common instances + private boolean instanceBasedDisjoints = true; + + // cache for reasoner queries + private Map<Description,Map<Description,Boolean>> cachedDisjoints = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator); + + + public Utility(ReasoningService rs) { + this.rs = rs; + } + + /** + * Compute the set of applicable object properties for a + * given description. + * + * @param index The index is a description which determines + * which of the properties are applicable. Exactly those which + * where the index and property domain are not disjoint are + * applicable, where disjoint is defined by {@link #isDisjoint(Description, Description)}. + * + */ + public SortedSet<ObjectProperty> computeApplicableObjectProperties(Description index) { + Set<ObjectProperty> objectProperties = rs.getObjectProperties(); + SortedSet<ObjectProperty> applicableObjectProperties = new TreeSet<ObjectProperty>(); + for(ObjectProperty op : objectProperties) { + Description domain = rs.getDomain(op); + if(!isDisjoint(index,domain)) + applicableObjectProperties.add(op); + } + return applicableObjectProperties; + } + + /** + * Given a set of applicable object properties, this method returns + * the most general ones, i.e. those where more general ones do not + * exist in the set of applicable properties. Due to the definition + * of "applicable", the returned set is just the intersection of the most + * general object properties and the applicable properties. (A non-applicable + * property cannot have applicable subproperties, because subproperties + * can only restrict, but not broaden their domain.) + * + * @param rs The underlying reasoning service. + * @param applicableObjectProperties The set of applicable properties. + * @return The most general applicable properties. + */ + public SortedSet<ObjectProperty> computeMgr(SortedSet<ObjectProperty> applicableObjectProperties) { + return Helper.intersection(rs.getMostGeneralRoles(), applicableObjectProperties); + } + + private boolean isDisjoint(Description d1, Description d2) { + // check whether we have cached this query + Map<Description,Boolean> tmp = cachedDisjoints.get(d1); + Boolean tmp2 = null; + if(tmp != null) + tmp2 = tmp.get(d2); + + if(tmp2==null) { + Boolean result; + if(instanceBasedDisjoints) { + result = isDisjointInstanceBased(d1,d2); + } else { + Description d = new Intersection(d1, d2); + result = rs.subsumes(new Nothing(), d); + } + // add the result to the cache (we add it twice such that + // the order of access does not matter) + + // create new entries if necessary + Map<Description,Boolean> map1 = new TreeMap<Description,Boolean>(conceptComparator); + Map<Description,Boolean> map2 = new TreeMap<Description,Boolean>(conceptComparator); + if(tmp == null) + cachedDisjoints.put(d1, map1); + if(!cachedDisjoints.containsKey(d2)) + cachedDisjoints.put(d2, map2); + + // add result symmetrically in the description matrix + cachedDisjoints.get(d1).put(d2, result); + cachedDisjoints.get(d2).put(d1, result); + return result; + } else { + return tmp2; + } + } + + private boolean isDisjointInstanceBased(Description d1, Description d2) { + SortedSet<Individual> d1Instances = rs.retrieval(d1); + SortedSet<Individual> d2Instances = rs.retrieval(d2); + for(Individual d1Instance : d1Instances) { + if(d2Instances.contains(d1Instance)) + return false; + } + return true; + } + +} Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -497,7 +497,7 @@ @WebMethod public String[] getAtomicConcepts(int id) throws ClientNotKnownException { - Set<NamedClass> atomicConcepts = getState(id).getReasoningService().getAtomicConcepts(); + Set<NamedClass> atomicConcepts = getState(id).getReasoningService().getNamedClasses(); return Datastructures.sortedSet2StringListConcepts(atomicConcepts); } @@ -525,7 +525,7 @@ @WebMethod public String[] getAtomicRoles(int id) throws ClientNotKnownException { ClientState state = getState(id); - Set<ObjectProperty> roles = state.getReasoningService().getAtomicRoles(); + Set<ObjectProperty> roles = state.getReasoningService().getObjectProperties(); return Datastructures.sortedSet2StringListRoles(roles); } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -111,7 +111,7 @@ public Set<NamedClass> doInBackground() { getWizardModel().getOre().detectReasoner(); - Set<NamedClass> ind = getWizardModel().getOre().getReasoningService().getAtomicConcepts(); + Set<NamedClass> ind = getWizardModel().getOre().getReasoningService().getNamedClasses(); ClassPanelOWLDescriptor nextPanel = (ClassPanelOWLDescriptor)getWizardModel().getPanelHashMap().get(getNextPanelDescriptor()); nextPanel.panel3.getModel().clear(); Modified: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -548,7 +548,7 @@ public Set<NamedClass> getpossibleClassesMoveTo(Individual ind){ Set<NamedClass> moveClasses = new HashSet<NamedClass>(); - for(NamedClass nc : rs.getAtomicConcepts()) + for(NamedClass nc : rs.getNamedClasses()) if(!rs.instanceCheck(nc, ind)) moveClasses.add(nc); @@ -558,7 +558,7 @@ public Set<NamedClass> getpossibleClassesMoveFrom(Individual ind){ Set<NamedClass> moveClasses = new HashSet<NamedClass>(); - for(NamedClass nc : rs.getAtomicConcepts()){ + for(NamedClass nc : rs.getNamedClasses()){ if(rs.instanceCheck(nc, ind)) moveClasses.add(nc); } Modified: trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -68,7 +68,7 @@ Object nextPanelDescriptor = descriptor.getNextPanelDescriptor(); - //TODO nochmal \xFCberdenken + //TODO nochmal �berdenken if(nextPanelDescriptor.equals("CLASS_CHOOSE_OWL_PANEL")){ ((ClassPanelOWLDescriptor)model.getPanelHashMap().get(nextPanelDescriptor)).panel3.getModel().clear(); new ConceptRetriever(nextPanelDescriptor).execute(); @@ -227,7 +227,7 @@ wizard.getModel().getOre().detectReasoner(); Set<NamedClass> ind = wizard.getModel().getOre() - .getReasoningService().getAtomicConcepts(); + .getReasoningService().getNamedClasses(); return ind; } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -452,7 +452,7 @@ SortedSet<Individual> individuals = null; if(!aktuell.getRootObject().toString().equals("Thing")) { - for(Iterator<NamedClass> i = rs.getAtomicConcepts().iterator(); i.hasNext();) + for(Iterator<NamedClass> i = rs.getNamedClasses().iterator(); i.hasNext();) { if(individuals==null) { Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -471,14 +471,14 @@ public static Set<NamedClass> computeConcepts(ReasoningService rs) { // if there is no ignore or allowed list, we just ignore the concepts // of uninteresting namespaces - Set<NamedClass> concepts = rs.getAtomicConcepts(); + Set<NamedClass> concepts = rs.getNamedClasses(); Helper.removeUninterestingConcepts(concepts); return concepts; } // concepts case 2: ignore list public static Set<NamedClass> computeConceptsUsingIgnoreList(ReasoningService rs, Set<NamedClass> ignoredConcepts) { - Set<NamedClass> concepts = rs.getAtomicConcepts(); + Set<NamedClass> concepts = rs.getNamedClasses(); Helper.removeUninterestingConcepts(concepts); for (NamedClass ac : ignoredConcepts) { boolean success = concepts.remove(ac); @@ -512,7 +512,7 @@ */ // public static ObjectProperty checkRoles(ReasoningService rs, Set<ObjectProperty> roles) { - Set<ObjectProperty> existingRoles = rs.getAtomicRoles(); + Set<ObjectProperty> existingRoles = rs.getObjectProperties(); for (ObjectProperty ar : roles) { if(!existingRoles.contains(ar)) return ar; @@ -528,7 +528,7 @@ */ // public static NamedClass checkConcepts(ReasoningService rs, Set<NamedClass> concepts) { - Set<NamedClass> existingConcepts = rs.getAtomicConcepts(); + Set<NamedClass> existingConcepts = rs.getNamedClasses(); for (NamedClass ar : concepts) { if(!existingConcepts.contains(ar)) return ar; @@ -542,7 +542,7 @@ long dematStartTime = System.currentTimeMillis(); FlatABox aBox = new FlatABox(); // FlatABox.getInstance(); - for (NamedClass atomicConcept : rs.getAtomicConcepts()) { + for (NamedClass atomicConcept : rs.getNamedClasses()) { aBox.atomicConceptsPos.put(atomicConcept.getName(), getStringSet(rs .retrieval(atomicConcept))); Negation negatedAtomicConcept = new Negation(atomicConcept); @@ -551,7 +551,7 @@ aBox.concepts.add(atomicConcept.getName()); } - for (ObjectProperty atomicRole : rs.getAtomicRoles()) { + for (ObjectProperty atomicRole : rs.getObjectProperties()) { aBox.rolesPos.put(atomicRole.getName(), getStringMap(rs.getRoleMembers(atomicRole))); aBox.roles.add(atomicRole.getName()); } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloser.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -86,7 +86,7 @@ * ExactCardinalityRestriction */ public void applyNumberRestrictions() { - Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); + Set<ObjectProperty> allRoles = this.rs.getObjectProperties(); // Set<Individual> allind = this.rs.getIndividuals(); testForTransitiveProperties(true); @@ -116,7 +116,7 @@ * ExactCardinalityRestriction */ public void applyNumberRestrictionsConcise() { - Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); + Set<ObjectProperty> allRoles = this.rs.getObjectProperties(); // Set<Individual> allind = this.rs.getIndividuals(); testForTransitiveProperties(true); @@ -167,7 +167,7 @@ * ExactCardinalityRestriction */ public void applyNumberRestrictionsNamed() { - Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); + Set<ObjectProperty> allRoles = this.rs.getObjectProperties(); // Set<Individual> allind = this.rs.getIndividuals(); testForTransitiveProperties(true); Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java 2008-07-31 16:27:38 UTC (rev 1042) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OntologyCloserOWLAPI.java 2008-07-31 16:33:29 UTC (rev 1043) @@ -53,7 +53,7 @@ */ public void applyNumberRestrictions() { System.out.println("apply ExactCardinalityRestriction to Individuals"); - Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); + Set<ObjectProperty> allRoles = this.rs.getObjectProperties(); System.out.println("found: " + allRoles.size() + " roles"); testForTransitiveProperties(true); @@ -95,7 +95,7 @@ */ public void applyNumberRestrictionsConcise() { - Set<ObjectProperty> allRoles = this.rs.getAtomicRoles(); + Set<ObjectProperty> allRoles = this.rs.getObjectProperties(); testForTransitiveProperties(true); // collect info for roles and individuals This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:27:45
|
Revision: 1042 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1042&view=rev Author: kurzum Date: 2008-07-31 16:27:38 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Wikipedia Category cleaner Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparql.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSPARQLConfiguration.java trunk/src/dl-learner/org/dllearner/utilities/learn/LearnSparqlold.java trunk/src/dl-learner/org/dllearner/utilities/learn/SPARQLExtractionEvaluation.java trunk/src/dl-learner/org/dllearner/utilities/learn/SPARQLMassLearning.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java Deleted: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-31 16:23:42 UTC (rev 1041) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -1,562 +0,0 @@ -/** - * 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.scripts; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.LearningProblem; -import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.owl.Description; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SPARQLTasks; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.utilities.Files; -import org.dllearner.utilities.JamonMonitorLogger; -import org.dllearner.utilities.datastructures.SetManipulation; -import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; -import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; - -public class SKOS7030 { - - public int test = 0; - - private static SPARQLTasks sparqlTasks; - - private static LearningAlgorithm la; - - private static final long wash = 1216800000000L; - - private boolean stable = true; - - // private static long wash = 1216901570168 - - private static Logger logger = Logger.getRootLogger(); - - static boolean local = true; - - static String url = ""; - - // LEARNING - static int recursiondepth = 1; - - static boolean closeAfterRecursion = true; - - static boolean randomizeCache = false; - - static double noise = 15; - - static int maxExecutionTimeInSeconds = 30; - - static int guaranteeXgoodDescriptions = 40; - - // examples - static int sparqlResultSize = 2000; - - static double percentOfSKOSSet = 0.2; - - static double negfactor = 1.0; - - SortedSet<String> posExamples = new TreeSet<String>(); - - SortedSet<String> fullPositiveSet = new TreeSet<String>(); - - SortedSet<String> fullPosSetWithoutPosExamples = new TreeSet<String>(); - - SortedSet<String> negExamples = new TreeSet<String>(); - - /** - * @param args - */ - public static void main(String[] args) { - initLogger(); - logger.info("Start"); - // String resultString=""; - // System.out.println(time()); - // System.out.println(System.currentTimeMillis()); - - - // parameters - - if (local) { - url = "http://139.18.2.37:8890/sparql"; - sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(), - SparqlEndpoint.getEndpointLOCALDBpedia()); - } else { - url = "http://dbpedia.openlinksw.com:8890/sparql"; - sparqlTasks = new SPARQLTasks(Cache.getPersistentCache(), - SparqlEndpoint.getEndpointDBpedia()); - } - - - String st= "http://dbpedia.org/class/yago/Person100007846"; - st = "http://dbpedia.org/class/yago/Leader109623038"; - System.out.println(sparqlTasks.getSuperClasses(st, 2)); - System.out.println(sparqlTasks.getSuperClasses(st, 1)); - System.out.println(sparqlTasks.getSubClasses(st, 0)); - - System.exit(0); - - //System.out.println(sparqlTasks.getDomain( - // "http://dbpedia.org/property/predecessor", 1000)); - - String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; - - // String - // award=("http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"); - - SKOS7030 s = new SKOS7030(); - - s.makeExamples(target, percentOfSKOSSet, negfactor, sparqlResultSize); - - // System.exit(0); - List<Description> conceptresults = new ArrayList<Description>(); - List<EvaluatedDescription> conceptresults2 = new ArrayList<EvaluatedDescription>(); - s.learn(); - - recordConceptClasses(); - - System.exit(0); - - // EvaluatedDescription - logger.debug("found nr of concepts: " + conceptresults.size()); - System.out.println(conceptresults); - - int x = 0; - - SortedSet<ResultMostCoveredInRest> res = new TreeSet<ResultMostCoveredInRest>(); - for (Description concept : conceptresults) { - if (x++ == 100) - break; - res.add(s.evaluate(concept, 1000)); - - } - - x = 0; - for (ResultMostCoveredInRest resultMostCoveredInRest : res) { - if (x++ == 10) - break; - System.out.println(resultMostCoveredInRest.concept); - System.out.println(resultMostCoveredInRest.accuracy); - System.out.println(resultMostCoveredInRest.retrievedInstancesSize); - - } - - s.print(res.first().concept, 1000); - - System.out.println("Finished"); - JamonMonitorLogger.printAllSortedByLabel(); - - } - - void print(final Description concept, final int sparqlResultLimit) { - logger.debug("evaluating concept: " + concept); - // SortedSet<String> instances = - // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(), - // sparqlResultLimit); - SortedSet<String> instances = sparqlTasks - .retrieveInstancesForClassDescriptionIncludingSubclasses(concept - .toKBSyntaxString(), sparqlResultLimit,1); - - SortedSet<String> coveredInRest = new TreeSet<String>( - fullPosSetWithoutPosExamples); - coveredInRest.retainAll(instances); - - SortedSet<String> coveredTotal = new TreeSet<String>(fullPositiveSet); - coveredTotal.retainAll(instances); - - SortedSet<String> notCoveredInRest = new TreeSet<String>( - fullPosSetWithoutPosExamples); - notCoveredInRest.retainAll(coveredInRest); - System.out.println(notCoveredInRest); - - SortedSet<String> notCoveredTotal = new TreeSet<String>(fullPositiveSet); - notCoveredTotal.retainAll(coveredTotal); - System.out.println(notCoveredTotal); - - } - - ResultMostCoveredInRest evaluate(Description concept, int sparqlResultLimit) { - logger.debug("evaluating concept: " + concept); - // SortedSet<String> instances = - // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(), - // sparqlResultLimit); - SortedSet<String> instances = sparqlTasks - .retrieveInstancesForClassDescriptionIncludingSubclasses(concept - .toKBSyntaxString(), sparqlResultLimit, 1 ); - - SortedSet<String> coveredInRest = new TreeSet<String>( - fullPosSetWithoutPosExamples); - coveredInRest.retainAll(instances); - - SortedSet<String> coveredTotal = new TreeSet<String>(fullPositiveSet); - coveredTotal.retainAll(instances); - - SortedSet<String> notCoveredInRest = new TreeSet<String>( - fullPosSetWithoutPosExamples); - notCoveredInRest.retainAll(coveredInRest); - - SortedSet<String> notCoveredTotal = new TreeSet<String>(fullPositiveSet); - notCoveredTotal.retainAll(coveredTotal); - double acc = (double) (coveredInRest.size() / fullPosSetWithoutPosExamples - .size()); - System.out.println("Accuracy: " + acc); - return new ResultMostCoveredInRest(concept, acc, instances.size()); - - } - - private static void initLogger() { - - SimpleLayout layout = new SimpleLayout(); - // create logger (a simple logger which outputs - // its messages to the console) - FileAppender fileAppender = null; - try { - fileAppender = new FileAppender(layout, "log/progress/skos" - + time() + ".txt", false); - } catch (Exception e) { - e.printStackTrace(); - } - - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.addAppender(fileAppender); - logger.setLevel(Level.DEBUG); - Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); - - } - - /* - * public static SortedSet<String> selectDBpediaConcepts(int number){ - * String query = "SELECT DISTINCT ?concept WHERE { \n" + "[] a ?concept - * .FILTER (regex(str(?concept),'yago'))" + " \n} \n"; //LIMIT "+number+" - * - * String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se))); - * ResultSet rs =SparqlQuery.JSONtoResultSet(JSON); JenaResultSetConvenience - * rsc = new JenaResultSetConvenience(rs); return - * SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number); } - */ - - public void makeExamples(String SKOSConcept, double percentOfSKOSSet, - double negfactor, int sparqlResultSize) { - - // POSITIVES - AutomaticPositiveExampleFinderSPARQL apos = new AutomaticPositiveExampleFinderSPARQL( - sparqlTasks); - apos.makePositiveExamplesFromSKOSConcept(SKOSConcept); - fullPositiveSet = apos.getPosExamples(); - - // System.exit(0); - - int poslimit = (int) Math.round(percentOfSKOSSet - * fullPositiveSet.size()); - int neglimit = (int) Math.round(poslimit * negfactor); - - posExamples = SetManipulation.fuzzyShrink(fullPositiveSet, poslimit); - - // NEGATIVES - - AutomaticNegativeExampleFinderSPARQL aneg = new AutomaticNegativeExampleFinderSPARQL( - fullPositiveSet, sparqlTasks); - - aneg.makeNegativeExamplesFromParallelClasses(posExamples, - sparqlResultSize); - negExamples = aneg.getNegativeExamples(neglimit, stable); - - logger.debug("POSITIVE EXAMPLES"); - for (String pos : posExamples) { - logger.debug("+" + pos); - } - - logger.debug("NEGATIVE EXAMPLES"); - for (String negs : this.negExamples) { - logger.debug("-" + negs); - } - - fullPosSetWithoutPosExamples = fullPositiveSet; - fullPosSetWithoutPosExamples.removeAll(posExamples); - - logger.debug(fullPositiveSet); - logger.debug(fullPosSetWithoutPosExamples); - } - - public void learn() { - - SortedSet<String> instances = new TreeSet<String>(); - instances.addAll(this.posExamples); - instances.addAll(this.negExamples); - - logger.info("Start Learning with"); - logger.info("positive examples: \t" + posExamples.size()); - logger.info("negative examples: \t" + negExamples.size()); - logger.info("instances \t" + instances.size()); - - ComponentManager cm = ComponentManager.getInstance(); - // LearningAlgorithm la = null; - ReasoningService rs = null; - LearningProblem lp = null; - SparqlKnowledgeSource ks = null; - try { - Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); - ks = cm.knowledgeSource(SparqlKnowledgeSource.class); - ReasonerComponent r = new FastInstanceChecker(sources); - rs = new ReasoningService(r); - // System.out.println("satisfy: "+rs.isSatisfiable()); - lp = new PosNegDefinitionLP(rs); - ((PosNegLP) lp).setPositiveExamples(SetManipulation - .stringToInd(this.posExamples)); - ((PosNegLP) lp).setNegativeExamples(SetManipulation - .stringToInd(this.negExamples)); - - la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, rs); - - logger.debug("start learning"); - - // KNOWLEDGESOURCE - cm.applyConfigEntry(ks, "instances", instances); - cm.applyConfigEntry(ks, "url", url); - cm.applyConfigEntry(ks, "recursionDepth", recursiondepth); - cm.applyConfigEntry(ks, "closeAfterRecursion", closeAfterRecursion); - cm.applyConfigEntry(ks, "predefinedFilter", "YAGO"); - if (local) - cm.applyConfigEntry(ks, "predefinedEndpoint", "LOCALDBPEDIA"); - else { - cm.applyConfigEntry(ks, "predefinedEndpoint", "DBPEDIA"); - } - if (randomizeCache) - cm.applyConfigEntry(ks, "cacheDir", "cache/" - + System.currentTimeMillis() + ""); - else { - cm.applyConfigEntry(ks, "cacheDir", Cache.getDefaultCacheDir()); - } - - // LEARNINGALGORITHM - cm.applyConfigEntry(la, "useAllConstructor", false); - cm.applyConfigEntry(la, "useExistsConstructor", true); - cm.applyConfigEntry(la, "useCardinalityRestrictions", false); - cm.applyConfigEntry(la, "useNegation", false); - cm.applyConfigEntry(la, "minExecutionTimeInSeconds", 0); - cm.applyConfigEntry(la, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - cm.applyConfigEntry(la, "guaranteeXgoodDescriptions", - guaranteeXgoodDescriptions); - cm.applyConfigEntry(la, "writeSearchTree", false); - cm.applyConfigEntry(la, "searchTreeFile", "log/SKOS.txt"); - cm.applyConfigEntry(la, "replaceSearchTree", true); - cm.applyConfigEntry(la, "noisePercentage", noise); - // cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",999999); - cm.applyConfigEntry(la, "logLevel", "TRACE"); - /* - * if(ignoredConcepts.size()>0) - * cm.applyConfigEntry(la,"ignoredConcepts",ignoredConcepts); - */ - - ks.init(); - sources.add(ks); - r.init(); - lp.init(); - la.init(); - - la.start(); - // Statistics.addTimeCollecting(sc.getTime()); - // Statistics.addTimeLearning(sc.getTime()); - - // return la.getCurrentlyBestDescriptions(); - - } catch (Exception e) { - e.printStackTrace(); - } - // return null; - - } - - // String t="\"http://dbpedia.org/class/yago/Fiction106367107\""; - // t="(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND - // (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND - // \"http://dbpedia.org/class/yago/Representative110522035\"))"; - // //System.out.println(t); - // //t="\"http://www.w3.org/2004/02/skos/core#subject\""; - // //conceptRewrite(t); - // //getSubClasses(t); - // - // AutomaticExampleFinderSKOSSPARQL ae= new - // AutomaticExampleFinderSKOSSPARQL( se); - // try{ - // System.out.println("oneconcept: "+t); - // SortedSet<String> instances = - // ae.queryConceptAsStringSet(conceptRewrite(t), 200); - // if(instances.size()>=0)System.out.println("size of instances - // "+instances.size()); - // if(instances.size()>=0 && instances.size()<100) - // System.out.println("instances"+instances); - // }catch (Exception e) { - // e.printStackTrace(); - // } - // SortedSet<String> concepts = new TreeSet<String>(); - - // System.out.println(DBpediaSKOS(prim)); - // double acc1=0.0; - // for (int i = 0; i < 5; i++) { - // acc1+=DBpediaSKOS(prim); - // } - // System.out.println("accprim"+(acc1/5)); - // - // double acc2=0.0; - // for (int i = 0; i < 5; i++) { - // acc2+=DBpediaSKOS(award); - // } - // System.out.println("accprim"+(acc2/5)); - - // DBpediaSKOS(concepts.first()); - // DBpediaSKOS(concepts.first()); - // concepts.remove(concepts.first()); - // DBpediaSKOS(concepts.first()); - // DBpediaSKOS(concepts.first()); - // concepts.remove(concepts.first()); - // DBpediaSKOS(concepts.first()); - // DBpediaSKOS(concepts.first()); - // algorithm="refinement"; - // roles(); - - /* - * System.out.println(Level.DEBUG.getClass()); - * System.out.println(Level.toLevel("INFO")); - * System.out.println(Level.INFO); - */ - // System.exit(0); - private class ResultCompare implements Comparable<ResultCompare> { - Description concept; - - double accuracy = 0.0; - - int retrievedInstancesSize = 0; - - public int compareTo(ResultCompare o2) { - return 0; - } - - - public boolean equals(ResultCompare o2) { - return this.concept.equals(o2.concept); - } - - public ResultCompare(Description conceptKBSyntax, double accuracy, - int retrievedInstancesSize) { - super(); - this.concept = conceptKBSyntax; - this.accuracy = accuracy; - this.retrievedInstancesSize = retrievedInstancesSize; - } - - } - - private class ResultMostCoveredInRest extends ResultCompare { - - public ResultMostCoveredInRest(Description concept, double accuracy, - int retrievedInstancesSize) { - super(concept, accuracy, retrievedInstancesSize); - - } - - public int compareTo(ResultMostCoveredInRest o2) { - if (this.equals(o2)) - return 0; - - if (this.accuracy > o2.accuracy) { - return 1; - } else if (this.accuracy == o2.accuracy) { - if (this.retrievedInstancesSize < o2.retrievedInstancesSize) - return 1; - else if (this.retrievedInstancesSize > o2.retrievedInstancesSize) { - return -1; - } else - return this.concept.toKBSyntaxString().compareTo( - o2.concept.toKBSyntaxString()); - } else { - return -1; - } - - } - - } - - public static String time() { - return ("" + (System.currentTimeMillis() - wash)).substring(0, 7); - - } - - /** - * - */ - public static void recordConceptClasses() { - StringBuffer result =new StringBuffer(); - StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n"); - StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n"); - int result1count = 1; - int result2count = 1; - List<EvaluatedDescription> conceptresults = la - .getCurrentlyBestEvaluatedDescriptions(5000, .70, true); - - int x = 0; - for (EvaluatedDescription description : conceptresults) { - if (x < 50) { - x++; - result.append(description + "\n"); - } - - if (!description.toString().contains("Entity")) { - result1.append(description + "\n"); - result1count++; - } - if (!description.toString().contains("OR")) { - result2.append(description + "\n"); - result2count++; - } - } - result.append("full size: " + conceptresults.size()); - result.append(result1.toString() + " size: " + result1count + "\n"); - result.append(result2.toString() + " size: " + result2count + "\n"); - - Files.createFile(new File("results/descriptions/concepts" + time() - + ".txt"), result.toString()); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java 2008-07-31 16:23:42 UTC (rev 1041) +++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLExtractionEvaluation.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -1,251 +0,0 @@ -package org.dllearner.scripts; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.utilities.learn.LearnSparql; -import org.dllearner.utilities.statistics.SimpleClock; -import org.dllearner.utilities.statistics.Statistics; - -import com.hp.hpl.jena.query.ResultSet; - -public class SPARQLExtractionEvaluation { - - static Cache c; - static SparqlEndpoint se; - private static Logger logger = Logger.getRootLogger(); - - //static String standardSettings=""; - //static String algorithm="refexamples"; - - //vars - static boolean useRelated = false; - static boolean useSuperClasses = true; - static boolean useParallelClasses = true; - static int poslimit = 0; - static int neglimit = 0; - static boolean randomizeCache = true; - - /** - * @param args - */ - public static void main(String[] args) { - init(); - System.out.println("Start"); - //logger.setLevel(Level.TRACE); - logger.setLevel(Level.WARN); - //Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.WARN); - //Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); - //System.out.println(Logger.getLogger(SparqlQuery.class).getLevel()); - SimpleClock sc=new SimpleClock(); - LocalDBpediaEvaluation(); - - sc.printAndSet("Finished"); - - } - - - static void LocalDBpediaEvaluation(){ - boolean local=true; - SimpleClock total =new SimpleClock(); - String url=""; - if(local){ - se = SparqlEndpoint.getEndpointLOCALDBpedia(); - - url = "http://139.18.2.37:8890/sparql"; - - }else{ - se = SparqlEndpoint.getEndpointDBpedia(); - url= "http://dbpedia.openlinksw.com:8890/sparql"; - } - - - SortedSet<String> concepts = new TreeSet<String>(); - SortedSet<String> tmpSet = new TreeSet<String>(); - //System.out.println(selectDBpediaConcepts(10)); - tmpSet=initConcepts(); - int number=tmpSet.size(); - //System.out.println(number); - //concepts.add("\"http://dbpedia.org/class/yago/Flamethrower103356559\""); - for (String string : tmpSet) { - //System.out.println("\""+string+"\","); - concepts.add("\""+string+"\""); - } - - - - SortedSet<String> posExamples = new TreeSet<String>(); - SortedSet<String> negExamples = new TreeSet<String>(); - - for (int a = 0; a < 1; a++) { - - poslimit+=15; - neglimit+=15; - printProgress(0, concepts.size(),0, "beginning",total.getTime()); - - int concount=0; - for (String oneConcept : concepts) { - concount++; - printProgress(concount, concepts.size(),0, oneConcept,total.getTime()); - int recursiondepth=0; - boolean closeAfterRecursion=true; - - System.out.println(oneConcept); - //AutomaticExampleFinderSPARQLold ae= new AutomaticExampleFinderSPARQLold( se); - - //ae.initDBpedia(oneConcept, useRelated, useSuperClasses,useParallelClasses, poslimit, neglimit); - - //posExamples = ae.getPosExamples(); - //negExamples = ae.getNegExamples(); - - for(recursiondepth=0;recursiondepth<4;recursiondepth++) { - - Statistics.setCurrentLabel(recursiondepth+""); - printProgress(concount, concepts.size(),recursiondepth, oneConcept,total.getTime()); - /*if(i==0){;} - else if(closeAfterRecursion) { - closeAfterRecursion=false; - recursiondepth++; - } - else { - closeAfterRecursion=true; - }*/ - - - Statistics.print(number); - - //System.out.println("currently at label "+Statistics.getCurrentLabel()+"||i: "+recursiondepth); - - LearnSparql ls = new LearnSparql(); - TreeSet<String> igno = new TreeSet<String>(); - igno.add(oneConcept.replaceAll("\"", "")); - //igno.add("\""+oneConcept+"\""); - //System.out.println(oneConcept); - - ls.learnDBpedia(posExamples, negExamples, url,igno,recursiondepth, closeAfterRecursion,randomizeCache); - - - } - } - Statistics.print(number); - String pre="log/gnu_"; - int examples=poslimit+neglimit; - String comment1="# "+examples+"examples\n"; - String f1=pre+"1avgtrip_"+examples+"example"+concepts.size()+"classes"; - writeToFile(f1, comment1+Statistics.getAVGTriplesForRecursionDepth(number)); - String comment2="# "+examples+"examples\n"; - String f2=pre+"2avgTimeExtraction_"+examples+"example"+concepts.size()+"classes"; - writeToFile(f2, comment2+Statistics.getAVGTimeCollecting(number)); - String comment3="# "+examples+"examples\n"; - String f3=pre+"2avgTimeLearning_"+examples+"example"+concepts.size()+"classes"; - writeToFile(f3, comment3+Statistics.getAVGTimeLearning(number)); - String comment4="# "+examples+"examples\n"; - String f4=pre+"2avgTotalTime_"+examples+"example"+concepts.size()+"classes"; - writeToFile(f4, comment4+Statistics.getAVGtotalTime(number)); - Statistics.reset(); - - }//outer - } - - - - public static void init() { - - SimpleLayout layout = new SimpleLayout(); - // create logger (a simple logger which outputs - // its messages to the console) - FileAppender fileAppender =null; ; - try{ - fileAppender = new FileAppender(layout,"log/sparqleval.txt",false); - }catch (Exception e) {e.printStackTrace();} - - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.addAppender(fileAppender); - - c = new Cache("cachetemp"); - - - } - - //FIXME - public static SortedSet<String> selectDBpediaConcepts(int number){ - String query = "SELECT DISTINCT ?concept WHERE { \n" + - "[] a ?concept .FILTER (regex(str(?concept),'yago'))" + - " \n} LIMIT "+1000+" \n "; // - - String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se))); - ResultSet rs =SparqlQuery.convertJSONtoResultSet(JSON); - if(rs==null); - //JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs); - //return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number); - return null; - } - - public static SortedSet<String> initConcepts(){ - SortedSet<String> concepts = new TreeSet<String>(); - concepts.add("http://dbpedia.org/class/yago/AirLane108492546"); - concepts.add("http://dbpedia.org/class/yago/AlphaBlocker102698769"); - concepts.add("http://dbpedia.org/class/yago/Articulation107131854"); - - concepts.add("http://dbpedia.org/class/yago/Ceremony107450842"); - concepts.add("http://dbpedia.org/class/yago/CookingOil107673145"); - concepts.add("http://dbpedia.org/class/yago/Corticosteroid114751417"); - concepts.add("http://dbpedia.org/class/yago/Curlew102033561"); - concepts.add("http://dbpedia.org/class/yago/DataStructure105728493"); - concepts.add("http://dbpedia.org/class/yago/Disappearance100053609"); - concepts.add("http://dbpedia.org/class/yago/Flintstone114871268"); -// concepts.add("http://dbpedia.org/class/yago/Form105930736"); -// concepts.add("http://dbpedia.org/class/yago/Hypochondriac110195487"); -// concepts.add("http://dbpedia.org/class/yago/Industrialist110204177"); -// concepts.add("http://dbpedia.org/class/yago/Lifeboat103662601"); -// concepts.add("http://dbpedia.org/class/yago/Particulate114839439"); -// concepts.add("http://dbpedia.org/class/yago/Patriot110407310"); -// concepts.add("http://dbpedia.org/class/yago/Reservation108587174"); -// concepts.add("http://dbpedia.org/class/yago/Schoolteacher110560352"); -// concepts.add("http://dbpedia.org/class/yago/Singer110599806"); -// concepts.add("http://dbpedia.org/class/yago/SupremeCourt108336188"); - - return concepts; - } - - protected static void writeToFile(String filename, String content) { - // create the file we want to use - File file = new File( filename); - - try { - file.createNewFile(); - FileOutputStream fos = new FileOutputStream(filename, false); - // ObjectOutputStream o = new ObjectOutputStream(fos); - fos.write(content.getBytes()); - fos.flush(); - fos.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static void printProgress(int con, int consize,int recdepth, String conceptname, long needed){ - int ex=poslimit+neglimit; - System.out.println("**********************STAT\n" + - "XXX num ex : "+ex+ " \n" + - "concept : "+con+"/"+consize+ " \n" + - "recursion : "+recdepth+" \n" + - "conceptname : "+conceptname+ "\n" + - "needed total: "+needed); - } - - -} Deleted: trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-07-31 16:23:42 UTC (rev 1041) +++ trunk/src/dl-learner/org/dllearner/scripts/SPARQLMassLearning.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -1,269 +0,0 @@ -package org.dllearner.scripts; - -import java.net.URLEncoder; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.utilities.learn.ConfWriter; -import org.dllearner.utilities.learn.LearnSparql; -import org.dllearner.utilities.statistics.SimpleClock; -import org.dllearner.utilities.statistics.Statistics; - -import com.hp.hpl.jena.query.ResultSet; - -public class SPARQLMassLearning { - - - static Cache c; - static SparqlEndpoint se; - private static Logger logger = Logger.getRootLogger(); - - static String standardSettings=""; - static String algorithm="refexamples"; - static String standardSettingsRefexamples = - "refexamples.minExecutionTimeInSeconds = 30;\n" + - "refexamples.maxExecutionTimeInSeconds = 30;\n" + - "//refexamples.guaranteeXgoodDescriptions = 10;\n" + - "refexamples.logLevel=\"TRACE\";\n" + - "refexamples.noisePercentage = 0.10;\n" + - "refexamples.writeSearchTree = false;\n" + - "refexamples.searchTreeFile = \"searchTree.txt\";\n" + - "refexamples.replaceSearchTree = true;\n\n" ; - - static String standardSettingsRefinement = - "refinement.minExecutionTimeInSeconds = 30;\n" + - "refinement.maxExecutionTimeInSeconds = 30;\n" + - "//refinement.guaranteeXgoodDescriptions = 10;\n" + - "refinement.logLevel=\"TRACE\";\n" + - "refinement.writeSearchTree = false;\n" + - "refinement.searchTreeFile = \"searchTree.txt\";\n" + - "refinement.replaceSearchTree = true;\n\n" ; - - - - static String standardDBpedia="" + - "sparql.recursionDepth = 1;\n" + - "sparql.predefinedFilter = \"YAGO\";\n" + - "sparql.predefinedEndpoint = \"DBPEDIA\";\n"; - //"sparql.logLevel = \"INFO\";\n"; - - - //vars - static boolean useRelated = false; - static boolean useSuperClasses = false; - static boolean useParallelClasses = true; - static int poslimit = 10; - static int neglimit = 20; - - /** - * @param args - */ - public static void main(String[] args) { - init(); - //logger.setLevel(Level.TRACE); - Logger.getLogger(SparqlKnowledgeSource.class).setLevel(Level.INFO); - //System.out.println(Logger.getLogger(SparqlQuery.class).getLevel()); - SimpleClock sc=new SimpleClock(); - - standardSettings=standardSettingsRefexamples+standardDBpedia; - //standardSettings=standardSettingsRefinement+standardDBpedia; - - DBpedia(); - //algorithm="refinement"; - //roles(); - - /*System.out.println(Level.DEBUG.getClass()); - System.out.println(Level.toLevel("INFO")); - System.out.println(Level.INFO);*/ - //System.exit(0); - - - - sc.printAndSet("Finished"); - - } - - - - - static void roles(){ - - se = SparqlEndpoint.getEndpointDBpedia(); - //se = SparqlEndpoint.EndpointUSCensus(); - SortedSet<String> roles = new TreeSet<String>(); - roles.add("http://dbpedia.org/property/birthPlace"); - //roles.add("http://www.rdfabout.com/rdf/schema/census/landArea"); - standardSettings+=algorithm+".ignoredRoles = {\""+roles.first()+"\"};\n"; - - SortedSet<String> posExamples = new TreeSet<String>(); - SortedSet<String> negExamples = new TreeSet<String>(); - String url = "http://dbpedia.openlinksw.com:8890/sparql"; - //HashMap<String, ResultSet> result = new HashMap<String, ResultSet>(); - //HashMap<String, String> result2 = new HashMap<String, String>(); - //System.out.println(concepts.first()); - //logger.setLevel(Level.TRACE); - //AutomaticExampleFinderRolesSPARQL ae= new AutomaticExampleFinderRolesSPARQL( se); - - //ae.initDomainRange(roles.first(), poslimit, neglimit); - - //posExamples = ae.getPosExamples(); - //negExamples = ae.getNegExamples(); - - System.out.println(posExamples); - System.out.println(negExamples); - //System.exit(0); - String tmp = roles.first().replace("http://dbpedia.org/property/", "").replace("\"",""); - String confname1 = ""; - String confname2 = ""; - try{ - confname1 = URLEncoder.encode(tmp, "UTF-8")+"_domain.conf"; - confname2 = URLEncoder.encode(tmp, "UTF-8")+"_range.conf"; - }catch (Exception e) {e.printStackTrace();} - // - ConfWriter cf=new ConfWriter(); - cf.addToStats("relearned role: "+roles.first()); - - //System.exit(0); - //"relearned concept: "; - cf.writeSPARQL(confname1, negExamples,posExamples, url, new TreeSet<String>(),standardSettings,algorithm); - - cf.writeSPARQL(confname2, posExamples, negExamples, url, new TreeSet<String>(),standardSettings,algorithm); - //new LearnSparql().learn(posExamples, negExamples, "http://dbpedia.openlinksw.com:8890/sparql", new TreeSet<String>()); - - - } - - static void DBpedia(){ - se = SparqlEndpoint.getEndpointLOCALDBpedia(); - //concepts.add("(EXISTS \"monarch\".TOP AND EXISTS \"predecessor\".(\"Knight\" OR \"Secretary\"))"); - - SortedSet<String> concepts = new TreeSet<String>(); - SortedSet<String> tmpSet=selectDBpediaConcepts(20); - System.out.println(concepts.size()); - for (String string : tmpSet) { - concepts.add("\""+string+"\""); - } - concepts.remove(concepts.first()); - concepts.remove(concepts.first()); - concepts.remove(concepts.first()); - concepts.remove(concepts.first()); - concepts.remove(concepts.first()); - concepts.remove(concepts.first()); - concepts.remove(concepts.first()); - //concepts.remove(concepts.first()); - //concepts.add("(\"http://dbpedia.org/class/yago/HeadOfState110164747\" AND (\"http://dbpedia.org/class/yago/Negotiator110351874\" AND \"http://dbpedia.org/class/yago/Representative110522035\"))"); - //concepts.add("\"http://dbpedia.org/class/yago/Person100007846\""); - //concepts.add("\"http://dbpedia.org/class/yago/FieldMarshal110086821\""); - //concepts.add("http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"); - //concepts.add("http://dbpedia.org/resource/Category:Grammy_Award_winners"); - //concepts.add("EXISTS \"http://dbpedia.org/property/grammyawards\".TOP"); - - SortedSet<String> posExamples = new TreeSet<String>(); - SortedSet<String> negExamples = new TreeSet<String>(); - String url = "http://dbpedia.openlinksw.com:8890/sparql"; - url = "http://139.18.2.37:8890/sparql"; - //HashMap<String, ResultSet> result = new HashMap<String, ResultSet>(); - //HashMap<String, String> result2 = new HashMap<String, String>(); - //System.out.println(concepts.first()); - //logger.setLevel(Level.TRACE); - - //String concept=concepts.first(); - //int i=0; - Statistics.setCurrentLabel("0"); - int recursiondepth=0; - boolean closeAfterRecursion=false; - //int numberOfTriples = 0; - for (String oneConcept : concepts) { - //AutomaticExampleFinderSPARQLold ae= new AutomaticExampleFinderSPARQLold( se); - useRelated = true; - useSuperClasses = true; - useParallelClasses = false; - - poslimit=10; - neglimit=10; - //ae.initDBpedia(concept, useRelated, useSuperClasses,useParallelClasses, poslimit, neglimit); - //posExamples = ae.getPosExamples(); - //negExamples = ae.getNegExamples(); - - - /*String tmp = concepts.first().replace("http://dbpedia.org/resource/Category:", "").replace("\"",""); - tmp = tmp.replace("http://dbpedia.org/class/yago/", ""); - tmp = tmp.replace("http://dbpedia.org/property/", ""); - String confname = ""; - try{ - confname = URLEncoder.encode(tmp, "UTF-8")+".conf"; - }catch (Exception e) {e.printStackTrace();}*/ - // - //ConfWriter cf=new ConfWriter(); - //cf.addToStats("relearned concept: "+concepts.first()); - //System.out.println(confname); - LearnSparql ls = new LearnSparql(); - TreeSet<String> igno = new TreeSet<String>(); - System.out.println(oneConcept); - //igno.add(oneConcept.replaceAll("\"", "")); - - ls.learnDBpedia(posExamples, negExamples, url,igno,recursiondepth, closeAfterRecursion,false); - - //System.out.println("AAAAAAAA"); - //System.exit(0); - //"relearned concept: "; - //cf.writeSPARQL(confname, posExamples, negExamples, url, new TreeSet<String>(),standardSettings,algorithm); - // - - } - //Statistics.print(); - } - - - - - - - - - public static void init() { - - SimpleLayout layout = new SimpleLayout(); - // create logger (a simple logger which outputs - // its messages to the console) - FileAppender fileAppender =null; ; - try{ - fileAppender = new FileAppender(layout,"the_log.txt",false); - }catch (Exception e) {e.printStackTrace();} - - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.addAppender(fileAppender); - logger.setLevel(Level.DEBUG); - c = new Cache("cachetemp"); - - - } - - public static SortedSet<String> selectDBpediaConcepts(int number){ - String query = "SELECT DISTINCT ?concept WHERE { \n" + - "[] a ?concept .FILTER (regex(str(?concept),'yago'))" + - " \n} \n"; //LIMIT "+number+" - - - String JSON = (c.executeSparqlQuery(new SparqlQuery(query, se))); - ResultSet rs =SparqlQuery.convertJSONtoResultSet(JSON); - if(rs==null); - //JenaResultSetConvenience rsc = new JenaResultSetConvenience(rs); - //return SetManipulation.fuzzyShrink(rsc.getStringListForVariable("concept"),number); - return null; - } - - - -} Added: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -0,0 +1,167 @@ +/** + * 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.scripts; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.owl.Individual; +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.scripts.improveWikipedia.ConceptSelector; +import org.dllearner.scripts.improveWikipedia.WikipediaCategoryTasks; +import org.dllearner.utilities.JamonMonitorLogger; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; +import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; + +public class WikipediaCategoryCleaner { + + private static SPARQLTasks sparqlTasks; + + private static Cache cache; + + private static Logger logger = Logger.getRootLogger(); + + private static boolean local = true; // localEndpoint switch + + // parameters + public static final int SPARQL_RESULTSET_LIMIT = 1000; + + public static double PERCENT_OF_SKOSSET = 1.0; // the 70/30 strategy was + + // abandoned + + public static double NEGFACTOR = 1.0; // size of randomly choosen negative + + // examples compared to positives + + /** + * @param args + */ + public static void main(String[] args) { + initLogger(); + logger.info("Start"); + + // SETUP cache and sparqltasks + cache = Cache.getPersistentCache(); + + if (local) { + // url = "http://139.18.2.37:8890/sparql"; + sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint + .getEndpointLOCALDBpedia()); + } else { + // url = "http://dbpedia.openlinksw.com:8890/sparql"; + sparqlTasks = new SPARQLTasks(cache, SparqlEndpoint + .getEndpointDBpedia()); + } + + String target = "http://dbpedia.org/resource/Category:Prime_Ministers_of_the_United_Kingdom"; + // target = + // "http://dbpedia.org/resource/Category:Best_Actor_Academy_Award_winners"; + + WikipediaCategoryTasks s = new WikipediaCategoryTasks(sparqlTasks); + // TODO Optimize + s.calculateDefinitelyWrongIndividuals(target, PERCENT_OF_SKOSSET, + NEGFACTOR, SPARQL_RESULTSET_LIMIT); + + logger.info("Found " + s.getDefinitelyWrongIndividuals().size() + + " incorrect individuals"); + logger.debug("incorrect Individuals: " + + s.getDefinitelyWrongIndividuals()); + logger.info("reevaluating " + s.getConceptresults().size() + + " found Concepts"); + logger + .info("END OF PHASE 1 **********************************************"); + + s.reevaluateAndRelearn(); + List<EvaluatedDescription> newEval = s.getConceptresults(); + printEvaluatedDescriptionCollection(5, newEval); + + System.out.println("Finished"); + JamonMonitorLogger.printAllSortedByLabel(); + + } + + private static void initLogger() { + + SimpleLayout layout = new SimpleLayout(); + // create logger (a simple logger which outputs + // its messages to the console) + FileAppender fileAppender = null; + try { + fileAppender = new FileAppender(layout, "log/progress/skos" + + ConceptSelector.time() + ".txt", false); + } catch (Exception e) { + e.printStackTrace(); + } + + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.addAppender(fileAppender); + logger.setLevel(Level.DEBUG); + Logger.getLogger(KnowledgeSource.class).setLevel(Level.WARN); + + Logger.getLogger(SparqlQuery.class).setLevel(Level.INFO); + Logger.getLogger(Cache.class).setLevel(Level.INFO); + Logger.getLogger(AutomaticNegativeExampleFinderSPARQL.class).setLevel( + Level.INFO); + Logger.getLogger(AutomaticPositiveExampleFinderSPARQL.class).setLevel( + Level.INFO); + } + + public static void printEvaluatedDescriptionCollection(int howMany, + Collection<EvaluatedDescription> c) { + int x = 0; + Set<Individual> first = null; + Set<Individual> tmp = new HashSet<Individual>(); + for (EvaluatedDescription ed : c) { + if (x == 0) { + first = ed.getNotCoveredPositives(); + } + if (x >= howMany) { + x++; + break; + } + + tmp.addAll(ed.getNotCoveredPositives()); + tmp.removeAll(first); + logger.debug("*************************"); + logger.debug("Concept: " + ed); + logger.debug("accuracy: " + ed.getAccuracy()); + logger.debug("Not Covered compared to First: " + tmp); + logger.debug(ed.getScore()); + tmp.clear(); + + } + } + +} Added: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -0,0 +1,200 @@ +/** + * 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.scripts.improveWikipedia; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.owl.Individual; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; + +/** + * @author Sebastian Hellmann + * + * The EvaluatedDescriptions from a fragment are + * validated against the SPARQLendpoint. + * There are different strategies, see the methods; + */ +public class ConceptSPARQLReEvaluator { + + private static Logger logger = Logger + .getLogger(ConceptSPARQLReEvaluator.class); + + List<EvaluatedDescription> descToBeReevaluated; + + SPARQLTasks sparqlTasks; + + int sparqlResultLimit = 1000; + + int depthOfRDFS = 1; + + public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks, + List<EvaluatedDescription> descToBeReevaluated) { + this.descToBeReevaluated = descToBeReevaluated; + this.sparqlTasks = sparqlTasks; + } + + public ConceptSPARQLReEvaluator(SPARQLTasks sparqlTasks, + List<EvaluatedDescription> descToBeReevaluated, int depthOfRDFS, + int sparqlResultLimit) { + this(sparqlTasks, descToBeReevaluated); + this.depthOfRDFS = depthOfRDFS; + this.sparqlResultLimit = sparqlResultLimit; + } + + + public List<EvaluatedDescription> reevaluateConceptsByDataCoverage( + SortedSet<String> positiveSet, int maxNrOfConcepts) { + List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet); + List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>(); + + while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) { + returnSet.add(tmp.remove(0)); + } + + return returnSet; + } + + /** + * Accuracy is calculated as correct positive classified over (correct + * positive classified + incorrect negative classified) "How many are + * correctly positive classified?" e.g. 50 individuals of a 60-individual + * Category (50/60) + * + * @param positiveSet + * @return + */ + public List<EvaluatedDescription> reevaluateConceptsByDataCoverage( + SortedSet<String> positiveSet) { + + SortedSet<EvaluatedDescription> returnSet = new TreeSet<EvaluatedDescription>( + new EvaluatedDescriptionComparator()); + + SortedSet<String> instances = new TreeSet<String>(); + SortedSet<String> PosAsPos = new TreeSet<String>(); + SortedSet<String> PosAsNeg = new TreeSet<String>(); + + // NegAsPos doesnt exist, because they are supposed to be possible + // candidates + SortedSet<Individual> NegAsPos = new TreeSet<Individual>(); + // NegAsNeg doesnt exist, because all + SortedSet<Individual> NegAsNeg = new TreeSet<Individual>(); + + for (EvaluatedDescription ed : descToBeReevaluated) { + instances = retrieveInstances(ed); + + // PosAsPos + PosAsPos.addAll(positiveSet); + PosAsPos.retainAll(instances); + + // PosAsNeg + PosAsNeg.addAll(positiveSet); + PosAsNeg.removeAll(PosAsPos); + + returnSet.add(new EvaluatedDescription(ed.getDescription(), Helper + .getIndividualSet(PosAsPos), Helper + .getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg)); + + PosAsPos.clear(); + PosAsNeg.clear(); + + } + + return new ArrayList<EvaluatedDescription>(returnSet); + + } + + public List<EvaluatedDescription> reevaluateConceptsByLowestRecall( + SortedSet<String> positiveSet, int maxNrOfConcepts) { + List<EvaluatedDescription> tmp = reevaluateConceptsByLowestRecall(positiveSet); + List<EvaluatedDescription> returnSet = new ArrayList<EvaluatedDescription>(); + + while ((!tmp.isEmpty()) && (returnSet.size() <= maxNrOfConcepts)) { + returnSet.add(tmp.remove(0)); + } + + return returnSet; + } + + /** + * Accuracy is calculated as correct positive classified over all retrieved + * e.g. 50 correct out of 400 retrieved (50/400) + * + * @param positiveSet + * @return + */ + public List<EvaluatedDescription> reevaluateConceptsByLowestRecall( + SortedSet<String> positiveSet) { + logger.info("reevaluating by lowest recall " + + descToBeReevaluated.size() + " concepts"); + SortedSet<EvaluatedDescription> returnSet = new TreeSet<EvaluatedDescription>( + new EvaluatedDescriptionComparator()); + + SortedSet<String> instances = new TreeSet<String>(); + + SortedSet<String> PosAsPos = new TreeSet<String>(); + SortedSet<String> PosAsNeg = new TreeSet<String>(); + + SortedSet<Individual> NegAsPos = new TreeSet<Individual>(); + + SortedSet<Individual> NegAsNeg = new TreeSet<Individual>(); + + // elements are immediately removed from the list to save memory + while (!descToBeReevaluated.isEmpty()) { + EvaluatedDescription ed = descToBeReevaluated.remove(0); + + instances = retrieveInstances(ed); + + // PosAsPos + PosAsPos.addAll(positiveSet); + PosAsPos.retainAll(instances); + + // PosAsNeg + PosAsNeg.addAll(instances); + PosAsNeg.removeAll(PosAsPos); + + returnSet.add(new EvaluatedDescription(ed.getDescription(), Helper + .getIndividualSet(PosAsPos), Helper + .getIndividualSet(PosAsNeg), NegAsPos, NegAsNeg)); + + PosAsPos.clear(); + PosAsNeg.clear(); + + } + logger.info("finished reevaluating by lowest recall :" + + returnSet.size() + " concepts"); + return new ArrayList<EvaluatedDescription>(returnSet); + + } + + private SortedSet<String> retrieveInstances(EvaluatedDescription ed) { + String kbsyntax = ed.getDescription().toKBSyntaxString(); + return sparqlTasks + .retrieveInstancesForClassDescriptionIncludingSubclasses( + kbsyntax, sparqlResultLimit, depthOfRDFS); + } + +} Added: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -0,0 +1,130 @@ +/** + * 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.scripts.improveWikipedia; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.utilities.Files; + +/** + * This is a simple class, it might be worked into other classes later. + * filters concepts and records some results + * + * @author Sebastian Hellmann + * + */ +public class ConceptSelector { + + private static final long WASH = 1216800000000L; + + List<EvaluatedDescription> concepts; + + public ConceptSelector(LearningAlgorithm la) { + super(); + this.concepts = la.getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, 0.0, true); + this.recordConceptClasses(); + + } + + + public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts) { + super(); + this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts); + + } + + public ConceptSelector(LearningAlgorithm la, int maxNrOfConcepts, double acctreshold) { + super(); + this.concepts = la.getCurrentlyBestEvaluatedDescriptions(maxNrOfConcepts, acctreshold, true); + this.recordConceptClasses(); + } + + public List<EvaluatedDescription> getConceptsWithoutOR(){ + return getConceptsNotContainingString("OR"); + } + + public List<EvaluatedDescription> getConceptsNotContainingString(String filterString, int limitSize){ + List<EvaluatedDescription> tmp = getConceptsNotContainingString(filterString); + List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>(); + + while ((!tmp.isEmpty()) && (result.size() <= limitSize)) { + result.add(tmp.remove(0)); + } + return result; + } + + + public List<EvaluatedDescription> getConceptsNotContainingString(String filterString){ + + List<EvaluatedDescription> result = new ArrayList<EvaluatedDescription>(); + for (EvaluatedDescription description : concepts) { + if (!description.toString().contains(filterString)) { + result.add(description); + } + + } + return result; + } + + + + + public void recordConceptClasses() { + StringBuffer result =new StringBuffer(); + StringBuffer result1 =new StringBuffer("\n\n ***********Entity*****\n"); + StringBuffer result2 =new StringBuffer("\n\n ***********OR*****\n"); + int result1count = 1; + int result2count = 1; + + + int x = 0; + for (EvaluatedDescription description : concepts) { + if (x < 50) { + x++; + result.append(description + "\n"); + } + + if (!description.toString().contains("Entity")) { + result1.append(description + "\n"); + result1count++; + } + if (!description.toString().contains("OR")) { + result2.append(description + "\n"); + result2count++; + } + } + result.append("full size: " + concepts.size()); + result.append(result1.toString() + " size: " + result1count + "\n"); + result.append(result2.toString() + " size: " + result2count + "\n"); + + Files.createFile(new File("results/descriptions/concepts" + time() + + ".txt"), result.toString()); + } + + public static String time() { + return ("" + (System.currentTimeMillis() - WASH)).substring(0, 7); + + } + +} Added: trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java 2008-07-31 16:27:38 UTC (rev 1042) @@ -0,0 +1,251 @@ +/** + * 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.scripts.improveWikipedia; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.scripts.WikipediaCategoryCleaner; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.datastructures.SetManipulation; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; +import org.dllearner.utilities.examples.AutomaticPositiveExampleFinderSPARQL; +import org.dllearner.utilities.learn.LearnSPARQLConfiguration; +import org.dllearner.utilities.learn.LearnSparql; + +public class WikipediaCategoryTasks { + + private static Logger logger = Logger + .getLogger(WikipediaCategoryTasks.class); + + private static final boolean STABLE = true; // used for developing, same + + // negExamples not random + + private static final int MAXIMUM_NUMBER_OF_CONCEPTS_KEPT = Integer.MAX_VALUE; + + private static final double ACCTRESHOLD = 0.0; + + private SPARQLTasks sparqlTasks; + + private SortedSet<String> posExamples = new TreeSet<String>(); + + private SortedSet<String> fullPositiveSet = new TreeSet<String>(); + + // private SortedSet<String> fullPosSetWithoutPosExamples = new + // TreeSet<String>(); + + private SortedSet<String> negExamples = new TreeSet<String>(); + + private SortedSet<String> definitelyWrongIndividuals = new TreeSet<String>(); + + private List<EvaluatedDescription> conceptresults = new ArrayList<EvaluatedDescription>(); + + public WikipediaCategoryTasks(SPARQLTasks sparqlTasks) { + this.sparqlTasks = sparqlTasks; + } + + /** + * @param SKOSConcept + * @param percentOfSKOSSet + * @param negfactor + * @param sparqlResultLimit + */ + public void calculateDefinitelyWrongIndividuals(String SKOSConcept, + double percentOfSKOSSet, double negfactor, int sparqlResultLimit) { + + makeExamples(SKOSConcept, percentOfSKOSSet, negfactor, + sparqlResultLimit); + + LearnSparql learner = new LearnSparql( + prepareConfigurationToFindWrongIndividuals()); + LearningAlgorithm la = null; + try { + la = learner.learn(posExamples, negExamples); + } catch (Exception e) { + e.printStackTrace(); + } + // TODO maybe not smart here + ConceptSelector cs = new ConceptSelector(la, + MAXIMUM_NUMBER_OF_CONCEPTS_KEPT, ACCTRESHOLD); + conceptresults = cs.getConceptsNotContainingString("Entity", + MAXIMUM_NUMBER_OF_CONCEPTS_KEPT); + if (conceptresults.size() == 0) { + logger.warn("NO GOOD CONCEPTS FOUND"); + } + + definitelyWrongIndividuals = Helper.getStringSet(conceptresults.get(0) + .getNotCoveredPositives()); + + // clean the examples + posExamples.removeAll(definitelyWrongIndividuals); + fullPositiveSet.removeAll(definitelyWrongIndividuals); + // fullPosSetWithoutPosExamples.removeAll(definitelyWrongIndividuals); + + logger.trace("posExamples" + posExamples.size()); + logger.trace("fullPositives" + fullPositiveSet.size()); + + negExamples.clear(); + + } + + public void reevaluateAndRelearn() { + + ConceptSPARQLReEvaluator csparql = new ConceptSPARQLReEvaluator( + sparqlTasks, conceptresults); + List<EvaluatedDescription> reEvaluatedDesc; + + // TODO Optimize here + reEvaluatedDesc = csparql.reevaluateConceptsByLowestRecall( + fullPositiveSet, 1); + + // TODO add check if it is correct + WikipediaCategoryCleaner.printEvaluatedDescriptionCollection(10, + reEvaluatedDesc); + EvaluatedDescription newDesc = reEvaluatedDesc.get(0); + logger.info("Best concept: " + newDesc.getDescription()); + + negExamples.clear(); + negExamples.addAll(Helper.getStringSet(newDesc.getCoveredPositives())); + negExamples.addAll(Helper + .getStringSet(newDesc.getNotCoveredPositives())); + negExamples.... [truncated message content] |
From: <ku...@us...> - 2008-07-31 16:23:46
|
Revision: 1041 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1041&view=rev Author: kurzum Date: 2008-07-31 16:23:42 +0000 (Thu, 31 Jul 2008) Log Message: ----------- package.html, headers Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/scripts/CloseOntology.java trunk/src/dl-learner/org/dllearner/scripts/NT2RDF.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/scripts/AutoDetectFilter.java trunk/src/dl-learner/org/dllearner/scripts/package.html Added: trunk/src/dl-learner/org/dllearner/scripts/AutoDetectFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/AutoDetectFilter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/AutoDetectFilter.java 2008-07-31 16:23:42 UTC (rev 1041) @@ -0,0 +1,85 @@ + +/** + * 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.scripts; + +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; + +/** + * @author Sebastian Hellmann + * This class is under developement and can not be completed, + * unless the & bug mentioned in SparqlQuery is completed + */ +public class AutoDetectFilter { + private SPARQLTasks sparqlTasks; + private String resource; + public AutoDetectFilter(SPARQLTasks sparqlTasks, String resource) { + super(); + this.sparqlTasks = sparqlTasks; + this.resource = resource; + } + + public static void main(String[] args) { + // String url = "http://139.18.2.37:8890/sparql"; + String resource = "http://dbpedia.org/resource/Angela_Merkel"; + //resource = "http://dbpedia.org/resource/Lutheran"; + AutoDetectFilter adf = new AutoDetectFilter(new SPARQLTasks(Cache.getDefaultCache(), + SparqlEndpoint.getEndpointDBpedia()),resource); + + adf.detect(); + } + + public void detect(){ + String s1 = "SELECT * WHERE { <"+resource+"> ?predicate ?object .FILTER (!isLiteral(?object))}"; + String s2 = "SELECT * WHERE { <"+resource+"> ?predicate ?object .FILTER (!isLiteral(?object))." + + "?object ?p2 ?o2." + + " }"; + + System.out.println(s1); + //System.out.println(sparqlTasks.query(s2)); + //System.exit(0); + + SortedSet<String> predicates = new TreeSet<String>(); + SortedSet<String> objects = new TreeSet<String>(); + SortedSet<String> legalpreds = new TreeSet<String>(); + SortedSet<String> legalObjs = new TreeSet<String>(); + + + predicates = sparqlTasks.queryAsSet(s1, "predicate"); + objects = sparqlTasks.queryAsSet(s1, "object"); + legalpreds = sparqlTasks.queryAsSet(s2, "predicate"); + legalObjs = sparqlTasks.queryAsSet(s2, "object"); + + + System.out.println(predicates); + System.out.println(legalpreds); + predicates.removeAll(legalpreds); + System.out.println(predicates); + + System.out.println(objects); + System.out.println(legalObjs); + objects.removeAll(legalObjs); + System.out.println(objects); + + } + +} Modified: trunk/src/dl-learner/org/dllearner/scripts/CloseOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/CloseOntology.java 2008-07-31 16:22:32 UTC (rev 1040) +++ trunk/src/dl-learner/org/dllearner/scripts/CloseOntology.java 2008-07-31 16:23:42 UTC (rev 1041) @@ -1,3 +1,20 @@ +/** + * 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.scripts; import java.io.File; Modified: trunk/src/dl-learner/org/dllearner/scripts/NT2RDF.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/NT2RDF.java 2008-07-31 16:22:32 UTC (rev 1040) +++ trunk/src/dl-learner/org/dllearner/scripts/NT2RDF.java 2008-07-31 16:23:42 UTC (rev 1041) @@ -1,3 +1,20 @@ +/** + * 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.scripts; import java.io.File; import java.net.URI; Added: trunk/src/dl-learner/org/dllearner/scripts/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/package.html 2008-07-31 16:23:42 UTC (rev 1041) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Runnable scripts, each for a different task or experiment.</p> +</body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:22:37
|
Revision: 1040 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1040&view=rev Author: kurzum Date: 2008-07-31 16:22:32 +0000 (Thu, 31 Jul 2008) Log Message: ----------- comments, improvements, package.html Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/package.html Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-31 16:19:27 UTC (rev 1039) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-31 16:22:32 UTC (rev 1040) @@ -112,7 +112,7 @@ final SortedSet<String> tmpSet = new TreeSet<String>(); // collect super/subclasses for the depth - for (; depth != 0; depth--) { + for (; (depth != 0) && (!toBeRetrieved.isEmpty()); depth--) { // collect super/subclasses for each class in toBeRetrieved // accumulate in tmpSet for (String oneClass : toBeRetrieved) { @@ -142,26 +142,22 @@ } /** - * gets a SortedSet of all subclasses. + * gets a SortedSet of all subclasses up to a certain depth * * @see conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache * c, boolean simple ) - * @param classURI + * @param classURI An URI string with no quotes * @param maxDepth * @return TreeSet of subclasses including classURI */ public SortedSet<String> getSubClasses(final String classURI, final int maxDepth) { - if (classURI.contains("\"")) { - // TODO exception - } +// TODO check for quotes in uris return getRecursiveSuperOrSubClasses(classURI, maxDepth, true); } /** - * QUALITY: workaround for a sparql glitch {?a owl:subclassOf ?b} returns an - * empty set on some endpoints. returns all direct subclasses of String - * concept + * returns all direct subclasses of String concept * * @param concept * An URI string with no quotes @@ -192,13 +188,6 @@ */ public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject( String role, String object, int sparqlResultLimit) { - /* - * String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + - * "?subject " + "<" + role + "> " + "<" + object + "> \n" + "} " + - * limit(sparqlResultLimit); - * - * return queryAsSet(sparqlQueryString, "subject"); - */ return queryPatternAsSet("?subject", "<" + role + ">", "<" + object + ">", "subject", sparqlResultLimit, true); } @@ -214,13 +203,6 @@ */ public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject, String role, int sparqlResultLimit) { - /* - * String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" + - * subject + "> " + "<" + role + "> " + " ?object \n" + "} LIMIT " + - * sparqlResultLimit; - * - * return queryAsSet(sparqlQueryString, "object"); - */ return queryPatternAsSet("<" + subject + ">", "<" + role + ">", "?object", "object", sparqlResultLimit, true); } @@ -238,8 +220,6 @@ String skosConcept, int sparqlResultLimit) { return queryPatternAsSet("?subject", "?predicate", "<" + skosConcept + ">", "subject", sparqlResultLimit, false); - // return - // retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject", } /** @@ -485,6 +465,10 @@ } + public SparqlEndpoint getSparqlEndpoint() { + return sparqlEndpoint; + } + } /* Added: trunk/src/dl-learner/org/dllearner/kb/sparql/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/package.html 2008-07-31 16:22:32 UTC (rev 1040) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Runnable scripts, each for a different task or experiment.</p> +</body> +</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:19:30
|
Revision: 1039 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1039&view=rev Author: kurzum Date: 2008-07-31 16:19:27 +0000 (Thu, 31 Jul 2008) Log Message: ----------- small changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-07-31 16:17:21 UTC (rev 1038) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-07-31 16:19:27 UTC (rev 1039) @@ -329,9 +329,9 @@ m.useConfiguration(sparqlQueryType, endpoint, manipulator, recursionDepth, getAllSuperClasses, closeAfterRecursion, cacheDir); - + String ont = ""; try { - String ont = ""; + // the actual extraction is started here SimpleClock sc2=new SimpleClock(); sc2.setTime(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:17:25
|
Revision: 1038 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1038&view=rev Author: kurzum Date: 2008-07-31 16:17:21 +0000 (Thu, 31 Jul 2008) Log Message: ----------- added a clearcache method Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-07-31 16:16:21 UTC (rev 1037) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-07-31 16:17:21 UTC (rev 1038) @@ -263,7 +263,7 @@ SparqlQuery.writeToSparqlLog("***********\nJSON retrieved from cache"); SparqlQuery.writeToSparqlLog(query.getSparqlQueryString()); SparqlQuery.writeToSparqlLog(query.getSparqlEndpoint().getURL().toString()); - SparqlQuery.writeToSparqlLog("JSON: "+result); + //SparqlQuery.writeToSparqlLog("JSON: "+result); JamonMonitorLogger.increaseCount(Cache.class, "SuccessfulHits"); } else { @@ -290,6 +290,24 @@ } /** + * deletes all Files in the cacheDir, does not delete the cacheDir itself, + * and can thus still be used without creating a new Cache Object + */ + public void clearCache() { + try{ + File f = new File(cacheDir); + String[] files = f.list(); + for (int i = 0; i < files.length; i++) { + new File(cacheDir+"/"+files[i]).delete(); + } + }catch (Exception e) { + logger.warn("deleting cache failed"); + e.printStackTrace(); + } + + } + + /** * Changes how long cached results will stay fresh (default 15 days). * @param days number of days */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:16:28
|
Revision: 1037 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1037&view=rev Author: kurzum Date: 2008-07-31 16:16:21 +0000 (Thu, 31 Jul 2008) Log Message: ----------- exceptions are caught, written to sparqllog and rethrown Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-31 16:14:45 UTC (rev 1036) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-31 16:16:21 UTC (rev 1037) @@ -25,6 +25,8 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; +import javax.xml.ws.http.HTTPException; + import org.apache.log4j.Logger; import org.dllearner.utilities.JamonMonitorLogger; @@ -40,10 +42,13 @@ * query (which may be necessary if a timeout is reached). * * @author Jens Lehmann + * @author Sebastian Hellmann * */ public class SparqlQuery { + private static boolean logDeletedOnStart = false; + private static Logger logger = Logger.getLogger(SparqlQuery.class); private boolean isRunning = false; @@ -75,9 +80,10 @@ * method getasjson * */ - public void send() { + public void send(){ wasExecuted = true; // isRunning = true; + ResultSet rs; writeToSparqlLog("***********\nNew Query:"); @@ -104,22 +110,40 @@ //the XML Parser throws an error, because he thinks &profile is an html entitie //but it doesn't end with an ; //the & must be masked to an & but I am not sure at the moment how to do that - rs = queryExecution.execSelect(); + try{ + + logger.debug("sending query: length: " + sparqlQueryString.length() + " | ENDPOINT: " + + sparqlEndpoint.getURL().toString()); + rs = queryExecution.execSelect(); + + + + json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs)); + //writeToSparqlLog("JSON: " + json); + }catch (HTTPException e) { + logger.warn("Exception in SparqlQuery\n"+ e.toString()); + logger.warn("query was "+ sparqlQueryString); + writeToSparqlLog("ERROR: HTTPException occured"+ e.toString()); + writeToSparqlLog("ERROR: query was: "+sparqlQueryString); + throw e; + }catch (RuntimeException e) { + //if (!(e instanceof HTTPException)) { + logger.warn("RuntimeException in SparqlQuery"+ e.toString()); + writeToSparqlLog("ERROR: HTTPException occured"+ e.toString()); + writeToSparqlLog("ERROR: query was: "+sparqlQueryString); + //} + throw e; + } + + // there is a minor issue here: Jamon now also measures ResultsetConversion + // the code would need a second try catch block to handle it correctly JamonMonitorLogger.getTimeMonitor(SparqlQuery.class, "httpTime").stop(); - - logger.debug("query length: " + sparqlQueryString.length() + " | ENDPOINT: " - + sparqlEndpoint.getURL().toString()); - // writeToSparqlLog("query: "+queryString+ " | ENDPOINT: - // "+endpoint.getURL().toString()); - - json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs)); - - writeToSparqlLog("JSON: " + json); - isRunning = false; - + } + + /** * Stops the execution of the query. */ @@ -194,11 +218,6 @@ */ public ResultSet getResultSet() { return (getJson() == null) ? null : convertJSONtoResultSet(json); - - /*if (getJson() == null) { - return null; - } else - return JSONtoResultSet(json);*/ } /** @@ -208,11 +227,6 @@ */ public String getXMLString() { return (getJson() == null) ? null : convertJSONtoXML(json); - - /*if (getJson() == null) { - return null; - } else - return JSONtoXML(json);*/ } /** @@ -223,8 +237,9 @@ */ public static void writeToSparqlLog(String s) { try { - // - FileWriter fw = new FileWriter("log/sparql.txt", true); + + FileWriter fw = new FileWriter("log/sparql.txt", logDeletedOnStart); + logDeletedOnStart = true; fw.write(s + "\n"); fw.flush(); fw.close(); @@ -304,4 +319,6 @@ public static String convertJSONtoXML(String json) { return convertResultSetToXMLString(convertJSONtoResultSet(json)); } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:14:50
|
Revision: 1036 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1036&view=rev Author: kurzum Date: 2008-07-31 16:14:45 +0000 (Thu, 31 Jul 2008) Log Message: ----------- small improvements Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-07-31 16:13:14 UTC (rev 1035) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-07-31 16:14:45 UTC (rev 1036) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Vector; import org.dllearner.utilities.datastructures.StringTuple; @@ -94,8 +96,8 @@ * @see org.dllearner.kb.sparql.datastructure.Node#toNTriple() */ @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); + public SortedSet<String> toNTriple() { + SortedSet<String> s = new TreeSet<String>(); s.add("<" + this.uri + "><" + rdftype + "><" + classns + ">."); for (PropertyNode one : properties) { Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-07-31 16:13:14 UTC (rev 1035) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-07-31 16:14:45 UTC (rev 1036) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Vector; import org.dllearner.utilities.datastructures.StringTuple; @@ -94,8 +96,8 @@ } @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); + public SortedSet<String> toNTriple() { + SortedSet<String> s = new TreeSet<String>(); s.add("<" + uri + "><" + rdftype + "><" + thing + ">."); for (ClassNode one : classes) { s.add("<" + uri + "><" + rdftype + "><" + one.getURI() + ">."); Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-07-31 16:13:14 UTC (rev 1035) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-07-31 16:14:45 UTC (rev 1036) @@ -66,7 +66,7 @@ System.out.println("Start extracting"); Node n = extractionAlgorithm.expandNode(uri, typedSparqlQuery); - Set<String> s = n.toNTriple(); + SortedSet<String> s = n.toNTriple(); String nt = ""; for (String str : s) { nt += str + "\n"; Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-07-31 16:13:14 UTC (rev 1035) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-07-31 16:14:45 UTC (rev 1036) @@ -20,7 +20,7 @@ package org.dllearner.kb.extraction; import java.net.URI; -import java.util.Set; +import java.util.SortedSet; import java.util.Vector; @@ -72,7 +72,7 @@ * * @return a set of n-triple */ - public abstract Set<String> toNTriple(); + public abstract SortedSet<String> toNTriple(); @Override public String toString() { Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-07-31 16:13:14 UTC (rev 1035) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-07-31 16:14:45 UTC (rev 1036) @@ -23,6 +23,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Vector; import org.dllearner.utilities.datastructures.StringTuple; @@ -88,8 +90,8 @@ } @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); + public SortedSet<String> toNTriple() { + SortedSet<String> s = new TreeSet<String>(); s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + "http://www.w3.org/2002/07/owl#ObjectProperty" + ">."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-31 16:13:18
|
Revision: 1035 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1035&view=rev Author: kurzum Date: 2008-07-31 16:13:14 +0000 (Thu, 31 Jul 2008) Log Message: ----------- added a getSore() getter method Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-07-31 14:29:56 UTC (rev 1034) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-07-31 16:13:14 UTC (rev 1035) @@ -101,6 +101,13 @@ public double getAccuracy() { return score.getAccuracy(); } + + /** + * @see org.dllearner.core.Score + */ + public Score getScore() { + return score; + } /** * @see org.dllearner.core.Score#getCoveredNegatives() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-31 14:30:06
|
Revision: 1034 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1034&view=rev Author: jenslehmann Date: 2008-07-31 14:29:56 +0000 (Thu, 31 Jul 2008) Log Message: ----------- - improved refinement operator interface - continued work on EL description trees Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -24,7 +24,12 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.UnsupportedLanguageException; /** * Represents an EL description tree, which corresponds to a @@ -86,6 +91,16 @@ } /** + * Constructs an EL description tree from an EL description. + * @param description A description + */ + public ELDescriptionTree(Description description) { + // TODO not implemented + // throw an exception if the description is not in EL + throw new UnsupportedLanguageException(description.toString(), "EL"); + } + + /** * Checks whether this node has a parent. If the parent link * is null, the node is considered to be a root node. * @return True of this is the root node and false otherwise. @@ -127,6 +142,33 @@ } /** + * This method transform the tree to an EL description. The + * node labels are transformed to an {@link Intersection} + * of {@link NamedClass}. Each edges is transformed to an + * {@link ObjectSomeRestriction}, where the property is the edge + * label and the child description the subtree the edge points + * to. Edges are also added to the intersection. If the intersection + * is empty, {@link Thing} is returned. + * @return The description corresponding to this EL description tree. + */ + public Description transformToDescription() { + if(label.size()==0 && edges.size()==0) { + return new Thing(); + } else { + Intersection is = new Intersection(); + for(NamedClass nc : label) { + is.addChild(nc); + } + for(Edge edge : edges) { + Description child = edge.getTree().transformToDescription(); + ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child); + is.addChild(osr); + } + return is; + } + } + + /** * @return The label of root node of this subtree. */ public SortedSet<NamedClass> getLabel() { Added: trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/UnsupportedLanguageException.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -0,0 +1,39 @@ +/** + * 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.core.owl; + +/** + * This exception is thrown if an operation does not support + * the required language. For instance, if a description containing + * a disjunction is passed to a method, which is only designed to + * handle EL concepts, this exception can be thrown. + * + * @author Jens Lehmann + * + */ +public class UnsupportedLanguageException extends RuntimeException { + + private static final long serialVersionUID = -1271204878357422920L; + + public UnsupportedLanguageException(String unsupportedConstruct, String targetLanguage) { + super("Unsupported construct \"" + unsupportedConstruct + "\". The target language is \"" + targetLanguage + "\"."); + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -19,9 +19,10 @@ */ package org.dllearner.refinementoperators; -import java.util.List; +import java.util.HashSet; import java.util.Set; +import org.dllearner.algorithms.el.ELDescriptionTree; import org.dllearner.core.owl.Description; /** @@ -42,24 +43,31 @@ * @author Jens Lehmann * */ -public class ELDown implements RefinementOperator { +public class ELDown extends RefinementOperatorAdapter { /* (non-Javadoc) * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) */ @Override public Set<Description> refine(Description concept) { - // TODO Auto-generated method stub - return null; + ELDescriptionTree tree = new ELDescriptionTree(concept); + Set<ELDescriptionTree> refinementTrees = refine(tree); + Set<Description> refinements = new HashSet<Description>(); + for(ELDescriptionTree refinementTree : refinementTrees) { + refinements.add(refinementTree.transformToDescription()); + } + return refinements; } - - /* (non-Javadoc) - * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) + + /** + * Performs downward refinement for the given tree. The operator + * works directly on EL description trees (which differ from the + * the tree structures build by descriptions). + * + * @param tree Input EL description tree. + * @return Set of refined EL description trees. */ - @Override - public Set<Description> refine(Description concept, int maxLength, - List<Description> knownRefinements) { - // TODO Auto-generated method stub + public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { return null; } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -34,7 +34,7 @@ * @author jl * */ -public class PsiDown implements RefinementOperator { +public class PsiDown extends RefinementOperatorAdapter { ConceptComparator conceptComparator = new ConceptComparator(); @@ -75,6 +75,7 @@ } } + @Override @SuppressWarnings("unchecked") public Set<Description> refine(Description concept) { @@ -236,6 +237,7 @@ } + @Override public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements) { throw new RuntimeException(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -22,7 +22,7 @@ import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.owl.ConceptComparator; -public class PsiUp implements RefinementOperator { +public class PsiUp extends RefinementOperatorAdapter { ConceptComparator conceptComparator = new ConceptComparator(); @@ -63,6 +63,7 @@ } } + @Override @SuppressWarnings("unchecked") public Set<Description> refine(Description concept) { @@ -212,6 +213,7 @@ return refinements; } + @Override public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements) { throw new RuntimeException(); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -1,3 +1,22 @@ +/** + * 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.refinementoperators; import java.util.List; @@ -5,10 +24,45 @@ import org.dllearner.core.owl.Description; +/** + * Interface for all refinement operators based on OWL/Description Logics. + * A refinement operator + * maps a description to a set of descriptions. For downward refinement + * operators those descriptions are more special. For upward refinement + * operators, those descriptions are more general. + * + * @author Jens Lehmann + * + */ public interface RefinementOperator { - public Set<Description> refine(Description concept); - // SortedSet zu erzwingen ist nicht so elegant - public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements); + /** + * Standard refinement operation. + * @param description The description, which will be refined. + * @return A set of refinements. + */ + public Set<Description> refine(Description description); + /** + * Optional refinement operation, where the learning algorithm can + * specify an additional bound on the length of descriptions. + * + * @param description The description, which will be refined. + * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. + * @return A set of refinements obeying the above restrictions. + */ + public Set<Description> refine(Description description, int maxLength); + + /** + * Optional refinement operation, where the learning algorithm can + * specify an additional bound on the length of descriptions and + * a list of known refinements, which do not need to be returned. + * + * @param description The description, which will be refined. + * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. + * @param knownRefinements A collection of known refinements, which do not need to be returned. + * @return A set of refinements obeying the above restrictions. + */ + public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements); + } Added: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperatorAdapter.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -0,0 +1,58 @@ +/** + * 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.refinementoperators; + +import java.util.List; +import java.util.Set; + +import org.dllearner.core.owl.Description; + +/** + * Adapter for {@link RefinementOperator} interface. + * + * @author Jens Lehmann + * + */ +public abstract class RefinementOperatorAdapter implements RefinementOperator { + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) + */ + @Override + public abstract Set<Description> refine(Description description); + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int) + */ + @Override + public Set<Description> refine(Description description, int maxLength) { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) + */ + @Override + public Set<Description> refine(Description description, int maxLength, + List<Description> knownRefinements) { + throw new UnsupportedOperationException(); + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -73,7 +73,7 @@ * @author Jens Lehmann * */ -public class RhoDRDown implements RefinementOperator { +public class RhoDRDown extends RefinementOperatorAdapter { @SuppressWarnings({"unused"}) private static Logger logger = Logger @@ -259,6 +259,7 @@ /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description) */ + @Override public Set<Description> refine(Description concept) { throw new RuntimeException(); } @@ -266,6 +267,7 @@ /* (non-Javadoc) * @see org.dllearner.algorithms.refinement.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) */ + @Override public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements) { return refine(description, maxLength, knownRefinements, startClass); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-31 11:45:59 UTC (rev 1033) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-31 14:29:56 UTC (rev 1034) @@ -59,7 +59,7 @@ * @author Jens Lehmann * */ -public class RhoDown implements RefinementOperator { +public class RhoDown extends RefinementOperatorAdapter { // private PosNegLP learningProblem; private ReasoningService rs; @@ -111,6 +111,7 @@ // rs = learningProblem.getReasoningService(); } + @Override public Set<Description> refine(Description concept) { throw new RuntimeException(); // TODO Auto-generated method stub @@ -123,6 +124,7 @@ // => als zweites wäre bei nicht ausreichendem Performancegewinn die Implementierung // von Minimallänge eine Möglichkeit (alle Refinements, auch improper, müssten // dann im Algorithmus gespeichert werden) + @Override @SuppressWarnings("unchecked") public SortedSet<Description> refine(Description concept, int maxLength, List<Description> knownRefinements) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-31 11:46:03
|
Revision: 1033 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1033&view=rev Author: jenslehmann Date: 2008-07-31 11:45:59 +0000 (Thu, 31 Jul 2008) Log Message: ----------- EL description trees continued Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 10:15:31 UTC (rev 1032) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -34,7 +34,10 @@ * of named classes and the edges are labelled with a property. * * In the documentation below "this node" refers to the root node - * of this EL description (sub-)tree. + * of this EL description (sub-)tree. One tree cannot be reused, + * i.e. used as subtree in several description trees, as some of + * the associated variables (level, simulation) depend on the overall + * tree. * * @author Jens Lehmann * @@ -45,16 +48,23 @@ private List<Edge> edges; + private int level; + // parent node in the tree; // null indicates that this node is a root node private ELDescriptionTree parent = null; + // to simplify equivalence checks and minimisation, we + // attach a simulation relation to the description tree + private Simulation simulation; + /** * Constructs an empty EL description tree with the empty set * as root label and an empty set of outgoing edges. */ public ELDescriptionTree() { this(new TreeSet<NamedClass>(), new LinkedList<Edge>()); + simulation = new Simulation(); } /** @@ -100,11 +110,13 @@ /** * Traverses the tree until the root node and counts how * many edges are traversed. If this node does not have a parent, - * zero is returned. + * zero is returned. This method is used for checking the integrity + * of the tree in unit tests. Use {@link #getLevel()} to get the + * level of the tree. * @return The level of this node (or more specifically the root * node of this subtree) within the overall EL description tree. */ - public int getLevel() { + public int computeLevel() { ELDescriptionTree root = this; int level = 0; while(root.parent != null) { @@ -127,5 +139,12 @@ public List<Edge> getEdges() { return edges; } + + /** + * @return The level of the (root node of) this subtree in the overall tree. + */ + public int getLevel() { + return level; + } } Added: trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/Simulation.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -0,0 +1,109 @@ +/** + * 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.algorithms.el; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Represents a simulation relation between EL description trees. + * + * @author Jens Lehmann + * + */ +public class Simulation { + + // the simulation relation S itself + private List<TreeTuple> relation; + + // { w | (v,w) \in S } for all w + private Map<ELDescriptionTree,List<ELDescriptionTree>> in; + + // { v | (v,w) \in S } for all v + private Map<ELDescriptionTree,List<ELDescriptionTree>> out; + + public Simulation() { + relation = new LinkedList<TreeTuple>(); + in = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>(); + out = new HashMap<ELDescriptionTree,List<ELDescriptionTree>>(); + } + + /** + * Adds a tuple to the simulation. + * + * @param tuple The new tuple. + * @see java.util.List#add(java.lang.Object) + */ + public void addTuple(TreeTuple tuple) { + relation.add(tuple); + + if(in.containsKey(tuple.getTree2())) { + in.get(tuple.getTree2()).add(tuple.getTree1()); + } else { + List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>(); + list.add(tuple.getTree1()); + in.put(tuple.getTree2(), list); + } + + if(out.containsKey(tuple.getTree1())) { + out.get(tuple.getTree1()).add(tuple.getTree2()); + } else { + List<ELDescriptionTree> list = new LinkedList<ELDescriptionTree>(); + list.add(tuple.getTree2()); + out.put(tuple.getTree1(), list); + } + } + + /** + * Removes a tuple from the simulation. + * + * @param tuple The new tuple. + * @see java.util.List#add(java.lang.Object) + */ + public void removeTuple(TreeTuple tuple) { + relation.remove(tuple); + + in.get(tuple.getTree2()).remove(tuple.getTree1()); + if(in.get(tuple.getTree2()).isEmpty()) + in.remove(tuple.getTree2()); + + out.get(tuple.getTree1()).remove(tuple.getTree2()); + if(out.get(tuple.getTree1()).isEmpty()) + out.remove(tuple.getTree1()); + } + + /** + * Gets the complete simulation relation. + * @return the relation + */ + public List<TreeTuple> getRelation() { + return relation; + } + + public List<ELDescriptionTree> in(ELDescriptionTree tree) { + return in.get(tree); + } + + public List<ELDescriptionTree> out(ELDescriptionTree tree) { + return out.get(tree); + } +} Added: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeTuple.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -0,0 +1,55 @@ +/** + * 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.algorithms.el; + +/** + * A tuple of two EL description trees. + * + * @author Jens Lehmann + * + */ +public class TreeTuple { + + private ELDescriptionTree tree1; + + private ELDescriptionTree tree2; + + public TreeTuple(ELDescriptionTree tree1, ELDescriptionTree tree2) { + this.tree1 = tree1; + this.tree2 = tree2; + } + + /** + * Gets first tree. + * @return - first tree + */ + public ELDescriptionTree getTree1() { + return tree1; + } + + /** + * Gets second tree. + * @return - second tree + */ + public ELDescriptionTree getTree2() { + return tree2; + } + +} Added: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-07-31 11:45:59 UTC (rev 1033) @@ -0,0 +1,49 @@ +/** + * 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.test.junit; + +import static org.junit.Assert.*; + +import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.algorithms.el.Simulation; +import org.dllearner.algorithms.el.TreeTuple; +import org.junit.Test; + +/** + * Tests related to EL description tree including operations on + * them, simulations, equivalence checks, minimisation etc. + * + * @author Jens Lehmann + * + */ +public final class ELDescriptionTreeTests { + + @Test + public void simulationTest() { + Simulation s = new Simulation(); + ELDescriptionTree t1 = new ELDescriptionTree(); + ELDescriptionTree t2 = new ELDescriptionTree(); + TreeTuple tuple1 = new TreeTuple(t1,t2); + s.addTuple(tuple1); + assertTrue(s.in(t2).size() == 1); + assertTrue(s.out(t2).size() == 0); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-31 10:15:35
|
Revision: 1032 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1032&view=rev Author: jenslehmann Date: 2008-07-31 10:15:31 +0000 (Thu, 31 Jul 2008) Log Message: ----------- fix for bug #2033082 Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-07-31 10:10:18 UTC (rev 1031) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-07-31 10:15:31 UTC (rev 1032) @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -332,15 +333,18 @@ for(OWLDataProperty owlProperty : owlDatatypeProperties) { DatatypeProperty dtp = new DatatypeProperty(owlProperty.getURI().toString()); Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); - OWLDataRange range = ranges.iterator().next(); - if(range.isDataType()) { - URI uri = ((OWLDataType)range).getURI(); - if(uri.equals(Datatype.BOOLEAN.getURI())) - booleanDatatypeProperties.add(dtp); - else if(uri.equals(Datatype.DOUBLE.getURI())) - doubleDatatypeProperties.add(dtp); - else if(uri.equals(Datatype.INT.getURI())) - intDatatypeProperties.add(dtp); + Iterator<OWLDataRange> it = ranges.iterator(); + if(it.hasNext()) { + OWLDataRange range = it.next(); + if(range.isDataType()) { + URI uri = ((OWLDataType)range).getURI(); + if(uri.equals(Datatype.BOOLEAN.getURI())) + booleanDatatypeProperties.add(dtp); + else if(uri.equals(Datatype.DOUBLE.getURI())) + doubleDatatypeProperties.add(dtp); + else if(uri.equals(Datatype.INT.getURI())) + intDatatypeProperties.add(dtp); + } } datatypeProperties.add(dtp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-31 10:10:22
|
Revision: 1031 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1031&view=rev Author: jenslehmann Date: 2008-07-31 10:10:18 +0000 (Thu, 31 Jul 2008) Log Message: ----------- fix for bug #2033067 Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-30 16:13:37 UTC (rev 1030) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-31 10:10:18 UTC (rev 1031) @@ -811,7 +811,11 @@ if(useCardinalityRestrictions) { for(ObjectProperty r : rs.getMostGeneralRoles()) { int maxFillers = maxNrOfFillers.get(r); - m4.add(new ObjectMaxCardinalityRestriction(maxFillers-1, r, new Thing())); + // zero fillers: <= -1 r.C does not make sense + // one filler: <= 0 r.C is equivalent to NOT EXISTS r.C, + // but we still keep it, because ALL r.NOT C may be difficult to reach + if(maxFillers > 0) + m4.add(new ObjectMaxCardinalityRestriction(maxFillers-1, r, new Thing())); } } m.put(4,m4); @@ -909,7 +913,11 @@ if(useCardinalityRestrictions) { for(ObjectProperty r : mgr.get(nc)) { int maxFillers = maxNrOfFillers.get(r); - m4.add(new ObjectMaxCardinalityRestriction(maxFillers-1, r, new Thing())); + // zero fillers: <= -1 r.C does not make sense + // one filler: <= 0 r.C is equivalent to NOT EXISTS r.C, + // but we still keep it, because ALL r.NOT C may be difficult to reach + if(maxFillers > 0) + m4.add(new ObjectMaxCardinalityRestriction(maxFillers-1, r, new Thing())); } } mA.get(nc).put(4,m4); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-30 16:13:43
|
Revision: 1030 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1030&view=rev Author: jenslehmann Date: 2008-07-30 16:13:37 +0000 (Wed, 30 Jul 2008) Log Message: ----------- partially implemented EL description trees Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-30 14:49:02 UTC (rev 1029) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-30 16:13:37 UTC (rev 1030) @@ -19,14 +19,23 @@ */ package org.dllearner.algorithms.el; +import java.util.LinkedList; import java.util.List; import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.owl.NamedClass; /** - * Represents an EL description tree. + * Represents an EL description tree, which corresponds to a + * description in the EL description logic. Note that an EL description tree + * can be a subtree of another EL description tree. In general, + * an EL description tree is a tree where the node label is a set + * of named classes and the edges are labelled with a property. * + * In the documentation below "this node" refers to the root node + * of this EL description (sub-)tree. + * * @author Jens Lehmann * */ @@ -36,15 +45,84 @@ private List<Edge> edges; + // parent node in the tree; + // null indicates that this node is a root node + private ELDescriptionTree parent = null; + /** - * @return the label + * Constructs an empty EL description tree with the empty set + * as root label and an empty set of outgoing edges. */ + public ELDescriptionTree() { + this(new TreeSet<NamedClass>(), new LinkedList<Edge>()); + } + + /** + * Constructs an EL description tree given its root label. + * @param label Label of the root node. + */ + public ELDescriptionTree(SortedSet<NamedClass> label) { + this(label, new LinkedList<Edge>()); + } + + /** + * Constructs an EL description tree given its root label and edges. + * @param label Label of the root node. + * @param edges Edges connected to the root node. + */ + public ELDescriptionTree(SortedSet<NamedClass> label, List<Edge> edges) { + this.label = label; + this.edges = edges; + } + + /** + * Checks whether this node has a parent. If the parent link + * is null, the node is considered to be a root node. + * @return True of this is the root node and false otherwise. + */ + public boolean isRoot() { + return parent == null; + } + + /** + * Traverses the EL description tree upwards until it finds + * the root and returns it. + * @return The root node of this EL description tree. + */ + public ELDescriptionTree getRoot() { + ELDescriptionTree root = this; + while(root.parent != null) { + root = parent; + } + return root; + } + + /** + * Traverses the tree until the root node and counts how + * many edges are traversed. If this node does not have a parent, + * zero is returned. + * @return The level of this node (or more specifically the root + * node of this subtree) within the overall EL description tree. + */ + public int getLevel() { + ELDescriptionTree root = this; + int level = 0; + while(root.parent != null) { + root = parent; + level++; + } + return level; + } + + /** + * @return The label of root node of this subtree. + */ public SortedSet<NamedClass> getLabel() { return label; } /** - * @return the edges + * @return The outgoing edges of this subtree. */ public List<Edge> getEdges() { return edges; Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-07-30 14:49:02 UTC (rev 1029) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-07-30 16:13:37 UTC (rev 1030) @@ -19,12 +19,44 @@ */ package org.dllearner.algorithms.el; +import org.dllearner.core.owl.ObjectProperty; + /** - * An edge in an EL description tree. + * A (directed) edge in an EL description tree. It consists of an edge + * label, which is an object property, and the EL description tree + * the edge points to. * * @author Jens Lehmann * */ public class Edge { + private ObjectProperty label; + + private ELDescriptionTree tree; + + /** + * Constructs and edge given a label and an EL description tree. + * @param label The label of this edge. + * @param tree The tree the edge points to (edges are directed). + */ + public Edge(ObjectProperty label, ELDescriptionTree tree) { + this.label = label; + this.tree = tree; + } + + /** + * @return The label of this edge. + */ + public ObjectProperty getLabel() { + return label; + } + + /** + * @return The EL description tree + */ + public ELDescriptionTree getTree() { + return tree; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-07-30 14:49:13
|
Revision: 1029 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1029&view=rev Author: jenslehmann Date: 2008-07-30 14:49:02 +0000 (Wed, 30 Jul 2008) Log Message: ----------- skeleton for EL learning algorithm Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/algorithms/el/ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java trunk/src/dl-learner/org/dllearner/algorithms/el/package.html trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java trunk/src/dl-learner/org/dllearner/refinementoperators/package.html Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java Added: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -0,0 +1,53 @@ +/** + * 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.algorithms.el; + +import java.util.List; +import java.util.SortedSet; + +import org.dllearner.core.owl.NamedClass; + +/** + * Represents an EL description tree. + * + * @author Jens Lehmann + * + */ +public class ELDescriptionTree { + + private SortedSet<NamedClass> label; + + private List<Edge> edges; + + /** + * @return the label + */ + public SortedSet<NamedClass> getLabel() { + return label; + } + + /** + * @return the edges + */ + public List<Edge> getEdges() { + return edges; + } + +} Added: trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/Edge.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -0,0 +1,30 @@ +/** + * 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.algorithms.el; + +/** + * An edge in an EL description tree. + * + * @author Jens Lehmann + * + */ +public class Edge { + +} Added: trunk/src/dl-learner/org/dllearner/algorithms/el/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/package.html 2008-07-30 14:49:02 UTC (rev 1029) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Learning algorithms for the EL description logic.</p> +</body> +</html> \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -32,7 +32,6 @@ import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -44,6 +43,7 @@ import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -1050,6 +1050,7 @@ return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore()); } + @Override public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { int count = 0; SortedSet<Node> rev = candidatesStable.descendingSet(); Deleted: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -1,14 +0,0 @@ -package org.dllearner.algorithms.refinement; - -import java.util.List; -import java.util.Set; - -import org.dllearner.core.owl.Description; - -public interface RefinementOperator { - - public Set<Description> refine(Description concept); - // SortedSet zu erzwingen ist nicht so elegant - public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements); - -} Deleted: trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/SearchSpace.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -1,21 +0,0 @@ -package org.dllearner.algorithms.refinement; - -import org.dllearner.core.owl.Description; - -/** - * Soll hauptsächlich dazu dienen zu testen, ob ein Konzept im - * Suchraum ist oder nicht. - * - * @author jl - * - */ - -public class SearchSpace { - - // determines whether a concept is in the search space - // noch nicht benutzt - public boolean isInSearchSpace(Description concept) { - return true; - } - -} Added: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -0,0 +1,66 @@ +/** + * 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.refinementoperators; + +import java.util.List; +import java.util.Set; + +import org.dllearner.core.owl.Description; + +/** + * EL downward refinement operator constructed by Jens Lehmann + * and Christoph Haase. It takes an EL description tree as input + * and outputs a set of EL description trees. + * + * <p>Properties: + * <ul> + * <li>complete</li> + * <li>proper</li> + * <li>finite</li> + * <li>uses class/property hierarchy</li> + * <li>takes domain/range into account</li> + * <li>uses disjoint classes/classes without common instances</li> + * </ul> + * + * @author Jens Lehmann + * + */ +public class ELDown implements RefinementOperator { + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) + */ + @Override + public Set<Description> refine(Description concept) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description, int, java.util.List) + */ + @Override + public Set<Description> refine(Description concept, int maxLength, + List<Description> knownRefinements) { + // TODO Auto-generated method stub + return null; + } + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiDown.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/PsiUp.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; -import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; Copied: trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java (from rev 1018, trunk/src/dl-learner/org/dllearner/algorithms/refinement/RefinementOperator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RefinementOperator.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -0,0 +1,14 @@ +package org.dllearner.refinementoperators; + +import java.util.List; +import java.util.Set; + +import org.dllearner.core.owl.Description; + +public interface RefinementOperator { + + public Set<Description> refine(Description concept); + // SortedSet zu erzwingen ist nicht so elegant + public Set<Description> refine(Description concept, int maxLength, List<Description> knownRefinements); + +} Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -33,7 +33,6 @@ import java.util.Map.Entry; import org.apache.log4j.Logger; -import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DataRange; Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -29,7 +29,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.DatatypeProperty; Added: trunk/src/dl-learner/org/dllearner/refinementoperators/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/package.html 2008-07-30 14:49:02 UTC (rev 1029) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>Refinement operator implementations.</p> +</body> +</html> \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java 2008-07-30 13:51:05 UTC (rev 1028) +++ trunk/src/dl-learner/org/dllearner/tools/ore/DescriptionLabel.java 2008-07-30 14:49:02 UTC (rev 1029) @@ -202,7 +202,7 @@ // MoveMenuItem move = new MoveMenuItem((NamedClass)desc, nc); // dme.add(move); // Set<NamedClass> complements = ore.getComplements(nc, ind); -// System.out.println("Gr\xF6\xDFe" + complements.size()); +// System.out.println("Gr��e" + complements.size()); // if(!(complements.size() <=1)){ // move.setEnabled(false); // StringBuffer strBuf = new StringBuffer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-30 13:51:09
|
Revision: 1028 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1028&view=rev Author: kurzum Date: 2008-07-30 13:51:05 +0000 (Wed, 30 Jul 2008) Log Message: ----------- checkstyle.xml working Added Paths: ----------- trunk/doc/checkstyle.xml Added: trunk/doc/checkstyle.xml =================================================================== --- trunk/doc/checkstyle.xml (rev 0) +++ trunk/doc/checkstyle.xml 2008-07-30 13:51:05 UTC (rev 1028) @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + This configuration file was written by the eclipse-cs plugin configuration editor +--> +<!-- + Checkstyle-Configuration: DL-Learner + Description: +Checkstyle configuration that checks the sun coding conventions. +--> +<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> +<module name="Checker"> + <property name="severity" value="warning"/> + <module name="TreeWalker"> + <module name="JavadocMethod"> + <property name="scope" value="package"/> + <property name="logLoadErrors" value="true"/> + <property name="suppressLoadErrors" value="true"/> + </module> + <module name="JavadocType"/> + <module name="JavadocVariable"> + <property name="scope" value="package"/> + </module> + <module name="JavadocStyle"/> + <module name="ConstantName"/> + <module name="LocalFinalVariableName"/> + <module name="LocalVariableName"/> + <module name="MemberName"/> + <module name="MethodName"/> + <module name="PackageName"/> + <module name="ParameterName"/> + <module name="StaticVariableName"/> + <module name="TypeName"/> + <module name="AvoidStarImport"> + <property name="severity" value="ignore"/> + </module> + <module name="IllegalImport"/> + <module name="RedundantImport"/> + <module name="UnusedImports"/> + <module name="FileLength"/> + <module name="LineLength"> + <property name="severity" value="ignore"/> + <property name="max" value="105"/> + </module> + <module name="MethodLength"/> + <module name="ParameterNumber"/> + <module name="EmptyForIteratorPad"/> + <module name="MethodParamPad"/> + <module name="OperatorWrap"/> + <module name="ParenPad"/> + <module name="TypecastParenPad"/> + <module name="WhitespaceAfter"/> + <module name="ModifierOrder"/> + <module name="RedundantModifier"/> + <module name="EmptyBlock"/> + <module name="LeftCurly"/> + <module name="NeedBraces"/> + <module name="RightCurly"/> + <module name="DoubleCheckedLocking"/> + <module name="EmptyStatement"/> + <module name="EqualsHashCode"/> + <module name="HiddenField"> + <property name="ignoreConstructorParameter" value="true"/> + <property name="ignoreSetter" value="true"/> + </module> + <module name="IllegalInstantiation"/> + <module name="InnerAssignment"/> + <module name="MissingSwitchDefault"/> + <module name="RedundantThrows"> + <property name="logLoadErrors" value="true"/> + <property name="suppressLoadErrors" value="true"/> + </module> + <module name="SimplifyBooleanExpression"/> + <module name="SimplifyBooleanReturn"/> + <module name="FinalClass"/> + <module name="HideUtilityClassConstructor"/> + <module name="InterfaceIsType"/> + <module name="VisibilityModifier"> + <property name="severity" value="ignore"/> + </module> + <module name="TodoComment"> + <property name="severity" value="ignore"/> + </module> + <module name="UpperEll"/> + <module name="Header"> + <property name="header" value="/** * 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/>. * */"/> + <property name="ignoreLines" value="20"/> + </module> + <module name="AbstractClassName"/> + </module> + <module name="PackageHtml"/> + <module name="NewlineAtEndOfFile"/> + <module name="Translation"/> +</module> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-30 13:34:58
|
Revision: 1027 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1027&view=rev Author: kurzum Date: 2008-07-30 13:34:56 +0000 (Wed, 30 Jul 2008) Log Message: ----------- more comments Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-30 09:24:46 UTC (rev 1026) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-07-30 13:34:56 UTC (rev 1027) @@ -412,6 +412,7 @@ return algorithm.getCurrentlyBestEvaluatedDescriptions(); } + /** {@inheritDoc} */ @Override public void stop() { algorithm.stop(); @@ -421,11 +422,13 @@ return algorithm.getStartNode(); } + /** {@inheritDoc} */ @Override public void pause() { // TODO: not implemented } + /** {@inheritDoc} */ @Override public void resume() { // TODO: not implemented @@ -434,6 +437,7 @@ /* (non-Javadoc) * @see org.dllearner.core.LearningAlgorithm#isRunning() */ + /** {@inheritDoc} */ @Override public boolean isRunning() { return algorithm.isRunning(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 09:24:46 UTC (rev 1026) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 13:34:56 UTC (rev 1027) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Sebastian Hellmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 09:24:46 UTC (rev 1026) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 13:34:56 UTC (rev 1027) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-07-30 09:24:51
|
Revision: 1026 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1026&view=rev Author: kurzum Date: 2008-07-30 09:24:46 +0000 (Wed, 30 Jul 2008) Log Message: ----------- more comments, code improvements Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -19,7 +19,6 @@ */ package org.dllearner.kb.sparql; -import java.util.LinkedList; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; @@ -27,19 +26,21 @@ import org.apache.log4j.Logger; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFactory; import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.query.ResultSetRewindable; import com.hp.hpl.jena.sparql.core.ResultBinding; - /** - * @author Sebastian Hellmann - * Convenience class for SPARQL queries - * initialized with a SparqlEndpoint. - * A Cache can also be used to further improve query time. - * Some methods allow basic reasoning + * @author Sebastian Hellmann Convenience class for SPARQL queries initialized + * with a SparqlEndpoint. A Cache can also be used to further improve + * query time. Some methods allow basic reasoning */ public class SPARQLTasks { + // TODO collect such things in a static class + private static final String SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + private static Logger logger = Logger.getLogger(SPARQLTasks.class); private final Cache cache; @@ -47,125 +48,114 @@ private final SparqlEndpoint sparqlEndpoint; /** - * @param cache a cache object - * @param sparqlEndpoint the Endpoint the sparql queries will be send to + * @param sparqlEndpoint + * the Endpoint the sparql queries will be send to */ - public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) { + public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) { super(); - this.cache = cache; + this.cache = null; this.sparqlEndpoint = sparqlEndpoint; } /** - * @param sparqlEndpoint the Endpoint the sparql queries will be send to + * @param cache + * a cache object + * @param sparqlEndpoint + * the Endpoint the sparql queries will be send to */ - public SPARQLTasks(final SparqlEndpoint sparqlEndpoint) { + public SPARQLTasks(final Cache cache, final SparqlEndpoint sparqlEndpoint) { super(); - this.cache = null; + this.cache = cache; this.sparqlEndpoint = sparqlEndpoint; } /** - * QUALITY: doesn't seem optimal, check! get all superclasses up to a - * certain depth 1 means direct superclasses depth + * get all superclasses up to a certain depth, 1 means direct superclasses + * only. * - * @param oneClass the class for which the superclasses will be retrieved - * @param maxdepth how far the RDF graph will be explored (1 means only direct SuperClasses) - * @return a Sorted String Set of all ClassNames, including the starting class + * @param classURI + * the uri of the class with no quotes for which the superclasses + * will be retrieved + * @param maxDepth + * how far the RDF graph will be explored (1 means only direct + * SuperClasses) + * @return a Sorted String Set of all ClassNames, including the starting + * class */ - public SortedSet<String> getSuperClasses(final String oneClass, - final int maxdepth) { - int depth = maxdepth; - SortedSet<String> superClasses = new TreeSet<String>(); - superClasses.add(oneClass); - SortedSet<String> ret = new TreeSet<String>(); - SortedSet<String> tmpset = new TreeSet<String>(); - String sparqlQuery = ""; - // ret.addAll(superClasses); - // logger.debug(superClasses); + public SortedSet<String> getSuperClasses(final String classURI, + final int maxDepth) { + // TODO check for quotes in uris + return getRecursiveSuperOrSubClasses(classURI, maxDepth, false); + } - for (; depth != 0; depth--) { - for (String oneSuperClass : superClasses) { + /** + * This is the underlying function to get Super and SubClasses. + * + * @param classURI + * the uri of the class with no quotes for which the classes will + * be retrieved + * @param maxDepth + * how far the RDF graph will be explored (1 means only direct + * related Classes) + * @return a Sorted String Set of all retrieved ClassNames, including the + * starting class + */ + private SortedSet<String> getRecursiveSuperOrSubClasses( + final String classURI, final int maxDepth, boolean subclasses) { + // TODO check for quotes in uris + int depth = maxDepth; - // tmp = oneSuperClass.replace("\"", ""); - sparqlQuery = "SELECT * WHERE { \n" - + "<" - + oneSuperClass - + "> " - + "<http://www.w3.org/2000/01/rdf-schema#subClassOf> ?superclass. \n" - + "}"; + final SortedSet<String> toBeRetrieved = new TreeSet<String>(); + toBeRetrieved.add(classURI); - tmpset.addAll(queryAsSet(sparqlQuery, "superclass")); + final SortedSet<String> returnSet = new TreeSet<String>(); + final SortedSet<String> tmpSet = new TreeSet<String>(); + // collect super/subclasses for the depth + for (; depth != 0; depth--) { + // collect super/subclasses for each class in toBeRetrieved + // accumulate in tmpSet + for (String oneClass : toBeRetrieved) { + if (subclasses) { + tmpSet.addAll(getDirectSubClasses(oneClass)); + } else { + tmpSet.addAll(getDirectSuperClasses(oneClass)); + } + }// end inner for - ret.addAll(tmpset); - // logger.debug(ret); - superClasses.clear(); - superClasses.addAll(tmpset); - tmpset.clear(); + + // remember all queried classes to return them. + returnSet.addAll(toBeRetrieved); + // then discard them + toBeRetrieved.clear(); + // all that are to be retrieved the next time. + toBeRetrieved.addAll(tmpSet); + // small optimization, remove all that have been processed already: + toBeRetrieved.removeAll(returnSet); + // reset + tmpSet.clear(); }// end outer for - // logger.debug(concept); - // logger.debug(query); - return ret; + + returnSet.addAll(toBeRetrieved); + + return returnSet; } /** * gets a SortedSet of all subclasses. - * QUALITY: maybe it is better to have a - * parameter int depth, to choose a depth of subclass interference * * @see conceptRewrite(String descriptionKBSyntax, SparqlEndpoint se, Cache * c, boolean simple ) - * @param description - * @param simple - * @return + * @param classURI + * @param maxDepth + * @return TreeSet of subclasses including classURI */ - public SortedSet<String> getSubClasses(final String description, - final boolean simple) { - // ResultSet rs = null; - // System.out.println(description); - SortedSet<String> alreadyQueried = new TreeSet<String>(); - try { - - // initialisation get direct Subclasses - LinkedList<String> remainingClasses = new LinkedList<String>(); - - // collect remaining classes - remainingClasses.addAll(getDirectSubClasses(description.replaceAll( - "\"", ""))); - - // remainingClasses.addAll(alreadyQueried); - - // alreadyQueried = new TreeSet<String>(); - alreadyQueried.add(description.replaceAll("\"", "")); - - if (simple) { - alreadyQueried.addAll(remainingClasses); - - } else { - - logger.warn("Retrieval auf all subclasses via SPARQL is cost intensive and might take a while"); - SortedSet<String> tmpSet = new TreeSet<String>(); - while (!remainingClasses.isEmpty()) { - - String tmp = remainingClasses.removeFirst(); - alreadyQueried.add(tmp); - - tmpSet = getDirectSubClasses(tmp); - for (String string : tmpSet) { - if (!(alreadyQueried.contains(string))) { - remainingClasses.add(string); - }// if - }// for - tmpSet.clear(); - }// while - }// else - - } catch (Exception e) { - logger.error(e.getStackTrace()); + public SortedSet<String> getSubClasses(final String classURI, + final int maxDepth) { + if (classURI.contains("\"")) { + // TODO exception } - - return alreadyQueried; + return getRecursiveSuperOrSubClasses(classURI, maxDepth, true); } /** @@ -173,101 +163,101 @@ * empty set on some endpoints. returns all direct subclasses of String * concept * - * @param concept An URI string with no quotes + * @param concept + * An URI string with no quotes * @return SortedSet of direct subclasses as String */ private SortedSet<String> getDirectSubClasses(String concept) { + return queryPatternAsSet("?subject", "<" + SUBCLASS_OF + ">", "<" + + concept + ">", "subject", 0, false); + } - String sparqlQueryString; - SortedSet<String> subClasses = new TreeSet<String>(); - ResultSet resultSet; - - sparqlQueryString = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <" - + concept + "> \n" + "}\n"; - - resultSet = queryAsResultSet(sparqlQueryString); - - @SuppressWarnings("unchecked") - List<ResultBinding> bindings = ResultSetFormatter.toList(resultSet); - String subject = ""; - String predicate = ""; - - for (ResultBinding resultBinding : bindings) { - - subject = ((resultBinding.get("subject").toString())); - predicate = ((resultBinding.get("predicate").toString())); - if (predicate - .equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#subClassOf")) { - subClasses.add(subject); - } - } - return subClasses; + private SortedSet<String> getDirectSuperClasses(String concept) { + return queryPatternAsSet("<" + concept + ">", "<" + SUBCLASS_OF + ">", + "?object", "object", 0, false); } /** - * Retrieves all resource for a fixed role and object. - * These instances are distinct. - * QUALITY: buggy because role doesn't work sometimes get subject with fixed - * role and object + * Retrieves all resource for a fixed role and object. These instances are + * distinct. QUALITY: buggy because role doesn't work sometimes get subject + * with fixed role and object * - * @param role An URI string with no quotes - * @param object An URI string with no quotes - * @param sparqlResultLimit Limits the ResultSet size + * @param role + * An URI string with no quotes + * @param object + * An URI string with no quotes + * @param sparqlResultLimit + * Limits the ResultSet size * @return SortedSet with the resulting subjects */ public SortedSet<String> retrieveDISTINCTSubjectsForRoleAndObject( String role, String object, int sparqlResultLimit) { - String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "?subject " - + "<" + role + "> " + "<" + object + "> \n" + "} " - + limit(sparqlResultLimit); - - return queryAsSet(sparqlQueryString, "subject"); + /* + * String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + + * "?subject " + "<" + role + "> " + "<" + object + "> \n" + "} " + + * limit(sparqlResultLimit); + * + * return queryAsSet(sparqlQueryString, "subject"); + */ + return queryPatternAsSet("?subject", "<" + role + ">", "<" + object + + ">", "subject", sparqlResultLimit, true); } /** - * @param subject An URI string with no quotes - * @param role An URI string with no quotes - * @param sparqlResultLimit Limits the ResultSet size - * @return + * @param subject + * An URI string with no quotes + * @param role + * An URI string with no quotes + * @param sparqlResultLimit + * Limits the ResultSet size + * @return SortedSet with the resulting objects */ public SortedSet<String> retrieveObjectsForSubjectAndRole(String subject, String role, int sparqlResultLimit) { - String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" + subject - + "> " + "<" + role + "> " + " ?object \n" + "} LIMIT " - + sparqlResultLimit; - - return queryAsSet(sparqlQueryString, "object"); + /* + * String sparqlQueryString = "SELECT DISTINCT * WHERE { \n " + "<" + + * subject + "> " + "<" + role + "> " + " ?object \n" + "} LIMIT " + + * sparqlResultLimit; + * + * return queryAsSet(sparqlQueryString, "object"); + */ + return queryPatternAsSet("<" + subject + ">", "<" + role + ">", + "?object", "object", sparqlResultLimit, true); } /** * all instances for a SKOS concept. * - * @param skosConcept An URI string with no quotes - * @param sparqlResultLimit Limits the ResultSet size - * @return + * @param skosConcept + * An URI string with no quotes + * @param sparqlResultLimit + * Limits the ResultSet size + * @return SortedSet with the instances */ public SortedSet<String> retrieveInstancesForSKOSConcept( String skosConcept, int sparqlResultLimit) { return queryPatternAsSet("?subject", "?predicate", "<" + skosConcept - + ">", "subject", sparqlResultLimit); + + ">", "subject", sparqlResultLimit, false); // return // retrieveDISTINCTSubjectsForRoleAndObject("http://www.w3.org/2004/02/skos/core#subject", } /** - * get all instances for a concept. + * get all instances for a complex concept / class description in KBSyntax. * - * @param conceptKBSyntax A description string in KBSyntax - * @param sparqlResultLimit Limits the ResultSet size - * @return + * @param conceptKBSyntax + * A description string in KBSyntax + * @param sparqlResultLimit + * Limits the ResultSet size + * @return SortedSet with the instance uris */ - public SortedSet<String> retrieveInstancesForConcept( + public SortedSet<String> retrieveInstancesForClassDescription( String conceptKBSyntax, int sparqlResultLimit) { String sparqlQueryString = ""; try { - sparqlQueryString = SparqlQueryDescriptionConvertVisitor.getSparqlQuery( - conceptKBSyntax, sparqlResultLimit); + sparqlQueryString = SparqlQueryDescriptionConvertVisitor + .getSparqlQuery(conceptKBSyntax, sparqlResultLimit); } catch (Exception e) { logger.warn(e.getMessage()); } @@ -275,20 +265,23 @@ } /** - * get all instances for a concept including RDFS Reasoning. + * same as <code>retrieveInstancesForClassDescription</code> including + * RDFS Reasoning. * - * @param conceptKBSyntax A description string in KBSyntax - * @param sparqlResultLimit Limits the ResultSet size - * @return + * @param conceptKBSyntax + * A description string in KBSyntax + * @param sparqlResultLimit + * Limits the ResultSet size + * @return SortedSet with the instance uris */ - public SortedSet<String> retrieveInstancesForConceptIncludingSubclasses( - String conceptKBSyntax, int sparqlResultLimit) { + public SortedSet<String> retrieveInstancesForClassDescriptionIncludingSubclasses( + String conceptKBSyntax, int sparqlResultLimit, int maxDepth) { String sparqlQueryString = ""; try { sparqlQueryString = SparqlQueryDescriptionConvertVisitor .getSparqlQueryIncludingSubclasses(conceptKBSyntax, - sparqlResultLimit, this, true); + sparqlResultLimit, this, maxDepth); } catch (Exception e) { logger.warn(e.getMessage()); @@ -299,67 +292,128 @@ /** * get all direct Classes of an instance. * - * @param instance An URI string with no quotes - * @param sparqlResultLimit Limits the ResultSet size + * @param instance + * An URI string with no quotes + * @param sparqlResultLimit + * Limits the ResultSet size * @return */ public SortedSet<String> getClassesForInstance(String instance, int sparqlResultLimit) { - String sparqlQueryString = "SELECT ?subject WHERE { \n " + "<" + instance - + ">" + " a " + "?subject " + "\n" + "} " + limit(sparqlResultLimit); - - return queryAsSet(sparqlQueryString, "subject"); + // String sparqlQueryString = "SELECT ?subject WHERE { \n " + "<" + + // instance + // + ">" + " a " + "?subject " + "\n" + "} " + limit(sparqlResultLimit); + return queryPatternAsSet("<" + instance + ">", "a", "?object", + "object", sparqlResultLimit, false); + // return queryAsSet(sparqlQueryString, "subject"); } - public SortedSet<String> getDomain(String role, int resultLimit) { + /** + * Returns all instances that are in the prefield (subject) of the + * property/role. + * + * Cave: These have to fulfill the following requirements: 1. They are not + * literals 2. They have at least a Class assigned 3. DISTINCT is used in + * the query + * + * TODO there might be a better name for the function + * + * @param role + * An URI of a property/role + * @param sparqlResultLimit + * ResultSet limit + * @return A String Set of instances + */ + public SortedSet<String> getDomainInstances(String role, + int sparqlResultLimit) { String sparqlQueryString = "SELECT DISTINCT ?domain " + "WHERE { \n" + "?domain <" + role + "> " + " ?o. \n" + "?domain a []\n." - + "FILTER (!isLiteral(?domain))." + "}\n" + limit(resultLimit); + + "FILTER (!isLiteral(?domain))." + "}\n" + + limit(sparqlResultLimit); return queryAsSet(sparqlQueryString, "domain"); } - public SortedSet<String> getRange(String role, int resultLimit) { + /** + * Returns all instances that are fillers of the property/role. Cave: These + * have to fulfill the following requirements: 1. The fillers are not + * literals 2. The fillers have at least a Class assigned 3. DISTINCT is + * used in the query + * + * TODO there might be a better name for the function + * + * @param role + * An URI of a property/role + * @param sparqlResultLimit + * ResultSet limit + * @return A String Set of instances + */ + public SortedSet<String> getRangeInstances(String role, + int sparqlResultLimit) { - String sparqlQueryString = "SELECT DISTINCT ?range " + "WHERE { \n" + "?s <" - + role + "> " + " ?range. \n" + "?range a [].\n" - + "FILTER (!isLiteral(?range))." + "}\n" + limit(resultLimit); + String sparqlQueryString = "SELECT DISTINCT ?range " + "WHERE { \n" + + "?s <" + role + "> " + " ?range. \n" + "?range a [].\n" + + "FILTER (!isLiteral(?range))." + "}\n" + + limit(sparqlResultLimit); return queryAsSet(sparqlQueryString, "range"); } /** - * //QUALITY rethink - * query a pattern with a standard SPARQL query. - * usage (?subject, <http://something>, - * <http://something> , subject ). + * query a pattern with a standard SPARQL query. The Query will be of the + * form SELECT * WHERE { subject predicate object } LIMIT X. It has a high + * degree of freedom, but only one variabla can be retrieved. * - * @param subject An URI string with no quotes - * @param predicate An URI string with no quotes - * @param object An URI string with no quotes - * @param var The single - * @return + * usage example 1 : queryPatternAsSet( "?subject", "<http://somerole>", + * "?object", "subject" ). retrieves all subjects, that have the role, + * somerole + * + * usage example 1 : queryPatternAsSet( "?subject", "<http://somerole>", + * "?object", "object" ). retrieves all objects, that have the role, + * somerole + * + * @param subject + * An URI string enclosed in <> or a SPARQL variable e.g. + * "?subject" + * @param predicate + * An URI string enclosed in <> or a SPARQL variable e.g. + * "?predicate" + * @param object + * An URI string enclosed in <> or a SPARQL variable e.g. + * "?object" + * @param variable + * The variable to be retrieved and put into the SortedSet + * @param sparqlResultLimit + * 0 means all + * @param distinct + * determines whether distinct is used + * @return a String Set with the Bindings of the variable in variable */ public SortedSet<String> queryPatternAsSet(String subject, - String predicate, String object, String var, int resultLimit) { - String sparqlQueryString = "SELECT ?subject WHERE { \n " + " " + subject - + " " + predicate + " " + object + " \n" + "} " - + limit(resultLimit); - return queryAsSet(sparqlQueryString, var); + String predicate, String object, String variable, + int sparqlResultLimit, boolean distinct) { + String sparqlQueryString = "SELECT " + ((distinct) ? "DISTINCT" : "") + + " * WHERE { \n " + " " + subject + " " + predicate + " " + + object + " \n" + "} " + limit(sparqlResultLimit); + return queryAsSet(sparqlQueryString, variable); } /** - * little higher level, executes query ,returns all resources for a variable. + * little higher level, executes query ,returns all resources for a + * variable. * - * @param sparqlQueryString The query - * @param var The single variable used in the query + * @param sparqlQueryString + * The query + * @param variable + * The single variable used in the query * @return */ - public SortedSet<String> queryAsSet(String sparqlQueryString, String var) { + public SortedSet<String> queryAsSet(String sparqlQueryString, + String variable) { ResultSet rs = null; try { String jsonString = query(sparqlQueryString); @@ -368,16 +422,18 @@ } catch (Exception e) { logger.warn(e.getMessage()); } - return getStringListForVariable(rs, var); + return getStringSetForVariableFromResultSet(ResultSetFactory + .makeRewindable(rs), variable); } /** * low level, executes query returns ResultSet. * - * @param sparqlQueryString The query + * @param sparqlQueryString + * The query * @return jena ResultSet */ - public ResultSet queryAsResultSet(String sparqlQueryString) { + public ResultSetRewindable queryAsResultSet(String sparqlQueryString) { return SparqlQuery.convertJSONtoResultSet(query(sparqlQueryString)); } @@ -385,7 +441,8 @@ /** * low level, executes query returns JSON. * - * @param sparqlQueryString The query + * @param sparqlQueryString + * The query * @return */ public String query(String sparqlQueryString) { @@ -395,30 +452,77 @@ sq.send(); jsonString = sq.getJson(); } else { - jsonString = cache.executeSparqlQuery(new SparqlQuery(sparqlQueryString, - sparqlEndpoint)); + jsonString = cache.executeSparqlQuery(new SparqlQuery( + sparqlQueryString, sparqlEndpoint)); } return jsonString; } - private String limit(int resultLimit) { - return (resultLimit > 0) ? (" LIMIT " + resultLimit) : ""; + /** + * a String Helper which constructs the limit clause of a sparql query. if + * sparqlResultLimit is zero, returns nothing + * + * @param sparqlResultLimit + * the resultsetlimit + * @return LIMIT sparqlResultLimit if bigger than zero, else returns ""; + */ + private String limit(int sparqlResultLimit) { + return (sparqlResultLimit > 0) ? (" LIMIT " + sparqlResultLimit) : ""; } - public static SortedSet<String> getStringListForVariable(ResultSet rs, - String var) { - SortedSet<String> result = new TreeSet<String>(); + public static SortedSet<String> getStringSetForVariableFromResultSet( + ResultSetRewindable rs, String variable) { + final SortedSet<String> result = new TreeSet<String>(); - // String s=ResultSetFormatter.asXMLString(this.rs); @SuppressWarnings("unchecked") - List<ResultBinding> l = ResultSetFormatter.toList(rs); + final List<ResultBinding> l = ResultSetFormatter.toList(rs); for (ResultBinding resultBinding : l) { - result.add(resultBinding.get(var).toString()); + result.add(resultBinding.get(variable).toString()); } - + rs.reset(); return result; } } + +/* + * here are some old functions, which were workarounds: + * + * + * QUALITY: workaround for a sparql glitch {?a owl:subclassOf ?b} returns an + * empty set on some endpoints. returns all direct subclasses of String concept + * + * @param concept An URI string with no quotes @return SortedSet of direct + * subclasses as String + * + * private SortedSet<String> getDirectSubClasses(String concept) { + * + * String sparqlQueryString; SortedSet<String> subClasses = new TreeSet<String>(); + * ResultSet resultSet; + * + * sparqlQueryString = "SELECT * \n " + "WHERE { \n" + " ?subject ?predicate <" + + * concept + "> \n" + "}\n"; + * + * resultSet = queryAsResultSet(sparqlQueryString); + * + * @SuppressWarnings("unchecked") List<ResultBinding> bindings = + * ResultSetFormatter.toList(resultSet); String subject = ""; String predicate = + * ""; + * + * for (ResultBinding resultBinding : bindings) { + * + * subject = ((resultBinding.get("subject").toString())); predicate = + * ((resultBinding.get("predicate").toString())); if (predicate + * .equalsIgnoreCase("http://www.w3.org/2000/01/rdf-schema#subClassOf")) { + * subClasses.add(subject); } } return subClasses; } + * + * + * + * + * + * + * + */ + Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -31,6 +31,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFactory; import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.query.ResultSetRewindable; import com.hp.hpl.jena.sparql.engine.http.HttpQuery; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; @@ -111,7 +112,7 @@ // writeToSparqlLog("query: "+queryString+ " | ENDPOINT: // "+endpoint.getURL().toString()); - json = SparqlQuery.convertResultSetToJSON(rs); + json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs)); writeToSparqlLog("JSON: " + json); @@ -238,30 +239,39 @@ /** * Converts Jena result set to XML. - * @param resultSet a Jena ResultSet + * To make a ResultSet rewindable use: + * ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet); + * @param resultSet The result set to transform, must be rewindable to prevent errors. * @return String xml */ - public static String convertResultSetToXMLString(ResultSet resultSet) { + public static String convertResultSetToXMLString(ResultSetRewindable resultSet) { // if (rs == null) // this.send(); - return ResultSetFormatter.asXMLString(resultSet); + String retVal = ResultSetFormatter.asXMLString(resultSet); + resultSet.reset(); + return retVal; } /** * Converts Jena result set to JSON. + * To make a ResultSet rewindable use: + * ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet); * * @param resultSet - * The result set to transform. + * The result set to transform, must be rewindable to prevent errors. * @return JSON representation of the result set. */ - public static String convertResultSetToJSON(ResultSet resultSet) { + public static String convertResultSetToJSON(ResultSetRewindable resultSet) { // if (rs == null) // this.send(); + //ResultSetRewindable rsRewind = ResultSetFactory.makeRewindable(resultSet); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ResultSetFormatter.outputAsJSON(baos, resultSet); // possible Jena bug: Jena modifies the result set during // JSON transformation, so we need to get it back - resultSet = convertJSONtoResultSet(baos.toString()); + //rsRewind. + //resultSet = convertJSONtoResultSet(baos.toString()); + resultSet.reset(); try { return baos.toString("UTF-8"); } catch (UnsupportedEncodingException e) { @@ -277,11 +287,11 @@ * A JSON representation if a SPARQL query result. * @return A Jena ResultSet. */ - public static ResultSet convertJSONtoResultSet(String json) { + public static ResultSetRewindable convertJSONtoResultSet(String json) { ByteArrayInputStream bais = new ByteArrayInputStream(json .getBytes(Charset.forName("UTF-8"))); // System.out.println("JSON " + json); - return ResultSetFactory.fromJSON(bais); + return ResultSetFactory.makeRewindable(ResultSetFactory.fromJSON(bais)); } /** Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertRDFS.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -38,7 +38,7 @@ public class SparqlQueryDescriptionConvertRDFS { //LOGGER: SparqlQueryDescriptionConvertVisitor - static Logger logger = Logger.getLogger(SparqlQueryDescriptionConvertVisitor.class); + static Logger logger = Logger.getLogger(SparqlQueryDescriptionConvertRDFS.class); /** * @@ -51,13 +51,13 @@ * @param c * a cache object, makes only sense if you use this function * often - * @param simple - * if true then only direct subclasses will be used (TRUE HIGHLY - * RECOMMENDED for large hierarchies) + * @param maxDepth + * determines the depth of retrieval, if 1 classes are replaced by direct subclasses only, + * 1 is HIGHLY RECOMMENDED FOR LARGE HIERARCHIES) * @return the altered String */ public static String conceptRewrite(String descriptionKBSyntax, SPARQLTasks st, - boolean simple) { + int maxDepth) { String quote = "\""; String returnValue = ""; String currentconcept = ""; @@ -79,7 +79,7 @@ // System.out.println(currentconcept); // subclasses are retrieved - subclasses = st.getSubClasses(currentconcept, simple); + subclasses = st.getSubClasses(currentconcept, maxDepth); // if only one then keep if (subclasses.size() == 1) Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryDescriptionConvertVisitor.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -157,13 +157,13 @@ * @param limit @see getSparqlQuery(Description description, int limit) * @param se * @param c - * @param simple + * @param maxDepth * @return * @throws ParseException */ - public static String getSparqlQueryIncludingSubclasses(String descriptionKBSyntax, int resultLimit, SPARQLTasks st, boolean simple) throws ParseException + public static String getSparqlQueryIncludingSubclasses(String descriptionKBSyntax, int resultLimit, SPARQLTasks st, int maxDepth) throws ParseException { - String rewritten = SparqlQueryDescriptionConvertRDFS.conceptRewrite(descriptionKBSyntax, st, simple); + String rewritten = SparqlQueryDescriptionConvertRDFS.conceptRewrite(descriptionKBSyntax, st, maxDepth); return getSparqlQuery(rewritten, resultLimit); Modified: trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/scripts/SKOS7030.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -112,7 +112,7 @@ // System.out.println(time()); // System.out.println(System.currentTimeMillis()); - + // parameters if (local) { @@ -125,6 +125,15 @@ SparqlEndpoint.getEndpointDBpedia()); } + + String st= "http://dbpedia.org/class/yago/Person100007846"; + st = "http://dbpedia.org/class/yago/Leader109623038"; + System.out.println(sparqlTasks.getSuperClasses(st, 2)); + System.out.println(sparqlTasks.getSuperClasses(st, 1)); + System.out.println(sparqlTasks.getSubClasses(st, 0)); + + System.exit(0); + //System.out.println(sparqlTasks.getDomain( // "http://dbpedia.org/property/predecessor", 1000)); @@ -183,8 +192,8 @@ // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(), // sparqlResultLimit); SortedSet<String> instances = sparqlTasks - .retrieveInstancesForConceptIncludingSubclasses(concept - .toKBSyntaxString(), sparqlResultLimit); + .retrieveInstancesForClassDescriptionIncludingSubclasses(concept + .toKBSyntaxString(), sparqlResultLimit,1); SortedSet<String> coveredInRest = new TreeSet<String>( fullPosSetWithoutPosExamples); @@ -210,8 +219,8 @@ // sparqlTasks.retrieveInstancesForConcept(oneConcept.toKBSyntaxString(), // sparqlResultLimit); SortedSet<String> instances = sparqlTasks - .retrieveInstancesForConceptIncludingSubclasses(concept - .toKBSyntaxString(), sparqlResultLimit); + .retrieveInstancesForClassDescriptionIncludingSubclasses(concept + .toKBSyntaxString(), sparqlResultLimit, 1 ); SortedSet<String> coveredInRest = new TreeSet<String>( fullPosSetWithoutPosExamples); Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -155,7 +155,7 @@ logger.debug(oneClass); // rsc = new // JenaResultSetConvenience(queryConcept("\""+oneClass+"\"",limit)); - this.fromParallelClasses.addAll(sparqltasks.retrieveInstancesForConcept("\"" + oneClass + this.fromParallelClasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + oneClass + "\"", resultLimit)); } @@ -180,7 +180,7 @@ for (String oneSuperClass : superClasses) { logger.debug(oneSuperClass); - this.fromSuperclasses.addAll(sparqltasks.retrieveInstancesForConcept("\"" + this.fromSuperclasses.addAll(sparqltasks.retrieveInstancesForClassDescription("\"" + oneSuperClass + "\"", resultLimit)); } @@ -191,7 +191,7 @@ @SuppressWarnings("unused") private void makeNegativeExamplesFromDomain(String role, int resultLimit){ logger.debug("making Negative Examples from Domain of : "+role); - this.fromDomain.addAll(sparqltasks.getDomain(role, resultLimit)); + this.fromDomain.addAll(sparqltasks.getDomainInstances(role, resultLimit)); this.fromDomain.removeAll(this.fullPositiveSet); logger.debug("|-neg Example size from Domain: "+this.fromDomain.size()); } @@ -199,7 +199,7 @@ @SuppressWarnings("unused") private void makeNegativeExamplesFromRange(String role, int resultLimit){ logger.debug("making Negative Examples from Range of : "+role); - this.fromRange.addAll(sparqltasks.getRange(role, resultLimit)); + this.fromRange.addAll(sparqltasks.getRangeInstances(role, resultLimit)); this.fromRange.removeAll(this.fullPositiveSet); logger.debug("|-neg Example size from Range: "+this.fromRange.size()); } Modified: trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java 2008-07-30 06:53:34 UTC (rev 1025) +++ trunk/src/dl-learner/org/dllearner/utilities/examples/AutomaticPositiveExampleFinderSPARQL.java 2008-07-30 09:24:46 UTC (rev 1026) @@ -28,7 +28,7 @@ //QUALITY resultsize is not accounted for public void makePositiveExamplesFromConcept(String conceptKBSyntax){ logger.debug("making Positive Examples from Concept: "+conceptKBSyntax); - this.posExamples = sparqltasks.retrieveInstancesForConcept(conceptKBSyntax, 0); + this.posExamples = sparqltasks.retrieveInstancesForClassDescription(conceptKBSyntax, 0); logger.debug(" pos Example size: "+posExamples.size()); } @@ -50,14 +50,14 @@ @SuppressWarnings("unused") public void makePositiveExamplesFromDomain(String role, int resultLimit){ logger.debug("making Positive Examples from Domain of : "+role); - this.posExamples.addAll(sparqltasks.getDomain(role, resultLimit)); + this.posExamples.addAll(sparqltasks.getDomainInstances(role, resultLimit)); logger.debug("pos Example size: "+posExamples.size()); } @SuppressWarnings("unused") public void makePositiveExamplesFromRange(String role, int resultLimit){ logger.debug("making Positive Examples from Range of : "+role); - this.posExamples.addAll(sparqltasks.getRange(role, resultLimit)); + this.posExamples.addAll(sparqltasks.getRangeInstances(role, resultLimit)); logger.debug("pos Example size: "+posExamples.size()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |