From: <ku...@us...> - 2008-04-22 15:19:20
|
Revision: 809 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=809&view=rev Author: kurzum Date: 2008-04-22 08:19:07 -0700 (Tue, 22 Apr 2008) Log Message: ----------- finished sparql script, some fine tuning needed Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-22 13:31:50 UTC (rev 808) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-04-22 15:19:07 UTC (rev 809) @@ -103,8 +103,11 @@ //extended Options private long maxExecutionTimeInSeconds; + private boolean maxExecutionTimeShown=false; private long minExecutionTimeInSeconds; + private boolean minExecutionTimeShown=false; private int guaranteeXgoodDescriptions; + private boolean guaranteeXgoodShown=false; // if set to false we do not test properness; this may seem wrong // but the disadvantage of properness testing are additional reasoner @@ -185,6 +188,7 @@ private int conceptTestsReasoner = 0; // time variables + private long runtime; private long algorithmStartTime; private long propernessCalcTimeNs = 0; private long propernessCalcReasoningTimeNs = 0; @@ -257,7 +261,7 @@ } public void start() { - + runtime=System.currentTimeMillis(); // TODO: write a JUnit test for this problem (long-lasting or infinite loops because // redundant children of a node are called recursively after when the node is extended // twice) @@ -387,26 +391,37 @@ Files.appendFile(searchTreeFile, treeString); } + + if(maxExecutionTimeReached()) { stop=true;} + solutionFound = (guaranteeXgoodDescriptions() ); + solutionFound = (minExecutionTimeReached()&& solutionFound); + //logger.info(minExecutionTimeReached()+"aaaaaaa "+solutions.size()+"::"+guaranteeXgoodDescriptions); + //logger.info(solutionFound+"aaaaaaa "+stop); + + // Anzahl Schleifendurchläufe loop++; - } - if(maxExecutionTimeReached()) { stop=true;} - boolean minSolutionrequirement = (solutions.size()>guaranteeXgoodDescriptions); + }//end while + - if(solutionFound && minExecutionTimeReached() && minSolutionrequirement) { + + if(solutionFound ) { logger.info("best node " + candidatesStable.last().getShortDescription(nrOfPositiveExamples, nrOfNegativeExamples, baseURI)); - logger.info("\nsolutions:"); + logger.info("\nsolutions ( top 5 ):"); + int show=1; for(Description c : solutions) { - logger.info(" " + c.toString(baseURI,null) + " (length " + c.getLength() +", depth " + c.getDepth() + ")"); + logger.info(show+": " + c.toString(baseURI,null) + " (length " + c.getLength() +", depth " + c.getDepth() + ")"); //TODO remove this line maybe // watch for String.replace Quick hack - logger.info(" MANCHESTER: " + + logger.info(" MANCHESTER: " + c.toManchesterSyntaxString(baseURI, new HashMap<String,String>()). replace("\"", "")); - logger.info(" KBSyntax: " + c.toKBSyntaxString()); + logger.info(" KBSyntax: " + c.toKBSyntaxString()); + if(show>=5){break;} + show++; } } logger.debug("size of candidate set: " + candidates.size()); @@ -1029,13 +1044,31 @@ return startNode; } + private boolean guaranteeXgoodDescriptions(){ + if(guaranteeXgoodShown)return true; + if(solutions.size()>guaranteeXgoodDescriptions){ + logger.info("Minimum number of good descriptions reached, stopping now..."); + guaranteeXgoodShown=true; + return true;} + else return false; + + } + + private boolean maxExecutionTimeReached(){ if(maxExecutionTimeInSeconds==0)return false; - long needed = System.nanoTime()- this.algorithmStartTime; + if(maxExecutionTimeShown)return true; + long needed = System.currentTimeMillis()- this.runtime; //millisec /100 //seconds /1000 - long maxNanoSeconds = maxExecutionTimeInSeconds *100*1000 ; - if(maxNanoSeconds<needed)return true; + long maxMilliSeconds = maxExecutionTimeInSeconds *1000 ; + //System.out.println("max"+maxMilliSeconds); + //System.out.println(needed); + + if(maxMilliSeconds<needed){ + logger.info("Maximum time reached, stopping now..."); + maxExecutionTimeShown=true; + return true;} else return false; } @@ -1045,12 +1078,19 @@ * @return true */ private boolean minExecutionTimeReached(){ + if(minExecutionTimeShown)return true; //if(minExecutionTimeInSeconds==0)return true; - long needed = System.nanoTime()- this.algorithmStartTime; + long needed = System.currentTimeMillis()- this.runtime; //millisec /100 //seconds /1000 - long minNanoSeconds = minExecutionTimeInSeconds *100*1000 ; - if(minNanoSeconds<needed)return true; + long minMilliSeconds = minExecutionTimeInSeconds *1000 ; + //System.out.println("min"+minMilliSeconds); + //System.out.println(needed); + + if(minMilliSeconds<needed){ + logger.info("Minimum time reached, stopping when next solution is found"); + minExecutionTimeShown=true; + return true;} else return false; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2008-04-22 13:31:50 UTC (rev 808) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2008-04-22 15:19:07 UTC (rev 809) @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.Vector; +import org.apache.log4j.Logger; import org.dllearner.kb.sparql.configuration.Configuration; import org.dllearner.kb.sparql.datastructure.ClassNode; import org.dllearner.kb.sparql.datastructure.InstanceNode; @@ -40,7 +41,8 @@ private int recursionDepth = 1; // private boolean getAllSuperClasses = true; // private boolean closeAfterRecursion = true; - private boolean print_flag = false; + private static Logger logger = Logger + .getLogger(ExtractionAlgorithm.class); public ExtractionAlgorithm(Configuration Configuration) { this.configuration = Configuration; @@ -79,7 +81,7 @@ System.out.println(n); Vector<Node> v = new Vector<Node>(); v.add(n); - p("StartVector: " + v); + logger.info("StartVector: " + v); // n.expand(tsp, this.Manipulator); // Vector<Node> second= for (int x = 1; x <= recursionDepth; x++) { @@ -87,7 +89,7 @@ Vector<Node> tmp = new Vector<Node>(); while (v.size() > 0) { Node tmpNode = v.remove(0); - p("Expanding " + tmpNode); + logger.info("Expanding " + tmpNode); // System.out.println(this.Manipulator); // these are the new not expanded nodes // the others are saved in connection with the original node @@ -97,14 +99,14 @@ tmp.addAll(tmpVec); } v = tmp; - System.out.println("Recursion counter: " + x + " with " + v.size() + logger.info("Recursion counter: " + x + " with " + v.size() + " Nodes remaining, needed: " + (System.currentTimeMillis() - time) + "ms"); time = System.currentTimeMillis(); } HashSet<String> hadAlready = new HashSet<String>(); - p("Get all superclasses"); + logger.info("Get all superclasses"); //p(configuration.toString()); // gets All Class Nodes and expands them further if (this.configuration.isGetAllSuperClasses()) { @@ -126,10 +128,10 @@ configuration); if (this.configuration.isCloseAfterRecursion()) { while (instances.size() > 0) { - p("Getting classes for remaining instances: " + logger.info("Getting classes for remaining instances: " + instances.size()); Node next = instances.remove(0); - p("Getting classes for: " + next); + logger.info("Getting classes for: " + next); classes.addAll(next.expand(tsqc, manipulator)); if (classes.size() >= manipulator.breakSuperClassRetrievalAfter) { break; @@ -139,14 +141,14 @@ Vector<Node> tmp = new Vector<Node>(); int i = 0; while (classes.size() > 0) { - p("Remaining classes: " + classes.size()); + logger.info("Remaining classes: " + classes.size()); // Iterator<Node> it=classes.iterator(); // Node next =(Node) it.next(); // classes.remove(next); Node next = classes.remove(0); if (!hadAlready.contains(next.getURI().toString())) { - p("Expanding: " + next); + logger.info("Expanding: " + next); // System.out.println(hadAlready.size()); hadAlready.add(next.getURI().toString()); tmp = next.expand(typedSparqlQuery, manipulator); @@ -172,9 +174,6 @@ } - void p(String s) { - if (print_flag) - System.out.println(s); - } + } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-04-22 13:31:50 UTC (rev 808) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-04-22 15:19:07 UTC (rev 809) @@ -67,10 +67,10 @@ public ResultSet send() { isRunning = true; ResultSet rs=null; - logger.info(queryString); + logger.trace(queryString); String service = endpoint.getURL().toString(); - logger.info(endpoint.getURL().toString()); + logger.trace(endpoint.getURL().toString()); // Jena access to SPARQL endpoint queryExecution = new QueryEngineHTTP(service, queryString); for (String dgu : endpoint.getDefaultGraphURIs()) { @@ -81,14 +81,14 @@ } logger.info("query SPARQL server"); try{ - //TODO after overnext Jena release + //TODO remove after overnext Jena release HttpQuery.urlLimit = 3*1024 ; rs = queryExecution.execSelect(); json=SparqlQuery.getAsJSON(rs); - logger.info(rs.getResultVars().toString()); + logger.trace(rs.getResultVars().toString()); } catch (Exception e){ sendException=new SparqlQueryException(e.getMessage()); - logger.info("Exception when querying Sparql Endpoint"); + logger.error("Exception when querying Sparql Endpoint"); } isRunning = false; return rs; Modified: trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java 2008-04-22 13:31:50 UTC (rev 808) +++ trunk/src/dl-learner/org/dllearner/test/SPARQLPreparation.java 2008-04-22 15:19:07 UTC (rev 809) @@ -4,6 +4,12 @@ import java.util.SortedSet; import java.util.TreeSet; +import javax.sound.midi.SysexMessage; + +import org.apache.log4j.ConsoleAppender; +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.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; @@ -19,7 +25,7 @@ static Cache c; static SparqlEndpoint se; - + private static Logger logger = Logger.getRootLogger(); /** * @param args */ @@ -27,6 +33,8 @@ init(); try { + + SimpleClock sc=new SimpleClock(); SortedSet<String> concepts = new TreeSet<String>(); //concepts.add("\"http://dbpedia.org/class/yago/Person100007846\""); @@ -52,13 +60,13 @@ negExamples.remove(string2); }; }*/ - System.out.println(negExamples.size()); + //System.out.println(negExamples.size()); negExamples.removeAll(posExamples); posExamples=shrink(posExamples,5); negExamples=shrink(negExamples,posExamples.size()); //System.out.println(posExamples.first())); - System.out.println(posExamples.size()); - System.out.println(negExamples.size()); + //System.out.println(posExamples.size()); + //System.out.println(negExamples.size()); // new ConfWriter().writeSPARQL("aaa.conf", posExamples, negExamples, url, new TreeSet<String>()); @@ -137,6 +145,14 @@ SparqlQueryDescriptionConvertVisitor.debug_flag = false; c = new Cache("cache"); se = SparqlEndpoint.dbpediaEndpoint(); + // create logger (a simple logger which outputs + // its messages to the console) + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.DEBUG); + } Modified: trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java 2008-04-22 13:31:50 UTC (rev 808) +++ trunk/src/dl-learner/org/dllearner/utilities/LearnSparql.java 2008-04-22 15:19:07 UTC (rev 809) @@ -24,6 +24,7 @@ public void learn(SortedSet<String> posExamples,SortedSet<String> negExamples, String uri, SortedSet<String> ignoredConcepts){ + ComponentManager cm = ComponentManager.getInstance(); LearningAlgorithm la = null; ReasoningService rs = null; @@ -68,8 +69,8 @@ cm.applyConfigEntry(la,"useExistsConstructor",true); cm.applyConfigEntry(la,"useCardinalityRestrictions",false); cm.applyConfigEntry(la,"useNegation",false); - cm.applyConfigEntry(la,"minExecutionTimeInSeconds",10); - cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",10); + cm.applyConfigEntry(la,"minExecutionTimeInSeconds",0); + cm.applyConfigEntry(la,"guaranteeXgoodDescriptions",20); //cm.applyConfigEntry(la,"quiet",false); if(ignoredConcepts.size()>0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |