From: <jen...@us...> - 2008-02-15 16:52:09
|
Revision: 577 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=577&view=rev Author: jenslehmann Date: 2008-02-15 08:18:52 -0800 (Fri, 15 Feb 2008) Log Message: ----------- - added php-examples directory, which should contain simple examples of web service interface usage - created small Utilities class (partially from old LearnerClient file) - added reasoning example Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Added Paths: ----------- trunk/src/php-examples/ trunk/src/php-examples/Reasoning.php trunk/src/php-examples/Utilities.php Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-15 12:44:08 UTC (rev 576) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-15 16:18:52 UTC (rev 577) @@ -35,6 +35,10 @@ import javax.jws.soap.SOAPBinding; import org.dllearner.Info; +import org.dllearner.algorithms.BruteForceLearner; +import org.dllearner.algorithms.RandomGuesser; +import org.dllearner.algorithms.gp.GP; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.Component; import org.dllearner.core.ComponentManager; @@ -57,6 +61,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.utilities.Datastructures; import org.dllearner.utilities.Helper; @@ -87,10 +92,15 @@ knowledgeSourceMapping.put("owlfile", OWLFile.class); knowledgeSourceMapping.put("sparql", SparqlKnowledgeSource.class); reasonerMapping.put("dig", DIGReasoner.class); + reasonerMapping.put("owlapi", OWLAPIReasoner.class); learningProblemMapping.put("posNegDefinition", PosNegDefinitionLP.class); learningProblemMapping.put("posNegInclusion", PosNegInclusionLP.class); learningProblemMapping.put("posOnlyDefinition", PosOnlyDefinitionLP.class); - learningAlgorithmMapping.put("refinement", ROLearner.class); + learningAlgorithmMapping.put("random", RandomGuesser.class); + learningAlgorithmMapping.put("bruteForce", BruteForceLearner.class); + learningAlgorithmMapping.put("genetic", ROLearner.class); + learningAlgorithmMapping.put("refinement", GP.class); + learningAlgorithmMapping.put("refexamples", ExampleBasedROLComponent.class); components = Helper.union(knowledgeSourceMapping.keySet(),reasonerMapping.keySet()); components = Helper.union(components, learningProblemMapping.keySet()); components = Helper.union(components, learningAlgorithmMapping.keySet()); Added: trunk/src/php-examples/Reasoning.php =================================================================== --- trunk/src/php-examples/Reasoning.php (rev 0) +++ trunk/src/php-examples/Reasoning.php 2008-02-15 16:18:52 UTC (rev 577) @@ -0,0 +1,59 @@ +<?php +/** + * 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/>. + * + */ + + /** + * Small example showing how to use DL-Learner for reasoning. + * + * @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/family/father.owl"); + +// create DL-Learner client +$client = new SoapClient("main.wsdl"); + +// load owl file in DIG reasoner (you need a running DIG reasoner) +$id = $client->generateID(); +$ksID = $client->addKnowledgeSource($id, "owlfile", $ontology); +$client->init($id, $ksID); +$rID = $client->setReasoner($id, "dig"); +$client->init($id, $rID); + +// create a concept in internal DL-Learner syntax +// ( = all female persons having at least one child) +$concept = '"http://example.com/father#female" AND EXISTS "http://example.com/father#hasChild".TOP'; +$instances = $client->retrieval($id, $concept); + +// print instances +echo 'instances of ' . $concept . ': <br />'; +echo '<pre>'; +print_r($instances->item); +echo '</pre>'; + +?> \ No newline at end of file Added: trunk/src/php-examples/Utilities.php =================================================================== --- trunk/src/php-examples/Utilities.php (rev 0) +++ trunk/src/php-examples/Utilities.php 2008-02-15 16:18:52 UTC (rev 577) @@ -0,0 +1,167 @@ +<?php +/** + * 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/>. + * + */ + +// Pear HTTP_Request class required +include ('HTTP/Request.php'); + +/** + * Collection of static utility functions. + * + * @author Jens Lehmann + * @author Sebastian Hellmann + */ + +class Utilities { + + /** + * Loads WSDL and imported XSD files from web service and stores them + * locally. + */ + public static function loadWSDLfiles($wsdluri) { + $main = self :: getRequest($wsdluri); + $other = self :: getXSDImports($main); + $newMain = self :: changeXSDImports($main); + self :: writeToFile("main.wsdl", $newMain); + $x = 0; + foreach ($other as $o) { + self :: writeToFile("def" . ($x++) . ".xsd", self :: getRequest($o)); + } + } + + /** + * Change XSD imports in WSDL file to point to local imports. + */ + public static function changeXSDImports($wsdlFileContent) { + $before = "<xsd:import schemaLocation=\""; + $after = "\" namespace=\""; + $newWSDL = ""; + $desca = "def"; + $descb = ".xsd"; + $x = 0; + while ($posstart = strpos($wsdlFileContent, $before)) { + $posstart += strlen($before); + $newWSDL .= substr($wsdlFileContent, 0, $posstart); + $wsdlFileContent = substr($wsdlFileContent, $posstart); + $newWSDL .= $desca . ($x++) . $descb; + $posend = strpos($wsdlFileContent, $after); + $wsdlFileContent = substr($wsdlFileContent, $posend); + } + return $newWSDL . $wsdlFileContent; + } + + /** + * Extracts XSD imports from WSDL file. + */ + public static function getXSDImports($wsdlFileContent) { + $before = "<xsd:import schemaLocation=\""; + $after = "\" namespace=\""; + $ret = array (); + while ($posstart = strpos($wsdlFileContent, $before)) { + $posstart += strlen($before); + $wsdlFileContent = substr($wsdlFileContent, $posstart); + $posend = strpos($wsdlFileContent, $after); + $tmp = substr($wsdlFileContent, 0, $posend); + $ret[] = $tmp; + $wsdlFileContent = substr($wsdlFileContent, $posend +strlen($after)); + } + return $ret; + } + + /** + * Peforms a GET request and returns body of result. + */ + public static function getRequest($uri) { + $req = & new HTTP_Request($uri); + $req->setMethod(HTTP_REQUEST_METHOD_GET); + $req->sendRequest(); + $ret = $req->getResponseBody(); + return $ret; + } + + /** + * Writes $content to file $filename. + */ + public static function writeToFile($filename, $content) { + $fp = fopen($filename, "w"); + fwrite($fp, $content); + fclose($fp); + } + + /** + * Prints a list of all Web Service components and their configuration options. + */ + public static function printWebserviceComponents($client) { + echo '<h1>Web Service Information</h1>'; + + echo '<h2>Knowledge Sources</h2>'; + Utilities :: printComponentsInfo($client, $client->getKnowledgeSources()->item); + + echo '<h2>Reasoners</h2>'; + Utilities :: printComponentsInfo($client, $client->getReasoners()->item); + + echo '<h2>Learning Problems</h2>'; + Utilities :: printComponentsInfo($client, $client->getLearningProblems()->item); + + echo '<h2>Learning Algorithms</h2>'; + Utilities :: printComponentsInfo($client, $client->getLearningAlgorithms()->item); + } + + /** + * Print information about all given components. + */ + public static function printComponentsInfo($client, $components) { + foreach ($components as $component) + Utilities :: printComponentInfo($client, $component); + } + + /** + * Print information about a component. + */ + public static function printComponentInfo($client, $component) { + echo '<h3>component: ' . $component . '</h3>'; + + $options = $client->getConfigOptions($component, true)->item; + if (!is_array($options)) + $options = array ( + $options + ); + + foreach ($options as $option) + Utilities :: printOption($option); + } + + /** + * Prints information about an option. + * + * @param String Option as returned by the DL-Learner web service + * getConfigOption() method. + */ + public static function printOption($option) { + $parts = split('#', $option); + echo 'option name: <b>' . $parts[0] . '</b><br />'; + echo 'option description: ' . $parts[1] . '<br />'; + echo 'option class: ' . $parts[2] . '<br />'; + if ($parts[3] != 'null') + echo 'option name: ' . $parts[3] . '<br />'; + echo '<br />'; + } +} +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |