From: <jen...@us...> - 2009-08-13 14:08:35
|
Revision: 1822 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1822&view=rev Author: jenslehmann Date: 2009-08-13 14:08:23 +0000 (Thu, 13 Aug 2009) Log Message: ----------- - added PHP example for class learning - implemented JSON return format for class learning - added new learning method to web service Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/php-examples/LearningSimple.php trunk/src/php-examples/main.wsdl Added Paths: ----------- trunk/src/php-examples/LearningClass.php Modified: trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java 2009-08-07 08:54:57 UTC (rev 1821) +++ trunk/src/dl-learner/org/dllearner/learningproblems/EvaluatedDescriptionClass.java 2009-08-13 14:08:23 UTC (rev 1822) @@ -24,6 +24,11 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIRenderers; +import org.json.JSONException; +import org.json.JSONObject; +import org.semanticweb.owl.model.OWLDescription; /** * An evaluated description for learning classes in ontologies. @@ -95,4 +100,28 @@ return classScore.followsFromKB(); } + /** + * 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)); + OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description); + object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d)); + object.put("descriptionKBSyntax", description.toKBSyntaxString()); + object.put("scoreValue", score.getAccuracy()); + object.put("additionalInstances", getAdditionalInstances()); + object.put("coveredInstances", getCoveredInstances()); + object.put("isConsistent", isConsistent()); + object.put("coverage", getCoverage()); + object.put("addition", getAddition()); + return object.toString(3); + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + } } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2009-08-07 08:54:57 UTC (rev 1821) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2009-08-13 14:08:23 UTC (rev 1822) @@ -356,12 +356,37 @@ * of the learned description. * * @param id The session ID. + * @return A JSON string encoding learned descriptions. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ + @WebMethod + public String learnDescriptionsEvaluated(int id) throws ClientNotKnownException { + ClientState state = getState(id); + state.getLearningAlgorithm().start(); + TreeSet<? extends EvaluatedDescription> descriptions = state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(); + String json = "{"; + int count = 1; + for(EvaluatedDescription description : descriptions) { + if (count>1) json += ",\"solution" + count + "\" : " + description.asJSON(); + else json += "\"solution" + count + "\" : " + description.asJSON(); + count++; + } + json+="}"; + return json; + } + + /** + * Returns a list of JSON encoded description including extra information + * (which partially depends on the learning problem) such as the accuracy + * of the learned description. + * + * @param id The session ID. * @param limit Maximum number of results desired. * @return A JSON string encoding learned descriptions. * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod - public String learnDescriptionsEvaluated(int id, int limit) throws ClientNotKnownException { + public String learnDescriptionsEvaluatedLimit(int id, int limit) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); List<? extends EvaluatedDescription> descriptions = state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(limit); Added: trunk/src/php-examples/LearningClass.php =================================================================== --- trunk/src/php-examples/LearningClass.php (rev 0) +++ trunk/src/php-examples/LearningClass.php 2009-08-13 14:08:23 UTC (rev 1822) @@ -0,0 +1,66 @@ +<?php +/** + * Copyright (C) 2007-2009, 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/>. + * + */ + + /** + * Small example showing how to use DL-Learner for learning class definitions. + * + * @author Jens Lehmann + */ + +include('Utilities.php'); + +// load WSDL files (has to be done due to a Java web service bug) +ini_set("soap.wsdl_cache_enabled","0"); +$wsdluri="http://localhost:8181/services?wsdl"; +// Utilities::loadWSDLfiles($wsdluri); + +// specifiy ontology +$ontology = 'file:'.realpath("../../examples/swore/swore.rdf"); + +// create DL-Learner client +$client = new SoapClient("main.wsdl"); +// $client = new SoapClient($wsdluri); + +$id = $client->generateID(); +$ksID = $client->addKnowledgeSource($id, "owlfile", $ontology); +$rID = $client->setReasoner($id, "fastInstanceChecker"); + +// create a learning problem +$lp = $client->setLearningProblem($id, "classLearning"); +$client->applyConfigEntryURL($id, $lp, "classToDescribe", "http://ns.softwiki.de/req/CustomerRequirement"); + +$la_id = $client->setLearningAlgorithm($id, "celoe"); + +$client->initAll($id); + +// learn concept +echo 'start learning ... '; +// get only concept +// $concept = $client->learn($id, "manchester"); +// get concept and additional information in JSON syntax +$concept = $client->learnDescriptionsEvaluated($id); +echo 'OK <br />'; + +echo 'solution: <pre>'; +var_dump(json_decode($concept, true)); +echo '</pre>'; + +?> Modified: trunk/src/php-examples/LearningSimple.php =================================================================== --- trunk/src/php-examples/LearningSimple.php 2009-08-07 08:54:57 UTC (rev 1821) +++ trunk/src/php-examples/LearningSimple.php 2009-08-13 14:08:23 UTC (rev 1822) @@ -30,7 +30,7 @@ // load WSDL files (has to be done due to a Java web service bug) ini_set("soap.wsdl_cache_enabled","0"); $wsdluri="http://localhost:8181/services?wsdl"; -Utilities::loadWSDLfiles($wsdluri); +// Utilities::loadWSDLfiles($wsdluri); // specifiy ontology $ontology = 'file:'.realpath("../../examples/family/father.owl"); Modified: trunk/src/php-examples/main.wsdl =================================================================== --- trunk/src/php-examples/main.wsdl 2009-08-07 08:54:57 UTC (rev 1821) +++ trunk/src/php-examples/main.wsdl 2009-08-13 14:08:23 UTC (rev 1822) @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. --><definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.dllearner.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://server.dllearner.org/" name="DLLearnerWSService"> +<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.1 in JDK 6. --><definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.dllearner.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://server.dllearner.org/" name="DLLearnerWSService"> <types> <xsd:schema> <xsd:import namespace="http://server.dllearner.org/" schemaLocation="def0.xsd"></xsd:import> @@ -117,7 +117,6 @@ </message> <message name="learnDescriptionsEvaluated"> <part name="arg0" type="xsd:int"></part> -<part name="arg1" type="xsd:int"></part> </message> <message name="learnDescriptionsEvaluatedResponse"> <part name="return" type="xsd:string"></part> @@ -129,6 +128,13 @@ <message name="getCurrentlyBestEvaluatedDescriptionsResponse"> <part name="return" type="xsd:string"></part> </message> +<message name="learnDescriptionsEvaluatedLimit"> +<part name="arg0" type="xsd:int"></part> +<part name="arg1" type="xsd:int"></part> +</message> +<message name="learnDescriptionsEvaluatedLimitResponse"> +<part name="return" type="xsd:string"></part> +</message> <message name="learnThreaded"> <part name="arg0" type="xsd:int"></part> </message> @@ -406,40 +412,40 @@ <fault message="tns:UnknownComponentException" name="UnknownComponentException"></fault> <fault message="tns:ComponentInitException" name="ComponentInitException"></fault> </operation> -<operation name="stop"> +<operation name="stop" parameterOrder="arg0"> <input message="tns:stop"></input> <output message="tns:stopResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="getBuild"> +<operation name="getBuild" parameterOrder=""> <input message="tns:getBuild"></input> <output message="tns:getBuildResponse"></output> </operation> -<operation name="ping"> +<operation name="ping" parameterOrder=""> <input message="tns:ping"></input> <output message="tns:pingResponse"></output> </operation> -<operation name="generateID"> +<operation name="generateID" parameterOrder=""> <input message="tns:generateID"></input> <output message="tns:generateIDResponse"></output> </operation> -<operation name="getComponents"> +<operation name="getComponents" parameterOrder=""> <input message="tns:getComponents"></input> <output message="tns:getComponentsResponse"></output> </operation> -<operation name="getKnowledgeSources"> +<operation name="getKnowledgeSources" parameterOrder=""> <input message="tns:getKnowledgeSources"></input> <output message="tns:getKnowledgeSourcesResponse"></output> </operation> -<operation name="getReasoners"> +<operation name="getReasoners" parameterOrder=""> <input message="tns:getReasoners"></input> <output message="tns:getReasonersResponse"></output> </operation> -<operation name="getLearningProblems"> +<operation name="getLearningProblems" parameterOrder=""> <input message="tns:getLearningProblems"></input> <output message="tns:getLearningProblemsResponse"></output> </operation> -<operation name="getLearningAlgorithms"> +<operation name="getLearningAlgorithms" parameterOrder=""> <input message="tns:getLearningAlgorithms"></input> <output message="tns:getLearningAlgorithmsResponse"></output> </operation> @@ -479,7 +485,7 @@ <fault message="tns:UnknownComponentException" name="UnknownComponentException"></fault> <fault message="tns:LearningProblemUnsupportedException" name="LearningProblemUnsupportedException"></fault> </operation> -<operation name="initAll"> +<operation name="initAll" parameterOrder="arg0"> <input message="tns:initAll"></input> <output message="tns:initAllResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -490,7 +496,7 @@ <output message="tns:learnResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="learnDescriptionsEvaluated" parameterOrder="arg0 arg1"> +<operation name="learnDescriptionsEvaluated" parameterOrder="arg0"> <input message="tns:learnDescriptionsEvaluated"></input> <output message="tns:learnDescriptionsEvaluatedResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -500,12 +506,17 @@ <output message="tns:getCurrentlyBestEvaluatedDescriptionsResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="learnThreaded"> +<operation name="learnDescriptionsEvaluatedLimit" parameterOrder="arg0 arg1"> +<input message="tns:learnDescriptionsEvaluatedLimit"></input> +<output message="tns:learnDescriptionsEvaluatedLimitResponse"></output> +<fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> +</operation> +<operation name="learnThreaded" parameterOrder="arg0"> <input message="tns:learnThreaded"></input> <output message="tns:learnThreadedResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="getCurrentlyBestConcept"> +<operation name="getCurrentlyBestConcept" parameterOrder="arg0"> <input message="tns:getCurrentlyBestConcept"></input> <output message="tns:getCurrentlyBestConceptResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -520,7 +531,7 @@ <output message="tns:getCurrentlyBestEvaluatedDescriptionsFilteredResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="isAlgorithmRunning"> +<operation name="isAlgorithmRunning" parameterOrder="arg0"> <input message="tns:isAlgorithmRunning"></input> <output message="tns:isAlgorithmRunningResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -608,12 +619,12 @@ <fault message="tns:UnknownComponentException" name="UnknownComponentException"></fault> <fault message="tns:ConfigOptionTypeException" name="ConfigOptionTypeException"></fault> </operation> -<operation name="getAtomicConcepts"> +<operation name="getAtomicConcepts" parameterOrder="arg0"> <input message="tns:getAtomicConcepts"></input> <output message="tns:getAtomicConceptsResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="getSubsumptionHierarchy"> +<operation name="getSubsumptionHierarchy" parameterOrder="arg0"> <input message="tns:getSubsumptionHierarchy"></input> <output message="tns:getSubsumptionHierarchyResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -624,17 +635,17 @@ <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> <fault message="tns:ParseException" name="ParseException"></fault> </operation> -<operation name="getConceptLength"> +<operation name="getConceptLength" parameterOrder="arg0"> <input message="tns:getConceptLength"></input> <output message="tns:getConceptLengthResponse"></output> <fault message="tns:ParseException" name="ParseException"></fault> </operation> -<operation name="getAtomicRoles"> +<operation name="getAtomicRoles" parameterOrder="arg0"> <input message="tns:getAtomicRoles"></input> <output message="tns:getAtomicRolesResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> </operation> -<operation name="getInstances"> +<operation name="getInstances" parameterOrder="arg0"> <input message="tns:getInstances"></input> <output message="tns:getInstancesResponse"></output> <fault message="tns:ClientNotKnownException" name="ClientNotKnownException"></fault> @@ -952,6 +963,18 @@ <soap:fault name="ClientNotKnownException" use="literal"></soap:fault> </fault> </operation> +<operation name="learnDescriptionsEvaluatedLimit"> +<soap:operation soapAction=""></soap:operation> +<input> +<soap:body use="literal" namespace="http://server.dllearner.org/"></soap:body> +</input> +<output> +<soap:body use="literal" namespace="http://server.dllearner.org/"></soap:body> +</output> +<fault name="ClientNotKnownException"> +<soap:fault name="ClientNotKnownException" use="literal"></soap:fault> +</fault> +</operation> <operation name="learnThreaded"> <soap:operation soapAction=""></soap:operation> <input> @@ -1465,4 +1488,4 @@ <soap:address location="http://localhost:8181/services"></soap:address> </port> </service> -</definitions> \ No newline at end of file +</definitions> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |