From: <ku...@us...> - 2007-08-22 10:40:12
|
Revision: 21 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=21&view=rev Author: kurzum Date: 2007-08-22 03:40:10 -0700 (Wed, 22 Aug 2007) Log Message: ----------- update Added Paths: ----------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS2.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java Added: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-08-22 10:40:10 UTC (rev 21) @@ -0,0 +1,227 @@ +package org.dllearner.server; + +import java.util.HashMap; +import java.util.Random; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + +import org.dllearner.server.exceptions.ClientNotKnownException; +import org.dllearner.server.exceptions.NoOntologySelectedException; +import org.dllearner.server.exceptions.OntologyURLNotValid; + +/** + * Offene Fragen: + * + * Welche Rückgabetypen sind erlaubt? + * Wie behandelt man Exceptions (z.B. aus angegebener URI kann keine Ontologie + * gelesen werden)? + * + * @author Jens Lehmann + * + */ +@WebService(name = "DLLearnerWebService") +@SOAPBinding(style = SOAPBinding.Style.RPC) +public class DLLearnerWS { + Random rand=new Random(); + private HashMap<Integer, ClientState> clients; + + // private String ontologyURL; + // private String ontologyFormat; + + + + public DLLearnerWS(){ + this.clients=new HashMap<Integer, ClientState>(); + + } + + /** + * + * + * + */ + @WebMethod + public int getID(){ + int id=rand.nextInt(); + while (id<=0){ + id=rand.nextInt(); + } + + // dont change to local function get, cause of exception + ClientState c=this.clients.get(new Long(id)); + if(c!=null){ + return getID(); + } + else { + this.clients.put(new Integer(id), new ClientState()); + System.out.println("new Client with id: "+id); + return id; + } + + } + + @WebMethod + public void addPositiveExample(int id,String posExample) throws ClientNotKnownException{ + ClientState c=getClientState(id); + c.addPositiveExample(posExample); + //positiveExamples.add(new Individual(posExample)); + } + @WebMethod + public void addNegativeExample(int id,String negExample) throws ClientNotKnownException { + ClientState c=getClientState(id); + c.addNegativeExample(negExample); + } + @WebMethod + public void addIgnoredConcept(int id,String concept)throws ClientNotKnownException { + getClientState(id).addIgnoredConcept(concept); + } + + @WebMethod + public String[] selectInstancesForAConcept(int id,String Concept)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).selectInstancesForAConcept(Concept); + } + + @WebMethod + public String[] selectAConcept(int id,String Concept,int Percentage)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).selectAConcept(Concept, Percentage); + } + + @WebMethod + public String[] getPositiveExamples(int id)throws ClientNotKnownException{ + ClientState c=getClientState(id); + return c.getPositiveExamples(); + } + @WebMethod + public String[] getNegativeExamples(int id)throws ClientNotKnownException{ + ClientState c=getClientState(id); + return c.getNegativeExamples(); + } + @WebMethod + public String[] getIgnoredConcepts(int id)throws ClientNotKnownException{ + return getClientState(id).getIgnoredConcepts(); + } + + @WebMethod + public boolean removePositiveExample(int id, String pos)throws ClientNotKnownException{ + return getClientState(id).removePositiveExample(pos); + } + + @WebMethod + public boolean removeNegativeExample(int id, String neg)throws ClientNotKnownException{ + return getClientState(id).removeNegativeExample(neg); + } + @WebMethod + public boolean removeAllExamples(int id)throws ClientNotKnownException{ + return getClientState(id).removeAllExamples(); + } + @WebMethod + public boolean removeAllPositiveExamples(int id)throws ClientNotKnownException{ + return getClientState(id).removeAllPositiveExamples(); + } + @WebMethod + public boolean removeAllNegativeExamples(int id)throws ClientNotKnownException{ + return getClientState(id).removeAllNegativeExamples(); + } + @WebMethod + public void removeIgnoredConcept(int id,String concept)throws ClientNotKnownException{ + getClientState(id).removeIgnoredConcept(concept); + } + + @WebMethod + public String getCurrentOntologyURL(int id)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).getCurrentOntologyURL(); + + } + + @WebMethod + public String[] getInstances(int id)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).getInstances(); + } + + @WebMethod + public String[] getAtomicConcepts(int id)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).getAtomicConcepts(); + } + + @WebMethod + public String[] getAtomicRoles(int id)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).getAtomicRoles(); + } + @WebMethod + public String[] getIndividualsForARole(int id,String Role)throws ClientNotKnownException, NoOntologySelectedException{ + return getClientState(id).getIndividualsForARole(Role); + } + @WebMethod + public String getSubsumptionHierarchy(int id)throws ClientNotKnownException, NoOntologySelectedException{ + return getClientState(id).getSubsumptionHierarchy(); + } + + @WebMethod + public String[] retrieval(int id,String Concept)throws ClientNotKnownException,NoOntologySelectedException{ + return getClientState(id).retrieval(Concept); + } + + @WebMethod + public void readOntology(int id,String ontologyURL, String format)throws ClientNotKnownException,OntologyURLNotValid{ + getClientState(id).readOntology(ontologyURL, format); + + } + + @WebMethod + public void removeOntology(int id)throws ClientNotKnownException{ + getClientState(id).removeOntology(); + } + + @WebMethod + public String learnConcept(int id)throws ClientNotKnownException{ + return "Deprecated method"; + + } + + + @WebMethod + public String getAlgorithmStatus(int id ) throws ClientNotKnownException{ + + return getClientState(id).getAlgorithmStatus(); + } + + + @WebMethod + public void learnMonitored(int id )throws ClientNotKnownException{ + getClientState(id).learnMonitored(); + } + /*@WebMethod + public void relearn(int id,String Concept )throws ClientNotKnownException{ + getClientState(id).relearn(Concept); + }*/ + + @WebMethod + public String getLastResult(int id)throws ClientNotKnownException{ + return getClientState(id).getLastResult(); + } + + @WebMethod + public void stop(int id)throws ClientNotKnownException{ + getClientState(id).stop(); + } + + + //*************************USER MANAGEMENT + + public ClientState getClientState(int id)throws ClientNotKnownException{ + System.out.println("Request from "+id); + ClientState c=this.clients.get(new Integer(id)); + if(c==null){ + //System.out.println(clients.keySet().toString()); + throw new ClientNotKnownException("Client with id: "+id+" is not known","ClientNotKnownException");}; + return c; + + } + + + + + +} \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS2.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS2.java 2007-08-22 10:40:10 UTC (rev 21) @@ -0,0 +1,68 @@ +package org.dllearner.server; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + +import org.dllearner.server.exceptions.ClientNotKnownException; + + +/** + * Offene Fragen: + * + * Welche Rückgabetypen sind erlaubt? + * Wie behandelt man Exceptions (z.B. aus angegebener URI kann keine Ontologie + * gelesen werden)? + * + * @author Jens Lehmann + * + */ +@WebService(name = "DLLearnerWebService") + +@SOAPBinding(style = SOAPBinding.Style.RPC) +public class DLLearnerWS2 { + + /* + // String[] funktioniert leider noch nicht + @WebMethod + public void addPositiveExamples(String[] posExamples) { + for(String example : posExamples) + positiveExamples.add(new Individual(example)); + } + + @WebMethod + public void addNegativeExamples(String[] negExamples) { + for(String example : negExamples) + negativeExamples.add(new Individual(example)); + } + */ + + @WebMethod + /** + * @param name + * + * @return The sum + * @throws AddNumbersException + * if any of the numbers to be added is negative. + * + **/ + public String hellosimple(String name) throws ClientNotKnownException{ + /*for (int i = 0; i < name.length; i++) { + name[i]=i+"nnnn<br>"; + }*/ + if(name.equals("aa"))throw new ClientNotKnownException("a","b"); + + return "bbb"; + } + + + // Testmethode + @WebMethod + public String hello(String name){ + name=null; + //name.substring(5); + //throw new NullPointerException(); + return "Hello " + name + "!"; + } + +} \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2007-08-22 10:40:10 UTC (rev 21) @@ -0,0 +1,70 @@ +package org.dllearner.server; + + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetSocketAddress; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.xml.ws.Endpoint; + +import com.sun.net.httpserver.HttpContext; +import com.sun.net.httpserver.HttpServer; + + +public class DLLearnerWSStart { + + public static void main(String[] args) { + String url = "http://139.18.114.78:8181/services"; + if (args.length > 0) + url = args[0]; + try{ + + InetSocketAddress isa=new InetSocketAddress("localhost",8181); + HttpServer server = HttpServer.create(isa, 5); + ExecutorService threads = Executors.newFixedThreadPool(5); + server.setExecutor(threads); + server.start(); + + System.out.print("Starting DL-Learner web service at http://" + + isa.getHostName()+":"+isa.getPort()+ "/services ... "); + Endpoint endpoint = Endpoint.create(new DLLearnerWS()); + //Endpoint endpoint = Endpoint.create(new CustomDataClass()); + HttpContext context = server.createContext("/services"); + endpoint.publish(context); + //Endpoint endpoint = Endpoint.publish(url, new DLLearnerWS()); + + System.out.println("OK."); + + + + System.out.println("Type \"exit\" to terminate web service."); + boolean terminate = false; + String inputString = ""; + do { + BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); + + try { + inputString = input.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + + if (inputString.equals("exit")) + terminate = true; + + } while (!terminate); + + System.out.print("Stopping web service ... "); + endpoint.stop(); + + server.stop(1); + threads.shutdown(); + System.out.println("OK."); + }catch (Exception e) {e.printStackTrace();} + } + +} Added: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSoriginal.java 2007-08-22 10:40:10 UTC (rev 21) @@ -0,0 +1,166 @@ +package org.dllearner.server; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + +import org.dllearner.Config; +import org.dllearner.LearningProblem; +import org.dllearner.Main; +import org.dllearner.OntologyFileFormat; +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.dl.Individual; +import org.dllearner.dl.KB; +import org.dllearner.reasoning.Reasoner; +import org.dllearner.reasoning.ReasoningMethodUnsupportedException; +import org.dllearner.reasoning.ReasoningService; + +/** + * Offene Fragen: + * + * Welche Rückgabetypen sind erlaubt? + * Wie behandelt man Exceptions (z.B. aus angegebener URI kann keine Ontologie + * gelesen werden)? + * + * @author Jens Lehmann + * + */ +@WebService(name = "DLLearnerWebService") +@SOAPBinding(style = SOAPBinding.Style.RPC) +public class DLLearnerWSoriginal { + + // private String ontologyURL; + // private String ontologyFormat; + private Reasoner reasoner; + private ReasoningService rs; + private SortedSet<Individual> positiveExamples = new TreeSet<Individual>(); + private SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); + + /** + * Specifies the URI of the ontology containing the background + * knowledge. Reads the ontology and sends it to the reasoner. + * + * @param ontologyURI The URI of the ontology to use. + */ + // gleiche Methoden mit verschiedenen Parametern sind offenbar problematisch + /* + @WebMethod + public void readOntology(String ontologyURI) { + readOntology(ontologyURI, "RDF/XML"); + } + */ + + /** + * Specifies the URI of the ontology containing the background + * knowledge and its format. Reads the ontology and sends it to + * the reasoner. + * + * @param ontologyURI The URI of the ontology to use. + * @param format "RDF/XML" or "N-TRIPLES". + */ + @WebMethod + public void readOntology(String ontologyURL, String format) { + // this.ontologyURL = ontologyURL; + // this.ontologyFormat = format; + + // TODO: potentielles Sicherheitsrisiko, da man damit derzeit auch lokale Dateien + // laden könnte (Fix: nur http:// zulassen, kein file://) + URL ontology = null; + try { + ontology = new URL(ontologyURL); + } catch (MalformedURLException e1) { + e1.printStackTrace(); + } + + OntologyFileFormat ofFormat; + if (format.equals("RDF/XML")) + ofFormat = OntologyFileFormat.RDF_XML; + else + ofFormat = OntologyFileFormat.N_TRIPLES; + + Map<URL, OntologyFileFormat> m = new HashMap<URL, OntologyFileFormat>(); + m.put(ontology, ofFormat); + + // Default-URI für DIG-Reasoner setzen + try { + Config.digReasonerURL = new URL("http://localhost:8081"); + } catch (MalformedURLException e) { + // Exception tritt nie auf, da URL korrekt + e.printStackTrace(); + } + + reasoner = Main.createReasoner(new KB(), m); + + rs = new ReasoningService(reasoner); + + } + + + @WebMethod + public String[] testString(String c) { + + return new String[]{"a","b"}; + } + + // String[] funktioniert leider noch nicht + @WebMethod + public void addPositiveExamples(String[] posExamples) { + for(String example : posExamples) + positiveExamples.add(new Individual(example)); + } + + @WebMethod + public void addNegativeExamples(String[] negExamples) { + for(String example : negExamples) + negativeExamples.add(new Individual(example)); + } + + + @WebMethod + public void addPositiveExample(String posExample) { + positiveExamples.add(new Individual(posExample)); + } + + @WebMethod + public void addNegativeExample(String negExample) { + negativeExamples.add(new Individual(negExample)); + } + + @WebMethod + public String learnConcept() { + // notwendige Vorverarbeitungsschritte für den Lernalgorithmus + // - es müssen ein paar Konzepte, die ev. von Jena generiert wurden ignoriert + // werden + // - die Subsumptionhierarchie muss erstellt werden + // - die Subsumptionhierarchie wird verbessert um das Lernen effizienter zu machen + Main.autoDetectConceptsAndRoles(rs); + reasoner.prepareSubsumptionHierarchy(); + if (Config.Refinement.improveSubsumptionHierarchy) { + try { + reasoner.getSubsumptionHierarchy().improveSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + // solange DIG-Reasoner eingestellt ist, schlägt diese Operation nie fehl + e.printStackTrace(); + } + } + + LearningProblem learningProblem = new LearningProblem(rs, positiveExamples, negativeExamples); + // erstmal wird nur der Refinement-Learner als Web-Service angeboten + ROLearner learner = new ROLearner(learningProblem); + return learner.getBestSolution().toString(); + } + + // Testmethode + @WebMethod + public String hello(String name) { + return "Hello " + name + "!"; + } + +} \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/server/LearnMonitor.java 2007-08-22 10:40:10 UTC (rev 21) @@ -0,0 +1,81 @@ +package org.dllearner.server; + +import org.dllearner.Config; +import org.dllearner.LearningProblem; +import org.dllearner.Main; +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.reasoning.ReasoningMethodUnsupportedException; + +public class LearnMonitor extends Thread { + + + private ClientState c; + private boolean active = false; + + //private ROLearner ROL; + + public LearnMonitor(ClientState c){ + this.c=c; + } + + + public void end(){ + + System.out.println("trying to end"); + System.out.println("ROL2"+c.ROL); + this.c.ROL.stop(); + c.setLastResult(c.ROL.getBestSolution().toString()); + c.setStatus("stopped"); + } + + public void learn(){ + + this.start(); + + } + + public void run(){ + try{ + c.setStatus("still running"); + active=true; + c.setStatus("running"); + + // notwendige Vorverarbeitungsschritte für den Lernalgorithmus + // - es müssen ein paar Konzepte, die ev. von Jena generiert wurden ignoriert + // werden + // - die Subsumptionhierarchie muss erstellt werden + // - die Subsumptionhierarchie wird verbessert um das Lernen effizienter zu machen + Main.autoDetectConceptsAndRoles(c.getRs()); + c.getReasoner().prepareSubsumptionHierarchy(); + if (Config.Refinement.improveSubsumptionHierarchy) { + try { + c.getReasoner().getSubsumptionHierarchy().improveSubsumptionHierarchy(); + } catch (ReasoningMethodUnsupportedException e) { + // solange DIG-Reasoner eingestellt ist, schlägt diese Operation nie fehl + e.printStackTrace(); + } + } + c.p("learning started"); + LearningProblem learningProblem = new LearningProblem(c.getRs(), c.getPosExamples(), c.getNegExamples()); + // erstmal wird nur der Refinement-Learner als Web-Service angeboten + //System.out.println("aaaa"); + c.ROL = new ROLearner(learningProblem); + + c.ROL.start(); + //new ROLearner(); + //c.p(("ROL1"+ROL)); + + + + + + + //c.setLastResult(c.ROL.getBestSolution().toString()); + c.setLastResult(c.ROL.getBestSolution().toString()); + c.setStatus("finished"); + + }catch (Exception e) {e.printStackTrace();} + finally{active=false;}; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |