From: <jen...@us...> - 2009-04-01 10:14:59
|
Revision: 1675 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1675&view=rev Author: jenslehmann Date: 2009-04-01 10:14:48 +0000 (Wed, 01 Apr 2009) Log Message: ----------- - unified component names of web service and command line (script updates may be needed) - started Javadoc of web service Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/php-examples/LearningSimple.php trunk/src/php-examples/LearningThreaded.php Modified: trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java 2009-04-01 09:45:26 UTC (rev 1674) +++ trunk/src/dl-learner/org/dllearner/cli/ConfMapper.java 2009-04-01 10:14:48 UTC (rev 1675) @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.Map.Entry; import org.dllearner.algorithms.BruteForceLearner; @@ -53,6 +54,10 @@ * Developer please edit the buildMappings() function to add new * CLI mappings. * + * TODO: For the web service, it may be interesting to hide some components + * and/or configuration options or even limit the maximum value of certain + * options. + * * @author Jens Lehmann * */ @@ -70,6 +75,9 @@ private static Map<String,Class<? extends Component>> componentTypeMapping = new TreeMap<String,Class<? extends Component>>(); private static Map<Class<? extends Component>, String> inverseTypeMapping = new HashMap<Class<? extends Component>,String>(); + // set of available components + private static Set<String> components = new TreeSet<String>(); + public ConfMapper() { buildMappings(); buildKeys(); @@ -107,6 +115,8 @@ for(Entry<String, Class<? extends Component>> entry : componentMapping.entrySet()) { inverseMapping.put(entry.getValue(), entry.getKey()); } + + components = componentTypeMapping.keySet(); } private static void buildKeys() { @@ -172,7 +182,7 @@ } public Set<String> getComponents() { - return componentMapping.keySet(); + return components; } } Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2009-04-01 09:45:26 UTC (rev 1674) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2009-04-01 10:14:48 UTC (rev 1675) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2009, Jens Lehmann * * This file is part of DL-Learner. * Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2009-04-01 09:45:26 UTC (rev 1674) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2009-04-01 10:14:48 UTC (rev 1675) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2009, Jens Lehmann * * This file is part of DL-Learner. * @@ -39,11 +39,7 @@ import org.apache.log4j.Logger; import org.dllearner.Info; -import org.dllearner.algorithms.BruteForceLearner; -import org.dllearner.algorithms.RandomGuesser; -import org.dllearner.algorithms.gp.GP; -import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.algorithms.refinement2.ROLComponent2; +import org.dllearner.cli.ConfMapper; import org.dllearner.core.Component; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; @@ -58,7 +54,6 @@ import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.NaturalLanguageDescriptionConvertVisitor; import org.dllearner.kb.sparql.SPARQLTasks; @@ -66,19 +61,17 @@ import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.kb.sparql.SparqlQueryException; -import org.dllearner.learningproblems.PosNegLPStandard; -import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.reasoning.OWLAPIReasoner; -import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; /** - * DL-Learner web service interface. + * DL-Learner web service interface. The web service makes use of the component + * architecture of DL-Learner (see + * <a href="http://dl-learner.org/wiki/Architecture">architecture wiki page</a>), + * i.e. it allows to create, configure and run components. In addition, it provides + * access to some reasoning and querying methods. * * @author Jens Lehmann * @@ -87,41 +80,13 @@ @SOAPBinding(style = SOAPBinding.Style.RPC) public class DLLearnerWS { - @SuppressWarnings("unused") - private static Logger logger = Logger - .getLogger(DLLearnerWS.class); + private static Logger logger = Logger.getLogger(DLLearnerWS.class); private Map<Integer, ClientState> clients = new TreeMap<Integer,ClientState>(); private Random rand=new Random(); private static ComponentManager cm = ComponentManager.getInstance(); + private static ConfMapper confMapper = new ConfMapper(); - // defines the components, which are accessible for the web service - private static Map<String,Class<? extends KnowledgeSource>> knowledgeSourceMapping = new TreeMap<String,Class<? extends KnowledgeSource>>(); - private static Map<String,Class<? extends ReasonerComponent>> reasonerMapping = new TreeMap<String,Class<? extends ReasonerComponent>>(); - private static Map<String,Class<? extends LearningProblem>> learningProblemMapping = new TreeMap<String,Class<? extends LearningProblem>>(); - private static Map<String,Class<? extends LearningAlgorithm>> learningAlgorithmMapping = new TreeMap<String,Class<? extends LearningAlgorithm>>(); - private static Set<String> components; - - public DLLearnerWS() { - // TODO maybe use ConfMapper (one could add methods there for removing - // certain components, which should not be accessible by the web service) - knowledgeSourceMapping.put("owlfile", OWLFile.class); - knowledgeSourceMapping.put("sparql", SparqlKnowledgeSource.class); - reasonerMapping.put("dig", DIGReasoner.class); - reasonerMapping.put("owlapi", OWLAPIReasoner.class); - reasonerMapping.put("fastInstanceChecker", FastInstanceChecker.class); - learningProblemMapping.put("posNegDefinition", PosNegLPStandard.class); - learningProblemMapping.put("posOnlyDefinition", PosOnlyLP.class); - learningAlgorithmMapping.put("random", RandomGuesser.class); - learningAlgorithmMapping.put("bruteForce", BruteForceLearner.class); - learningAlgorithmMapping.put("gp", GP.class); - learningAlgorithmMapping.put("refinement", ROLearner.class); - learningAlgorithmMapping.put("refexamples", ROLComponent2.class); - components = Helper.union(knowledgeSourceMapping.keySet(),reasonerMapping.keySet()); - components = Helper.union(components, learningProblemMapping.keySet()); - components = Helper.union(components, learningAlgorithmMapping.keySet()); - } - /** * Returns the DL-Learner version this web service is based on. * @return DL-Learner-Build. @@ -132,6 +97,16 @@ } /** + * Method to check whether web service is online and how fast it responses. + * This method simply returns true. + * @return Always returns true. + */ + @WebMethod + public boolean ping() { + return true; + } + + /** * Generates a unique ID for the client and initialises a session. * Using the ID the client can call the other web service methods. * Two calls to this method are guaranteed to return different results. @@ -142,70 +117,78 @@ public int generateID() { int id; do { - id = rand.nextInt(); + id = Math.abs(rand.nextInt()); } while(clients.containsKey(id)); clients.put(id, new ClientState()); + logger.info("New client " + id + " at DL-Learner web service."); return id; } - // returns session state or throws client not known exception - private ClientState getState(int id) throws ClientNotKnownException { - ClientState state = clients.get(id); - if(state==null) - throw new ClientNotKnownException(id); - return state; - } - - // returns the class which is referred to by the string - private Class<? extends Component> getComponent(String component) throws UnknownComponentException { - if(knowledgeSourceMapping.containsKey(component)) - return knowledgeSourceMapping.get(component); - else if(reasonerMapping.containsKey(component)) - return reasonerMapping.get(component); - else if(learningProblemMapping.containsKey(component)) - return learningProblemMapping.get(component); - else if(learningAlgorithmMapping.containsKey(component)) - return learningAlgorithmMapping.get(component); - else - throw new UnknownComponentException(component); - } - /////////////////////////////////////// // methods for basic component setup // /////////////////////////////////////// + /** + * Gets a list of all DL-Learner components accessible via this web service. + * @return All components accessible via this web service. + */ @WebMethod public String[] getComponents() { + Set<String> components = confMapper.getComponents(); return components.toArray(new String[components.size()]); } + /** + * Gets a list of all DL-Learner knowledge source components accessible via this web service. + * @return All knowledge source components accessible via this web service. + */ @WebMethod public String[] getKnowledgeSources() { - Set<String> knowledgeSources = knowledgeSourceMapping.keySet(); + Set<String> knowledgeSources = confMapper.getKnowledgeSources(); return knowledgeSources.toArray(new String[knowledgeSources.size()]); } + /** + * Gets a list of all DL-Learner reasoner components accessible via this web service. + * @return All reasoner components accessible via this web service. + */ @WebMethod public String[] getReasoners() { - Set<String> reasoners = reasonerMapping.keySet(); + Set<String> reasoners = confMapper.getReasoners(); return reasoners.toArray(new String[reasoners.size()]); } + /** + * Gets a list of all DL-Learner learning problem components accessible via this web service. + * @return All learning problem components accessible via this web service. + */ @WebMethod public String[] getLearningProblems() { - Set<String> learningProblems = learningProblemMapping.keySet(); + Set<String> learningProblems = confMapper.getLearningProblems(); return learningProblems.toArray(new String[learningProblems.size()]); } + /** + * Gets a list of all DL-Learner learning algorithm components accessible via this web service. + * @return All learning algorithm components accessible via this web service. + */ @WebMethod public String[] getLearningAlgorithms() { - Set<String> learningAlgorithms = learningAlgorithmMapping.keySet(); + Set<String> learningAlgorithms = confMapper.getLearningAlgorithms(); return learningAlgorithms.toArray(new String[learningAlgorithms.size()]); } + /** + * Gets the configuration options supported by the component. This allows e.g. to + * automatically build user interfaces for configuring components. + * @param component Name of the component. + * @param allInfo Whether or not complete information is desired (including option description, allowed values, default value). + * @return A list of configuration options supported by the component. + * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). + */ @WebMethod public String[] getConfigOptions(String component, boolean allInfo) throws UnknownComponentException { - Class<? extends Component> componentClass = getComponent(component); + Class<? extends Component> componentClass = confMapper.getComponentClass(component); List<ConfigOption<?>> options = ComponentManager.getConfigOptions(componentClass); String[] optionsString = new String[options.size()]; for(int i=0; i<options.size(); i++) { @@ -223,13 +206,18 @@ /** * Adds a knowledge source. * + * @param id The session ID. + * @param component The name of the component. + * @param url The URL of the knowledge source. * @return An identifier for the component. - * @throws MalformedURLException + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). + * @throws MalformedURLException Thrown if passed URL is malformed. */ @WebMethod public int addKnowledgeSource(int id, String component, String url) throws ClientNotKnownException, UnknownComponentException, MalformedURLException { ClientState state = getState(id); - Class<? extends KnowledgeSource> ksClass = knowledgeSourceMapping.get(component); + Class<? extends KnowledgeSource> ksClass = confMapper.getKnowledgeSourceClass(component); if(ksClass == null) throw new UnknownComponentException(component); KnowledgeSource ks = cm.knowledgeSource(ksClass); @@ -237,15 +225,31 @@ return state.addKnowledgeSource(ks); } + /** + * Removes a knowledge source. + * + * @param id The session ID. + * @param componentID ID of knowledge source to remove. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public void removeKnowledgeSource(int id, int componentID) throws ClientNotKnownException { getState(id).removeKnowledgeSource(componentID); } + /** + * Sets the reasoner to use. + * + * @param id The session ID. + * @param component The name of the component. + * @return An identifier for the component. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). + */ @WebMethod public int setReasoner(int id, String component) throws ClientNotKnownException, UnknownComponentException { ClientState state = getState(id); - Class<? extends ReasonerComponent> rcClass = reasonerMapping.get(component); + Class<? extends ReasonerComponent> rcClass = confMapper.getReasonerComponentClass(component); if(rcClass == null) throw new UnknownComponentException(component); @@ -253,10 +257,19 @@ return state.setReasonerComponent(rc); } + /** + * Sets the learning problem to use. + * + * @param id The session ID. + * @param component The name of the component. + * @return An identifier for the component. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). + */ @WebMethod public int setLearningProblem(int id, String component) throws ClientNotKnownException, UnknownComponentException { ClientState state = getState(id); - Class<? extends LearningProblem> lpClass = learningProblemMapping.get(component); + Class<? extends LearningProblem> lpClass = confMapper.getLearningProblemClass(component); if(lpClass == null) throw new UnknownComponentException(component); @@ -264,10 +277,20 @@ return state.setLearningProblem(lp); } + /** + * Sets the learning algorithm to use. + * + * @param id The session ID. + * @param component The name of the component. + * @return An identifier for the component. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException Thrown if component is not known (see {@link #getComponents()}). + * @throws LearningProblemUnsupportedException Thrown if the learning problem is not supported by the specified learning algorithm. + */ @WebMethod public int setLearningAlgorithm(int id, String component) throws ClientNotKnownException, UnknownComponentException, LearningProblemUnsupportedException { ClientState state = getState(id); - Class<? extends LearningAlgorithm> laClass = learningAlgorithmMapping.get(component); + Class<? extends LearningAlgorithm> laClass = confMapper.getLearningAlgorithmClass(component); if(laClass == null) throw new UnknownComponentException(component); @@ -278,7 +301,7 @@ /** * Initialise all components. * @param id Session ID. - * @throws ComponentInitException + * @throws ComponentInitException Thrown if an error occurs during component initialisation. */ @WebMethod public void initAll(int id) throws ClientNotKnownException, ComponentInitException { @@ -294,7 +317,7 @@ * Initialise the specified component. * @param id Session-ID. * @param componentID Component-ID. - * @throws ClientNotKnownException Thrown if the client ID is nor registered. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. * @throws UnknownComponentException Thrown if the component is unknown. * @throws ComponentInitException */ @@ -312,7 +335,7 @@ * @param id Session ID. * @param format The format of the result string: "manchester", "kb", "dl". * @return The best solution found. - * @throws ClientNotKnownException + * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod public String learn(int id, String format) throws ClientNotKnownException { @@ -327,6 +350,16 @@ return solution.toString(); } + /** + * 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 { ClientState state = getState(id); @@ -349,7 +382,7 @@ * controlled using other Web Service methods. * * @param id Session ID. - * @throws ClientNotKnownException + * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod public void learnThreaded(int id) throws ClientNotKnownException { @@ -365,12 +398,26 @@ learningThread.start(); } + /** + * + * @param id The session ID. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public String getCurrentlyBestConcept(int id) throws ClientNotKnownException { ClientState state = getState(id); return state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescription().toString(); } + /** + * + * @param id The session ID. + * @param nrOfConcepts + * @param format + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public String[] getCurrentlyBestConcepts(int id, int nrOfConcepts, String format) throws ClientNotKnownException { ClientState state = getState(id); @@ -387,17 +434,42 @@ return conc.toArray(new String[conc.size()]); } + /** + * + * @param id The session ID. + * @param limit + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public String getCurrentlyBestEvaluatedDescriptions(int id, int limit) throws ClientNotKnownException{ return currentlyBestEvaluatedDescriptions(id,limit,-1,false); } + /** + * + * @param id The session ID. + * @param nrOfDescriptions + * @param accuracyThreshold + * @param filterNonMinimalDescriptions + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public String getCurrentlyBestEvaluatedDescriptionsFiltered(int id,int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) throws ClientNotKnownException { return currentlyBestEvaluatedDescriptions(id,nrOfDescriptions,accuracyThreshold,filterNonMinimalDescriptions); } + /** + * + * @param id The session ID. + * @param nrOfDescriptions + * @param accuracyThreshold + * @param filterNonMinimalDescriptions + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ private String currentlyBestEvaluatedDescriptions(int id,int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) throws ClientNotKnownException { ClientState state = getState(id); @@ -415,6 +487,12 @@ return json; } + /** + * + * @param id The session ID. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public boolean isAlgorithmRunning(int id) throws ClientNotKnownException { return getState(id).getLearningAlgorithm().isRunning(); @@ -422,8 +500,8 @@ /** * Stops the learning algorithm smoothly. - * @param id - * @throws ClientNotKnownException + * @param id The session ID. + * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod public void stop(int id) throws ClientNotKnownException { @@ -434,6 +512,12 @@ // methods for component configuration // ///////////////////////////////////////// + /** + * + * @param id The session ID. + * @param positiveExamples + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public void setPositiveExamples(int id, String[] positiveExamples) throws ClientNotKnownException { ClientState state = getState(id); @@ -441,6 +525,13 @@ cm.applyConfigEntry(state.getLearningProblem(), "positiveExamples", posExamples); } + + /** + * + * @param id The session ID. + * @param negativeExamples + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + */ @WebMethod public void setNegativeExamples(int id, String[] negativeExamples) throws ClientNotKnownException { ClientState state = getState(id); @@ -448,16 +539,44 @@ cm.applyConfigEntry(state.getLearningProblem(), "negativeExamples", negExamples); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @param value + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + */ @WebMethod public void applyConfigEntryInt(int sessionID, int componentID, String optionName, Integer value) throws ClientNotKnownException, UnknownComponentException { applyConfigEntry(sessionID, componentID,optionName,value); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @param value + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + */ @WebMethod public void applyConfigEntryString(int sessionID, int componentID, String optionName, String value) throws ClientNotKnownException, UnknownComponentException { applyConfigEntry(sessionID, componentID,optionName,value); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @param value + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws MalformedURLException + */ @WebMethod public void applyConfigEntryURL(int sessionID, int componentID, String optionName, String value) throws ClientNotKnownException, UnknownComponentException, MalformedURLException { // URLs are passed as String and then converted @@ -465,69 +584,141 @@ applyConfigEntry(sessionID, componentID,optionName,url); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @param value + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + */ @WebMethod public void applyConfigEntryStringArray(int sessionID, int componentID, String optionName, String[] value) throws ClientNotKnownException, UnknownComponentException { Set<String> stringSet = new TreeSet<String>(Arrays.asList(value)); applyConfigEntry(sessionID, componentID,optionName,stringSet); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @param value + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + */ @WebMethod public void applyConfigEntryBoolean(int sessionID, int componentID, String optionName, Boolean value) throws ClientNotKnownException, UnknownComponentException { applyConfigEntry(sessionID, componentID,optionName,value); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @param value + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + */ private void applyConfigEntry(int sessionID, int componentID, String optionName, Object value) throws ClientNotKnownException, UnknownComponentException { ClientState state = getState(sessionID); Component component = state.getComponent(componentID); cm.applyConfigEntry(component, optionName, value); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws ConfigOptionTypeException + */ @WebMethod public String[] getConfigOptionValueStringArray(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { return getConfigOptionValue(sessionID, componentID, optionName, String[].class); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws ConfigOptionTypeException + */ @WebMethod public String getConfigOptionValueString(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { return getConfigOptionValue(sessionID, componentID, optionName, String.class); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws ConfigOptionTypeException + */ @WebMethod public String getConfigOptionValueURL(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { URL url = getConfigOptionValue(sessionID, componentID, optionName, URL.class); return url.toString(); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws ConfigOptionTypeException + */ @WebMethod public Double getConfigOptionValueDouble(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { return getConfigOptionValue(sessionID, componentID, optionName, Double.class); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws ConfigOptionTypeException + */ @WebMethod public Boolean getConfigOptionValueBoolean(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { return getConfigOptionValue(sessionID, componentID, optionName, Boolean.class); } + /** + * + * @param sessionID The session ID. + * @param componentID The componentID. + * @param optionName The name of the configuration option. + * @return + * @throws ClientNotKnownException Thrown if client (session ID) is not known. + * @throws UnknownComponentException + * @throws ConfigOptionTypeException + */ @WebMethod public Integer getConfigOptionValueInt(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { return getConfigOptionValue(sessionID, componentID, optionName, Integer.class); } - @SuppressWarnings({"unchecked"}) - private <T> T getConfigOptionValue(int sessionID, int componentID, String optionName, Class<T> clazz) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { - Object value = getConfigOptionValue(sessionID, componentID, optionName); - if(clazz.isInstance(value)) - return (T) value; - else - throw new ConfigOptionTypeException(optionName, clazz, value.getClass()); - } - - private Object getConfigOptionValue(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException { - ClientState state = getState(sessionID); - Component component = state.getComponent(componentID); - return cm.getConfigOptionValue(component, optionName); - } - //////////////////////////////////// // reasoning and querying methods // //////////////////////////////////// @@ -778,9 +969,31 @@ return negExamples.toArray(new String[negExamples.size()]); } - @WebMethod - public void debug(String deb) - { - System.out.println(deb); + ///////////////////////////// + // private utility methods // + ///////////////////////////// + + // returns session state or throws client not known exception + private ClientState getState(int id) throws ClientNotKnownException { + ClientState state = clients.get(id); + if(state==null) + throw new ClientNotKnownException(id); + return state; } + + @SuppressWarnings({"unchecked"}) + private <T> T getConfigOptionValue(int sessionID, int componentID, String optionName, Class<T> clazz) throws ClientNotKnownException, UnknownComponentException, ConfigOptionTypeException { + Object value = getConfigOptionValue(sessionID, componentID, optionName); + if(clazz.isInstance(value)) + return (T) value; + else + throw new ConfigOptionTypeException(optionName, clazz, value.getClass()); + } + + private Object getConfigOptionValue(int sessionID, int componentID, String optionName) throws ClientNotKnownException, UnknownComponentException { + ClientState state = getState(sessionID); + Component component = state.getComponent(componentID); + return cm.getConfigOptionValue(component, optionName); + } + } Modified: trunk/src/php-examples/LearningSimple.php =================================================================== --- trunk/src/php-examples/LearningSimple.php 2009-04-01 09:45:26 UTC (rev 1674) +++ trunk/src/php-examples/LearningSimple.php 2009-04-01 10:14:48 UTC (rev 1675) @@ -51,7 +51,7 @@ $negExamples = array('http://example.com/father#heinz', 'http://example.com/father#anna', 'http://example.com/father#michelle'); -$client->setLearningProblem($id, "posNegDefinition"); +$client->setLearningProblem($id, "posNegLPStandard"); $client->setPositiveExamples($id, $posExamples); $client->setNegativeExamples($id, $negExamples); Modified: trunk/src/php-examples/LearningThreaded.php =================================================================== --- trunk/src/php-examples/LearningThreaded.php 2009-04-01 09:45:26 UTC (rev 1674) +++ trunk/src/php-examples/LearningThreaded.php 2009-04-01 10:14:48 UTC (rev 1675) @@ -41,6 +41,12 @@ // load owl file in reasoner $id = $client->generateID(); + +$state = $client->getState($id); + +var_dump($state); +echo 'STATE END'; + $ksID = $client->addKnowledgeSource($id, "owlfile", $ontology); $rID = $client->setReasoner($id, "owlapi"); @@ -62,7 +68,7 @@ 'http://localhost/foo#mandy', 'http://localhost/foo#miriam', 'http://localhost/foo#hanna'); -$client->setLearningProblem($id, "posNegDefinition"); +$client->setLearningProblem($id, "posNegLPStandard"); $client->setPositiveExamples($id, $posExamples); $client->setNegativeExamples($id, $negExamples); @@ -94,7 +100,7 @@ } while($running); -// print best concepts found (not all of are +// print best concepts found (not all of which are // necessarily perfect solutions) echo '<br />Algorithm finished. Best concepts: '; echo '<pre>'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |