From: <jen...@us...> - 2008-06-30 14:12:52
|
Revision: 994 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=994&view=rev Author: jenslehmann Date: 2008-06-30 07:12:50 -0700 (Mon, 30 Jun 2008) Log Message: ----------- added converter of evaluated descriptions to a JSON format to simplify exchanging solutions Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/php-examples/LearningSimple.php Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-06-30 14:12:50 UTC (rev 994) @@ -1071,9 +1071,9 @@ @Override public Score getSolutionScore() { if(posOnly) - return posOnlyLearningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); + return posOnlyLearningProblem.computeScore(getCurrentlyBestDescription()); else - return learningProblem.computeScore(getCurrentlyBestEvaluatedDescription().getDescription()); + return learningProblem.computeScore(getCurrentlyBestDescription()); } Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-06-30 14:12:50 UTC (rev 994) @@ -25,6 +25,9 @@ import org.dllearner.core.owl.Individual; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.ScoreTwoValued; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; /** * This represents a class description, which has been @@ -138,4 +141,35 @@ public String getSparqlQuery(int limit) { return SparqlQueryDescriptionConvertVisitor.getSparqlQuery(description, limit); } + + /** + * This convenience method can be used to store and exchange evaluated + * descriptions by transforming them to a JSON string. + * @return A JSON representation of an evaluated description. + */ + public String asJSON() { + JSONObject object = new JSONObject(); + try { + object.put("descriptionManchesterSyntax", description.toManchesterSyntaxString(null, null)); + object.put("accuracy", score.getAccuracy()); + object.put("coveredPositives", getJSONArray(score.getCoveredPositives())); + object.put("coveredNegatives", getJSONArray(score.getCoveredNegatives())); + object.put("notCoveredPositives", getJSONArray(score.getNotCoveredPositives())); + object.put("notCoveredNegatives", getJSONArray(score.getNotCoveredNegatives())); + return object.toString(3); + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + } + + // we need to use this method instead of the standard JSON array constructor, + // otherwise we'll get unexpected results (JSONArray does not take Individuals + // as arguments and does not use toString) + private static JSONArray getJSONArray(Set<Individual> individuals) { + JSONArray j = new JSONArray(); + for(Individual i : individuals) + j.put(i.getName()); + return j; + } } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-06-30 14:12:50 UTC (rev 994) @@ -45,6 +45,7 @@ import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; 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; @@ -317,6 +318,20 @@ return solution.toString(); } + @WebMethod + public String learnDescriptionsEvaluated(int id, int limit) throws ClientNotKnownException { + ClientState state = getState(id); + state.getLearningAlgorithm().start(); + List<EvaluatedDescription> descriptions = state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(limit); + String json = "{"; + int count = 1; + for(EvaluatedDescription description : descriptions) { + json += "\"solution" + count + "\" : " + description.asJSON(); + count++; + } + return json; + } + /** * Starts the learning algorithm and returns immediately. The learning * algorithm is executed in its own thread and can be queried and Modified: trunk/src/php-examples/LearningSimple.php =================================================================== --- trunk/src/php-examples/LearningSimple.php 2008-06-30 11:26:39 UTC (rev 993) +++ trunk/src/php-examples/LearningSimple.php 2008-06-30 14:12:50 UTC (rev 994) @@ -62,8 +62,11 @@ // learn concept echo 'start learning ... '; -$concept = $client->learn($id, "manchester"); +// get only concept +// $concept = $client->learn($id, "manchester"); +// get concept and additional information in JSON syntax +$concept = $client->learnDescriptionsEvaluated($id, 5); echo 'OK <br />'; -echo 'solution: ' . $concept; +echo 'solution: <pre>' . $concept . '</pre>'; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |