You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <jen...@us...> - 2008-02-06 16:36:39
|
Revision: 502 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=502&view=rev Author: jenslehmann Date: 2008-02-06 08:36:36 -0800 (Wed, 06 Feb 2008) Log Message: ----------- - removed KAON2 from project such that DL-Learner now builds solely upon open source libraries - direct KAON2 reasoning no longer possible (KAON2 can still be used over DIG if desired) - most of the other KAON2 functionality rewritten to OWL API, in particular KB to OWL export Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/lib/components.ini 2008-02-06 16:36:36 UTC (rev 502) @@ -8,7 +8,6 @@ org.dllearner.reasoning.OWLAPIReasoner org.dllearner.reasoning.DIGReasoner org.dllearner.reasoning.FastRetrievalReasoner -org.dllearner.reasoning.KAON2Reasoner # learning problems org.dllearner.learningproblems.PosNegDefinitionLP org.dllearner.learningproblems.PosNegInclusionLP Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-06 16:36:36 UTC (rev 502) @@ -20,7 +20,6 @@ package org.dllearner.core; -import java.io.File; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -34,8 +33,6 @@ import org.dllearner.core.dl.Individual; import org.dllearner.core.dl.RoleHierarchy; import org.dllearner.core.dl.SubsumptionHierarchy; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.KAON2Reasoner; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.SortedSetTuple; @@ -400,17 +397,6 @@ return result; } - // speichern einer Ontolgie wird speziell behandelt, da kein Reasoning - public void saveOntology(File file, OntologyFormat format) { - if (getReasonerType() == ReasonerType.KAON2) { - ((KAON2Reasoner) reasoner).saveOntology(file, format); - } else if (getReasonerType() == ReasonerType.DIG) { - // DIG erzeugt momentan auch nur einen KAON2-Reasoner und - // exportiert dann mit der obigen Funktion - ((DIGReasoner) reasoner).saveOntology(file, format); - } - } - public Set<AtomicConcept> getAtomicConcepts() { return reasoner.getAtomicConcepts(); } Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-02-06 16:36:36 UTC (rev 502) @@ -36,12 +36,20 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.KAON2Reasoner; -import org.semanticweb.kaon2.api.KAON2Exception; -import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; -import org.semanticweb.kaon2.api.reasoner.Reasoner; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyManager; +import org.semanticweb.owl.model.OWLOntologyStorageException; +import org.semanticweb.owl.model.UnknownOWLOntologyException; +import org.semanticweb.owl.util.SimpleURIMapper; /** + * KB files are an internal convenience format used in DL-Learner. Their + * syntax is close to Description Logics and easy to use. KB files can be + * exported to OWL for usage outside of DL-Learner. + * * @author Jens Lehmann * */ @@ -118,25 +126,47 @@ @Override public void export(File file, org.dllearner.core.OntologyFormat format){ - Reasoner kaon2Reasoner = KAON2Reasoner.getKAON2Reasoner(kb); - - String kaon2Format = null; - if(format.equals(org.dllearner.core.OntologyFormat.RDF_XML)) - kaon2Format = OntologyFileFormat.OWL_RDF; - else { - System.err.println("Warning: Cannot export format " + format + ". Exiting."); - System.exit(0); - } - + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + URI ontologyURI = URI.create("http://example.com"); + URI physicalURI = file.toURI(); + SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); + manager.addURIMapper(mapper); + OWLOntology ontology; try { - kaon2Reasoner.getOntology().saveOntology(kaon2Format,file,"ISO-8859-1"); - } catch (KAON2Exception e) { + ontology = manager.createOntology(ontologyURI); + OWLAPIReasoner.fillOWLAPIOntology(manager,ontology,kb); + manager.saveOntology(ontology); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block e.printStackTrace(); - } catch (IOException e) { + } catch (UnknownOWLOntologyException e) { + // TODO Auto-generated catch block e.printStackTrace(); - } catch (InterruptedException e) { + } catch (OWLOntologyStorageException e) { + // TODO Auto-generated catch block e.printStackTrace(); - } + } + + +// Reasoner kaon2Reasoner = KAON2Reasoner.getKAON2Reasoner(kb); +// +// String kaon2Format = null; +// if(format.equals(org.dllearner.core.OntologyFormat.RDF_XML)) +// kaon2Format = OntologyFileFormat.OWL_RDF; +// else { +// System.err.println("Warning: Cannot export format " + format + ". Exiting."); +// System.exit(0); +// } +// +// try { +// kaon2Reasoner.getOntology().saveOntology(kaon2Format,file,"ISO-8859-1"); +// } catch (KAON2Exception e) { +// e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } } public URL getURL() { Deleted: trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2008-02-06 16:36:36 UTC (rev 502) @@ -1,859 +0,0 @@ -package org.dllearner.reasoning; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.config.CommonConfigOptions; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.dl.All; -import org.dllearner.core.dl.AssertionalAxiom; -import org.dllearner.core.dl.AtomicConcept; -import org.dllearner.core.dl.AtomicRole; -import org.dllearner.core.dl.Bottom; -import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.ConceptAssertion; -import org.dllearner.core.dl.Conjunction; -import org.dllearner.core.dl.Disjunction; -import org.dllearner.core.dl.Equality; -import org.dllearner.core.dl.Exists; -import org.dllearner.core.dl.FunctionalRoleAxiom; -import org.dllearner.core.dl.Inclusion; -import org.dllearner.core.dl.Individual; -import org.dllearner.core.dl.InverseRoleAxiom; -import org.dllearner.core.dl.KB; -import org.dllearner.core.dl.MultiConjunction; -import org.dllearner.core.dl.MultiDisjunction; -import org.dllearner.core.dl.Negation; -import org.dllearner.core.dl.RBoxAxiom; -import org.dllearner.core.dl.RoleAssertion; -import org.dllearner.core.dl.SubRoleAxiom; -import org.dllearner.core.dl.SymmetricRoleAxiom; -import org.dllearner.core.dl.TerminologicalAxiom; -import org.dllearner.core.dl.Top; -import org.dllearner.core.dl.TransitiveRoleAxiom; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.Helper; -import org.semanticweb.kaon2.api.DefaultOntologyResolver; -import org.semanticweb.kaon2.api.KAON2Connection; -import org.semanticweb.kaon2.api.KAON2Exception; -import org.semanticweb.kaon2.api.KAON2Manager; -import org.semanticweb.kaon2.api.Ontology; -import org.semanticweb.kaon2.api.Request; -import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; -import org.semanticweb.kaon2.api.logic.Formula; -import org.semanticweb.kaon2.api.logic.Literal; -import org.semanticweb.kaon2.api.logic.QueryDefinition; -import org.semanticweb.kaon2.api.logic.Variable; -import org.semanticweb.kaon2.api.owl.axioms.ObjectPropertyAttribute; -import org.semanticweb.kaon2.api.owl.elements.Description; -import org.semanticweb.kaon2.api.owl.elements.OWLClass; -import org.semanticweb.kaon2.api.owl.elements.ObjectProperty; -import org.semanticweb.kaon2.api.reasoner.Query; -import org.semanticweb.kaon2.api.reasoner.SubsumptionHierarchy; -import org.semanticweb.kaon2.api.reasoner.SubsumptionHierarchy.Node; - -/** - * - * Subsumption-Hierarchie wird automatisch beim ersten Aufruf von getMoreGeneral|SpecialConcept - * berechnet. - * - * @author jl - * - */ -public class KAON2Reasoner extends ReasonerComponent { - - // configuration options - private boolean una = false; - - ConceptComparator conceptComparator = new ConceptComparator(); - - Set<AtomicConcept> atomicConcepts; - Set<AtomicRole> atomicRoles; - SortedSet<Individual> individuals; - SubsumptionHierarchy kaon2SubsumptionHierarchy = null; - org.dllearner.core.dl.SubsumptionHierarchy subsumptionHierarchy; - - private org.semanticweb.kaon2.api.reasoner.Reasoner kaon2Reasoner; - private KAON2Connection kaon2Connection; - - public KAON2Reasoner(KB kb, Map<URL,org.dllearner.core.OntologyFormat> imports) { - - if(imports.size()>1) - System.out.println("Warning: KAON2-Reasoner currently supports only one import file. Ignoring all other imports."); - - try { - kaon2Connection = KAON2Manager.newConnection(); - } catch (KAON2Exception e2) { - e2.printStackTrace(); - } - - DefaultOntologyResolver resolver = new DefaultOntologyResolver(); - - // Set<String> ontologyURIs = new HashSet<String>(); - String ontologyURI = ""; - URL importFile = null; - if (!imports.isEmpty()) { - // alter Code - nicht empfehlenswert, da feste URI zugewiesen wird - // resolver.registerReplacement("foo", imports.get(0).toURI().toString()); - - // neuer Code - liest Dateien richtig ein - // es ist aber noch nicht richtig klar, was bei mehreren eingelesenen - // Ontologien passieren soll - // for(File file : imports) { - // String ontologyURI = resolver.registerOntology(file); - // ontologyURIs.add(ontologyURI); - //} - - // eine beliebige Datei auswählen - importFile = imports.keySet().iterator().next(); - - try { - // System.out.println(imports.get(0)); - // resolver.r - - // TODO: testen, ob Umstellung von File auf URL funktioniert! - // ontologyURI = resolver.registerOntology(importFile); - ontologyURI = resolver.registerOntology(importFile.toString()); - - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } else { - // falls nur aus Config-Datei gelesen wird, dann wird resolver - // eigentlich nicht gebraucht => trotzdem erwartet KAON2 ein physische - // URI - // resolver.registerReplacement("foo", "file:foo.xml"); - resolver.registerReplacement("http://localhost/foo", "file:nothing.xml"); - } - - kaon2Connection.setOntologyResolver(resolver); - Ontology ontology = null; - - if (!imports.isEmpty()) { - System.out.print("Importing Ontology " + importFile.toString() + " ... "); - ontology = importKB(ontologyURI, imports.get(importFile), kaon2Connection); - } else { - try { - // ontology = connection.createOntology("foo", new - // HashMap<String, Object>()); - ontology = kaon2Connection.createOntology("http://localhost/foo", - new HashMap<String, Object>()); - } catch (KAON2Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - - // System.out.println(importedFile.getPath().toURI().toString()); - // resolver.registerReplacement("foo", "file:" + - // importedFile.getPath()); - // resolver.registerReplacement("foo", - // importedFile.toURI().toString()); - - kaon2Reasoner = getKAON2Reasoner(kb, ontology); - - // Individuals, Concepts und Roles aus Wissensbasis auslesen - Request<ObjectProperty> requestRoles = ontology - .createEntityRequest(ObjectProperty.class); - Request<OWLClass> requestConcepts = ontology.createEntityRequest(OWLClass.class); - Request<org.semanticweb.kaon2.api.owl.elements.Individual> requestIndividuals = ontology - .createEntityRequest(org.semanticweb.kaon2.api.owl.elements.Individual.class); - - atomicConcepts = new HashSet<AtomicConcept>(); - atomicRoles = new HashSet<AtomicRole>(); - individuals = new TreeSet<Individual>(); - - try { - for (ObjectProperty role : requestRoles.get()) { - atomicRoles.add(new AtomicRole(role.toString())); - // getRole(role.toString()); - } - - for (OWLClass concept : requestConcepts.get()) { - // Top und Bottom sind bei mir keine atomaren Konzepte, sondern - // werden - // extra behandelt - if (!concept.equals(KAON2Manager.factory().thing()) - && !concept.equals(KAON2Manager.factory().nothing())) - atomicConcepts.add(new AtomicConcept(concept.toString())); - // System.out.println(concept.toString()); - } - for (org.semanticweb.kaon2.api.owl.elements.Individual ind : requestIndividuals.get()) { - // getIndividual(ind.toString()); - individuals.add(new Individual(ind.toString())); - } - - // je nachdem, ob unique names assumption aktiviert ist, muss - // man jetzt noch hinzuf�gen, dass die Individuen verschieden sind - if (una) { - Set<org.semanticweb.kaon2.api.owl.elements.Individual> individualsSet = new HashSet<org.semanticweb.kaon2.api.owl.elements.Individual>(); - for (Individual individual : individuals) - individualsSet.add(KAON2Manager.factory().individual(individual.getName())); - ontology.addAxiom(KAON2Manager.factory().differentIndividuals( - individualsSet)); - } - - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - // wandelt einen Bezeichner in eine URI für die interne KB - // (http://localhost/foo) um; - // die Umwandlungen machen KAON2 noch langsamer, aber sie sind notwendig - // für eine korrekte Ontologie, die wiederum für den Export wichtig ist; - // es wird einfach gesagt, dass alles was nicht mit "http://" beginnt ein - // interner Bezeichner ist; - // eine sauberere Lösung wäre für die internen Sachen auch immer eine URI - // zu fordern bzw. eine ähnliche Heuristik wie hier schon beim parsen zu - // verwenden; für DIG ist das allerdings nicht notwendig (basiert auf DLs, - // also benötigt keine URIs) und erfordert relativ umfangreiche Änderungen - // => es wird jetzt doch die saubere Lösung verwendet - /* - private String getInternalURI(String name) { - if(name.startsWith("http://")) - return name; - else - return internalNamespace + name; - } - - // wandelt eine lokal vergebene URI in einen Bezeichner um - private String getNameFromInternalURI(String uri) { - if(uri.startsWith(internalNamespace)) - return uri.substring(internalNamespace.length()); - else - return uri; - } - */ - - public static String getName() { - return "KAON2 reasoner"; - } - - // TODO: hier werden momentan keine allowed concepts berücksichtigt - // (benötigt rekursive Aufrufe, da ein erlaubtes Konzept von einem nicht - // erlaubten verdeckt werden könnte) - public void prepareSubsumptionHierarchy(Set<AtomicConcept> allowedConcepts) { - try { - kaon2SubsumptionHierarchy = kaon2Reasoner.getSubsumptionHierarchy(); - } catch (KAON2Exception e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - // umwandeln in eine für die Lernalgorithmen verwertbare - // Subsumptionhierarchie - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyUp = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - TreeMap<Concept,TreeSet<Concept>> subsumptionHierarchyDown = new TreeMap<Concept,TreeSet<Concept>>(conceptComparator); - - Top top = new Top(); - OWLClass kaon2Top = KAON2Manager.factory().thing(); - subsumptionHierarchyDown.put(top, (TreeSet<Concept>) getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor(kaon2Top).getChildNodes())); - // subsumptionHierarchyUp.put(top, new TreeSet<Concept>(conceptComparator)); - - Bottom bottom = new Bottom(); - OWLClass kaon2Bottom = KAON2Manager.factory().nothing(); - subsumptionHierarchyUp.put(bottom, (TreeSet<Concept>) getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor(kaon2Bottom).getParentNodes())); - // subsumptionHierarchyDown.put(bottom, new TreeSet<Concept>(conceptComparator)); - - for(AtomicConcept ac : atomicConcepts) { - OWLClass kaon2Ac = (OWLClass) getKAON2Description(ac); - subsumptionHierarchyDown.put(ac, (TreeSet<Concept>) getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor(kaon2Ac).getChildNodes())); - subsumptionHierarchyUp.put(ac, (TreeSet<Concept>) getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor(kaon2Ac).getParentNodes())); - } - - subsumptionHierarchy = new org.dllearner.core.dl.SubsumptionHierarchy(atomicConcepts, subsumptionHierarchyUp, subsumptionHierarchyDown); - } - - @Override - public SortedSet<Individual> retrieval(Concept c) { - SortedSet<Individual> result = new TreeSet<Individual>(); - Description d = getKAON2Description(c); - - Query query = null; - try { - query = kaon2Reasoner.createQuery(d); - query.open(); - while (!query.afterLast()) { - // tupleBuffer = query.tupleBuffer(); - String individual = query.tupleBuffer()[0].toString(); - result.add(new Individual(individual)); - query.next(); - } - query.close(); - query.dispose(); - } catch (KAON2Exception e) { - e.printStackTrace(); - System.exit(0); - } catch (InterruptedException e) { - e.printStackTrace(); - System.exit(0); - } - return result; - } - - public boolean instanceCheck(Concept c, String s) { - boolean result; - - Description d = getKAON2Description(c); - // ev. Aufruf Main.getIndividual g�nstiger?? - org.semanticweb.kaon2.api.owl.elements.Individual i = KAON2Manager.factory().individual(s); - - // Individual i = Main.getIndividual(s); - // ClassMember cm = KAON2Manager.factory().classMember(d, i); - // Formula f = KAON2Manager.factory().classMember(d,i); - // Constant constant = KAON2Manager.factory().constant(i); - // Predicate predicate = KAON2Manager.factory().p - Literal l = KAON2Manager.factory().literal(true, d, i); - // Formula f = KAON2Manager.factory(). - - // TODO: mal mit Boris abkl�ren wie der Instance-Check - // gemacht werden soll; eine Formel zu erstellen erscheint - // mir ziemlich umst�ndlich und ist mir auch nicht ganz - // klar wie das gemacht wird - - QueryDefinition qd = KAON2Manager.factory().queryDefinition(l, new Variable[] {}); - - // kaon2Reasoner.createQuery(l, new Variable[] { }); - // Query q; - result = true; - try { - Query query = kaon2Reasoner.createQuery(qd); - query.open(); - if (query.afterLast()) - result = false; - query.close(); - query.dispose(); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return result; - } - - @Override - public boolean subsumes(Concept superConcept, Concept subConcept) { - Description d1 = getKAON2Description(superConcept); - Description d2 = getKAON2Description(subConcept); - try { - return kaon2Reasoner.subsumedBy(d2, d1); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - throw new Error("Subsumption Error in KAON2."); - } - - @Override - public boolean isSatisfiable() { - try { - return kaon2Reasoner.isSatisfiable(); - } catch (KAON2Exception e1) { - e1.printStackTrace(); - } catch (InterruptedException e2) { - e2.printStackTrace(); - } - throw new Error("Error in satisfiability check in KAON2."); - } - - /* - private SortedSet<Concept> getMoreGeneralConcepts(Concept concept) { - // if (subsumptionHierarchy == null) { - // computeSubsumptionHierarchy(); - // } - - Description d = getKAON2Description(concept); - if(!(d instanceof OWLClass)) { - System.out.println("description: " + d); - System.out.println("concept:" + concept); - } - OWLClass owlClass = (OWLClass) d; - return getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor( - owlClass).getParentNodes()); - } - - private SortedSet<Concept> getMoreSpecialConcepts(Concept concept) { - // if (subsumptionHierarchy == null) { - // computeSubsumptionHierarchy(); - // } - - OWLClass owlClass = (OWLClass) getKAON2Description(concept); - return getConceptsFromSubsumptionHierarchyNodes(kaon2SubsumptionHierarchy.getNodeFor( - owlClass).getChildNodes()); - } - */ - - @Override - public org.dllearner.core.dl.SubsumptionHierarchy getSubsumptionHierarchy() { - return subsumptionHierarchy; - } - - private SortedSet<Concept> getConceptsFromSubsumptionHierarchyNodes(Set<Node> nodes) { - SortedSet<Concept> ret = new TreeSet<Concept>(conceptComparator); - for (Node node : nodes) { - // es wird nur das erste Konzept unter mehreren �quivalenten - // beachtet - Iterator<OWLClass> it = node.getOWLClasses().iterator(); - ret.add(getConcept(it.next())); - if (node.getOWLClasses().size() > 1) - System.out - .println("Warning: Ontology contains equivalent classes. Only one" - + "representative of each equivalence class is used for learning. The others" - + "are ignored."); - } - return ret; - } - - public Concept getConcept(Description description) { - if (description.equals(KAON2Manager.factory().thing())) { - return new Top(); - } else if (description.equals(KAON2Manager.factory().nothing())) { - return new Bottom(); - } else if (description instanceof OWLClass) { - return new AtomicConcept(description.toString()); - } else { - throw new Error("Transforming complex KAON2 descriptions not supported."); - } - } - - @Override - public Map<org.dllearner.core.dl.Individual, SortedSet<org.dllearner.core.dl.Individual>> getRoleMembers(AtomicRole atomicRole) { - Map<org.dllearner.core.dl.Individual, SortedSet<org.dllearner.core.dl.Individual>> returnMap = new TreeMap<org.dllearner.core.dl.Individual, SortedSet<org.dllearner.core.dl.Individual>>(); - - Query query; - Object[] tupleBuffer; - ObjectProperty role = KAON2Manager.factory().objectProperty(atomicRole.getName()); - // positiver Query - try { - query = kaon2Reasoner.createQuery(role); - - query.open(); - while (!query.afterLast()) { - tupleBuffer = query.tupleBuffer(); - org.dllearner.core.dl.Individual individual1 = new org.dllearner.core.dl.Individual(tupleBuffer[0].toString()); - org.dllearner.core.dl.Individual individual2 = new org.dllearner.core.dl.Individual(tupleBuffer[1].toString()); - // addIndividualToRole(aBox.rolesPos, name, individual1, - // individual2); - Helper.addMapEntry(returnMap, individual1, individual2); - query.next(); - } - query.close(); - query.dispose(); - } catch (KAON2Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return returnMap; - } - - public void saveOntology(File file, org.dllearner.core.OntologyFormat format) { - // File exportFile = new File(baseDir, fileName); - // String format = OntologyFileFormat.OWL_RDF; - String kaon2Format = null; - if(format.equals(org.dllearner.core.OntologyFormat.RDF_XML)) - kaon2Format = OntologyFileFormat.OWL_RDF; - else { - System.err.println("Warning: Cannot export format " + format + ". Exiting."); - System.exit(0); - } - - try { - kaon2Reasoner.getOntology().saveOntology(kaon2Format,file,"ISO-8859-1"); - } catch (KAON2Exception e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public static Ontology importKB(File importFile) { - - Ontology ontology = null; - try { - System.out.print("Importing " + importFile + " ... "); - long importStartTime = System.currentTimeMillis(); - - // TODO: hier wird Ontologie richtig importiert; dass muss im - // Konstruktor eventuell entsprechend angepasst werden - DefaultOntologyResolver resolver = new DefaultOntologyResolver(); - String ontologyURI = resolver.registerOntology(importFile); - KAON2Connection connection = KAON2Manager.newConnection(); - connection.setOntologyResolver(resolver); - ontology = connection.openOntology(ontologyURI, new HashMap<String,Object>()); - long importDuration = System.currentTimeMillis() - importStartTime; - System.out.println("OK (" + importDuration + " ms) [ontology URI " + ontologyURI + "]"); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ontology; - } - - private static Ontology importKB(String ontologyURI, org.dllearner.core.OntologyFormat format, KAON2Connection connection) { - Ontology ontology = null; - try { - long importStartTime = System.currentTimeMillis(); - ontology = connection.openOntology(ontologyURI, new HashMap<String, Object>()); - long importDuration = System.currentTimeMillis() - importStartTime; - System.out.println("OK (" + importDuration + " ms)"); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ontology; - } - - // Umwandlung eines Konzepts in eigener Darstellung zu einem - // KAON2-Konzept (hat die st�ndige Umwandlung eine gro�e Auswirkung - // auf die Effizienz? - es m�ssen zumindest h�ufig neue Konzepte - // erzeugt werden) - public static Description getKAON2Description(Concept concept) { - if (concept instanceof AtomicConcept) { - return KAON2Manager.factory().owlClass(((AtomicConcept) concept).getName()); - } else if (concept instanceof Bottom) { - return KAON2Manager.factory().nothing(); - } else if (concept instanceof Top) { - return KAON2Manager.factory().thing(); - } else if (concept instanceof Negation) { - return KAON2Manager.factory().objectNot( - getKAON2Description(concept.getChild(0))); - } else if (concept instanceof Conjunction) { - Description d1 = getKAON2Description(concept.getChild(0)); - Description d2 = getKAON2Description(concept.getChild(1)); - return KAON2Manager.factory().objectAnd(d1, d2); - } else if (concept instanceof Disjunction) { - Description d1 = getKAON2Description(concept.getChild(0)); - Description d2 = getKAON2Description(concept.getChild(1)); - return KAON2Manager.factory().objectOr(d1, d2); - } else if (concept instanceof All) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((All) concept).getRole().getName()); - Description d = getKAON2Description(concept.getChild(0)); - return KAON2Manager.factory().objectAll(role, d); - } else if(concept instanceof Exists) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((Exists) concept).getRole().getName()); - Description d = getKAON2Description(concept.getChild(0)); - return KAON2Manager.factory().objectSome(role, d); - } else if(concept instanceof MultiConjunction) { - List<Description> descriptions = new LinkedList<Description>(); - for(Concept child : concept.getChildren()) { - descriptions.add(getKAON2Description(child)); - } - return KAON2Manager.factory().objectAnd(descriptions); - } else if(concept instanceof MultiDisjunction) { - List<Description> descriptions = new LinkedList<Description>(); - for(Concept child : concept.getChildren()) { - descriptions.add(getKAON2Description(child)); - } - return KAON2Manager.factory().objectOr(descriptions); - } - - throw new IllegalArgumentException("Unsupported concept type."); - } - - public static org.semanticweb.kaon2.api.reasoner.Reasoner getKAON2Reasoner(KB kb) { - try { - KAON2Connection connection = KAON2Manager.newConnection(); - - DefaultOntologyResolver resolver = new DefaultOntologyResolver(); - resolver.registerReplacement("http://localhost/foo", "file:nothing.xml"); - connection.setOntologyResolver(resolver); - Ontology ontology = connection.createOntology("http://localhost/foo", - new HashMap<String, Object>()); - return getKAON2Reasoner(kb, ontology); - - } catch (KAON2Exception e) { - e.printStackTrace(); - return null; - } - } - - private static org.semanticweb.kaon2.api.reasoner.Reasoner getKAON2Reasoner(KB kb, - Ontology ontology) { - - org.semanticweb.kaon2.api.reasoner.Reasoner reasoner = null; - - try { - - for (AssertionalAxiom axiom : kb.getAbox()) { - if (axiom instanceof ConceptAssertion) { - Description d = getKAON2Description(((ConceptAssertion) axiom) - .getConcept()); - // TODO: checken ob unterschiedliche Objekte - // unterschiedliche - // Individuen sind, auch wenn sie den gleichen Namen haben - org.semanticweb.kaon2.api.owl.elements.Individual i = KAON2Manager.factory().individual( - ((ConceptAssertion) axiom).getIndividual().getName()); - ontology.addAxiom(KAON2Manager.factory().classMember(d, i)); - } else if (axiom instanceof RoleAssertion) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((RoleAssertion) axiom).getRole().getName()); - org.semanticweb.kaon2.api.owl.elements.Individual i1 = KAON2Manager.factory().individual( - ((RoleAssertion) axiom).getIndividual1().getName()); - org.semanticweb.kaon2.api.owl.elements.Individual i2 = KAON2Manager.factory().individual( - ((RoleAssertion) axiom).getIndividual2().getName()); - // Code zur Unterst�tzung negierter Rollenzusicherungen, - // falls sp�ter ben�tigt - // Literal l = KAON2Manager.factory().literal(true, role, - // i1, i2); - // Rule r = KAON2Manager.factory().rule(new Formula[] {}, - // true, new Formula[] { l }); - // changes.add(new OntologyChangeEvent(r, - // OntologyChangeEvent.ChangeType.ADD)); - ontology.addAxiom(KAON2Manager.factory().objectPropertyMember(role, - i1, i2)); - } - } - - for (RBoxAxiom axiom : kb.getRbox()) { - if (axiom instanceof FunctionalRoleAxiom) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((FunctionalRoleAxiom) axiom).getRole().getName()); - ontology.addAxiom(KAON2Manager.factory().objectPropertyAttribute( - role, ObjectPropertyAttribute.OBJECT_PROPERTY_FUNCTIONAL)); - } else if (axiom instanceof SymmetricRoleAxiom) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((SymmetricRoleAxiom) axiom).getRole().getName()); - ontology.addAxiom(KAON2Manager.factory().objectPropertyAttribute( - role, ObjectPropertyAttribute.OBJECT_PROPERTY_SYMMETRIC)); - - // alternative Implementierung ohne Hilfskonstrukt - //ObjectProperty inverseRole = KAON2Manager.factory().objectProperty( - // ((SymmetricRoleAxiom) axiom).getRole().getName()); - //ontology.addAxiom(KAON2Manager.factory().inverseObjectProperties( - // role, inverseRole)); - //ontology.addAxiom(KAON2Manager.factory().equivalentObjectProperties(role, - // inverseRole)); - } else if (axiom instanceof TransitiveRoleAxiom) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((SymmetricRoleAxiom) axiom).getRole().getName()); - ontology.addAxiom(KAON2Manager.factory().objectPropertyAttribute( - role, ObjectPropertyAttribute.OBJECT_PROPERTY_TRANSITIVE)); - } else if (axiom instanceof InverseRoleAxiom) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((InverseRoleAxiom) axiom).getRole().getName()); - ObjectProperty inverseRole = KAON2Manager.factory().objectProperty( - ((InverseRoleAxiom) axiom).getInverseRole().getName()); - ontology.addAxiom(KAON2Manager.factory().inverseObjectProperties( - role, inverseRole)); - } else if (axiom instanceof SubRoleAxiom) { - ObjectProperty role = KAON2Manager.factory().objectProperty( - ((SubRoleAxiom) axiom).getRole().getName()); - ObjectProperty subRole = KAON2Manager.factory().objectProperty( - ((SubRoleAxiom) axiom).getSubRole().getName()); - ontology.addAxiom(KAON2Manager.factory().subObjectPropertyOf(subRole, - role)); - } - } - - for (TerminologicalAxiom axiom : kb.getTbox()) { - if (axiom instanceof Equality) { - Description d1 = getKAON2Description(((Equality) axiom).getConcept1()); - Description d2 = getKAON2Description(((Equality) axiom).getConcept2()); - ontology.addAxiom(KAON2Manager.factory().equivalentClasses(d1, d2)); - } else if (axiom instanceof Inclusion) { - Description subConcept = getKAON2Description(((Inclusion) axiom) - .getSubConcept()); - Description superConcept = getKAON2Description(((Inclusion) axiom) - .getSuperConcept()); - ontology.addAxiom(KAON2Manager.factory().subClassOf(subConcept, - superConcept)); - } - } - - // ontology.applyChanges(changes); - reasoner = ontology.createReasoner(); - } catch (KAON2Exception e) { - e.printStackTrace(); - System.out.println(e); - } - - return reasoner; - } - - public Map<String, SortedSet<String>> getNegatedRoleMembers(AtomicRole atomicRole) { - Map<String, SortedSet<String>> returnMap = new TreeMap<String, SortedSet<String>>(); - - Query query; - Object[] tupleBuffer; - ObjectProperty role = KAON2Manager.factory().objectProperty(atomicRole.getName()); - // negativer Query - // wird �ber Rule-ML gemacht - Variable X = KAON2Manager.factory().variable("X"); - Variable Y = KAON2Manager.factory().variable("Y"); - // ObjectProperty role = roles.get(name); - Literal l = KAON2Manager.factory().literal(true, role, X, Y); - Formula f = null; - - // falls closed world assumption, dann reicht default negation -// if (Config.owa) - // wegen BUG IN KAON2 momentan auskommentiert - // f = KAON2Manager.factory().classicalNegation(l); -// ; -// else - f = KAON2Manager.factory().defaultNegation(l); - - // if-Teil entf�llt, sobald Bug in KAON2 gefixt wurde -// if (!Config.owa) { - // ClassicalNegation cn = - // KAON2Manager.factory().classicalNegation(l); - try { - query = kaon2Reasoner.createQuery(f, new Variable[] { X, Y }, null, null); - - // BUG IN KAON2, DESWEGEN AUSKOMMENTIERT - - // System.out.println(); - query.open(); - while (!query.afterLast()) { - tupleBuffer = query.tupleBuffer(); - String individual1 = tupleBuffer[0].toString(); - String individual2 = tupleBuffer[1].toString(); - // addIndividualToRole(aBox.rolesNeg, name, - // individual1,individual2); - System.out.println(atomicRole.getName() + " " + individual1 + " " - + individual2); - query.next(); - } - query.close(); - query.dispose(); - } catch (KAON2Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// } - - return returnMap; - } - - public void terminateReasoner() { - kaon2Reasoner.dispose(); - try { - kaon2Connection.close(); - } catch (KAON2Exception e) { - e.printStackTrace(); - } - } - - public ReasonerType getReasonerType() { - return ReasonerType.KAON2; - } - - public Set<AtomicConcept> getAtomicConcepts() { - return atomicConcepts; - } - - public Set<AtomicRole> getAtomicRoles() { - return atomicRoles; - } - - public SortedSet<Individual> getIndividuals() { - return individuals; - } - - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(CommonConfigOptions.getUNA()); - return options; - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if(name.equals("una")) - una = (Boolean) entry.getValue(); - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - // TODO Auto-generated method stub - - } - - // Problem: mit den eigenen Datenstrukturen wird OWL nicht vollständig - // abgedeckt z.B. data types, d.h. ohne Erweiterung der internen Strukturen - // kann nicht jede KAON2-Ontologie importiert werden - // TODO: unvollständig - /* - public static void importKAON2Ontology(KB kb, Ontology ontology) throws KAON2Exception { - Set<Axiom> axioms = ontology.createAxiomRequest().getAll(); - - // KB kb = new KB(); - for(Axiom axiom : axioms) { - if(axiom instanceof ClassMember) { - String individual = ((ClassMember)axiom).getIndividual().toString(); - Concept concept = importKAON2Concept(((ClassMember)axiom).getDescription()); - ConceptAssertion ca = new ConceptAssertion(concept, individual); - kb.addABoxAxiom(ca); - // da es eine externe API ist, können wir nicht sicher sein alle - // Axiome erwischt zu haben - } else { - throw new RuntimeException("Failed to import the following axiom: " + axiom); - } - } - } - */ - - // TODO: unvollständig - /* - private static Concept importKAON2Concept(Description description) { - if (description.equals(KAON2Manager.factory().thing())) { - return new Top(); - } else if (description.equals(KAON2Manager.factory().nothing())) { - return new Bottom(); - } else if (description instanceof OWLClass) { - return new AtomicConcept(description.toString()); - } else { - throw new RuntimeException("Failed to convert the following KAON2 description: " + description); - } - } - */ - - -} Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-06 16:36:36 UTC (rev 502) @@ -38,26 +38,41 @@ import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.dl.All; +import org.dllearner.core.dl.AssertionalAxiom; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Bottom; import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.ConceptAssertion; import org.dllearner.core.dl.Conjunction; import org.dllearner.core.dl.Disjunction; +import org.dllearner.core.dl.Equality; import org.dllearner.core.dl.Exists; +import org.dllearner.core.dl.FunctionalRoleAxiom; +import org.dllearner.core.dl.Inclusion; import org.dllearner.core.dl.Individual; +import org.dllearner.core.dl.InverseRoleAxiom; +import org.dllearner.core.dl.KB; import org.dllearner.core.dl.MultiConjunction; import org.dllearner.core.dl.MultiDisjunction; import org.dllearner.core.dl.Negation; +import org.dllearner.core.dl.RBoxAxiom; +import org.dllearner.core.dl.RoleAssertion; import org.dllearner.core.dl.RoleHierarchy; +import org.dllearner.core.dl.SubRoleAxiom; import org.dllearner.core.dl.SubsumptionHierarchy; +import org.dllearner.core.dl.SymmetricRoleAxiom; +import org.dllearner.core.dl.TerminologicalAxiom; import org.dllearner.core.dl.Top; +import org.dllearner.core.dl.TransitiveRoleAxiom; import org.dllearner.kb.OWLFile; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.RoleComparator; import org.semanticweb.owl.apibinding.OWLManager; import org.semanticweb.owl.inference.OWLReasoner; import org.semanticweb.owl.inference.OWLReasonerException; +import org.semanticweb.owl.model.AddAxiom; +import org.semanticweb.owl.model.OWLAxiom; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLDataFactory; import org.semanticweb.owl.model.OWLDescription; @@ -65,6 +80,7 @@ import org.semanticweb.owl.model.OWLNamedObject; import org.semanticweb.owl.model.OWLObjectProperty; import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyCreationException; import org.semanticweb.owl.model.OWLOntologyManager; @@ -85,6 +101,8 @@ private OWLReasoner reasoner; // the data factory is used to generate OWL API objects private OWLDataFactory factory; + // static factory + private static OWLDataFactory staticFactory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); private ConceptComparator conceptComparator = new ConceptComparator(); private RoleComparator roleComparator = new RoleComparator(); @@ -503,19 +521,19 @@ return new AtomicConcept(owlClass.getURI().toString()); } - public OWLObjectProperty getOWLAPIDescription(AtomicRole role) { - return factory.getOWLObjectProperty(URI.create(role.getName())); + public static OWLObjectProperty getOWLAPIDescription(AtomicRole role) { + return staticFactory.getOWLObjectProperty(URI.create(role.getName())); } - public OWLDescription getOWLAPIDescription(Concept concept) { + public static OWLDescription getOWLAPIDescription(Concept concept) { if (concept instanceof AtomicConcept) { - return factory.getOWLClass(URI.create(((AtomicConcept)concept).getName())); + return staticFactory.getOWLClass(URI.create(((AtomicConcept)concept).getName())); } else if (concept instanceof Bottom) { - return factory.getOWLNothing(); + return staticFactory.getOWLNothing(); } else if (concept instanceof Top) { - return factory.getOWLThing(); + return staticFactory.getOWLThing(); } else if (concept instanceof Negation) { - return factory.getOWLObjectComplementOf( + return staticFactory.getOWLObjectComplementOf( getOWLAPIDescription(concept.getChild(0))); } else if (concept instanceof Conjunction) { OWLDescription d1 = getOWLAPIDescription(concept.getChild(0)); @@ -523,39 +541,133 @@ Set<OWLDescription> d = new HashSet<OWLDescription>(); d.add(d1); d.add(d2); - return factory.getOWLObjectIntersectionOf(d); + return staticFactory.getOWLObjectIntersectionOf(d); } else if (concept instanceof Disjunction) { OWLDescription d1 = getOWLAPIDescription(concept.getChild(0)); OWLDescription d2 = getOWLAPIDescription(concept.getChild(1)); Set<OWLDescription> d = new HashSet<OWLDescription>(); d.add(d1); d.add(d2); - return factory.getOWLObjectUnionOf(d); + return staticFactory.getOWLObjectUnionOf(d); } else if (concept instanceof All) { - OWLObjectProperty role = factory.getOWLObjectProperty( + OWLObjectProperty role = staticFactory.getOWLObjectProperty( URI.create(((All) concept).getRole().getName())); OWLDescription d = getOWLAPIDescription(concept.getChild(0)); - return factory.getOWLObjectAllRestriction(role, d); + return staticFactory.getOWLObjectAllRestriction(role, d); } else if(concept instanceof Exists) { - OWLObjectProperty role = factory.getOWLObjectProperty( + OWLObjectProperty role = staticFactory.getOWLObjectProperty( URI.create(((Exists) concept).getRole().getName())); OWLDescription d = getOWLAPIDescription(concept.getChild(0)); - return factory.getOWLObjectSomeRestriction(role, d); + return staticFactory.getOWLObjectSomeRestriction(role, d); } else if(concept instanceof MultiConjunction) { Set<OWLDescription> descriptions = new HashSet<OWLDescription>(); for(Concept child : concept.getChildren()) descriptions.add(getOWLAPIDescription(child)); - return factory.getOWLObjectIntersectionOf(descriptions); + return staticFactory.getOWLObjectIntersectionOf(descriptions); } else if(concept instanceof MultiDisjunction) { Set<OWLDescription> descriptions = new HashSet<OWLDescription>(); for(Concept child : concept.getChildren()) descriptions.add(getOWLAPIDescription(child)); - return factory.getOWLObjectUnionOf(descriptions); + return staticFactory.getOWLObjectUnionOf(descriptions); } throw new IllegalArgumentException("Unsupported concept type."); } + public static void fillOWLAPIOntology(OWLOntologyManager manager, OWLOntology ontology, KB kb) { + + // OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + // OWLOntology ontology = manager.createOntology(ontologyURI); + try { + for (AssertionalAxiom axiom : kb.getAbox()) { + if (axiom instanceof ConceptAssertion) { + OWLDescription d = getOWLAPIDescription(((ConceptAssertion) axiom) + .getConcept()); + OWLIndividual i = factory.getOWLIndividual(URI.create( + ((ConceptAssertion) axiom).getIndividual().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLClassAssertionAxiom(i, d); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + + manager.applyChange(addAxiom); + + } else if (axiom instanceof RoleAssertion) { + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((RoleAssertion) axiom).getRole().getName())); + OWLIndividual i1 = factory.getOWLIndividual( + URI.create(((RoleAssertion) axiom).getIndividual1().getName())); + OWLIndividual i2 = factory.getOWLIndividual( + URI.create(((RoleAssertion) axiom).getIndividual2().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLObjectPropertyAssertionAxiom(i1, role, i2); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } + } + + for (RBoxAxiom axiom : kb.getRbox()) { + if (axiom instanceof FunctionalRoleAxiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((FunctionalRoleAxiom) axiom).getRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLFunctionalObjectPropertyAxiom(role); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } else if (axiom instanceof SymmetricRoleAxiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((SymmetricRoleAxiom) axiom).getRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLSymmetricObjectPropertyAxiom(role); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } else if (axiom instanceof TransitiveRoleAxiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((SymmetricRoleAxiom) axiom).getRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLTransitiveObjectPropertyAxiom(role); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } else if (axiom instanceof InverseRoleAxiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((InverseRoleAxiom) axiom).getRole().getName())); + OWLObjectProperty inverseRole = factory.getOWLObjectProperty( + URI.create(((InverseRoleAxiom) axiom).getInverseRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLInverseObjectPropertiesAxiom(role, inverseRole); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } else if (axiom instanceof SubRoleAxiom) { + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((SubRoleAxiom) axiom).getRole().getName())); + OWLObjectProperty subRole = factory.getOWLObjectProperty( + URI.create(((SubRoleAxiom) axiom).getSubRole().getName())); + OWLAxiom axiomOWLAPI = factory.getOWLSubObjectPropertyAxiom(subRole, role); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } + } + + for (TerminologicalAxiom axiom : kb.getTbox()) { + if (axiom instanceof Equality) { + OWLDescription d1 = getOWLAPIDescription(((Equality) axiom).getConcept1()); + OWLDescription d2 = getOWLAPIDescription(((Equality) axiom).getConcept2()); + Set<OWLDescription> ds = new HashSet<OWLDescription>(); + ds.add(d1); + ds.add(d2); + OWLAxiom axiomOWLAPI = factory.getOWLEquivalentClassesAxiom(ds); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } else if (axiom instanceof Inclusion) { + OWLDescription subConcept = getOWLAPIDescription(((Inclusion) axiom) + .getSubConcept()); + OWLDescription superConcept = getOWLAPIDescription(((Inclusion) axiom) + .getSuperConcept()); + OWLAxiom axiomOWLAPI = factory.getOWLSubClassAxiom(subConcept, superConcept); + AddAxiom addAxiom = new AddAxiom(ontology, axiomOWLAPI); + manager.applyChange(addAxiom); + } + } + } catch (OWLOntologyChangeException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** * Test * Modified: trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-06 16:36:36 UTC (rev 502) @@ -25,7 +25,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; -import java.util.TreeSet; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; Modified: trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java 2008-02-06 15:24:06 UTC (rev 501) +++ trunk/src/dl-learner/org/dllearner/utilities/OntologyClassRewriter.java 2008-02-06 16:36:36 UTC (rev 502) @@ -1,27 +1,51 @@ +/** + * Copyright (C) 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/>. + * + */ + package org.dllearner.utilities; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; -import java.util.HashMap; -import java.util.Set; import org.dllearner.core.dl.Concept; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; -import org.dllearner.reasoning.KAON2Reasoner; -import org.semanticweb.kaon2.api.DefaultOntologyResolver; -import org.semanticweb.kaon2.api.KAON2Connection; -import org.semanticweb.kaon2.api.KAON2Exception; -import org.semanticweb.kaon2.api.KAON2Manager; -import org.semanticweb.kaon2.api.Ontology; -import org.semanticweb.kaon2.api.Request; -import org.semanticweb.kaon2.api.formatting.OntologyFileFormat; -import org.semanticweb.kaon2.api.owl.axioms.EquivalentClasses; -import org.semanticweb.kaon2.api.owl.elements.Description; -import org.semanticweb.kaon2.api.owl.elements.OWLClass; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLClass; +import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyManager; +/** + * Utility class to replace a definition in an OWL file by a learned + * definition. + * + * TODO: Class is currently not working. There is still some KAON2 specific + * code (commented out), which has to be converted to OWL API code. + * + * @author Jens Lehmann + * + */ public class OntologyClassRewriter { public static void main(String[] args) { @@ -37,6 +61,7 @@ System.out.println(rewrittenOntology); } + @SuppressWarnings({"unused"}) public static String rewriteOntology(String urlString, String className, String newConceptString) { try { @@ -45,44 +70,54 @@ Concept newConceptInternal = KBParser.parseConcept(newConceptString); // umwandeln in interne KAON2-Darstellung (bereits im DL-Learner implementiert) - Description newConceptKAON2 = KAON2Reasoner.getKAON2Description(newConceptInternal); + // Description newConceptKAON2 = KAON2Reasoner.getKAON2Description(newConceptInternal); + OWLDescription newConceptOWLAPI = OWLAPIReasoner.getOWLAPIDescription(newConceptInternal); // Umwandlung Klassenname in atomate KAON2-Klasse - OWLClass classKAON2 = KAON2Manager.factory().owlClass(className); + // OWLClass classKAON2 = KAON2Manager.factory().owlClass(className); + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLDataFactory factory = manager.getOWLDataFactory(); + OWLClass classOWLAPI = factory.getOWLClass(URI.create(className)); // Test, ob es eine richtige URL ist (ansonsten wird Exception geworfen) new URL(urlString); // einlesen der Ontologie - DefaultOntologyResolver resolver = new DefaultOntologyResolver(); - KAON2Connection connection = KAON2Manager.newConnection(); - connection.setOntologyResolver(resolver); - Ontology ontology = connection.openOntology(urlString, new HashMap<String,Object>()); + // DefaultOntologyResolver resolver = new DefaultOntologyResolver(); + // KAON2Connection connection = KAON2Manager.newConnection(); + // connection.setOntologyResolver(resolver); + // Ontology ontology = connection.openOntology(urlString, new HashMap<String,Object>()); - // suchen von Äquivalenzaxiomen - Request<EquivalentClasses> equivalenceAxiomsRequest = ontology.createAxiomRequest(EquivalentClasses.class); - Set<EquivalentClasses> equivalenceAxioms = equivalenceAxiomsRequest.get(); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(URI.create(urlString)); - for(EquivalentClasses eq : equivalenceAxioms) { - Set<Description> eqDescriptions = eq.getDescriptions(); - if(eqDescriptions.size() != 2) - System.out.println("Warning: Rewriting more than two equivalent descriptions not supported yet." + - " Possibly incorrect ontology returned."); - - // entfernen aller Äquivalenzaxiome, die die Klasse enthalten - if(eqDescriptions.contains(classKAON2)) - ontology.removeAxiom(eq); - } + // TODO - // hinzufügen des neuen Äquivalenzaxioms - EquivalentClasses eqNew = KAON2Manager.factory().equivalentClasses(classKAON2, newConceptKAON2); - ontology.addAxiom(eqNew); + // suchen von Äquivalenzaxiomen +// Request<EquivalentClasses> equivalenceAxiomsRequest = ontology.createAxiomRequest(EquivalentClasses.class); +// Set<EquivalentClasses> equivalenceAxioms = equivalenceAxiomsRequest.get(); +// +// for(EquivalentClasses eq : equivalenceAxioms) { +// Set<Description> eqDescriptions = eq.getDescriptions(); +// if(eqDescriptions.size() != 2) +// System.out.println("Warning: Rewriting more than two equivalent descriptions not supported yet." + +// " Possibly incorrect ontology returned."); +// +// // entfernen aller Äquivalenzaxiome, die die Klasse enthalten +// if(eqDescriptions.contains(classKAON2)) +// ontology.removeAxiom(eq); +// } +// +// // hinzufügen des neuen Äquivalenzaxioms +// EquivalentClasses eqNew = KAON2Manager.factory().equivalentClasses(classKAON2, newConceptKAON2); +// ontology.addAxiom(eqNew); +// +// // umwandeln der Ontologie in einen String +// ByteArrayOutputStream os = new ByteArrayOutputStream(); +// ontology.saveOntology(OntologyFileFormat.OWL_RDF,os,"ISO-8859-1"); +// +// return os.toString(); + return ""; - // umwandeln der Ontologie in einen String - ByteArrayOutputStream os = new ByteArrayOutputStream(); - ontology.saveOntology(OntologyFileFormat.OWL_RDF,os,"ISO-8859-1"); - return os.toString(); - // in einigen der folgenden Fälle sollten im Web-Service Exceptions geworfen // werden (throws ...) z.B. bei ParseException } catch (ParseException e) { @@ -92,16 +127,10 @@ // TODO Auto-generated catch block e.printStackTrace(); System.out.println("Syntactically incorrect URL."); - } catch (KAON2Exception e) { + } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + } throw new Error("Ontology could not be rewritten. Exiting."); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-06 15:24:13
|
Revision: 501 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=501&view=rev Author: sknappe Date: 2008-02-06 07:24:06 -0800 (Wed, 06 Feb 2008) Log Message: ----------- changed the design a bit Modified Paths: -------------- trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/index.php Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-06 14:47:37 UTC (rev 500) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-06 15:24:06 UTC (rev 501) @@ -118,7 +118,7 @@ //BUILD ARTICLE TITLE $artTitle=$triples['http://www.w3.org/2000/01/rdf-schema#label'][0]; - + session_start(); //store article in session, to navigate between last 5 articles quickly $contentArray=array('content' => $content,'subject' => $artTitle); if (!isset($_SESSION['nextArticle'])){ @@ -153,6 +153,7 @@ } } else { + session_start(); //Article is in session $content=$_SESSION['articles'][$fromCache]['content']; $artTitle=$_SESSION['articles'][$fromCache]['subject']; Modified: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2008-02-06 14:47:37 UTC (rev 500) +++ trunk/src/dbpedia-navigator/index.php 2008-02-06 15:24:06 UTC (rev 501) @@ -42,7 +42,7 @@ <body> <!-- <h1>DBpedia Navigator</h1> --> -<div><img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> <input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /> <span id="conceptlink"></span><span id="Loading" style="display:none">Server Call... <input type="button" value="Stop" class="button" onclick="xajax_stopServerCall();return false;" /></span></div> +<div><table border="0" width="100%"><tr><td width="35%"><img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /></td><td width="50%"><span id="conceptlink"></span></td><td width="15%"><span id="Loading" style="display:none">Server Call... <img src="images/remove.png" onclick="xajax_stopServerCall();return false;" /></span></td></tr></table></div> <div id="layer" style="display:none"> <div id="layerContent" style="display:none"></div> </div> @@ -81,7 +81,7 @@ <a href="http://www.w3.org/2001/sw/DataAccess/"><img src="images/sw-sparql-green.png" alt="SPARQL logo"/></a> </div> - + <input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /> </div><!-- END leftSidebar --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-06 14:47:44
|
Revision: 500 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=500&view=rev Author: sknappe Date: 2008-02-06 06:47:37 -0800 (Wed, 06 Feb 2008) Log Message: ----------- fixed some unnessecary code Modified Paths: -------------- trunk/src/dbpedia-navigator/ajaxfunctions.php Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-06 14:46:49 UTC (rev 499) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-06 14:47:37 UTC (rev 500) @@ -368,7 +368,6 @@ session_write_close(); setRunning($id,"false"); $objResponse=new xajaxResponse(); - //$objResponse->append("searchcontent", "innerHTML", "Stop"); return $objResponse; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-06 14:46:52
|
Revision: 499 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=499&view=rev Author: sknappe Date: 2008-02-06 06:46:49 -0800 (Wed, 06 Feb 2008) Log Message: ----------- You now have the chance to abort the current server call Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php trunk/src/dbpedia-navigator/ajax.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/index.php Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-02-06 14:41:42 UTC (rev 498) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-02-06 14:46:49 UTC (rev 499) @@ -85,6 +85,15 @@ $seconds = $i * $sleeptime; $i++; + + //look, if algorithm was stopped + $file=fopen($this->id.".temp","r"); + $run=fgets($file); + fclose($file); + if ($run=="false"){ + $this->client->stop($this->id); + throw new Exception("Learning stopped"); + } } while($seconds<$this->ttl&&$running); $this->client->stop($this->id); @@ -115,7 +124,6 @@ $running=true; $i = 1; $sleeptime = 1; - do { // sleep a while sleep($sleeptime); @@ -129,6 +137,14 @@ $seconds = $i * $sleeptime; $i++; + //look, if algorithm was stopped + $file=fopen($this->id.".temp","r"); + $run=fgets($file); + fclose($file); + if ($run=="false"){ + $this->client->stopSparqlQuery($id,$queryID); + throw new Exception("Query stopped"); + } } while($seconds<$this->ttl); $this->client->stopSparqlQuery($id,$queryID); } Modified: trunk/src/dbpedia-navigator/ajax.php =================================================================== --- trunk/src/dbpedia-navigator/ajax.php 2008-02-06 14:41:42 UTC (rev 498) +++ trunk/src/dbpedia-navigator/ajax.php 2008-02-06 14:46:49 UTC (rev 499) @@ -28,4 +28,5 @@ $xajax->registerFunction('showInterests'); $xajax->registerFunction('removePosInterest'); $xajax->registerFunction('removeNegInterest'); +$xajax->registerFunction('stopServerCall'); ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-06 14:41:42 UTC (rev 498) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-06 14:46:49 UTC (rev 499) @@ -1,22 +1,26 @@ <?php ini_set('max_execution_time',200); -$sid = $_GET['sid']; -session_id($sid); -session_start(); require("ajax.php"); $xajax->processRequest(); function getsubjects($label) { - require_once("DLLearnerConnection.php"); + $sid = $_GET['sid']; + session_id($sid); + session_start(); + $id=$_SESSION['id']; + $ksID=$_SESSION['ksID']; + session_write_close(); + setRunning($id,"true"); + //initialise content $content=""; try{ - $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); - - + require_once("DLLearnerConnection.php"); + $sc=new DLLearnerConnection($id,$ksID); + $subjects=$sc->getSubjects($label); foreach ($subjects as $subject) @@ -34,9 +38,18 @@ function getarticle($subject,$fromCache) { + $sid = $_GET['sid']; + session_id($sid); + session_start(); + $articles=$_SESSION['articles']; + $id=$_SESSION['id']; + $ksID=$_SESSION['ksID']; + session_write_close(); + setRunning($id,"true"); + //if article is in session, get it out of the session - if (isset($_SESSION['articles'])){ - foreach ($_SESSION['articles'] as $key => $value) + if (isset($articles)){ + foreach ($articles as $key => $value) { if ($value['subject']==$subject){ $fromCache=$key; @@ -59,7 +72,7 @@ //if there are errors see catch block try{ require_once("DLLearnerConnection.php"); - $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); + $sc=new DLLearnerConnection($id,$ksID); $triples=$sc->getTriples($subject); //BUILD ARTICLE @@ -68,7 +81,7 @@ // display a picture if there is one if(isset($triples['http://xmlns.com/foaf/0.1/depiction'])) - $content.='<img src="'.$triples['http://xmlns.com/foaf/0.1/depiction'][0].'" alt="Picture of '.$subject_nice.'" style="float:right; max-width:200px;" \>'; + $content.='<img src="'.$triples['http://xmlns.com/foaf/0.1/depiction'][0].'" alt="Picture of '.$subject.'" style="float:right; max-width:200px;" \>'; // add short description in english $content.="<h4>Short Description</h4><p>".urldecode($triples['http://dbpedia.org/property/abstract'][0])."</p>"; @@ -131,7 +144,8 @@ //BUILD SEARCHRESULT if ($fromCache==-1) - $searchResult.="<a href=\"\" onclick=\"xajax_getsubjects('".$subject."');return false;\">Show more Results</a>"; + $searchResult.="<a href=\"\" onclick=\"xajax_getsubjects('".$subject."');return false;\">Show more Results</a>"; + } catch (Exception $e) { $content=$e->getMessage(); @@ -164,6 +178,9 @@ function toPositive($subject) { + $sid = $_GET['sid']; + session_id($sid); + session_start(); unset($_SESSION['negative'][$subject]); if (!isset($_SESSION['positive'])){ $array=array($subject => $subject); @@ -182,6 +199,9 @@ function toNegative($subject) { + $sid = $_GET['sid']; + session_id($sid); + session_start(); unset($_SESSION['positive'][$subject]); if (!isset($_SESSION['negative'])){ $array=array($subject => $subject); @@ -200,6 +220,9 @@ function clearPositives() { + $sid = $_GET['sid']; + session_id($sid); + session_start(); unset($_SESSION['positive']); $objResponse = new xajaxResponse(); @@ -209,6 +232,9 @@ function clearNegatives() { + $sid = $_GET['sid']; + session_id($sid); + session_start(); unset($_SESSION['negative']); $objResponse = new xajaxResponse(); @@ -218,6 +244,9 @@ function showInterests() { + $sid = $_GET['sid']; + session_id($sid); + session_start(); //add Positives and Negatives to Interests $posInterests=""; if (isset($_SESSION['positive'])) foreach($_SESSION['positive'] as $pos){ @@ -236,6 +265,9 @@ function removePosInterest($subject) { + $sid = $_GET['sid']; + session_id($sid); + session_start(); unset($_SESSION['positive'][$subject]); $objResponse = new xajaxResponse(); @@ -245,6 +277,9 @@ function removeNegInterest($subject) { + $sid = $_GET['sid']; + session_id($sid); + session_start(); unset($_SESSION['negative'][$subject]); $objResponse = new xajaxResponse(); @@ -254,29 +289,40 @@ function learnConcept() { + $sid = $_GET['sid']; + session_id($sid); + session_start(); + + $positives=$_SESSION['positive']; + $negatives=$_SESSION['negative']; + $id=$_SESSION['id']; + $ksID=$_SESSION['ksID']; + session_write_close(); + setRunning($id,"true"); $concept=""; - if (isset($_SESSION['positive'])) + if (isset($positives)) { $posArray=array(); - foreach ($_SESSION['positive'] as $pos) + foreach ($positives as $pos) $posArray[]=$pos; $negArray=array(); - if (isset($_SESSION['negative'])) - foreach ($_SESSION['negative'] as $neg) + if (isset($negatives)) + foreach ($negatives as $neg) $negArray[]=$neg; require_once("DLLearnerConnection.php"); - $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); - - - $concepts=$sc->getConceptFromExamples($posArray,$negArray); - - $_SESSION['lastLearnedConcept']=$concepts; - $concept.="<table border=0>\n"; - foreach ($concepts as $con){ - $concept.="<tr><td><a href=\"\" onclick=\"xajax_getSubjectsFromConcept('".$con."');return false;\" />".$con."</a></td></tr>"; + $sc=new DLLearnerConnection($id, $ksID); + try{ + $concepts=$sc->getConceptFromExamples($posArray,$negArray); + + $concept.="<table border=0>\n"; + foreach ($concepts as $con){ + $concept.="<tr><td><a href=\"\" onclick=\"xajax_getSubjectsFromConcept('".$con."');return false;\" />".$con."</a></td></tr>"; + } + $concept.="</table>"; + } catch(Exception $e){ + $concept.=$e->getMessage(); } - $concept.="</table>"; } else $concept="You must choose at least one positive example."; @@ -287,10 +333,18 @@ function getSubjectsFromConcept($concept) { + $sid = $_GET['sid']; + session_id($sid); + session_start(); + $id=$_SESSION['id']; + $ksID=$_SESSION['ksID']; + session_write_stop(); + setRunning("true"); + $content=""; try{ require_once("DLLearnerConnection.php"); - $sc=new DLLearnerConnection($_SESSION['id'],$_SESSION['ksID']); + $sc=new DLLearnerConnection($id,$ksID); $subjects=$sc->getSubjectsFromConcept($concept); foreach ($subjects as $subject) { @@ -305,9 +359,29 @@ return $objResponse; } +function stopServerCall() +{ + $sid = $_GET['sid']; + session_id($sid); + session_start(); + $id=$_SESSION['id']; + session_write_close(); + setRunning($id,"false"); + $objResponse=new xajaxResponse(); + //$objResponse->append("searchcontent", "innerHTML", "Stop"); + return $objResponse; +} + /////////////////////// // Helper Functions. // /////////////////////// + +function setRunning($id,$running) +{ + $file=fopen($id.".temp","w"); + fwrite($file, $running); + fclose($file); +} function get_triple_table($triples) { Modified: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2008-02-06 14:41:42 UTC (rev 498) +++ trunk/src/dbpedia-navigator/index.php 2008-02-06 14:46:49 UTC (rev 499) @@ -42,7 +42,7 @@ <body> <!-- <h1>DBpedia Navigator</h1> --> -<div><img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> <input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /> <span id="conceptlink"></span><span id="Loading" style="display:none">Loading...</span></div> +<div><img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> <input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /> <span id="conceptlink"></span><span id="Loading" style="display:none">Server Call... <input type="button" value="Stop" class="button" onclick="xajax_stopServerCall();return false;" /></span></div> <div id="layer" style="display:none"> <div id="layerContent" style="display:none"></div> </div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-06 14:41:48
|
Revision: 498 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=498&view=rev Author: jenslehmann Date: 2008-02-06 06:41:42 -0800 (Wed, 06 Feb 2008) Log Message: ----------- finished cross validator Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java trunk/src/dl-learner/org/dllearner/utilities/Stat.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2008-02-06 14:41:42 UTC (rev 498) @@ -11,6 +11,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.Logger; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -38,6 +39,9 @@ public class ROLearner extends LearningAlgorithm { + private static Logger logger = Logger + .getLogger(LearningAlgorithm.class); + public enum Heuristic { LEXICOGRAPHIC, FLEXIBLE } // configuration options @@ -461,7 +465,7 @@ loop++; if(!quiet) - System.out.println("--- loop " + loop + " finished ---"); + logger.debug("--- loop " + loop + " finished ---"); } @@ -864,15 +868,15 @@ // Refinementoperator auf Konzept anwenden String bestNodeString = "currently best node: " + candidatesStable.last(); // searchTree += bestNodeString + "\n"; - System.out.println(bestNodeString); + logger.info(bestNodeString); String expandedNodeString = "next expanded node: " + candidates.last(); // searchTree += expandedNodeString + "\n"; - System.out.println(expandedNodeString); - System.out.println("algorithm runtime " + Helper.prettyPrintNanoSeconds(algorithmRuntime)); + logger.debug(expandedNodeString); + logger.debug("algorithm runtime " + Helper.prettyPrintNanoSeconds(algorithmRuntime)); String expansionString = "horizontal expansion: " + minimumHorizontalExpansion + " to " + maximumHorizontalExpansion; // searchTree += expansionString + "\n"; - System.out.println(expansionString); - System.out.println("size of candidate set: " + candidates.size()); + logger.debug(expansionString); + logger.debug("size of candidate set: " + candidates.size()); // System.out.println("properness max recursion depth: " + maxRecDepth); // System.out.println("max. number of one-step refinements: " + maxNrOfRefinements); // System.out.println("max. number of children of a node: " + maxNrOfChildren); @@ -916,9 +920,9 @@ System.out.println("onnf time percentage: " + df.format(onnfTimePercentage) + "%"); System.out.println("shortening time percentage: " + df.format(shorteningTimePercentage) + "%"); } - System.out.println("properness tests (reasoner/short concept/too weak list): " + propernessTestsReasoner + "/" + propernessTestsAvoidedByShortConceptConstruction + logger.debug("properness tests (reasoner/short concept/too weak list): " + propernessTestsReasoner + "/" + propernessTestsAvoidedByShortConceptConstruction + "/" + propernessTestsAvoidedByTooWeakList); - System.out.println("concept tests (reasoner/too weak list/overly general list/redundant concepts): " + conceptTestsReasoner + "/" + logger.debug("concept tests (reasoner/too weak list/overly general list/redundant concepts): " + conceptTestsReasoner + "/" + conceptTestsTooWeakList + "/" + conceptTestsOverlyGeneralList + "/" + redundantConcepts); } Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-06 14:41:42 UTC (rev 498) @@ -710,4 +710,12 @@ return la; } + public LearningProblem getLearningProblem() { + return lp; + } + + public ReasoningService getReasoningService() { + return rs; + } + } Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java 2008-02-06 14:41:42 UTC (rev 498) @@ -19,18 +19,10 @@ */ package org.dllearner.learningproblems; -import java.util.Collection; -import java.util.LinkedList; -import java.util.Set; import java.util.SortedSet; import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; -import org.dllearner.core.config.CommonConfigMappings; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.utilities.Helper; @@ -55,47 +47,12 @@ /* * (non-Javadoc) * - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String name = entry.getOptionName(); - if (name.equals("positiveExamples")) - positiveExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - } - - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringSetConfigOption("positiveExamples", - "positive examples")); - return options; - } - - /* - * (non-Javadoc) - * * @see org.dllearner.core.Component#getName() */ public static String getName() { return "positive only definition learning problem"; } - - /** - * @return the positiveExamples - */ - public SortedSet<Individual> getPositiveExamples() { - return positiveExamples; - } - /** - * @return the pseudoNegatives - */ - public SortedSet<Individual> getPseudoNegatives() { - return pseudoNegatives; - } - /* (non-Javadoc) * @see org.dllearner.core.Component#init() */ Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyLP.java 2008-02-06 14:41:42 UTC (rev 498) @@ -19,17 +19,64 @@ */ package org.dllearner.learningproblems; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Set; +import java.util.SortedSet; + import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; +import org.dllearner.core.config.CommonConfigMappings; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.dl.Individual; /** + * A learning problem, where we learn from positive examples only. + * * @author Jens Lehmann * */ public abstract class PosOnlyLP extends LearningProblem { + protected SortedSet<Individual> positiveExamples; + protected SortedSet<Individual> pseudoNegatives; + public PosOnlyLP(ReasoningService reasoningService) { super(reasoningService); } + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String name = entry.getOptionName(); + if (name.equals("positiveExamples")) + positiveExamples = CommonConfigMappings + .getIndividualSet((Set<String>) entry.getValue()); + } + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringSetConfigOption("positiveExamples", + "positive examples")); + return options; + } + + public SortedSet<Individual> getPositiveExamples() { + return positiveExamples; + } + + /** + * @return the pseudoNegatives + */ + public SortedSet<Individual> getPseudoNegatives() { + return pseudoNegatives; + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-06 14:41:42 UTC (rev 498) @@ -20,16 +20,30 @@ package org.dllearner.utilities; import java.io.File; +import java.text.DecimalFormat; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.dllearner.cli.Start; +import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyLP; /** - * Performs cross validation for the given problem. + * Performs cross validation for the given problem. Supports + * k-fold cross-validation and leave-one-out cross-validation. * * @author Jens Lehmann * @@ -41,9 +55,15 @@ public static void main(String[] args) { File file = new File(args[0]); + boolean leaveOneOut = false; int folds = 10; + + // use second argument as number of folds; if not specified + // leave one out cross validation is used if(args.length > 1) folds = Integer.parseInt(args[1]); + else + leaveOneOut = true; // create logger (a simple logger which outputs // its messages to the console) @@ -51,19 +71,181 @@ ConsoleAppender consoleAppender = new ConsoleAppender(layout); logger.removeAllAppenders(); logger.addAppender(consoleAppender); - logger.setLevel(Level.INFO); + logger.setLevel(Level.WARN); - new CrossValidation(file, folds); + new CrossValidation(file, folds, leaveOneOut); } - public CrossValidation(File file, int folds) { + public CrossValidation(File file, int folds, boolean leaveOneOut) { + + DecimalFormat df = new DecimalFormat(); + ComponentManager cm = ComponentManager.getInstance(); + + // the first read of the file is used to detect the examples + // and set up the splits correctly according to our validation + // method Start start = new Start(file); - LearningAlgorithm la = start.getLearningAlgorithm(); + LearningProblem lp = start.getLearningProblem(); + ReasoningService rs = start.getReasoningService(); + + // the training and test sets used later on + List<Set<Individual>> trainingSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> trainingSetsNeg = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); + + if(lp instanceof PosNegLP) { + + Set<Individual> posExamples = ((PosNegLP)lp).getPositiveExamples(); + List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); + Set<Individual> negExamples = ((PosNegLP)lp).getNegativeExamples(); + List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); + + // sanity check whether nr. of folds makes sense for this benchmark + if(!leaveOneOut && (posExamples.size()<folds || negExamples.size()<folds)) { + System.out.println("The number of folds is higher than the number of " + + "positive/negative examples. This can result in empty test sets. Exiting."); + System.exit(0); + } + + if(leaveOneOut) { + // note that leave-one-out is not identical to k-fold with + // k = nr. of examples in the current implementation, because + // with n folds and n examples there is no guarantee that a fold + // is never empty (this is an implementation issue) + int nrOfExamples = posExamples.size() + negExamples.size(); + for(int i = 0; i < nrOfExamples; i++) { + // ... + } + System.out.println("Leave-one-out not supported yet."); + System.exit(1); + } else { + // calculating where to split the sets, ; note that we split + // positive and negative examples separately such that the + // distribution of positive and negative examples remains similar + // (note that there better but more complex ways to implement this, + // which guarantee that the sum of the elements of a fold for pos + // and neg differs by at most 1 - it can differ by 2 in our implementation, + // e.g. with 3 folds, 4 pos. examples, 4 neg. examples) + int[] splitsPos = calculateSplits(posExamples.size(),folds); + int[] splitsNeg = calculateSplits(negExamples.size(),folds); + + // calculating training and test sets + for(int i=0; i<folds; i++) { + Set<Individual> testPos = getTestingSet(posExamplesList, splitsPos, i); + Set<Individual> testNeg = getTestingSet(negExamplesList, splitsNeg, i); + testSetsPos.add(i, testPos); + testSetsNeg.add(i, testNeg); + trainingSetsPos.add(i, getTrainingSet(posExamples, testPos)); + trainingSetsNeg.add(i, getTrainingSet(negExamples, testNeg)); + } + + } + + } else if(lp instanceof PosOnlyLP) { + System.out.println("Cross validation for positive only learning not supported yet."); + System.exit(0); + // Set<Individual> posExamples = ((PosOnlyLP)lp).getPositiveExamples(); + // int[] splits = calculateSplits(posExamples.size(),folds); + } else { + System.out.println("Cross validation for learning problem " + lp + " not supported."); + System.exit(0); + } + + // statistical values + Stat runtime = new Stat(); + Stat accuracy = new Stat(); + Stat length = new Stat(); + + // run the algorithm for(int currFold=0; currFold<folds; currFold++) { + // we always perform a full initialisation to make sure that + // no objects are reused + start = new Start(file); + lp = start.getLearningProblem(); + Set<String> pos = Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); + Set<String> neg = Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); + cm.applyConfigEntry(lp, "positiveExamples", pos); + cm.applyConfigEntry(lp, "negativeExamples", neg); + + LearningAlgorithm la = start.getLearningAlgorithm(); + long algorithmStartTime = System.nanoTime(); la.start(); - } + long algorithmDuration = System.nanoTime() - algorithmStartTime; + runtime.addNumber(algorithmDuration/(double)1000000000); + + Concept concept = la.getBestSolution(); + int correctExamples = getCorrectPosClassified(rs, concept, testSetsPos.get(currFold)) + + getCorrectNegClassified(rs, concept, testSetsNeg.get(currFold)); + double currAccuracy = 100*((double)correctExamples/(testSetsPos.get(currFold).size()+ + testSetsNeg.get(currFold).size())); + accuracy.addNumber(currAccuracy); + + length.addNumber(concept.getLength()); + + System.out.println("fold " + currFold + " (" + file + "):"); + System.out.println(" concept: " + concept); + System.out.println(" accuracy: " + df.format(currAccuracy) + "%"); + System.out.println(" length: " + df.format(concept.getLength())); + System.out.println(" runtime: " + df.format(algorithmDuration/(double)1000000000) + "s"); + } + + System.out.println(); + System.out.println("Finished " + folds + "-folds cross-validation on " + file + "."); + System.out.println("runtime: " + statOutput(df, runtime, "s")); + System.out.println("length: " + statOutput(df, length, "")); + System.out.println("accuracy: " + statOutput(df, accuracy, "%")); + } + private int getCorrectPosClassified(ReasoningService rs, Concept concept, Set<Individual> posClassified) { + return rs.instanceCheck(concept, posClassified).size(); + } + + private int getCorrectNegClassified(ReasoningService rs, Concept concept, Set<Individual> negClassified) { + return negClassified.size() - rs.instanceCheck(concept, negClassified).size(); + } + + private Set<Individual> getTestingSet(List<Individual> examples, int[] splits, int fold) { + int fromIndex; + // we either start from 0 or after the last fold ended + if(fold == 0) + fromIndex = 0; + else + fromIndex = splits[fold-1]; + // the split corresponds to the ends of the folds + int toIndex = splits[fold]; + + Set<Individual> testingSet = new HashSet<Individual>(); + // +1 because 2nd element is exclusive in subList method + testingSet.addAll(examples.subList(fromIndex, toIndex)); + return testingSet; + } + + private Set<Individual> getTrainingSet(Set<Individual> examples, Set<Individual> testingSet) { + return Helper.difference(examples, testingSet); + } + + // takes nr. of examples and the nr. of folds for this examples; + // returns an array which says where each fold ends, i.e. + // splits[i] is the index of the last element of fold i in the examples + private int[] calculateSplits(int nrOfExamples, int folds) { + int[] splits = new int[folds]; + for(int i=1; i<=folds; i++) { + // we always round up to the next integer + splits[i-1] = (int)Math.ceil(i*nrOfExamples/(double)folds); + } + return splits; + } + + private String statOutput(DecimalFormat df, Stat stat, String unit) { + String str = "av. " + df.format(stat.getMean()) + unit; + str += " (deviation " + df.format(stat.getStandardDeviation()) + unit + "; "; + str += "min " + df.format(stat.getMin()) + unit + "; "; + str += "max " + df.format(stat.getMax()) + unit + ")"; + return str; + } + } Modified: trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/utilities/Datastructures.java 2008-02-06 14:41:42 UTC (rev 498) @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.Set; +import java.util.TreeSet; import org.dllearner.core.dl.AtomicConcept; import org.dllearner.core.dl.AtomicRole; @@ -99,4 +100,12 @@ Arrays.sort(ret); return ret; } + + public static Set<String> individualSetToStringSet(Set<Individual> individuals) { + Set<String> ret = new TreeSet<String>(); + for(Individual ind : individuals) { + ret.add(ind.toString()); + } + return ret; + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/Stat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/Stat.java 2008-02-05 15:59:48 UTC (rev 497) +++ trunk/src/dl-learner/org/dllearner/utilities/Stat.java 2008-02-06 14:41:42 UTC (rev 498) @@ -32,6 +32,8 @@ private int count = 0; private double sum = 0; private double squareSum = 0; + private double min = Double.MAX_VALUE; + private double max = Double.MIN_NORMAL; /** * Add a number to this object. @@ -43,6 +45,10 @@ count++; sum += number; squareSum += number * number; + if(number<min) + min=number; + if(number>max) + max=number; } /** @@ -94,4 +100,18 @@ return root; } + /** + * @return the min + */ + public double getMin() { + return min; + } + + /** + * @return the max + */ + public double getMax() { + return max; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 15:59:49
|
Revision: 497 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=497&view=rev Author: sknappe Date: 2008-02-05 07:59:48 -0800 (Tue, 05 Feb 2008) Log Message: ----------- now everything is in one function, no session variables needed anymore Modified Paths: -------------- trunk/src/dbpedia-navigator/ajax.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/index.php Modified: trunk/src/dbpedia-navigator/ajax.php =================================================================== --- trunk/src/dbpedia-navigator/ajax.php 2008-02-05 15:39:08 UTC (rev 496) +++ trunk/src/dbpedia-navigator/ajax.php 2008-02-05 15:59:48 UTC (rev 497) @@ -4,35 +4,28 @@ $xajax = new xajax("ajaxfunctions.php?sid=$sid"); $xajax->configureMany(array('debug'=>true)); -$xajax->register(XAJAX_FUNCTION, 'showSubjects', array( + +$xajax->register(XAJAX_FUNCTION, 'getsubjects', array( 'onResponseDelay' => 'showLoading', 'beforeResponseProcessing' => 'hideLoading' )); -$xajax->registerFunction('getarticle'); -$xajax->registerFunction('toPositive'); -$xajax->registerFunction('toNegative'); -$xajax->registerFunction('clearPositives'); -$xajax->registerFunction('clearNegatives'); -$xajax->registerFunction('showInterests'); -$xajax->registerFunction('getAndShowArticle'); -$xajax->registerFunction('learnConcept'); -$xajax->registerFunction('getSubjectsFromConcept'); -$xajax->registerFunction('getAndShowSubjects'); -$xajax->registerFunction('getsubjects'); -$xajax->register(XAJAX_FUNCTION,'showArticle', array( +$xajax->register(XAJAX_FUNCTION,'getarticle', array( 'onResponseDelay' => 'showLoading', 'beforeResponseProcessing' => 'hideLoading' )); -$xajax->registerFunction('removePosInterest'); -$xajax->registerFunction('removeNegInterest'); -$xajax->register(XAJAX_FUNCTION,'showConcept', array( +$xajax->register(XAJAX_FUNCTION,'learnConcept', array( 'onResponseDelay' => 'showLoading', 'beforeResponseProcessing' => 'hideLoading' )); -$xajax->registerFunction('learnAndShowConcept'); -$xajax->register(XAJAX_FUNCTION,'showSubjectsFromConcept', array( +$xajax->register(XAJAX_FUNCTION,'getSubjectsFromConcept', array( 'onResponseDelay' => 'showLoading', 'beforeResponseProcessing' => 'hideLoading' )); -$xajax->registerFunction('getAndShowSubjectsFromConcept'); + $xajax->registerFunction('toPositive'); +$xajax->registerFunction('toNegative'); +$xajax->registerFunction('clearPositives'); +$xajax->registerFunction('clearNegatives'); +$xajax->registerFunction('showInterests'); +$xajax->registerFunction('removePosInterest'); +$xajax->registerFunction('removeNegInterest'); ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-05 15:39:08 UTC (rev 496) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-02-05 15:59:48 UTC (rev 497) @@ -21,29 +21,17 @@ foreach ($subjects as $subject) { - $content.="<a href=\"\" onclick=\"xajax_getAndShowArticle('".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."',-2);return false;\">".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."</a><br/>"; + $content.="<a href=\"\" onclick=\"xajax_getarticle('".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."',-2);return false;\">".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."</a><br/>"; } } catch (Exception $e){ $content=$e->getMessage(); } - $_SESSION['subjects']=$content; - $objResponse = new xajaxResponse(); + $objResponse->assign("searchcontent", "innerHTML", $content); return $objResponse; } -function showSubjects() -{ - while (!isset($_SESSION['subjects'])){ - sleep(0.5); - } - $objResponse = new xajaxResponse(); - $objResponse->assign("searchcontent", "innerHTML", $_SESSION['subjects']); - unset($_SESSION['subjects']); - return $objResponse; -} - function getarticle($subject,$fromCache) { //if article is in session, get it out of the session @@ -143,7 +131,7 @@ //BUILD SEARCHRESULT if ($fromCache==-1) - $searchResult.="<a href=\"\" onclick=\"xajax_getAndShowSubjects('".$subject."');return false;\">Show more Results</a>"; + $searchResult.="<a href=\"\" onclick=\"xajax_getsubjects('".$subject."');return false;\">Show more Results</a>"; } catch (Exception $e) { $content=$e->getMessage(); @@ -160,49 +148,20 @@ if (isset($_SESSION['articles'])){ foreach ($_SESSION['articles'] as $key => $value) { - $lastArticles.="<a href=\"\" onclick=\"xajax_getAndShowArticle('',".$key.");return false;\">".$value['subject']."</a><br/>"; + $lastArticles.="<a href=\"\" onclick=\"xajax_getarticle('',".$key.");return false;\">".$value['subject']."</a><br/>"; } } - //put whole site content into session - $_SESSION['artContent']=$content; - $_SESSION['artTitle']=$artTitle; - $_SESSION['artLast']=$lastArticles; - $_SESSION['artSubjects']=$searchResult; - $objResponse = new xajaxResponse(); + $objResponse->assign("articlecontent", "innerHTML", $content); + $objResponse->assign("ArticleTitle","innerHTML",$artTitle); + $objResponse->assign("lastarticles","innerHTML",$lastArticles); + $objResponse->assign("searchcontent", "innerHTML", $searchResult); + + $objResponse->call('xajax_showInterests'); return $objResponse; } -function showArticle() -{ - while (!isset($_SESSION['artSubjects'])){ - sleep(0.5); - } - $objResponse = new xajaxResponse(); - $objResponse->assign("articlecontent", "innerHTML", $_SESSION['artContent']); - $objResponse->assign("ArticleTitle","innerHTML",$_SESSION['artTitle']); - $objResponse->assign("lastarticles","innerHTML",$_SESSION['artLast']); - if ($_SESSION['artSubjects']!="") $objResponse->assign("searchcontent", "innerHTML", $_SESSION['artSubjects']); - if (strpos($_SESSION['artContent'],"Did not find an article with that name")===0) - $objResponse->call('xajax_getAndShowSubjects',$_SESSION['artTitle']); - unset($_SESSION['artContent']); - unset($_SESSION['artTitle']); - unset($_SESSION['artLast']); - unset($_SESSION['artSubjects']); - - $objResponse->call('xajax_showInterests'); - return $objResponse; -} - -function getAndShowArticle($subject,$fromCache) -{ - $objResponse = new xajaxResponse(); - $objResponse->call('xajax_getarticle',$subject,$fromCache); - $objResponse->call('xajax_showArticle'); - return $objResponse; -} - function toPositive($subject) { unset($_SESSION['negative'][$subject]); @@ -315,15 +274,14 @@ $_SESSION['lastLearnedConcept']=$concepts; $concept.="<table border=0>\n"; foreach ($concepts as $con){ - $concept.="<tr><td><a href=\"\" onclick=\"xajax_getAndShowSubjectsFromConcept('".$con."');return false;\" />".$con."</a></td></tr>"; + $concept.="<tr><td><a href=\"\" onclick=\"xajax_getSubjectsFromConcept('".$con."');return false;\" />".$con."</a></td></tr>"; } $concept.="</table>"; } else $concept="You must choose at least one positive example."; - $_SESSION['conceptcontent']=$concept; - $objResponse = new xajaxResponse(); + $objResponse->assign("conceptlink", "innerHTML", $concept); return $objResponse; } @@ -336,65 +294,17 @@ $subjects=$sc->getSubjectsFromConcept($concept); foreach ($subjects as $subject) { - $content.="<a href=\"\" onclick=\"xajax_getAndShowArticle('".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."',-2);return false;\">".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."</a><br/>"; + $content.="<a href=\"\" onclick=\"xajax_getarticle('".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."',-2);return false;\">".urldecode(str_replace("_"," ",substr (strrchr ($subject, "/"), 1)))."</a><br/>"; } } catch (Exception $e){ $content=$e->getMessage(); } - $_SESSION['conceptsubjectcontent']=$content; $objResponse = new xajaxResponse(); + $objResponse->assign("searchcontent", "innerHTML", $content); return $objResponse; } -function getAndShowSubjects($keyword) -{ - $objResponse = new xajaxResponse(); - $objResponse->call('xajax_getsubjects',$keyword); - $objResponse->call('xajax_showSubjects'); - return $objResponse; -} - -function learnAndShowConcept() -{ - $objResponse = new xajaxResponse(); - $objResponse->call('xajax_learnConcept'); - $objResponse->call('xajax_showConcept'); - return $objResponse; -} - -function showConcept() -{ - while (!isset($_SESSION['conceptcontent'])){ - sleep(0.5); - } - - $objResponse = new xajaxResponse(); - $objResponse->assign("conceptlink", "innerHTML", $_SESSION['conceptcontent']); - unset($_SESSION['conceptcontent']); - return $objResponse; -} - -function getAndShowSubjectsFromConcept($concept) -{ - $objResponse = new xajaxResponse(); - $objResponse->call('xajax_getSubjectsFromConcept',$concept); - $objResponse->call('xajax_showSubjectsFromConcept'); - return $objResponse; -} - -function showSubjectsFromConcept() -{ - while (!isset($_SESSION['conceptsubjectcontent'])){ - sleep(0.5); - } - - $objResponse = new xajaxResponse(); - $objResponse->assign("searchcontent", "innerHTML", $_SESSION['conceptsubjectcontent']); - unset($_SESSION['conceptsubjectcontent']); - return $objResponse; -} - /////////////////////// // Helper Functions. // /////////////////////// Modified: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2008-02-05 15:39:08 UTC (rev 496) +++ trunk/src/dbpedia-navigator/index.php 2008-02-05 15:59:48 UTC (rev 497) @@ -42,7 +42,7 @@ <body> <!-- <h1>DBpedia Navigator</h1> --> -<div><img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> <input type="button" value="Learn" class="button" onclick="xajax_learnAndShowConcept();return false;" /> <span id="conceptlink"></span><span id="Loading" style="display:none">Loading...</span></div> +<div><img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> <input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /> <span id="conceptlink"></span><span id="Loading" style="display:none">Loading...</span></div> <div id="layer" style="display:none"> <div id="layerContent" style="display:none"></div> </div> @@ -54,9 +54,9 @@ <div class="boxtitle">Search DBpedia</div> <div class="boxcontent" id="search"> <!-- Search:<br/> --> - <form onSubmit="xajax_getAndShowArticle(document.getElementById('label').value,-1);return false;"> + <form onSubmit="xajax_getarticle(document.getElementById('label').value,-1);return false;"> <input type="text" name="label" id="label" /><br/> - <input type="button" value="Search" class="button" onclick="xajax_getAndShowArticle(document.getElementById('label').value,-1);return false;" /> + <input type="button" value="Search" class="button" onclick="xajax_getarticle(document.getElementById('label').value,-1);return false;" /> <!-- <input type="button" value="Fulltext" class="button" onclick=""/> --> </form> </div> <!-- boxcontent --> @@ -66,7 +66,6 @@ <div class="boxtitle">Search Results</div> <div class="boxcontent"> <div id="searchcontent" style="display:block"></div> - <div id="loadingSubject" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> </div> <!-- boxcontent --> </div> <!-- box --> @@ -96,7 +95,6 @@ and uses the background knowledge in DBpedia to suggest possible interesting navigation links. </div> - <div id="loadingArticle" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> </div> <!-- boxcontent --> </div> <!-- box --> </div><!-- content --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 15:39:13
|
Revision: 496 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=496&view=rev Author: sknappe Date: 2008-02-05 07:39:08 -0800 (Tue, 05 Feb 2008) Log Message: ----------- deleted test files, no longer necessary Removed Paths: ------------- trunk/src/dbpedia-navigator/SoapTest.php Deleted: trunk/src/dbpedia-navigator/SoapTest.php =================================================================== --- trunk/src/dbpedia-navigator/SoapTest.php 2008-02-05 15:38:39 UTC (rev 495) +++ trunk/src/dbpedia-navigator/SoapTest.php 2008-02-05 15:39:08 UTC (rev 496) @@ -1,7 +0,0 @@ -<?php - $start=microtime(true); - $client = new SoapClient("http://www.foreclosuredatabank.com/soapserver.php?wsdl"); - print($client->latestProperties('33149')); - $stop=microtime(true)-$start; - print "<br/>".$stop; -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 15:38:41
|
Revision: 495 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=495&view=rev Author: sknappe Date: 2008-02-05 07:38:39 -0800 (Tue, 05 Feb 2008) Log Message: ----------- deleted test files, no longer necessary Removed Paths: ------------- trunk/src/dbpedia-navigator/indextest.php trunk/src/dbpedia-navigator/xajaxtest.php Deleted: trunk/src/dbpedia-navigator/indextest.php =================================================================== --- trunk/src/dbpedia-navigator/indextest.php 2008-02-05 11:43:54 UTC (rev 494) +++ trunk/src/dbpedia-navigator/indextest.php 2008-02-05 15:38:39 UTC (rev 495) @@ -1,56 +0,0 @@ -<?php -ini_set('error_reporting',E_ALL); - -require("xajaxtest.php"); - -?> -<!DOCTYPE html - PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <head> - <title>DBpedia Navigator</title> - <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> - <link rel="stylesheet" href="default.css"/> - <?php $xajax->printJavascript('xajax/'); ?> - </head> - <body> - -<!-- <h1>DBpedia Navigator</h1> --> -<img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> -<div id="layer" style="display:none"> - <div id="layerContent" style="display:none"></div> -</div> - -<div id="wrapper"> - <div id="leftSidebar"> - - <div class="box" id="concept"> - <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Learned Concept</td><td class="right"><input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /></td></tr></table></div> - <div class="boxcontent"> - <div id="conceptcontent" style="display:none"></div> - <div id="loadingConcept" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> - </div> <!-- boxcontent --> - </div> <!-- box --> - - </div><!-- END leftSidebar --> - - <div id="content"> - <div class="box"> - <div class="boxtitle" id="ArticleTitle">Welcome</div> - <div class="boxcontent" id="article"> - <div id="articlecontent" style="display:block"> - <br /><br /> - Verz\xF6gerung - </div> - <div id="loadingArticle" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> - </div> <!-- boxcontent --> - </div> <!-- box --> - </div><!-- content --> - - <!-- <div id="clear"></div> --> - -</div><!-- wrapper --> - </body> -</html> - \ No newline at end of file Deleted: trunk/src/dbpedia-navigator/xajaxtest.php =================================================================== --- trunk/src/dbpedia-navigator/xajaxtest.php 2008-02-05 11:43:54 UTC (rev 494) +++ trunk/src/dbpedia-navigator/xajaxtest.php 2008-02-05 15:38:39 UTC (rev 495) @@ -1,17 +0,0 @@ -<?php -require_once ("xajax/xajax_core/xajax.inc.php"); -$xajax = new xajax(); -$xajax->configureMany(array('debug'=>true)); -$xajax->registerFunction('learnConcept'); -$xajax->processRequest(); - -function learnConcept() -{ - $start=microtime(true); - $client=new SoapClient("main.wsdl"); - $id=$client->generateID(); - $objResponse=new xajaxResponse(); - $objResponse->append("articlecontent","innerHTML",microtime(true)-$start); - return $objResponse; -} -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 11:44:12
|
Revision: 494 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=494&view=rev Author: sknappe Date: 2008-02-05 03:43:54 -0800 (Tue, 05 Feb 2008) Log Message: ----------- Testklasse f?\195?\188r Aufrufen eines Webservices und Verz?\195?\182gerung beim Fertigladen. Added Paths: ----------- trunk/src/dbpedia-navigator/SoapTest.php Added: trunk/src/dbpedia-navigator/SoapTest.php =================================================================== --- trunk/src/dbpedia-navigator/SoapTest.php (rev 0) +++ trunk/src/dbpedia-navigator/SoapTest.php 2008-02-05 11:43:54 UTC (rev 494) @@ -0,0 +1,7 @@ +<?php + $start=microtime(true); + $client = new SoapClient("http://www.foreclosuredatabank.com/soapserver.php?wsdl"); + print($client->latestProperties('33149')); + $stop=microtime(true)-$start; + print "<br/>".$stop; +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 11:36:50
|
Revision: 493 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=493&view=rev Author: sknappe Date: 2008-02-05 03:36:44 -0800 (Tue, 05 Feb 2008) Log Message: ----------- Modified Paths: -------------- trunk/src/dbpedia-navigator/indextest.php Modified: trunk/src/dbpedia-navigator/indextest.php =================================================================== --- trunk/src/dbpedia-navigator/indextest.php 2008-02-05 11:35:35 UTC (rev 492) +++ trunk/src/dbpedia-navigator/indextest.php 2008-02-05 11:36:44 UTC (rev 493) @@ -41,9 +41,7 @@ <div class="boxcontent" id="article"> <div id="articlecontent" style="display:block"> <br /><br /> - Welcome to the DBpedia Navigator interface! DBpedia Navigator allows you to search DBpedia - and uses the background knowledge in DBpedia to suggest possible interesting navigation - links. + Verz\xF6gerung </div> <div id="loadingArticle" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> </div> <!-- boxcontent --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 11:35:38
|
Revision: 492 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=492&view=rev Author: sknappe Date: 2008-02-05 03:35:35 -0800 (Tue, 05 Feb 2008) Log Message: ----------- time is measured Modified Paths: -------------- trunk/src/dbpedia-navigator/xajaxtest.php Modified: trunk/src/dbpedia-navigator/xajaxtest.php =================================================================== --- trunk/src/dbpedia-navigator/xajaxtest.php 2008-02-05 11:34:00 UTC (rev 491) +++ trunk/src/dbpedia-navigator/xajaxtest.php 2008-02-05 11:35:35 UTC (rev 492) @@ -7,10 +7,11 @@ function learnConcept() { + $start=microtime(true); $client=new SoapClient("main.wsdl"); $id=$client->generateID(); $objResponse=new xajaxResponse(); - $objResponse->append("articlecontent","innerHTML","Test"); + $objResponse->append("articlecontent","innerHTML",microtime(true)-$start); return $objResponse; } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-02-05 11:34:02
|
Revision: 491 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=491&view=rev Author: sknappe Date: 2008-02-05 03:34:00 -0800 (Tue, 05 Feb 2008) Log Message: ----------- verz?\195?\182gerungstest Added Paths: ----------- trunk/src/dbpedia-navigator/indextest.php trunk/src/dbpedia-navigator/xajaxtest.php Added: trunk/src/dbpedia-navigator/indextest.php =================================================================== --- trunk/src/dbpedia-navigator/indextest.php (rev 0) +++ trunk/src/dbpedia-navigator/indextest.php 2008-02-05 11:34:00 UTC (rev 491) @@ -0,0 +1,58 @@ +<?php +ini_set('error_reporting',E_ALL); + +require("xajaxtest.php"); + +?> +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <title>DBpedia Navigator</title> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + <link rel="stylesheet" href="default.css"/> + <?php $xajax->printJavascript('xajax/'); ?> + </head> + <body> + +<!-- <h1>DBpedia Navigator</h1> --> +<img src="images/dbpedia_navigator.png" alt="DBpedia Navigator" style="padding:5px" /> +<div id="layer" style="display:none"> + <div id="layerContent" style="display:none"></div> +</div> + +<div id="wrapper"> + <div id="leftSidebar"> + + <div class="box" id="concept"> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Learned Concept</td><td class="right"><input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /></td></tr></table></div> + <div class="boxcontent"> + <div id="conceptcontent" style="display:none"></div> + <div id="loadingConcept" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> + </div> <!-- boxcontent --> + </div> <!-- box --> + + </div><!-- END leftSidebar --> + + <div id="content"> + <div class="box"> + <div class="boxtitle" id="ArticleTitle">Welcome</div> + <div class="boxcontent" id="article"> + <div id="articlecontent" style="display:block"> + <br /><br /> + Welcome to the DBpedia Navigator interface! DBpedia Navigator allows you to search DBpedia + and uses the background knowledge in DBpedia to suggest possible interesting navigation + links. + </div> + <div id="loadingArticle" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> + </div> <!-- boxcontent --> + </div> <!-- box --> + </div><!-- content --> + + <!-- <div id="clear"></div> --> + +</div><!-- wrapper --> + </body> +</html> + \ No newline at end of file Added: trunk/src/dbpedia-navigator/xajaxtest.php =================================================================== --- trunk/src/dbpedia-navigator/xajaxtest.php (rev 0) +++ trunk/src/dbpedia-navigator/xajaxtest.php 2008-02-05 11:34:00 UTC (rev 491) @@ -0,0 +1,16 @@ +<?php +require_once ("xajax/xajax_core/xajax.inc.php"); +$xajax = new xajax(); +$xajax->configureMany(array('debug'=>true)); +$xajax->registerFunction('learnConcept'); +$xajax->processRequest(); + +function learnConcept() +{ + $client=new SoapClient("main.wsdl"); + $id=$client->generateID(); + $objResponse=new xajaxResponse(); + $objResponse->append("articlecontent","innerHTML","Test"); + return $objResponse; +} +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-04 18:56:24
|
Revision: 490 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=490&view=rev Author: jenslehmann Date: 2008-02-04 10:56:10 -0800 (Mon, 04 Feb 2008) Log Message: ----------- started cross validator (not working yet) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-04 14:54:07 UTC (rev 489) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-04 18:56:10 UTC (rev 490) @@ -94,6 +94,10 @@ private static Logger logger = Logger.getRootLogger(); + private LearningAlgorithm la; + private LearningProblem lp; + private ReasoningService rs; + /** * Entry point for CLI interface. * @@ -101,12 +105,11 @@ */ public static void main(String[] args) { File file = new File(args[args.length - 1]); - String baseDir = file.getParentFile().getPath(); - + boolean inQueryMode = false; if (args.length > 1 && args[0].equals("-q")) inQueryMode = true; - + // create logger (a simple logger which outputs // its messages to the console) SimpleLayout layout = new SimpleLayout(); @@ -115,6 +118,17 @@ logger.addAppender(consoleAppender); logger.setLevel(Level.INFO); + Start start = new Start(file); + start.start(inQueryMode); + } + + /** + * Initialise all components based on conf file. + * @param file Conf file to read. + */ + public Start(File file) { + String baseDir = file.getParentFile().getPath(); + // create component manager instance System.out.print("starting component manager ... "); long cmStartTime = System.nanoTime(); @@ -161,12 +175,11 @@ ReasonerComponent reasoner = cm.reasoner(reasonerClass, sources); configureComponent(cm, reasoner, componentPrefixMapping, parser); initComponent(cm, reasoner); - ReasoningService rs = cm.reasoningService(reasoner); + rs = cm.reasoningService(reasoner); // step 3: detect learning problem ConfFileOption problemOption = parser.getConfOptionsByName("problem"); Class<? extends LearningProblem> lpClass = null; - LearningProblem lp = null; if (problemOption == null || problemOption.getStringValue().equals("posNegDefinition")) lpClass = PosNegDefinitionLP.class; else if (problemOption.getStringValue().equals("posNegInclusion")) @@ -187,7 +200,6 @@ // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); - LearningAlgorithm la = null; Class<? extends LearningAlgorithm> laClass = null; if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; @@ -229,8 +241,10 @@ } // handle any CLI options - processCLIOptions(cm, parser, rs); - + processCLIOptions(cm, parser, rs); + } + + public void start(boolean inQueryMode) { if (inQueryMode) processQueryMode(lp, rs); else { @@ -240,10 +254,9 @@ long algDuration = System.nanoTime() - algStartTime; printConclusions(rs, algDuration); - } - + } } - + // creates a mapping from components to option prefix strings private static Map<Class<? extends Component>, String> createComponentPrefixMapping() { Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); @@ -693,4 +706,8 @@ System.exit(0); } + public LearningAlgorithm getLearningAlgorithm() { + return la; + } + } Added: trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-04 18:56:10 UTC (rev 490) @@ -0,0 +1,69 @@ +/** + * 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/>. + * + */ +package org.dllearner.utilities; + +import java.io.File; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.dllearner.cli.Start; +import org.dllearner.core.LearningAlgorithm; + +/** + * Performs cross validation for the given problem. + * + * @author Jens Lehmann + * + */ +public class CrossValidation { + + private static Logger logger = Logger.getRootLogger(); + + public static void main(String[] args) { + File file = new File(args[0]); + + int folds = 10; + if(args.length > 1) + folds = Integer.parseInt(args[1]); + + // create logger (a simple logger which outputs + // its messages to the console) + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.INFO); + + new CrossValidation(file, folds); + + } + + public CrossValidation(File file, int folds) { + Start start = new Start(file); + LearningAlgorithm la = start.getLearningAlgorithm(); + + for(int currFold=0; currFold<folds; currFold++) { + la.start(); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-02-04 14:54:12
|
Revision: 489 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=489&view=rev Author: jenslehmann Date: 2008-02-04 06:54:07 -0800 (Mon, 04 Feb 2008) Log Message: ----------- - moved all tests to org.dllearner.test - some cleanup, fixed warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/server/ClientState.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java trunk/src/dl-learner/org/dllearner/test/junit/ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java trunk/src/dl-learner/org/dllearner/test/junit/package.html Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/ trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java trunk/src/dl-learner/org/dllearner/test/ComponentTests.java trunk/src/dl-learner/org/dllearner/test/package.html Deleted: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,84 +0,0 @@ -/** - * Copyright (C) 2007, 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/>. - * - */ -package org.dllearner.core; - -import java.io.File; -import java.util.Set; -import java.util.TreeSet; - -import org.dllearner.algorithms.RandomGuesser; -import org.dllearner.kb.OWLFile; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.reasoning.DIGReasoner; - -/** - * Test for component based design. - * - * @author Jens Lehmann - * - */ -public class ComponentTest { - - /** - * @param args - */ - public static void main(String[] args) { - - // get singleton instance of component manager - ComponentManager cm = ComponentManager.getInstance(); - - // create knowledge source - KnowledgeSource source = cm.knowledgeSource(OWLFile.class); - String example = "examples/father.owl"; - cm.applyConfigEntry(source, "url", new File(example).toURI().toString()); - source.init(); - - // create DIG reasoning service with standard settings - ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); - // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); - reasoner.init(); - ReasoningService rs = cm.reasoningService(reasoner); - - // create a learning problem and set positive and negative examples - LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); - Set<String> positiveExamples = new TreeSet<String>(); - positiveExamples.add("http://example.com/father#stefan"); - positiveExamples.add("http://example.com/father#markus"); - positiveExamples.add("http://example.com/father#martin"); - Set<String> negativeExamples = new TreeSet<String>(); - negativeExamples.add("http://example.com/father#heinz"); - negativeExamples.add("http://example.com/father#anna"); - negativeExamples.add("http://example.com/father#michelle"); - cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); - cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); - lp.init(); - - // create the learning algorithm - LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); - cm.applyConfigEntry(la, "numberOfTrees", 100); - cm.applyConfigEntry(la, "maxDepth", 5); - la.init(); - - // start the algorithm and print the best concept found - la.start(); - System.out.println(la.getBestSolution()); - } - -} Modified: trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-02-04 14:54:07 UTC (rev 489) @@ -34,6 +34,7 @@ } // method to start thread + @Override public void run() { if (config.getLearningAlgorithm() != null) config.getLearningAlgorithm().start(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-02-04 14:54:07 UTC (rev 489) @@ -160,20 +160,6 @@ } /** - * sends a query and returns complicated Jena List with ResultBindings - * - * - * @return jena List<ResultBinding> - */ - @Deprecated - @SuppressWarnings( { "unchecked" }) - public List<ResultBinding> getAsList() { - if (rs == null) - this.send(); - return ResultSetFormatter.toList(rs); - } - - /** * Converts Jena result set to JSON. * * @param resultSet The result set to transform. Deleted: trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,65 +0,0 @@ -package org.dllearner.reasoning; - -import org.semanticweb.owl.model.*; -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.inference.OWLReasoner; -import org.semanticweb.owl.inference.OWLReasonerException; - -import java.net.URI; -import java.util.HashSet; -import java.util.Set; -import java.io.File; - -public class FaCTBugDemo { - - public static void main(String[] args) { - - try { - URI uri = new File("examples/father.owl").toURI(); - - // Create our ontology manager in the usual way. - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - - // Load a copy of the pizza ontology. We'll load the ontology from the web. - OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri); - - OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); - // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); - - // seems to be needed for some reason although no ontology is imported - Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); - reasoner.loadOntologies(importsClosure); - - reasoner.classify(); - reasoner.realise(); - - OWLDataFactory factory = manager.getOWLDataFactory(); - - OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male")); - OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild")); - OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing()); - Set<OWLDescription> set = new HashSet<OWLDescription>(); - set.add(male); - set.add(hasSomeChild); - OWLDescription father = factory.getOWLObjectIntersectionOf(set); - OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin")); - - if(reasoner.hasType(martin, father, false)) - System.out.println("positive result"); // Pellet 1.5.1 (correct) - else - System.out.println("negative result"); // FaCT++ 1.10 - - } - catch(UnsupportedOperationException exception) { - System.out.println("Unsupported reasoner operation."); - } - catch(OWLReasonerException ex) { - System.out.println("Reasoner error: " + ex.getMessage()); - } - catch (OWLOntologyCreationException e) { - System.out.println("Could not load the pizza ontology: " + e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - } - } -} Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-02-04 14:54:07 UTC (rev 489) @@ -34,7 +34,6 @@ import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.kb.sparql.SparqlQueryThreaded; /** Deleted: trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,39 +0,0 @@ -/** - * 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/>. - * - */ -package org.dllearner.test; - -import org.junit.runner.JUnitCore; - -/** - * Class designed to run all DL-Learner component tests. Note, - * that in Eclipse (and similar in other IDEs) you can run - * JUnit tests by clicking on a file containing methods annotated - * with @Test and "Run As JUnit Test". - * - * @author Jens Lehmann - * - */ -public class AllTestsRunner { - - public static void main(String[] args) { - JUnitCore.main("org.dllearner.test.ComponentTests"); - } - -} Copied: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java (from rev 488, trunk/src/dl-learner/org/dllearner/core/ComponentTest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,90 @@ +/** + * Copyright (C) 2007, 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/>. + * + */ +package org.dllearner.test; + +import java.io.File; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.algorithms.RandomGuesser; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.reasoning.DIGReasoner; + +/** + * Test for component based design. + * + * @author Jens Lehmann + * + */ +public class ComponentTest { + + /** + * @param args + */ + public static void main(String[] args) { + + // get singleton instance of component manager + ComponentManager cm = ComponentManager.getInstance(); + + // create knowledge source + KnowledgeSource source = cm.knowledgeSource(OWLFile.class); + String example = "examples/father.owl"; + cm.applyConfigEntry(source, "url", new File(example).toURI().toString()); + source.init(); + + // create DIG reasoning service with standard settings + ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); + // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); + reasoner.init(); + ReasoningService rs = cm.reasoningService(reasoner); + + // create a learning problem and set positive and negative examples + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + Set<String> positiveExamples = new TreeSet<String>(); + positiveExamples.add("http://example.com/father#stefan"); + positiveExamples.add("http://example.com/father#markus"); + positiveExamples.add("http://example.com/father#martin"); + Set<String> negativeExamples = new TreeSet<String>(); + negativeExamples.add("http://example.com/father#heinz"); + negativeExamples.add("http://example.com/father#anna"); + negativeExamples.add("http://example.com/father#michelle"); + cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); + cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); + lp.init(); + + // create the learning algorithm + LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + cm.applyConfigEntry(la, "numberOfTrees", 100); + cm.applyConfigEntry(la, "maxDepth", 5); + la.init(); + + // start the algorithm and print the best concept found + la.start(); + System.out.println(la.getBestSolution()); + } + +} Deleted: trunk/src/dl-learner/org/dllearner/test/ComponentTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTests.java 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTests.java 2008-02-04 14:54:07 UTC (rev 489) @@ -1,54 +0,0 @@ -/** - * 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/>. - * - */ -package org.dllearner.test; - -import java.util.List; - -import org.dllearner.core.Component; -import org.dllearner.core.ComponentManager; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * A suite of JUnit tests related to the DL-Learner component architecture. - * - * @author Jens Lehmann - * - */ -public class ComponentTests { - - /** - * Checks whether all components implement the getName() method. While it - * cannot be enforced to implement a static method, it should be done (e.g. - * to be used as label for the component in GUIs). - */ - @Test - public void nameTest() { - String defaultName = Component.getName(); - ComponentManager cm = ComponentManager.getInstance(); - List<Class<? extends Component>> components = cm.getComponents(); - for (Class<? extends Component> component : components) { - String componentName = cm.getComponentName(component); - assertFalse(component + " does not overwrite getName().", componentName - .equals(defaultName)); - } - } - -} Copied: trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java (from rev 488, trunk/src/dl-learner/org/dllearner/reasoning/FaCTBugDemo.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/FaCTBugDemo.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,65 @@ +package org.dllearner.test; + +import org.semanticweb.owl.model.*; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.inference.OWLReasoner; +import org.semanticweb.owl.inference.OWLReasonerException; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; +import java.io.File; + +public class FaCTBugDemo { + + public static void main(String[] args) { + + try { + URI uri = new File("examples/father.owl").toURI(); + + // Create our ontology manager in the usual way. + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + + // Load a copy of the pizza ontology. We'll load the ontology from the web. + OWLOntology ont = manager.loadOntologyFromPhysicalURI(uri); + + OWLReasoner reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); + // OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); + + // seems to be needed for some reason although no ontology is imported + Set<OWLOntology> importsClosure = manager.getImportsClosure(ont); + reasoner.loadOntologies(importsClosure); + + reasoner.classify(); + reasoner.realise(); + + OWLDataFactory factory = manager.getOWLDataFactory(); + + OWLClass male = factory.getOWLClass(URI.create("http://example.com/father#male")); + OWLObjectProperty hasChild = factory.getOWLObjectProperty(URI.create("http://example.com/father#hasChild")); + OWLObjectSomeRestriction hasSomeChild = factory.getOWLObjectSomeRestriction(hasChild, factory.getOWLThing()); + Set<OWLDescription> set = new HashSet<OWLDescription>(); + set.add(male); + set.add(hasSomeChild); + OWLDescription father = factory.getOWLObjectIntersectionOf(set); + OWLIndividual martin = factory.getOWLIndividual(URI.create("http://example.com/father#martin")); + + if(reasoner.hasType(martin, father, false)) + System.out.println("positive result"); // Pellet 1.5.1 (correct) + else + System.out.println("negative result"); // FaCT++ 1.10 + + } + catch(UnsupportedOperationException exception) { + System.out.println("Unsupported reasoner operation."); + } + catch(OWLReasonerException ex) { + System.out.println("Reasoner error: " + ex.getMessage()); + } + catch (OWLOntologyCreationException e) { + System.out.println("Could not load the pizza ontology: " + e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Added: trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/JenaHTTPTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,102 @@ +package org.dllearner.test; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URLEncoder; + +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +public class JenaHTTPTest { + public static void main(String[] args) throws Exception{ + + String query="SELECT DISTINCT ?object\n"+ + "FROM <http://dbpedia.org>\n"+ + "WHERE { <http://dbpedia.org/resource/Leipzig> <http://www.w3.org/2000/01/rdf-schema#label> ?object}\n"; + + double time=0; + for (int i=0; i<101; i++) + { + if (i!=0) time+=JenaHTTPTest.httpQuery(query); + } + time=time/100; + System.out.println("Durchschnittliche Zeit f�r eine Anfrage per Http-Methode: "+time); + + time=0; + for (int i=0; i<101; i++) + { + if (i!=0) time+=JenaHTTPTest.jenaQuery(query); + } + time=time/100; + System.out.println("Durchschnittliche Zeit f�r eine Anfrage per Jena-Methode: "+time); + } + + private static double jenaQuery(String query) + { + double start=System.currentTimeMillis(); + QueryEngineHTTP queryExecution=new QueryEngineHTTP("http://localhost:8890/sparql",query); + queryExecution.addDefaultGraph("http://dbpedia.org"); + // Jena access to DBpedia SPARQL endpoint + // ResultSet rs = + queryExecution.execSelect(); + double end=System.currentTimeMillis(); + return ((end-start)/1000); + } + + private static double httpQuery(String query) throws Exception + { + char value[]={13,10}; + String cut=new String(value); + String test="GET /sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + URLEncoder.encode(query, "UTF-8")+ + "&format=application%2Fsparql-results%2Bxml HTTP/1.1"+cut+ + "Host: localhost"+cut+ + "Connection: close"+cut+ + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"+cut+ + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"+cut+ + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"+cut+ + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"+cut+ + cut; + String retval=""; + // + double start=System.currentTimeMillis(); + byte resp[]=null; + + try{ + Socket SparqlServer=new Socket(InetAddress.getByName("localhost"),8890); + String request=test; + // send request + (SparqlServer.getOutputStream()).write(request.getBytes()); + + //get Response + resp=readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); + retval=new String(resp); + retval=retval.substring(retval.indexOf(cut+""+cut)+4); + + SparqlServer.close(); + } catch (Exception e){} + double end=System.currentTimeMillis(); + return (end-start)/1000; + } + + private static byte[] readBuffer(InputStream IS) + throws IOException{ + byte buffer[] = new byte[0xffff]; + int nbytes=0; + byte resp[]=new byte[0]; + while ((nbytes=IS.read(buffer))!=-1) { + byte tmp[]=new byte[resp.length+nbytes]; + int i=0; + for (;i<resp.length;i++){ + tmp[i]=resp[i]; + } + for(int a=0;a<nbytes;a++,i++){ + tmp[i]=buffer[a]; + } + resp=tmp; + } + return resp; + } +} Copied: trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java (from rev 488, trunk/src/dl-learner/org/dllearner/kb/sparql/test/JenaQueryToResultSpeedTest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/JenaQueryToResultSpeedTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,163 @@ +/** + * 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/>. + * + */ +package org.dllearner.test; + +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; + + +public class JenaQueryToResultSpeedTest { + static boolean print_flag=false; + + public static void main(String[] args) { + + String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " + + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" + + "SELECT ?episode ?chalkboard_gag WHERE { ?episode skos:subject" + + " <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>." + + " ?episode dbpedia2:blackboard ?chalkboard_gag }"; + + int howOften=20; + testJenaAsXML(howOften, queryString); + testJenaAsList(howOften, queryString); + testJenaAsJSON(howOften, queryString); + testJenaAsJSONandBack(howOften, queryString); + + + + // compareResults( queryString); + + } + + + public static void testJenaAsXML(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + ResultSet rs = sqJena.send(); + SparqlQuery.getAsXMLString(rs); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + rs = sqJena.send(); + SparqlQuery.getAsXMLString(rs); + p("Jena as XML needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as XML total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + public static void testJenaAsList(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + //sqJena.getAsList(); + sqJena.send(); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + // sqJena.getAsList(); + ResultSet rs = sqJena.send(); + ResultSetFormatter.toList(rs); + p("Jena as List needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as List total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + public static void testJenaAsJSON(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + ResultSet rs = sqJena.send(); + SparqlQuery.getAsJSON(rs); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + rs = sqJena.send(); + SparqlQuery.getAsJSON(rs); + p("Jena as JSON needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as JSON total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + public static void testJenaAsJSONandBack(int howOften, String queryString){ + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // first query is not counted + ResultSet rs = sqJena.send(); + SparqlQuery.getAsJSON(rs); + long now = System.currentTimeMillis(); + long tmp = now; + for (int i = 0; i < howOften; i++) { + + // System.out.println(sqJena.getAsJSON()); + rs = sqJena.send(); + String json = SparqlQuery.getAsJSON(rs); + SparqlQuery.JSONtoResultSet(json); + p("Jena as JSON and back needed: " + + (System.currentTimeMillis() - tmp)); + tmp = System.currentTimeMillis(); + + } + long total=System.currentTimeMillis() - now; + System.out.println("Jena as JSON and back total: " + total + + " ms , average: "+ (total/howOften) ); + + } + + + public static void compareResults(String queryString) { + SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena = new SparqlQuery(queryString, sse); + // SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); + + ResultSet rs = sqJena.send(); + System.out.println(SparqlQuery.getAsXMLString(rs)); + // System.out.println(sqConv.getAsXMLString("")); + + } + + static void p(String s) { + if (print_flag) + System.out.println(s); + } +} Added: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,69 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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/>. + * + */ +package org.dllearner.test; + +import java.io.File; +import java.io.FileWriter; +import java.net.URI; +import java.util.LinkedList; + +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.Manipulator; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.utilities.StringTuple; + +/** + * Test class, uses the whole thing + * + * @author Sebastian Hellmann + * + */ +public class SparqlExtractionTest { + + public static void main(String[] args) { + System.out.println("Start"); + // String test2 = "http://www.extraction.org/config#dbpediatest"; + // String test = "http://www.extraction.org/config#localjoseki"; + try { + // URI u = new URI(test); + Manager m = new Manager(); + // m.usePredefinedConfiguration(u); + + URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); + m.useConfiguration( + SparqlQueryType.getFilterByNumber(1),SparqlEndpoint.getEndpointByNumber(1), + new Manipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()), + 1,true,true); + //, , + //manipulator, recursiondepth, getAllSuperClasses, closeAfterRecursion) + + String filename = System.currentTimeMillis() + ".nt"; + FileWriter fw = new FileWriter(new File(filename), true); + fw.write(m.extract(u2)); + fw.flush(); + fw.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} Copied: trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java (from rev 488, trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/AllTestsRunner.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,39 @@ +/** + * 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/>. + * + */ +package org.dllearner.test.junit; + +import org.junit.runner.JUnitCore; + +/** + * Class designed to run all DL-Learner component tests. Note, + * that in Eclipse (and similar in other IDEs) you can run + * JUnit tests by clicking on a file containing methods annotated + * with @Test and "Run As JUnit Test". + * + * @author Jens Lehmann + * + */ +public class AllTestsRunner { + + public static void main(String[] args) { + JUnitCore.main("org.dllearner.test.ComponentTests"); + } + +} Copied: trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java (from rev 488, trunk/src/dl-learner/org/dllearner/test/ComponentTests.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ComponentTests.java 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,54 @@ +/** + * 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/>. + * + */ +package org.dllearner.test.junit; + +import java.util.List; + +import org.dllearner.core.Component; +import org.dllearner.core.ComponentManager; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * A suite of JUnit tests related to the DL-Learner component architecture. + * + * @author Jens Lehmann + * + */ +public class ComponentTests { + + /** + * Checks whether all components implement the getName() method. While it + * cannot be enforced to implement a static method, it should be done (e.g. + * to be used as label for the component in GUIs). + */ + @Test + public void nameTest() { + String defaultName = Component.getName(); + ComponentManager cm = ComponentManager.getInstance(); + List<Class<? extends Component>> components = cm.getComponents(); + for (Class<? extends Component> component : components) { + String componentName = cm.getComponentName(component); + assertFalse(component + " does not overwrite getName().", componentName + .equals(defaultName)); + } + } + +} Copied: trunk/src/dl-learner/org/dllearner/test/junit/package.html (from rev 488, trunk/src/dl-learner/org/dllearner/test/package.html) =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/package.html 2008-02-04 14:54:07 UTC (rev 489) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>DL-Learner JUnit tests.</p> +</body> +</html> \ No newline at end of file Deleted: trunk/src/dl-learner/org/dllearner/test/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/test/package.html 2008-02-04 11:38:43 UTC (rev 488) +++ trunk/src/dl-learner/org/dllearner/test/package.html 2008-02-04 14:54:07 UTC (rev 489) @@ -1,7 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> -<html> -<head></head> -<body bgcolor="white"> -<p>DL-Learner JUnit tests.</p> -</body> -</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-04 11:38:57
|
Revision: 488 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=488&view=rev Author: tonytacker Date: 2008-02-04 03:38:43 -0800 (Mon, 04 Feb 2008) Log Message: ----------- full width for optionPanel Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-04 11:12:46 UTC (rev 487) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-04 11:38:43 UTC (rev 488) @@ -68,7 +68,6 @@ // add scrollPane JScrollPane centerScroller = new JScrollPane(centerPanel); centerScroller.setPreferredSize(new Dimension(400, 200)); - // add Panels add(centerScroller, BorderLayout.CENTER); Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-04 11:12:46 UTC (rev 487) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-04 11:38:43 UTC (rev 488) @@ -44,11 +44,11 @@ private Config config = new Config(); - private JPanel tab1 = new JPanel(); - private JPanel tab2 = new JPanel(); - private JPanel tab3 = new JPanel(); - private JPanel tab4 = new JPanel(); - private JPanel tab5 = new JPanel(); + private JPanel tab1; + private JPanel tab2; + private JPanel tab3; + private JPanel tab4; + private JPanel tab5; private JMenuBar menuBar = new JMenuBar(); private JMenu menuFile = new JMenu("File"); @@ -61,11 +61,11 @@ this.setLocationByPlatform(true); this.setSize(800, 600); - tab1.add(new KnowledgeSourcePanel(config)); - tab2.add(new ReasonerPanel(config)); - tab3.add(new LearningProblemPanel(config)); - tab4.add(new LearningAlgorithmPanel(config)); - tab5.add(new RunPanel(config)); + tab1 = new KnowledgeSourcePanel(config); + tab2 = new ReasonerPanel(config); + tab3 = new LearningProblemPanel(config); + tab4 = new LearningAlgorithmPanel(config); + tab5 = new RunPanel(config); tabPane.addTab("Knowledge Source", tab1); tabPane.addTab("Reasoner", tab2); tabPane.addTab("Learning Problem", tab3); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-04 11:12:58
|
Revision: 487 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=487&view=rev Author: tonytacker Date: 2008-02-04 03:12:46 -0800 (Mon, 04 Feb 2008) Log Message: ----------- could be a way to change set<String> - change button should later open an extra window Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-03 04:55:57 UTC (rev 486) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-04 11:12:46 UTC (rev 487) @@ -68,6 +68,7 @@ super(new BorderLayout()); this.config = config; + problems = config.getComponentManager().getLearningProblems(); initButton = new JButton("Init LearningProblem"); initButton.addActionListener(this); @@ -78,8 +79,6 @@ choosePanel.add(getInstancesButton); cb.addActionListener(this); - problems = config.getComponentManager().getLearningProblems(); - // add into comboBox for (int i = 0; i < problems.size(); i++) { cb.addItem(config.getComponentManager().getComponentName( @@ -139,6 +138,10 @@ for (int i : selectedIndices) posExampleSet.add(individuals.get(i).toString()); config.setPosExampleSet(posExampleSet); + config.getComponentManager().applyConfigEntry( + config.getLearningProblem(), "positiveExamples", + config.getPosExampleSet()); + updateOptionPanel(); } }); @@ -153,6 +156,10 @@ for (int i : selectedIndices) negExampleSet.add(individuals.get(i).toString()); config.setNegExampleSet(negExampleSet); + config.getComponentManager().applyConfigEntry( + config.getLearningProblem(), "negativeExamples", + config.getNegExampleSet()); + updateOptionPanel(); } }); @@ -219,10 +226,8 @@ * after this, next tab can be used */ public void init() { + config.getComponentManager().applyConfigEntry( - config.getLearningProblem(), "positiveExamples", - config.getPosExampleSet()); - config.getComponentManager().applyConfigEntry( config.getLearningProblem(), "negativeExamples", config.getNegExampleSet()); config.getLearningProblem().init(); Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-03 04:55:57 UTC (rev 486) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-04 11:12:46 UTC (rev 487) @@ -109,11 +109,11 @@ "StringConfigOption")) { widgetPanel = new WidgetPanelString(config, component, componentOption, optionList.get(i)); -/* } else if (optionList.get(i).getClass().toString().contains( + } else if (optionList.get(i).getClass().toString().contains( "StringSetConfigOption")) { widgetPanel = new WidgetPanelStringSet(config, component, componentOption, optionList.get(i)); -*/ } else { + } else { widgetPanel = new WidgetPanelDefault(config, component, componentOption, optionList.get(i)); } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-02-03 04:55:57 UTC (rev 486) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-02-04 11:12:46 UTC (rev 487) @@ -21,15 +21,18 @@ */ import java.awt.BorderLayout; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Color; -import java.util.Set; +import java.util.*; -//import javax.swing.JTextField; +import javax.swing.DefaultListModel; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JButton; +import javax.swing.JScrollPane; import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; @@ -51,13 +54,15 @@ private ConfigOption<?> configOption; private JLabel nameLabel; private JPanel widgetPanel = new JPanel(); - private JButton setButton = new JButton("Set"); + private JButton changeButton = new JButton("Change"); private Component component; private Class<? extends Component> componentOption; - private Set<String> value; - //private JTextField stringField = new JTextField(15); + private Set<String> value = new HashSet<String>(); + private JList stringList = new JList(); + private DefaultListModel listModel = new DefaultListModel(); + public WidgetPanelStringSet(Config config, Component component, Class<? extends Component> componentOption, ConfigOption<?> configOption) { @@ -76,7 +81,7 @@ } public void actionPerformed(ActionEvent e) { - if (e.getSource() == setButton) { + if (e.getSource() == changeButton) { setEntry(); } } @@ -88,19 +93,40 @@ widgetPanel.add(nameLabel); } + @SuppressWarnings("unchecked") @Override protected void showThingToChange() { if (component != null) { // StringSetConfigOption if (configOption.getClass().toString().contains( "StringSetConfigOption")) { - setButton.addActionListener(this); - //widgetPanel.add(stringField); - widgetPanel.add(setButton); + // previous set value + if (configOption != null) { + // take set + value = (Set<String>) config.getComponentManager() + .getConfigOptionValue(component, + configOption.getName()); + // fill list + if (value != null) { + for (Iterator<String> iterator = value.iterator(); iterator + .hasNext();) { + String item = iterator.next(); + listModel.addElement(item); + } + } + } + stringList.setModel(listModel); + stringList.setLayoutOrientation(JList.VERTICAL); + stringList.setVisibleRowCount(-1); + JScrollPane stringListScroller = new JScrollPane(stringList); + stringListScroller.setPreferredSize(new Dimension(200, 100)); + widgetPanel.add(stringListScroller); + widgetPanel.add(changeButton); + changeButton.addActionListener(this); } // UNKNOWN else { - JLabel notImplementedLabel = new JLabel("not a stringSet"); + JLabel notImplementedLabel = new JLabel("not a set of strings"); notImplementedLabel.setForeground(Color.RED); widgetPanel.add(notImplementedLabel); } @@ -109,31 +135,26 @@ noConfigOptionLabel.setForeground(Color.MAGENTA); widgetPanel.add(noConfigOptionLabel); } - - //System.out.println("value: " + value); - - } @Override protected void setEntry() { StringSetConfigOption specialOption; - //value = stringField.getText(); // get from input + // value = stringField.getText(); // get from input specialOption = (StringSetConfigOption) config.getComponentManager() .getConfigOption(componentOption, configOption.getName()); + try { ConfigEntry<Set<String>> specialEntry = new ConfigEntry<Set<String>>( specialOption, value); config.getComponentManager().applyConfigEntry(component, specialEntry); - System.out.println("set String: " + configOption.getName() + " = " + System.out.println("set StringSet: " + configOption.getName() + " = " + value); } catch (InvalidConfigOptionValueException s) { s.printStackTrace(); } - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-03 04:56:16
|
Revision: 486 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=486&view=rev Author: tonytacker Date: 2008-02-02 20:55:57 -0800 (Sat, 02 Feb 2008) Log Message: ----------- LearningProblemPanel works now, add WidgetPanelStringSet for StringSetConfigOption (not implemented in GUI) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-02-03 04:55:57 UTC (rev 486) @@ -124,7 +124,7 @@ return la; } - /* + /** * KnowledgeSource.init has run? * return true, if it was */ @@ -132,7 +132,7 @@ return isInit[0]; } - /* + /** * set true if you run KnowwledgeSource.init */ protected void setInitKnowledgeSource(Boolean is) { @@ -141,7 +141,7 @@ isInit[i] = false; } - /* + /** * Reasoner.init has run? * return true, if it was */ @@ -149,7 +149,7 @@ return isInit[1]; } - /* + /** * set true if you run Reasoner.init */ protected void setInitReasoner(Boolean is) { @@ -158,7 +158,7 @@ isInit[i] = false; } - /* + /** * LearningProblem.init has run? * return true, if it was */ @@ -166,7 +166,7 @@ return isInit[2]; } - /* + /** * set true if you run LearningProblem.init */ protected void setInitLearningProblem(Boolean is) { @@ -175,7 +175,7 @@ isInit[i] = false; } - /* + /** * LearningAlgorithm.init() has run? * return true, if it was */ @@ -183,7 +183,7 @@ return isInit[3]; } - /* + /** * set true if you run LearningAlgorithm.init */ protected void setLearningAlgorithm(Boolean is) { Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-03 04:55:57 UTC (rev 486) @@ -89,7 +89,7 @@ init(); } - /* + /** * after this, you can change widgets */ public void getInstances() { @@ -98,7 +98,7 @@ updateOptionPanel(); } - /* + /** * after this, next tab can be used */ public void init() { @@ -109,7 +109,7 @@ + "\n"); } - /* + /** * update OptionPanel with new selection */ public void updateOptionPanel() { Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-03 04:55:57 UTC (rev 486) @@ -82,14 +82,14 @@ // read selected Class choosenClassIndex = cb.getSelectedIndex(); - if (e.getSource() == getInstancesButton) + if (e.getSource() == getInstancesButton && config.isInitLearningProblem()) getInstances(); - if (e.getSource() == initButton && config.getURI() != null) + if (e.getSource() == initButton && config.isInitLearningProblem()) init(); } - /* + /** * after this, you can change widgets */ public void getInstances() { @@ -103,7 +103,7 @@ } } - /* + /** * after this, next tab can be used */ public void init() { @@ -112,7 +112,7 @@ } - /* + /** * update OptionPanel with new selection */ public void updateOptionPanel() { Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-03 04:55:57 UTC (rev 486) @@ -51,11 +51,11 @@ private String[] lpBoxItems = {}; private JComboBox cb = new JComboBox(lpBoxItems); private JPanel choosePanel = new JPanel(); - private JPanel centerPanel = new JPanel(); - private JPanel lpPanel = new JPanel(); + private JPanel listPanel = new JPanel(); + private JPanel initPanel = new JPanel(); private JLabel posLabel = new JLabel("positive Examples"); private JLabel negLabel = new JLabel("negative Examples"); - private JButton initButton; + private JButton initButton, getInstancesButton; private int choosenClassIndex; private List<Individual> individuals; private JList posList = new JList(); @@ -71,9 +71,12 @@ initButton = new JButton("Init LearningProblem"); initButton.addActionListener(this); - + initPanel.add(initButton); + getInstancesButton = new JButton("Get Instances"); + getInstancesButton.addActionListener(this); choosePanel.add(cb); - choosePanel.add(initButton); + choosePanel.add(getInstancesButton); + cb.addActionListener(this); problems = config.getComponentManager().getLearningProblems(); @@ -102,33 +105,29 @@ // define GridBag GridBagLayout gridbag = new GridBagLayout(); - centerPanel.setLayout(gridbag); + listPanel.setLayout(gridbag); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.anchor = GridBagConstraints.CENTER; buildConstraints(constraints, 0, 0, 1, 1, 100, 100); gridbag.setConstraints(posLabel, constraints); - centerPanel.add(posLabel); + listPanel.add(posLabel); buildConstraints(constraints, 1, 0, 1, 1, 100, 100); gridbag.setConstraints(negLabel, constraints); - centerPanel.add(negLabel); + listPanel.add(negLabel); buildConstraints(constraints, 0, 1, 1, 1, 100, 100); gridbag.setConstraints(posListScroller, constraints); - centerPanel.add(posListScroller); + listPanel.add(posListScroller); buildConstraints(constraints, 1, 1, 1, 1, 100, 100); gridbag.setConstraints(negListScroller, constraints); - centerPanel.add(negListScroller); + listPanel.add(negListScroller); - buildConstraints(constraints, 0, 2, 2, 1, 100, 100); - gridbag.setConstraints(lpPanel, constraints); - centerPanel.add(lpPanel); + add(listPanel, BorderLayout.CENTER); - add(centerPanel, BorderLayout.CENTER); - // listener for posList posList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { @@ -160,11 +159,13 @@ optionPanel = new OptionPanel(config, config.getLearningProblem(), problems.get(choosenClassIndex)); - cb.addActionListener(this); + buildConstraints(constraints, 0, 2, 2, 1, 100, 100); + gridbag.setConstraints(optionPanel, constraints); + listPanel.add(optionPanel); add(choosePanel, BorderLayout.PAGE_START); - add(centerPanel, BorderLayout.CENTER); - add(optionPanel, BorderLayout.PAGE_END); + add(listPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); } @@ -172,39 +173,14 @@ // read selected LearningProblemClass choosenClassIndex = cb.getSelectedIndex(); - // init - if (e.getSource() == initButton && config.getReasoningService() != null) { - config.setLearningProblem(config.getComponentManager() - .learningProblem(problems.get(choosenClassIndex), - config.getReasoningService())); - config.getComponentManager().applyConfigEntry( - config.getLearningProblem(), "positiveExamples", - config.getPosExampleSet()); - config.getComponentManager().applyConfigEntry( - config.getLearningProblem(), "negativeExamples", - config.getNegExampleSet()); - config.getLearningProblem().init(); - System.out.println("init LearningProblem"); - updateOptionPanel(); + if (e.getSource() == getInstancesButton && config.isInitReasoner()) + getInstances(); - // lists - if (config.getReasoningService() != null) { - // fill lists - Set<Individual> individualsSet = config.getReasoningService() - .getIndividuals(); - individuals = new LinkedList<Individual>(individualsSet); - DefaultListModel listModel = new DefaultListModel(); - for (Individual ind : individuals) { - listModel.addElement(ind); - } - posList.setModel(listModel); - negList.setModel(listModel); - } - } - + if (e.getSource() == initButton && config.isInitReasoner()) + init(); } - /* + /** * Define GridBagConstraints */ private void buildConstraints(GridBagConstraints gbc, int gx, int gy, @@ -217,6 +193,47 @@ gbc.weighty = wy; } + /** + * after this, you can change widgets + */ + public void getInstances() { + config.setLearningProblem(config.getComponentManager().learningProblem( + problems.get(choosenClassIndex), config.getReasoningService())); + // lists + if (config.getReasoningService() != null) { + // fill lists + Set<Individual> individualsSet = config.getReasoningService() + .getIndividuals(); + individuals = new LinkedList<Individual>(individualsSet); + DefaultListModel listModel = new DefaultListModel(); + for (Individual ind : individuals) { + listModel.addElement(ind); + } + posList.setModel(listModel); + negList.setModel(listModel); + } + updateOptionPanel(); + } + + /** + * after this, next tab can be used + */ + public void init() { + config.getComponentManager().applyConfigEntry( + config.getLearningProblem(), "positiveExamples", + config.getPosExampleSet()); + config.getComponentManager().applyConfigEntry( + config.getLearningProblem(), "negativeExamples", + config.getNegExampleSet()); + config.getLearningProblem().init(); + config.setInitLearningProblem(true); + System.out.println("init LearningProblem"); + + } + + /** + * update OptionPanel with new selection + */ public void updateOptionPanel() { // update OptionPanel optionPanel.update(config.getLearningProblem(), problems Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-03 04:55:57 UTC (rev 486) @@ -109,7 +109,11 @@ "StringConfigOption")) { widgetPanel = new WidgetPanelString(config, component, componentOption, optionList.get(i)); - } else { +/* } else if (optionList.get(i).getClass().toString().contains( + "StringSetConfigOption")) { + widgetPanel = new WidgetPanelStringSet(config, component, + componentOption, optionList.get(i)); +*/ } else { widgetPanel = new WidgetPanelDefault(config, component, componentOption, optionList.get(i)); } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-03 04:55:57 UTC (rev 486) @@ -93,7 +93,7 @@ init(); } - /* + /** * after this, you can change widgets */ public void getInstances() { @@ -105,7 +105,7 @@ } } - /* + /** * after this, next tab can be used */ public void init() { @@ -118,7 +118,7 @@ config.setInitReasoner(true); } - /* + /** * update OptionPanel with new selection */ public void updateOptionPanel() { Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-03 04:55:57 UTC (rev 486) @@ -120,7 +120,7 @@ widgetPanel.add(notImplementedLabel); } } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no init (Boolean)"); + JLabel noConfigOptionLabel = new JLabel("no instance (Boolean)"); noConfigOptionLabel.setForeground(Color.MAGENTA); widgetPanel.add(noConfigOptionLabel); } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java 2008-02-03 04:55:57 UTC (rev 486) @@ -121,7 +121,7 @@ widgetPanel.add(notImplementedLabel); } } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no init (Double)"); + JLabel noConfigOptionLabel = new JLabel("no instance (Double)"); noConfigOptionLabel.setForeground(Color.MAGENTA); widgetPanel.add(noConfigOptionLabel); } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-02-03 04:55:57 UTC (rev 486) @@ -122,7 +122,7 @@ widgetPanel.add(notImplementedLabel); } } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no init (Integer)"); + JLabel noConfigOptionLabel = new JLabel("no instance (Integer)"); noConfigOptionLabel.setForeground(Color.MAGENTA); widgetPanel.add(noConfigOptionLabel); } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-02 05:06:46 UTC (rev 485) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-03 04:55:57 UTC (rev 486) @@ -135,7 +135,7 @@ widgetPanel.add(notImplementedLabel); } } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel("no init (String)"); + JLabel noConfigOptionLabel = new JLabel("no instance (String)"); noConfigOptionLabel.setForeground(Color.MAGENTA); widgetPanel.add(noConfigOptionLabel); } Added: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelStringSet.java 2008-02-03 04:55:57 UTC (rev 486) @@ -0,0 +1,139 @@ +package org.dllearner.gui; + +/** + * 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/>. + * + */ + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.Color; +import java.util.Set; + +//import javax.swing.JTextField; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JButton; + +import org.dllearner.core.Component; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.config.InvalidConfigOptionValueException; + +/** + * WidgetPanelStringSet + * + * @author Tilo Hielscher + * + */ +public class WidgetPanelStringSet extends AbstractWidgetPanel implements + ActionListener { + + private static final long serialVersionUID = 7832726987046601916L; + private Config config; + private ConfigOption<?> configOption; + private JLabel nameLabel; + private JPanel widgetPanel = new JPanel(); + private JButton setButton = new JButton("Set"); + private Component component; + private Class<? extends Component> componentOption; + + private Set<String> value; + //private JTextField stringField = new JTextField(15); + + public WidgetPanelStringSet(Config config, Component component, + Class<? extends Component> componentOption, + ConfigOption<?> configOption) { + this.config = config; + this.configOption = configOption; + this.component = component; + this.componentOption = componentOption; + + showLabel(); // name of option and tooltip + showThingToChange(); // textfield, setbutton + add(widgetPanel, BorderLayout.CENTER); + } + + public JPanel getPanel() { + return this; + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == setButton) { + setEntry(); + } + } + + @Override + protected void showLabel() { + nameLabel = new JLabel(configOption.getName()); + nameLabel.setToolTipText(configOption.getDescription()); + widgetPanel.add(nameLabel); + } + + @Override + protected void showThingToChange() { + if (component != null) { + // StringSetConfigOption + if (configOption.getClass().toString().contains( + "StringSetConfigOption")) { + setButton.addActionListener(this); + //widgetPanel.add(stringField); + widgetPanel.add(setButton); + } + // UNKNOWN + else { + JLabel notImplementedLabel = new JLabel("not a stringSet"); + notImplementedLabel.setForeground(Color.RED); + widgetPanel.add(notImplementedLabel); + } + } else { // configOption == NULL + JLabel noConfigOptionLabel = new JLabel("no instance (StringSet)"); + noConfigOptionLabel.setForeground(Color.MAGENTA); + widgetPanel.add(noConfigOptionLabel); + } + + //System.out.println("value: " + value); + + + } + + @Override + protected void setEntry() { + StringSetConfigOption specialOption; + //value = stringField.getText(); // get from input + specialOption = (StringSetConfigOption) config.getComponentManager() + .getConfigOption(componentOption, configOption.getName()); + try { + ConfigEntry<Set<String>> specialEntry = new ConfigEntry<Set<String>>( + specialOption, value); + config.getComponentManager().applyConfigEntry(component, + specialEntry); + System.out.println("set String: " + configOption.getName() + " = " + + value); + } catch (InvalidConfigOptionValueException s) { + s.printStackTrace(); + } + + + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-02 05:06:49
|
Revision: 485 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=485&view=rev Author: tonytacker Date: 2008-02-01 21:06:46 -0800 (Fri, 01 Feb 2008) Log Message: ----------- changed layout- LearningProblemPanel doesn't work now - will be fixed on next commit Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-02-02 02:49:37 UTC (rev 484) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-02-02 05:06:46 UTC (rev 485) @@ -49,7 +49,9 @@ private Set<String> negExampleSet = new HashSet<String>(); private LearningProblem lp; private LearningAlgorithm la; - + private boolean[] isInit = new boolean[4]; + + protected ComponentManager getComponentManager() { return cm; } @@ -122,4 +124,70 @@ return la; } + /* + * KnowledgeSource.init has run? + * return true, if it was + */ + protected boolean isInitKnowledgeSource() { + return isInit[0]; + } + + /* + * set true if you run KnowwledgeSource.init + */ + protected void setInitKnowledgeSource(Boolean is) { + isInit[0] = is; + for (int i=1; i<4; i++) + isInit[i] = false; + } + + /* + * Reasoner.init has run? + * return true, if it was + */ + protected boolean isInitReasoner() { + return isInit[1]; + } + + /* + * set true if you run Reasoner.init + */ + protected void setInitReasoner(Boolean is) { + isInit[1] = is; + for (int i=2; i<4; i++) + isInit[i] = false; + } + + /* + * LearningProblem.init has run? + * return true, if it was + */ + protected boolean isInitLearningProblem() { + return isInit[2]; + } + + /* + * set true if you run LearningProblem.init + */ + protected void setInitLearningProblem(Boolean is) { + isInit[2] = is; + for (int i=3; i<4; i++) + isInit[i] = false; + } + + /* + * LearningAlgorithm.init() has run? + * return true, if it was + */ + protected boolean isLearningAlgorithm() { + return isInit[3]; + } + + /* + * set true if you run LearningAlgorithm.init + */ + protected void setLearningAlgorithm(Boolean is) { + isInit[3] = is; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 02:49:37 UTC (rev 484) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 05:06:46 UTC (rev 485) @@ -103,6 +103,7 @@ */ public void init() { config.getKnowledgeSource().init(); + config.setInitKnowledgeSource(true); System.out.println("init KnowledgeSource with \n" + sources.get(choosenClassIndex) + " and \n" + config.getURI() + "\n"); Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-02 02:49:37 UTC (rev 484) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-02 05:06:46 UTC (rev 485) @@ -42,7 +42,7 @@ private JPanel choosePanel = new JPanel(); private OptionPanel optionPanel; private JPanel initPanel = new JPanel(); - private JButton initButton; + private JButton initButton, getInstancesButton; private String[] cbItems = {}; private JComboBox cb = new JComboBox(cbItems); private int choosenClassIndex; @@ -51,29 +51,30 @@ super(new BorderLayout()); this.config = config; + learners = config.getComponentManager().getLearningAlgorithms(); initButton = new JButton("Init LearingAlgorithm"); initButton.addActionListener(this); - initPanel.add(initButton); + getInstancesButton = new JButton("Get Instances"); + getInstancesButton.addActionListener(this); - choosePanel.add(cb); - // add into comboBox - learners = config.getComponentManager().getLearningAlgorithms(); for (int i = 0; i < learners.size(); i++) { cb.addItem(config.getComponentManager().getComponentName( learners.get(i))); } + choosePanel.add(cb); + choosePanel.add(getInstancesButton); cb.addActionListener(this); optionPanel = new OptionPanel(config, config.getLearningAlgorithm(), learners.get(choosenClassIndex)); add(choosePanel, BorderLayout.PAGE_START); - add(initPanel, BorderLayout.CENTER); - add(optionPanel, BorderLayout.PAGE_END); + add(optionPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); } @@ -81,20 +82,42 @@ // read selected Class choosenClassIndex = cb.getSelectedIndex(); - // init - if (e.getSource() == initButton && config.getLearningProblem() != null) { + if (e.getSource() == getInstancesButton) + getInstances(); + + if (e.getSource() == initButton && config.getURI() != null) + init(); + } + + /* + * after this, you can change widgets + */ + public void getInstances() { + if (config.getLearningProblem() != null + && config.getReasoningService() != null) { config.setLearningAlgorithm(config.getComponentManager() .learningAlgorithm(learners.get(choosenClassIndex), config.getLearningProblem(), config.getReasoningService())); - System.out.println("init LearningAlgorithm"); - config.getLearningAlgorithm().init(); updateOptionPanel(); } } + /* + * after this, next tab can be used + */ + public void init() { + config.getLearningAlgorithm().init(); + System.out.println("init LearningAlgorithm"); + + } + + /* + * update OptionPanel with new selection + */ public void updateOptionPanel() { // update OptionPanel - optionPanel.update(config.getLearningAlgorithm(), learners.get(choosenClassIndex)); + optionPanel.update(config.getLearningAlgorithm(), learners + .get(choosenClassIndex)); } } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-02 02:49:37 UTC (rev 484) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-02 05:06:46 UTC (rev 485) @@ -97,9 +97,12 @@ * after this, you can change widgets */ public void getInstances() { - config.setReasoner(config.getComponentManager().reasoner( - reasoners.get(choosenClassIndex), config.getKnowledgeSource())); - updateOptionPanel(); + if (config.isInitKnowledgeSource()) { + config.setReasoner(config.getComponentManager().reasoner( + reasoners.get(choosenClassIndex), + config.getKnowledgeSource())); + updateOptionPanel(); + } } /* @@ -112,6 +115,7 @@ config.setReasoningService(config.getComponentManager() .reasoningService(config.getReasoner())); System.out.println("init ReasoningService"); + config.setInitReasoner(true); } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-02 02:49:39
|
Revision: 484 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=484&view=rev Author: tonytacker Date: 2008-02-01 18:49:37 -0800 (Fri, 01 Feb 2008) Log Message: ----------- better ReasonerPanel Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 02:17:19 UTC (rev 483) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 02:49:37 UTC (rev 484) @@ -67,9 +67,9 @@ choosePanel.add(cb); choosePanel.add(getInstancesButton); - initPanel.add(initButton); optionPanel = new OptionPanel(config, config.getKnowledgeSource(), sources.get(choosenClassIndex)); + initPanel.add(initButton); add(choosePanel, BorderLayout.PAGE_START); add(optionPanel, BorderLayout.CENTER); Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-02 02:17:19 UTC (rev 483) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-02 02:49:37 UTC (rev 484) @@ -43,7 +43,7 @@ private JPanel choosePanel = new JPanel(); private JPanel initPanel = new JPanel(); private OptionPanel optionPanel; - private JButton initButton; + private JButton initButton, getInstancesButton; private Config config; private String[] cbItems = {}; private JComboBox cb = new JComboBox(cbItems); @@ -53,15 +53,17 @@ super(new BorderLayout()); this.config = config; + reasoners = config.getComponentManager().getReasonerComponents(); initButton = new JButton("Init Reasoner"); initButton.addActionListener(this); initPanel.add(initButton); + getInstancesButton = new JButton("Get Instances"); + getInstancesButton.addActionListener(this); choosePanel.add(cb); // add into comboBox - reasoners = config.getComponentManager().getReasonerComponents(); for (int i = 0; i < reasoners.size(); i++) { cb.addItem(config.getComponentManager().getComponentName( reasoners.get(i))); @@ -70,11 +72,13 @@ optionPanel = new OptionPanel(config, config.getReasoner(), reasoners .get(choosenClassIndex)); + choosePanel.add(getInstancesButton); + cb.addActionListener(this); add(choosePanel, BorderLayout.PAGE_START); - add(initPanel, BorderLayout.CENTER); - add(optionPanel, BorderLayout.PAGE_END); + add(optionPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); } @@ -82,24 +86,40 @@ // read selected Class choosenClassIndex = cb.getSelectedIndex(); - if (e.getSource() == initButton && config.getKnowledgeSource() != null) { - // set reasoner - config.setReasoner(config.getComponentManager().reasoner( - reasoners.get(choosenClassIndex), - config.getKnowledgeSource())); - config.getReasoner().init(); + if (e.getSource() == getInstancesButton) + getInstances(); - // set ReasoningService - config.setReasoningService(config.getComponentManager() - .reasoningService(config.getReasoner())); + if (e.getSource() == initButton && config.getKnowledgeSource() != null) + init(); + } - System.out.println("init Reasoner"); - updateOptionPanel(); - } + /* + * after this, you can change widgets + */ + public void getInstances() { + config.setReasoner(config.getComponentManager().reasoner( + reasoners.get(choosenClassIndex), config.getKnowledgeSource())); + updateOptionPanel(); } + /* + * after this, next tab can be used + */ + public void init() { + config.getReasoner().init(); + System.out.println("init Reasoner"); + // set ReasoningService + config.setReasoningService(config.getComponentManager() + .reasoningService(config.getReasoner())); + System.out.println("init ReasoningService"); + } + + /* + * update OptionPanel with new selection + */ public void updateOptionPanel() { - // update OptionPanel - optionPanel.update(config.getReasoner(), reasoners.get(choosenClassIndex)); + optionPanel.update(config.getReasoner(), reasoners + .get(choosenClassIndex)); } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-02 02:17:21
|
Revision: 483 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=483&view=rev Author: tonytacker Date: 2008-02-01 18:17:19 -0800 (Fri, 01 Feb 2008) Log Message: ----------- choose now file/URI over widget in KnowledgeSourcePanel Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/RunPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-01 07:58:29 UTC (rev 482) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-02 02:17:19 UTC (rev 483) @@ -20,18 +20,11 @@ * */ -import java.io.File; import java.util.List; - import javax.swing.*; -import javax.swing.event.*; - import java.awt.BorderLayout; -import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.GridBagLayout; - import org.dllearner.core.KnowledgeSource; /** @@ -44,16 +37,14 @@ private static final long serialVersionUID = -7678275020058043937L; - private JFileChooser fc; - private JButton openButton, initButton; - private JTextField fileDisplay; + private JButton initButton, getInstancesButton; private String[] kbBoxItems = {}; private JComboBox cb = new JComboBox(kbBoxItems); - private JPanel centerPanel, choosePanel, initPanel; + private JPanel choosePanel = new JPanel(); + private JPanel initPanel = new JPanel(); private Config config; private int choosenClassIndex; private List<Class<? extends KnowledgeSource>> sources; - private JLabel infoLabel = new JLabel("choose local file or type URL"); private OptionPanel optionPanel; KnowledgeSourcePanel(final Config config) { @@ -62,77 +53,27 @@ this.config = config; sources = config.getComponentManager().getKnowledgeSources(); - fc = new JFileChooser(new File("examples/")); - openButton = new JButton("choose local file"); - openButton.addActionListener(this); - + getInstancesButton = new JButton("Get Instances"); + getInstancesButton.addActionListener(this); initButton = new JButton("Init KnowledgeSource"); initButton.addActionListener(this); - fileDisplay = new JTextField(35); - fileDisplay.setEditable(true); - - // update config if textfield fileDisplay changed - fileDisplay.getDocument().addDocumentListener(new DocumentListener() { - public void insertUpdate(DocumentEvent e) { - config.setURI(fileDisplay.getText()); - } - - public void removeUpdate(DocumentEvent e) { - config.setURI(fileDisplay.getText()); - } - - public void changedUpdate(DocumentEvent e) { - config.setURI(fileDisplay.getText()); - } - }); - // add to comboBox for (int i = 0; i < sources.size(); i++) { - // cb.addItem(sources.get(i).getSimpleName()); cb.addItem(config.getComponentManager().getComponentName( sources.get(i))); } - cb.addActionListener(this); - choosePanel = new JPanel(); choosePanel.add(cb); - - initPanel = new JPanel(); + choosePanel.add(getInstancesButton); initPanel.add(initButton); - - centerPanel = new JPanel(); - - // define GridBag - GridBagLayout gridbag = new GridBagLayout(); - centerPanel.setLayout(gridbag); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.fill = GridBagConstraints.BOTH; - constraints.anchor = GridBagConstraints.CENTER; - - buildConstraints(constraints, 0, 0, 1, 1, 100, 100); - gridbag.setConstraints(infoLabel, constraints); - centerPanel.add(infoLabel); - - buildConstraints(constraints, 0, 1, 1, 1, 100, 100); - gridbag.setConstraints(fileDisplay, constraints); - centerPanel.add(fileDisplay); - - buildConstraints(constraints, 1, 1, 1, 1, 100, 100); - gridbag.setConstraints(openButton, constraints); - centerPanel.add(openButton); - - buildConstraints(constraints, 0, 2, 2, 1, 100, 100); - gridbag.setConstraints(initPanel, constraints); - centerPanel.add(initPanel); - optionPanel = new OptionPanel(config, config.getKnowledgeSource(), sources.get(choosenClassIndex)); add(choosePanel, BorderLayout.PAGE_START); - add(centerPanel, BorderLayout.CENTER); - add(optionPanel, BorderLayout.PAGE_END); + add(optionPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); choosenClassIndex = cb.getSelectedIndex(); } @@ -140,60 +81,37 @@ public void actionPerformed(ActionEvent e) { // read selected KnowledgeSourceClass choosenClassIndex = cb.getSelectedIndex(); - checkIfSparql(); - // open File - if (e.getSource() == openButton) { - int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - String URI = "file://"; - // make "file://" before local URI - URI = URI.concat(fc.getSelectedFile().toString()); - config.setURI(URI); // save variable - fileDisplay.setText(URI); - } - return; - } + if (e.getSource() == getInstancesButton) + getInstances(); - // init - if (e.getSource() == initButton && config.getURI() != null) { - config.setKnowledgeSource(config.getComponentManager() - .knowledgeSource(sources.get(choosenClassIndex))); - config.getComponentManager().applyConfigEntry( - config.getKnowledgeSource(), "url", config.getURI()); - config.getKnowledgeSource().init(); - System.out.println("init KnowledgeSource with \n" - + sources.get(choosenClassIndex) + " and \n" - + config.getURI() + "\n"); - updateOptionPanel(); - } + if (e.getSource() == initButton && config.getURI() != null) + init(); } /* - * Define GridBagConstraints + * after this, you can change widgets */ - private void buildConstraints(GridBagConstraints gbc, int gx, int gy, - int gw, int gh, int wx, int wy) { - gbc.gridx = gx; - gbc.gridy = gy; - gbc.gridwidth = gw; - gbc.gridheight = gh; - gbc.weightx = wx; - gbc.weighty = wy; + public void getInstances() { + config.setKnowledgeSource(config.getComponentManager().knowledgeSource( + sources.get(choosenClassIndex))); + updateOptionPanel(); } - private void checkIfSparql() { - if (sources.get(choosenClassIndex).toString().contains("Sparql")) { - openButton.setEnabled(false); - infoLabel.setText("type URL"); - } else { - openButton.setEnabled(true); - infoLabel.setText("choose local file or type URL"); - } + /* + * after this, next tab can be used + */ + public void init() { + config.getKnowledgeSource().init(); + System.out.println("init KnowledgeSource with \n" + + sources.get(choosenClassIndex) + " and \n" + config.getURI() + + "\n"); } + /* + * update OptionPanel with new selection + */ public void updateOptionPanel() { - // update OptionPanel optionPanel.update(config.getKnowledgeSource(), sources .get(choosenClassIndex)); } Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-01 07:58:29 UTC (rev 482) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-02 02:17:19 UTC (rev 483) @@ -26,7 +26,7 @@ import javax.swing.*; -import org.dllearner.core.dl.Concept; +//import org.dllearner.core.dl.Concept; /** * OutputPanel @@ -70,8 +70,6 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == runButton && config.getLearningAlgorithm() != null) { - //config.getLearningAlgorithm().start(); - //thread = new ThreadRun(config); thread = new ThreadRun(config); thread.start(); //Concept solution = config.getLearningAlgorithm().getBestSolution(); Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-01 07:58:29 UTC (rev 482) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-02 02:17:19 UTC (rev 483) @@ -24,7 +24,9 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Color; +import java.io.File; +import javax.swing.JFileChooser; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JPanel; @@ -76,6 +78,16 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == setButton) { + if (checkForFilename()) { + // file dialog + JFileChooser fc = new JFileChooser(new File("examples/")); + int returnVal = fc.showOpenDialog(this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + value = fc.getSelectedFile().toString(); + stringField.setText(value); + config.setURI(value); // save variable + } + } setEntry(); } } @@ -113,6 +125,8 @@ setButton.addActionListener(this); widgetPanel.add(stringField); widgetPanel.add(setButton); + if (checkForFilename()) + setButton.setText("choose local file"); } // UNKNOWN else { @@ -144,4 +158,16 @@ s.printStackTrace(); } } + + /* + * Widget filename getName() == filename you should open a file dialog in + * ActionPerformed + */ + private Boolean checkForFilename() { + if (configOption.getName().equalsIgnoreCase("filename")) + return true; + else + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-01 07:58:33
|
Revision: 482 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=482&view=rev Author: tonytacker Date: 2008-01-31 23:58:29 -0800 (Thu, 31 Jan 2008) Log Message: ----------- run algorithm in extra thread to stop if you want Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-01 06:38:03 UTC (rev 481) +++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2008-02-01 07:58:29 UTC (rev 482) @@ -38,10 +38,13 @@ private static final long serialVersionUID = 1643304576470046636L; - private JButton runButton; + private JButton runButton, stopButton; private JTextArea infoArea; private Config config; + + private ThreadRun thread; + RunPanel(Config config) { super(new BorderLayout()); @@ -49,12 +52,15 @@ runButton = new JButton("Run"); runButton.addActionListener(this); - + stopButton = new JButton("Stop"); + stopButton.addActionListener(this); + infoArea = new JTextArea(20, 50); JScrollPane infoScroll = new JScrollPane(infoArea); JPanel showPanel = new JPanel(); showPanel.add(runButton); + showPanel.add(stopButton); JPanel infoPanel = new JPanel(); infoPanel.add(infoScroll); @@ -64,9 +70,17 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == runButton && config.getLearningAlgorithm() != null) { - config.getLearningAlgorithm().start(); - Concept solution = config.getLearningAlgorithm().getBestSolution(); - infoArea.setText(solution.toString()); + //config.getLearningAlgorithm().start(); + //thread = new ThreadRun(config); + thread = new ThreadRun(config); + thread.start(); + //Concept solution = config.getLearningAlgorithm().getBestSolution(); + //infoArea.setText(solution.toString()); } + if (e.getSource() == stopButton && config.getLearningAlgorithm() != null) { + //config.getLearningAlgorithm().stop(); + thread.exit(); + } } + } Added: trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/ThreadRun.java 2008-02-01 07:58:29 UTC (rev 482) @@ -0,0 +1,46 @@ +package org.dllearner.gui; + +/** + * 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/>. + * + */ + +/** + * threadRun + * + * @author Tilo Hielscher + */ +public class ThreadRun extends Thread { + + Config config; + + public ThreadRun(Config config) { + this.config = config; + } + + // method to start thread + public void run() { + if (config.getLearningAlgorithm() != null) + config.getLearningAlgorithm().start(); + } + + public void exit() { + if (config.getLearningAlgorithm() != null) + config.getLearningAlgorithm().stop(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-01 06:38:07
|
Revision: 481 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=481&view=rev Author: tonytacker Date: 2008-01-31 22:38:03 -0800 (Thu, 31 Jan 2008) Log Message: ----------- implement JMenu for later open/save config Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-01 05:28:50 UTC (rev 480) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-01 06:38:03 UTC (rev 481) @@ -76,19 +76,20 @@ } - public void update(Component component, Class<? extends Component> componentOption) { + public void update(Component component, + Class<? extends Component> componentOption) { this.componentOption = componentOption; this.component = component; showWidgets(); } /* - * define here what core.config.class is what type of widget - * WidgetPanelDefault is for none defined classes + * Define here what core.config.class is what type of widget. + * WidgetPanelDefault is for none defined classes. */ private void showWidgets() { JPanel widgetPanel; - optionList = ComponentManager.getConfigOptions(componentOption); + optionList = ComponentManager.getConfigOptions(componentOption); centerPanel.removeAll(); // clear panel for (int i = 0; i < optionList.size(); i++) { buildConstraints(constraints, 0, i, 1, 1, 0, 0); @@ -105,9 +106,9 @@ widgetPanel = new WidgetPanelDouble(config, component, componentOption, optionList.get(i)); } else if (optionList.get(i).getClass().toString().contains( - "StringConfigOption")) { - widgetPanel = new WidgetPanelString(config, component, - componentOption, optionList.get(i)); + "StringConfigOption")) { + widgetPanel = new WidgetPanelString(config, component, + componentOption, optionList.get(i)); } else { widgetPanel = new WidgetPanelDefault(config, component, componentOption, optionList.get(i)); Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-01 05:28:50 UTC (rev 480) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-02-01 06:38:03 UTC (rev 481) @@ -22,6 +22,9 @@ import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -33,25 +36,31 @@ * @author Tilo Hielscher * */ +public class StartGUI extends JFrame implements ActionListener { -public class StartGUI extends JFrame { - private static final long serialVersionUID = -739265982906533775L; - public JTabbedPane tabPane = new JTabbedPane(); + private JTabbedPane tabPane = new JTabbedPane(); + private Config config = new Config(); + private JPanel tab1 = new JPanel(); private JPanel tab2 = new JPanel(); private JPanel tab3 = new JPanel(); private JPanel tab4 = new JPanel(); private JPanel tab5 = new JPanel(); + private JMenuBar menuBar = new JMenuBar(); + private JMenu menuFile = new JMenu("File"); + private JMenuItem openItem = new JMenuItem("Open Config"); + private JMenuItem saveItem = new JMenuItem("Save Config"); + public StartGUI() { - Config config = new Config(); this.setTitle("DL-Learner GUI"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationByPlatform(true); this.setSize(800, 600); + tab1.add(new KnowledgeSourcePanel(config)); tab2.add(new ReasonerPanel(config)); tab3.add(new LearningProblemPanel(config)); @@ -62,6 +71,14 @@ tabPane.addTab("Learning Problem", tab3); tabPane.addTab("Learning Algorithm", tab4); tabPane.addTab("Run", tab5); + + this.setJMenuBar(menuBar); + menuBar.add(menuFile); + menuFile.add(openItem); + openItem.addActionListener(this); + menuFile.add(saveItem); + saveItem.addActionListener(this); + this.add(tabPane); this.setVisible(true); } @@ -78,8 +95,13 @@ new StartGUI(); } - protected void renew() { - tabPane.repaint(); + public void actionPerformed(ActionEvent e) { + if (e.getSource() == openItem) { + System.out.println("openItem was pressed"); + } + if (e.getSource() == saveItem) { + System.out.println("saveItem was pressed"); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-01 05:29:01
|
Revision: 480 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=480&view=rev Author: tonytacker Date: 2008-01-31 21:28:50 -0800 (Thu, 31 Jan 2008) Log Message: ----------- implement an if on all widgets to read config before setting default value, fixed some bugs to do this Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-01 05:28:50 UTC (rev 480) @@ -129,7 +129,6 @@ optionPanel = new OptionPanel(config, config.getKnowledgeSource(), sources.get(choosenClassIndex)); - updateOptionPanel(); add(choosePanel, BorderLayout.PAGE_START); add(centerPanel, BorderLayout.CENTER); @@ -141,7 +140,6 @@ public void actionPerformed(ActionEvent e) { // read selected KnowledgeSourceClass choosenClassIndex = cb.getSelectedIndex(); - updateOptionPanel(); checkIfSparql(); // open File @@ -196,7 +194,7 @@ public void updateOptionPanel() { // update OptionPanel - optionPanel.setComponent(config.getKnowledgeSource()); - optionPanel.setComponentOption(sources.get(choosenClassIndex)); + optionPanel.update(config.getKnowledgeSource(), sources + .get(choosenClassIndex)); } } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-01 05:28:50 UTC (rev 480) @@ -70,7 +70,6 @@ optionPanel = new OptionPanel(config, config.getLearningAlgorithm(), learners.get(choosenClassIndex)); - updateOptionPanel(); add(choosePanel, BorderLayout.PAGE_START); add(initPanel, BorderLayout.CENTER); @@ -81,22 +80,21 @@ public void actionPerformed(ActionEvent e) { // read selected Class choosenClassIndex = cb.getSelectedIndex(); - updateOptionPanel(); + // init if (e.getSource() == initButton && config.getLearningProblem() != null) { config.setLearningAlgorithm(config.getComponentManager() .learningAlgorithm(learners.get(choosenClassIndex), config.getLearningProblem(), config.getReasoningService())); - updateOptionPanel(); System.out.println("init LearningAlgorithm"); config.getLearningAlgorithm().init(); + updateOptionPanel(); } } public void updateOptionPanel() { // update OptionPanel - optionPanel.setComponent(config.getLearningAlgorithm()); - optionPanel.setComponentOption(learners.get(choosenClassIndex)); + optionPanel.update(config.getLearningAlgorithm(), learners.get(choosenClassIndex)); } } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-01 05:28:50 UTC (rev 480) @@ -55,7 +55,7 @@ private JPanel lpPanel = new JPanel(); private JLabel posLabel = new JLabel("positive Examples"); private JLabel negLabel = new JLabel("negative Examples"); - private JButton initButton, readListButton; + private JButton initButton; private int choosenClassIndex; private List<Individual> individuals; private JList posList = new JList(); @@ -72,18 +72,13 @@ initButton = new JButton("Init LearningProblem"); initButton.addActionListener(this); - readListButton = new JButton("Get Instances"); - readListButton.addActionListener(this); - choosePanel.add(cb); - choosePanel.add(readListButton); - lpPanel.add(initButton); + choosePanel.add(initButton); problems = config.getComponentManager().getLearningProblems(); // add into comboBox for (int i = 0; i < problems.size(); i++) { - // cb.addItem(problems.get(i).getSimpleName()); cb.addItem(config.getComponentManager().getComponentName( problems.get(i))); } @@ -127,10 +122,10 @@ buildConstraints(constraints, 1, 1, 1, 1, 100, 100); gridbag.setConstraints(negListScroller, constraints); centerPanel.add(negListScroller); - + buildConstraints(constraints, 0, 2, 2, 1, 100, 100); gridbag.setConstraints(lpPanel, constraints); - centerPanel.add(lpPanel); + centerPanel.add(lpPanel); add(centerPanel, BorderLayout.CENTER); @@ -164,41 +159,21 @@ optionPanel = new OptionPanel(config, config.getLearningProblem(), problems.get(choosenClassIndex)); - updateOptionPanel(); cb.addActionListener(this); - + add(choosePanel, BorderLayout.PAGE_START); add(centerPanel, BorderLayout.CENTER); add(optionPanel, BorderLayout.PAGE_END); - + } public void actionPerformed(ActionEvent e) { // read selected LearningProblemClass choosenClassIndex = cb.getSelectedIndex(); - updateOptionPanel(); - // get list after reasoner init - if (e.getSource() == readListButton - && config.getReasoningService() != null) { - // fill lists - Set<Individual> individualsSet = config.getReasoningService() - .getIndividuals(); - individuals = new LinkedList<Individual>(individualsSet); - DefaultListModel listModel = new DefaultListModel(); - for (Individual ind : individuals) { - listModel.addElement(ind); - } - posList.setModel(listModel); - negList.setModel(listModel); - } - // init - if (e.getSource() == initButton - && config.getReasoningService() != null - && (config.getPosExampleSet().size() > 0 || config - .getNegExampleSet().size() > 0)) { + if (e.getSource() == initButton && config.getReasoningService() != null) { config.setLearningProblem(config.getComponentManager() .learningProblem(problems.get(choosenClassIndex), config.getReasoningService())); @@ -211,6 +186,20 @@ config.getLearningProblem().init(); System.out.println("init LearningProblem"); updateOptionPanel(); + + // lists + if (config.getReasoningService() != null) { + // fill lists + Set<Individual> individualsSet = config.getReasoningService() + .getIndividuals(); + individuals = new LinkedList<Individual>(individualsSet); + DefaultListModel listModel = new DefaultListModel(); + for (Individual ind : individuals) { + listModel.addElement(ind); + } + posList.setModel(listModel); + negList.setModel(listModel); + } } } @@ -230,7 +219,7 @@ public void updateOptionPanel() { // update OptionPanel - optionPanel.setComponent(config.getLearningProblem()); - optionPanel.setComponentOption(problems.get(choosenClassIndex)); + optionPanel.update(config.getLearningProblem(), problems + .get(choosenClassIndex)); } } Modified: trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/OptionPanel.java 2008-02-01 05:28:50 UTC (rev 480) @@ -76,16 +76,12 @@ } - public void setComponent(Component component) { + public void update(Component component, Class<? extends Component> componentOption) { + this.componentOption = componentOption; this.component = component; showWidgets(); } - public void setComponentOption(Class<? extends Component> componentOption) { - this.componentOption = componentOption; - showWidgets(); - } - /* * define here what core.config.class is what type of widget * WidgetPanelDefault is for none defined classes Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-01 05:28:50 UTC (rev 480) @@ -63,14 +63,12 @@ // add into comboBox reasoners = config.getComponentManager().getReasonerComponents(); for (int i = 0; i < reasoners.size(); i++) { - // cb.addItem(reasoners.get(i).getSimpleName()); cb.addItem(config.getComponentManager().getComponentName( reasoners.get(i))); } optionPanel = new OptionPanel(config, config.getReasoner(), reasoners .get(choosenClassIndex)); - updateOptionPanel(); cb.addActionListener(this); @@ -83,7 +81,6 @@ public void actionPerformed(ActionEvent e) { // read selected Class choosenClassIndex = cb.getSelectedIndex(); - updateOptionPanel(); if (e.getSource() == initButton && config.getKnowledgeSource() != null) { // set reasoner @@ -103,7 +100,6 @@ public void updateOptionPanel() { // update OptionPanel - optionPanel.setComponent(config.getReasoner()); - optionPanel.setComponentOption(reasoners.get(choosenClassIndex)); + optionPanel.update(config.getReasoner(), reasoners.get(choosenClassIndex)); } } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-01 05:28:50 UTC (rev 480) @@ -87,25 +87,30 @@ @Override protected void showThingToChange() { if (component != null) { - // IntegerConfigOption + // BooleanConfigOption if (configOption.getClass().toString().contains( "BooleanConfigOption")) { + // previous set value + if (configOption != null) { + value = (Boolean) config.getComponentManager() + .getConfigOptionValue(component, + configOption.getName()); + } // default value - if (configOption.getDefaultValue() != null) { + else if (configOption.getDefaultValue() != null) { value = (Boolean) configOption.getDefaultValue(); - System.out.println ("TEST Boolean default: " + configOption.getDefaultValue()); } - // then false - else { + // value == null + if (value == null) { value = false; } - // cb.setText(value.toString()); + // set cb-index if (value == false) cb.setSelectedIndex(0); else cb.setSelectedIndex(1); cb.addActionListener(this); - + widgetPanel.add(cb); } // UNKNOWN @@ -115,8 +120,7 @@ widgetPanel.add(notImplementedLabel); } } else { // configOption == NULL - JLabel noConfigOptionLabel = new JLabel( - "no init (Boolean)"); + JLabel noConfigOptionLabel = new JLabel("no init (Boolean)"); noConfigOptionLabel.setForeground(Color.MAGENTA); widgetPanel.add(noConfigOptionLabel); } Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelDouble.java 2008-02-01 05:28:50 UTC (rev 480) @@ -30,7 +30,7 @@ import javax.swing.JPanel; import javax.swing.JButton; -import org.dllearner.core.Component; +import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DoubleConfigOption; @@ -93,16 +93,23 @@ // DoubleConfigOption if (configOption.getClass().toString().contains( "DoubleConfigOption")) { + // previous set value + if (configOption != null) { + value = (Double) config.getComponentManager() + .getConfigOptionValue(component, + configOption.getName()); + } // default value - if (configOption.getDefaultValue() != null) { + else if (configOption.getDefaultValue() != null) { value = (Double) configOption.getDefaultValue(); } - // then 0 - else { + // value == null + if (value == null) { value = 0.0; } doubleField.setText(value.toString()); - doubleField.setToolTipText(configOption.getAllowedValuesDescription()); + doubleField.setToolTipText(configOption + .getAllowedValuesDescription()); setButton.addActionListener(this); widgetPanel.add(doubleField); widgetPanel.add(setButton); Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelInteger.java 2008-02-01 05:28:50 UTC (rev 480) @@ -30,7 +30,7 @@ import javax.swing.JPanel; import javax.swing.JButton; -import org.dllearner.core.Component; +import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerConfigOption; @@ -94,16 +94,23 @@ // IntegerConfigOption if (configOption.getClass().toString().contains( "IntegerConfigOption")) { + // previous set value + if (configOption != null) { + value = (Integer) config.getComponentManager() + .getConfigOptionValue(component, + configOption.getName()); + } // default value - if (configOption.getDefaultValue() != null) { + else if (configOption.getDefaultValue() != null) { value = (Integer) configOption.getDefaultValue(); } - // then 0 - else { + // value == null + if (value == null) { value = 0; } integerField.setText(value.toString()); - integerField.setToolTipText(configOption.getAllowedValuesDescription()); + integerField.setToolTipText(configOption + .getAllowedValuesDescription()); setButton.addActionListener(this); widgetPanel.add(integerField); widgetPanel.add(setButton); Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-01 02:50:44 UTC (rev 479) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelString.java 2008-02-01 05:28:50 UTC (rev 480) @@ -30,7 +30,7 @@ import javax.swing.JPanel; import javax.swing.JButton; -import org.dllearner.core.Component; +import org.dllearner.core.Component; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.StringConfigOption; @@ -93,16 +93,23 @@ // StringConfigOption if (configOption.getClass().toString().contains( "StringConfigOption")) { + // previous set value + if (configOption != null) { + value = (String) config.getComponentManager() + .getConfigOptionValue(component, + configOption.getName()); + } // default value - if (configOption.getDefaultValue() != null) { + else if (configOption.getDefaultValue() != null) { value = (String) configOption.getDefaultValue(); } - // then "" - else { + // value == null + if (value == null) { value = ""; } stringField.setText(value.toString()); - stringField.setToolTipText(configOption.getAllowedValuesDescription()); + stringField.setToolTipText(configOption + .getAllowedValuesDescription()); setButton.addActionListener(this); widgetPanel.add(stringField); widgetPanel.add(setButton); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-02-01 02:50:47
|
Revision: 479 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=479&view=rev Author: tonytacker Date: 2008-01-31 18:50:44 -0800 (Thu, 31 Jan 2008) Log Message: ----------- fixed 2 bugs with false/true - should now be right Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java Modified: trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-01-31 09:43:05 UTC (rev 478) +++ trunk/src/dl-learner/org/dllearner/gui/WidgetPanelBoolean.java 2008-02-01 02:50:44 UTC (rev 479) @@ -53,7 +53,7 @@ private Class<? extends Component> componentOption; private Boolean value; - private String[] kbBoxItems = { "true", "false" }; + private String[] kbBoxItems = { "false", "true" }; private JComboBox cb = new JComboBox(kbBoxItems); public WidgetPanelBoolean(Config config, Component component, @@ -93,6 +93,7 @@ // default value if (configOption.getDefaultValue() != null) { value = (Boolean) configOption.getDefaultValue(); + System.out.println ("TEST Boolean default: " + configOption.getDefaultValue()); } // then false else { @@ -125,9 +126,9 @@ protected void setEntry() { BooleanConfigOption specialOption; if (cb.getSelectedIndex() == 0) + value = false; + else value = true; - else - value = false; specialOption = (BooleanConfigOption) config.getComponentManager() .getConfigOption(componentOption, configOption.getName()); try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-01-31 09:43:07
|
Revision: 478 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=478&view=rev Author: sknappe Date: 2008-01-31 01:43:05 -0800 (Thu, 31 Jan 2008) Log Message: ----------- fixed a bug when processing several best concepts Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-31 09:21:34 UTC (rev 477) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-31 09:43:05 UTC (rev 478) @@ -20,6 +20,8 @@ package org.dllearner.server; import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; @@ -321,7 +323,11 @@ public String[] getCurrentlyBestConcepts(int id, int nrOfConcepts) throws ClientNotKnownException { ClientState state = getState(id); List<Concept> bestConcepts = state.getLearningAlgorithm().getBestSolutions(nrOfConcepts); - return bestConcepts.toArray(new String[bestConcepts.size()]); + List<String> conc=new LinkedList<String>(); + Iterator<Concept> iter=bestConcepts.iterator(); + while (iter.hasNext()) + conc.add(iter.next().toString()); + return conc.toArray(new String[conc.size()]); } @WebMethod This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |