From: <lor...@us...> - 2011-08-17 13:30:22
|
Revision: 3060 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3060&view=rev Author: lorenz_b Date: 2011-08-17 13:30:12 +0000 (Wed, 17 Aug 2011) Log Message: ----------- Fixed small bugs. Added version property to algorithm in enrichment output. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2011-08-17 13:30:12 UTC (rev 3060) @@ -3,12 +3,10 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -96,15 +94,14 @@ logger.info("Existing domain: " + existingDomain); //get subjects with types - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - Map<Individual, Set<NamedClass>> newIndividual2Types; + Map<Individual, SortedSet<NamedClass>> individual2Types = new HashMap<Individual, SortedSet<NamedClass>>(); boolean repeat = true; + int limit = 1000; while(!terminationCriteriaSatisfied() && repeat){ - newIndividual2Types = getSubjectsWithTypes(fetchedRows); - individual2Types.putAll(newIndividual2Types); - currentlyBestAxioms = buildBestAxioms(individual2Types); + int ret = addIndividualsWithTypes(individual2Types, limit, fetchedRows); + currentlyBestAxioms = buildEvaluatedAxioms(individual2Types); fetchedRows += 1000; - repeat = !newIndividual2Types.isEmpty(); + repeat = (ret == limit); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @@ -148,10 +145,10 @@ return timeLimitExceeded || resultLimitExceeded; } - private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<NamedClass>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); - for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(Entry<Individual, SortedSet<NamedClass>> entry : individual2Types.entrySet()){ for(NamedClass nc : entry.getValue()){ Integer cnt = result.get(nc); if(cnt == null){ @@ -194,25 +191,30 @@ return sortedSet; } - private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(int offset){ - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - int limit = 1000; - String query = String.format("SELECT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, offset); + private int addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ + String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + +// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); + ResultSet rs = executeQuery(query); + Individual ind; + NamedClass newType; QuerySolution qs; - Individual ind; - Set<NamedClass> types; + SortedSet<NamedClass> types; + int cnt = 0; while(rs.hasNext()){ + cnt++; qs = rs.next(); ind = new Individual(qs.getResource("ind").getURI()); - types = individual2Types.get(ind); + newType = new NamedClass(qs.getResource("type").getURI()); + types = ind2Types.get(ind); if(types == null){ - types = new HashSet<NamedClass>(); - individual2Types.put(ind, types); + types = new TreeSet<NamedClass>(); + ind2Types.put(ind, types); } - types.add(new NamedClass(qs.getResource("type").getURI())); + types.add(newType); } - return individual2Types; + return cnt; } /* Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2011-08-17 13:30:12 UTC (rev 3060) @@ -3,12 +3,10 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -27,7 +25,6 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyRangeAxiom; import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.OWL2Datatype; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.learningproblems.AxiomScore; @@ -95,16 +92,15 @@ DataRange existingRange = reasoner.getRange(propertyToDescribe); logger.debug("Existing range: " + existingRange); - //get objects with types - Map<Individual, Set<Datatype>> individual2Types = new HashMap<Individual, Set<Datatype>>(); - Map<Individual, Set<Datatype>> newIndividual2Types; + //get objects with datatypes + Map<Individual, SortedSet<Datatype>> individual2Datatypes = new HashMap<Individual, SortedSet<Datatype>>(); boolean repeat = true; + int limit = 1000; while(!terminationCriteriaSatisfied() && repeat){ - newIndividual2Types = getObjectsWithDatatypes(fetchedRows); - individual2Types.putAll(newIndividual2Types); - currentlyBestAxioms = buildBestAxioms(individual2Types); + int ret = addIndividualsWithTypes(individual2Datatypes, limit, fetchedRows); + currentlyBestAxioms = buildEvaluatedAxioms(individual2Datatypes); fetchedRows += 1000; - repeat = !newIndividual2Types.isEmpty(); + repeat = (ret == limit); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @@ -148,10 +144,10 @@ return timeLimitExceeded || resultLimitExceeded; } - private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<Datatype>> individual2Types){ + private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Datatype>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Datatype, Integer> result = new HashMap<Datatype, Integer>(); - for(Entry<Individual, Set<Datatype>> entry : individual2Types.entrySet()){ + for(Entry<Individual, SortedSet<Datatype>> entry : individual2Types.entrySet()){ for(Datatype nc : entry.getValue()){ Integer cnt = result.get(nc); if(cnt == null){ @@ -194,25 +190,28 @@ return sortedSet; } - private Map<Individual, Set<Datatype>> getObjectsWithDatatypes(int offset){ - Map<Individual, Set<Datatype>> individual2Datatypes = new HashMap<Individual, Set<Datatype>>(); - int limit = 1000; + private int addIndividualsWithTypes(Map<Individual, SortedSet<Datatype>> ind2Datatypes, int limit, int offset){ String query = String.format("SELECT ?ind, (DATATYPE(?val) AS ?datatype) WHERE {?ind <%s> ?val.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + ResultSet rs = executeQuery(query); - QuerySolution qs; Individual ind; - Set<Datatype> types; + Datatype newType; + QuerySolution qs; + SortedSet<Datatype> types; + int cnt = 0; while(rs.hasNext()){ + cnt++; qs = rs.next(); ind = new Individual(qs.getResource("ind").getURI()); - types = individual2Datatypes.get(ind); + newType = new Datatype(qs.getResource("datatype").getURI()); + types = ind2Datatypes.get(ind); if(types == null){ - types = new HashSet<Datatype>(); - individual2Datatypes.put(ind, types); + types = new TreeSet<Datatype>(); + ind2Datatypes.put(ind, types); } - types.add(new Datatype(qs.getResource("datatype").getURI())); + types.add(newType); } - return individual2Datatypes; + return cnt; } /* Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-08-17 13:30:12 UTC (rev 3060) @@ -31,6 +31,7 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; @@ -97,15 +98,14 @@ logger.info("Existing domain: " + existingDomain); //get subjects with types - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - Map<Individual, Set<NamedClass>> newIndividual2Types; + Map<Individual, SortedSet<NamedClass>> individual2Types = new HashMap<Individual, SortedSet<NamedClass>>(); boolean repeat = true; + int limit = 1000; while(!terminationCriteriaSatisfied() && repeat){ - newIndividual2Types = getSubjectsWithTypes(fetchedRows); - individual2Types.putAll(newIndividual2Types); - currentlyBestAxioms = buildBestAxioms(individual2Types); + int ret = addIndividualsWithTypes(individual2Types, limit, fetchedRows); + currentlyBestAxioms = buildEvaluatedAxioms(individual2Types); fetchedRows += 1000; - repeat = !newIndividual2Types.isEmpty(); + repeat = (ret == limit); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @@ -149,10 +149,10 @@ return timeLimitExceeded || resultLimitExceeded; } - private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<NamedClass>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); - for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(Entry<Individual, SortedSet<NamedClass>> entry : individual2Types.entrySet()){ for(NamedClass nc : entry.getValue()){ Integer cnt = result.get(nc); if(cnt == null){ @@ -195,25 +195,30 @@ return sortedSet; } - private Map<Individual, Set<NamedClass>> getSubjectsWithTypes(int offset){ - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - int limit = 1000; - String query = String.format("SELECT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getURI().toString(), limit, offset); + private int addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ + String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + +// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); + ResultSet rs = executeQuery(query); + Individual ind; + NamedClass newType; QuerySolution qs; - Individual ind; - Set<NamedClass> types; + SortedSet<NamedClass> types; + int cnt = 0; while(rs.hasNext()){ + cnt++; qs = rs.next(); ind = new Individual(qs.getResource("ind").getURI()); - types = individual2Types.get(ind); + newType = new NamedClass(qs.getResource("type").getURI()); + types = ind2Types.get(ind); if(types == null){ - types = new HashSet<NamedClass>(); - individual2Types.put(ind, types); + types = new TreeSet<NamedClass>(); + ind2Types.put(ind, types); } - types.add(new NamedClass(qs.getResource("type").getURI())); + types.add(newType); } - return individual2Types; + return cnt; } /* Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-17 10:59:06 UTC (rev 3059) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2011-08-17 13:30:12 UTC (rev 3060) @@ -3,12 +3,10 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -22,7 +20,6 @@ import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; -import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -97,15 +94,14 @@ logger.debug("Existing range: " + existingRange); //get objects with types - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - Map<Individual, Set<NamedClass>> newIndividual2Types; + Map<Individual, SortedSet<NamedClass>> individual2Types = new HashMap<Individual, SortedSet<NamedClass>>(); boolean repeat = true; + int limit = 1000; while(!terminationCriteriaSatisfied() && repeat){ - newIndividual2Types = getObjectsWithTypes(fetchedRows); - individual2Types.putAll(newIndividual2Types); - currentlyBestAxioms = buildBestAxioms(individual2Types); + int ret = addIndividualsWithTypes(individual2Types, limit, fetchedRows); + currentlyBestAxioms = buildEvaluatedAxioms(individual2Types); fetchedRows += 1000; - repeat = !newIndividual2Types.isEmpty(); + repeat = (ret == limit); } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } @@ -149,10 +145,10 @@ return timeLimitExceeded || resultLimitExceeded; } - private List<EvaluatedAxiom> buildBestAxioms(Map<Individual, Set<NamedClass>> individual2Types){ + private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<NamedClass>> individual2Types){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); - for(Entry<Individual, Set<NamedClass>> entry : individual2Types.entrySet()){ + for(Entry<Individual, SortedSet<NamedClass>> entry : individual2Types.entrySet()){ for(NamedClass nc : entry.getValue()){ Integer cnt = result.get(nc); if(cnt == null){ @@ -195,25 +191,30 @@ return sortedSet; } - private Map<Individual, Set<NamedClass>> getObjectsWithTypes(int offset){ - Map<Individual, Set<NamedClass>> individual2Types = new HashMap<Individual, Set<NamedClass>>(); - int limit = 1000; + private int addIndividualsWithTypes(Map<Individual, SortedSet<NamedClass>> ind2Types, int limit, int offset){ String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + +// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); + ResultSet rs = executeQuery(query); + Individual ind; + NamedClass newType; QuerySolution qs; - Individual ind; - Set<NamedClass> types; + SortedSet<NamedClass> types; + int cnt = 0; while(rs.hasNext()){ + cnt++; qs = rs.next(); ind = new Individual(qs.getResource("ind").getURI()); - types = individual2Types.get(ind); + newType = new NamedClass(qs.getResource("type").getURI()); + types = ind2Types.get(ind); if(types == null){ - types = new HashSet<NamedClass>(); - individual2Types.put(ind, types); + types = new TreeSet<NamedClass>(); + ind2Types.put(ind, types); } - types.add(new NamedClass(qs.getResource("type").getURI())); + types.add(newType); } - return individual2Types; + return cnt; } /* Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 10:59:06 UTC (rev 3059) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 13:30:12 UTC (rev 3060) @@ -22,7 +22,6 @@ import static java.util.Arrays.asList; import java.io.IOException; -import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; import java.net.MalformedURLException; @@ -103,7 +102,6 @@ import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget; import org.semanticweb.owlapi.io.SystemOutDocumentTarget; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotation; @@ -115,12 +113,9 @@ import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; -import org.semanticweb.owlapi.util.DefaultPrefixManager; import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; -import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer; -import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxPrefixNameShortFormProvider; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; @@ -403,7 +398,8 @@ ax = f.getOWLAnnotationAssertionAxiom(algorithmInd.asOWLNamedIndividual().getIRI(), labelAnno); axioms.add(ax); //add version to algorithm - //TODO + ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.version, algorithmInd, algorithm.getClass().getAnnotation(ComponentAnn.class).version()); + axioms.add(ax); //add algorithm instance to algorithm run instance ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, algorithmRunInd, algorithmInd); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-17 14:31:20
|
Revision: 3061 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3061&view=rev Author: jenslehmann Date: 2011-08-17 14:31:09 +0000 (Wed, 17 Aug 2011) Log Message: ----------- - first version of HTML help page generator for annotation based components completed * see interfaces/doc/configOptions.html * display general information about components as well as information about their options * component visibility can be toggled by type - config option annotation refined: * the "required" method allows to distinguish between required and optional options * the "defaultValue" method allows to specify a default value (see also its Javadoc) - added some convenience methods in AnnComponentManager Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java trunk/scripts/src/main/java/org/dllearner/scripts/DocumentationHTMLGenerator.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -22,6 +22,7 @@ import java.util.List; import org.dllearner.core.ClassExpressionLearningAlgorithm; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.owl.Description; @@ -33,6 +34,7 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "disjoint classes learner", shortName = "cldisjoint", version = 0.1) public class DisjointClassesLearner implements ClassExpressionLearningAlgorithm { @Override Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -31,6 +31,7 @@ import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; import org.dllearner.core.ClassExpressionLearningAlgorithm; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; @@ -65,13 +66,14 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "simple subclass learner", shortName = "clsub", version = 0.1) public class SimpleSubclassLearner implements ClassExpressionLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(SimpleSubclassLearner.class); - @ConfigOption(name="classToDescribe", description="", propertyEditorClass=NamedClassEditor.class) + @ConfigOption(name="classToDescribe", required=true, description="", propertyEditorClass=NamedClassEditor.class) private NamedClass classToDescribe; - @ConfigOption(name="maxExecutionTimeInSeconds", description="", propertyEditorClass=IntegerEditor.class) + @ConfigOption(name="maxExecutionTimeInSeconds", defaultValue="10", description="", propertyEditorClass=IntegerEditor.class) private int maxExecutionTimeInSeconds = 10; @ConfigOption(name="maxFetchedRows", description="The maximum number of rows fetched from the endpoint to approximate the result.", propertyEditorClass=IntegerEditor.class) private int maxFetchedRows = 0; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -77,7 +77,7 @@ * @author Jens Lehmann * */ -@ComponentAnn(name="CELOE", shortName="celoe", version=1.0) +@ComponentAnn(name="CELOE", shortName="celoe", version=1.0, description="CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.") public class CELOE extends AbstractCELA { private static Logger logger = Logger.getLogger(CELOE.class); Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -19,10 +19,13 @@ */ package org.dllearner.core; +import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -64,8 +67,8 @@ "org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner", "org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner", "org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner", - "org.dllearner.algorithms.algorithms.DisjointClassesLearner", - "org.dllearner.algorithms.algorithms.SimpleSubclassLearner", + "org.dllearner.algorithms.DisjointClassesLearner", + "org.dllearner.algorithms.SimpleSubclassLearner", } )); private static Collection<Class<? extends Component>> components; private static Map<Class<? extends Component>, String> componentNames; @@ -74,6 +77,8 @@ private AnnComponentManager() { // conversion of class strings to objects + components = new HashSet<Class<? extends Component>>(); + componentNames = new HashMap<Class<? extends Component>, String>(); for (String componentClassName : componentClassNames) { try { Class<? extends Component> component = Class.forName(componentClassName).asSubclass(Component.class); @@ -198,6 +203,28 @@ } return true; } + + // method lists all core interfaces implemented by a component (directly or indirectly) + // TODO: incomplete + public static List<Class<? extends Component>> getCoreComponentTypes(Class<? extends Component> component) { + List<Class<? extends Component>> types = new LinkedList<Class<? extends Component>>(); + if(KnowledgeSource.class.isAssignableFrom(component)) { + types.add(KnowledgeSource.class); + } + if(LearningAlgorithm.class.isAssignableFrom(component)) { + types.add(LearningAlgorithm.class); + } + if(LearningProblem.class.isAssignableFrom(component)) { + types.add(LearningProblem.class); + } + if(ReasonerComponent.class.isAssignableFrom(component)) { + types.add(ReasonerComponent.class); + } + if(AxiomLearningAlgorithm.class.isAssignableFrom(component)) { + types.add(AxiomLearningAlgorithm.class); + } + return types; + } /** * Returns the name of a DL-Learner component. @@ -206,6 +233,9 @@ */ public static String getName(Class<? extends Component> component){ ComponentAnn ann = component.getAnnotation(ComponentAnn.class); + if(ann == null) { + throw new Error("Component " + component + " does not use component annotation."); + } return ann.name(); } @@ -215,7 +245,66 @@ * @return Name of the component. */ public static String getName(Component component){ - ComponentAnn ann = component.getClass().getAnnotation(ComponentAnn.class); - return ann.name(); + return getName(component.getClass()); } + + /** + * Returns the name of a DL-Learner component. + * @param component + * @return Name of the component. + */ + public static String getShortName(Class<? extends Component> component){ + ComponentAnn ann = component.getAnnotation(ComponentAnn.class); + if(ann == null) { + throw new Error("Component " + component + " does not use component annotation."); + } + return ann.shortName(); + } + + /** + * Returns the short name of a DL-Learner component. + * @param component + * @return Short name of the component. + */ + public static String getShortName(Component component){ + return getShortName(component.getClass()); + } + + /** + * Returns the name of a DL-Learner component. + * @param component + * @return Name of the component. + */ + public static String getDescription(Class<? extends Component> component){ + ComponentAnn ann = component.getAnnotation(ComponentAnn.class); + return ann.description(); + } + + /** + * Returns the description of a DL-Learner component. + * @param component + * @return Description of the component. + */ + public static String getDescription(Component component){ + return getDescription(component.getClass()); + } + + /** + * Returns the version of a DL-Learner component. + * @param component + * @return Version of the component. + */ + public static double getVersion(Class<? extends Component> component){ + ComponentAnn ann = component.getAnnotation(ComponentAnn.class); + return ann.version(); + } + + /** + * Returns the version of a DL-Learner component. + * @param component + * @return Version of the component. + */ + public static double getVersion(Component component){ + return getVersion(component.getClass()); + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentAnn.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -53,4 +53,11 @@ * @return A version number of this component. */ double version(); + + /** + * An optional description of the component. This can be shown in tool tips, + * help etc. + * @return The description of the component. + */ + String description() default ""; } Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; +import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; import org.dllearner.core.Component; @@ -69,9 +70,18 @@ * @return */ public static List<ConfigOption> getConfigOptions(Component component){ + return getConfigOptions(component.getClass()); + } + + /** + * Returns all config options for the given component. + * @param component + * @return + */ + public static List<ConfigOption> getConfigOptions(Class<? extends Component> component){ List<ConfigOption> options = new ArrayList<ConfigOption>(); - Field[] fields = component.getClass().getDeclaredFields(); + Field[] fields = component.getDeclaredFields(); for(Field f : fields){ ConfigOption option = f.getAnnotation(ConfigOption.class); if(option != null){ @@ -80,7 +90,7 @@ } return options; - } + } private static Class<?> getClassForObject(Object obj){ if(map.containsKey(obj.getClass())){ Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -50,4 +50,21 @@ * @return */ Class<?> propertyEditorClass(); + + /** + * Returns whether this option is required for initializing the component. + * @return True if the option is required and false otherwise. + */ + boolean required() default false; + + /** + * Returns the default value of this config option. Default values should be set for all + * optional values. + * It is an overhead to describe the default value both in the source code and in the + * annotation. There are two reasons for this: a) the value of the field cannot easily be accessed + * without creating an instance of the component and b) for more complex structures the default + * may only be created in the constructor or init method. + * @return The default value of this option. + */ + String defaultValue() default ""; } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/DocumentationHTMLGenerator.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/DocumentationHTMLGenerator.java 2011-08-17 13:30:12 UTC (rev 3060) +++ trunk/scripts/src/main/java/org/dllearner/scripts/DocumentationHTMLGenerator.java 2011-08-17 14:31:09 UTC (rev 3061) @@ -20,12 +20,17 @@ package org.dllearner.scripts; import java.io.File; +import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.Map.Entry; +import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.Component; +import org.dllearner.core.config.ConfigHelper; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.utilities.Files; /** * Script for generating documentation for all components, in particular @@ -58,31 +63,106 @@ // heading sb.append("<h1>DL-Learner Components</h1>\n"); + // filter interface + sb.append("<p>Filter components by implemented interfaces:</p>\n<ul>"); + sb.append("<a href=\"#\" onClick=\"showAllCat()\">show all</a>"); + sb.append("<li><a href=\"#\" onClick=\"showOnlyCat('KnowledgeSource')\">KnowledgeSource</a></li>"); + sb.append("<li><a href=\"#\" onClick=\"showOnlyCat('ReasonerComponent')\">ReasonerComponent</a></li>"); + sb.append("<li><a href=\"#\" onClick=\"showOnlyCat('LearningProblem')\">LearningProblem</a></li>"); + sb.append("<li><a href=\"#\" onClick=\"showOnlyCat('LearningAlgorithm')\">LearningAlgorithm</a>"); + sb.append("<ul><li><a href=\"#\" onClick=\"showOnlyCat('AxiomLearningAlgorithm')\">AxiomLearningAlgorithm</a></li></ul></li>"); + sb.append("</ul>"); + + // general explanations + sb.append("<p>Click on a component to get an overview on its configuration options.</p>"); + // generate component overview sb.append("<ul>\n"); for(Entry<String, Class<? extends Component>> compEntry : componentNamesInv.entrySet()) { - sb.append("<li><a href=\"#" + compEntry.getValue() + "\">"+compEntry.getKey()+"</a></li>\n"); + sb.append("<div class=\"" + getCoreTypes(compEntry.getValue()) + "\"><li><a href=\"#" + compEntry.getValue().getName() + "\">"+compEntry.getKey()+"</a></li></div>\n"); } sb.append("</ul>\n"); // generate actual documentation per component for(Entry<String, Class<? extends Component>> compEntry : componentNamesInv.entrySet()) { - sb.append("<a name=\"#" + compEntry.getValue() + "\" /><h2>"+compEntry.getKey()+"</h2>\n"); + Class<? extends Component> comp = compEntry.getValue(); + sb.append("<div class=\"" + getCoreTypes(comp) + "\">"); + // heading + anchor + sb.append("<a name=\"" + comp.getName() + "\"><h2>"+compEntry.getKey()+"</h2></a>\n"); + // some information about the component + sb.append("<p>short name: " + AnnComponentManager.getShortName(comp) + "<br />"); + sb.append("version: " + AnnComponentManager.getVersion(comp) + "<br />"); + sb.append("implements: " + getCoreTypes(comp).replace(" ", ", ") + "<br />"); + String description = AnnComponentManager.getDescription(comp); + if(description.length() > 0) { + sb.append("description: " + AnnComponentManager.getDescription(comp) + "<br />"); + } + sb.append("</p>"); + + // generate table for configuration options + List<ConfigOption> options = ConfigHelper.getConfigOptions(comp); + if(options.isEmpty()) { + sb.append("This component does not have configuration options."); + } else { + sb.append("<table id=\"hor-minimalist-a\"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody>\n"); + for(ConfigOption option : options) { + sb.append("<tr><td>" + option.name() + "</td><td>" + option.description() + "</td><td> " + getOptionType(option) + "</td><td>" + option.defaultValue() + "</td><td> " + option.required() + "</td></tr>\n"); + } + sb.append("</tbody></table>\n"); + } + sb.append("</div>\n"); } sb.append(getFooter()); + + Files.createFile(file, sb.toString()); } private String getHeader() { - return "<html><head><title>DL-Learner components and configuration options</title></head><body>"; + StringBuffer sb = new StringBuffer(); + sb.append("<html><head><title>DL-Learner components and configuration options</title>\n"); + sb.append("<style type=\"text/css\">\n"); + sb.append("body { line-height: 1.6em; font-size: 15px; font-family: \"Lucida Sans Unicode\", \"Lucida Grande\", Sans-Serif; }\n"); + sb.append("#hor-minimalist-a { font-size: 13px; background: #fff; margin: 30px; width: 90%;border-collapse: collapse; text-align: left; } \n"); + sb.append("#hor-minimalist-a th { font-size: 15px; font-weight: normal; color: #039; padding: 10px 8px; border-bottom: 2px solid #6678b1; }\n"); + sb.append("#hor-minimalist-a td { color: #669;padding: 9px 8px 0px 8px; }\n"); + sb.append("#hor-minimalist-a tbody tr:hover td { color: #009; }\n"); + sb.append("</style>\n"); + sb.append("<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js\"></script>"); + sb.append("<script type=\"text/javascript\" language=\"javascript\">\n"); + sb.append("//<![CDATA[\n"); + sb.append("function showOnlyCat(className){\n"); + sb.append(" $('div').show(); $('div').not('.'+className).hide(); }\n"); + sb.append("function showAllCat(){\n"); + sb.append(" $('div').show() };\n"); + sb.append("//]]>\n"); + sb.append("</script>\n"); + sb.append("</head><body>\n"); + return sb.toString(); } private String getFooter() { return "</body></html>"; } + // this is a hack, because we just assume that every PropertyEditor is named + // as TypeEditor (e.g. ObjectPropertyEditor); however that hack does not too much harm here + private static String getOptionType(ConfigOption option) { + String name = option.propertyEditorClass().getSimpleName(); + return name.substring(0, name.length()-6); + } + + private static String getCoreTypes(Class<? extends Component> comp) { + List<Class<? extends Component>> types = AnnComponentManager.getCoreComponentTypes(comp); + String str = ""; + for(Class<?extends Component> type : types) { + str += " " + type.getSimpleName(); + } + return str.substring(1); + } + public static void main(String[] args) { - File file = new File("doc/configOptions.html"); + File file = new File("../interfaces/doc/configOptions.html"); DocumentationHTMLGenerator dg = new DocumentationHTMLGenerator(); dg.writeConfigDocumentation(file); System.out.println("Done"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-17 19:24:02
|
Revision: 3063 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3063&view=rev Author: jenslehmann Date: 2011-08-17 18:38:28 +0000 (Wed, 17 Aug 2011) Log Message: ----------- implemented new simple negative example finder for SPARQL and integrated it in enrichment script Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-08-17 14:34:36 UTC (rev 3062) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2011-08-17 18:38:28 UTC (rev 3063) @@ -100,7 +100,7 @@ "org.dllearner.kb.KBFile", "org.dllearner.kb.sparql.SparqlKnowledgeSource", "org.dllearner.kb.OWLAPIOntology", - "org.dllearner.kb.SparqlEndpointKS", +// "org.dllearner.kb.SparqlEndpointKS", //reasoners "org.dllearner.reasoning.OWLAPIReasoner", "org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner", // added by Josue Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2011-08-17 14:34:36 UTC (rev 3062) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2011-08-17 18:38:28 UTC (rev 3063) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2011, Jens Lehmann * * This file is part of DL-Learner. * @@ -38,12 +38,14 @@ import com.hp.hpl.jena.query.ResultSetFactory; import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.query.ResultSetRewindable; -import com.hp.hpl.jena.sparql.core.ResultBinding; /** - * @author Sebastian Hellmann Convenience class for SPARQL queries initialized + * Convenience class for SPARQL queries initialized * with a SparqlEndpoint. A Cache can also be used to further improve * query time. Some methods allow basic reasoning + * + * @author Sebastian Hellmann + * @author Jens Lehmann */ public class SPARQLTasks { @@ -93,6 +95,16 @@ // TODO check for quotes in uris return getRecursiveSuperOrSubClasses(classURI, maxDepth, false); } + + public SortedSet<String> getParallelClasses(String classURI, int limit) { + String query = "SELECT ?sub WHERE { <" + classURI + "> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super ."; + query += "?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super ."; + query += "FILTER( ?sub != <" + classURI + ">) . } LIMIT " + limit; + return queryAsSet(query, "?sub"); +// SparqlQuery sq = new SparqlQuery(query, sparqlEndpoint); +// ResultSet rs = sq.send(); + + } /** * This is the underlying function to get Super and SubClasses. Added: trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2011-08-17 18:38:28 UTC (rev 3063) @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2007-2011, 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.examples; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.utilities.datastructures.Datastructures; + +/** + * + * Utility class for automatically retrieving negative examples from a + * SPARQL endpoint given a set of positive examples. + * + * @author Jens Lehmann + * @author Sebastian Hellmann + * + */ +public class AutomaticNegativeExampleFinderSPARQL2 { + + private SparqlEndpoint se; + + // for re-using existing queries + private SPARQLReasoner sr; + private SPARQLTasks st; + + public AutomaticNegativeExampleFinderSPARQL2(SparqlEndpoint se) { + this.se = se; + SparqlEndpointKS ks = new SparqlEndpointKS(se); + sr = new SPARQLReasoner(ks); + st = new SPARQLTasks(se); + } + + /** + * Get negative examples when learning the description of a class, i.e. + * all positives are from some known class. + * + * Currently, the method implementation is preliminary and does not allow + * to configure internals. + * + * @param classURI The known class of all positive examples. + * @param positiveExamples The existing positive examples. + */ + public SortedSet<String> getNegativeExamples(String classURI, SortedSet<String> positiveExamples) { + // get some individuals from parallel classes (we perform one query per class to avoid + // only getting individuals from a single class) + Set<String> parallelClasses = st.getParallelClasses(classURI, 5); // TODO: limit could be configurable + SortedSet<String> negEx = new TreeSet<String>(); + for(String parallelClass : parallelClasses) { + Set<String> inds = Datastructures.individualSetToStringSet(sr.getIndividuals(new NamedClass(parallelClass), 10)); + negEx.addAll(inds); + if(negEx.size()>100) { + return negEx; + } + } + // add some random instances + String query = "SELECT ?inst { ?inst <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?x } LIMIT 20"; + negEx.addAll(st.queryAsSet(query, "?inst")); + return negEx; + } + +} Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 14:34:36 UTC (rev 3062) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 18:38:28 UTC (rev 3063) @@ -36,6 +36,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -99,8 +100,10 @@ import org.dllearner.utilities.EnrichmentVocabulary; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.SystemOutDocumentTarget; import org.semanticweb.owlapi.model.IRI; @@ -185,7 +188,6 @@ classAlgorithms.add(CELOE.class); } - @SuppressWarnings("unchecked") public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, MalformedURLException { // sanity check that endpoint/graph returns at least one triple @@ -210,15 +212,18 @@ st.getAllObjectProperties(); } else { if(resource instanceof ObjectProperty) { + System.out.println(resource + " appears to be an object property. Running appropriate algorithms."); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof DatatypeProperty) { + System.out.println(resource + " appears to be a data property. Running appropriate algorithms."); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof NamedClass) { + System.out.println(resource + " appears to be a class. Running appropriate algorithms."); for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { if(algorithmClass == CELOE.class) { applyCELOE(ks, false); @@ -234,24 +239,31 @@ } private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, boolean equivalence) throws ComponentInitException, LearningProblemUnsupportedException, MalformedURLException { - SPARQLTasks st = new SPARQLTasks(se); +// SPARQLTasks st = new SPARQLTasks(se); // get instances of class as positive examples SPARQLReasoner sr = new SPARQLReasoner(ks); - SortedSet<Individual> posExamples = sr.getIndividuals((NamedClass)resource, 50); + SortedSet<Individual> posExamples = sr.getIndividuals((NamedClass)resource, 20); SortedSet<String> posExStr = Helper.getStringSet(posExamples); // get negative examples via various strategies - AutomaticNegativeExampleFinderSPARQL finder = new AutomaticNegativeExampleFinderSPARQL(posExStr, st, null); - finder.makeNegativeExamplesFromNearbyClasses(posExStr, 50); - finder.makeNegativeExamplesFromParallelClasses(posExStr, 50); - finder.makeNegativeExamplesFromRelatedInstances(posExStr, "http://dbpedia.org/resource/"); - finder.makeNegativeExamplesFromSuperClasses(resource.getName(), 50); +// AutomaticNegativeExampleFinderSPARQL finder = new AutomaticNegativeExampleFinderSPARQL(posExStr, st, null); +// finder.makeNegativeExamplesFromNearbyClasses(posExStr, 50); +// finder.makeNegativeExamplesFromParallelClasses(posExStr, 50); +// finder.makeNegativeExamplesFromRelatedInstances(posExStr, "http://dbpedia.org/resource/"); +// finder.makeNegativeExamplesFromSuperClasses(resource.getName(), 50); // finder.makeNegativeExamplesFromRandomInstances(); - SortedSet<String> negExStr = finder.getNegativeExamples(50, false); +// SortedSet<String> negExStr = finder.getNegativeExamples(50, false); + // use own implementation of negative example finder + System.out.print("finding negatives ... "); + AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); + SortedSet<String> negExStr = finder.getNegativeExamples(resource.getName(), posExStr); + negExStr = SetManipulation.fuzzyShrink(negExStr, 20); SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + System.out.println("done (" + negExStr.size()+ ")"); + ComponentManager cm = ComponentManager.getInstance(); SparqlKnowledgeSource ks2 = cm.knowledgeSource(SparqlKnowledgeSource.class); @@ -263,7 +275,9 @@ ks2.getConfigurator().setRecursionDepth(1); ks2.getConfigurator().setCloseAfterRecursion(true); // ks2.getConfigurator().setSaveExtractedFragment(true); + System.out.println("getting fragment ... "); ks2.init(); + System.out.println("done"); AbstractReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, ks2); rc.init(); @@ -276,15 +290,17 @@ lp.getConfigurator().setType("equivalence"); lp.getConfigurator().setAccuracyMethod("fmeasure"); lp.getConfigurator().setUseApproximations(false); + lp.getConfigurator().setMaxExecutionTimeInSeconds(10); lp.init(); - CELOE la = cm.learningAlgorithm(CELOE.class, lp, rc); CELOEConfigurator cc = la.getConfigurator(); cc.setMaxExecutionTimeInSeconds(100); cc.setNoisePercentage(20); la.init(); + System.out.print("running CELOE ... "); la.start(); + System.out.println("done"); // convert the result to axioms (to make it compatible with the other algorithms) TreeSet<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-18 09:22:47
|
Revision: 3068 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3068&view=rev Author: jenslehmann Date: 2011-08-18 09:22:41 +0000 (Thu, 18 Aug 2011) Log Message: ----------- - extended ConfigHelper with methods to get all config options and their values - worked on RDF output generation of enrichment script Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java 2011-08-18 09:22:16 UTC (rev 3067) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigHelper.java 2011-08-18 09:22:41 UTC (rev 3068) @@ -74,6 +74,58 @@ } /** + * + * @param component The component to analyse. + * @return All config options of the component with their respective value. + */ + public static Map<ConfigOption,String> getConfigOptionValuesString(Component component) { + Map<ConfigOption,String> optionValues = new HashMap<ConfigOption,String>(); + Field[] fields = getConfigOptions(component).getClass().getDeclaredFields(); + for(Field field : fields) { + ConfigOption option = field.getAnnotation(ConfigOption.class); + if(option != null) { + Class<? extends PropertyEditor> editorClass = option.propertyEditorClass(); + PropertyEditor editor = null; + try { + editor = editorClass.newInstance(); + Object object = field.get(component); + editor.setValue(object); + String value = editor.getAsText(); + optionValues.put(option, value); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + return optionValues; + } + + /** + * + * @param component The component to analyse. + * @return All config options of the component with their respective value. + */ + public static Map<ConfigOption,Object> getConfigOptionValues(Component component) { + Map<ConfigOption,Object> optionValues = new HashMap<ConfigOption,Object>(); + Field[] fields = getConfigOptions(component).getClass().getDeclaredFields(); + for(Field field : fields) { + ConfigOption option = field.getAnnotation(ConfigOption.class); + if(option != null) { + try { + optionValues.put(option, field.get(component)); + } catch (IllegalArgumentException e1) { + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + e1.printStackTrace(); + } + } + } + return optionValues; + } + + /** * Returns all config options for the given component. * @param component * @return Modified: trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-08-18 09:22:16 UTC (rev 3067) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ConfigOption.java 2011-08-18 09:22:41 UTC (rev 3068) @@ -19,6 +19,7 @@ */ package org.dllearner.core.config; +import java.beans.PropertyEditor; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -49,7 +50,7 @@ * An implementation of the Property Editor to use * @return */ - Class<?> propertyEditorClass(); + Class<? extends PropertyEditor> propertyEditorClass(); /** * Returns whether this option is required for initializing the component. Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-18 09:22:16 UTC (rev 3067) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-18 09:22:41 UTC (rev 3068) @@ -21,6 +21,8 @@ import static java.util.Arrays.asList; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; @@ -35,6 +37,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; @@ -79,6 +82,7 @@ import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigHelper; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.configurators.CELOEConfigurator; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; @@ -135,21 +139,29 @@ // data structure for holding the result of an algorithm run private class AlgorithmRun { - private LearningAlgorithm algorithm; + // we only store the algorithm class and not the learning algorithm object, + // since otherwise we run into memory problems for full enrichment + private Class<? extends LearningAlgorithm> algorithm; private List<EvaluatedAxiom> axioms; - - public AlgorithmRun(LearningAlgorithm algorithm, List<EvaluatedAxiom> axioms) { + private Map<ConfigOption,String> parameters; + + public AlgorithmRun(Class<? extends LearningAlgorithm> algorithm, List<EvaluatedAxiom> axioms, Map<ConfigOption,String> parameters) { this.algorithm = algorithm; this.axioms = axioms; + this.parameters = parameters; } - public LearningAlgorithm getAlgorithm() { + public Class<? extends LearningAlgorithm> getAlgorithm() { return algorithm; } public List<EvaluatedAxiom> getAxioms() { return axioms; } + + public Map<ConfigOption, String> getParameters() { + return parameters; + } } private static Logger logger = Logger.getLogger(Enrichment.class); @@ -177,8 +189,8 @@ private List<Class<? extends LearningAlgorithm>> classAlgorithms; // list of generated axioms while script is running + private List<AlgorithmRun> algorithmRuns; - private CommonPrefixMap prefixes = new CommonPrefixMap(); public Enrichment(SparqlEndpoint se, Entity resource, boolean verbose) { @@ -209,6 +221,8 @@ classAlgorithms.add(DisjointClassesLearner.class); classAlgorithms.add(SimpleSubclassLearner.class); classAlgorithms.add(CELOE.class); + + algorithmRuns = new LinkedList<AlgorithmRun>(); } @SuppressWarnings("unchecked") @@ -318,7 +332,7 @@ ks2.getConfigurator().setDefaultGraphURIs(new TreeSet<String>(ks.getEndpoint().getDefaultGraphURIs())); ks2.getConfigurator().setUseLits(false); ks2.getConfigurator().setUseCacheDatabase(true); - ks2.getConfigurator().setRecursionDepth(1); + ks2.getConfigurator().setRecursionDepth(2); ks2.getConfigurator().setCloseAfterRecursion(true); // ks2.getConfigurator().setSaveExtractedFragment(true); System.out.println("getting fragment ... "); @@ -371,7 +385,7 @@ evaluatedAxioms.add(new EvaluatedAxiom(axiom, score)); } - toRDF(evaluatedAxioms, la, ks); + algorithmRuns.add(new AlgorithmRun(CELOE.class, evaluatedAxioms, ConfigHelper.getConfigOptionValuesString(la))); cm.freeAllComponents(); return evaluatedAxioms; } @@ -409,7 +423,7 @@ .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); System.out.println(prettyPrint(learnedAxioms)); - toRDF(learnedAxioms, learner, ks); + algorithmRuns.add(new AlgorithmRun(learner.getClass(), learnedAxioms, ConfigHelper.getConfigOptionValuesString(learner))); return learnedAxioms; } @@ -437,11 +451,11 @@ /* * Generates list of OWL axioms. */ - private void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks){ - toRDF(evalAxioms, algorithm, ks, null); + private List<OWLAxiom> toRDF(List<EvaluatedAxiom> evalAxioms, Class<? extends LearningAlgorithm> algorithm, Map<ConfigOption,String> parameters, SparqlEndpointKS ks){ + return toRDF(evalAxioms, algorithm, parameters, ks, null); } - private void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks, String defaultNamespace){ + private List<OWLAxiom> toRDF(List<EvaluatedAxiom> evalAxioms, Class<? extends LearningAlgorithm> algorithm, Map<ConfigOption,String> parameters, SparqlEndpointKS ks, String defaultNamespace){ if(defaultNamespace == null || defaultNamespace.isEmpty()){ defaultNamespace = DEFAULT_NS; } @@ -464,7 +478,7 @@ ax = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.AlgorithmRun, algorithmRunInd); axioms.add(ax); //generate instance for algorithm - String algorithmName = algorithm.getClass().getAnnotation(ComponentAnn.class).name(); + String algorithmName = algorithm.getAnnotation(ComponentAnn.class).name(); String algorithmID = "http://dl-learner.org#" + algorithmName.replace(" ", "_"); OWLIndividual algorithmInd = f.getOWLNamedIndividual(IRI.create(algorithmID)); //add label to algorithm instance @@ -474,7 +488,7 @@ ax = f.getOWLAnnotationAssertionAxiom(algorithmInd.asOWLNamedIndividual().getIRI(), labelAnno); axioms.add(ax); //add version to algorithm - ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.version, algorithmInd, algorithm.getClass().getAnnotation(ComponentAnn.class).version()); + ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.version, algorithmInd, algorithm.getAnnotation(ComponentAnn.class).version()); axioms.add(ax); //add algorithm instance to algorithm run instance ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, @@ -512,9 +526,10 @@ } - printManchesterOWLSyntax(axioms, defaultNamespace); - printTurtleSyntax(axioms); +// printManchesterOWLSyntax(axioms, defaultNamespace); +// printTurtleSyntax(axioms); // printNTriplesSyntax(axioms); + return axioms; } private String generateId(){ @@ -546,6 +561,16 @@ } } + private Model getModel(List<OWLAxiom> axioms) { + Model model = ModelFactory.createDefaultModel(); + try { + Conversion.OWLAPIOntology2JenaModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)), model); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } + return model; + } + /* * Write axioms in Turtle syntax. */ @@ -578,6 +603,10 @@ } } + public List<AlgorithmRun> getAlgorithmRuns() { + return algorithmRuns; + } + public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException { SimpleLayout layout = new SimpleLayout(); @@ -598,9 +627,9 @@ parser.acceptsAll(asList("r", "resource"), "The resource for which enrichment axioms should be suggested.").withOptionalArg().ofType(URI.class); parser.acceptsAll(asList("o", "output"), "Specify a file where the output can be written.") - .withOptionalArg(); + .withOptionalArg().ofType(File.class); parser.acceptsAll(asList("f", "format"), - "Format of the generated output (plain, html, rdf).").withOptionalArg() + "Format of the generated output (plain, html, rdf/xml, turtle, manchester, sparul).").withOptionalArg() .ofType(String.class).defaultsTo("plain"); // parse options and display a message for the user in case of problems @@ -651,8 +680,31 @@ Enrichment e = new Enrichment(se, resource, verbose); e.start(); - // TODO: print output in correct format + SparqlEndpointKS ks = new SparqlEndpointKS(se); + // TODO: some handling for inaccessible files or overwriting existing files + File f = (File) options.valueOf("o"); + + // print output in correct format + if(options.has("f")) { + // TODO: handle other formats + if(options.valueOf("f").equals("turtle")) { + List<AlgorithmRun> runs = e.getAlgorithmRuns(); + List<OWLAxiom> axioms = new LinkedList<OWLAxiom>(); + for(AlgorithmRun run : runs) { + axioms.addAll(e.toRDF(run.getAxioms(), run.getAlgorithm(), run.getParameters(), ks)); + } + Model model = e.getModel(axioms); + if(options.has("o")) { + model.write(new FileOutputStream(f)); + } else { + System.out.println("ENRICHMENT["); + model.write(System.out); + System.out.println("]"); + } + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-18 14:49:28
|
Revision: 3069 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3069&view=rev Author: lorenz_b Date: 2011-08-18 14:49:21 +0000 (Thu, 18 Aug 2011) Log Message: ----------- Small bugfix. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWL2SPARULConverter.java trunk/scripts/src/main/resources/log4j.properties Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-18 09:22:41 UTC (rev 3068) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-08-18 14:49:21 UTC (rev 3069) @@ -288,7 +288,7 @@ l.init(); l.start(); - for(EvaluatedDescription e : l.getCurrentlyBestEvaluatedDescriptions(300)){ + for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(50)){ System.out.println(e); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-18 09:22:41 UTC (rev 3068) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2011-08-18 14:49:21 UTC (rev 3069) @@ -137,9 +137,8 @@ public List<Axiom> getCurrentlyBestAxioms(int nrOfAxioms) { List<Axiom> bestAxioms = new ArrayList<Axiom>(); - Iterator<EvaluatedAxiom> it = currentlyBestAxioms.iterator(); - while(bestAxioms.size() < nrOfAxioms && it.hasNext()){ - bestAxioms.add(it.next().getAxiom()); + for(EvaluatedAxiom evAx : getCurrentlyBestEvaluatedAxioms(nrOfAxioms)){ + bestAxioms.add(evAx.getAxiom()); } return bestAxioms; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2011-08-18 09:22:41 UTC (rev 3068) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2011-08-18 14:49:21 UTC (rev 3069) @@ -19,6 +19,7 @@ */ package org.dllearner.core.owl; +import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -52,12 +53,31 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return "DisjointClasses()"; + StringBuffer sb = new StringBuffer(); + sb.append("DisjointClasses("); + Iterator<Description> it = descriptions.iterator(); + while(it.hasNext()){ + sb.append(it.next().toString()); + if(it.hasNext()){ + sb.append(", "); + } + } + sb.append(")"); + return sb.toString(); } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - throw new Error("DisjointClassesAxiom: Not implemented"); + StringBuffer sb = new StringBuffer(); + sb.append("DisjointClasses("); + Iterator<Description> it = descriptions.iterator(); + while(it.hasNext()){ + sb.append(it.next().toKBSyntaxString()); + if(it.hasNext()){ + sb.append(", "); + } + } + sb.append(")"); + return sb.toString(); } @@ -83,7 +103,17 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "DISJOINT_CLASSES_AXIOM NOT IMPLEMENTED"; + StringBuffer sb = new StringBuffer(); + sb.append("DisjointClasses("); + Iterator<Description> it = descriptions.iterator(); + while(it.hasNext()){ + sb.append(it.next().toManchesterSyntaxString(baseURI, prefixes)); + if(it.hasNext()){ + sb.append(", "); + } + } + sb.append(")"); + return sb.toString(); } } Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWL2SPARULConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWL2SPARULConverter.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWL2SPARULConverter.java 2011-08-18 14:49:21 UTC (rev 3069) @@ -0,0 +1,102 @@ +package org.dllearner.utilities.owl; + +import java.util.Collection; +import java.util.List; + +import org.coode.owlapi.rdf.model.AbstractTranslator; +import org.coode.owlapi.rdf.model.RDFLiteralNode; +import org.coode.owlapi.rdf.model.RDFNode; +import org.coode.owlapi.rdf.model.RDFResourceNode; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyChange; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.RemoveAxiom; + +public class OWL2SPARULConverter + extends + AbstractTranslator<RDFNode, RDFResourceNode, RDFResourceNode, RDFLiteralNode> { + private StringBuilder sb; + + public OWL2SPARULConverter(OWLOntologyManager manager, + OWLOntology ontology, boolean useStrongTyping) { + super(manager, ontology, useStrongTyping); + } + + public OWL2SPARULConverter(OWLOntology ontology, boolean useStrongTyping) { + super(ontology.getOWLOntologyManager(), ontology, useStrongTyping); + } + + public String convert(OWLOntology ontology) { + return convert(ontology, true); + } + + public String convert(OWLOntology ontology, boolean add) { + return convert(ontology.getAxioms()); + } + + public String convert(Collection<OWLAxiom> axioms) { + return convert(axioms, true); + } + + public String convert(Collection<OWLAxiom> axioms, boolean add) { + sb = new StringBuilder(); + for (OWLAxiom ax : axioms) { + sb.append(add ? "INSERT DATA" + : "DELETE DATA"); + sb.append("{"); + ax.accept(this); + sb.append("}"); + sb.append("\n"); + } + return sb.toString(); + } + + public String translate(List<OWLOntologyChange> changes) { + sb = new StringBuilder(); + for (OWLOntologyChange change : changes) { + sb.append(change instanceof RemoveAxiom ? "DELETE DATA" + : "INSERT DATA"); + sb.append("{"); + change.getAxiom().accept(this); + sb.append("}"); + sb.append("\n"); + } + return sb.toString(); + } + + @Override + protected void addTriple(RDFResourceNode subject, RDFResourceNode pred, + RDFNode object) { + sb.append(subject).append(" ").append(pred).append(" ").append(object); + + } + + @Override + protected RDFResourceNode getAnonymousNode(Object key) { + return new RDFResourceNode(System.identityHashCode(key)); + } + + @Override + protected RDFResourceNode getPredicateNode(IRI iri) { + return new RDFResourceNode(iri); + } + + @Override + protected RDFResourceNode getResourceNode(IRI iri) { + return new RDFResourceNode(iri); + } + + @Override + protected RDFLiteralNode getLiteralNode(OWLLiteral literal) { + if (literal.getDatatype() != null) { + return new RDFLiteralNode(literal.toString(), literal.getDatatype() + .getIRI()); + } else { + return new RDFLiteralNode(literal.toString(), literal.getLang()); + } + + } +} Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-18 09:22:41 UTC (rev 3068) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-18 14:49:21 UTC (rev 3069) @@ -21,6 +21,7 @@ import static java.util.Arrays.asList; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -127,6 +128,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Statement; /** * Command Line Interface for Enrichment. @@ -495,7 +497,16 @@ algorithmRunInd, algorithmInd); axioms.add(ax); //add Parameters to algorithm run instance - //TODO + OWLIndividual paramInd; + for(Entry<ConfigOption, String> entry : parameters.entrySet()){ + paramInd = f.getOWLNamedIndividual(IRI.create(generateId())); + ax = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Parameter, paramInd); + axioms.add(ax); + ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.parameterName, paramInd, entry.getKey().name()); + axioms.add(ax); + ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.parameterValue, paramInd, entry.getValue()); + axioms.add(ax); + } //add used input to algorithm run instance try { OWLNamedIndividual knowldegeBaseInd = f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL())); @@ -561,10 +572,24 @@ } } +// private Model getModel(List<OWLAxiom> axioms) { +// Model model = ModelFactory.createDefaultModel(); +// try { +// Conversion.OWLAPIOntology2JenaModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)), model); +// } catch (OWLOntologyCreationException e) { +// e.printStackTrace(); +// } +// return model; +// } + private Model getModel(List<OWLAxiom> axioms) { Model model = ModelFactory.createDefaultModel(); try { - Conversion.OWLAPIOntology2JenaModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)), model); + OWLOntology ontology = OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)); +// String s = new org.aksw.commons.owlapi.StringConverter(ontology).toStringAsRDFXML();System.out.println(s); + String s = new org.aksw.commons.owlapi.StringConverter(ontology).toStringAsTurtle();System.out.println(s); + ByteArrayInputStream bs = new ByteArrayInputStream(s.getBytes()); + model.read(bs, "", "TURTLE"); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } @@ -695,6 +720,18 @@ axioms.addAll(e.toRDF(run.getAxioms(), run.getAlgorithm(), run.getParameters(), ks)); } Model model = e.getModel(axioms); + for(Statement st : model.listStatements().toList()){ + System.out.println("--------------------"); +// System.out.println(st); + if(st.getSubject().isResource()){ + System.out.println(st.getSubject()); + } + System.out.println(st.getPredicate()); + if(st.getObject().isResource()){ + + } + System.out.println(st.getObject()); + } if(options.has("o")) { model.write(new FileOutputStream(f)); } else { Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-18 09:22:41 UTC (rev 3068) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-18 14:49:21 UTC (rev 3069) @@ -38,7 +38,11 @@ import java.util.Set; import java.util.prefs.Preferences; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.apache.velocity.context.EvaluateContext; import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.algorithms.celoe.CELOE; @@ -59,14 +63,17 @@ import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; +import org.dllearner.core.AbstractCELA; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; @@ -94,9 +101,9 @@ private int nrOfAxiomsToLearn = 10; // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 10; - private int maxDataProperties = 10; - private int maxClasses = 10; + private int maxObjectProperties = 0; + private int maxDataProperties = 0; + private int maxClasses = 0; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -135,9 +142,9 @@ dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); - classAlgorithms.add(DisjointClassesLearner.class); +// classAlgorithms.add(DisjointClassesLearner.class); classAlgorithms.add(SimpleSubclassLearner.class); - classAlgorithms.add(CELOE.class); +// classAlgorithms.add(CELOE.class); initDBConnection(); } @@ -196,7 +203,7 @@ IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { long overallStartTime = System.currentTimeMillis(); - ComponentManager cm = ComponentManager.getInstance(); +// ComponentManager cm = ComponentManager.getInstance(); // create DBpedia Live knowledge source SparqlEndpoint se = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); @@ -206,8 +213,10 @@ evaluateObjectProperties(ks); -// evaluateDataProperties(ks); + evaluateDataProperties(ks); + evaluateClasses(ks); + System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); } @@ -217,50 +226,58 @@ for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { int objectProperties = 0; - for (ObjectProperty property : properties) { - - // dynamically invoke constructor with SPARQL knowledge source - AxiomLearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - learner.init(); - // learner.setPropertyToDescribe(property); - // learner.setMaxExecutionTimeInSeconds(10); - String algName = AnnComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + property + " ... "); - long startTime = System.currentTimeMillis(); - boolean timeout = false; - try { - learner.start(); - } catch (Exception e) { - if(e.getCause() instanceof SocketTimeoutException){ - timeout = true; - } - } - long runTime = System.currentTimeMillis() - startTime; - List<EvaluatedAxiom> learnedAxioms = learner - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - if(timeout){ - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); - } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); - } else { - for (EvaluatedAxiom learnedAxiom : learnedAxioms) { - double score = learnedAxiom.getScore().getAccuracy(); - if (Double.isNaN(score)) { - score = -1; + + String algName = ""; + for (ObjectProperty property : properties) { + + try { + // dynamically invoke constructor with SPARQL knowledge source + AxiomLearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + learner.init(); + // learner.setPropertyToDescribe(property); + // learner.setMaxExecutionTimeInSeconds(10); + algName = AnnComponentManager.getName(learner); + System.out.println("Applying " + algName + " on " + property + " ... "); + long startTime = System.currentTimeMillis(); + boolean timeout = false; + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true;throw e; + } } - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), - score, runTime); + long runTime = System.currentTimeMillis() - startTime; + List<EvaluatedAxiom> learnedAxioms = learner + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + if(timeout){ + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); + } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + double score = learnedAxiom.getScore().getAccuracy(); + if (Double.isNaN(score)) { + score = -1; + } + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), + score, runTime); + } + } + objectProperties++; + if (maxObjectProperties != 0 && objectProperties > maxObjectProperties) { + break; + } + + } catch (Exception e) { + logger.error("Error occured for object property " + property.getName() + " with algorithm " + algName , e); } } - objectProperties++; - if (maxObjectProperties != 0 && objectProperties > maxObjectProperties) { - break; - } - } + } } @@ -269,8 +286,11 @@ for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { int dataProperties = 0; + + String algName = ""; for (DatatypeProperty property : properties) { + try{ // dynamically invoke constructor with SPARQL knowledge source AxiomLearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); @@ -280,7 +300,7 @@ learner.init(); // learner.setPropertyToDescribe(property); // learner.setMaxExecutionTimeInSeconds(10); - String algName = AnnComponentManager.getName(learner); + algName = AnnComponentManager.getName(learner); System.out.println("Applying " + algName + " on " + property + " ... "); long startTime = System.currentTimeMillis(); boolean timeout = false; @@ -312,10 +332,76 @@ if (maxDataProperties != 0 && dataProperties > maxDataProperties) { break; } + + } catch (Exception e) { + logger.error("Error occured for data property " + property.getName() + " with algorithm " + algName , e); } + } } } + + private void evaluateClasses(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException{ + Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); + for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { + int classesCnt = 0; + for (NamedClass cls : classes) { + + try{ + // dynamically invoke constructor with SPARQL knowledge source + LearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + ConfigHelper.configure(learner, "classToDescribe", cls.toString()); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + learner.init(); + // learner.setPropertyToDescribe(property); + // learner.setMaxExecutionTimeInSeconds(10); + String algName = AnnComponentManager.getName(learner); + System.out.println("Applying " + algName + " on " + cls + " ... "); + long startTime = System.currentTimeMillis(); + boolean timeout = false; + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true; + } + } + long runTime = System.currentTimeMillis() - startTime; + if(learner instanceof AxiomLearningAlgorithm){ + List<EvaluatedAxiom> learnedAxioms = ((AxiomLearningAlgorithm)learner) + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + if(timeout){ + writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); + } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { + writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + double score = learnedAxiom.getScore().getAccuracy(); + if (Double.isNaN(score)) { + score = -1; + } + writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), + score, runTime); + } + } + } else if(learner instanceof AbstractCELA){ + + } + + classesCnt++; + if (maxClasses != 0 && classesCnt > maxClasses) { + break; + } + + } catch(Exception e){ + logger.error("Error occured for class " + cls.getName(), e); + } + } + } + } + public void printResultsPlain() { } @@ -357,11 +443,15 @@ public static void main(String[] args) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, - NoSuchMethodException, ComponentInitException, SQLException { + NoSuchMethodException, ComponentInitException, SQLException, IOException { EnrichmentEvaluation ee = new EnrichmentEvaluation(); ee.start(); // ee.printResultsPlain(); Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); + FileAppender app = new FileAppender(new SimpleLayout(), "log/enrichmentEvalErrors.log"); + Logger.getRootLogger().setLevel(Level.ERROR); + Logger.getRootLogger().removeAllAppenders(); + Logger.getRootLogger().addAppender(app); } } Added: trunk/scripts/src/main/resources/log4j.properties =================================================================== --- trunk/scripts/src/main/resources/log4j.properties (rev 0) +++ trunk/scripts/src/main/resources/log4j.properties 2011-08-18 14:49:21 UTC (rev 3069) @@ -0,0 +1,9 @@ +log4j.appender.A1=org.apache.log4j.RollingFileAppender +log4j.appender.A1.File=log/errors.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout + +log4j.appender.A2=org.apache.log4j.RollingFileAppender +log4j.appender.A2.File=log/queries.log +log4j.appender.A2.layout=org.apache.log4j.PatternLayout + +log4j.rootLogger=ERROR,A1 \ 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...> - 2011-08-19 14:28:34
|
Revision: 3073 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3073&view=rev Author: jenslehmann Date: 2011-08-19 14:28:26 +0000 (Fri, 19 Aug 2011) Log Message: ----------- adapted parser for extended conf file syntax + example Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption.java Added Paths: ----------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConstants.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserTokenManager.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ParseException.java trunk/interfaces/src/main/java/org/dllearner/confparser2/SimpleCharStream.java trunk/interfaces/src/main/java/org/dllearner/confparser2/Token.java trunk/interfaces/src/main/java/org/dllearner/confparser2/TokenMgrError.java trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj trunk/test/newconf/ trunk/test/newconf/test1.conf Added: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-19 14:28:26 UTC (rev 3073) @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2007-2011, 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.cli; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.List; + +import org.dllearner.confparser2.ConfParser; +import org.dllearner.confparser2.ParseException; + +/** + * + * New commandline interface. + * + * @author Jens Lehmann + * + */ +public class CLI { + + /** + * @param args + * @throws ParseException + * @throws FileNotFoundException + */ + public static void main(String[] args) throws FileNotFoundException, ParseException { + ConfParser parser = ConfParser.parseFile(new File("../test/newconf/test1.conf")); + List<ConfFileOption> options = parser.getConfOptions(); + for(ConfFileOption option : options) { + System.out.println(option); + } + + System.out.println("positive examples: " + parser.getPositiveExamples()); + System.out.println("negative examples: " + parser.getNegativeExamples()); + } + +} Modified: trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption.java 2011-08-19 11:12:51 UTC (rev 3072) +++ trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption.java 2011-08-19 14:28:26 UTC (rev 3073) @@ -205,7 +205,12 @@ else return completeOption + "=" + doubleValue; else - return completeOption + "=" + stringValue; + if(isListOption) + return completeOption + "=" + listTuples; + else if(isSetOption) + return completeOption + "=" + setValues; + else + return completeOption + "=" + stringValue; } public String getFullName() { Added: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java 2011-08-19 14:28:26 UTC (rev 3073) @@ -0,0 +1,897 @@ +/* Generated By:JavaCC: Do not edit this line. ConfParser.java */ +package org.dllearner.confparser2; + +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.HashSet; +import java.util.SortedSet; +import java.util.TreeSet; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.dllearner.Info; + +import org.dllearner.cli.*; +import org.dllearner.parser.KBParser; +import org.dllearner.utilities.datastructures.*; + +public class ConfParser implements ConfParserConstants { + + // examples + private SortedSet<String> positiveExamples = new TreeSet<String>(); + private SortedSet<String> negativeExamples = new TreeSet<String>(); + + // conf file options + private List<ConfFileOption> confOptions = new LinkedList<ConfFileOption>(); + private Map<String,ConfFileOption> confOptionsByName = new HashMap<String,ConfFileOption>(); + private Map<String,List<ConfFileOption>> confOptionsByPrefix = new HashMap<String,List<ConfFileOption>>(); + + private void addConfOption(ConfFileOption confOption) { + confOptions.add(confOption); + confOptionsByName.put(confOption.getFullName(), confOption); + String prefix = confOption.getOption(); + if(confOptionsByPrefix.containsKey(prefix)) + confOptionsByPrefix.get(prefix).add(confOption); + else { + LinkedList<ConfFileOption> optionList = new LinkedList<ConfFileOption>(); + optionList.add(confOption); + confOptionsByPrefix.put(prefix,optionList); + } + } + + public SortedSet<String> getPositiveExamples() { + return positiveExamples; + } + + public SortedSet<String> getNegativeExamples() { + return negativeExamples; + } + + public List<ConfFileOption> getConfOptions() { + return confOptions; + } + + public Map<String,ConfFileOption> getConfOptionsByName() { + return confOptionsByName; + } + + public ConfFileOption getConfOptionsByName(String name) { + return confOptionsByName.get(name); + } + + public Map<String,List<ConfFileOption>> getConfOptionsByPrefix() { + return confOptionsByPrefix; + } + + public List<ConfFileOption> getConfOptionsByPrefix(String prefix) { + return confOptionsByPrefix.get(prefix); + } + + public static ConfParser parseFile(File filename) throws FileNotFoundException, ParseException { + ConfParser parser = new ConfParser(new FileInputStream(filename)); + parser.Start(); + return parser; + } + + final public void Start() throws ParseException { + ConfFileOption confOption; + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case POS_EX: + case NEG_EX: + case ID: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + if (jj_2_1(2147483647)) { + confOption = ConfOption(); + addConfOption(confOption); + } else if (jj_2_2(2147483647)) { + PosExample(); + } else if (jj_2_3(2147483647)) { + NegExample(); + } else { + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(0); + } + + final public ConfFileOption ConfOption() throws ParseException { + boolean containsSubOption=false, isNumeric=false, isDouble=false, isSet=false, isList=false, useColon=false; + String option="", subOption="", value="", value1="", value2="", tmp="", tmp2=""; + int number = 0; + double numberDouble = 0; + ConfFileOption confOption; + Set<String> values = new HashSet<String>(); + List<StringTuple> tuples = new LinkedList<StringTuple>(); + option = Id(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMAND_END: + jj_consume_token(COMMAND_END); + subOption = Id(); + containsSubOption=true; + break; + default: + jj_la1[1] = jj_gen; + ; + } + jj_consume_token(25); + if (jj_2_6(2)) { + value1 = Id(); + jj_consume_token(28); + value2 = Id(); + useColon = true; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + value = Id(); + break; + case STRING: + value = String(); + break; + case NUMBER: + number = Integer(); + isNumeric=true; + break; + case DOUBLE: + numberDouble = Double(); + isNumeric=true; isDouble=true; + break; + default: + jj_la1[8] = jj_gen; + if (jj_2_7(2147483647)) { + jj_consume_token(26); + jj_consume_token(29); + isSet=true; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 26: + jj_consume_token(26); + label_2: + while (true) { + if (jj_2_4(2)) { + ; + } else { + break label_2; + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + values.add(tmp); + jj_consume_token(30); + } + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + values.add(tmp); + jj_consume_token(29); + isSet=true; + break; + default: + jj_la1[9] = jj_gen; + if (jj_2_8(2147483647)) { + jj_consume_token(27); + jj_consume_token(31); + isList=true; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 27: + jj_consume_token(27); + label_3: + while (true) { + if (jj_2_5(6)) { + ; + } else { + break label_3; + } + jj_consume_token(32); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(30); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp2 = String(); + break; + case ID: + tmp2 = Id(); + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(33); + tuples.add(new StringTuple(tmp,tmp2)); + jj_consume_token(30); + } + jj_consume_token(32); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[6] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(30); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp2 = String(); + break; + case ID: + tmp2 = Id(); + break; + default: + jj_la1[7] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(33); + tuples.add(new StringTuple(tmp,tmp2)); + jj_consume_token(31); + isList=true; + break; + default: + jj_la1[10] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + } + } + jj_consume_token(CONF_END); + if(containsSubOption) { + if(isNumeric) + if(isDouble) + confOption = new ConfFileOption(option,subOption,numberDouble); + else + confOption = new ConfFileOption(option,subOption,number); + else + if(isSet) + confOption = new ConfFileOption(option,subOption,values); + else if(isList) + confOption = new ConfFileOption(option,subOption,tuples); + else + { if(useColon) + confOption = new ConfFileOption(option,subOption,value1 + ":" + value2); + else + confOption = new ConfFileOption(option,subOption,value); + } + + } else { + if(isNumeric) + if(isDouble) + confOption = new ConfFileOption(option,numberDouble); + else + confOption = new ConfFileOption(option,number); + else + if(isSet) + confOption = new ConfFileOption(option,values); + else if(isList) + confOption = new ConfFileOption(option,tuples); + else + confOption = new ConfFileOption(option,value); + } + {if (true) return confOption;} + throw new Error("Missing return statement in function"); + } + + final public void PosExample() throws ParseException { + String i; + jj_consume_token(POS_EX); + i = Individual(); + positiveExamples.add(i); + } + + final public void NegExample() throws ParseException { + String i; + jj_consume_token(NEG_EX); + i = Individual(); + negativeExamples.add(i); + } + + final public String Individual() throws ParseException { + String name; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + name = Id(); + break; + case STRING: + name = String(); + break; + default: + jj_la1[11] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + {if (true) return KBParser.getInternalURI(name);} + throw new Error("Missing return statement in function"); + } + + final public String Id() throws ParseException { + Token t; + t = jj_consume_token(ID); + {if (true) return t.image;} + throw new Error("Missing return statement in function"); + } + + final public double Double() throws ParseException { + Token t; + t = jj_consume_token(DOUBLE); + {if (true) return new Double(t.image);} + throw new Error("Missing return statement in function"); + } + + final public int Integer() throws ParseException { + Token t; + t = jj_consume_token(NUMBER); + {if (true) return new Integer(t.image);} + throw new Error("Missing return statement in function"); + } + + final public String String() throws ParseException { + Token t; + String s; + t = jj_consume_token(STRING); + // enclosing "" are removed + s = t.image; + s = s.substring(1, s.length() - 1); + {if (true) return s;} + throw new Error("Missing return statement in function"); + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + private boolean jj_2_4(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + private boolean jj_2_5(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + private boolean jj_2_6(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + private boolean jj_2_7(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_7(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + private boolean jj_2_8(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_8(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(7, xla); } + } + + private boolean jj_3R_5() { + if (jj_scan_token(COMMAND_END)) return true; + if (jj_3R_4()) return true; + return false; + } + + private boolean jj_3R_11() { + if (jj_3R_4()) return true; + return false; + } + + private boolean jj_3_6() { + if (jj_3R_4()) return true; + if (jj_scan_token(28)) return true; + return false; + } + + private boolean jj_3_3() { + if (jj_scan_token(NEG_EX)) return true; + return false; + } + + private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; + return false; + } + + private boolean jj_3_2() { + if (jj_scan_token(POS_EX)) return true; + return false; + } + + private boolean jj_3_1() { + if (jj_3R_4()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_5()) jj_scanpos = xsp; + if (jj_scan_token(25)) return true; + xsp = jj_scanpos; + if (jj_3R_6()) { + jj_scanpos = xsp; + if (jj_3R_7()) { + jj_scanpos = xsp; + if (jj_3R_8()) { + jj_scanpos = xsp; + if (jj_3R_9()) { + jj_scanpos = xsp; + if (jj_scan_token(26)) { + jj_scanpos = xsp; + if (jj_scan_token(27)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_12() { + if (jj_3R_18()) return true; + return false; + } + + private boolean jj_3R_15() { + if (jj_3R_4()) return true; + return false; + } + + private boolean jj_3R_8() { + if (jj_3R_17()) return true; + return false; + } + + private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; + return false; + } + + private boolean jj_3R_10() { + if (jj_3R_18()) return true; + return false; + } + + private boolean jj_3R_7() { + if (jj_3R_16()) return true; + return false; + } + + private boolean jj_3_8() { + if (jj_scan_token(27)) return true; + if (jj_scan_token(31)) return true; + return false; + } + + private boolean jj_3R_14() { + if (jj_3R_18()) return true; + return false; + } + + private boolean jj_3R_18() { + if (jj_scan_token(STRING)) return true; + return false; + } + + private boolean jj_3_5() { + if (jj_scan_token(32)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_12()) { + jj_scanpos = xsp; + if (jj_3R_13()) return true; + } + if (jj_scan_token(30)) return true; + xsp = jj_scanpos; + if (jj_3R_14()) { + jj_scanpos = xsp; + if (jj_3R_15()) return true; + } + if (jj_scan_token(33)) return true; + if (jj_scan_token(30)) return true; + return false; + } + + private boolean jj_3_7() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(29)) return true; + return false; + } + + private boolean jj_3R_6() { + if (jj_3R_4()) return true; + return false; + } + + private boolean jj_3_4() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_10()) { + jj_scanpos = xsp; + if (jj_3R_11()) return true; + } + if (jj_scan_token(30)) return true; + return false; + } + + private boolean jj_3R_16() { + if (jj_scan_token(NUMBER)) return true; + return false; + } + + private boolean jj_3R_13() { + if (jj_3R_4()) return true; + return false; + } + + private boolean jj_3R_9() { + if (jj_3R_18()) return true; + return false; + } + + /** Generated Token Manager. */ + public ConfParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[12]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static { + jj_la1_init_0(); + jj_la1_init_1(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x1c00,0x100,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1007000,0x4000000,0x8000000,0x1001000,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[8]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public ConfParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public ConfParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ConfParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public ConfParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ConfParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public ConfParser(ConfParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(ConfParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[34]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 12; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<<j)) != 0) { + la1tokens[j] = true; + } + if ((jj_la1_1[i] & (1<<j)) != 0) { + la1tokens[32+j] = true; + } + } + } + } + for (int i = 0; i < 34; i++) { + if (la1tokens[i]) { + jj_expentry = new int[1]; + jj_expentry[0] = i; + jj_expentries.add(jj_expentry); + } + } + jj_endpos = 0; + jj_rescan_token(); + jj_add_error_token(0, 0); + int[][] exptokseq = new int[jj_expentries.size()][]; + for (int i = 0; i < jj_expentries.size(); i++) { + exptokseq[i] = jj_expentries.get(i); + } + return new ParseException(token, exptokseq, tokenImage); + } + + /** Enable tracing. */ + final public void enable_tracing() { + } + + /** Disable tracing. */ + final public void disable_tracing() { + } + + private void jj_rescan_token() { + jj_rescan = true; + for (int i = 0; i < 8; i++) { + try { + JJCalls p = jj_2_rtns[i]; + do { + if (p.gen > jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + case 7: jj_3_8(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConstants.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConstants.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConstants.java 2011-08-19 14:28:26 UTC (rev 3073) @@ -0,0 +1,95 @@ +/* Generated By:JavaCC: Do not edit this line. ConfParserConstants.java */ +package org.dllearner.confparser2; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface ConfParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int SINGLE_LINE_COMMENT = 5; + /** RegularExpression Id. */ + int FORMAL_COMMENT = 6; + /** RegularExpression Id. */ + int MULTI_LINE_COMMENT = 7; + /** RegularExpression Id. */ + int COMMAND_END = 8; + /** RegularExpression Id. */ + int CONF_END = 9; + /** RegularExpression Id. */ + int POS_EX = 10; + /** RegularExpression Id. */ + int NEG_EX = 11; + /** RegularExpression Id. */ + int ID = 12; + /** RegularExpression Id. */ + int NUMBER = 13; + /** RegularExpression Id. */ + int DOUBLE = 14; + /** RegularExpression Id. */ + int TOP = 15; + /** RegularExpression Id. */ + int BOTTOM = 16; + /** RegularExpression Id. */ + int AND = 17; + /** RegularExpression Id. */ + int OR = 18; + /** RegularExpression Id. */ + int EXISTS = 19; + /** RegularExpression Id. */ + int ALL = 20; + /** RegularExpression Id. */ + int NOT = 21; + /** RegularExpression Id. */ + int GE = 22; + /** RegularExpression Id. */ + int LE = 23; + /** RegularExpression Id. */ + int STRING = 24; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "<EOF>", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "<SINGLE_LINE_COMMENT>", + "<FORMAL_COMMENT>", + "<MULTI_LINE_COMMENT>", + "\".\"", + "\";\"", + "\"+\"", + "\"-\"", + "<ID>", + "<NUMBER>", + "<DOUBLE>", + "\"TOP\"", + "\"BOTTOM\"", + "\"AND\"", + "\"OR\"", + "<EXISTS>", + "<ALL>", + "<NOT>", + "\">=\"", + "\"<=\"", + "<STRING>", + "\"=\"", + "\"{\"", + "\"[\"", + "\":\"", + "\"}\"", + "\",\"", + "\"]\"", + "\"(\"", + "\")\"", + }; + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserTokenManager.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserTokenManager.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserTokenManager.java 2011-08-19 14:28:26 UTC (rev 3073) @@ -0,0 +1,774 @@ +/* Generated By:JavaCC: Do not edit this line. ConfParserTokenManager.java */ +package org.dllearner.confparser2; +import java.util.HashMap; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.HashSet; +import java.util.SortedSet; +import java.util.TreeSet; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import org.dllearner.Info; +import org.dllearner.cli.*; +import org.dllearner.parser.KBParser; +import org.dllearner.utilities.datastructures.*; + +/** Token Manager. */ +public class ConfParserTokenManager implements ConfParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) +{ + switch (pos) + { + case 0: + if ((active0 & 0x20000L) != 0L) + return 13; + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 32); + case 41: + return jjStopAtPos(0, 33); + case 43: + return jjStopAtPos(0, 10); + case 44: + return jjStopAtPos(0, 30); + case 45: + return jjStopAtPos(0, 11); + case 46: + return jjStopAtPos(0, 8); + case 58: + return jjStopAtPos(0, 28); + case 59: + return jjStopAtPos(0, 9); + case 60: + return jjMoveStringLiteralDfa1_0(0x800000L); + case 61: + return jjStopAtPos(0, 25); + case 62: + return jjMoveStringLiteralDfa1_0(0x400000L); + case 65: + return jjMoveStringLiteralDfa1_0(0x20000L); + case 66: + return jjMoveStringLiteralDfa1_0(0x10000L); + case 79: + return jjMoveStringLiteralDfa1_0(0x40000L); + case 84: + return jjMoveStringLiteralDfa1_0(0x8000L); + case 91: + return jjStopAtPos(0, 27); + case 93: + return jjStopAtPos(0, 31); + case 123: + return jjStopAtPos(0, 26); + case 125: + return jjStopAtPos(0, 29); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 61: + if ((active0 & 0x400000L) != 0L) + return jjStopAtPos(1, 22); + else if ((active0 & 0x800000L) != 0L) + return jjStopAtPos(1, 23); + break; + case 78: + return jjMoveStringLiteralDfa2_0(active0, 0x20000L); + case 79: + return jjMoveStringLiteralDfa2_0(active0, 0x18000L); + case 82: + if ((active0 & 0x40000L) != 0L) + return jjStopAtPos(1, 18); + break; + default : + break; + } + return jjStartNfa_0(0, active0); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0); + return 2; + } + switch(curChar) + { + case 68: + if ((active0 & 0x20000L) != 0L) + return jjStopAtPos(2, 17); + break; + case 80: + if ((active0 & 0x8000L) != 0L) + return jjStopAtPos(2, 15); + break; + case 84: + return jjMoveStringLiteralDfa3_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(1, active0); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0); + return 3; + } + switch(curChar) + { + case 84: + return jjMoveStringLiteralDfa4_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(2, active0); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0); + return 4; + } + switch(curChar) + { + case 79: + return jjMoveStringLiteralDfa5_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(3, active0); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0); + return 5; + } + switch(curChar) + { + case 77: + if ((active0 & 0x10000L) != 0L) + return jjStopAtPos(5, 16); + break; + default : + break; + } + return jjStartNfa_0(4, active0); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 53; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 13) + kind = 13; + jjCheckNAddStates(0, 2); + } + else if (curChar == 48) + { + if (kind > 13) + kind = 13; + jjCheckNAdd(50); + } + else if (curChar == 47) + jjAddStates(3, 5); + else if (curChar == 34) + jjCheckNAddTwoStates(21, 22); + break; + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 12) + kind = 12; + jjstateSet[jjnewStateCnt++] = 1; + break; + case 20: + if (curChar == 34) + jjCheckNAddTwoStates(21, 22); + break; + case 21: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddTwoStates(21, 22); + break; + case 22: + if (curChar == 34 && kind > 24) + kind = 24; + break; + case 28: + if (curChar == 47) + jjAddStates(3, 5); + break; + case 29: + if (curChar == 47) + jjCheckNAddStates(6, 8); + break; + case 30: + if ((0xffffffffffffdbffL & l) != 0L) + jjCheckNAddStates(6, 8); + break; + case 31: + if ((0x2400L & l) != 0L && kind > 5) + kind = 5; + break; + case 32: + if (curChar == 10 && kind > 5) + kind = 5; + break; + case 33: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 32; + break; + case 34: + if (curChar == 42) + jjCheckNAddTwoStates(35, 36); + break; + case 35: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(35, 36); + break; + case 36: + if (curChar == 42) + jjCheckNAddStates(9, 11); + break; + case 37: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 38: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 39: + if (curChar == 47 && kind > 6) + kind = 6; + break; + case 40: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 34; + break; + case 41: + if (curChar == 42) + jjCheckNAddTwoStates(42, 43); + break; + case 42: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(42, 43); + break; + case 43: + if (curChar == 42) + jjCheckNAddStates(12, 14); + break; + case 44: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + case 45: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + case 46: + if (curChar == 47 && kind > 7) + kind = 7; + break; + case 47: + if ((0x3fe000000000000L & l) == 0L) + break; + if (kind > 13) + kind = 13; + jjCheckNAddStates(0, 2); + break; + case 48: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 13) + kind = 13; + jjCheckNAdd(48); + break; + case 49: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(49, 50); + break; + case 50: + if (curChar != 46) + break; + if (kind > 14) + kind = 14; + jjCheckNAdd(51); + break; + case 51: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 14) + kind = 14; + jjCheckNAdd(51); + break; + case 52: + if (curChar != 48) + break; + if (kind > 13) + kind = 13; + jjCheckNAdd(50); + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x7fffffe00000000L & l) != 0L) + { + if (kind > 12) + kind = 12; + jjCheckNAdd(1); + } + else if (curChar == 78) + jjAddStates(15, 16); + else if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 18; + else if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 13; + else if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 10; + else if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 1: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 12) + kind = 12; + jjCheckNAdd(1); + break; + case 2: + if (curChar == 83 && kind > 19) + kind = 19; + break; + case 3: + if (curChar == 84) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 4: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 3; + break; + case 5: + if (curChar == 73) + jjstateSet[jjnewStateCnt++] = 4; + break; + case 6: + if (curChar == 88) + jjstateSet[jjnewStateCnt++] = 5; + break; + case 7: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 8: + if (curChar == 69 && kind > 19) + kind = 19; + break; + case 9: + if (curChar == 77) + jjstateSet[jjnewStateCnt++] = 8; + break; + case 10: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 9; + break; + case 11: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 12: + if (curChar == 76 && kind > 20) + kind = 20; + break; + case 13: + case 15: + if (curChar == 76) + jjCheckNAdd(12); + break; + case 14: + if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 13; + break; + case 16: + if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 15; + break; + case 17: + if (curChar == 82) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 18: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 18; + break; + case 21: + if ((0xffffffffefffffffL & l) != 0L) + jjAddStates(17, 18); + break; + case 23: + if (curChar == 78) + jjAddStates(15, 16); + break; + case 24: + if (curChar == 71 && kind > 21) + kind = 21; + break; + case 25: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 24; + break; + case 26: + if (curChar == 84 && kind > 21) + kind = 21; + break; + case 27: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 26; + break; + case 30: + jjAddStates(6, 8); + break; + case 35: + jjCheckNAddTwoStates(35, 36); + break; + case 37: + case 38: + jjCheckNAddTwoStates(38, 36); + break; + case 42: + jjCheckNAddTwoStates(42, 43); + break; + case 44: + case 45: + jjCheckNAddTwoStates(45, 43); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 21: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(17, 18); + break; + case 30: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(6, 8); + break; + case 35: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(35, 36); + break; + case 37: + case 38: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 42: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(42, 43); + break; + case 44: + case 45: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 53 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 48, 49, 50, 29, 40, 41, 30, 31, 33, 36, 37, 39, 43, 44, 46, 25, + 27, 21, 22, +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, "\56", "\73", "\53", "\55", null, +null, null, "\124\117\120", "\102\117\124\124\117\115", "\101\116\104", "\117\122", +null, null, null, "\76\75", "\74\75", null, "\75", "\173", "\133", "\72", "\175", +"\54", "\135", "\50", "\51", }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0x3ffffff01L, +}; +static final long[] jjtoSkip = { + 0xfeL, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[53]; +private final int[] jjstateSet = new int[106]; +protected char curChar; +/** Constructor. */ +public ConfParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public ConfParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 53; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser2/ParseException.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ParseException.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ParseException.java 2011-08-19 14:28:26 UTC (rev 3073) @@ -0,0 +1,187 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package org.dllearner.confparser2; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(Token currentTokenVal, + int[][] expectedTokenSequencesVal, + String[] tokenImageVal + ) + { + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage"... [truncated message content] |
From: <sha...@us...> - 2011-08-19 23:24:46
|
Revision: 3074 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3074&view=rev Author: shadowtm Date: 2011-08-19 23:24:40 +0000 (Fri, 19 Aug 2011) Log Message: ----------- Added an IConfiguration interface to encapsulate the information needed for a DLLearner configuration. Made an implementation of this that wrapped the ConfParser. Added a test case to exercise all functionality of this implementation. Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/configuration/ trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java trunk/components-core/src/test/resources/ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java trunk/interfaces/src/test/java/org/dllearner/confparser2/ trunk/interfaces/src/test/java/org/dllearner/confparser2/ConfParserConfigurationTest.java trunk/interfaces/src/test/resources/ trunk/interfaces/src/test/resources/org/ trunk/interfaces/src/test/resources/org/dllearner/ trunk/interfaces/src/test/resources/org/dllearner/confparser2/ trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf Added: trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-19 23:24:40 UTC (rev 3074) @@ -0,0 +1,56 @@ +package org.dllearner.configuration; + +import java.util.Properties; +import java.util.Set; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/18/11 + * Time: 9:45 PM + * + * This interface defines our interaction with a DL-Learner specific configuration. + * + */ +public interface IConfiguration { + + /** + * Get the object for the given key. + * + * @param key The key of the object to retrieve. + * @return The Object representation of the value keyed by key. + */ + public Object getObjectValue(String key); + + /** + * Get a Properties object describing all of the properties which this configuration object + * knows about. + * + * As Properties are basically Map<String,String> objects, you can use getObjectValue(String key). To + * get the Object. + * + * @return A Properties Object. + */ + public Properties getProperties(); + + /** + * Get the set of positive examples associated with this configuration. + * + * Never returns null, only an empty set if there are no positive examples. + * + * @return The set of positive examples associated with this configuration. + */ + public Set<String> getPositiveExamples(); + + /** + * Get the set of negative examples associated with this configuration. + * + * Never returns null, only an empty set if there are no negative examples. + * + * @return The set of negative examples associated with this configuration. + */ + public Set<String> getNegativeExamples(); + + + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-19 23:24:40 UTC (rev 3074) @@ -0,0 +1,116 @@ +package org.dllearner.confparser2; + +import org.dllearner.cli.ConfFileOption; +import org.dllearner.configuration.IConfiguration; +import org.dllearner.utilities.datastructures.StringTuple; +import org.springframework.core.io.Resource; + +import java.io.IOException; +import java.util.*; + + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/19/11 + * Time: 2:30 PM + * + * Conf Parser based implementation of the IConfiguration interface. + * + * We use the ConfParser to read DL-Learn conf files. + */ +public class ConfParserConfiguration implements IConfiguration { + + private final ConfParser parser; + + public ConfParserConfiguration(Resource source){ + try { + parser = new ConfParser(source.getInputStream()); + parser.Start(); + } catch (ParseException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public Object getObjectValue(String name) { + + Object result = null; + try { + ConfFileOption confOption = parser.getConfOptionsByName(name); + + result = confOption.getValue(); + result = convert(result); + } catch (Exception e) { + throw new RuntimeException("Problem with creating object named: " + name, e); + } + return result; + } + + /** + * Convert if we have certain types. + * + * @param input The object to convert if necessary. + * @return The converted version of input + */ + protected Object convert(Object input) { + Object result = input; + + /** Convert to a map if we have a list of String Tuples */ + if(input instanceof List){ + List set = (List) input; + Iterator iterator = set.iterator(); + if(iterator.hasNext()){ + Object firstElement = iterator.next(); + if(firstElement instanceof StringTuple){ + result = convertToMap(iterator, (StringTuple) firstElement); + } + } + + } + return result; + } + + private Map<String,String> convertToMap(Iterator iterator, StringTuple firstElement) { + + /** Convert to map */ + Map<String,String> result = new HashMap<String, String>(); + result.put(firstElement.a,firstElement.b); + + /** Add the rest of the tuples */ + while(iterator.hasNext()){ + StringTuple nextTuple = (StringTuple)iterator.next(); + result.put(nextTuple.a,nextTuple.b); + } + return result; + } + + @Override + public Properties getProperties() { + Properties props = new Properties(); + + List<ConfFileOption> options = parser.getConfOptions(); + for (ConfFileOption option : options) { + String fullName = option.getFullName(); + String stringValue = option.getValue().toString(); + try { + props.setProperty(fullName, stringValue); + } catch (Exception e) { + throw new RuntimeException("Problem with property name: " + fullName + " and value " + stringValue,e); + } + } + return props; + } + + @Override + public Set<String> getPositiveExamples() { + return parser.getPositiveExamples(); + } + + @Override + public Set<String> getNegativeExamples() { + return parser.getNegativeExamples(); + } +} Added: trunk/interfaces/src/test/java/org/dllearner/confparser2/ConfParserConfigurationTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/confparser2/ConfParserConfigurationTest.java (rev 0) +++ trunk/interfaces/src/test/java/org/dllearner/confparser2/ConfParserConfigurationTest.java 2011-08-19 23:24:40 UTC (rev 3074) @@ -0,0 +1,123 @@ +package org.dllearner.confparser2; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/19/11 + * Time: 4:26 PM + * <p/> + * Basic Test + */ +public class ConfParserConfigurationTest { + + private ConfParserConfiguration configuration; + + @Before + public void setUp() throws Exception { + Resource confFile = new ClassPathResource("/org/dllearner/confparser2/confParserConfigurationTest.conf"); + + configuration = new ConfParserConfiguration(confFile); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testStringValueProperty() throws Exception { + + Object simpleValue = configuration.getObjectValue("testBean.simpleValue"); + Assert.assertTrue(simpleValue instanceof String); + Assert.assertEquals("simple value example", simpleValue); + + } + + @Test + public void testComponentValueProperty() throws Exception { + + Object value = configuration.getObjectValue("testBean.component"); + /** We expect a string back here */ + Assert.assertTrue(value instanceof String); + Assert.assertEquals("component:test", value); + + } + + @Test + public void testIntValueProperty() throws Exception { + + Object value = configuration.getObjectValue("testBean.intValue"); + /** We expect a string back here */ + Assert.assertTrue(value instanceof Integer); + Assert.assertEquals(23, value); + + } + + @Test + public void testDoubleValueProperty() throws Exception { + + Object value = configuration.getObjectValue("testBean.doubleValue"); + /** We expect a string back here */ + Assert.assertTrue(value instanceof Double); + Assert.assertEquals(78.5d, (Double) value, .001); + + } + + @Test + public void testSetValueProperty() throws Exception { + + Object value = configuration.getObjectValue("testBean.setValue"); + /** We expect a string back here */ + Assert.assertTrue(value instanceof Set); + Set<String> set = (Set<String>) value; + Assert.assertTrue(set.size() == 1); + Assert.assertTrue(set.contains("a")); + + } + + @Test + public void testMapValueProperty() throws Exception { + + Object value = configuration.getObjectValue("testBean.mapValue"); + /** We expect a string back here */ + Assert.assertTrue(value instanceof Map); + Map<String, String> set = (Map<String, String>) value; + Assert.assertTrue(set.size() == 2); + Assert.assertEquals(set.get("a"), "b"); + Assert.assertEquals(set.get("c"), "d"); + } + + @Test + public void testGetProperties() throws Exception { + Properties properties = configuration.getProperties(); + Assert.assertTrue(properties.size() == 6); + Assert.assertTrue(properties.get("testBean.intValue").equals("23")); + + } + + @Test + public void testGetNegativeExamples(){ + Set<String> negativeExamples = configuration.getNegativeExamples(); + Assert.assertTrue(negativeExamples.size() == 1); + Assert.assertTrue(negativeExamples.contains("http://example.org/neg1/")); + } + + + @Test + public void testGetPositiveExamples(){ + Set<String> negativeExamples = configuration.getPositiveExamples(); + Assert.assertTrue(negativeExamples.size() == 1); + Assert.assertTrue(negativeExamples.contains("http://example.org/pos1/")); + } +} Added: trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf =================================================================== --- trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf (rev 0) +++ trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf 2011-08-19 23:24:40 UTC (rev 3074) @@ -0,0 +1,21 @@ +/** + * A multi-line comment, which is ignored. + */ + +// a single line comment, which is ignored +testBean.simpleValue="simple value example"; // simple value + +testBean.component=component:test; // I wonder whether we even need the component keyword or could just write beanName.property=:test; + +testBean.intValue = 23; // an integer value + +testBean.doubleValue = 78.5; // a double value + +testBean.setValue={"a"}; // a set (list is not implemented, but can be done analogously) + +testBean.mapValue=[("a","b"),("c","d")]; // a map (we can use whatever syntax we like, this is the existing one) + +// you can also specify positive and negative examples +// (not sure if we really need that) ++"http://example.org/pos1/" +-"http://example.org/neg1/" \ 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...> - 2011-08-22 12:19:16
|
Revision: 3087 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3087&view=rev Author: jenslehmann Date: 2011-08-22 12:19:10 +0000 (Mon, 22 Aug 2011) Log Message: ----------- conf parser change Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj trunk/test/newconf/test1.conf Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java 2011-08-22 11:35:00 UTC (rev 3086) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java 2011-08-22 12:19:10 UTC (rev 3087) @@ -161,7 +161,7 @@ jj_consume_token(26); label_2: while (true) { - if (jj_2_4(2)) { + if (jj_2_4(4)) { ; } else { break label_2; @@ -171,14 +171,14 @@ tmp = String(); break; case ID: - tmp = Id(); + tmp = ComplexId(); break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - values.add(tmp); + values.add(tmp); jj_consume_token(30); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -186,16 +186,16 @@ tmp = String(); break; case ID: - tmp = Id(); + tmp = ComplexId(); break; default: jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - values.add(tmp); + values.add(tmp); jj_consume_token(29); - isSet=true; + isSet=true; break; default: jj_la1[9] = jj_gen; @@ -298,7 +298,9 @@ else if(isList) confOption = new ConfFileOption(option,subOption,tuples); else - { if(useColon) + { // this is just a temporary hack to get the double colon notation working; + // of course we can pass value1 and value2 as separate parameters later on + if(useColon) confOption = new ConfFileOption(option,subOption,value1 + ":" + value2); else confOption = new ConfFileOption(option,subOption,value); @@ -354,6 +356,28 @@ throw new Error("Missing return statement in function"); } + final public String ComplexId() throws ParseException { + Token t1,t2; + if (jj_2_9(2)) { + t1 = jj_consume_token(ID); + jj_consume_token(28); + t2 = jj_consume_token(ID); + {if (true) return t1.image + ":" + t2.image;} + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + t1 = jj_consume_token(ID); + {if (true) return t1.image;} + break; + default: + jj_la1[12] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + throw new Error("Missing return statement in function"); + } + final public String Id() throws ParseException { Token t; t = jj_consume_token(ID); @@ -442,6 +466,13 @@ finally { jj_save(7, xla); } } + private boolean jj_2_9(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_9(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(8, xla); } + } + private boolean jj_3R_5() { if (jj_scan_token(COMMAND_END)) return true; if (jj_3R_4()) return true; @@ -449,7 +480,7 @@ } private boolean jj_3R_11() { - if (jj_3R_4()) return true; + if (jj_3R_19()) return true; return false; } @@ -464,8 +495,8 @@ return false; } - private boolean jj_3R_17() { - if (jj_scan_token(DOUBLE)) return true; + private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; return false; } @@ -515,11 +546,33 @@ return false; } - private boolean jj_3R_4() { + private boolean jj_3R_20() { if (jj_scan_token(ID)) return true; return false; } + private boolean jj_3R_19() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_9()) { + jj_scanpos = xsp; + if (jj_3R_20()) return true; + } + return false; + } + + private boolean jj_3_9() { + if (jj_scan_token(ID)) return true; + if (jj_scan_token(28)) return true; + if (jj_scan_token(ID)) return true; + return false; + } + + private boolean jj_3R_18() { + if (jj_scan_token(STRING)) return true; + return false; + } + private boolean jj_3R_10() { if (jj_3R_18()) return true; return false; @@ -541,8 +594,8 @@ return false; } - private boolean jj_3R_18() { - if (jj_scan_token(STRING)) return true; + private boolean jj_3R_16() { + if (jj_scan_token(NUMBER)) return true; return false; } @@ -587,8 +640,8 @@ return false; } - private boolean jj_3R_16() { - if (jj_scan_token(NUMBER)) return true; + private boolean jj_3R_17() { + if (jj_scan_token(DOUBLE)) return true; return false; } @@ -613,7 +666,7 @@ private Token jj_scanpos, jj_lastpos; private int jj_la; private int jj_gen; - final private int[] jj_la1 = new int[12]; + final private int[] jj_la1 = new int[13]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { @@ -621,12 +674,12 @@ jj_la1_init_1(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x1c00,0x100,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1007000,0x4000000,0x8000000,0x1001000,}; + jj_la1_0 = new int[] {0x1c00,0x100,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1001000,0x1007000,0x4000000,0x8000000,0x1001000,0x1000,}; } private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; } - final private JJCalls[] jj_2_rtns = new JJCalls[8]; + final private JJCalls[] jj_2_rtns = new JJCalls[9]; private boolean jj_rescan = false; private int jj_gc = 0; @@ -641,7 +694,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < 13; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -656,7 +709,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < 13; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -667,7 +720,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < 13; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -678,7 +731,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < 13; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -688,7 +741,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < 13; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -698,7 +751,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 12; i++) jj_la1[i] = -1; + for (int i = 0; i < 13; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -815,7 +868,7 @@ la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 12; i++) { + for (int i = 0; i < 13; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<<j)) != 0) { @@ -854,7 +907,7 @@ private void jj_rescan_token() { jj_rescan = true; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 9; i++) { try { JJCalls p = jj_2_rtns[i]; do { @@ -869,6 +922,7 @@ case 5: jj_3_6(); break; case 6: jj_3_7(); break; case 7: jj_3_8(); break; + case 8: jj_3_9(); break; } } p = p.next; Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj 2011-08-22 11:35:00 UTC (rev 3086) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj 2011-08-22 12:19:10 UTC (rev 3087) @@ -183,8 +183,8 @@ // empty set | LOOKAHEAD("{" "}") "{" "}" {isSet=true;} // set with several elements - | "{" ( LOOKAHEAD(2) ( tmp=String() | tmp=Id() ) {values.add(tmp);} "," )* - (tmp=String() | tmp=Id()) {values.add(tmp);} "}" {isSet=true;} + | "{" ( LOOKAHEAD(4) ( tmp=String() | tmp=ComplexId() ) { values.add(tmp);} "," )* + (tmp=String() | tmp=ComplexId()) {values.add(tmp);} "}" {isSet=true;} // empty list | LOOKAHEAD("[" "]") "[" "]" {isList=true;} // a list with several elements, which tuples @@ -258,6 +258,16 @@ } } +String ComplexId() : +{ + Token t1,t2; +} +{ + LOOKAHEAD(2) t1=<ID> ":" t2=<ID> { return t1.image + ":" + t2.image; } + |t1=<ID> { return t1.image; } +} + + String Id() : { Token t; Modified: trunk/test/newconf/test1.conf =================================================================== --- trunk/test/newconf/test1.conf 2011-08-22 11:35:00 UTC (rev 3086) +++ trunk/test/newconf/test1.conf 2011-08-22 12:19:10 UTC (rev 3087) @@ -12,8 +12,10 @@ beanName.property = 78.5; // a double value -beanName.property={"a"}; // a set (list is not implemented, but can be done analogously) +beanName.property={"a", "b"}; // a set (list is not implemented, but can be done analogously) +beanName.property = { component:test1, component:test2, component:test3 }; + beanName.property=[("a","b"),("c","d")]; // a map (we can use whatever syntax we like, this is the existing one) // you can also specify positive and negative examples This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2011-08-22 13:21:40
|
Revision: 3090 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3090&view=rev Author: shadowtm Date: 2011-08-22 13:21:34 +0000 (Mon, 22 Aug 2011) Log Message: ----------- Added support for declaring beans which aren't in the XML file - this will help us create components on the fly. This makes the beanName.type reserved for declaring the class type of the bean for now - we can make this smarter in the future Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf Added Paths: ----------- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java Modified: trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-22 13:02:58 UTC (rev 3089) +++ trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-22 13:21:34 UTC (rev 3090) @@ -19,6 +19,7 @@ package org.dllearner.configuration; +import java.util.Collection; import java.util.Properties; import java.util.Set; @@ -53,6 +54,21 @@ public Properties getProperties(); /** + * Get a collection of all the bean names defined in the configuration. + * + * @return a collection of all the bean names defined in the configuration. + */ + public Collection<String> getBeanNames(); + + /** + * Get the class for the given bean. + * + * @param beanName The name of the bean to get the class for. + * @return The class for the given bean. + */ + public Class getClass(String beanName); + + /** * Get the set of positive examples associated with this configuration. * * Never returns null, only an empty set if there are no positive examples. Added: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-22 13:21:34 UTC (rev 3090) @@ -0,0 +1,50 @@ +package org.dllearner.configuration.spring; + +import org.dllearner.configuration.IConfiguration; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; + +import java.util.Collection; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/22/11 + * Time: 6:38 AM + * + * This class is used to insert BeanDefinitions that are declared in the configuration file that + * do not exist in the existing registry (ie. they aren't declared in the spring XML file). + */ +public class ConfigurationBasedBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor { + + private final IConfiguration configuration; + + public ConfigurationBasedBeanDefinitionRegistryPostProcessor(IConfiguration configuration) { + this.configuration = configuration; + } + + @Override + public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { + Collection<String> beanNames = configuration.getBeanNames(); + + for (String beanName : beanNames) { + if(!registry.containsBeanDefinition(beanName)){ + Class beanClass = configuration.getClass(beanName); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClass); + + BeanDefinition definition = builder.getBeanDefinition(); + registry.registerBeanDefinition(beanName,definition); + } + } + + } + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + /** Do nothing here */ + } +} Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-22 13:02:58 UTC (rev 3089) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-22 13:21:34 UTC (rev 3090) @@ -93,17 +93,40 @@ List<ConfFileOption> options = parser.getConfOptions(); for (ConfFileOption option : options) { - String fullName = option.getFullName(); - String stringValue = option.getValue().toString(); - try { - props.setProperty(fullName, stringValue); - } catch (Exception e) { - throw new RuntimeException("Problem with property name: " + fullName + " and value " + stringValue,e); + if (!excludedFromProperties(option)) { + String fullName = option.getFullName(); + String stringValue = option.getValue().toString(); + try { + props.setProperty(fullName, stringValue); + } catch (Exception e) { + throw new RuntimeException("Problem with property name: " + fullName + " and value " + stringValue,e); + } } } return props; } + + /** + * Determine if this option should be excluded from the properties list. + * + * @param option The option to test + * @return True if it should be excluded + */ + private boolean excludedFromProperties(ConfFileOption option){ + boolean result = false; + + if(option.isStringOption()){ + String subOption = option.getSubOption(); + /** Exclude where suboption = true */ + if(subOption.equals("type")){ + result = true; + } + } + + return result; + } + @Override public Set<String> getPositiveExamples() { return parser.getPositiveExamples(); @@ -113,4 +136,30 @@ public Set<String> getNegativeExamples() { return parser.getNegativeExamples(); } + + @Override + public Collection<String> getBeanNames() { + Collection<String> beanNames = new HashSet<String>(); + + List<ConfFileOption> options = parser.getConfOptions(); + for (ConfFileOption option : options) { + beanNames.add(option.getOption()); + } + return beanNames; + } + + @Override + public Class getClass(String beanName) { + Class result = null; + /** TODO Do something that isn't hard coded like this or use a more specific name than type. The result of this must be the class - so however we get it doesn't matter */ + ConfFileOption option = parser.getConfOptionsByName(beanName + ".type"); + try { + result = Class.forName((String) option.getValue()); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Problem getting class type for bean: " + beanName + " - trying to instantiate class: " + option.getValue()); + } + + return result; + + } } Modified: trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java 2011-08-22 13:02:58 UTC (rev 3089) +++ trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java 2011-08-22 13:21:34 UTC (rev 3090) @@ -5,6 +5,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; @@ -30,6 +31,8 @@ Resource confFile = new ClassPathResource("/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf"); ConfParserConfiguration configuration = new ConfParserConfiguration(confFile); + BeanDefinitionRegistryPostProcessor beanDefinitionRegistryPostProcessor = new ConfigurationBasedBeanDefinitionRegistryPostProcessor(configuration); + ConfigurationBasedPropertyOverrideConfigurer configurer = new ConfigurationBasedPropertyOverrideConfigurer(configuration, false); configurer.setProperties(configuration.getProperties()); configurer.getComponentKeyPrefixes().add("component:"); @@ -41,7 +44,9 @@ springConfigurationFiles[0] = springConfigurationLocation; context = new ClassPathXmlApplicationContext(springConfigurationFiles, false); + context.addBeanFactoryPostProcessor(beanDefinitionRegistryPostProcessor); context.addBeanFactoryPostProcessor(configurer); + context.refresh(); } @@ -59,10 +64,13 @@ TestBean secondBean = testBean.getComponent(); validateSecondBean(secondBean); validateThirdBean(secondBean.getComponent()); + validateFourthBean(context.getBean("fourthBean", TestBean.class)); } private void validateThirdBean(TestBean thirdBean) { Assert.assertEquals(thirdBean.getIntValue(), (Integer) 3); + TestBean fourthBean = thirdBean.getComponent(); + validateFourthBean(fourthBean); } private void validateFirstBean(TestBean testBean) { @@ -84,4 +92,8 @@ } + private void validateFourthBean(TestBean fourthBean){ + Assert.assertEquals(fourthBean.getSimpleValue(), "Fourth Bean - not specified in xml"); + } + } Modified: trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf =================================================================== --- trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-08-22 13:02:58 UTC (rev 3089) +++ trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-08-22 13:21:34 UTC (rev 3090) @@ -24,7 +24,11 @@ secondBean.mapValue=[("f","g"),("c","d")]; // a map (we can use whatever syntax we like, this is the existing one) thirdBean.intValue=3; +thirdBean.component=component:fourthBean; + +fourthBean.simpleValue="Fourth Bean - not specified in xml"; +fourthBean.type="org.dllearner.configuration.spring.TestBean"; // you can also specify positive and negative examples // (not sure if we really need that) +"http://example.org/pos1/" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-22 13:56:11
|
Revision: 3093 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3093&view=rev Author: jenslehmann Date: 2011-08-22 13:56:05 +0000 (Mon, 22 Aug 2011) Log Message: ----------- refined method for obtaining the class from the value of .type in conf files Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-22 13:55:55 UTC (rev 3092) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-22 13:56:05 UTC (rev 3093) @@ -30,6 +30,8 @@ import java.util.List; import java.util.Map; +import org.apache.commons.collections15.BidiMap; +import org.apache.commons.collections15.bidimap.DualHashBidiMap; import org.apache.commons.lang.ClassUtils; /** @@ -71,19 +73,22 @@ "org.dllearner.algorithms.SimpleSubclassLearner", } )); private static Collection<Class<? extends Component>> components; - private static Map<Class<? extends Component>, String> componentNames; + private static BidiMap<Class<? extends Component>, String> componentNames; + private static BidiMap<Class<? extends Component>, String> componentNamesShort; private static AnnComponentManager cm = null; private AnnComponentManager() { // conversion of class strings to objects components = new HashSet<Class<? extends Component>>(); - componentNames = new HashMap<Class<? extends Component>, String>(); + componentNames = new DualHashBidiMap<Class<? extends Component>, String>(); + componentNamesShort = new DualHashBidiMap<Class<? extends Component>, String>(); for (String componentClassName : componentClassNames) { try { Class<? extends Component> component = Class.forName(componentClassName).asSubclass(Component.class); components.add(component); componentNames.put(component, getName(component)); + componentNamesShort.put(component, getShortName(component)); } catch (ClassNotFoundException e) { e.printStackTrace(); } @@ -112,16 +117,27 @@ } /** - * Convenience methed, which returns a list of components along with + * Convenience method, which returns a list of components along with * their name. * * @return A map where the key is the class of the component and the * value is its name. */ - public Map<Class<? extends Component>, String> getComponentsNamed() { + public BidiMap<Class<? extends Component>, String> getComponentsNamed() { return componentNames; } + /** + * Convenience method, which returns a list of components along with + * their name. + * + * @return A map where the key is the class of the component and the + * value is its name. + */ + public BidiMap<Class<? extends Component>, String> getComponentsNamedShort() { + return componentNamesShort; + } + public boolean isCompatible() { return false; } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-22 13:55:55 UTC (rev 3092) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-22 13:56:05 UTC (rev 3093) @@ -2,6 +2,8 @@ import org.dllearner.cli.ConfFileOption; import org.dllearner.configuration.IConfiguration; +import org.dllearner.core.AnnComponentManager; +import org.dllearner.core.Component; import org.dllearner.utilities.datastructures.StringTuple; import org.springframework.core.io.Resource; @@ -149,16 +151,27 @@ } @Override - public Class getClass(String beanName) { - Class result = null; - /** TODO Do something that isn't hard coded like this or use a more specific name than type. The result of this must be the class - so however we get it doesn't matter */ + public Class<?> getClass(String beanName) { + Class<?> result = null; ConfFileOption option = parser.getConfOptionsByName(beanName + ".type"); + String value = (String) option.getValue(); + // first option: use long name of @ComponentAnn annotation + Class<? extends Component> classFromName = AnnComponentManager.getInstance().getComponentsNamed().getKey(value); + if(classFromName != null) { + return classFromName; + } + // second option: use short name of @ComponentAnn annotation + Class<? extends Component> classFromShortName = AnnComponentManager.getInstance().getComponentsNamedShort().getKey(value); + if(classFromShortName != null) { + return classFromShortName; + } + // third option: use specified class name try { - result = Class.forName((String) option.getValue()); + result = Class.forName(value); } catch (ClassNotFoundException e) { + // if all methods fail, throw an exception throw new RuntimeException("Problem getting class type for bean: " + beanName + " - trying to instantiate class: " + option.getValue()); } - return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-23 06:43:19
|
Revision: 3096 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3096&view=rev Author: jenslehmann Date: 2011-08-23 06:43:13 +0000 (Tue, 23 Aug 2011) Log Message: ----------- added support for specifying a confidence threshold in enrichment script Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-08-23 03:24:09 UTC (rev 3095) +++ trunk/components-core/src/main/java/org/dllearner/core/AxiomLearningAlgorithm.java 2011-08-23 06:43:13 UTC (rev 3096) @@ -49,6 +49,7 @@ */ public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms); - + public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms, + double accuracyThreshold); } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-23 03:24:09 UTC (rev 3095) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-23 06:43:13 UTC (rev 3096) @@ -184,6 +184,7 @@ // number of axioms which will be learned/considered (only applies to // some learners) private int nrOfAxiomsToLearn = 10; + private double threshold = 0.7; // lists of algorithms to apply private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; @@ -195,10 +196,11 @@ private CommonPrefixMap prefixes = new CommonPrefixMap(); - public Enrichment(SparqlEndpoint se, Entity resource, boolean verbose) { + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, boolean verbose) { this.se = se; this.resource = resource; this.verbose = verbose; + this.threshold = threshold; objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); @@ -374,7 +376,7 @@ System.out.println("done"); // convert the result to axioms (to make it compatible with the other algorithms) - TreeSet<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(); + List<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(threshold); List<EvaluatedAxiom> evaluatedAxioms = new LinkedList<EvaluatedAxiom>(); for(EvaluatedDescription learnedDescription : learnedDescriptions) { Axiom axiom; @@ -422,7 +424,7 @@ long runtime = System.currentTimeMillis() - startTime; System.out.println("done in " + runtime + "ms"); List<EvaluatedAxiom> learnedAxioms = learner - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn, threshold); System.out.println(prettyPrint(learnedAxioms)); algorithmRuns.add(new AlgorithmRun(learner.getClass(), learnedAxioms, ConfigHelper.getConfigOptionValuesString(learner))); @@ -656,6 +658,9 @@ parser.acceptsAll(asList("f", "format"), "Format of the generated output (plain, html, rdf/xml, turtle, manchester, sparul).").withOptionalArg() .ofType(String.class).defaultsTo("plain"); + parser.acceptsAll(asList("t", "threshold"), + "Confidence threshold for suggestions. Set it to a value between 0 and 1.").withOptionalArg() + .ofType(Double.class).defaultsTo(0.7); // parse options and display a message for the user in case of problems OptionSet options = null; @@ -701,8 +706,9 @@ } boolean verbose = (Boolean) options.valueOf("v"); + double threshold = (Double) options.valueOf("t"); - Enrichment e = new Enrichment(se, resource, verbose); + Enrichment e = new Enrichment(se, resource, threshold, verbose); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-23 16:10:16
|
Revision: 3103 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3103&view=rev Author: jenslehmann Date: 2011-08-23 16:10:09 +0000 (Tue, 23 Aug 2011) Log Message: ----------- further changes related to the previous commit Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/QTL.java trunk/interfaces/src/main/java/org/dllearner/cli/Start.java trunk/interfaces/src/main/java/org/dllearner/server/nke/Learner.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EvaluationComputingScript.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/OntologyEngineering.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2011-08-23 16:05:46 UTC (rev 3102) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2011-08-23 16:10:09 UTC (rev 3103) @@ -257,6 +257,14 @@ return bestEvaluatedDescriptions.getSet().last(); } + public boolean isInstanceBasedDisjoints() { + return instanceBasedDisjoints; + } + + public void setInstanceBasedDisjoints(boolean instanceBasedDisjoints) { + this.instanceBasedDisjoints = instanceBasedDisjoints; + } + @Override public TreeSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { return bestEvaluatedDescriptions.getSet(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/QTL.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/QTL.java 2011-08-23 16:05:46 UTC (rev 3102) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/QTL.java 2011-08-23 16:10:09 UTC (rev 3103) @@ -115,7 +115,6 @@ return options; } - @Override public Configurator getConfigurator() { return null; } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Start.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Start.java 2011-08-23 16:05:46 UTC (rev 3102) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Start.java 2011-08-23 16:10:09 UTC (rev 3103) @@ -695,7 +695,7 @@ // components String message = "OK"; if (component instanceof KBFile) - message = ((KBFile) component).getURL().toString() + " read"; + message = ((KBFile) component).getUrl().toString() + " read"; else if (component instanceof DIGReasoner) { DIGReasoner reasoner = (DIGReasoner) component; message = "using " + reasoner.getIdentifier() + " connected via DIG 1.1 at " Modified: trunk/interfaces/src/main/java/org/dllearner/server/nke/Learner.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/server/nke/Learner.java 2011-08-23 16:05:46 UTC (rev 3102) +++ trunk/interfaces/src/main/java/org/dllearner/server/nke/Learner.java 2011-08-23 16:10:09 UTC (rev 3103) @@ -92,7 +92,7 @@ ELLearningAlgorithm la = cm.learningAlgorithm(ELLearningAlgorithm.class, lp, rc); - la.getConfigurator().setInstanceBasedDisjoints(false); + la.setInstanceBasedDisjoints(false); // CELOE la = cm.learningAlgorithm(CELOE.class, lp, rc); la.init(); log.debug("Running learning algorithm"); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EvaluationComputingScript.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EvaluationComputingScript.java 2011-08-23 16:05:46 UTC (rev 3102) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EvaluationComputingScript.java 2011-08-23 16:10:09 UTC (rev 3103) @@ -163,7 +163,7 @@ ComponentManager cm = ComponentManager.getInstance(); // initialize KnowledgeSource ks = cm.knowledgeSource(OWLFile.class); - ks.getConfigurator().setUrl(ontologyURI.toURL()); + ks.setURL(ontologyURI.toURL()); ks.init(); System.out.println("Loaded ontology " + ontologyURI + "."); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/OntologyEngineering.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/OntologyEngineering.java 2011-08-23 16:05:46 UTC (rev 3102) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/OntologyEngineering.java 2011-08-23 16:10:09 UTC (rev 3103) @@ -103,10 +103,10 @@ // load OWL in reasoner OWLFile ks = cm.knowledgeSource(OWLFile.class); if(args[0].startsWith("http")) { - ks.getConfigurator().setUrl(new URL(args[0])); + ks.setURL(new URL(args[0])); } else { File owlFile = new File(args[0]); - ks.getConfigurator().setUrl(owlFile.toURI().toURL()); + ks.setURL(owlFile.toURI().toURL()); } ks.init(); AbstractReasonerComponent reasoner = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2011-08-24 04:53:24
|
Revision: 3105 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3105&view=rev Author: shadowtm Date: 2011-08-24 04:53:15 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Made modifications to components used by the Father example. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown2.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/Utility.java trunk/components-core/src/main/java/org/dllearner/utilities/Helper.java trunk/components-core/src/main/java/org/dllearner/utilities/components/ReasonerComponentFactory.java trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SortedSetTuple.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyCloser.java trunk/components-core/src/test/java/org/dllearner/test/FuzzyDLLTest_noFuzzyTrains.java trunk/components-core/src/test/java/org/dllearner/test/junit/HeuristicTests.java trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/QTL.java trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/gui/TreeWindow.java trunk/interfaces/src/test/java/org/dllearner/test/junit/OWLlinkTest.java trunk/interfaces/src/test/java/org/dllearner/test/junit/ReasonerTests.java trunk/scripts/src/main/java/org/dllearner/examples/KRKModular.java trunk/scripts/src/main/java/org/dllearner/scripts/CloseOntology.java trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EvaluationComputingScript.java trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java Added Paths: ----------- trunk/interfaces/src/test/java/org/dllearner/cli/ trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/pom.xml 2011-08-24 04:53:15 UTC (rev 3105) @@ -285,5 +285,9 @@ <artifactId>commons-codec</artifactId> <version>20041127.091804</version> </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + </dependency> </dependencies> </project> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,13 +19,7 @@ package org.dllearner.algorithms.el; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import org.apache.log4j.Logger; import org.dllearner.core.ComponentInitException; @@ -113,8 +107,8 @@ private double posWeight = 1.2; // 2; private int startPosExamplesSize; // private int startNegExamplesSize; - private SortedSet<Individual> currentPosExamples; - private SortedSet<Individual> currentNegExamples; + private Set<Individual> currentPosExamples; + private Set<Individual> currentNegExamples; private SearchTreeNode bestCurrentNode; private double bestCurrentScore = 0; private long treeStartTime; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/gp/GPUtilities.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,12 +19,7 @@ package org.dllearner.algorithms.gp; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.SortedSet; -import java.util.TreeMap; +import java.util.*; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; @@ -474,7 +469,7 @@ private static ScoreThreeValued getScore(int conceptLength, AbstractLearningProblem learningProblem, AbstractReasonerComponent rs, SortedSet<Individual> posClassified, SortedSet<Individual> negClassified) { // es muss hier die Helper-Methode verwendet werden, sonst werden // Individuals gel�scht !! - SortedSet<Individual> neutClassified = Helper.intersection(rs.getIndividuals(),posClassified); + Set<Individual> neutClassified = Helper.intersection(rs.getIndividuals(),posClassified); // learningProblem.getReasoner().getIndividuals(); // neutClassified.retainAll(posClassified); neutClassified.retainAll(negClassified); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -340,10 +340,10 @@ // warn the user if he/she sets any non-standard heuristic, because it will just be ignored if(learningProblem instanceof PosNegLPStandard) { - if(((PosNegLPStandard)learningProblem).getConfigurator().getUseApproximations()) { + if(((PosNegLPStandard)learningProblem).isUseApproximations()) { System.err.println("You actived approximations for the considered learning problem, but OCEL does not support it. Option will be ignored. (Recommendation: Use CELOE instead.)"); } - if(!((PosNegLPStandard)learningProblem).getConfigurator().getAccuracyMethod().equals("predacc")) { + if(!((PosNegLPStandard)learningProblem).getAccuracyMethod().equals("predacc")) { System.err.println("You have chosen a non-standard (predictive accuracy) heuristic in your learning problem, but OCEL does not support it. Option will be ignored. (Recommendation: Use CELOE instead.)"); } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -34,13 +34,12 @@ */ public abstract class AbstractLearningProblem extends AbstractComponent implements LearningProblem { + private AbstractReasonerComponent reasoner; + + public AbstractLearningProblem(){ + + } /** - * Implementations of learning problems can use this class - * variable to perform reasoner operations. - */ - protected AbstractReasonerComponent reasoner; - - /** * Constructs a learning problem using a reasoning service for * querying the background knowledge. It can be used for * evaluating solution candidates. @@ -109,5 +108,17 @@ * @return A value between 0 and 1 indicating the quality (of a class description) * or -1 as described above. */ - public abstract double getAccuracyOrTooWeak(Description description, double noise); + public abstract double getAccuracyOrTooWeak(Description description, double noise); + + /** + * Implementations of learning problems can use this class + * variable to perform reasoner operations. + */ + public AbstractReasonerComponent getReasoner() { + return reasoner; + } + + public void setReasoner(AbstractReasonerComponent reasoner) { + this.reasoner = reasoner; + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -121,6 +121,10 @@ */ protected Set<AbstractKnowledgeSource> sources; + + public AbstractReasonerComponent(){ + + } /** * Constructs a new reasoner component. * @@ -140,6 +144,10 @@ return sources; } + public void setSources(Set<AbstractKnowledgeSource> sources){ + this.sources = sources; + } + /** * Method to exchange the reasoner underlying the learning problem. * Implementations, which do not only use the provided sources class Modified: trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -20,19 +20,14 @@ package org.dllearner.kb; import java.io.File; +import java.io.FileNotFoundException; import java.net.URI; -import java.util.Collection; -import java.util.LinkedList; import org.apache.log4j.Logger; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.configurators.KBFileConfigurator; -import org.dllearner.core.options.ConfigEntry; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.InvalidConfigOptionValueException; -import org.dllearner.core.options.URLConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.KB; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; @@ -55,8 +50,10 @@ private KB kb; - @org.dllearner.core.config.ConfigOption(name = "url", description = "URL pointer to the KB file", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) + @ConfigOption(name = "url", description = "URL pointer to the KB file", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) private String url; + @ConfigOption(name = "baseDir", description = "Base Directory to look for the file in", defaultValue = ".", required = false, propertyEditorClass = StringTrimmerEditor.class) + private String baseDir; /** * Default constructor (needed for reflection in ComponentManager). @@ -83,8 +80,18 @@ @Override public void init() throws ComponentInitException { try { + if (getUrl() != null) { - kb = KBParser.parseKBFile(getUrl()); + String fileString = getUrl(); + if (fileString.startsWith("http:") || fileString.startsWith("file:")) { + /** Leave it as is */ + kb = KBParser.parseKBFile(getUrl()); + } else { + File f = new File(baseDir, getUrl()); + setUrl(f.toURI().toString()); + kb = KBParser.parseKBFile(f); + } + logger.trace("KB File " + getUrl() + " parsed successfully."); } else { throw new ComponentInitException("No URL option or kb object given. Cannot initialise KBFile component."); @@ -92,6 +99,8 @@ } catch (ParseException e) { throw new ComponentInitException("KB file " + getUrl() + " could not be parsed correctly.", e); + }catch (FileNotFoundException e) { + throw new ComponentInitException("KB file " + getUrl() + " could not be found.", e); } } @@ -131,4 +140,12 @@ public void setUrl(String url) { this.url = url; } + + public String getBaseDir() { + return baseDir; + } + + public void setBaseDir(String baseDir) { + this.baseDir = baseDir; + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -152,14 +152,14 @@ // useFMeasure = configurator.getAccuracyMethod().equals("fmeasure"); approxDelta = configurator.getApproxAccuracy(); - if(!reasoner.getNamedClasses().contains(classToDescribe)) { + if(!getReasoner().getNamedClasses().contains(classToDescribe)) { throw new ComponentInitException("The class \"" + configurator.getClassToDescribe() + "\" does not exist. Make sure you spelled it correctly."); } - classInstances = new LinkedList<Individual>(reasoner.getIndividuals(classToDescribe)); + classInstances = new LinkedList<Individual>(getReasoner().getIndividuals(classToDescribe)); // sanity check if(classInstances.size() == 0) { - throw new ComponentInitException("Class " + classToDescribe + " has 0 instances according to \"" + ComponentManager.getInstance().getComponentName(reasoner.getClass()) + "\". Cannot perform class learning with 0 instances."); + throw new ComponentInitException("Class " + classToDescribe + " has 0 instances according to \"" + ComponentManager.getInstance().getComponentName(getReasoner().getClass()) + "\". Cannot perform class learning with 0 instances."); } classInstancesSet = new TreeSet<Individual>(classInstances); @@ -174,10 +174,10 @@ // we compute the instances of the super class to perform // optimisations later on - Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); - TreeSet<Individual> superClassInstancesTmp = new TreeSet<Individual>(reasoner.getIndividuals()); + Set<Description> superClasses = getReasoner().getClassHierarchy().getSuperClasses(classToDescribe); + TreeSet<Individual> superClassInstancesTmp = new TreeSet<Individual>(getReasoner().getIndividuals()); for(Description superClass : superClasses) { - superClassInstancesTmp.retainAll(reasoner.getIndividuals(superClass)); + superClassInstancesTmp.retainAll(getReasoner().getIndividuals(superClass)); } // we create one list, which includes instances of the class (an instance of the class is also instance of all super classes) ... classAndSuperClassInstances = new LinkedList<Individual>(superClassInstancesTmp); @@ -194,7 +194,7 @@ Description classToDescribeNeg = new Negation(classToDescribe); negatedClassInstances = new TreeSet<Individual>(); for(Individual ind : superClassInstances) { - if(reasoner.hasType(classToDescribeNeg, ind)) { + if(getReasoner().hasType(classToDescribeNeg, ind)) { negatedClassInstances.add(ind); } } @@ -213,7 +213,7 @@ // overhang Set<Individual> additionalInstances = new TreeSet<Individual>(); for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances.add(ind); } } @@ -221,7 +221,7 @@ // coverage Set<Individual> coveredInstances = new TreeSet<Individual>(); for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances.add(ind); } } @@ -292,7 +292,7 @@ int instancesNotCovered = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -309,7 +309,7 @@ for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } testsPerformed++; @@ -346,7 +346,7 @@ int upperEstimateA = classInstances.size(); for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -416,7 +416,7 @@ for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } @@ -487,7 +487,7 @@ Individual posExample = itPos.next(); // System.out.println(posExample); - if(reasoner.hasType(description, posExample)) { + if(getReasoner().hasType(description, posExample)) { posClassifiedAsPos++; } else { notCoveredPos++; @@ -502,7 +502,7 @@ if(itNeg.hasNext()) { Individual negExample = itNeg.next(); - if(!reasoner.hasType(description, negExample)) { + if(!getReasoner().hasType(description, negExample)) { negClassifiedAsNeg++; } nrOfNegChecks++; @@ -537,7 +537,7 @@ // computing R(A) TreeSet<Individual> coveredInstancesSet = new TreeSet<Individual>(); for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstancesSet.add(ind); } if(terminationTimeExpired()){ @@ -554,7 +554,7 @@ // computing R(C) restricted to relevant instances TreeSet<Individual> additionalInstancesSet = new TreeSet<Individual>(); for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstancesSet.add(ind); } if(terminationTimeExpired()){ @@ -570,7 +570,7 @@ // computing R(C) restricted to relevant instances int additionalInstances = 0; for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances++; } if(terminationTimeExpired()){ @@ -581,7 +581,7 @@ // computing R(A) int coveredInstances = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } if(terminationTimeExpired()){ @@ -635,9 +635,9 @@ Description descriptionNeg = new Negation(description); // loop through all relevant instances for(Individual ind : classAndSuperClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { icPos.add(ind); - } else if(reasoner.hasType(descriptionNeg, ind)) { + } else if(getReasoner().hasType(descriptionNeg, ind)) { icNeg.add(ind); } if(terminationTimeExpired()){ @@ -712,7 +712,7 @@ public double getRecall(Description description) { int coveredInstances = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } } @@ -723,14 +723,14 @@ int additionalInstances = 0; for(Individual ind : superClassInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances++; } } int coveredInstances = 0; for(Individual ind : classInstances) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } } @@ -834,10 +834,10 @@ } else { axiom = new SubClassAxiom(classToDescribe, description); } - return reasoner.remainsSatisfiable(axiom); + return getReasoner().remainsSatisfiable(axiom); } public boolean followsFromKB(Description description) { - return equivalence ? reasoner.isEquivalentClass(description, classToDescribe) : reasoner.isSuperClassOf(description, classToDescribe); + return equivalence ? getReasoner().isEquivalentClass(description, classToDescribe) : getReasoner().isSuperClassOf(description, classToDescribe); } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluationCache.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -20,6 +20,7 @@ package org.dllearner.learningproblems; import java.util.Map; +import java.util.Set; import java.util.SortedSet; import java.util.TreeMap; @@ -104,7 +105,7 @@ } private SortedSetTuple<Individual> handleMultiConjunction(Intersection mc) { - SortedSet<Individual> pos = cache.get(mc.getChild(0)); + Set<Individual> pos = cache.get(mc.getChild(0)); for(int i=1; i<mc.getChildren().size(); i++) { pos = Helper.intersection(pos, cache.get(mc.getChild(i))); } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,24 +19,16 @@ package org.dllearner.learningproblems; -import java.util.Collection; -import java.util.LinkedList; import java.util.Set; -import java.util.SortedSet; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.CommonConfigMappings; -import org.dllearner.core.options.CommonConfigOptions; -import org.dllearner.core.options.ConfigEntry; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.InvalidConfigOptionValueException; -import org.dllearner.core.options.StringConfigOption; -import org.dllearner.core.options.StringSetConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.utilities.Helper; +import org.springframework.beans.propertyeditors.StringTrimmerEditor; +import sun.beans.editors.BoolEditor; +import sun.beans.editors.DoubleEditor; /** * @author Jens Lehmann @@ -44,15 +36,19 @@ */ public abstract class PosNegLP extends AbstractLearningProblem { - protected SortedSet<Individual> positiveExamples; - protected SortedSet<Individual> negativeExamples; - protected SortedSet<Individual> allExamples; - - protected boolean useRetrievalForClassification = false; - protected UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - protected double percentPerLengthUnit = 0.05; + protected Set<Individual> positiveExamples; + protected Set<Individual> negativeExamples; + protected Set<Individual> allExamples; - /** + @org.dllearner.core.config.ConfigOption(name = "useRetrievalForClassification", description = "\"Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.",defaultValue = "false", propertyEditorClass = BoolEditor.class) + private boolean useRetrievalForClassification = false; + @org.dllearner.core.config.ConfigOption(name = "useMultiInstanceChecks", description = "Use The Multi Instance Checks", defaultValue = "UseMultiInstanceChecks.TWOCHECKS", required = false, propertyEditorClass = StringTrimmerEditor.class) + private UseMultiInstanceChecks useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; + @org.dllearner.core.config.ConfigOption(name = "percentPerLengthUnit", description = "Percent Per Length Unit", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) + private double percentPerLengthUnit = 0.05; + + + /** * If instance checks are used for testing concepts (e.g. no retrieval), then * there are several options to do this. The enumeration lists the supported * options. These options are only important if the reasoning mechanism @@ -77,59 +73,20 @@ */ ONECHECK }; - + + + public PosNegLP(){ + + } + public PosNegLP(AbstractReasonerComponent reasoningService) { super(reasoningService); } - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringSetConfigOption("positiveExamples", - "positive examples",null, true, false)); - options.add(new StringSetConfigOption("negativeExamples", - "negative examples",null, true, false)); - options.add(new BooleanConfigOption("useRetrievalForClassficiation", - "Specifies whether to use retrieval or instance checks for testing a concept. - NO LONGER FULLY SUPPORTED.", false)); - options.add(CommonConfigOptions.getPercentPerLenghtUnitOption(0.05)); - StringConfigOption multiInstanceChecks = new StringConfigOption("useMultiInstanceChecks", "See UseMultiInstanceChecks enum. - NO LONGER FULLY SUPPORTED.","twoChecks"); - multiInstanceChecks.setAllowedValues(new String[] {"never", "twoChecks", "oneCheck"}); - options.add(multiInstanceChecks); - return options; - } - + /* * (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()); - else if (name.equals("negativeExamples")) - negativeExamples = CommonConfigMappings - .getIndividualSet((Set<String>) entry.getValue()); - else if (name.equals("useRetrievalForClassficiation")) { - useRetrievalForClassification = (Boolean) entry.getValue(); - } else if (name.equals("percentPerLengthUnit")) - percentPerLengthUnit = (Double) entry.getValue(); - else if (name.equals("useMultiInstanceChecks")) { - String value = (String) entry.getValue(); - if(value.equals("oneCheck")) - useMultiInstanceChecks = UseMultiInstanceChecks.ONECHECK; - else if(value.equals("twoChecks")) - useMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - else - useMultiInstanceChecks = UseMultiInstanceChecks.NEVER; - } - } - - /* - * (non-Javadoc) - * * @see org.dllearner.core.Component#init() */ @Override @@ -137,19 +94,19 @@ allExamples = Helper.union(positiveExamples, negativeExamples); } - public SortedSet<Individual> getNegativeExamples() { + public Set<Individual> getNegativeExamples() { return negativeExamples; } - public SortedSet<Individual> getPositiveExamples() { + public Set<Individual> getPositiveExamples() { return positiveExamples; } - public void setNegativeExamples(SortedSet<Individual> set) { + public void setNegativeExamples(Set<Individual> set) { this.negativeExamples=set; } - public void setPositiveExamples(SortedSet<Individual> set) { + public void setPositiveExamples(Set<Individual> set) { this.positiveExamples=set; } @@ -158,5 +115,26 @@ public double getPercentPerLengthUnit() { return percentPerLengthUnit; } - + + public void setPercentPerLengthUnit(double percentPerLengthUnit) { + this.percentPerLengthUnit = percentPerLengthUnit; + } + + public boolean isUseRetrievalForClassification() { + return useRetrievalForClassification; + } + + public void setUseRetrievalForClassification(boolean useRetrievalForClassification) { + this.useRetrievalForClassification = useRetrievalForClassification; + } + + public UseMultiInstanceChecks getUseMultiInstanceChecks() { + return useMultiInstanceChecks; + } + + public void setUseMultiInstanceChecks(UseMultiInstanceChecks useMultiInstanceChecks) { + this.useMultiInstanceChecks = useMultiInstanceChecks; + } + + } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,24 +19,22 @@ package org.dllearner.learningproblems; -import java.util.Collection; import java.util.Iterator; -import java.util.LinkedList; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.configurators.PosNegLPStandardConfigurator; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.DoubleConfigOption; -import org.dllearner.core.options.StringConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.utilities.Helper; +import org.springframework.beans.propertyeditors.StringTrimmerEditor; +import sun.beans.editors.BoolEditor; +import sun.beans.editors.DoubleEditor; /** * The aim of this learning problem is to learn a concept definition such that @@ -51,43 +49,40 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "PosNegLPStandard", shortName = "posNegStandard", version = 0.8) public class PosNegLPStandard extends PosNegLP { - private PosNegLPStandardConfigurator configurator; - + // approximation and F-measure // (taken from class learning => super class instances corresponds to negative examples // and class instances to positive examples) + @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) private double approxDelta = 0.05; + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false, propertyEditorClass = BoolEditor.class) private boolean useApproximations; + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) + private String accuracyMethod = "predacc"; + // private boolean useFMeasure; private boolean useOldDIGOptions = false; private HeuristicType heuristic = HeuristicType.PRED_ACC; - public PosNegLPStandardConfigurator getConfigurator() { - return configurator; - } - public PosNegLPStandard(AbstractReasonerComponent reasoningService) { - super(reasoningService); - this.configurator = new PosNegLPStandardConfigurator(this); + public PosNegLPStandard() { } public PosNegLPStandard(AbstractReasonerComponent reasoningService, SortedSet<Individual> positiveExamples, SortedSet<Individual> negativeExamples) { - super(reasoningService); + this.setReasoner(reasoningService); this.positiveExamples = positiveExamples; this.negativeExamples = negativeExamples; - this.configurator = new PosNegLPStandardConfigurator(this); } - + @Override public void init() { super.init(); - useApproximations = configurator.getUseApproximations(); - approxDelta = configurator.getApproxAccuracy(); - - String accM = configurator.getAccuracyMethod(); + + String accM = getAccuracyMethod(); if(accM.equals("standard")) { heuristic = HeuristicType.AMEASURE; } else if(accM.equals("fmeasure")) { @@ -121,19 +116,7 @@ public static String getName() { return "pos neg learning problem"; } - - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(PosNegLP.createConfigOptions()); - BooleanConfigOption approx = new BooleanConfigOption("useApproximations", "whether to use stochastic approximations for computing accuracy", false); - options.add(approx); - DoubleConfigOption approxAccuracy = new DoubleConfigOption("approxAccuracy", "accuracy of the approximation (only for expert use)", 0.05); - options.add(approxAccuracy); - StringConfigOption accMethod = new StringConfigOption("accuracyMethod", "Specifies, which method/function to use for computing accuracy.","predacc"); // or domain/range of a property. - accMethod.setAllowedValues(new String[] {"fmeasure", "predacc"}); - options.add(accMethod); - return options; - } - + /** * This method computes (using the reasoner) whether a concept is too weak. * If it is not weak, it returns the number of covered negative examples. It @@ -150,9 +133,9 @@ @Override public int coveredNegativeExamplesOrTooWeak(Description concept) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + if (isUseRetrievalForClassification()) { + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + Set<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); // the set is constructed piecewise to avoid expensive set @@ -170,21 +153,21 @@ else return negAsPos.size(); } else { - if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { + if (getUseMultiInstanceChecks() != UseMultiInstanceChecks.NEVER) { // two checks - if (useMultiInstanceChecks == UseMultiInstanceChecks.TWOCHECKS) { - Set<Individual> s = reasoner.hasType(concept, positiveExamples); + if (getUseMultiInstanceChecks() == UseMultiInstanceChecks.TWOCHECKS) { + Set<Individual> s = getReasoner().hasType(concept, positiveExamples); // if the concept is too weak, then do not query negative // examples if (s.size() != positiveExamples.size()) return -1; else { - s = reasoner.hasType(concept, negativeExamples); + s = getReasoner().hasType(concept, negativeExamples); return s.size(); } // one check } else { - Set<Individual> s = reasoner.hasType(concept, allExamples); + Set<Individual> s = getReasoner().hasType(concept, allExamples); // test whether all positive examples are covered if (s.containsAll(positiveExamples)) return s.size() - positiveExamples.size(); @@ -196,12 +179,12 @@ SortedSet<Individual> negAsPos = new TreeSet<Individual>(); for (Individual example : positiveExamples) { - if (!reasoner.hasType(concept, example)) + if (!getReasoner().hasType(concept, example)) return -1; // posAsNeg.add(example); } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); } @@ -229,10 +212,10 @@ @Override public ScorePosNeg computeScore(Description concept) { if(useOldDIGOptions) { - if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + if (isUseRetrievalForClassification()) { + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + Set<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + Set<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); // piecewise set construction @@ -245,18 +228,18 @@ if (!posClassified.contains(negExample)) negAsNeg.add(negExample); } - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg); // instance checks for classification } else { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + Set<Individual> posAsPos = new TreeSet<Individual>(); + Set<Individual> posAsNeg = new TreeSet<Individual>(); + Set<Individual> negAsPos = new TreeSet<Individual>(); + Set<Individual> negAsNeg = new TreeSet<Individual>(); - if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - SortedSet<Individual> posClassified = reasoner.hasType(concept, - allExamples); - SortedSet<Individual> negClassified = Helper.difference(allExamples, + if (getUseMultiInstanceChecks() != UseMultiInstanceChecks.NEVER) { + SortedSet<Individual> posClassified = getReasoner().hasType(concept, + allExamples); + Set<Individual> negClassified = Helper.difference(allExamples, posClassified); posAsPos = Helper.intersection(positiveExamples, posClassified); posAsNeg = Helper.intersection(positiveExamples, negClassified); @@ -265,24 +248,24 @@ // System.out.println("pos classified: " + posClassified); - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg); } else { for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); } - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg); } } @@ -294,14 +277,14 @@ SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); @@ -310,7 +293,7 @@ // TODO: this computes accuracy twice - more elegant method should be implemented double accuracy = getAccuracyOrTooWeakExact(concept,1); - return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, + return new ScoreTwoValued(concept.getLength(), getPercentPerLengthUnit(), posAsPos, posAsNeg, negAsPos, negAsNeg, accuracy); } @@ -373,7 +356,7 @@ Individual posExample = itPos.next(); // System.out.println(posExample); - if(reasoner.hasType(description, posExample)) { + if(getReasoner().hasType(description, posExample)) { posClassifiedAsPos++; } else { notCoveredPos++; @@ -388,7 +371,7 @@ if(itNeg.hasNext()) { Individual negExample = itNeg.next(); - if(!reasoner.hasType(description, negExample)) { + if(!getReasoner().hasType(description, negExample)) { negClassifiedAsNeg++; } nrOfNegChecks++; @@ -415,7 +398,7 @@ int instancesNotCovered = 0; for(Individual ind : positiveExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -432,7 +415,7 @@ for(Individual ind : negativeExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } testsPerformed++; @@ -499,7 +482,7 @@ int notCoveredNeg = 0; for (Individual example : positiveExamples) { - if (!reasoner.hasType(description, example)) { + if (!getReasoner().hasType(description, example)) { notCoveredPos++; if(notCoveredPos >= maxNotCovered) { return -1; @@ -507,7 +490,7 @@ } } for (Individual example : negativeExamples) { - if (!reasoner.hasType(description, example)) { + if (!getReasoner().hasType(description, example)) { notCoveredNeg++; } } @@ -524,14 +507,14 @@ public double getFMeasureOrTooWeakExact(Description description, double noise) { int additionalInstances = 0; for(Individual ind : negativeExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { additionalInstances++; } } int coveredInstances = 0; for(Individual ind : positiveExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { coveredInstances++; } } @@ -566,7 +549,7 @@ int upperEstimateA = positiveExamples.size(); for(Individual ind : positiveExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -629,7 +612,7 @@ for(Individual ind : negativeExamples) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } @@ -685,6 +668,29 @@ private double getFMeasure(double recall, double precision) { return 2 * precision * recall / (precision + recall); - } - + } + + public double getApproxDelta() { + return approxDelta; + } + + public void setApproxDelta(double approxDelta) { + this.approxDelta = approxDelta; + } + + public boolean isUseApproximations() { + return useApproximations; + } + + public void setUseApproximations(boolean useApproximations) { + this.useApproximations = useApproximations; + } + + public String getAccuracyMethod() { + return accuracyMethod; + } + + public void setAccuracyMethod(String accuracyMethod) { + this.accuracyMethod = accuracyMethod; + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -20,6 +20,7 @@ package org.dllearner.learningproblems; import java.util.Collection; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -44,7 +45,7 @@ */ public class PosNegLPStrict extends PosNegLP { - private SortedSet<Individual> neutralExamples; + private Set<Individual> neutralExamples; private boolean penaliseNeutralExamples = false; private static final double defaultAccuracyPenalty = 1; @@ -104,7 +105,7 @@ // compute neutral examples, i.e. those which are neither positive // nor negative (we have to take care to copy sets instead of // modifying them) - neutralExamples = Helper.intersection(reasoner.getIndividuals(),positiveExamples); + neutralExamples = Helper.intersection(getReasoner().getIndividuals(),positiveExamples); neutralExamples.retainAll(negativeExamples); } @@ -113,23 +114,23 @@ */ @Override public ScorePosNeg computeScore(Description concept) { - if(useRetrievalForClassification) { - if(reasoner.getReasonerType() == ReasonerType.FAST_RETRIEVAL) { - SortedSetTuple<Individual> tuple = reasoner.doubleRetrieval(concept); + if(isUseRetrievalForClassification()) { + if(getReasoner().getReasonerType() == ReasonerType.FAST_RETRIEVAL) { + SortedSetTuple<Individual> tuple = getReasoner().doubleRetrieval(concept); // this.defPosSet = tuple.getPosSet(); // this.defNegSet = tuple.getNegSet(); - SortedSet<Individual> neutClassified = Helper.intersectionTuple(reasoner.getIndividuals(),tuple); - return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); - } else if(reasoner.getReasonerType() == ReasonerType.KAON2) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> negClassified = reasoner.getIndividuals(new Negation(concept)); - SortedSet<Individual> neutClassified = Helper.intersection(reasoner.getIndividuals(),posClassified); + Set<Individual> neutClassified = Helper.intersectionTuple(getReasoner().getIndividuals(),tuple); + return new ScoreThreeValued(concept.getLength(),accuracyPenalty, errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), tuple.getPosSet(),neutClassified,tuple.getNegSet(),positiveExamples,neutralExamples,negativeExamples); + } else if(getReasoner().getReasonerType() == ReasonerType.KAON2) { + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + SortedSet<Individual> negClassified = getReasoner().getIndividuals(new Negation(concept)); + Set<Individual> neutClassified = Helper.intersection(getReasoner().getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } else { - if(reasoner.getReasonerType() == ReasonerType.KAON2) { + if(getReasoner().getReasonerType() == ReasonerType.KAON2) { if(penaliseNeutralExamples) throw new Error("It does not make sense to use single instance checks when" + "neutral examples are penalized. Use Retrievals instead."); @@ -144,28 +145,28 @@ // umstellen // pos => pos for(Individual example : positiveExamples) { - if(reasoner.hasType(concept, example)) + if(getReasoner().hasType(concept, example)) posClassified.add(example); } // neg => pos for(Individual example: negativeExamples) { - if(reasoner.hasType(concept, example)) + if(getReasoner().hasType(concept, example)) posClassified.add(example); } // pos => neg for(Individual example : positiveExamples) { - if(reasoner.hasType(new Negation(concept), example)) + if(getReasoner().hasType(new Negation(concept), example)) negClassified.add(example); } // neg => neg for(Individual example : negativeExamples) { - if(reasoner.hasType(new Negation(concept), example)) + if(getReasoner().hasType(new Negation(concept), example)) negClassified.add(example); } - SortedSet<Individual> neutClassified = Helper.intersection(reasoner.getIndividuals(),posClassified); + Set<Individual> neutClassified = Helper.intersection(getReasoner().getIndividuals(),posClassified); neutClassified.retainAll(negClassified); - return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, percentPerLengthUnit, posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); + return new ScoreThreeValued(concept.getLength(), accuracyPenalty, errorPenalty, penaliseNeutralExamples, getPercentPerLengthUnit(), posClassified,neutClassified,negClassified,positiveExamples,neutralExamples,negativeExamples); } else throw new Error("score cannot be computed in this configuration"); } @@ -179,7 +180,7 @@ throw new UnsupportedOperationException("Method not implemented for three valued definition learning problem."); } - public SortedSet<Individual> getNeutralExamples() { + public Set<Individual> getNeutralExamples() { return neutralExamples; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -116,7 +116,7 @@ // reasoning options (i.e. options are the same up to reversed example sets) // definitionLP.init(); - individuals = new LinkedList<Individual>(reasoner.getIndividuals()); + individuals = new LinkedList<Individual>(getReasoner().getIndividuals()); positiveExamplesShuffled = new LinkedList<Individual>(positiveExamples); Random rand = new Random(1); Collections.shuffle(individuals, rand); @@ -144,7 +144,7 @@ */ @Override public ScorePosOnly computeScore(Description description) { - Set<Individual> retrieval = reasoner.getIndividuals(description); + Set<Individual> retrieval = getReasoner().getIndividuals(description); Set<Individual> instancesCovered = new TreeSet<Individual>(); Set<Individual> instancesNotCovered = new TreeSet<Individual>(); @@ -178,7 +178,7 @@ */ @Override public double getAccuracy(Description description) { - Set<Individual> retrieval = reasoner.getIndividuals(description); + Set<Individual> retrieval = getReasoner().getIndividuals(description); int instancesCovered = 0; for(Individual ind : positiveExamples) { @@ -215,7 +215,7 @@ int upperEstimateA = positiveExamples.size(); for(Individual ind : positiveExamplesShuffled) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesCovered++; } else { instancesNotCovered ++; @@ -267,7 +267,7 @@ for(Individual ind : individuals) { - if(reasoner.hasType(description, ind)) { + if(getReasoner().hasType(description, ind)) { instancesDescription++; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ScoreThreeValued.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -21,7 +21,6 @@ import java.text.DecimalFormat; import java.util.Set; -import java.util.SortedSet; import org.dllearner.core.owl.Individual; import org.dllearner.utilities.Helper; @@ -55,12 +54,12 @@ private boolean showCorrectClassifications = false; private static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; - private SortedSet<Individual> posClassified; - private SortedSet<Individual> neutClassified; - private SortedSet<Individual> negClassified; - private SortedSet<Individual> posExamples; - private SortedSet<Individual> neutExamples; - private SortedSet<Individual> negExamples; + private Set<Individual> posClassified; + private Set<Individual> neutClassified; + private Set<Individual> negClassified; + private Set<Individual> posExamples; + private Set<Individual> neutExamples; + private Set<Individual> negExamples; private Set<Individual> posAsNeg; private Set<Individual> negAsPos; @@ -86,12 +85,12 @@ double errorPenalty, boolean penaliseNeutralExamples, double percentPerLengthUnit, - SortedSet<Individual> posClassified, - SortedSet<Individual> neutClassified, - SortedSet<Individual> negClassified, - SortedSet<Individual> posExamples, - SortedSet<Individual> neutExamples, - SortedSet<Individual> negExamples) { + Set<Individual> posClassified, + Set<Individual> neutClassified, + Set<Individual> negClassified, + Set<Individual> posExamples, + Set<Individual> neutExamples, + Set<Individual> negExamples) { this.conceptLength = conceptLength; this.accuracyPenalty = accuracyPenalty; this.errorPenalty = errorPenalty; @@ -207,11 +206,11 @@ return str; } - public SortedSet<Individual> getNegClassified() { + public Set<Individual> getNegClassified() { return negClassified; } - public SortedSet<Individual> getPosClassified() { + public Set<Individual> getPosClassified() { return posClassified; } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java 2011-08-24 00:40:14 UTC (rev 3104) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/fuzzydll/FuzzyPosNegLPStandard.java 2011-08-24 04:53:15 UTC (rev 3105) @@ -19,13 +19,7 @@ package org.dllearner.learningproblems.fuzzydll; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Scanner; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; @@ -41,7 +35,6 @@ import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.Heuristics; -import org.dllearner.learningproblems.fuzzydll.FuzzyPosNegLP; import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.learningproblems.Heuristics.HeuristicType; @@ -248,9 +241,9 @@ public ScorePosNeg computeScore(Description concept) { if(useOldDIGOptions) { if (useRetrievalForClassification) { - SortedSet<Individual> posClassified = reasoner.getIndividuals(concept); - SortedSet<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); - SortedSet<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); + SortedSet<Individual> posClassified = getReasoner().getIndividuals(concept); + Set<Individual> posAsPos = Helper.intersection(positiveExamples, posClassified); + Set<Individual> negAsPos = Helper.intersection(negativeExamples, posClassified); SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); // piecewise set construction @@ -266,13 +259,13 @@ return new ScoreTwoValued(concept.getLength(), percentPerLengthUnit, posAsPos, posAsNeg, negAsPos, negAsNeg); // instance checks for classification } else { - SortedSet<Individual> posAsPos = new TreeSet<Individual>(); - SortedSet<Individual> posAsNeg = new TreeSet<Individual>(); - SortedSet<Individual> negAsPos = new TreeSet<Individual>(); - SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); + Set<Individual> posAsPos = new TreeSet<Individual>(); + Set<Individual> posAsNeg = new TreeSet<Individual>(); + Set<Individual> negAsPos = new TreeSet<Individual>(); + Set<Individual> negAsNeg = new TreeSet<Individual>(); if (useMultiInstanceChecks != UseMultiInstanceChecks.NEVER) { - SortedSet<Individual> posClassified = reasoner.hasType(concept, allExamples); + SortedSet<Individual> posClassified = getReasoner().hasType(concept, allExamples); SortedSet<Individual> negClassified = Helper.difference(allExamples, posClassified); posAsPos = Helper.intersection(positiveExamples, posClassified); posAsNeg = Helper.intersection(positiveExamples, negClassified); @@ -286,14 +279,14 @@ } else { for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); @@ -310,14 +303,14 @@ SortedSet<Individual> negAsNeg = new TreeSet<Individual>(); for (Individual example : positiveExamples) { - if (reasoner.hasType(concept, example)) { + if (getReasoner().hasType(concept, example)) { posAsPos.add(example); } else { posAsNeg.add(example); } } for (Individual example : negativeExamples) { - if (reasoner.hasType(concept, example)) + if (getReasoner().hasType(concept, example)) negAsPos.add(example); else negAsNeg.add(example); @@ -388,7 +381,7 @@ Individual posExample = itPos.next(); // System.out.println(posExample); - if(reasoner.hasType(description, posExample)) { + if(getReasoner().hasType(description, posExample)) { posClassifiedAsPos++; } else { notCoveredPos++; @@ -403,7 +396,7 @@ if(itNeg.hasNext()) { Individual negExample = itNeg.next(); - if(!reasoner.hasType(description, negExample)) { + if(!getReasoner().has... [truncated message content] |
From: <jen...@us...> - 2011-08-24 09:34:41
|
Revision: 3108 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3108&view=rev Author: jenslehmann Date: 2011-08-24 09:34:32 +0000 (Wed, 24 Aug 2011) Log Message: ----------- removed the OCELConfigurator class and rewrote dozens of code snippets using it Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ExampleBasedNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java trunk/components-core/src/main/java/org/dllearner/core/config/BooleanEditor.java trunk/components-core/src/main/java/org/dllearner/core/configurators/ComponentFactory.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/fuzzydll/FuzzyRhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/ExampleDataCollector.java trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java trunk/examples/family/father.conf trunk/scripts/src/main/java/org/dllearner/scripts/ConfigJavaGenerator.java trunk/scripts/src/main/java/org/dllearner/scripts/DumbLPFinder.java trunk/scripts/src/main/java/org/dllearner/scripts/NewSample.java trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -229,8 +229,26 @@ singleSuggestionMode = configurator.getSingleSuggestionMode(); + // TODO: 1. turn those into instance variables / fields 2. provide getters/setters; + // 3. annotate them with @ConfigOption => this all needs to be done in FuzzyRhoDRDown, + // not in this class + boolean useExistsConstructor = true; + int valueFrequencyThreshold = 2; + boolean useCardinalityRestrictions = false; + int cardinalityLimit = 1; + boolean useHasValueConstructor = false; + boolean useNegation = true; + boolean useStringDatatypes = false; + boolean useBooleanDatatypes = false; + boolean useDoubleDatatypes = false; + boolean instanceBasedDisjoints = true; + boolean applyAllFilter = true; + boolean applyExistsFilter = true; + boolean useAllConstructor = true; + // create refinement operator - operator = new FuzzyRhoDRDown(reasoner, classHierarchy, startClass, configurator); + operator = new FuzzyRhoDRDown(reasoner, classHierarchy, cardinalityLimit, useHasValueConstructor, useStringDatatypes, instanceBasedDisjoints, applyAllFilter, applyExistsFilter, useAllConstructor, + useExistsConstructor, valueFrequencyThreshold, useCardinalityRestrictions, useNegation, useBooleanDatatypes, useDoubleDatatypes, (NamedClass) startClass); baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); if(configurator.getWriteSearchTree()) { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ExampleBasedNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ExampleBasedNode.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ExampleBasedNode.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -26,7 +26,6 @@ import java.util.TreeSet; import org.dllearner.algorithms.SearchTreeNode; -import org.dllearner.core.configurators.OCELConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.utilities.owl.ConceptComparator; @@ -45,7 +44,7 @@ // public static long exampleMemoryCounter = 0; - private OCELConfigurator configurator; +// private OCELConfigurator configurator; private static DecimalFormat df = new DecimalFormat(); @@ -68,6 +67,11 @@ private boolean isQualityEvaluated; private boolean isRedundant; + private double negativeWeight; + private double startNodeBonus; + private double expansionPenaltyFactor; + private int negationPenalty; + private static ConceptComparator conceptComparator = new ConceptComparator(); private static NodeComparatorStable nodeComparator = new NodeComparatorStable(); @@ -80,11 +84,15 @@ // a flag whether this could be a solution for a posonly learning problem private boolean isPosOnlyCandidate = true; - public ExampleBasedNode(OCELConfigurator configurator, Description concept) { - this.configurator = configurator; + public ExampleBasedNode(Description concept, double negativeWeight, double startNodeBonus, double expansionPenaltyFactor, int negationPenalty) { +// this.configurator = configurator; this.concept = concept; horizontalExpansion = 0; isQualityEvaluated = false; + this.negativeWeight = negativeWeight; + this.startNodeBonus = startNodeBonus; + this.expansionPenaltyFactor = expansionPenaltyFactor; + this.negationPenalty = negationPenalty; } public void setHorizontalExpansion(int horizontalExpansion) { @@ -180,7 +188,7 @@ ret += "acc:" + df.format(accuracy) + "% "; // comment this out to display the heuristic score with default parameters - double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, configurator); + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); ret += "h:" +df.format(heuristicScore) + " "; int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); @@ -203,7 +211,7 @@ ret += "<b>acc: " + df.format(accuracy) + "% </b>"; // comment this out to display the heuristic score with default parameters - double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, configurator); + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); ret += "h:" +df.format(heuristicScore) + " "; int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); @@ -227,7 +235,7 @@ ret += "acc:" + df.format(accuracy) + "% "; // comment this out to display the heuristic score with default parameters - double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, configurator); + double heuristicScore = MultiHeuristic.getNodeScore(this, nrOfPositiveExamples, nrOfNegativeExamples, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); ret += "h:" +df.format(heuristicScore) + " "; int wrongPositives = nrOfPositiveExamples - coveredPositives.size(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -21,7 +21,6 @@ import java.util.List; -import org.dllearner.core.configurators.OCELConfigurator; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Negation; @@ -70,7 +69,7 @@ public class MultiHeuristic implements ExampleBasedHeuristic { private ConceptComparator conceptComparator = new ConceptComparator(); - private OCELConfigurator configurator; +// private OCELConfigurator configurator; // heuristic parameters private double expansionPenaltyFactor = 0.02; @@ -80,6 +79,7 @@ // penalise errors on positive examples harder than on negative examples // (positive weight = 1) private double negativeWeight = 1.0; // was 0.8; + private int negationPenalty = 0; // examples private int nrOfNegativeExamples; @@ -92,13 +92,13 @@ // this(nrOfPositiveExamples, nrOfNegativeExamples, 0.02, 0.5); } - public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, OCELConfigurator configurator) { + public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, double negativeWeight, double startNodeBonus, double expansionPenaltyFactor, int negationPenalty) { this.nrOfNegativeExamples = nrOfNegativeExamples; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; - this.configurator = configurator; - negativeWeight = configurator.getNegativeWeight(); - startNodeBonus = configurator.getStartNodeBonus(); - expansionPenaltyFactor = configurator.getExpansionPenaltyFactor(); +// this.configurator = configurator; + this.negativeWeight = negativeWeight; + this.startNodeBonus = startNodeBonus; + this.expansionPenaltyFactor = expansionPenaltyFactor; } // public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, double expansionPenaltyFactor, double gainBonusFactor) { @@ -144,8 +144,8 @@ return (coveredPositives + negativeWeight * (nrOfNegativeExamples - coveredNegatives))/(double)nrOfExamples; } - public static double getNodeScore(ExampleBasedNode node, int nrOfPositiveExamples, int nrOfNegativeExamples, OCELConfigurator configurator) { - MultiHeuristic multi = new MultiHeuristic(nrOfPositiveExamples, nrOfNegativeExamples, configurator); + public static double getNodeScore(ExampleBasedNode node, int nrOfPositiveExamples, int nrOfNegativeExamples, double negativeWeight, double startNodeBonus, double expansionPenaltyFactor, int negationPenalty) { + MultiHeuristic multi = new MultiHeuristic(nrOfPositiveExamples, nrOfNegativeExamples, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); return multi.getNodeScore(node); } @@ -162,7 +162,7 @@ // we put a penalty on negations, because they often overfit // (TODO: make configurable) else if(description instanceof Negation) { - bonus = -configurator.getNegationPenalty(); + bonus = -negationPenalty; } // if(description instanceof BooleanValueRestriction) Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -28,11 +28,10 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.configurators.OCELConfigurator; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; import org.dllearner.core.options.CommonConfigOptions; @@ -82,16 +81,15 @@ */ public class OCEL extends AbstractCELA { - private OCELConfigurator configurator; - - public OCELConfigurator getConfigurator(){ - return configurator; - } +// private OCELConfigurator configurator; +// +// public OCELConfigurator getConfigurator(){ +// return configurator; +// } // actual algorithm private ROLearner2 algorithm; - private static Logger logger = Logger - .getLogger(OCEL.class); + private static Logger logger = Logger.getLogger(OCEL.class); private String logLevel = CommonConfigOptions.logLevelDefault; RhoDRDown operator; @@ -125,6 +123,7 @@ private static double noisePercentageDefault = 0.0; private double noisePercentage = noisePercentageDefault; private NamedClass startClass = null; + private boolean useDataHasValueConstructor = false; //refactor this private static boolean usePropernessChecksDefault = false; private boolean usePropernessChecks = usePropernessChecksDefault; @@ -139,11 +138,20 @@ private int guaranteeXgoodDescriptions = CommonConfigOptions.guaranteeXgoodDescriptionsDefault; private int maxClassDescriptionTests = CommonConfigOptions.maxClassDescriptionTestsDefault; + private double negativeWeight; + private double startNodeBonus; + private double expansionPenaltyFactor; + private int negationPenalty; + private boolean terminateOnNoiseReached = true; + // Variablen zur Einstellung der Protokollierung // boolean quiet = false; boolean showBenchmarkInformation = false; // boolean createTreeString = false; // String searchTree = new String(); + private int cardinalityLimit; + private boolean useStringDatatypes; + private boolean instanceBasedDisjoints; // Konfiguration des Algorithmus // Faktor für horizontale Erweiterung (notwendig für completeness) @@ -153,12 +161,12 @@ // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { public OCEL(PosNegLP learningProblem, AbstractReasonerComponent reasoningService) { super(learningProblem, reasoningService); - this.configurator = new OCELConfigurator(this); +// this.configurator = new OCELConfigurator(this); } public OCEL(PosOnlyLP learningProblem, AbstractReasonerComponent reasoningService) { super(learningProblem, reasoningService); - this.configurator = new OCELConfigurator(this); +// this.configurator = new OCELConfigurator(this); } public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { @@ -332,9 +340,9 @@ } else { if(learningProblem instanceof PosOnlyLP) { // throw new RuntimeException("does not work with positive examples only yet"); - algHeuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, configurator); + algHeuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } else { - algHeuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), configurator); + algHeuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } } @@ -392,7 +400,7 @@ operator = new RhoDRDown( reasoner, classHierarchy, - configurator, +// configurator, applyAllFilter, applyExistsFilter, useAllConstructor, @@ -403,13 +411,16 @@ useNegation, useBooleanDatatypes, useDoubleDatatypes, - startClass + startClass, + cardinalityLimit, + useStringDatatypes, + instanceBasedDisjoints ); // create an algorithm object and pass all configuration // options to it algorithm = new ROLearner2( - configurator, +// configurator, learningProblem, reasoner, operator, @@ -430,7 +441,12 @@ minExecutionTimeInSeconds, guaranteeXgoodDescriptions, maxClassDescriptionTests, - forceRefinementLengthIncrease + forceRefinementLengthIncrease, + terminateOnNoiseReached, + negativeWeight, + startNodeBonus, + expansionPenaltyFactor, + negationPenalty ); // note: used concepts and roles do not need to be passed // as argument, because it is sufficient to prepare the @@ -498,4 +514,332 @@ public RhoDRDown getRefinementOperator() { return operator; } + + public RhoDRDown getOperator() { + return operator; + } + + public void setOperator(RhoDRDown operator) { + this.operator = operator; + } + + public boolean isWriteSearchTree() { + return writeSearchTree; + } + + public void setWriteSearchTree(boolean writeSearchTree) { + this.writeSearchTree = writeSearchTree; + } + + public File getSearchTreeFile() { + return searchTreeFile; + } + + public void setSearchTreeFile(File searchTreeFile) { + this.searchTreeFile = searchTreeFile; + } + + public boolean isReplaceSearchTree() { + return replaceSearchTree; + } + + public void setReplaceSearchTree(boolean replaceSearchTree) { + this.replaceSearchTree = replaceSearchTree; + } + + public String getHeuristic() { + return heuristic; + } + + public void setHeuristic(String heuristic) { + this.heuristic = heuristic; + } + + public Set<NamedClass> getAllowedConcepts() { + return allowedConcepts; + } + + public void setAllowedConcepts(Set<NamedClass> allowedConcepts) { + this.allowedConcepts = allowedConcepts; + } + + public Set<ObjectProperty> getAllowedRoles() { + return allowedRoles; + } + + public void setAllowedRoles(Set<ObjectProperty> allowedRoles) { + this.allowedRoles = allowedRoles; + } + + public Set<NamedClass> getIgnoredConcepts() { + return ignoredConcepts; + } + + public void setIgnoredConcepts(Set<NamedClass> ignoredConcepts) { + this.ignoredConcepts = ignoredConcepts; + } + + public Set<ObjectProperty> getIgnoredRoles() { + return ignoredRoles; + } + + public void setIgnoredRoles(Set<ObjectProperty> ignoredRoles) { + this.ignoredRoles = ignoredRoles; + } + + public Set<NamedClass> getUsedConcepts() { + return usedConcepts; + } + + public void setUsedConcepts(Set<NamedClass> usedConcepts) { + this.usedConcepts = usedConcepts; + } + + public Set<ObjectProperty> getUsedRoles() { + return usedRoles; + } + + public void setUsedRoles(Set<ObjectProperty> usedRoles) { + this.usedRoles = usedRoles; + } + + public boolean isApplyAllFilter() { + return applyAllFilter; + } + + public void setApplyAllFilter(boolean applyAllFilter) { + this.applyAllFilter = applyAllFilter; + } + + public boolean isApplyExistsFilter() { + return applyExistsFilter; + } + + public void setApplyExistsFilter(boolean applyExistsFilter) { + this.applyExistsFilter = applyExistsFilter; + } + + public boolean isUseTooWeakList() { + return useTooWeakList; + } + + public void setUseTooWeakList(boolean useTooWeakList) { + this.useTooWeakList = useTooWeakList; + } + + public boolean isUseOverlyGeneralList() { + return useOverlyGeneralList; + } + + public void setUseOverlyGeneralList(boolean useOverlyGeneralList) { + this.useOverlyGeneralList = useOverlyGeneralList; + } + + public boolean isUseShortConceptConstruction() { + return useShortConceptConstruction; + } + + public void setUseShortConceptConstruction(boolean useShortConceptConstruction) { + this.useShortConceptConstruction = useShortConceptConstruction; + } + + public boolean isImproveSubsumptionHierarchy() { + return improveSubsumptionHierarchy; + } + + public void setImproveSubsumptionHierarchy(boolean improveSubsumptionHierarchy) { + this.improveSubsumptionHierarchy = improveSubsumptionHierarchy; + } + + public boolean isUseAllConstructor() { + return useAllConstructor; + } + + public void setUseAllConstructor(boolean useAllConstructor) { + this.useAllConstructor = useAllConstructor; + } + + public boolean isUseExistsConstructor() { + return useExistsConstructor; + } + + public void setUseExistsConstructor(boolean useExistsConstructor) { + this.useExistsConstructor = useExistsConstructor; + } + + public boolean isUseHasValueConstructor() { + return useHasValueConstructor; + } + + public void setUseHasValueConstructor(boolean useHasValueConstructor) { + this.useHasValueConstructor = useHasValueConstructor; + } + + public int getValueFrequencyThreshold() { + return valueFrequencyThreshold; + } + + public void setValueFrequencyThreshold(int valueFrequencyThreshold) { + this.valueFrequencyThreshold = valueFrequencyThreshold; + } + + public boolean isUseCardinalityRestrictions() { + return useCardinalityRestrictions; + } + + public void setUseCardinalityRestrictions(boolean useCardinalityRestrictions) { + this.useCardinalityRestrictions = useCardinalityRestrictions; + } + + public boolean isUseNegation() { + return useNegation; + } + + public void setUseNegation(boolean useNegation) { + this.useNegation = useNegation; + } + + public boolean isUseBooleanDatatypes() { + return useBooleanDatatypes; + } + + public void setUseBooleanDatatypes(boolean useBooleanDatatypes) { + this.useBooleanDatatypes = useBooleanDatatypes; + } + + public boolean isUseDoubleDatatypes() { + return useDoubleDatatypes; + } + + public void setUseDoubleDatatypes(boolean useDoubleDatatypes) { + this.useDoubleDatatypes = useDoubleDatatypes; + } + + public double getNoisePercentage() { + return noisePercentage; + } + + public void setNoisePercentage(double noisePercentage) { + this.noisePercentage = noisePercentage; + } + + public NamedClass getStartClass() { + return startClass; + } + + public void setStartClass(NamedClass startClass) { + this.startClass = startClass; + } + + public boolean isUsePropernessChecks() { + return usePropernessChecks; + } + + public void setUsePropernessChecks(boolean usePropernessChecks) { + this.usePropernessChecks = usePropernessChecks; + } + + public int getMaxPosOnlyExpansion() { + return maxPosOnlyExpansion; + } + + public void setMaxPosOnlyExpansion(int maxPosOnlyExpansion) { + this.maxPosOnlyExpansion = maxPosOnlyExpansion; + } + + public boolean isForceRefinementLengthIncrease() { + return forceRefinementLengthIncrease; + } + + public void setForceRefinementLengthIncrease(boolean forceRefinementLengthIncrease) { + this.forceRefinementLengthIncrease = forceRefinementLengthIncrease; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public int getMinExecutionTimeInSeconds() { + return minExecutionTimeInSeconds; + } + + public void setMinExecutionTimeInSeconds(int minExecutionTimeInSeconds) { + this.minExecutionTimeInSeconds = minExecutionTimeInSeconds; + } + + public int getGuaranteeXgoodDescriptions() { + return guaranteeXgoodDescriptions; + } + + public void setGuaranteeXgoodDescriptions(int guaranteeXgoodDescriptions) { + this.guaranteeXgoodDescriptions = guaranteeXgoodDescriptions; + } + + public int getMaxClassDescriptionTests() { + return maxClassDescriptionTests; + } + + public void setMaxClassDescriptionTests(int maxClassDescriptionTests) { + this.maxClassDescriptionTests = maxClassDescriptionTests; + } + + public boolean isShowBenchmarkInformation() { + return showBenchmarkInformation; + } + + public void setShowBenchmarkInformation(boolean showBenchmarkInformation) { + this.showBenchmarkInformation = showBenchmarkInformation; + } + + public double getNegativeWeight() { + return negativeWeight; + } + + public void setNegativeWeight(double negativeWeight) { + this.negativeWeight = negativeWeight; + } + + public double getStartNodeBonus() { + return startNodeBonus; + } + + public void setStartNodeBonus(double startNodeBonus) { + this.startNodeBonus = startNodeBonus; + } + + public double getExpansionPenaltyFactor() { + return expansionPenaltyFactor; + } + + public void setExpansionPenaltyFactor(double expansionPenaltyFactor) { + this.expansionPenaltyFactor = expansionPenaltyFactor; + } + + public double getNegationPenalty() { + return negationPenalty; + } + + public void setNegationPenalty(int negationPenalty) { + this.negationPenalty = negationPenalty; + } + + public boolean isUseDataHasValueConstructor() { + return useDataHasValueConstructor; + } + + public void setUseDataHasValueConstructor(boolean useDataHasValueConstructor) { + this.useDataHasValueConstructor = useDataHasValueConstructor; + } + + public boolean isTerminateOnNoiseReached() { + return terminateOnNoiseReached; + } + + public void setTerminateOnNoiseReached(boolean terminateOnNoiseReached) { + this.terminateOnNoiseReached = terminateOnNoiseReached; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -35,7 +35,6 @@ import org.apache.log4j.Logger; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.configurators.OCELConfigurator; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; @@ -64,7 +63,7 @@ public class ROLearner2 { private static Logger logger = Logger.getLogger(ROLearner2.class); - private OCELConfigurator configurator; +// private OCELConfigurator configurator; // basic setup: learning problem and reasoning service private AbstractReasonerComponent rs; @@ -211,8 +210,18 @@ private String baseURI; private Map<String, String> prefixes; + private boolean terminateOnNoiseReached; + + private double negativeWeight; + + private double startNodeBonus; + + private double expansionPenaltyFactor; + + private int negationPenalty; + public ROLearner2( - OCELConfigurator configurator, +// OCELConfigurator configurator, AbstractLearningProblem learningProblem, AbstractReasonerComponent rs, RefinementOperator operator, @@ -224,7 +233,9 @@ boolean useTooWeakList, boolean useOverlyGeneralList, boolean useShortConceptConstruction, boolean usePropernessChecks, int maxPosOnlyExpansion, int maxExecutionTimeInSeconds, int minExecutionTimeInSeconds, - int guaranteeXgoodDescriptions, int maxClassDescriptionTests, boolean forceRefinementLengthIncrease) { + int guaranteeXgoodDescriptions, int maxClassDescriptionTests, boolean forceRefinementLengthIncrease, + boolean terminateOnNoiseReached, + double negativeWeight, double startNodeBonus, double expansionPenaltyFactor, int negationPenalty) { PosNegLP lp = (PosNegLP) learningProblem; @@ -234,11 +245,17 @@ nrOfPositiveExamples = positiveExamples.size(); nrOfNegativeExamples = negativeExamples.size(); + this.negativeWeight = negativeWeight; + this.startNodeBonus = startNodeBonus; + this.expansionPenaltyFactor = expansionPenaltyFactor; + this.negationPenalty = negationPenalty; + // System.out.println(nrOfPositiveExamples); // System.out.println(nrOfNegativeExamples); // System.exit(0); - this.configurator = configurator; +// this.configurator = configurator; + this.terminateOnNoiseReached = terminateOnNoiseReached; nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; this.rs = rs; this.operator = (RhoDRDown) operator; @@ -353,10 +370,10 @@ // start search with start class if (startDescription == null) { - startNode = new ExampleBasedNode(configurator, Thing.instance); + startNode = new ExampleBasedNode(Thing.instance, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); startNode.setCoveredExamples(positiveExamples, negativeExamples); } else { - startNode = new ExampleBasedNode(configurator, startDescription); + startNode = new ExampleBasedNode(startDescription, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); Set<Individual> coveredNegatives = rs.hasType(startDescription, negativeExamples); Set<Individual> coveredPositives = rs.hasType(startDescription, positiveExamples); startNode.setCoveredExamples(coveredPositives, coveredNegatives); @@ -627,7 +644,7 @@ properRefinements.add(refinement); tooWeakList.add(refinement); - ExampleBasedNode newNode = new ExampleBasedNode(configurator, refinement); + ExampleBasedNode newNode = new ExampleBasedNode(refinement, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); newNode.setHorizontalExpansion(refinement.getLength() - 1); newNode.setTooWeak(true); newNode @@ -717,7 +734,7 @@ if (nonRedundant) { // newly created node - ExampleBasedNode newNode = new ExampleBasedNode(configurator, refinement); + ExampleBasedNode newNode = new ExampleBasedNode(refinement, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); // die -1 ist wichtig, da sonst keine gleich langen Refinements // für den neuen Knoten erlaubt wären z.B. person => male newNode.setHorizontalExpansion(refinement.getLength() - 1); @@ -1326,7 +1343,7 @@ // reached - unless this termination criterion is switched off using terminateOnNoiseReached = false if (guaranteeXgoodAlreadyReached){ result = true; - } else if(solutions.size() >= guaranteeXgoodDescriptions && configurator.getTerminateOnNoiseReached()) { + } else if(solutions.size() >= guaranteeXgoodDescriptions && terminateOnNoiseReached) { if(guaranteeXgoodDescriptions != 1) { logger.info("Minimum number (" + guaranteeXgoodDescriptions + ") of good descriptions reached."); Modified: trunk/components-core/src/main/java/org/dllearner/core/config/BooleanEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/BooleanEditor.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/core/config/BooleanEditor.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -8,6 +8,8 @@ public class BooleanEditor implements PropertyEditor { + private Boolean value; + @Override public void addPropertyChangeListener(PropertyChangeListener listener) { // TODO Auto-generated method stub @@ -16,8 +18,7 @@ @Override public String getAsText() { - // TODO Auto-generated method stub - return null; + return value.toString(); } @Override @@ -64,8 +65,7 @@ @Override public void setAsText(String text) throws IllegalArgumentException { - // TODO Auto-generated method stub - + value = Boolean.valueOf(text); } @Override Modified: trunk/components-core/src/main/java/org/dllearner/core/configurators/ComponentFactory.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/ComponentFactory.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/ComponentFactory.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -290,9 +290,9 @@ * @throws LearningProblemUnsupportedException see * @return a component ready for initialization OCEL **/ -public static OCEL getOCEL(AbstractLearningProblem learningProblem, AbstractReasonerComponent reasoningService) throws LearningProblemUnsupportedException { -return OCELConfigurator.getOCEL(learningProblem, reasoningService); -} +//public static OCEL getOCEL(AbstractLearningProblem learningProblem, AbstractReasonerComponent reasoningService) throws LearningProblemUnsupportedException { +//return OCELConfigurator.getOCEL(learningProblem, reasoningService); +//} /** * @param learningProblem see LearningProblem Deleted: trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java 2011-08-24 09:14:11 UTC (rev 3107) +++ trunk/components-core/src/main/java/org/dllearner/core/configurators/OCELConfigurator.java 2011-08-24 09:34:32 UTC (rev 3108) @@ -1,811 +0,0 @@ -/** - * Copyright (C) 2007-2011, 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.configurators; - -import java.util.Set; -import org.dllearner.algorithms.ocel.OCEL; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractLearningProblem; -import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.configurators.RefinementOperatorConfigurator; - -/** -* automatically generated, do not edit manually. -* run org.dllearner.scripts.ConfigJavaGenerator to update -**/ -@SuppressWarnings("all") -public class OCELConfigurator extends RefinementOperatorConfigurator implements Configurator { - -private boolean reinitNecessary = false; -private OCEL oCEL; - -/** -* @param oCEL see OCEL -**/ -public OCELConfigurator(OCEL oCEL){ -this.oCEL = oCEL; -} - -/** -* @param reasoningService see reasoningService -* @param learningProblem see learningProblem -* @throws LearningProblemUnsupportedException see -* @return OCEL -**/ -public static OCEL getOCEL(AbstractLearningProblem learningProblem, AbstractReasonerComponent reasoningService) throws LearningProblemUnsupportedException{ -OCEL component = ComponentManager.getInstance().learningAlgorithm(OCEL.class, learningProblem, reasoningService); -return component; -} - -/** -* writeSearchTree specifies whether to write a search tree. -* mandatory: false| reinit necessary: true -* default value: false -* @return boolean -**/ -public boolean getWriteSearchTree() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "writeSearchTree") ; -} -/** -* searchTreeFile file to use for the search tree. -* mandatory: false| reinit necessary: true -* default value: log/searchTree.txt -* @return String -**/ -public String getSearchTreeFile() { -return (String) ComponentManager.getInstance().getConfigOptionValue(oCEL, "searchTreeFile") ; -} -/** -* replaceSearchTree specifies whether to replace the search tree in the log file after each run or append the new search tree. -* mandatory: false| reinit necessary: true -* default value: false -* @return boolean -**/ -public boolean getReplaceSearchTree() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "replaceSearchTree") ; -} -/** -* heuristic specifiy the heuristic to use. -* mandatory: false| reinit necessary: true -* default value: lexicographic -* @return String -**/ -public String getHeuristic() { -return (String) ComponentManager.getInstance().getConfigOptionValue(oCEL, "heuristic") ; -} -/** -* applyAllFilter usage of equivalence ALL R.C AND ALL R.D = ALL R.(C AND D). -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getApplyAllFilter() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "applyAllFilter") ; -} -/** -* applyExistsFilter usage of equivalence EXISTS R.C OR EXISTS R.D = EXISTS R.(C OR D). -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getApplyExistsFilter() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "applyExistsFilter") ; -} -/** -* useTooWeakList try to filter out too weak concepts without sending them to the reasoner. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseTooWeakList() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useTooWeakList") ; -} -/** -* useOverlyGeneralList try to find overly general concept without sending them to the reasoner. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseOverlyGeneralList() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useOverlyGeneralList") ; -} -/** -* useShortConceptConstruction shorten concept to see whether they already exist. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseShortConceptConstruction() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useShortConceptConstruction") ; -} -/** -* horizontalExpansionFactor horizontal expansion factor (see publication for description). -* mandatory: false| reinit necessary: true -* default value: 0.6 -* @return double -**/ -public double getHorizontalExpansionFactor() { -return (Double) ComponentManager.getInstance().getConfigOptionValue(oCEL, "horizontalExpansionFactor") ; -} -/** -* improveSubsumptionHierarchy simplify subsumption hierarchy to reduce search space (see publication for description). -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getImproveSubsumptionHierarchy() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "improveSubsumptionHierarchy") ; -} -/** -* allowedConcepts concepts the algorithm is allowed to use. -* mandatory: false| reinit necessary: true -* default value: null -* @return Set(String) -**/ -@SuppressWarnings("unchecked") -public Set<String> getAllowedConcepts() { -return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(oCEL, "allowedConcepts") ; -} -/** -* ignoredConcepts concepts the algorithm must ignore. -* mandatory: false| reinit necessary: true -* default value: null -* @return Set(String) -**/ -@SuppressWarnings("unchecked") -public Set<String> getIgnoredConcepts() { -return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(oCEL, "ignoredConcepts") ; -} -/** -* allowedRoles roles the algorithm is allowed to use. -* mandatory: false| reinit necessary: true -* default value: null -* @return Set(String) -**/ -@SuppressWarnings("unchecked") -public Set<String> getAllowedRoles() { -return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(oCEL, "allowedRoles") ; -} -/** -* ignoredRoles roles the algorithm must ignore. -* mandatory: false| reinit necessary: true -* default value: null -* @return Set(String) -**/ -@SuppressWarnings("unchecked") -public Set<String> getIgnoredRoles() { -return (Set<String>) ComponentManager.getInstance().getConfigOptionValue(oCEL, "ignoredRoles") ; -} -/** -* useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseAllConstructor() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useAllConstructor") ; -} -/** -* useExistsConstructor specifies whether the existential concept constructor is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseExistsConstructor() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useExistsConstructor") ; -} -/** -* useHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: false -* @return boolean -**/ -public boolean getUseHasValueConstructor() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useHasValueConstructor") ; -} -/** -* useDataHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm in combination with data properties. -* mandatory: false| reinit necessary: true -* default value: false -* @return boolean -**/ -public boolean getUseDataHasValueConstructor() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useDataHasValueConstructor") ; -} -/** -* valueFrequencyThreshold specifies how often an object must occur as value in order to be considered for hasValue restrictions. -* mandatory: false| reinit necessary: true -* default value: 3 -* @return int -**/ -public int getValueFrequencyThreshold() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "valueFrequencyThreshold") ; -} -/** -* useCardinalityRestrictions specifies whether CardinalityRestrictions is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseCardinalityRestrictions() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useCardinalityRestrictions") ; -} -/** -* cardinalityLimit Gives the maximum number used in cardinality restrictions.. -* mandatory: false| reinit necessary: true -* default value: 5 -* @return int -**/ -public int getCardinalityLimit() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "cardinalityLimit") ; -} -/** -* useNegation specifies whether negation is used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseNegation() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useNegation") ; -} -/** -* useBooleanDatatypes specifies whether boolean datatypes are used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseBooleanDatatypes() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useBooleanDatatypes") ; -} -/** -* useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getUseDoubleDatatypes() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useDoubleDatatypes") ; -} -/** -* useStringDatatypes specifies whether string datatypes are used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: false -* @return boolean -**/ -public boolean getUseStringDatatypes() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "useStringDatatypes") ; -} -/** -* maxExecutionTimeInSeconds algorithm will stop after specified seconds. -* mandatory: false| reinit necessary: true -* default value: 0 -* @return int -**/ -public int getMaxExecutionTimeInSeconds() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "maxExecutionTimeInSeconds") ; -} -/** -* minExecutionTimeInSeconds algorithm will run at least specified seconds. -* mandatory: false| reinit necessary: true -* default value: 0 -* @return int -**/ -public int getMinExecutionTimeInSeconds() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "minExecutionTimeInSeconds") ; -} -/** -* guaranteeXgoodDescriptions algorithm will run until X good (100%) concept descritpions are found. -* mandatory: false| reinit necessary: true -* default value: 1 -* @return int -**/ -public int getGuaranteeXgoodDescriptions() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "guaranteeXgoodDescriptions") ; -} -/** -* maxClassDescriptionTests The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.). -* mandatory: false| reinit necessary: true -* default value: 0 -* @return int -**/ -public int getMaxClassDescriptionTests() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "maxClassDescriptionTests") ; -} -/** -* logLevel determines the logLevel for this component, can be {TRACE, DEBUG, INFO}. -* mandatory: false| reinit necessary: true -* default value: DEBUG -* @return String -**/ -public String getLogLevel() { -return (String) ComponentManager.getInstance().getConfigOptionValue(oCEL, "logLevel") ; -} -/** -* usePropernessChecks specifies whether to check for equivalence (i.e. discard equivalent refinements). -* mandatory: false| reinit necessary: true -* default value: false -* @return boolean -**/ -public boolean getUsePropernessChecks() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "usePropernessChecks") ; -} -/** -* noisePercentage the (approximated) percentage of noise within the examples. -* mandatory: false| reinit necessary: true -* default value: 0.0 -* @return double -**/ -public double getNoisePercentage() { -return (Double) ComponentManager.getInstance().getConfigOptionValue(oCEL, "noisePercentage") ; -} -/** -* terminateOnNoiseReached specifies whether to terminate when noise criterion is met. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getTerminateOnNoiseReached() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "terminateOnNoiseReached") ; -} -/** -* startClass the named class which should be used to start the algorithm (GUI: needs a widget for selecting a class). -* mandatory: false| reinit necessary: true -* default value: null -* @return String -**/ -public String getStartClass() { -return (String) ComponentManager.getInstance().getConfigOptionValue(oCEL, "startClass") ; -} -/** -* forceRefinementLengthIncrease specifies whether nodes should be expanded until only longer refinements are reached. -* mandatory: false| reinit necessary: true -* default value: null -* @return boolean -**/ -public boolean getForceRefinementLengthIncrease() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "forceRefinementLengthIncrease") ; -} -/** -* negativeWeight Used to penalise errors on negative examples different from those of positive examples (lower = less importance for negatives).. -* mandatory: false| reinit necessary: true -* default value: 1.0 -* @return double -**/ -public double getNegativeWeight() { -return (Double) ComponentManager.getInstance().getConfigOptionValue(oCEL, "negativeWeight") ; -} -/** -* startNodeBonus You can use this to give a heuristic bonus on the start node (= initially broader exploration of search space).. -* mandatory: false| reinit necessary: true -* default value: 0.0 -* @return double -**/ -public double getStartNodeBonus() { -return (Double) ComponentManager.getInstance().getConfigOptionValue(oCEL, "startNodeBonus") ; -} -/** -* negationPenalty Penalty on negations (TODO: better explanation).. -* mandatory: false| reinit necessary: true -* default value: 0 -* @return int -**/ -public int getNegationPenalty() { -return (Integer) ComponentManager.getInstance().getConfigOptionValue(oCEL, "negationPenalty") ; -} -/** -* expansionPenaltyFactor describes the reduction in heuristic score one is willing to accept for reducing the length of the concept by one. -* mandatory: false| reinit necessary: true -* default value: 0.02 -* @return double -**/ -public double getExpansionPenaltyFactor() { -return (Double) ComponentManager.getInstance().getConfigOptionValue(oCEL, "expansionPenaltyFactor") ; -} -/** -* instanceBasedDisjoints Specifies whether to use real disjointness checks or instance based ones (no common instances) in the refinement operator.. -* mandatory: false| reinit necessary: true -* default value: true -* @return boolean -**/ -public boolean getInstanceBasedDisjoints() { -return (Boolean) ComponentManager.getInstance().getConfigOptionValue(oCEL, "instanceBasedDisjoints") ; -} - -/** -* @param writeSearchTree specifies whether to write a search tree. -* mandatory: false| reinit necessary: true -* default value: false -**/ -public void setWriteSearchTree(boolean writeSearchTree) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "writeSearchTree", writeSearchTree); -reinitNecessary = true; -} -/** -* @param searchTreeFile file to use for the search tree. -* mandatory: false| reinit necessary: true -* default value: log/searchTree.txt -**/ -public void setSearchTreeFile(String searchTreeFile) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "searchTreeFile", searchTreeFile); -reinitNecessary = true; -} -/** -* @param replaceSearchTree specifies whether to replace the search tree in the log file after each run or append the new search tree. -* mandatory: false| reinit necessary: true -* default value: false -**/ -public void setReplaceSearchTree(boolean replaceSearchTree) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "replaceSearchTree", replaceSearchTree); -reinitNecessary = true; -} -/** -* @param heuristic specifiy the heuristic to use. -* mandatory: false| reinit necessary: true -* default value: lexicographic -**/ -public void setHeuristic(String heuristic) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "heuristic", heuristic); -reinitNecessary = true; -} -/** -* @param applyAllFilter usage of equivalence ALL R.C AND ALL R.D = ALL R.(C AND D). -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setApplyAllFilter(boolean applyAllFilter) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "applyAllFilter", applyAllFilter); -reinitNecessary = true; -} -/** -* @param applyExistsFilter usage of equivalence EXISTS R.C OR EXISTS R.D = EXISTS R.(C OR D). -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setApplyExistsFilter(boolean applyExistsFilter) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "applyExistsFilter", applyExistsFilter); -reinitNecessary = true; -} -/** -* @param useTooWeakList try to filter out too weak concepts without sending them to the reasoner. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseTooWeakList(boolean useTooWeakList) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useTooWeakList", useTooWeakList); -reinitNecessary = true; -} -/** -* @param useOverlyGeneralList try to find overly general concept without sending them to the reasoner. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseOverlyGeneralList(boolean useOverlyGeneralList) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useOverlyGeneralList", useOverlyGeneralList); -reinitNecessary = true; -} -/** -* @param useShortConceptConstruction shorten concept to see whether they already exist. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseShortConceptConstruction(boolean useShortConceptConstruction) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useShortConceptConstruction", useShortConceptConstruction); -reinitNecessary = true; -} -/** -* @param horizontalExpansionFactor horizontal expansion factor (see publication for description). -* mandatory: false| reinit necessary: true -* default value: 0.6 -**/ -public void setHorizontalExpansionFactor(double horizontalExpansionFactor) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "horizontalExpansionFactor", horizontalExpansionFactor); -reinitNecessary = true; -} -/** -* @param improveSubsumptionHierarchy simplify subsumption hierarchy to reduce search space (see publication for description). -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setImproveSubsumptionHierarchy(boolean improveSubsumptionHierarchy) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "improveSubsumptionHierarchy", improveSubsumptionHierarchy); -reinitNecessary = true; -} -/** -* @param allowedConcepts concepts the algorithm is allowed to use. -* mandatory: false| reinit necessary: true -* default value: null -**/ -public void setAllowedConcepts(Set<String> allowedConcepts) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "allowedConcepts", allowedConcepts); -reinitNecessary = true; -} -/** -* @param ignoredConcepts concepts the algorithm must ignore. -* mandatory: false| reinit necessary: true -* default value: null -**/ -public void setIgnoredConcepts(Set<String> ignoredConcepts) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "ignoredConcepts", ignoredConcepts); -reinitNecessary = true; -} -/** -* @param allowedRoles roles the algorithm is allowed to use. -* mandatory: false| reinit necessary: true -* default value: null -**/ -public void setAllowedRoles(Set<String> allowedRoles) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "allowedRoles", allowedRoles); -reinitNecessary = true; -} -/** -* @param ignoredRoles roles the algorithm must ignore. -* mandatory: false| reinit necessary: true -* default value: null -**/ -public void setIgnoredRoles(Set<String> ignoredRoles) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "ignoredRoles", ignoredRoles); -reinitNecessary = true; -} -/** -* @param useAllConstructor specifies whether the universal concept constructor is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseAllConstructor(boolean useAllConstructor) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useAllConstructor", useAllConstructor); -reinitNecessary = true; -} -/** -* @param useExistsConstructor specifies whether the existential concept constructor is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseExistsConstructor(boolean useExistsConstructor) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useExistsConstructor", useExistsConstructor); -reinitNecessary = true; -} -/** -* @param useHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: false -**/ -public void setUseHasValueConstructor(boolean useHasValueConstructor) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useHasValueConstructor", useHasValueConstructor); -reinitNecessary = true; -} -/** -* @param useDataHasValueConstructor specifies whether the hasValue constructor is used in the learning algorithm in combination with data properties. -* mandatory: false| reinit necessary: true -* default value: false -**/ -public void setUseDataHasValueConstructor(boolean useDataHasValueConstructor) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useDataHasValueConstructor", useDataHasValueConstructor); -reinitNecessary = true; -} -/** -* @param valueFrequencyThreshold specifies how often an object must occur as value in order to be considered for hasValue restrictions. -* mandatory: false| reinit necessary: true -* default value: 3 -**/ -public void setValueFrequencyThreshold(int valueFrequencyThreshold) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "valueFrequencyThreshold", valueFrequencyThreshold); -reinitNecessary = true; -} -/** -* @param useCardinalityRestrictions specifies whether CardinalityRestrictions is used in the learning algorithm. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseCardinalityRestrictions(boolean useCardinalityRestrictions) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useCardinalityRestrictions", useCardinalityRestrictions); -reinitNecessary = true; -} -/** -* @param cardinalityLimit Gives the maximum number used in cardinality restrictions.. -* mandatory: false| reinit necessary: true -* default value: 5 -**/ -public void setCardinalityLimit(int cardinalityLimit) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "cardinalityLimit", cardinalityLimit); -reinitNecessary = true; -} -/** -* @param useNegation specifies whether negation is used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseNegation(boolean useNegation) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useNegation", useNegation); -reinitNecessary = true; -} -/** -* @param useBooleanDatatypes specifies whether boolean datatypes are used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseBooleanDatatypes(boolean useBooleanDatatypes) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useBooleanDatatypes", useBooleanDatatypes); -reinitNecessary = true; -} -/** -* @param useDoubleDatatypes specifies whether double datatypes are used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: true -**/ -public void setUseDoubleDatatypes(boolean useDoubleDatatypes) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useDoubleDatatypes", useDoubleDatatypes); -reinitNecessary = true; -} -/** -* @param useStringDatatypes specifies whether string datatypes are used in the learning algorothm. -* mandatory: false| reinit necessary: true -* default value: false -**/ -public void setUseStringDatatypes(boolean useStringDatatypes) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "useStringDatatypes", useStringDatatypes); -reinitNecessary = true; -} -/** -* @param maxExecutionTimeInSeconds algorithm will stop after specified seconds. -* mandatory: false| reinit necessary: true -* default value: 0 -**/ -public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); -reinitNecessary = true; -} -/** -* @param minExecutionTimeInSeconds algorithm will run at least specified seconds. -* mandatory: false| reinit necessary: true -* default value: 0 -**/ -public void setMinExecutionTimeInSeconds(int minExecutionTimeInSeconds) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "minExecutionTimeInSeconds", minExecutionTimeInSeconds); -reinitNecessary = true; -} -/** -* @param guaranteeXgoodDescriptions algorithm will run until X good (100%) concept descritpions are found. -* mandatory: false| reinit necessary: true -* default value: 1 -**/ -public void setGuaranteeXgoodDescriptions(int guaranteeXgoodDescriptions) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "guaranteeXgoodDescriptions", guaranteeXgoodDescriptions); -reinitNecessary = true; -} -/** -* @param maxClassDescriptionTests The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.). -* mandatory: false| reinit necessary: true -* default value: 0 -**/ -public void setMaxClassDescriptionTests(int maxClassDescriptionTests) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "maxClassDescriptionTests", maxClassDescriptionTests); -reinitNecessary = true; -} -/** -* @param logLevel determines the logLevel for this component, can be {TRACE, DEBUG, INFO}. -* mandatory: false| reinit necessary: true -* default value: DEBUG -**/ -public void setLogLevel(String logLevel) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "logLevel", logLevel); -reinitNecessary = true; -} -/** -* @param usePropernessChecks specifies whether to check for equivalence (i.e. discard equivalent refinements). -* mandatory: false| reinit necessary: true -* default value: false -**/ -public void setUsePropernessChecks(boolean usePropernessChecks) { -ComponentManager.getInstance().applyConfigEntry(oCEL, "usePropernessChecks", usePropernessChecks); -reinitNecessary = true; -} -/** -* @param noisePercentage the (approximated) percentage of noise within the examples. -* mandatory: false| rein... [truncated message content] |
From: <jen...@us...> - 2011-08-24 14:38:16
|
Revision: 3116 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3116&view=rev Author: jenslehmann Date: 2011-08-24 14:38:09 +0000 (Wed, 24 Aug 2011) Log Message: ----------- prepared rho refinement operator and OCEL heuristic for usage as components Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/examples/family/father.conf Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -37,6 +37,7 @@ import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.configurators.CELOEConfigurator; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -21,6 +21,12 @@ import java.util.List; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DoubleEditor; +import org.dllearner.core.config.IntegerEditor; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Negation; @@ -66,19 +72,32 @@ * @author Jens Lehmann * */ -public class MultiHeuristic implements ExampleBasedHeuristic { +@ComponentAnn(name = "multiple criteria heuristic", shortName = "multiheuristic", version = 0.7) +public class MultiHeuristic implements ExampleBasedHeuristic, Component { private ConceptComparator conceptComparator = new ConceptComparator(); // private OCELConfigurator configurator; // heuristic parameters + + @ConfigOption(name = "expansionPenaltyFactor", defaultValue="0.02", propertyEditorClass = DoubleEditor.class) private double expansionPenaltyFactor = 0.02; + + @ConfigOption(name = "gainBonusFactor", defaultValue="0.5", propertyEditorClass = DoubleEditor.class) private double gainBonusFactor = 0.5; + + @ConfigOption(name = "nodeChildPenalty", defaultValue="0.0001", propertyEditorClass = DoubleEditor.class) private double nodeChildPenalty = 0.0001; // (use higher values than 0.0001 for simple learning problems); + + @ConfigOption(name = "startNodeBonus", defaultValue="0.1", propertyEditorClass = DoubleEditor.class) private double startNodeBonus = 0.1; //was 2.0 + // penalise errors on positive examples harder than on negative examples // (positive weight = 1) + @ConfigOption(name = "negativeWeight", defaultValue="1.0", propertyEditorClass = DoubleEditor.class) private double negativeWeight = 1.0; // was 0.8; + + @ConfigOption(name = "negationPenalty", defaultValue="0", propertyEditorClass = IntegerEditor.class) private int negationPenalty = 0; // examples @@ -108,6 +127,10 @@ // this.gainBonusFactor = gainBonusFactor; // } + @Override + public void init() throws ComponentInitException { + // nothing to do here + } /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) @@ -180,4 +203,5 @@ } return bonus; } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -31,6 +31,7 @@ import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigMappings; @@ -79,6 +80,7 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "OWL Class Expression Learner", shortName = "ocel", version = 1.2) public class OCEL extends AbstractCELA { // private OCELConfigurator configurator; @@ -91,14 +93,17 @@ private ROLearner2 algorithm; private static Logger logger = Logger.getLogger(OCEL.class); private String logLevel = CommonConfigOptions.logLevelDefault; - RhoDRDown operator; - + + // dependencies + private RhoDRDown operator; + private ExampleBasedHeuristic heuristic; + // configuration options private boolean writeSearchTree; private File searchTreeFile; private boolean replaceSearchTree = false; private static String defaultSearchTreeFile = "log/searchTree.txt"; - private String heuristic = "multi"; + private String heuristicStr = "multi"; Set<NamedClass> allowedConcepts; Set<ObjectProperty> allowedRoles; Set<NamedClass> ignoredConcepts; @@ -244,9 +249,9 @@ else if(name.equals("heuristic")) { String value = (String) entry.getValue(); if(value.equals("lexicographic")) - heuristic = "lexicographic"; + heuristicStr = "lexicographic"; else - heuristic = "flexible"; + heuristicStr = "flexible"; } else if(name.equals("allowedConcepts")) { allowedConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); } else if(name.equals("allowedRoles")) { @@ -328,21 +333,21 @@ Files.clearFile(searchTreeFile); // adjust heuristic - ExampleBasedHeuristic algHeuristic; + - if(heuristic == "lexicographic") - algHeuristic = new LexicographicHeuristic(); - else if(heuristic == "flexible") { + if(heuristicStr == "lexicographic") + heuristic = new LexicographicHeuristic(); + else if(heuristicStr == "flexible") { if(learningProblem instanceof PosOnlyLP) { throw new RuntimeException("does not work with positive examples only yet"); } - algHeuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); + heuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); } else { if(learningProblem instanceof PosOnlyLP) { // throw new RuntimeException("does not work with positive examples only yet"); - algHeuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); + heuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } else { - algHeuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); + heuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); } } @@ -424,7 +429,7 @@ learningProblem, reasoner, operator, - algHeuristic, + heuristic, startClass, // usedConcepts, // usedRoles, @@ -548,11 +553,11 @@ } public String getHeuristic() { - return heuristic; + return heuristicStr; } public void setHeuristic(String heuristic) { - this.heuristic = heuristic; + this.heuristicStr = heuristic; } public Set<NamedClass> getAllowedConcepts() { @@ -842,4 +847,8 @@ public void setTerminateOnNoiseReached(boolean terminateOnNoiseReached) { this.terminateOnNoiseReached = terminateOnNoiseReached; } + + public void setHeuristic(ExampleBasedHeuristic heuristic) { + this.heuristic = heuristic; + } } Added: trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/DoubleEditor.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -0,0 +1,83 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; + +public class DoubleEditor implements PropertyEditor { + + private Double value; + + @Override + public void addPropertyChangeListener(PropertyChangeListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public String getAsText() { + return value.toString(); + } + + @Override + public Component getCustomEditor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getJavaInitializationString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getTags() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isPaintable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void paintValue(Graphics arg0, Rectangle arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = Double.valueOf(text); + } + + @Override + public void setValue(Object arg0) { + // TODO Auto-generated method stub + + } + + @Override + public boolean supportsCustomEditor() { + // TODO Auto-generated method stub + return false; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -63,8 +63,10 @@ // and class instances to positive examples) @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false, propertyEditorClass = DoubleEditor.class) private double approxDelta = 0.05; + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false, propertyEditorClass = BoolEditor.class) private boolean useApproximations; + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) private String accuracyMethod = "predacc"; Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2011-08-24 14:38:09 UTC (rev 3116) @@ -35,6 +35,10 @@ import org.apache.log4j.Logger; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.configurators.RefinementOperatorConfigurator; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.owl.BooleanValueRestriction; @@ -84,12 +88,13 @@ * @author Jens Lehmann * */ -public class RhoDRDown extends RefinementOperatorAdapter { +@ComponentAnn(name = "rho refinement operator", shortName = "rho", version = 0.8) +public class RhoDRDown extends RefinementOperatorAdapter implements Component { private static Logger logger = Logger .getLogger(RhoDRDown.class); - private AbstractReasonerComponent rs; + private AbstractReasonerComponent reasoner; // hierarchies private ClassHierarchy subHierarchy; @@ -164,24 +169,47 @@ private Map<DatatypeProperty, Map<Constant, Integer>> dataValueFrequency = new HashMap<DatatypeProperty, Map<Constant, Integer>>(); private boolean useDataHasValueConstructor = false; - // staistics + // statistics public long mComputationTimeNs = 0; public long topComputationTimeNs = 0; + @ConfigOption(name = "applyAllFilter", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean applyAllFilter = true; + + @ConfigOption(name = "applyExistsFilter", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean applyExistsFilter = true; + + @ConfigOption(name = "useAllConstructor", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useAllConstructor = true; + + @ConfigOption(name = "useExistsConstructor", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useExistsConstructor = true; + + @ConfigOption(name = "useHasValueConstructor", defaultValue="false", propertyEditorClass = BooleanEditor.class) private boolean useHasValueConstructor = false; + + @ConfigOption(name = "useCardinalityRestrictions", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useCardinalityRestrictions = true; + + @ConfigOption(name = "useNegation", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useNegation = true; + + @ConfigOption(name = "useBooleanDatatypes", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useBooleanDatatypes = true; + + @ConfigOption(name = "useDoubleDatatypes", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean useDoubleDatatypes = true; - @SuppressWarnings("unused") + + @ConfigOption(name = "useStringDatatypes", defaultValue="false", propertyEditorClass = BooleanEditor.class) private boolean useStringDatatypes = false; + + @ConfigOption(name = "disjointChecks", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean disjointChecks = true; + + @ConfigOption(name = "instanceBasedDisjoints", defaultValue="true", propertyEditorClass = BooleanEditor.class) private boolean instanceBasedDisjoints = true; + @ConfigOption(name = "dropDisjuncts", defaultValue="false", propertyEditorClass = BooleanEditor.class) private boolean dropDisjuncts = false; // caches for reasoner queries @@ -191,15 +219,19 @@ // private Map<NamedClass,Map<NamedClass,Boolean>> notABDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); // private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); + public RhoDRDown() { + + } + public RhoDRDown(AbstractReasonerComponent reasoningService) { // this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null); - this.rs = reasoningService; - this.subHierarchy = rs.getClassHierarchy(); + this.reasoner = reasoningService; + this.subHierarchy = reasoner.getClassHierarchy(); init(); } public RhoDRDown(AbstractReasonerComponent reasoner, ClassHierarchy subHierarchy, Description startClass, RefinementOperatorConfigurator configurator) { - this.rs = reasoner; + this.reasoner = reasoner; this.subHierarchy = subHierarchy; this.startClass = startClass; useAllConstructor = configurator.getUseAllConstructor(); @@ -223,7 +255,7 @@ public RhoDRDown(AbstractReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass, int cardinalityLimit, boolean useStringDatatypes, boolean instanceBasedDisjoints) { - this.rs = reasoningService; + this.reasoner = reasoningService; this.subHierarchy = subHierarchy; this.applyAllFilter = applyAllFilter; this.applyExistsFilter = applyExistsFilter; @@ -248,9 +280,9 @@ public void init() { // query reasoner for domains and ranges // (because they are used often in the operator) - for(ObjectProperty op : rs.getObjectProperties()) { - opDomains.put(op, rs.getDomain(op)); - opRanges.put(op, rs.getRange(op)); + for(ObjectProperty op : reasoner.getObjectProperties()) { + opDomains.put(op, reasoner.getDomain(op)); + opRanges.put(op, reasoner.getRange(op)); if(useHasValueConstructor) { // init @@ -258,7 +290,7 @@ valueFrequency.put(op, opMap); // sets ordered by corresponding individual (which we ignore) - Collection<SortedSet<Individual>> fillerSets = rs.getPropertyMembers(op).values(); + Collection<SortedSet<Individual>> fillerSets = reasoner.getPropertyMembers(op).values(); for(SortedSet<Individual> fillerSet : fillerSets) { for(Individual i : fillerSet) { // System.out.println("op " + op + " i " + i); @@ -286,15 +318,15 @@ } - for(DatatypeProperty dp : rs.getDatatypeProperties()) { - dpDomains.put(dp, rs.getDomain(dp)); + for(DatatypeProperty dp : reasoner.getDatatypeProperties()) { + dpDomains.put(dp, reasoner.getDomain(dp)); if(useDataHasValueConstructor) { Map<Constant, Integer> dpMap = new TreeMap<Constant, Integer>(); dataValueFrequency.put(dp, dpMap); // sets ordered by corresponding individual (which we ignore) - Collection<SortedSet<Constant>> fillerSets = rs.getDatatypeMembers(dp).values(); + Collection<SortedSet<Constant>> fillerSets = reasoner.getDatatypeMembers(dp).values(); for(SortedSet<Constant> fillerSet : fillerSets) { for(Constant i : fillerSet) { // System.out.println("op " + op + " i " + i); @@ -326,16 +358,16 @@ dataValueFrequency = null; // compute splits for double datatype properties - for(DatatypeProperty dp : rs.getDoubleDatatypeProperties()) { + for(DatatypeProperty dp : reasoner.getDoubleDatatypeProperties()) { computeSplits(dp); } // determine the maximum number of fillers for each role // (up to a specified cardinality maximum) if(useCardinalityRestrictions) { - for(ObjectProperty op : rs.getObjectProperties()) { + for(ObjectProperty op : reasoner.getObjectProperties()) { int maxFillers = 0; - Map<Individual,SortedSet<Individual>> opMembers = rs.getPropertyMembers(op); + Map<Individual,SortedSet<Individual>> opMembers = reasoner.getPropertyMembers(op); for(SortedSet<Individual> inds : opMembers.values()) { if(inds.size()>maxFillers) maxFillers = inds.size(); @@ -543,7 +575,7 @@ // rule 2: EXISTS r.D => EXISTS s.D or EXISTS r^-1.D => EXISTS s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = rs.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) refinements.add(new ObjectSomeRestriction(moreSpecialRole, description.getChild(0))); @@ -587,7 +619,7 @@ // rule 3: ALL r.D => ALL s.D or ALL r^-1.D => ALL s^-1.D // currently inverse roles are not supported ObjectProperty ar = (ObjectProperty) role; - Set<ObjectProperty> moreSpecialRoles = rs.getSubProperties(ar); + Set<ObjectProperty> moreSpecialRoles = reasoner.getSubProperties(ar); for(ObjectProperty moreSpecialRole : moreSpecialRoles) { refinements.add(new ObjectAllRestriction(moreSpecialRole, description.getChild(0))); } @@ -666,7 +698,7 @@ } else if (description instanceof StringValueRestriction) { StringValueRestriction svr = (StringValueRestriction) description; DatatypeProperty dp = svr.getRestrictedPropertyExpression(); - Set<DatatypeProperty> subDPs = rs.getSubProperties(dp); + Set<DatatypeProperty> subDPs = reasoner.getSubProperties(dp); for(DatatypeProperty subDP : subDPs) { refinements.add(new StringValueRestriction(subDP, svr.getStringValue())); } @@ -967,7 +999,7 @@ // boolean datatypes, e.g. testPositive = true if(useBooleanDatatypes) { - Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> booleanDPs = reasoner.getBooleanDatatypeProperties(); for(DatatypeProperty dp : booleanDPs) { m2.add(new BooleanValueRestriction(dp,true)); m2.add(new BooleanValueRestriction(dp,false)); @@ -978,7 +1010,7 @@ SortedSet<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { // only uses most general roles - for(ObjectProperty r : rs.getMostGeneralProperties()) { + for(ObjectProperty r : reasoner.getMostGeneralProperties()) { m3.add(new ObjectSomeRestriction(r, new Thing())); } } @@ -987,13 +1019,13 @@ // we allow \forall r.\top here because otherwise the operator // becomes too difficult to manage due to dependencies between // M_A and M_A' where A'=ran(r) - for(ObjectProperty r : rs.getMostGeneralProperties()) { + for(ObjectProperty r : reasoner.getMostGeneralProperties()) { m3.add(new ObjectAllRestriction(r, new Thing())); } } if(useDoubleDatatypes) { - Set<DatatypeProperty> doubleDPs = rs.getDoubleDatatypeProperties(); + Set<DatatypeProperty> doubleDPs = reasoner.getDoubleDatatypeProperties(); for(DatatypeProperty dp : doubleDPs) { if(splits.get(dp).size()>0) { DoubleMaxValue max = new DoubleMaxValue(splits.get(dp).get(splits.get(dp).size()-1)); @@ -1005,7 +1037,7 @@ } if(useDataHasValueConstructor) { - Set<DatatypeProperty> stringDPs = rs.getStringDatatypeProperties(); + Set<DatatypeProperty> stringDPs = reasoner.getStringDatatypeProperties(); for(DatatypeProperty dp : stringDPs) { // loop over frequent values Set<Constant> freqValues = frequentDataValues.get(dp); @@ -1019,7 +1051,7 @@ SortedSet<Description> m4 = new TreeSet<Description>(conceptComparator); if(useCardinalityRestrictions) { - for(ObjectProperty r : rs.getMostGeneralProperties()) { + for(ObjectProperty r : reasoner.getMostGeneralProperties()) { int maxFillers = maxNrOfFillers.get(r); // zero fillers: <= -1 r.C does not make sense // one filler: <= 0 r.C is equivalent to NOT EXISTS r.C, @@ -1199,8 +1231,8 @@ if(instanceBasedDisjoints) { // bug: tests should be performed against the index, not the upper class // SortedSet<Individual> tmp = rs.getIndividuals(upperClass); - SortedSet<Individual> tmp = rs.getIndividuals(index); - tmp.removeAll(rs.getIndividuals(candidate)); + SortedSet<Individual> tmp = reasoner.getIndividuals(index); + tmp.removeAll(reasoner.getIndividuals(candidate)); // System.out.println(" instances of " + index + " and not " + candidate + ": " + tmp.size()); meaningful = tmp.size() != 0; } else { @@ -1242,8 +1274,8 @@ boolean meaningful; // System.out.println("not disjoint"); if(instanceBasedDisjoints) { - SortedSet<Individual> tmp = rs.getIndividuals(index); - tmp.removeAll(rs.getIndividuals(new Negation(candidate))); + SortedSet<Individual> tmp = reasoner.getIndividuals(index); + tmp.removeAll(reasoner.getIndividuals(new Negation(candidate))); meaningful = tmp.size() != 0; // System.out.println("instances " + tmp.size()); } else { @@ -1272,14 +1304,14 @@ mgdd.put(domain, new TreeSet<DatatypeProperty>()); mgsd.put(domain, new TreeSet<DatatypeProperty>()); - SortedSet<ObjectProperty> mostGeneral = rs.getMostGeneralProperties(); + SortedSet<ObjectProperty> mostGeneral = reasoner.getMostGeneralProperties(); computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); - SortedSet<DatatypeProperty> mostGeneralDP = rs.getMostGeneralDatatypeProperties(); + SortedSet<DatatypeProperty> mostGeneralDP = reasoner.getMostGeneralDatatypeProperties(); // we make the (reasonable) assumption here that all sub and super // datatype properties have the same type (e.g. boolean, integer, double) - Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, rs.getBooleanDatatypeProperties()); - Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, rs.getDoubleDatatypeProperties()); - Set<DatatypeProperty> mostGeneralSDP = Helper.intersection(mostGeneralDP, rs.getStringDatatypeProperties()); + Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, reasoner.getBooleanDatatypeProperties()); + Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, reasoner.getDoubleDatatypeProperties()); + Set<DatatypeProperty> mostGeneralSDP = Helper.intersection(mostGeneralDP, reasoner.getStringDatatypeProperties()); computeMgbdRecursive(domain, mostGeneralBDP, mgbd.get(domain)); computeMgddRecursive(domain, mostGeneralDDP, mgdd.get(domain)); computeMgsdRecursive(domain, mostGeneralSDP, mgsd.get(domain)); @@ -1290,7 +1322,7 @@ if(appOP.get(domain).contains(prop)) mgrTmp.add(prop); else - computeMgrRecursive(domain, rs.getSubProperties(prop), mgrTmp); + computeMgrRecursive(domain, reasoner.getSubProperties(prop), mgrTmp); } } @@ -1299,7 +1331,7 @@ if(appBD.get(domain).contains(prop)) mgbdTmp.add(prop); else - computeMgbdRecursive(domain, rs.getSubProperties(prop), mgbdTmp); + computeMgbdRecursive(domain, reasoner.getSubProperties(prop), mgbdTmp); } } @@ -1308,7 +1340,7 @@ if(appDD.get(domain).contains(prop)) mgddTmp.add(prop); else - computeMgddRecursive(domain, rs.getSubProperties(prop), mgddTmp); + computeMgddRecursive(domain, reasoner.getSubProperties(prop), mgddTmp); } } @@ -1317,41 +1349,41 @@ if(appDD.get(domain).contains(prop)) mgsdTmp.add(prop); else - computeMgsdRecursive(domain, rs.getSubProperties(prop), mgsdTmp); + computeMgsdRecursive(domain, reasoner.getSubProperties(prop), mgsdTmp); } } // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { // object properties - Set<ObjectProperty> mostGeneral = rs.getObjectProperties(); + Set<ObjectProperty> mostGeneral = reasoner.getObjectProperties(); Set<ObjectProperty> applicableRoles = new TreeSet<ObjectProperty>(); for(ObjectProperty role : mostGeneral) { // TODO: currently we just rely on named classes as roles, // instead of computing dom(r) and ran(r) - Description d = rs.getDomain(role); + Description d = reasoner.getDomain(role); if(!isDisjoint(domain,d)) applicableRoles.add(role); } appOP.put(domain, applicableRoles); // boolean datatype properties - Set<DatatypeProperty> mostGeneralBDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> mostGeneralBDPs = reasoner.getBooleanDatatypeProperties(); Set<DatatypeProperty> applicableBDPs = new TreeSet<DatatypeProperty>(); for(DatatypeProperty role : mostGeneralBDPs) { // Description d = (NamedClass) rs.getDomain(role); - Description d = rs.getDomain(role); + Description d = reasoner.getDomain(role); if(!isDisjoint(domain,d)) applicableBDPs.add(role); } appBD.put(domain, applicableBDPs); // double datatype properties - Set<DatatypeProperty> mostGeneralDDPs = rs.getDoubleDatatypeProperties(); + Set<DatatypeProperty> mostGeneralDDPs = reasoner.getDoubleDatatypeProperties(); Set<DatatypeProperty> applicableDDPs = new TreeSet<DatatypeProperty>(); for(DatatypeProperty role : mostGeneralDDPs) { // Description d = (NamedClass) rs.getDomain(role); - Description d = rs.getDomain(role); + Description d = reasoner.getDomain(role); // System.out.println("domain: " + d); if(!isDisjoint(domain,d)) applicableDDPs.add(role); @@ -1400,7 +1432,7 @@ result = isDisjointInstanceBased(d1,d2); } else { Description d = new Intersection(d1, d2); - result = rs.isSuperClassOf(new Nothing(), d); + result = reasoner.isSuperClassOf(new Nothing(), d); } // add the result to the cache (we add it twice such that // the order of access does not matter) @@ -1427,8 +1459,8 @@ } private boolean isDisjointInstanceBased(Description d1, Description d2) { - SortedSet<Individual> d1Instances = rs.getIndividuals(d1); - SortedSet<Individual> d2Instances = rs.getIndividuals(d2); + SortedSet<Individual> d1Instances = reasoner.getIndividuals(d1); + SortedSet<Individual> d2Instances = reasoner.getIndividuals(d2); // System.out.println(d1 + " " + d2); // System.out.println(d1 + " " + d1Instances); // System.out.println(d2 + " " + d2Instances); @@ -1459,7 +1491,7 @@ // if(tmp2==null) { Description notA = new Negation(a); Description d = new Intersection(notA, b); - Boolean result = rs.isSuperClassOf(new Nothing(), d); + Boolean result = reasoner.isSuperClassOf(new Nothing(), d); // ... add to cache ... return result; // } else @@ -1474,13 +1506,13 @@ Description notA = new Negation(a); Description d = new Intersection(notA, b); // check b subClassOf b AND NOT A (if yes then it is not meaningful) - return !rs.isSuperClassOf(d, b); + return !reasoner.isSuperClassOf(d, b); } private void computeSplits(DatatypeProperty dp) { Set<Double> valuesSet = new TreeSet<Double>(); // Set<Individual> individuals = rs.getIndividuals(); - Map<Individual,SortedSet<Double>> valueMap = rs.getDoubleDatatypeMembers(dp); + Map<Individual,SortedSet<Double>> valueMap = reasoner.getDoubleDatatypeMembers(dp); // add all values to the set (duplicates will be remove automatically) for(Entry<Individual,SortedSet<Double>> e : valueMap.entrySet()) valuesSet.addAll(e.getValue()); @@ -1507,4 +1539,108 @@ // System.out.println(splits); // System.exit(0); } + + public int getFrequencyThreshold() { + return frequencyThreshold; + } + + public void setFrequencyThreshold(int frequencyThreshold) { + this.frequencyThreshold = frequencyThreshold; + } + + public boolean isUseDataHasValueConstructor() { + return useDataHasValueConstructor; + } + + public void setUseDataHasValueConstructor(boolean useDataHasValueConstructor) { + this.useDataHasValueConstructor = useDataHasValueConstructor; + } + + public boolean isApplyAllFilter() { + return applyAllFilter; + } + + public void setApplyAllFilter(boolean applyAllFilter) { + this.applyAllFilter = applyAllFilter; + } + + public boolean isUseAllConstructor() { + return useAllConstructor; + } + + public void setUseAllConstructor(boolean useAllConstructor) { + this.useAllConstructor = useAllConstructor; + } + + public boolean isUseExistsConstructor() { + return useExistsConstructor; + } + + public void setUseExistsConstructor(boolean useExistsConstructor) { + this.useExistsConstructor = useExistsConstructor; + } + + public boolean isUseHasValueConstructor() { + return useHasValueConstructor; + } + + public void setUseHasValueConstructor(boolean useHasValueConstructor) { + this.useHasValueConstructor = useHasValueConstructor; + } + + public boolean isUseCardinalityRestrictions() { + return useCardinalityRestrictions; + } + + public void setUseCardinalityRestrictions(boolean useCardinalityRestrictions) { + this.useCardinalityRestrictions = useCardinalityRestrictions; + } + + public boolean isUseNegation() { + return useNegation; + } + + public void setUseNegation(boolean useNegation) { + this.useNegation = useNegation; + } + + public boolean isUseBooleanDatatypes() { + return useBooleanDatatypes; + } + + public void setUseBooleanDatatypes(boolean useBooleanDatatypes) { + this.useBooleanDatatypes = useBooleanDatatypes; + } + + public boolean isUseDoubleDatatypes() { + return useDoubleDatatypes; + } + + public void setUseDoubleDatatypes(boolean useDoubleDatatypes) { + this.useDoubleDatatypes = useDoubleDatatypes; + } + + public boolean isUseStringDatatypes() { + return useStringDatatypes; + } + + public void setUseStringDatatypes(boolean useStringDatatypes) { + this.useStringDatatypes = useStringDatatypes; + } + + public boolean isInstanceBasedDisjoints() { + return instanceBasedDisjoints; + } + + public void setInstanceBasedDisjoints(boolean instanceBasedDisjoints) { + this.instanceBasedDisjoints = instanceBasedDisjoints; + } + + public AbstractReasonerComponent getReasoner() { + return reasoner; + } + + public void setReasoner(AbstractReasonerComponent reasoner) { + this.reasoner = reasoner; + } } \ No newline at end of file Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-24 14:28:03 UTC (rev 3115) +++ trunk/examples/family/father.conf 2011-08-24 14:38:09 UTC (rev 3116) @@ -10,7 +10,7 @@ // knowledge source definition ks.type = "KB file"; ks.url = "father.kb"; -ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. // reasoner reasoner.type = "fast instance checker"; @@ -20,6 +20,25 @@ embeddedReasoner.sources = {"component:kbFile"}; // learning problem -learningProblem.type = "posNegStandard"; -learningProblem.positiveExamples = {"stefan","markus","bernd"}; -learningProblem.negativeExamples = {"heinz","anna","gabi","michelle"}; +lp.type = "posNegStandard"; +lp.positiveExamples = {"stefan","markus","bernd"}; +lp.negativeExamples = {"heinz","anna","gabi","michelle"}; + +// TODO: the stuff below is untested and just shows what it could look like + +// plug a reasoner into the learning problem +lp.reasoner = reasoner; + +// create a refinement operator and configure it +op.type = "rho"; +op.useCardinalityRestrictions = true; + +// create a heuristic and configure it +h.type = "multiheuristic"; +h.expansionPenaltyFactor = 0.2; + +// create learning algorithm to run +alg.type = "ocel"; +alg.operator = component:op; +alg.learningProblem = component:lp; +alg.heuristic = component:h; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-25 08:06:52
|
Revision: 3118 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3118&view=rev Author: jenslehmann Date: 2011-08-25 08:06:45 +0000 (Thu, 25 Aug 2011) Log Message: ----------- modified new CLI parser such that it does not require semicolons anymore Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/examples/family/father.conf trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-24 18:37:17 UTC (rev 3117) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-25 08:06:45 UTC (rev 3118) @@ -711,7 +711,7 @@ stop || (configurator.getMaxClassDescriptionTests() != 0 && (expressionTests >= configurator.getMaxClassDescriptionTests())) || (configurator.getMaxExecutionTimeInSeconds() != 0 && ((System.nanoTime() - nanoStartTime) >= (configurator.getMaxExecutionTimeInSeconds()*1000000000l))) || - (configurator.getTerminateOnNoiseReached() && (100*getCurrentlyBestAccuracy()>100-configurator.getNoisePercentage())); + (configurator.getTerminateOnNoiseReached() && (100*getCurrentlyBestAccuracy()>=100-configurator.getNoisePercentage())); } private void reset() { Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-24 18:37:17 UTC (rev 3117) +++ trunk/examples/family/father.conf 2011-08-25 08:06:45 UTC (rev 3118) @@ -8,37 +8,38 @@ */ // knowledge source definition -ks.type = "KB file"; -ks.url = "father.kb"; +ks.type = "KB file" +ks.url = "father.kb" // ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. // reasoner -reasoner.type = "fast instance checker"; -reasoner.reasonerComponent = component:embeddedReasoner; -reasoner.sources = {"component:ks"}; -embeddedReasoner.type = "org.dllearner.reasoning.OWLAPIReasoner"; -embeddedReasoner.sources = {"component:kbFile"}; +reasoner.type = "fast instance checker" +reasoner.reasonerComponent = component:embeddedReasoner +reasoner.sources = {"component:ks"} +embeddedReasoner.type = "org.dllearner.reasoning.OWLAPIReasoner" +embeddedReasoner.sources = {"component:kbFile"} // learning problem -lp.type = "posNegStandard"; -lp.positiveExamples = {"stefan","markus","bernd"}; -lp.negativeExamples = {"heinz","anna","gabi","michelle"}; +lp.type = "posNegStandard" +lp.positiveExamples = {"stefan","markus","bernd"} +lp.negativeExamples = {"heinz","anna","gabi","michelle"} // TODO: the stuff below is untested and just shows what it could look like // plug a reasoner into the learning problem -lp.reasoner = reasoner; +lp.reasoner = reasoner // create a refinement operator and configure it -op.type = "rho"; -op.useCardinalityRestrictions = true; +op.type = "rho" +op.useCardinalityRestrictions = true // create a heuristic and configure it -h.type = "multiheuristic"; -h.expansionPenaltyFactor = 0.2; +h.type = "multiheuristic" +h.expansionPenaltyFactor = 0.2 // create learning algorithm to run -alg.type = "ocel"; -alg.operator = component:op; -alg.learningProblem = component:lp; -alg.heuristic = component:h; +alg.type = "ocel" +alg.operator = component:op +alg.learningProblem = component:lp +alg.heuristic = component:h + Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-24 18:37:17 UTC (rev 3117) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-25 08:06:45 UTC (rev 3118) @@ -56,7 +56,7 @@ */ public static void main(String[] args) throws FileNotFoundException, ParseException { /** TODO Get conf file location from args */ - ConfParser parser = ConfParser.parseFile(new File("../test/newconf/test1.conf")); + ConfParser parser = ConfParser.parseFile(new File("../examples/family/father.conf")); List<ConfFileOption> options = parser.getConfOptions(); for(ConfFileOption option : options) { System.out.println(option); Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java 2011-08-24 18:37:17 UTC (rev 3117) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParser.java 2011-08-25 08:06:45 UTC (rev 3118) @@ -285,7 +285,6 @@ } } } - jj_consume_token(CONF_END); if(containsSubOption) { if(isNumeric) if(isDouble) @@ -490,13 +489,13 @@ return false; } - private boolean jj_3_3() { - if (jj_scan_token(NEG_EX)) return true; + private boolean jj_3R_4() { + if (jj_scan_token(ID)) return true; return false; } - private boolean jj_3R_4() { - if (jj_scan_token(ID)) return true; + private boolean jj_3_3() { + if (jj_scan_token(NEG_EX)) return true; return false; } @@ -536,6 +535,11 @@ return false; } + private boolean jj_3R_20() { + if (jj_scan_token(ID)) return true; + return false; + } + private boolean jj_3R_15() { if (jj_3R_4()) return true; return false; @@ -546,11 +550,6 @@ return false; } - private boolean jj_3R_20() { - if (jj_scan_token(ID)) return true; - return false; - } - private boolean jj_3R_19() { Token xsp; xsp = jj_scanpos; @@ -589,13 +588,13 @@ return false; } - private boolean jj_3R_14() { - if (jj_3R_18()) return true; + private boolean jj_3R_16() { + if (jj_scan_token(NUMBER)) return true; return false; } - private boolean jj_3R_16() { - if (jj_scan_token(NUMBER)) return true; + private boolean jj_3R_14() { + if (jj_3R_18()) return true; return false; } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj 2011-08-24 18:37:17 UTC (rev 3117) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/conf2.jj 2011-08-25 08:06:45 UTC (rev 3118) @@ -195,7 +195,8 @@ "(" (tmp=String() | tmp=Id()) "," (tmp2=String() | tmp2=Id()) ")" {tuples.add(new StringTuple(tmp,tmp2));} "]" {isList=true;} - ) <CONF_END> + ) + // <CONF_END> { if(containsSubOption) { if(isNumeric) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-25 08:44:11
|
Revision: 3119 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3119&view=rev Author: jenslehmann Date: 2011-08-25 08:44:05 +0000 (Thu, 25 Aug 2011) Log Message: ----------- created new test case and annotations Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/ListStringEditor.java trunk/components-core/src/main/java/org/dllearner/core/config/README.txt trunk/test/newconf/test2.conf Added: trunk/components-core/src/main/java/org/dllearner/core/config/ListStringEditor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/ListStringEditor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/ListStringEditor.java 2011-08-25 08:44:05 UTC (rev 3119) @@ -0,0 +1,89 @@ +package org.dllearner.core.config; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; +import java.util.List; + +/** + * + * TODO: Implementation not working yet. Please enhance it. + * + */ +public class ListStringEditor implements PropertyEditor { + + private List<String> value; + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public String getAsText() { + return value.toString(); + } + + @Override + public Component getCustomEditor() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getJavaInitializationString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getTags() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isPaintable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + throw new Error("not implemented"); + } + + @Override + public void setValue(Object value) { + // TODO Auto-generated method stub + + } + + @Override + public boolean supportsCustomEditor() { + // TODO Auto-generated method stub + return false; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/core/config/README.txt =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/README.txt (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/README.txt 2011-08-25 08:44:05 UTC (rev 3119) @@ -0,0 +1,4 @@ +In DL-Learner, we should use the following external property +editors: + +URL => org.springframework.beans.propertyeditors.URLEditor Modified: trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-08-25 08:06:45 UTC (rev 3118) +++ trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2011-08-25 08:44:05 UTC (rev 3119) @@ -23,9 +23,13 @@ import java.util.LinkedList; import java.util.List; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.ListStringEditor; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.springframework.beans.propertyeditors.URLEditor; /** * SPARQL endpoint knowledge source (without fragment extraction), @@ -35,13 +39,20 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "SPARQL endpoint", shortName = "sparql", version = 0.2) public class SparqlEndpointKS implements KnowledgeSource { private SparqlEndpoint endpoint; // TODO: turn those into config options + + @ConfigOption(name = "url", required=true, propertyEditorClass = URLEditor.class) private URL url; + + @ConfigOption(name = "url", defaultValue="[]", required=false, propertyEditorClass = ListStringEditor.class) private List<String> defaultGraphURIs = new LinkedList<String>(); + + @ConfigOption(name = "url", defaultValue="[]", required=false, propertyEditorClass = ListStringEditor.class) private List<String> namedGraphURIs = new LinkedList<String>(); public SparqlEndpointKS() { Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2011-08-25 08:06:45 UTC (rev 3118) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2011-08-25 08:44:05 UTC (rev 3119) @@ -32,6 +32,7 @@ import org.apache.log4j.Logger; import org.dllearner.core.AbstractKnowledgeSource; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.OntologyFormat; import org.dllearner.core.OntologyFormatUnsupportedException; import org.dllearner.core.configurators.SparqlKnowledgeSourceConfigurator; @@ -72,6 +73,7 @@ * @author Sebastian Knappe * @author Sebastian Hellmann */ +@ComponentAnn(name = "SPARQL endpoint fragment", shortName = "sparqlfrag", version = 0.5) public class SparqlKnowledgeSource extends AbstractKnowledgeSource { private ProgressMonitor mon; Added: trunk/test/newconf/test2.conf =================================================================== --- trunk/test/newconf/test2.conf (rev 0) +++ trunk/test/newconf/test2.conf 2011-08-25 08:44:05 UTC (rev 3119) @@ -0,0 +1,9 @@ + +ks.type = "sparql" +ks.url = "http://live.dbpedia.org/sparql" +ks.defaultGraphURIs = {"http://dbpedia.org"} + +alg.type = "objectproperty range learner" +alg.source = component:ks +alg.propertyToDescribe = "http://dbpedia.org/ontology/leader" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2011-08-26 04:15:10
|
Revision: 3126 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3126&view=rev Author: shadowtm Date: 2011-08-26 04:15:03 +0000 (Fri, 26 Aug 2011) Log Message: ----------- Got the Father.conf file to load everything that the algorithm needed and begin executing the OCEL algorithm. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/RandomGuesser.java trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/algorithms/refinement/ROLearner.java trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/RandomGuesser.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/RandomGuesser.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -25,7 +25,6 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.core.*; -import org.dllearner.core.configurators.RandomGuesserConfigurator; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.IntegerConfigOption; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -32,9 +32,6 @@ import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.configurators.Configurator; -import org.dllearner.core.configurators.ELLearningAlgorithmConfigurator; -import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; @@ -91,11 +88,7 @@ return problems; } - // we can assume a PosNegLP, because it is the only supported one - private PosNegLP getLearningProblem() { - return (PosNegLP) learningProblem; - } - + // @Override // public ELLearningAlgorithmConfigurator getConfigurator() { // return configurator; @@ -166,7 +159,7 @@ Description description = descriptionTree.transformToDescription(); // double accuracy = getLearningProblem().getAccuracyOrTooWeak(description, 0); - int negCovers = getLearningProblem().coveredNegativeExamplesOrTooWeak(description); + int negCovers = ((PosNegLP)getLearningProblem()).coveredNegativeExamplesOrTooWeak(description); if(negCovers == -1) { // if(accuracy == -1) { node.setTooWeak(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -139,11 +139,6 @@ return options; } - // we can assume a PosNegLP, because it is the only supported one - private PosNegLP getLearningProblem() { - return (PosNegLP) learningProblem; - } - public Configurator getConfigurator() { return configurator; } @@ -399,8 +394,8 @@ trees.clear(); currentSolution.clear(); bestEvaluatedDescription = learningProblem.evaluate(Thing.instance); - currentPosExamples = getLearningProblem().getPositiveExamples(); - currentNegExamples = getLearningProblem().getNegativeExamples(); + currentPosExamples = ((PosNegLP)getLearningProblem()).getPositiveExamples(); + currentNegExamples = ((PosNegLP)getLearningProblem()).getNegativeExamples(); startPosExamplesSize = currentPosExamples.size(); // startNegExamplesSize = currentNegExamples.size(); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/MultiHeuristic.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -119,7 +119,11 @@ this.startNodeBonus = startNodeBonus; this.expansionPenaltyFactor = expansionPenaltyFactor; } - + + public MultiHeuristic(){ + + } + // public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, double expansionPenaltyFactor, double gainBonusFactor) { // this.nrOfNegativeExamples = nrOfNegativeExamples; // nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; @@ -204,4 +208,11 @@ return bonus; } + public double getExpansionPenaltyFactor() { + return expansionPenaltyFactor; + } + + public void setExpansionPenaltyFactor(double expansionPenaltyFactor) { + this.expansionPenaltyFactor = expansionPenaltyFactor; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -162,6 +162,10 @@ // Faktor für horizontale Erweiterung (notwendig für completeness) // double horizontalExpansionFactor = 0.6; + + public OCEL(){ + + } // soll später einen Operator und eine Heuristik entgegennehmen // public ROLearner(LearningProblem learningProblem, LearningProblem learningProblem2) { public OCEL(PosNegLP learningProblem, AbstractReasonerComponent reasoningService) { @@ -318,7 +322,7 @@ public void init() throws ComponentInitException { // exit with a ComponentInitException if the reasoner is unsupported for this learning algorithm - if(reasoner.getReasonerType() == ReasonerType.DIG) { + if(getReasoner().getReasonerType() == ReasonerType.DIG) { throw new ComponentInitException("DIG does not support the inferences needed in the selected learning algorithm component: " + getName()); } @@ -341,14 +345,15 @@ if(learningProblem instanceof PosOnlyLP) { throw new RuntimeException("does not work with positive examples only yet"); } - heuristic = new FlexibleHeuristic(((PosNegLP)learningProblem).getNegativeExamples().size(), ((PosNegLP)learningProblem).getPercentPerLengthUnit()); + heuristic = new FlexibleHeuristic(((PosNegLP) getLearningProblem()).getNegativeExamples().size(), ((PosNegLP) getLearningProblem()).getPercentPerLengthUnit()); } else { - if(learningProblem instanceof PosOnlyLP) { + //The Heuristic is now injected +// if(getLearningProblem() instanceof PosOnlyLP) { // throw new RuntimeException("does not work with positive examples only yet"); - heuristic = new MultiHeuristic(((PosOnlyLP)learningProblem).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); - } else { - heuristic = new MultiHeuristic(((PosNegLP)learningProblem).getPositiveExamples().size(),((PosNegLP)learningProblem).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); - } +// heuristic = new MultiHeuristic(((PosOnlyLP) getLearningProblem()).getPositiveExamples().size(),0, negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); +// } else { +// heuristic = new MultiHeuristic(((PosNegLP) getLearningProblem()).getPositiveExamples().size(),((PosNegLP) getLearningProblem()).getNegativeExamples().size(), negativeWeight, startNodeBonus, expansionPenaltyFactor, negationPenalty); +// } } // warn the user if he/she sets any non-standard heuristic, because it will just be ignored @@ -552,11 +557,11 @@ this.replaceSearchTree = replaceSearchTree; } - public String getHeuristic() { + public String getHeuristicStr() { return heuristicStr; } - public void setHeuristic(String heuristic) { + public void setHeuristicStr(String heuristic) { this.heuristicStr = heuristic; } @@ -851,4 +856,8 @@ public void setHeuristic(ExampleBasedHeuristic heuristic) { this.heuristic = heuristic; } + + public ExampleBasedHeuristic getHeuristic() { + return heuristic; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/refinement/ROLearner.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/refinement/ROLearner.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -982,7 +982,7 @@ // System.out.println("max. number of one-step refinements: " + maxNrOfRefinements); // System.out.println("max. number of children of a node: " + maxNrOfChildren); logger.debug("subsumption time: " + Helper.prettyPrintNanoSeconds(reasoner.getSubsumptionReasoningTimeNs())); - logger.debug("instance check time: " + Helper.prettyPrintNanoSeconds(reasoner.getInstanceCheckReasoningTimeNs())); + logger.debug("instance check time: " + Helper.prettyPrintNanoSeconds(reasoner.getInstanceCheckReasoningTimeNs())); } if(showBenchmarkInformation) { Modified: trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -86,6 +86,12 @@ */ public Set<String> getNegativeExamples(); + /** + * Get the Base Directory where this configuration should be running out of. + * + * @return The Base Directory where this configuration should be running out of. + */ + public String getBaseDir(); } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -60,6 +60,13 @@ */ protected AbstractReasonerComponent reasoner; + + /** + * Default Constructor + */ + public AbstractCELA(){ + + } /** * Each learning algorithm gets a learning problem and * a reasoner as input. @@ -270,5 +277,28 @@ public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { return new LinkedList<Class<? extends AbstractLearningProblem>>(); } - + + /** + * The learning problem variable, which must be used by + * all learning algorithm implementations. + */ + public AbstractLearningProblem getLearningProblem() { + return learningProblem; + } + + public void setLearningProblem(AbstractLearningProblem learningProblem) { + this.learningProblem = learningProblem; + } + + /** + * The reasoning service variable, which must be used by + * all learning algorithm implementations. + */ + public AbstractReasonerComponent getReasoner() { + return reasoner; + } + + public void setReasoner(AbstractReasonerComponent reasoner) { + this.reasoner = reasoner; + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -73,6 +73,12 @@ "org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner", "org.dllearner.algorithms.DisjointClassesLearner", "org.dllearner.algorithms.SimpleSubclassLearner", + "org.dllearner.kb.KBFile", + "org.dllearner.learningproblems.PosNegLPStandard", + "org.dllearner.reasoning.FastInstanceChecker", + "org.dllearner.algorithms.ocel.OCEL", + "org.dllearner.algorithms.ocel.MultiHeuristic", + "org.dllearner.refinementoperators.RhoDRDown", } )); private static Collection<Class<? extends Component>> components; private static BidiMap<Class<? extends Component>, String> componentNames; Modified: trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -55,7 +55,6 @@ @ConfigOption(name = "url", description = "URL pointer to the KB file", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) private String url; - @ConfigOption(name = "baseDir", description = "Base Directory to look for the file in", defaultValue = ".", required = false, propertyEditorClass = StringTrimmerEditor.class) private String baseDir; /** Modified: trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -49,7 +49,7 @@ // TODO: turn this into a config option private URL url; - + private String baseDir; // private URL url; // private OWLFileConfigurator configurator ; // @Override @@ -139,4 +139,11 @@ throw new Error("OWL -> KB conversion not implemented yet."); } + public String getBaseDir() { + return baseDir; + } + + public void setBaseDir(String baseDir) { + this.baseDir = baseDir; + } } Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -1,6 +1,8 @@ package org.dllearner.configuration.spring; import org.dllearner.configuration.IConfiguration; +import org.dllearner.kb.KBFile; +import org.dllearner.kb.OWLFile; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -37,6 +39,12 @@ BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClass); BeanDefinition definition = builder.getBeanDefinition(); + + /** Add Base Directory */ + if(beanClass.isAssignableFrom(KBFile.class) || beanClass.isAssignableFrom(OWLFile.class)){ + definition.getPropertyValues().addPropertyValue("baseDir",configuration.getBaseDir()); + } + registry.registerBeanDefinition(beanName,definition); } } Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -27,13 +27,14 @@ ConfigurableApplicationContext context = null; ConfParserConfiguration configuration = new ConfParserConfiguration(confFile); + // Post Processors BeanDefinitionRegistryPostProcessor beanDefinitionRegistryPostProcessor = new ConfigurationBasedBeanDefinitionRegistryPostProcessor(configuration); ConfigurationBasedPropertyOverrideConfigurer configurer = new ConfigurationBasedPropertyOverrideConfigurer(configuration, false); configurer.setProperties(configuration.getProperties()); configurer.getComponentKeyPrefixes().addAll(componentKeyPrefixes); - /** These files need to be loaded first */ + //These files need to be loaded first List<Resource> allSpringConfigFiles = new ArrayList<Resource>(); allSpringConfigFiles.add(new ClassPathResource("/org/dllearner/configuration/spring/bean-post-processor-configuration.xml")); allSpringConfigFiles.addAll(springConfigurationLocations); @@ -46,10 +47,11 @@ } context = new ClassPathXmlApplicationContext(springConfigurationFiles, false); - /** These post processors run before object instantiation */ + // These post processors run before object instantiation context.addBeanFactoryPostProcessor(beanDefinitionRegistryPostProcessor); context.addBeanFactoryPostProcessor(configurer); + //Instantiate and initialize the beans. context.refresh(); return context; } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -24,9 +24,11 @@ public class ConfParserConfiguration implements IConfiguration { private final ConfParser parser; + private final String baseDir; public ConfParserConfiguration(Resource source){ try { + baseDir = source.getFile().getAbsoluteFile().getParent(); parser = new ConfParser(source.getInputStream()); parser.Start(); } catch (ParseException e) { @@ -175,4 +177,9 @@ return result; } + + @Override + public String getBaseDir() { + return baseDir; + } } Modified: trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-26 04:15:03 UTC (rev 3126) @@ -1,6 +1,7 @@ package org.dllearner.cli; import junit.framework.Assert; +import org.dllearner.algorithms.ocel.OCEL; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; import org.dllearner.learningproblems.PosNegLPStandard; @@ -33,6 +34,7 @@ /** The DL-Learner Config File */ Resource confFile = new FileSystemResource("./examples/family/father.conf"); +// confFile.getAbsoluteFile().getParent( /** Component Key Prefixes */ List<String> componentKeyPrefixes = new ArrayList<String>(); componentKeyPrefixes.add("component:"); @@ -50,10 +52,18 @@ @Test public void testFatherConf(){ - context.getBean("kbFile"); - PosNegLPStandard lp = context.getBean("learningProblem", PosNegLPStandard.class); + PosNegLPStandard lp = context.getBean("lp", PosNegLPStandard.class); Assert.assertTrue(lp.getPositiveExamples().size() == 3); Assert.assertTrue(lp.getNegativeExamples().size() == 4); + Assert.assertNotNull(lp.getReasoner()); + + OCEL algorithm = context.getBean("alg",OCEL.class); + Assert.assertNotNull(algorithm); + + algorithm.start(); + + + } } Modified: trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf =================================================================== --- trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-08-26 04:15:03 UTC (rev 3126) @@ -3,33 +3,33 @@ */ // a single line comment, which is ignored -testBean.simpleValue="simple value example"; // simple value +testBean.simpleValue="simple value example" // simple value -testBean.component=component:secondBean; // I wonder whether we even need the component keyword or could just write beanName.property=:test; +testBean.component=component:secondBean // I wonder whether we even need the component keyword or could just write beanName.property=:test; -testBean.intValue = 23; // an integer value +testBean.intValue = 23 // an integer value -testBean.doubleValue = 78.5; // a double value +testBean.doubleValue = 78.5 // a double value -testBean.setValue={"a"}; // a set (list is not implemented, but can be done analogously) +testBean.setValue={"a"} // a set (list is not implemented, but can be done analogously) -testBean.mapValue=[("a","b"),("c","d")]; // a map (we can use whatever syntax we like, this is the existing one) +testBean.mapValue=[("a","b"),("c","d")] // a map (we can use whatever syntax we like, this is the existing one) // Second Bean Definition - to show loading of a referenced bean -secondBean.simpleValue="second bean example"; // simple value -secondBean.component=component:thirdBean; //Another Bean -secondBean.intValue = 85; // an integer value -secondBean.doubleValue = 178.5; // a double value -secondBean.setValue={"e"}; // a set (list is not implemented, but can be done analogously) -secondBean.mapValue=[("f","g"),("c","d")]; // a map (we can use whatever syntax we like, this is the existing one) -secondBean.componentSet={"component:thirdBean","component:fourthBean"}; +secondBean.simpleValue="second bean example" // simple value +secondBean.component=component:thirdBean //Another Bean +secondBean.intValue = 85 // an integer value +secondBean.doubleValue = 178.5 // a double value +secondBean.setValue={"e"} // a set (list is not implemented, but can be done analogously) +secondBean.mapValue=[("f","g"),("c","d")] // a map (we can use whatever syntax we like, this is the existing one) +secondBean.componentSet={"component:thirdBean","component:fourthBean"} -thirdBean.intValue=3; -thirdBean.component=component:fourthBean; +thirdBean.intValue=3 +thirdBean.component=component:fourthBean -fourthBean.simpleValue="Fourth Bean - not specified in xml"; -fourthBean.type="org.dllearner.configuration.spring.TestBean"; +fourthBean.simpleValue="Fourth Bean - not specified in xml" +fourthBean.type="org.dllearner.configuration.spring.TestBean" // you can also specify positive and negative examples // (not sure if we really need that) +"http://example.org/pos1/" Modified: trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf =================================================================== --- trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf 2011-08-25 15:10:11 UTC (rev 3125) +++ trunk/interfaces/src/test/resources/org/dllearner/confparser2/confParserConfigurationTest.conf 2011-08-26 04:15:03 UTC (rev 3126) @@ -3,17 +3,17 @@ */ // a single line comment, which is ignored -testBean.simpleValue="simple value example"; // simple value +testBean.simpleValue="simple value example" // simple value -testBean.component=component:test; // I wonder whether we even need the component keyword or could just write beanName.property=:test; +testBean.component=component:test // I wonder whether we even need the component keyword or could just write beanName.property=:test; -testBean.intValue = 23; // an integer value +testBean.intValue = 23 // an integer value -testBean.doubleValue = 78.5; // a double value +testBean.doubleValue = 78.5 // a double value -testBean.setValue={"a"}; // a set (list is not implemented, but can be done analogously) +testBean.setValue={"a"} // a set (list is not implemented, but can be done analogously) -testBean.mapValue=[("a","b"),("c","d")]; // a map (we can use whatever syntax we like, this is the existing one) +testBean.mapValue=[("a","b"),("c","d")] // a map (we can use whatever syntax we like, this is the existing one) // you can also specify positive and negative examples // (not sure if we really need that) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-26 07:30:35
|
Revision: 3129 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3129&view=rev Author: jenslehmann Date: 2011-08-26 07:30:28 +0000 (Fri, 26 Aug 2011) Log Message: ----------- improved error handling for learning problem with positive and negative examples Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java trunk/examples/family/father.conf trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java 2011-08-26 06:19:11 UTC (rev 3128) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractLearningProblem.java 2011-08-26 07:30:28 UTC (rev 3129) @@ -34,7 +34,7 @@ */ public abstract class AbstractLearningProblem extends AbstractComponent implements LearningProblem { - private AbstractReasonerComponent reasoner; + protected AbstractReasonerComponent reasoner; public AbstractLearningProblem(){ Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-26 06:19:11 UTC (rev 3128) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLP.java 2011-08-26 07:30:28 UTC (rev 3129) @@ -26,6 +26,7 @@ import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.options.StringConfigOption; @@ -111,8 +112,15 @@ * @see org.dllearner.core.Component#init() */ @Override - public void init() { + public void init() throws ComponentInitException { allExamples = Helper.union(positiveExamples, negativeExamples); + + if(!reasoner.getIndividuals().containsAll(allExamples)) { + String str = "The examples below are not contained in the knowledge base (check spelling and prefixes)\n"; + Set<Individual> inds = Helper.difference(allExamples, reasoner.getIndividuals()); + str += inds.toString(); + throw new ComponentInitException(str); + } } public Set<Individual> getNegativeExamples() { Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-26 06:19:11 UTC (rev 3128) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2011-08-26 07:30:28 UTC (rev 3129) @@ -27,6 +27,7 @@ import java.util.TreeSet; import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.config.ConfigOption; @@ -102,7 +103,7 @@ } @Override - public void init() { + public void init() throws ComponentInitException { super.init(); String accM = getAccuracyMethod(); @@ -498,15 +499,27 @@ * @see org.dllearner.core.LearningProblem#getAccuracyOrTooWeak(org.dllearner.core.owl.Description, double) */ public double getPredAccuracyOrTooWeakExact(Description description, double noise) { - + // TODO: what we essentially need here is that if the noise justifies + // not covering 1.23 examples, then we stop with 2 examples not covered; + // but when noise justifies not covering exactly 2 examples, we can actually + // only stop with 3 examples; so we would have to add 1 for exact matches + // which is not done yet int maxNotCovered = (int) Math.ceil(noise*positiveExamples.size()); + // maybe use this approach: +// int maxNotCovered = (int) Math.ceil(noise*positiveExamples.size()+0.0001); + System.out.println("noise: " + noise); + System.out.println("max not covered: " + maxNotCovered); + int notCoveredPos = 0; int notCoveredNeg = 0; for (Individual example : positiveExamples) { if (!getReasoner().hasType(description, example)) { notCoveredPos++; + + System.out.println("d:" + description + "; ex:" + example); + if(notCoveredPos >= maxNotCovered) { return -1; } @@ -518,6 +531,9 @@ } } + System.out.println("not covered pos: " + notCoveredPos); + System.out.println("not covered neg: " + notCoveredNeg); + // if(useFMeasure) { // double recall = (positiveExamples.size() - notCoveredPos) / (double) positiveExamples.size(); // double precision = (positiveExamples.size() - notCoveredPos) / (double) (allExamples.size() - notCoveredPos - notCoveredNeg); Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2011-08-26 06:19:11 UTC (rev 3128) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2011-08-26 07:30:28 UTC (rev 3129) @@ -24,6 +24,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.configurators.PosNegLPStrictConfigurator; @@ -100,7 +101,7 @@ * @see org.dllearner.core.Component#init() */ @Override - public void init() { + public void init() throws ComponentInitException { super.init(); // compute neutral examples, i.e. those which are neither positive // nor negative (we have to take care to copy sets instead of Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-26 06:19:11 UTC (rev 3128) +++ trunk/examples/family/father.conf 2011-08-26 07:30:28 UTC (rev 3129) @@ -22,11 +22,9 @@ // learning problem lp.type = "posNegStandard" -lp.positiveExamples = {"stefan","markus","bernd"} -lp.negativeExamples = {"heinz","anna","gabi","michelle"} +lp.positiveExamples = {"http://localhost/foo#stefan","http://localhost/foo#markus","http://localhost/foo#bernd"} +lp.negativeExamples = {"http://localhost/foo#heinz","http://localhost/foo#anna","http://localhost/foo#gabi","http://localhost/foo#michelle"} -// TODO: the stuff below is untested and just shows what it could look like - // plug a reasoner into the learning problem lp.reasoner = component:reasoner //lp.reasoner = reasoner - try to remove the component:part in the parser Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-26 06:19:11 UTC (rev 3128) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-26 07:30:28 UTC (rev 3129) @@ -30,6 +30,12 @@ import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; import org.dllearner.confparser2.ParseException; import org.dllearner.core.AbstractCELA; +import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Thing; +import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.reasoning.FastInstanceChecker; import org.springframework.context.ApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; @@ -43,8 +49,6 @@ */ public class CLI { - - public CLI(){ } @@ -58,8 +62,9 @@ * @param args * @throws ParseException * @throws IOException + * @throws ReasoningMethodUnsupportedException */ - public static void main(String[] args) throws ParseException, IOException { + public static void main(String[] args) throws ParseException, IOException, ReasoningMethodUnsupportedException { System.out.println("DL-Learner " + Info.build + " [TODO: read pom.version and put it here (make sure that the code for getting the version also works in the release build!)] command line interface"); @@ -87,10 +92,23 @@ ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); ApplicationContext context = builder.buildApplicationContext(confFile,componentKeyPrefixes,springConfigResources); + // a lot of debugging stuff +// FastInstanceChecker fi = context.getBean("reasoner", FastInstanceChecker.class); +// System.out.println(fi.getClassHierarchy()); +// NamedClass male = new NamedClass("http://localhost/foo#male"); +// System.out.println(fi.getIndividuals(new NamedClass("http://localhost/foo#male"))); +// System.out.println(fi.getIndividuals().size()); +// System.out.println("has type: " + fi.hasTypeImpl(male, new Individual("http://localhost/foo#bernd"))); +// +// PosNegLPStandard lp = context.getBean("lp", PosNegLPStandard.class); +// System.out.println(lp.getPositiveExamples()); +// System.out.println(lp.getNegativeExamples()); +// System.out.println(lp.getAccuracy(new NamedClass("http://localhost/foo#male"))); + // start algorithm in conf file OCEL algorithm = context.getBean("alg",OCEL.class); algorithm.start(); - + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-26 08:27:52
|
Revision: 3131 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3131&view=rev Author: jenslehmann Date: 2011-08-26 08:27:45 +0000 (Fri, 26 Aug 2011) Log Message: ----------- started preparation of moosique.conf example for new CLI Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java Added Paths: ----------- trunk/examples/sparql/moosique_new.conf Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-26 07:43:17 UTC (rev 3130) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2011-08-26 08:27:45 UTC (rev 3131) @@ -149,6 +149,10 @@ return configurator; } + public CELOE() { + + } + public CELOE(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) { super(problem, reasoner); configurator = new CELOEConfigurator(this); Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-26 07:43:17 UTC (rev 3130) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-26 08:27:45 UTC (rev 3131) @@ -74,7 +74,11 @@ "org.dllearner.algorithms.DisjointClassesLearner", "org.dllearner.algorithms.SimpleSubclassLearner", "org.dllearner.kb.KBFile", + "org.dllearner.kb.OWLFile", + "org.dllearner.kb.SparqlEndpointKS", + "org.dllearner.kb.sparql.SparqlKnowledgeSource", "org.dllearner.learningproblems.PosNegLPStandard", + "org.dllearner.learningproblems.PosOnlyLP", "org.dllearner.reasoning.FastInstanceChecker", "org.dllearner.algorithms.ocel.OCEL", "org.dllearner.algorithms.ocel.MultiHeuristic", Modified: trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2011-08-26 07:43:17 UTC (rev 3130) +++ trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2011-08-26 08:27:45 UTC (rev 3131) @@ -26,6 +26,7 @@ import java.util.LinkedList; import org.apache.log4j.Logger; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.OntologyFormat; @@ -42,6 +43,7 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "OWL File", shortName = "owlfile", version = 0.9) public class OWLFile extends AbstractKnowledgeSource { private static Logger logger = Logger Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-08-26 07:43:17 UTC (rev 3130) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2011-08-26 08:27:45 UTC (rev 3131) @@ -30,6 +30,7 @@ import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.configurators.PosOnlyLPConfigurator; import org.dllearner.core.options.CommonConfigMappings; import org.dllearner.core.options.ConfigEntry; @@ -45,6 +46,7 @@ * @author Jens Lehmann * */ +@ComponentAnn(name = "positive only learning problem", shortName = "posonlylp", version = 0.6) public class PosOnlyLP extends AbstractLearningProblem { protected SortedSet<Individual> positiveExamples; Added: trunk/examples/sparql/moosique_new.conf =================================================================== --- trunk/examples/sparql/moosique_new.conf (rev 0) +++ trunk/examples/sparql/moosique_new.conf 2011-08-26 08:27:45 UTC (rev 3131) @@ -0,0 +1,78 @@ + +/** + * moosique.net test example + */ + +// select the Jamendo endpoint as knowledge source +jamendo.type = "SPARQL endpoint fragment" +jamendo.url = "http://dbtune.org/jamendo/sparql/" + +// select a set of "starting instances" => this includes positive examples (tracks/albums/artists +// last heard) as well as randomly selected objects of the same type (track/album/artist) - +// preferably those which have at least e.g. 3 tags; +// starting from these instances, DL-Learner extracts a fragment of the Jamendo knowledge base +jamendo.instances = { +"http://dbtune.org/jamendo/record/1059", +"http://dbtune.org/jamendo/record/1162", +"http://dbtune.org/jamendo/record/1262", +"http://dbtune.org/jamendo/record/1363", +"http://dbtune.org/jamendo/record/1465", +"http://dbtune.org/jamendo/record/1568", +"http://dbtune.org/jamendo/record/1668", +"http://dbtune.org/jamendo/record/1769", +"http://dbtune.org/jamendo/record/1869", +"http://dbtune.org/jamendo/record/1970" +} + +// recursion depth => the maximum distance of an object in the fragment from one of +// the starting instances +jamendo.recursionDepth = 2 + +// we transform tags to classes (such that we can build a taxonomy of tags) on the fly; +// => later we may send the taxonomy to Yves if he is interested in using a taxonomy instead +// of plain tags +jamendo.replacePredicate=[( +"http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag", +"http://www.w3.org/1999/02/22-rdf-syntax-ns#type")] + +// whether to save the extracted fragment (use e.g. Protege to view it); +// by default this goes to fragmentOntology.owl in the DL-Learner directory +jamendo.saveExtractedFragment = false + +// we now import the background knowledge including the taxonomy of tags +// (but you can specify any additional knowledge in this file - the more +// knowledge available, the better the suggestions) +// you can use e.g. Protege to create the taxonomy +// (set File >> Preferences >> Renderer to qnames) or a plain text editor +jamendoOntology.type = "OWL File" +jamendoOntology.url = "jamendo.owl" + +reasoner.type = "fast instance checker" +reasoner.sources = {component:jamendo, component:jamendoOntology} + +// we want to learn from positive examples only +lp.type = "positive only learning problem" +lp.positiveExamples = { +"http://dbtune.org/jamendo/record/1059", +"http://dbtune.org/jamendo/record/1162", +"http://dbtune.org/jamendo/record/1262" } +lp.reasoner = component:reasoner + +// we use the CELOE algorithm +alg.type = "celoe" +alg.reasoner = component:reasoner +alg.learningProblem = component:lp +// set the start class to the correct type (Record in this case) - not supported yet +// celoe.startClass = "http://purl.org/ontology/mo/Record"; +// let it run for a short amount of time (we only want simple expressions) +alg.maxExecutionTimeInSeconds = 2 +// use owl:hasValue if appropriate +// see: http://www.w3.org/TR/2008/WD-owl2-syntax-20081202/#Individual_Value_Restriction +// not sure whether this greatly influences the results +// alg.useHasValueConstructor = true +// alg.valueFrequencyThreshold = 2 + +// the conversion to natural language is not yet covered here; +// you can use the class org.dllearner.sparql.NaturalLanguageDescriptionConverter for this, +// but the implementation is quite bad at the moment; +// TODO: we could implement support for post processor in the CLI, which convert solutions to natural language This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-26 17:55:10
|
Revision: 3132 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3132&view=rev Author: jenslehmann Date: 2011-08-26 17:55:02 +0000 (Fri, 26 Aug 2011) Log Message: ----------- created yet another conf parser and a test case for it Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/core/config/PropertyEditorMapping.java trunk/examples/family/father_new.conf trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ParseException.java trunk/interfaces/src/main/java/org/dllearner/confparser3/SimpleCharStream.java trunk/interfaces/src/main/java/org/dllearner/confparser3/Token.java trunk/interfaces/src/main/java/org/dllearner/confparser3/TokenMgrError.java trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj trunk/interfaces/src/test/java/org/dllearner/confparser3/ trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/core/config/README.txt Added: trunk/components-core/src/main/java/org/dllearner/core/config/PropertyEditorMapping.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/PropertyEditorMapping.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/config/PropertyEditorMapping.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2007-2011, 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.config; + +import java.beans.PropertyEditor; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.springframework.beans.propertyeditors.URLEditor; + +/** + * This class declares the mapping between property editors and the types they should + * edit in DL-Learner. + * + * @author Jens Lehmann + * + */ +public final class PropertyEditorMapping { + + public static final Map<Class<?>,Class<? extends PropertyEditor>> map = new HashMap<Class<?>,Class<? extends PropertyEditor>>(); + static { + map.put(Boolean.class, BooleanEditor.class); + map.put(Integer.class, IntegerEditor.class); + map.put(URL.class, URLEditor.class); + } + +} Deleted: trunk/components-core/src/main/java/org/dllearner/core/config/README.txt =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/config/README.txt 2011-08-26 08:27:45 UTC (rev 3131) +++ trunk/components-core/src/main/java/org/dllearner/core/config/README.txt 2011-08-26 17:55:02 UTC (rev 3132) @@ -1,4 +0,0 @@ -In DL-Learner, we should use the following external property -editors: - -URL => org.springframework.beans.propertyeditors.URLEditor Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2011-08-26 08:27:45 UTC (rev 3131) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -58,7 +58,7 @@ * * @author Jens Lehmann */ -@ComponentAnn(name = "OWLAPIReasoner", shortName = "owlApiReasoner", version = 0.8) +@ComponentAnn(name = "OWL API Reasoner", shortName = "oar", version = 0.8) public class OWLAPIReasoner extends AbstractReasonerComponent { // private static Logger logger = Logger Added: trunk/examples/family/father_new.conf =================================================================== --- trunk/examples/family/father_new.conf (rev 0) +++ trunk/examples/family/father_new.conf 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,48 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +// knowledge source definition +ks.type = "KB file" +ks.url = "father.kb" +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. + +// reasoner +reasoner.type = "fast instance checker" +reasoner.reasonerComponent = embeddedReasoner +reasoner.sources = { ks } + +embeddedReasoner.type = "OWL API Reasoner" +embeddedReasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = {"http://localhost/foo#stefan","http://localhost/foo#markus","http://localhost/foo#bernd"} +lp.negativeExamples = {"http://localhost/foo#heinz","http://localhost/foo#anna","http://localhost/foo#gabi","http://localhost/foo#michelle"} + +// plug a reasoner into the learning problem +lp.reasoner = reasoner +//lp.reasoner = reasoner - try to remove the component:part in the parser + +// create a refinement operator and configure it +op.type = "rho" +op.useCardinalityRestrictions = true +op.reasoner = reasoner + +// create a heuristic and configure it +h.type = "multiheuristic" +h.expansionPenaltyFactor = 0.2 + +// create learning algorithm to run +alg.type = "ocel" +alg.reasoner = reasoner +alg.operator = op +alg.learningProblem = lp +alg.heuristic = h +alg.maxExecutionTimeInSeconds = 15 + Added: trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,101 @@ +/** + * 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.cli; + + +/** + * Programmatic representation of an option setting in a conf file: + * bean.property = value; + * + * TODO: Class is not stable yet. + * + * @author Jens Lehmann + * + */ +public class ConfFileOption2 { + + // a boolean flag which indicates whether the value was in quotes + private boolean inQuotes; + + private String beanName; + + private String propertyName; + + private String propertyValue; + + private Class<?> propertyType; + + // TODO: Do we want to store the actual value as object here or leave it up to + // the corresponding PropertyEditor to create it? + private Object valueObject; + + public ConfFileOption2() { + + } + + public boolean isInQuotes() { + return inQuotes; + } + + public void setInQuotes(boolean inQuotes) { + this.inQuotes = inQuotes; + } + + public String getBeanName() { + return beanName; + } + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } + + public String getPropertyValue() { + return propertyValue; + } + + public void setPropertyValue(String propertyValue) { + this.propertyValue = propertyValue; + } + + public Class<?> getPropertyType() { + return propertyType; + } + + public void setPropertyType(Class<?> propertyType) { + this.propertyType = propertyType; + } + + public Object getValueObject() { + return valueObject; + } + + public void setValueObject(Object valueObject) { + this.valueObject = valueObject; + } + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,773 @@ +/* Generated By:JavaCC: Do not edit this line. ConfParser.java */ +package org.dllearner.confparser3; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.dllearner.cli.ConfFileOption2; +import org.dllearner.parser.KBParser; +import org.dllearner.utilities.datastructures.StringTuple; + +public class ConfParser implements ConfParserConstants { + + // conf file options + private List<ConfFileOption2> confOptions = new LinkedList<ConfFileOption2>(); + private Map<String,ConfFileOption2> confOptionsByProperty = new HashMap<String,ConfFileOption2>(); + private Map<String,List<ConfFileOption2>> confOptionsByBean = new HashMap<String,List<ConfFileOption2>>(); + + private void addConfOption(ConfFileOption2 confOption) { + confOptions.add(confOption); + confOptionsByProperty.put(confOption.getPropertyName(), confOption); + String beanName = confOption.getBeanName(); + if(confOptionsByBean.containsKey(beanName)) + confOptionsByBean.get(beanName).add(confOption); + else { + LinkedList<ConfFileOption2> optionList = new LinkedList<ConfFileOption2>(); + optionList.add(confOption); + confOptionsByBean.put(beanName,optionList); + } + } + + public List<ConfFileOption2> getConfOptions() { + return confOptions; + } + + public Map<String,ConfFileOption2> getConfOptionsByProperty() { + return confOptionsByProperty; + } + + public ConfFileOption2 getConfOptionsByProperty(String propertyName) { + return confOptionsByProperty.get(propertyName); + } + + public Map<String,List<ConfFileOption2>> getConfOptionsByBean() { + return confOptionsByBean; + } + + public List<ConfFileOption2> getConfOptionsByBean(String beanName) { + return confOptionsByBean.get(beanName); + } + + public static ConfParser parseFile(File filename) throws FileNotFoundException, ParseException { + ConfParser parser = new ConfParser(new FileInputStream(filename)); + parser.Start(); + return parser; + } + + final public void Start() throws ParseException { + ConfFileOption2 confOption; + label_1: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + ; + break; + default: + jj_la1[0] = jj_gen; + break label_1; + } + confOption = ConfOption(); + addConfOption(confOption); + } + jj_consume_token(0); + } + + final public ConfFileOption2 ConfOption() throws ParseException { + boolean containsSubOption=false; + String value="", value1="", value2="", tmp="", tmp2=""; + Set<String> values = new HashSet<String>(); + List<StringTuple> tuples = new LinkedList<StringTuple>(); + + ConfFileOption2 option = new ConfFileOption2(); + boolean inQuotes = false; + String beanName; + String propertyName = ""; + String propertyValue; + Class<?> propertyType; + Object val = null; + beanName = Id(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case COMMAND_END: + jj_consume_token(COMMAND_END); + propertyName = Id(); + containsSubOption=true; + break; + default: + jj_la1[1] = jj_gen; + ; + } + jj_consume_token(25); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + // two strings separated by a double colon + // LOOKAHEAD(2) value1=Id() ":" value2=Id() { useColon = true; } + // simple string + propertyValue = Id(); + val = propertyValue; propertyType = String.class; + break; + case STRING: + propertyValue = String(); + val = propertyValue; inQuotes = true; propertyType = String.class; + break; + case NUMBER: + val = Integer(); + propertyValue = val.toString(); propertyType = Integer.class; + break; + case DOUBLE: + val = Double(); + propertyValue = val.toString(); propertyType = Double.class; + break; + default: + jj_la1[6] = jj_gen; + if (jj_2_4(2147483647)) { + jj_consume_token(26); + jj_consume_token(27); + val = new HashSet(); propertyType = Set.class; propertyValue = "{}"; + } else if (jj_2_5(4)) { + jj_consume_token(26); + label_2: + while (true) { + if (jj_2_1(2)) { + ; + } else { + break label_2; + } + tmp = String(); + values.add(tmp); + jj_consume_token(28); + } + tmp = String(); + values.add(tmp); + jj_consume_token(27); + propertyType = Set.class; propertyValue = "{ TODO }"; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 26: + jj_consume_token(26); + label_3: + while (true) { + if (jj_2_2(4)) { + ; + } else { + break label_3; + } + tmp = Id(); + values.add(tmp); + jj_consume_token(28); + } + tmp = Id(); + values.add(tmp); + jj_consume_token(27); + val = values; propertyType = Set.class; propertyValue = "{ TODO }"; + break; + default: + jj_la1[7] = jj_gen; + if (jj_2_6(2147483647)) { + jj_consume_token(29); + jj_consume_token(30); + val = new LinkedList(); propertyType = List.class; propertyValue = "[]"; + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 29: + jj_consume_token(29); + label_4: + while (true) { + if (jj_2_3(6)) { + ; + } else { + break label_4; + } + jj_consume_token(31); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[2] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(28); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp2 = String(); + break; + case ID: + tmp2 = Id(); + break; + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(32); + tuples.add(new StringTuple(tmp,tmp2)); + jj_consume_token(28); + } + jj_consume_token(31); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp = String(); + break; + case ID: + tmp = Id(); + break; + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(28); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case STRING: + tmp2 = String(); + break; + case ID: + tmp2 = Id(); + break; + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(32); + tuples.add(new StringTuple(tmp,tmp2)); + jj_consume_token(30); + val = values; propertyType = List.class; + break; + default: + jj_la1[8] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } + } + } + if(containsSubOption) { + option.setInQuotes(inQuotes); + option.setBeanName(beanName); + option.setPropertyName(propertyName); + option.setPropertyType(propertyType); + option.setValueObject(val); + } else { + // ... currently nothing here (maybe special parser directives) + } + {if (true) return option;} + throw new Error("Missing return statement in function"); + } + + final public String Individual() throws ParseException { + String name; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + name = Id(); + break; + case STRING: + name = String(); + break; + default: + jj_la1[9] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + {if (true) return KBParser.getInternalURI(name);} + throw new Error("Missing return statement in function"); + } + + final public String ComplexId() throws ParseException { + Token t1,t2; + if (jj_2_7(2)) { + t1 = jj_consume_token(ID); + jj_consume_token(33); + t2 = jj_consume_token(ID); + {if (true) return t1.image + ":" + t2.image;} + } else { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ID: + t1 = jj_consume_token(ID); + {if (true) return t1.image;} + break; + default: + jj_la1[10] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + throw new Error("Missing return statement in function"); + } + + final public String Id() throws ParseException { + Token t; + t = jj_consume_token(ID); + {if (true) return t.image;} + throw new Error("Missing return statement in function"); + } + + final public Double Double() throws ParseException { + Token t; + t = jj_consume_token(DOUBLE); + {if (true) return new Double(t.image);} + throw new Error("Missing return statement in function"); + } + + final public Integer Integer() throws ParseException { + Token t; + t = jj_consume_token(NUMBER); + {if (true) return new Integer(t.image);} + throw new Error("Missing return statement in function"); + } + + final public String String() throws ParseException { + Token t; + String s; + t = jj_consume_token(STRING); + // enclosing "" are removed + s = t.image; + s = s.substring(1, s.length() - 1); + {if (true) return s;} + throw new Error("Missing return statement in function"); + } + + private boolean jj_2_1(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_1(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_2(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_2_3(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_3(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + private boolean jj_2_4(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_4(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + private boolean jj_2_5(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_5(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + private boolean jj_2_6(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_6(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + private boolean jj_2_7(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_7(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + private boolean jj_3R_8() { + if (jj_3R_6()) return true; + return false; + } + + private boolean jj_3_5() { + if (jj_scan_token(26)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_1()) { jj_scanpos = xsp; break; } + } + if (jj_3R_5()) return true; + if (jj_scan_token(27)) return true; + return false; + } + + private boolean jj_3_1() { + if (jj_3R_5()) return true; + if (jj_scan_token(28)) return true; + return false; + } + + private boolean jj_3_6() { + if (jj_scan_token(29)) return true; + if (jj_scan_token(30)) return true; + return false; + } + + private boolean jj_3_7() { + if (jj_scan_token(ID)) return true; + if (jj_scan_token(33)) return true; + return false; + } + + private boolean jj_3R_9() { + if (jj_3R_5()) return true; + return false; + } + + private boolean jj_3R_5() { + if (jj_scan_token(STRING)) return true; + return false; + } + + private boolean jj_3_3() { + if (jj_scan_token(31)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_7()) { + jj_scanpos = xsp; + if (jj_3R_8()) return true; + } + if (jj_scan_token(28)) return true; + xsp = jj_scanpos; + if (jj_3R_9()) { + jj_scanpos = xsp; + if (jj_3R_10()) return true; + } + if (jj_scan_token(32)) return true; + if (jj_scan_token(28)) return true; + return false; + } + + private boolean jj_3_2() { + if (jj_3R_6()) return true; + if (jj_scan_token(28)) return true; + return false; + } + + private boolean jj_3R_10() { + if (jj_3R_6()) return true; + return false; + } + + private boolean jj_3R_7() { + if (jj_3R_5()) return true; + return false; + } + + private boolean jj_3_4() { + if (jj_scan_token(26)) return true; + if (jj_scan_token(27)) return true; + return false; + } + + private boolean jj_3R_6() { + if (jj_scan_token(ID)) return true; + return false; + } + + /** Generated Token Manager. */ + public ConfParserTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[11]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static { + jj_la1_init_0(); + jj_la1_init_1(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x1000,0x100,0x1001000,0x1001000,0x1001000,0x1001000,0x1007000,0x4000000,0x20000000,0x1001000,0x1000,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; + } + final private JJCalls[] jj_2_rtns = new JJCalls[7]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** Constructor with InputStream. */ + public ConfParser(java.io.InputStream stream) { + this(stream, null); + } + /** Constructor with InputStream and supplied encoding */ + public ConfParser(java.io.InputStream stream, String encoding) { + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ConfParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream) { + ReInit(stream, null); + } + /** Reinitialise. */ + public void ReInit(java.io.InputStream stream, String encoding) { + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor. */ + public ConfParser(java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ConfParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(java.io.Reader stream) { + jj_input_stream.ReInit(stream, 1, 1); + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Constructor with generated Token Manager. */ + public ConfParser(ConfParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** Reinitialise. */ + public void ReInit(ConfParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(int kind) throws ParseException { + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + static private final class LookaheadSuccess extends java.lang.Error { } + final private LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + +/** Get the next Token. */ + final public Token getNextToken() { + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + +/** Get the specific Token. */ + final public Token getToken(int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; + } + + private int jj_ntk() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); + } + + private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) return; + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) { + int[] oldentry = (int[])(it.next()); + if (oldentry.length == jj_expentry.length) { + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + continue jj_entries_loop; + } + } + jj_expentries.add(jj_expentry); + break jj_entries_loop; + } + } + if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; + } + } + + /** Generate ParseException. */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[34]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 11; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<<j)) != 0) { + la1tokens[j] = true; + } + if ((jj_la1_1[i] & (1<<j)) != 0) { + la1tokens[32+j] = true; + } + } + } + } + for (int i = 0; i < 34; i++) { + if (la1tokens[i]) { + jj_expentry = new int[1]; + jj_expentry[0] = i; + jj_expentries.add(jj_expentry); + } + } + jj_endpos = 0; + jj_rescan_token(); + jj_add_error_token(0, 0); + int[][] exptokseq = new int[jj_expentries.size()][]; + for (int i = 0; i < jj_expentries.size(); i++) { + exptokseq[i] = jj_expentries.get(i); + } + return new ParseException(token, exptokseq, tokenImage); + } + + /** Enable tracing. */ + final public void enable_tracing() { + } + + /** Disable tracing. */ + final public void disable_tracing() { + } + + private void jj_rescan_token() { + jj_rescan = true; + for (int i = 0; i < 7; i++) { + try { + JJCalls p = jj_2_rtns[i]; + do { + if (p.gen > jj_gen) { + jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,95 @@ +/* Generated By:JavaCC: Do not edit this line. ConfParserConstants.java */ +package org.dllearner.confparser3; + + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ +public interface ConfParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int SINGLE_LINE_COMMENT = 5; + /** RegularExpression Id. */ + int FORMAL_COMMENT = 6; + /** RegularExpression Id. */ + int MULTI_LINE_COMMENT = 7; + /** RegularExpression Id. */ + int COMMAND_END = 8; + /** RegularExpression Id. */ + int CONF_END = 9; + /** RegularExpression Id. */ + int POS_EX = 10; + /** RegularExpression Id. */ + int NEG_EX = 11; + /** RegularExpression Id. */ + int ID = 12; + /** RegularExpression Id. */ + int NUMBER = 13; + /** RegularExpression Id. */ + int DOUBLE = 14; + /** RegularExpression Id. */ + int TOP = 15; + /** RegularExpression Id. */ + int BOTTOM = 16; + /** RegularExpression Id. */ + int AND = 17; + /** RegularExpression Id. */ + int OR = 18; + /** RegularExpression Id. */ + int EXISTS = 19; + /** RegularExpression Id. */ + int ALL = 20; + /** RegularExpression Id. */ + int NOT = 21; + /** RegularExpression Id. */ + int GE = 22; + /** RegularExpression Id. */ + int LE = 23; + /** RegularExpression Id. */ + int STRING = 24; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "<EOF>", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "<SINGLE_LINE_COMMENT>", + "<FORMAL_COMMENT>", + "<MULTI_LINE_COMMENT>", + "\".\"", + "\";\"", + "\"+\"", + "\"-\"", + "<ID>", + "<NUMBER>", + "<DOUBLE>", + "\"TOP\"", + "\"BOTTOM\"", + "\"AND\"", + "\"OR\"", + "<EXISTS>", + "<ALL>", + "<NOT>", + "\">=\"", + "\"<=\"", + "<STRING>", + "\"=\"", + "\"{\"", + "\"}\"", + "\",\"", + "\"[\"", + "\"]\"", + "\"(\"", + "\")\"", + "\":\"", + }; + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,770 @@ +/* Generated By:JavaCC: Do not edit this line. ConfParserTokenManager.java */ +package org.dllearner.confparser3; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.dllearner.cli.ConfFileOption2; +import org.dllearner.parser.KBParser; +import org.dllearner.utilities.datastructures.StringTuple; + +/** Token Manager. */ +public class ConfParserTokenManager implements ConfParserConstants +{ + + /** Debug output. */ + public java.io.PrintStream debugStream = System.out; + /** Set debug output. */ + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } +private final int jjStopStringLiteralDfa_0(int pos, long active0) +{ + switch (pos) + { + case 0: + if ((active0 & 0x20000L) != 0L) + return 13; + return -1; + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0) +{ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0() +{ + switch(curChar) + { + case 40: + return jjStopAtPos(0, 31); + case 41: + return jjStopAtPos(0, 32); + case 43: + return jjStopAtPos(0, 10); + case 44: + return jjStopAtPos(0, 28); + case 45: + return jjStopAtPos(0, 11); + case 46: + return jjStopAtPos(0, 8); + case 58: + return jjStopAtPos(0, 33); + case 59: + return jjStopAtPos(0, 9); + case 60: + return jjMoveStringLiteralDfa1_0(0x800000L); + case 61: + return jjStopAtPos(0, 25); + case 62: + return jjMoveStringLiteralDfa1_0(0x400000L); + case 65: + return jjMoveStringLiteralDfa1_0(0x20000L); + case 66: + return jjMoveStringLiteralDfa1_0(0x10000L); + case 79: + return jjMoveStringLiteralDfa1_0(0x40000L); + case 84: + return jjMoveStringLiteralDfa1_0(0x8000L); + case 91: + return jjStopAtPos(0, 29); + case 93: + return jjStopAtPos(0, 30); + case 123: + return jjStopAtPos(0, 26); + case 125: + return jjStopAtPos(0, 27); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveStringLiteralDfa1_0(long active0) +{ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 61: + if ((active0 & 0x400000L) != 0L) + return jjStopAtPos(1, 22); + else if ((active0 & 0x800000L) != 0L) + return jjStopAtPos(1, 23); + break; + case 78: + return jjMoveStringLiteralDfa2_0(active0, 0x20000L); + case 79: + return jjMoveStringLiteralDfa2_0(active0, 0x18000L); + case 82: + if ((active0 & 0x40000L) != 0L) + return jjStopAtPos(1, 18); + break; + default : + break; + } + return jjStartNfa_0(0, active0); +} +private int jjMoveStringLiteralDfa2_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0); + return 2; + } + switch(curChar) + { + case 68: + if ((active0 & 0x20000L) != 0L) + return jjStopAtPos(2, 17); + break; + case 80: + if ((active0 & 0x8000L) != 0L) + return jjStopAtPos(2, 15); + break; + case 84: + return jjMoveStringLiteralDfa3_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(1, active0); +} +private int jjMoveStringLiteralDfa3_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0); + return 3; + } + switch(curChar) + { + case 84: + return jjMoveStringLiteralDfa4_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(2, active0); +} +private int jjMoveStringLiteralDfa4_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0); + return 4; + } + switch(curChar) + { + case 79: + return jjMoveStringLiteralDfa5_0(active0, 0x10000L); + default : + break; + } + return jjStartNfa_0(3, active0); +} +private int jjMoveStringLiteralDfa5_0(long old0, long active0) +{ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0); + return 5; + } + switch(curChar) + { + case 77: + if ((active0 & 0x10000L) != 0L) + return jjStopAtPos(5, 16); + break; + default : + break; + } + return jjStartNfa_0(4, active0); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 53; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 13) + kind = 13; + jjCheckNAddStates(0, 2); + } + else if (curChar == 48) + { + if (kind > 13) + kind = 13; + jjCheckNAdd(50); + } + else if (curChar == 47) + jjAddStates(3, 5); + else if (curChar == 34) + jjCheckNAddTwoStates(21, 22); + break; + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 12) + kind = 12; + jjstateSet[jjnewStateCnt++] = 1; + break; + case 20: + if (curChar == 34) + jjCheckNAddTwoStates(21, 22); + break; + case 21: + if ((0xfffffffbffffdbffL & l) != 0L) + jjCheckNAddTwoStates(21, 22); + break; + case 22: + if (curChar == 34 && kind > 24) + kind = 24; + break; + case 28: + if (curChar == 47) + jjAddStates(3, 5); + break; + case 29: + if (curChar == 47) + jjCheckNAddStates(6, 8); + break; + case 30: + if ((0xffffffffffffdbffL & l) != 0L) + jjCheckNAddStates(6, 8); + break; + case 31: + if ((0x2400L & l) != 0L && kind > 5) + kind = 5; + break; + case 32: + if (curChar == 10 && kind > 5) + kind = 5; + break; + case 33: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 32; + break; + case 34: + if (curChar == 42) + jjCheckNAddTwoStates(35, 36); + break; + case 35: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(35, 36); + break; + case 36: + if (curChar == 42) + jjCheckNAddStates(9, 11); + break; + case 37: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 38: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 39: + if (curChar == 47 && kind > 6) + kind = 6; + break; + case 40: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 34; + break; + case 41: + if (curChar == 42) + jjCheckNAddTwoStates(42, 43); + break; + case 42: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(42, 43); + break; + case 43: + if (curChar == 42) + jjCheckNAddStates(12, 14); + break; + case 44: + if ((0xffff7bffffffffffL & l) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + case 45: + if ((0xfffffbffffffffffL & l) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + case 46: + if (curChar == 47 && kind > 7) + kind = 7; + break; + case 47: + if ((0x3fe000000000000L & l) == 0L) + break; + if (kind > 13) + kind = 13; + jjCheckNAddStates(0, 2); + break; + case 48: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 13) + kind = 13; + jjCheckNAdd(48); + break; + case 49: + if ((0x3ff000000000000L & l) != 0L) + jjCheckNAddTwoStates(49, 50); + break; + case 50: + if (curChar != 46) + break; + if (kind > 14) + kind = 14; + jjCheckNAdd(51); + break; + case 51: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 14) + kind = 14; + jjCheckNAdd(51); + break; + case 52: + if (curChar != 48) + break; + if (kind > 13) + kind = 13; + jjCheckNAdd(50); + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x7fffffe00000000L & l) != 0L) + { + if (kind > 12) + kind = 12; + jjCheckNAdd(1); + } + else if (curChar == 78) + jjAddStates(15, 16); + else if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 18; + else if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 13; + else if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 10; + else if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 1: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 12) + kind = 12; + jjCheckNAdd(1); + break; + case 2: + if (curChar == 83 && kind > 19) + kind = 19; + break; + case 3: + if (curChar == 84) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 4: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 3; + break; + case 5: + if (curChar == 73) + jjstateSet[jjnewStateCnt++] = 4; + break; + case 6: + if (curChar == 88) + jjstateSet[jjnewStateCnt++] = 5; + break; + case 7: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 8: + if (curChar == 69 && kind > 19) + kind = 19; + break; + case 9: + if (curChar == 77) + jjstateSet[jjnewStateCnt++] = 8; + break; + case 10: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 9; + break; + case 11: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 12: + if (curChar == 76 && kind > 20) + kind = 20; + break; + case 13: + case 15: + if (curChar == 76) + jjCheckNAdd(12); + break; + case 14: + if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 13; + break; + case 16: + if (curChar == 65) + jjstateSet[jjnewStateCnt++] = 15; + break; + case 17: + if (curChar == 82) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 18: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 18; + break; + case 21: + if ((0xffffffffefffffffL & l) != 0L) + jjAddStates(17, 18); + break; + case 23: + if (curChar == 78) + jjAddStates(15, 16); + break; + case 24: + if (curChar == 71 && kind > 21) + kind = 21; + break; + case 25: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 24; + break; + case 26: + if (curChar == 84 && kind > 21) + kind = 21; + break; + case 27: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 26; + break; + case 30: + jjAddStates(6, 8); + break; + case 35: + jjCheckNAddTwoStates(35, 36); + break; + case 37: + case 38: + jjCheckNAddTwoStates(38, 36); + break; + case 42: + jjCheckNAddTwoStates(42, 43); + break; + case 44: + case 45: + jjCheckNAddTwoStates(45, 43); + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 21: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(17, 18); + break; + case 30: + if ((jjbitVec0[i2] & l2) != 0L) + jjAddStates(6, 8); + break; + case 35: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(35, 36); + break; + case 37: + case 38: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(38, 36); + break; + case 42: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(42, 43); + break; + case 44: + case 45: + if ((jjbitVec0[i2] & l2) != 0L) + jjCheckNAddTwoStates(45, 43); + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + if ((i = jjnewStateCnt) == (startsAt = 53 - (jjnewStateCnt = startsAt))) + return curPos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return curPos; } + } +} +static final int[] jjnextStates = { + 48, 49, 50, 29, 40, 41, 30, 31, 33, 36, 37, 39, 43, 44, 46, 25, + 27, 21, 22, +}; + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, "\56", "\73", "\53", "\55", null, +null, null, "\124\117\120", "\102\117\124\124\117\115", "\101\116\104", "\117\122", +null, null, null, "\76\75", "\74\75", null, "\75", "\173", "\175", "\54", "\133", +"\135", "\50", "\51", "\72", }; + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; +static final long[] jjtoToken = { + 0x3ffffff01L, +}; +static final long[] jjtoSkip = { + 0xfeL, +}; +protected SimpleCharStream input_stream; +private final int[] jjrounds = new int[53]; +private final int[] jjstateSet = new int[106]; +protected char curChar; +/** Constructor. */ +public ConfParserTokenManager(SimpleCharStream stream){ + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + input_stream = stream; +} + +/** Constructor. */ +public ConfParserTokenManager(SimpleCharStream stream, int lexState){ + this(stream); + SwitchTo(lexState); +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream) +{ + jjmatchedPos = jjnewStateCnt = 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); +} +private void ReInitRounds() +{ + int i; + jjround = 0x80000001; + for (i = 53; i-- > 0;) + jjrounds[i] = 0x80000000; +} + +/** Reinitialise parser. */ +public void ReInit(SimpleCharStream stream, int lexState) +{ + ReInit(stream); + SwitchTo(lexState); +} + +/** Switch to specified lex state. */ +public void SwitchTo(int lexState) +{ + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; +} + +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop : + for (;;) + { + try + { + curChar = input_stream.BeginToken(); + } + catch(java.io.IOException e) + { + jjmatchedKind = 0; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) + curChar = input_stream.BeginToken(); + } + catch (java.io.IOException e1) { continue EOFLoop; } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { input_stream.readChar(); input_stream.backup(1); } + catch (java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.GetImage(); + } + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); + } +} + +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/ParseException.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ParseException.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ParseException.java 2011-08-26 17:55:02 UTC (rev 3132) @@ -0,0 +1,187 @@ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ +package org.dllearner.confparser3; + +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long s... [truncated message content] |
From: <jen...@us...> - 2011-08-26 19:33:47
|
Revision: 3134 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3134&view=rev Author: jenslehmann Date: 2011-08-26 19:33:41 +0000 (Fri, 26 Aug 2011) Log Message: ----------- implemented prefix replacement in conf files via post processing directives Modified Paths: -------------- trunk/examples/family/father.conf trunk/examples/family/father_new.conf trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java Added Paths: ----------- trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/examples/family/father.conf 2011-08-26 19:33:41 UTC (rev 3134) @@ -15,7 +15,6 @@ // reasoner reasoner.type = "fast instance checker" reasoner.reasonerComponent = component:embeddedReasoner -reasoner.sources = {"component:ks"} embeddedReasoner.type = "org.dllearner.reasoning.OWLAPIReasoner" embeddedReasoner.sources = {"component:ks"} Modified: trunk/examples/family/father_new.conf =================================================================== --- trunk/examples/family/father_new.conf 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/examples/family/father_new.conf 2011-08-26 19:33:41 UTC (rev 3134) @@ -7,6 +7,9 @@ * Copyright (C) 2007, Jens Lehmann */ +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] + // knowledge source definition ks.type = "KB file" ks.url = "father.kb" @@ -15,15 +18,14 @@ // reasoner reasoner.type = "fast instance checker" reasoner.reasonerComponent = embeddedReasoner -reasoner.sources = { ks } embeddedReasoner.type = "OWL API Reasoner" embeddedReasoner.sources = { ks } // learning problem lp.type = "posNegStandard" -lp.positiveExamples = {"http://localhost/foo#stefan","http://localhost/foo#markus","http://localhost/foo#bernd"} -lp.negativeExamples = {"http://localhost/foo#heinz","http://localhost/foo#anna","http://localhost/foo#gabi","http://localhost/foo#michelle"} +lp.positiveExamples = {"kb:stefan","kb:markus","kb:bernd"} +lp.negativeExamples = {"kb:heinz","kb:anna","kb:gabi","kb:michelle"} // plug a reasoner into the learning problem lp.reasoner = reasoner Modified: trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -44,6 +44,7 @@ // TODO: Do we want to store the actual value as object here or leave it up to // the corresponding PropertyEditor to create it? + @Deprecated private Object valueObject; public ConfFileOption2() { @@ -90,10 +91,12 @@ this.propertyType = propertyType; } + @Deprecated public Object getValueObject() { return valueObject; } + @Deprecated public void setValueObject(Object valueObject) { this.valueObject = valueObject; } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -17,6 +17,9 @@ public class ConfParser implements ConfParserConstants { + // special directives (those without a property name) + private Map<String,ConfFileOption2> specialOptions = new HashMap<String,ConfFileOption2>(); + // conf file options private List<ConfFileOption2> confOptions = new LinkedList<ConfFileOption2>(); private Map<String,ConfFileOption2> confOptionsByProperty = new HashMap<String,ConfFileOption2>(); @@ -74,9 +77,15 @@ break label_1; } confOption = ConfOption(); - addConfOption(confOption); + if(confOption.getPropertyName() == null) { + specialOptions.put(confOption.getBeanName(),confOption); + } else { + addConfOption(confOption); + } } jj_consume_token(0); + PostProcessor pp = new PostProcessor(confOptions, specialOptions); + pp.applyAll(); } final public ConfFileOption2 ConfOption() throws ParseException { @@ -89,7 +98,7 @@ boolean inQuotes = false; String beanName; String propertyName = ""; - String propertyValue; + String propertyValue = ""; Class<?> propertyType; Object val = null; beanName = Id(); @@ -129,7 +138,7 @@ propertyValue = val.toString(); propertyType = Double.class; break; default: - jj_la1[6] = jj_gen; + jj_la1[2] = jj_gen; if (jj_2_4(2147483647)) { jj_consume_token(14); jj_consume_token(15); @@ -144,13 +153,13 @@ break label_2; } tmp = String(); - values.add(tmp); + values.add(tmp); propertyValue += "\u005c"" + tmp + "\u005c", "; jj_consume_token(16); } tmp = String(); - values.add(tmp); + values.add(tmp); propertyValue += "\u005c"" + tmp + "\u005c""; jj_consume_token(15); - propertyType = Set.class; propertyValue = "{ TODO }"; val = values; inQuotes = true; + propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; inQuotes = true; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 14: @@ -163,16 +172,16 @@ break label_3; } tmp = Id(); - values.add(tmp); + values.add(tmp); propertyValue += tmp + ", "; jj_consume_token(16); } tmp = Id(); - values.add(tmp); + values.add(tmp); propertyValue += tmp; jj_consume_token(15); - val = values; propertyType = Set.class; propertyValue = "{ TODO }"; + val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; break; default: - jj_la1[7] = jj_gen; + jj_la1[3] = jj_gen; if (jj_2_6(2147483647)) { jj_consume_token(17); jj_consume_token(18); @@ -189,68 +198,24 @@ break label_4; } jj_consume_token(19); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp = String(); - break; - case ID: - tmp = Id(); - break; - default: - jj_la1[2] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp = String(); jj_consume_token(16); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp2 = String(); - break; - case ID: - tmp2 = Id(); - break; - default: - jj_la1[3] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp2 = String(); jj_consume_token(20); - tuples.add(new StringTuple(tmp,tmp2)); + tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\u005c""+ tmp + "\u005c",\u005c"" + tmp2 + "\u005c"), "; jj_consume_token(16); } jj_consume_token(19); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp = String(); - break; - case ID: - tmp = Id(); - break; - default: - jj_la1[4] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp = String(); jj_consume_token(16); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp2 = String(); - break; - case ID: - tmp2 = Id(); - break; - default: - jj_la1[5] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp2 = String(); jj_consume_token(20); - tuples.add(new StringTuple(tmp,tmp2)); + tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\u005c""+ tmp + "\u005c",\u005c"" + tmp2 + "\u005c")"; jj_consume_token(18); - val = values; propertyType = List.class; + val = tuples; propertyType = List.class; propertyValue = "["+ propertyValue + "]"; break; default: - jj_la1[8] = jj_gen; + jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -258,15 +223,14 @@ } } } + option.setInQuotes(inQuotes); + option.setBeanName(beanName); if(containsSubOption) { - option.setInQuotes(inQuotes); - option.setBeanName(beanName); option.setPropertyName(propertyName); - option.setPropertyType(propertyType); - option.setValueObject(val); - } else { - // ... currently nothing here (maybe special parser directives) } + option.setPropertyType(propertyType); + option.setPropertyValue(propertyValue); + option.setValueObject(val); {if (true) return option;} throw new Error("Missing return statement in function"); } @@ -281,7 +245,7 @@ name = String(); break; default: - jj_la1[9] = jj_gen; + jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -303,7 +267,7 @@ {if (true) return t1.image;} break; default: - jj_la1[10] = jj_gen; + jj_la1[6] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -392,38 +356,6 @@ finally { jj_save(6, xla); } } - private boolean jj_3_2() { - if (jj_3R_6()) return true; - if (jj_scan_token(16)) return true; - return false; - } - - private boolean jj_3R_10() { - if (jj_3R_6()) return true; - return false; - } - - private boolean jj_3R_7() { - if (jj_3R_5()) return true; - return false; - } - - private boolean jj_3_4() { - if (jj_scan_token(14)) return true; - if (jj_scan_token(15)) return true; - return false; - } - - private boolean jj_3R_6() { - if (jj_scan_token(ID)) return true; - return false; - } - - private boolean jj_3R_8() { - if (jj_3R_6()) return true; - return false; - } - private boolean jj_3_5() { if (jj_scan_token(14)) return true; Token xsp; @@ -454,11 +386,6 @@ return false; } - private boolean jj_3R_9() { - if (jj_3R_5()) return true; - return false; - } - private boolean jj_3R_5() { if (jj_scan_token(STRING)) return true; return false; @@ -466,23 +393,31 @@ private boolean jj_3_3() { if (jj_scan_token(19)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_7()) { - jj_scanpos = xsp; - if (jj_3R_8()) return true; - } + if (jj_3R_5()) return true; if (jj_scan_token(16)) return true; - xsp = jj_scanpos; - if (jj_3R_9()) { - jj_scanpos = xsp; - if (jj_3R_10()) return true; - } + if (jj_3R_5()) return true; if (jj_scan_token(20)) return true; if (jj_scan_token(16)) return true; return false; } + private boolean jj_3_2() { + if (jj_3R_6()) return true; + if (jj_scan_token(16)) return true; + return false; + } + + private boolean jj_3_4() { + if (jj_scan_token(14)) return true; + if (jj_scan_token(15)) return true; + return false; + } + + private boolean jj_3R_6() { + if (jj_scan_token(ID)) return true; + return false; + } + /** Generated Token Manager. */ public ConfParserTokenManager token_source; SimpleCharStream jj_input_stream; @@ -494,13 +429,13 @@ private Token jj_scanpos, jj_lastpos; private int jj_la; private int jj_gen; - final private int[] jj_la1 = new int[11]; + final private int[] jj_la1 = new int[7]; static private int[] jj_la1_0; static { jj_la1_init_0(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x200,0x100,0x1200,0x1200,0x1200,0x1200,0x1e00,0x4000,0x20000,0x1200,0x200,}; + jj_la1_0 = new int[] {0x200,0x100,0x1e00,0x4000,0x20000,0x1200,0x200,}; } final private JJCalls[] jj_2_rtns = new JJCalls[7]; private boolean jj_rescan = false; @@ -517,7 +452,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -532,7 +467,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -543,7 +478,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -554,7 +489,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -564,7 +499,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -574,7 +509,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -691,7 +626,7 @@ la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 11; i++) { + for (int i = 0; i < 7; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<<j)) != 0) { Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -0,0 +1,66 @@ +/** + * 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.confparser3; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.dllearner.cli.ConfFileOption2; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * Performs post processing of conf files based on special parsing directives. + * + * @author Jens Lehmann + * + */ +public class PostProcessor { + + List<ConfFileOption2> confOptions; + Map<String, ConfFileOption2> directives; + + public PostProcessor(List<ConfFileOption2> confOptions, Map<String, ConfFileOption2> directives) { + this.confOptions = confOptions; + this.directives = directives; + } + + /** + * Applies all special directives by modifying the conf options. + */ + public void applyAll() { + // apply prefix directive + ConfFileOption2 prefixOption = directives.get("prefixes"); + if(prefixOption != null) { + List<StringTuple> prefixes = (List<StringTuple>) prefixOption.getValueObject(); + + // loop through all options and replaces prefixes + for(ConfFileOption2 option : confOptions) { + String value = option.getPropertyValue(); + for(StringTuple prefix : prefixes) { + // we only replace the prefix if it occurs directly after a quote + value = value.replaceAll("\"" + prefix.a + ":", "\"" + prefix.b); + } + option.setPropertyValue(value); + } + } + } +} Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-26 19:33:41 UTC (rev 3134) @@ -47,6 +47,9 @@ public class ConfParser { + // special directives (those without a property name) + private Map<String,ConfFileOption2> specialOptions = new HashMap<String,ConfFileOption2>(); + // conf file options private List<ConfFileOption2> confOptions = new LinkedList<ConfFileOption2>(); private Map<String,ConfFileOption2> confOptionsByProperty = new HashMap<String,ConfFileOption2>(); @@ -120,9 +123,16 @@ } { ( confOption = ConfOption() - { addConfOption(confOption); } + { if(confOption.getPropertyName() == null) { + specialOptions.put(confOption.getBeanName(),confOption); + } else { + addConfOption(confOption); + } + } )* <EOF> + { PostProcessor pp = new PostProcessor(confOptions, specialOptions); + pp.applyAll(); } } ConfFileOption2 ConfOption() : @@ -136,7 +146,7 @@ boolean inQuotes = false; String beanName; String propertyName = ""; - String propertyValue; + String propertyValue = ""; Class<?> propertyType; Object val = null; } @@ -158,35 +168,34 @@ // empty set | LOOKAHEAD("{" "}") "{" "}" { val = new HashSet(); propertyType = Set.class; propertyValue = "{}"; } // set with several elements which are quoted - | LOOKAHEAD(4) "{" ( LOOKAHEAD(2) tmp=String() { values.add(tmp);} "," )* - tmp=String() {values.add(tmp);} "}" - { propertyType = Set.class; propertyValue = "{ TODO }"; val = values; inQuotes = true;} + | LOOKAHEAD(4) "{" ( LOOKAHEAD(2) tmp=String() { values.add(tmp); propertyValue += "\"" + tmp + "\", ";} "," )* + tmp=String() {values.add(tmp); propertyValue += "\"" + tmp + "\"";} "}" + { propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; inQuotes = true;} // set with several elements which are not quoted - | "{" ( LOOKAHEAD(4) tmp=Id() { values.add(tmp);} "," )* - ( tmp=Id()) {values.add(tmp);} "}" - { val = values; propertyType = Set.class; propertyValue = "{ TODO }"; } + | "{" ( LOOKAHEAD(4) tmp=Id() { values.add(tmp); propertyValue += tmp + ", "; } "," )* + ( tmp=Id()) {values.add(tmp); propertyValue += tmp;} "}" + { val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; } // empty list | LOOKAHEAD("[" "]") "[" "]" { val = new LinkedList(); propertyType = List.class; propertyValue = "[]";} // a list with several elements, which tuples // e.g. [("a","b"),("c","d")] | "[" - ( LOOKAHEAD(6) "(" (tmp=String() | tmp=Id()) "," (tmp2=String() | tmp2=Id()) ")" - {tuples.add(new StringTuple(tmp,tmp2));} "," )* - "(" (tmp=String() | tmp=Id()) "," (tmp2=String() | tmp2=Id()) ")" - {tuples.add(new StringTuple(tmp,tmp2));} - "]" { val = values; propertyType = List.class;} + ( LOOKAHEAD(6) "(" tmp=String() "," tmp2=String() ")" + {tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\""+ tmp + "\",\"" + tmp2 + "\"), "; } "," )* + "(" tmp=String() "," tmp2=String() ")" + {tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\""+ tmp + "\",\"" + tmp2 + "\")";} + "]" { val = tuples; propertyType = List.class; propertyValue = "["+ propertyValue + "]";} ) // <CONF_END> { - if(containsSubOption) { - option.setInQuotes(inQuotes); - option.setBeanName(beanName); + option.setInQuotes(inQuotes); + option.setBeanName(beanName); + if(containsSubOption) { option.setPropertyName(propertyName); - option.setPropertyType(propertyType); - option.setValueObject(val); - } else { - // ... currently nothing here (maybe special parser directives) } + option.setPropertyType(propertyType); + option.setPropertyValue(propertyValue); + option.setValueObject(val); return option; } } Modified: trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -15,7 +15,7 @@ public void test() throws FileNotFoundException, ParseException { ConfParser parser = ConfParser.parseFile(new File("../examples/family/father_new.conf")); for(ConfFileOption2 option : parser.getConfOptions()) { - System.out.print(option.getBeanName() + "." + option.getPropertyName() + " = " + option.getValueObject()); + System.out.print(option.getBeanName() + "." + option.getPropertyName() + " = " + option.getPropertyValue()); if((option.getPropertyType().equals(String.class) || option.getPropertyType().equals(Set.class)) && !option.isInQuotes()) { System.out.println(" (bean reference)"); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2011-08-27 20:07:16
|
Revision: 3140 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3140&view=rev Author: shadowtm Date: 2011-08-27 20:07:08 +0000 (Sat, 27 Aug 2011) Log Message: ----------- Moved over to the confparser3 version of configuration syntax - also made Map and Set property editors. Created Property Editors for Sets of Individuals on the PosNegLP class. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj trunk/interfaces/src/main/resources/org/dllearner/configuration/spring/bean-post-processor-configuration.xml trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/configuration/IConfigurationProperty.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java trunk/interfaces/src/main/java/org/dllearner/confparser3/IndividualCollectionEditor.java trunk/interfaces/src/main/java/org/dllearner/confparser3/MapEditor.java trunk/interfaces/src/main/java/org/dllearner/confparser3/SetEditor.java Removed Paths: ------------- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurer.java Modified: trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -94,4 +94,7 @@ public String getBaseDir(); + public Collection<IConfigurationProperty> getConfigurationOptions(String beanName); + + } Added: trunk/components-core/src/main/java/org/dllearner/configuration/IConfigurationProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/configuration/IConfigurationProperty.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/configuration/IConfigurationProperty.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -0,0 +1,49 @@ +package org.dllearner.configuration; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/27/11 + * Time: 8:57 AM + * + * Respresents a Configuraiton Option setting. + */ +public interface IConfigurationProperty { + + /** + * Get the Name of this Property + * + * @return The Name of this property. + */ + public String getName(); + + + /** + * Get the String representation of the value of this property. + * + * @return The String representation of the value of this property. + */ + public String getValue(); + + /** + * Get the type of this value. + * + * @return The type of this value. + */ + public Class getType(); + + + /** + * Does this property represent a bean reference? + * + * @return True if it does. + */ + public boolean isBeanReference(); + + /** + * Does this property represent a collection of bean references? + * + * @return True if it does. + */ + public boolean isBeanReferenceCollection(); +} Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -80,6 +80,7 @@ "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.PosOnlyLP", "org.dllearner.reasoning.FastInstanceChecker", + "org.dllearner.reasoning.OWLAPIReasoner", "org.dllearner.algorithms.ocel.OCEL", "org.dllearner.algorithms.ocel.MultiHeuristic", "org.dllearner.refinementoperators.RhoDRDown", Modified: trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -20,6 +20,8 @@ package org.dllearner.cli; +import org.dllearner.configuration.IConfigurationProperty; + /** * Programmatic representation of an option setting in a conf file: * bean.property = value; @@ -29,10 +31,12 @@ * @author Jens Lehmann * */ -public class ConfFileOption2 { +public class ConfFileOption2 implements IConfigurationProperty{ // a boolean flag which indicates whether it is a reference to a bean (or set/list of beans) private boolean isBeanRef; + + private boolean isBeanReferenceCollection; private String beanName; @@ -101,5 +105,34 @@ public void setBeanRef(boolean isBeanRef) { this.isBeanRef = isBeanRef; } - + + @Override + public String getName() { + return getPropertyName(); + } + + @Override + public String getValue() { + return getPropertyValue(); + } + + @Override + public boolean isBeanReference() { + return isBeanRef(); + } + + @Override + public Class getType() { + return getPropertyType(); + } + + @Override + public boolean isBeanReferenceCollection() { + return isBeanReferenceCollection; + } + + public void setBeanReferenceCollection(boolean beanReferenceCollection) { + isBeanReferenceCollection = beanReferenceCollection; + } + } Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -1,23 +1,27 @@ package org.dllearner.configuration.spring; import org.dllearner.configuration.IConfiguration; +import org.dllearner.configuration.IConfigurationProperty; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; +import org.springframework.beans.factory.support.ManagedSet; import java.util.Collection; +import java.util.StringTokenizer; /** * Created by IntelliJ IDEA. * User: Chris * Date: 8/22/11 * Time: 6:38 AM - * + * <p/> * This class is used to insert BeanDefinitions that are declared in the configuration file that * do not exist in the existing registry (ie. they aren't declared in the spring XML file). */ @@ -29,23 +33,24 @@ this.configuration = configuration; } + /** + * Ensure that BeanDefinitions exist for all referenced beans in the configuration. + * + * @param registry The Bean registry to use. + * @throws BeansException + */ @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { - Collection<String> beanNames = configuration.getBeanNames(); + final Collection<String> beanNames = configuration.getBeanNames(); for (String beanName : beanNames) { - if(!registry.containsBeanDefinition(beanName)){ + if (!registry.containsBeanDefinition(beanName)) { Class beanClass = configuration.getClass(beanName); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClass); BeanDefinition definition = builder.getBeanDefinition(); - /** Add Base Directory */ - if(beanClass.isAssignableFrom(KBFile.class) || beanClass.isAssignableFrom(OWLFile.class)){ - definition.getPropertyValues().addPropertyValue("baseDir",configuration.getBaseDir()); - } - - registry.registerBeanDefinition(beanName,definition); + registry.registerBeanDefinition(beanName, definition); } } @@ -53,6 +58,59 @@ @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - /** Do nothing here */ + + final Collection<String> beanNames = configuration.getBeanNames(); + + + for (String beanName : beanNames) { + + BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); + + Collection<IConfigurationProperty> properties = configuration.getConfigurationOptions(beanName); + + for (IConfigurationProperty property : properties) { + + Object value = property.getValue(); + //Process Single Bean References + if (property.isBeanReference()) { + BeanDefinition referencedBean = beanFactory.getBeanDefinition(property.getValue()); + value = referencedBean; + } + + //Process collections of bean references + if(property.isBeanReferenceCollection()){ + StringTokenizer tokenizer = new StringTokenizer(property.getValue(),"{,} ",false); + Collection<RuntimeBeanReference> beanReferences = new ManagedSet<RuntimeBeanReference>(); + while(tokenizer.hasMoreTokens()){ + String referencedBeanName = tokenizer.nextToken(); + beanReferences.add(new RuntimeBeanReference(referencedBeanName)); + } + value = beanReferences; + } + + addBaseDirectoryIfNeeded(beanDefinition); + + beanDefinition.getPropertyValues().add(property.getName(), value); + } + } } + + /** + * Add Base Directory Value to Beans which need it. + * + * @param beanDefinition The curren Bean Definition + */ + private void addBaseDirectoryIfNeeded(BeanDefinition beanDefinition) { + Class beanClass = null; + try { + beanClass = Class.forName(beanDefinition.getBeanClassName()); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Can't find class " + beanDefinition.getBeanClassName()); + } + /** Add Base Directory */ + if (beanClass.isAssignableFrom(KBFile.class) || beanClass.isAssignableFrom(OWLFile.class)) { + beanDefinition.getPropertyValues().add("baseDir", configuration.getBaseDir()); + } + } + } Deleted: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurer.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurer.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurer.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -1,209 +0,0 @@ -package org.dllearner.configuration.spring; - -import org.dllearner.configuration.IConfiguration; -import org.springframework.beans.PropertyValue; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyOverrideConfigurer; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.support.ManagedSet; - -import java.util.*; - -/** - * Created by IntelliJ IDEA. - * User: Chris - * Date: 8/18/11 - * Time: 9:12 PM - * <p/> - * Extending the Custom Property Override Configurer so that we can use our IConfiguration objects - * in conjunction with a Spring Based Configuration. - */ -public class ConfigurationBasedPropertyOverrideConfigurer extends PropertyOverrideConfigurer { - - - private final IConfiguration configuration; - private boolean ignoreInvalidKeys = false; - private List<String> componentKeyPrefixes = new ArrayList<String>(); - - /** - * Primary Constructor. - * - * @param configuration The DL-Learner Configuration object. - * @param ignoreInvalidKeys Consult the PropertyOverrideConfigurer documentation for the usage of this variable. - */ - public ConfigurationBasedPropertyOverrideConfigurer(IConfiguration configuration, boolean ignoreInvalidKeys) { - super(); - this.configuration = configuration; - this.ignoreInvalidKeys = ignoreInvalidKeys; - setIgnoreInvalidKeys(false); - } - - @Override - protected void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String value) { - - BeanDefinition bd = getBeanDefinition(factory, beanName); - - Object obj = buildObject(beanName, property); - - applyPropertyValue(factory, beanName, property, bd, obj); - - - } - - /** - * Build the object represented by beanName.property as it is represented in the configuration. - * - * @param beanName The bean name of the object to build - * @param property The property name of the object to build - * @return The object represented by beanName.property - */ - protected Object buildObject(String beanName, String property) { - StringBuilder objKey = buildObjectKey(beanName, property); - return configuration.getObjectValue(objKey.toString()); - } - - /** - * Get the Bean Definition for a particular bean. - * - * @param factory The factory to get the bean from. - * @param beanName The bean to get. - * @return The bean definition of beanName - */ - protected BeanDefinition getBeanDefinition(ConfigurableListableBeanFactory factory, String beanName) { - BeanDefinition bd = factory.getBeanDefinition(beanName); - while (bd.getOriginatingBeanDefinition() != null) { - bd = bd.getOriginatingBeanDefinition(); - } - return bd; - } - - /** - * Apply obj to a property value. - * @param factory - * @param beanName - * @param property - * @param bd - * @param obj - */ - private void applyPropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, BeanDefinition bd, Object obj) { - /** Check if Object represents a ReferencedBean */ - String referencedBeanName = getReferencedBeanName(obj); - if (referencedBeanName != null && !referencedBeanName.isEmpty()) { - applyBeanReferencePropertyValue(factory, beanName, property, referencedBeanName); - } else { - //TODO I don't like this code - refactor to make it more elegant later - if(obj instanceof Collection){ - /** Now check for a Collection of component references */ - Collection collection = (Collection) obj; - - /** TODO: Now we only work with Sets as that is what comes from the configuration - but we should probably support other collection types as well */ - /** The managed set is the key to getting this to work - there are other managed objects we could use in the future */ - Collection components = new ManagedSet(); - - for (Object o : collection) { - if(o instanceof String){ - referencedBeanName = getReferencedBeanName(o); - if(referencedBeanName != null && !referencedBeanName.isEmpty()){ - components.add(new RuntimeBeanReference(referencedBeanName)); - } - } - } - if (components.isEmpty()) { - applyRegularPropertyValue(property, bd, obj); - } else { - bd.getPropertyValues().addPropertyValue(property, components); - } - - }else{ - /** We have a regular property value */ - applyRegularPropertyValue(property, bd, obj); - } - } - } - - private void applyRegularPropertyValue(String property, BeanDefinition bd, Object obj) { - PropertyValue pv = new PropertyValue(property, obj); - pv.setOptional(ignoreInvalidKeys); - bd.getPropertyValues().addPropertyValue(pv); - } - - /** - * Apply a bean reference to beanName.property in the given factory. - * - * @param factory The factory to use. - * @param beanName The bean name - * @param property The property name. - * @param referencedBean The referenced bean to set as bean.property in factory. - */ - private void applyBeanReferencePropertyValue(ConfigurableListableBeanFactory factory, String beanName, String property, String referencedBean) { - BeanDefinition bd = getBeanDefinition(factory, beanName); - /** You have to get the bean definition of the referenced bean here - don't try to get the bean itself or you'll get a objects which aren't completely initialized yet */ - Object obj = factory.getBeanDefinition(referencedBean); - bd.getPropertyValues().addPropertyValue(property, obj); - } - - /** - * Build the object key which is just name beanName.property or beanName if property is null. - * @param beanName First part of the key. - * @param property Second part of the key (after the period). - * @return The object key. - */ - private StringBuilder buildObjectKey(String beanName, String property) { - StringBuilder objName = new StringBuilder(); - objName.append(beanName); - if (property != null && !property.isEmpty()) { - objName.append("."); - objName.append(property); - } - return objName; - } - - /** - * Determine if value is a name of a referenced bean. - * <p/> - * This will return the name of the referenced bean if it does. If not, it will return null. - * - * @param object The object to check. - * @return True if we need to do custom loading of this value, false if we can use the parent. - */ - protected String getReferencedBeanName(Object object) { - - String result = null; - - boolean found = false; - - Iterator<String> itr = getComponentKeyPrefixes().iterator(); - - if (object instanceof String) { - String value = (String) object; - while (!found && itr.hasNext()) { - String prefix = itr.next(); - if (value.startsWith(prefix)) { - found = true; - result = value.substring(prefix.length()); - } - } - } - return result; - - } - - /** - * Get the list of prefixes that cause us to do custom loading. - * - * @return The list of prefixes that cause us to do custom loading. - */ - public List<String> getComponentKeyPrefixes() { - return componentKeyPrefixes; - } - - /** - * Set the list of prefixes that cause us to do custom loading. - * - * @param componentKeyPrefixes the list of prefixes that cause us to do custom loading. - */ - public void setComponentKeyPrefixes(List<String> componentKeyPrefixes) { - this.componentKeyPrefixes = componentKeyPrefixes; - } -} Added: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/CustomPropertyEditorRegistrar.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -0,0 +1,43 @@ +package org.dllearner.configuration.spring; + +import org.dllearner.confparser3.IndividualCollectionEditor; +import org.dllearner.confparser3.MapEditor; +import org.dllearner.confparser3.SetEditor; +import org.dllearner.learningproblems.PosNegLP; +import org.springframework.beans.BeanWrapper; +import org.springframework.beans.PropertyEditorRegistrar; +import org.springframework.beans.PropertyEditorRegistry; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/27/11 + * Time: 12:38 PM + * <p/> + * This is where we will register custom property editors for properties which can't be configured by the standard + * PropertyEditors. + */ +public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar { + + @Override + public void registerCustomEditors(PropertyEditorRegistry registry) { + + if (registry instanceof BeanWrapper) { + Object wrappedInstance = ((BeanWrapper) registry).getWrappedInstance(); + if (wrappedInstance instanceof PosNegLP) { + registry.registerCustomEditor(Collection.class, "positiveExamples", new IndividualCollectionEditor()); + registry.registerCustomEditor(Collection.class, "negativeExamples", new IndividualCollectionEditor()); + } + } + + //Wrappers for all beans + registry.registerCustomEditor(Map.class,new MapEditor()); + registry.registerCustomEditor(Set.class,new SetEditor()); + + + } +} Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -29,10 +29,6 @@ // Post Processors BeanDefinitionRegistryPostProcessor beanDefinitionRegistryPostProcessor = new ConfigurationBasedBeanDefinitionRegistryPostProcessor(configuration); - ConfigurationBasedPropertyOverrideConfigurer configurer = new ConfigurationBasedPropertyOverrideConfigurer(configuration, false); - configurer.setProperties(configuration.getProperties()); - configurer.getComponentKeyPrefixes().addAll(componentKeyPrefixes); - //These files need to be loaded first List<Resource> allSpringConfigFiles = new ArrayList<Resource>(); allSpringConfigFiles.add(new ClassPathResource("/org/dllearner/configuration/spring/bean-post-processor-configuration.xml")); @@ -48,7 +44,6 @@ // These post processors run before object instantiation context.addBeanFactoryPostProcessor(beanDefinitionRegistryPostProcessor); - context.addBeanFactoryPostProcessor(configurer); //Instantiate and initialize the beans. context.refresh(); Modified: trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/confparser2/ConfParserConfiguration.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -2,6 +2,7 @@ import org.dllearner.cli.ConfFileOption; import org.dllearner.configuration.IConfiguration; +import org.dllearner.configuration.IConfigurationProperty; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.Component; import org.dllearner.utilities.datastructures.StringTuple; @@ -182,4 +183,9 @@ public String getBaseDir() { return baseDir; } + + @Override + public Collection<IConfigurationProperty> getConfigurationOptions(String beanName) { + throw new RuntimeException("Don't use this class - use the one in the confparser3 package."); + } } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -96,6 +96,7 @@ ConfFileOption2 option = new ConfFileOption2(); boolean isBeanRef = false; + boolean isBeanCollection = false; String beanName; String propertyName = ""; String propertyValue = ""; @@ -164,7 +165,7 @@ switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 17: jj_consume_token(17); - val = new HashSet(); propertyType = Set.class; propertyValue = "-"; isBeanRef = true; + val = new HashSet(); propertyType = Set.class; propertyValue = "-"; isBeanCollection = true; break; case 14: jj_consume_token(14); @@ -182,7 +183,7 @@ tmp = Id(); values.add(tmp); propertyValue += tmp; jj_consume_token(15); - val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; isBeanRef = true; + val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; isBeanCollection = true; break; default: jj_la1[3] = jj_gen; @@ -228,6 +229,7 @@ } } option.setBeanRef(isBeanRef); + option.setBeanReferenceCollection(isBeanCollection); option.setBeanName(beanName); if(containsSubOption) { option.setPropertyName(propertyName); Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -0,0 +1,125 @@ +package org.dllearner.confparser3; + +import org.dllearner.cli.ConfFileOption2; +import org.dllearner.configuration.IConfiguration; +import org.dllearner.configuration.IConfigurationProperty; +import org.dllearner.core.AnnComponentManager; +import org.dllearner.core.Component; +import org.springframework.core.io.Resource; + +import java.io.IOException; +import java.util.*; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/27/11 + * Time: 7:21 AM + * <p/> + * Conf Parser Based implementation. + */ +public class ConfParserConfiguration implements IConfiguration { + + private final ConfParser parser; + private final String baseDir; + private final String typeProperty = "type"; + + + public ConfParserConfiguration(Resource source) { + try { + baseDir = source.getFile().getAbsoluteFile().getParent(); + parser = new ConfParser(source.getInputStream()); + parser.Start(); + } catch (ParseException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public Object getObjectValue(String key) { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public Properties getProperties() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public Collection<String> getBeanNames() { + Set<String> result = new HashSet<String>(); + Map<String,List<ConfFileOption2>> beans = parser.getConfOptionsByBean(); + result.addAll(beans.keySet()); + return result; + } + + @Override + public Class getClass(String beanName) { + + List<ConfFileOption2> confOptions = parser.getConfOptionsByBean(beanName); + + ConfFileOption2 option = null; + for (ConfFileOption2 confOption : confOptions) { + if(typeProperty.equalsIgnoreCase(confOption.getPropertyName())){ + option = confOption; + } + } + + if(option == null){ + throw new RuntimeException("No type property set for bean: " + beanName); + } + + Class<?> result = null; + + String value = (String) option.getPropertyValue(); + // first option: use long name of @ComponentAnn annotation + Class<? extends Component> classFromName = AnnComponentManager.getInstance().getComponentsNamed().getKey(value); + if(classFromName != null) { + return classFromName; + } + // second option: use short name of @ComponentAnn annotation + Class<? extends Component> classFromShortName = AnnComponentManager.getInstance().getComponentsNamedShort().getKey(value); + if(classFromShortName != null) { + return classFromShortName; + } + // third option: use specified class name + try { + result = Class.forName(value); + } catch (ClassNotFoundException e) { + // if all methods fail, throw an exception + throw new RuntimeException("Problem getting class type for bean: " + beanName + " - trying to instantiate class: " + option.getPropertyValue()); + } + return result; + } + + @Override + public Set<String> getPositiveExamples() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public Set<String> getNegativeExamples() { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public String getBaseDir() { + return baseDir; + } + + @Override + public Collection<IConfigurationProperty> getConfigurationOptions(String beanName) { + List<ConfFileOption2> confFileOptions = parser.getConfOptionsByBean(beanName); + Collection<IConfigurationProperty> result = new ArrayList<IConfigurationProperty>(); + + for (ConfFileOption2 confFileOption : confFileOptions) { + + if (!typeProperty.equalsIgnoreCase(confFileOption.getPropertyName())) { + result.add(confFileOption); + } + } + return result; + } +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/IndividualCollectionEditor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/IndividualCollectionEditor.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/IndividualCollectionEditor.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -0,0 +1,39 @@ +package org.dllearner.confparser3; + +import org.dllearner.core.owl.Individual; + +import java.beans.PropertyEditorSupport; +import java.util.Collection; +import java.util.StringTokenizer; +import java.util.TreeSet; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/27/11 + * Time: 11:42 AM + * + * Property Editor for Collections of Individuals. + */ +public class IndividualCollectionEditor extends PropertyEditorSupport { + + public IndividualCollectionEditor() { + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + setValue(convert(text)); + } + + + // @Override + protected Collection<Individual> convert(String value) { + Collection<Individual> result = new TreeSet<Individual>(); + StringTokenizer tokenizer = new StringTokenizer(value, "{}\", "); + while (tokenizer.hasMoreElements()) { + result.add(new Individual(tokenizer.nextToken())); + } + return result; + } + +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/MapEditor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/MapEditor.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/MapEditor.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -0,0 +1,38 @@ +package org.dllearner.confparser3; + +import java.beans.PropertyEditorSupport; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/27/11 + * Time: 1:41 PM + * + * Convert our string structure to a Map + */ +public class MapEditor extends PropertyEditorSupport{ + + + @Override + public void setAsText(String text) throws IllegalArgumentException { + + StringTokenizer tokenizer = new StringTokenizer(text,"[(,\") ]"); + + if((tokenizer.countTokens() % 2) != 0){ + throw new RuntimeException("Expected an even number of tokens, check your map syntax: " + text); + } + + Map<String, String> result = new HashMap<String, String>(); + + while (tokenizer.hasMoreTokens()){ + String key = tokenizer.nextToken(); + String value = tokenizer.nextToken(); + result.put(key,value); + } + + setValue(result); + } +} Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/SetEditor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/SetEditor.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/SetEditor.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -0,0 +1,29 @@ +package org.dllearner.confparser3; + +import java.beans.PropertyEditorSupport; +import java.util.*; + +/** + * Created by IntelliJ IDEA. + * User: Chris + * Date: 8/27/11 + * Time: 1:57 PM + * <p/> + * Property Editor for Sets. + */ +public class SetEditor extends PropertyEditorSupport { + + @Override + public void setAsText(String text) throws IllegalArgumentException { + + StringTokenizer tokenizer = new StringTokenizer(text, "[(,\") ]"); + + Set<String> result = new HashSet<String>(); + + while (tokenizer.hasMoreTokens()) { + result.add(tokenizer.nextToken()); + } + + setValue(result); + } +} Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-27 20:07:08 UTC (rev 3140) @@ -144,6 +144,7 @@ ConfFileOption2 option = new ConfFileOption2(); boolean isBeanRef = false; + boolean isBeanCollection = false; String beanName; String propertyName = ""; String propertyValue = ""; @@ -172,11 +173,11 @@ tmp=String() {values.add(tmp); propertyValue += "\"" + tmp + "\"";} "}" { propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; } // empty bean set - | "-" { val = new HashSet(); propertyType = Set.class; propertyValue = "-"; isBeanRef = true;} + | "-" { val = new HashSet(); propertyType = Set.class; propertyValue = "-"; isBeanCollection = true;} // set with several elements which are not quoted | "{" ( LOOKAHEAD(4) tmp=Id() { values.add(tmp); propertyValue += tmp + ", "; } "," )* ( tmp=Id()) {values.add(tmp); propertyValue += tmp;} "}" - { val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; isBeanRef = true;} + { val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; isBeanCollection = true;} // empty list | LOOKAHEAD("[" "]") "[" "]" { val = new LinkedList(); propertyType = List.class; propertyValue = "[]";} // a list with several elements, which tuples @@ -191,6 +192,7 @@ // <CONF_END> { option.setBeanRef(isBeanRef); + option.setBeanReferenceCollection(isBeanCollection); option.setBeanName(beanName); if(containsSubOption) { option.setPropertyName(propertyName); @@ -214,7 +216,7 @@ } String ComplexId() : -{ +{ Token t1,t2; } { Modified: trunk/interfaces/src/main/resources/org/dllearner/configuration/spring/bean-post-processor-configuration.xml =================================================================== --- trunk/interfaces/src/main/resources/org/dllearner/configuration/spring/bean-post-processor-configuration.xml 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/main/resources/org/dllearner/configuration/spring/bean-post-processor-configuration.xml 2011-08-27 20:07:08 UTC (rev 3140) @@ -4,4 +4,15 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="org.dllearner.configuration.spring.ComponentInitializationBeanPostProcessor"/> + + <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> + <property name="propertyEditorRegistrars"> + <list> + <ref bean="customPropertyEditorRegistrar"/> + </list> + </property> + </bean> + + <bean id="customPropertyEditorRegistrar" + class="org.dllearner.configuration.spring.CustomPropertyEditorRegistrar"/> </beans> \ No newline at end of file Modified: trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -5,7 +5,7 @@ import org.dllearner.configuration.IConfiguration; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; -import org.dllearner.confparser2.ConfParserConfiguration; +import org.dllearner.confparser3.ConfParserConfiguration; import org.dllearner.learningproblems.PosNegLPStandard; import org.junit.BeforeClass; import org.junit.Test; @@ -34,7 +34,7 @@ ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); /** The DL-Learner Config File */ - Resource confFile = new FileSystemResource("../examples/family/father.conf"); + Resource confFile = new FileSystemResource("../examples/family/father_new.conf"); // confFile.getAbsoluteFile().getParent( //Component Key Prefixes Modified: trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java 2011-08-27 20:07:08 UTC (rev 3140) @@ -2,7 +2,7 @@ import junit.framework.Assert; import org.dllearner.configuration.IConfiguration; -import org.dllearner.confparser2.ConfParserConfiguration; +import org.dllearner.confparser3.ConfParserConfiguration; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -90,6 +90,7 @@ Assert.assertEquals(secondBean.getIntValue(), (Integer) 85); Assert.assertEquals(secondBean.getDoubleValue(), (Double) 178.5); Assert.assertTrue(secondBean.getSetValue().contains("e")); + Assert.assertTrue(secondBean.getSetValue().contains("f")); Assert.assertTrue(secondBean.getMapValue().get("f").equals("g")); Assert.assertTrue(secondBean.getComponent() != null); Assert.assertTrue(secondBean.getComponentSet().size() == 2); Modified: trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf =================================================================== --- trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-08-27 14:39:48 UTC (rev 3139) +++ trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-08-27 20:07:08 UTC (rev 3140) @@ -5,7 +5,7 @@ // a single line comment, which is ignored testBean.simpleValue="simple value example" // simple value -testBean.component=component:secondBean // I wonder whether we even need the component keyword or could just write beanName.property=:test; +testBean.component=secondBean // I wonder whether we even need the component keyword or could just write beanName.property=:test; testBean.intValue = 23 // an integer value @@ -17,20 +17,17 @@ // Second Bean Definition - to show loading of a referenced bean secondBean.simpleValue="second bean example" // simple value -secondBean.component=component:thirdBean //Another Bean +secondBean.component=thirdBean //Another Bean secondBean.intValue = 85 // an integer value secondBean.doubleValue = 178.5 // a double value -secondBean.setValue={"e"} // a set (list is not implemented, but can be done analogously) +secondBean.setValue={"e","f"} // a set (list is not implemented, but can be done analogously) secondBean.mapValue=[("f","g"),("c","d")] // a map (we can use whatever syntax we like, this is the existing one) -secondBean.componentSet={"component:thirdBean","component:fourthBean"} +secondBean.componentSet={thirdBean,fourthBean} thirdBean.intValue=3 -thirdBean.component=component:fourthBean +thirdBean.component=fourthBean fourthBean.simpleValue="Fourth Bean - not specified in xml" fourthBean.type="org.dllearner.configuration.spring.TestBean" -// you can also specify positive and negative examples -// (not sure if we really need that) -+"http://example.org/pos1/" --"http://example.org/neg1/" \ 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: <sha...@us...> - 2011-08-27 20:28:47
|
Revision: 3141 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3141&view=rev Author: shadowtm Date: 2011-08-27 20:28:40 +0000 (Sat, 27 Aug 2011) Log Message: ----------- Removed confparser2 directory and renamed father_new.conf to just father.conf Modified Paths: -------------- trunk/examples/family/father.conf trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java Removed Paths: ------------- trunk/examples/family/father_new.conf trunk/interfaces/src/main/java/org/dllearner/confparser2/ trunk/interfaces/src/test/java/org/dllearner/confparser2/ trunk/interfaces/src/test/resources/org/dllearner/confparser2/ Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-27 20:07:08 UTC (rev 3140) +++ trunk/examples/family/father.conf 2011-08-27 20:28:40 UTC (rev 3141) @@ -7,6 +7,9 @@ * Copyright (C) 2007, Jens Lehmann */ +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] + // knowledge source definition ks.type = "KB file" ks.url = "father.kb" @@ -14,24 +17,24 @@ // reasoner reasoner.type = "fast instance checker" -reasoner.reasonerComponent = component:embeddedReasoner +reasoner.reasonerComponent = embeddedReasoner -embeddedReasoner.type = "org.dllearner.reasoning.OWLAPIReasoner" -embeddedReasoner.sources = {"component:ks"} +embeddedReasoner.type = "OWL API Reasoner" +embeddedReasoner.sources = { ks } // learning problem lp.type = "posNegStandard" -lp.positiveExamples = {"http://localhost/foo#stefan","http://localhost/foo#markus","http://localhost/foo#bernd"} -lp.negativeExamples = {"http://localhost/foo#heinz","http://localhost/foo#anna","http://localhost/foo#gabi","http://localhost/foo#michelle"} +lp.positiveExamples = {"kb:stefan","kb:markus","kb:bernd"} +lp.negativeExamples = {"kb:heinz","kb:anna","kb:gabi","kb:michelle"} // plug a reasoner into the learning problem -lp.reasoner = component:reasoner +lp.reasoner = reasoner //lp.reasoner = reasoner - try to remove the component:part in the parser // create a refinement operator and configure it op.type = "rho" op.useCardinalityRestrictions = true -op.reasoner = component:reasoner +op.reasoner = reasoner // create a heuristic and configure it h.type = "multiheuristic" @@ -39,9 +42,8 @@ // create learning algorithm to run alg.type = "ocel" -alg.reasoner = component:reasoner -alg.operator = component:op -alg.learningProblem = component:lp -alg.heuristic = component:h -alg.maxExecutionTimeInSeconds=15 - +alg.reasoner = reasoner +alg.operator = op +alg.learningProblem = lp +alg.heuristic = h +alg.maxExecutionTimeInSeconds = 15 \ No newline at end of file Deleted: trunk/examples/family/father_new.conf =================================================================== --- trunk/examples/family/father_new.conf 2011-08-27 20:07:08 UTC (rev 3140) +++ trunk/examples/family/father_new.conf 2011-08-27 20:28:40 UTC (rev 3141) @@ -1,50 +0,0 @@ -/** - * Father Example - * - * possible solution: - * male AND EXISTS hasChild.TOP - * - * Copyright (C) 2007, Jens Lehmann - */ - -// declare some prefixes to use as abbreviations -prefixes = [ ("kb","http://localhost/foo#") ] - -// knowledge source definition -ks.type = "KB file" -ks.url = "father.kb" -// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. - -// reasoner -reasoner.type = "fast instance checker" -reasoner.reasonerComponent = embeddedReasoner - -embeddedReasoner.type = "OWL API Reasoner" -embeddedReasoner.sources = { ks } - -// learning problem -lp.type = "posNegStandard" -lp.positiveExamples = {"kb:stefan","kb:markus","kb:bernd"} -lp.negativeExamples = {"kb:heinz","kb:anna","kb:gabi","kb:michelle"} - -// plug a reasoner into the learning problem -lp.reasoner = reasoner -//lp.reasoner = reasoner - try to remove the component:part in the parser - -// create a refinement operator and configure it -op.type = "rho" -op.useCardinalityRestrictions = true -op.reasoner = reasoner - -// create a heuristic and configure it -h.type = "multiheuristic" -h.expansionPenaltyFactor = 0.2 - -// create learning algorithm to run -alg.type = "ocel" -alg.reasoner = reasoner -alg.operator = op -alg.learningProblem = lp -alg.heuristic = h -alg.maxExecutionTimeInSeconds = 15 - Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-27 20:07:08 UTC (rev 3140) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2011-08-27 20:28:40 UTC (rev 3141) @@ -29,8 +29,8 @@ import org.dllearner.configuration.IConfiguration; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; -import org.dllearner.confparser2.ConfParserConfiguration; -import org.dllearner.confparser2.ParseException; +import org.dllearner.confparser3.ConfParserConfiguration; +import org.dllearner.confparser3.ParseException; import org.dllearner.core.AbstractCELA; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.springframework.context.ApplicationContext; Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2011-08-27 20:07:08 UTC (rev 3140) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2011-08-27 20:28:40 UTC (rev 3141) @@ -1,7 +1,6 @@ package org.dllearner.configuration.spring; import org.dllearner.configuration.IConfiguration; -import org.dllearner.confparser2.ConfParserConfiguration; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; Modified: trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-27 20:07:08 UTC (rev 3140) +++ trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-27 20:28:40 UTC (rev 3141) @@ -34,7 +34,7 @@ ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); /** The DL-Learner Config File */ - Resource confFile = new FileSystemResource("../examples/family/father_new.conf"); + Resource confFile = new FileSystemResource("../examples/family/father.conf"); // confFile.getAbsoluteFile().getParent( //Component Key Prefixes Modified: trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-27 20:07:08 UTC (rev 3140) +++ trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-27 20:28:40 UTC (rev 3141) @@ -35,7 +35,7 @@ @Test public void test() throws FileNotFoundException, ParseException { - ConfParser parser = ConfParser.parseFile(new File("../examples/family/father_new.conf")); + ConfParser parser = ConfParser.parseFile(new File("../examples/family/father.conf")); for(ConfFileOption2 option : parser.getConfOptions()) { System.out.print(option.getBeanName() + "." + option.getPropertyName() + " = " + option.getPropertyValue()); if(option.isBeanRef()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2011-08-27 20:37:46
|
Revision: 3142 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3142&view=rev Author: shadowtm Date: 2011-08-27 20:37:40 +0000 (Sat, 27 Aug 2011) Log Message: ----------- Cleaned up the IConfiguration interface and added a father_autowired.conf example. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java Added Paths: ----------- trunk/examples/family/father_autowired.conf Modified: trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-27 20:28:40 UTC (rev 3141) +++ trunk/components-core/src/main/java/org/dllearner/configuration/IConfiguration.java 2011-08-27 20:37:40 UTC (rev 3142) @@ -20,8 +20,6 @@ package org.dllearner.configuration; import java.util.Collection; -import java.util.Properties; -import java.util.Set; /** * Created by IntelliJ IDEA. @@ -35,25 +33,6 @@ public interface IConfiguration { /** - * Get the object for the given key. - * - * @param key The key of the object to retrieve. - * @return The Object representation of the value keyed by key. - */ - public Object getObjectValue(String key); - - /** - * Get a Properties object describing all of the properties which this configuration object - * knows about. - * - * As Properties are basically Map<String,String> objects, you can use getObjectValue(String key). To - * get the Object. - * - * @return A Properties Object. - */ - public Properties getProperties(); - - /** * Get a collection of all the bean names defined in the configuration. * * @return a collection of all the bean names defined in the configuration. @@ -69,32 +48,17 @@ public Class getClass(String beanName); /** - * Get the set of positive examples associated with this configuration. - * - * Never returns null, only an empty set if there are no positive examples. - * - * @return The set of positive examples associated with this configuration. - */ - public Set<String> getPositiveExamples(); - - /** - * Get the set of negative examples associated with this configuration. - * - * Never returns null, only an empty set if there are no negative examples. - * - * @return The set of negative examples associated with this configuration. - */ - public Set<String> getNegativeExamples(); - - /** * Get the Base Directory where this configuration should be running out of. * * @return The Base Directory where this configuration should be running out of. */ public String getBaseDir(); - - public Collection<IConfigurationProperty> getConfigurationOptions(String beanName); - - + /** + * Get the configuration properties for the specified bean. + * + * @param beanName The bean to get properties for. + * @return A collection of properties + */ + public Collection<IConfigurationProperty> getConfigurationProperties(String beanName); } Copied: trunk/examples/family/father_autowired.conf (from rev 3141, trunk/examples/family/father.conf) =================================================================== --- trunk/examples/family/father_autowired.conf (rev 0) +++ trunk/examples/family/father_autowired.conf 2011-08-27 20:37:40 UTC (rev 3142) @@ -0,0 +1,49 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] + +// knowledge source definition +ks.type = "KB file" +ks.url = "father.kb" +// ks.baseDir = "examples/family"; //Assuming running from parent directory of examples. + +// reasoner +reasoner.type = "fast instance checker" +reasoner.reasonerComponent = embeddedReasoner + +embeddedReasoner.type = "OWL API Reasoner" +embeddedReasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = {"kb:stefan","kb:markus","kb:bernd"} +lp.negativeExamples = {"kb:heinz","kb:anna","kb:gabi","kb:michelle"} + +// plug a reasoner into the learning problem +lp.reasoner = reasoner +//lp.reasoner = reasoner - try to remove the component:part in the parser + +// create a refinement operator and configure it +op.type = "rho" +op.useCardinalityRestrictions = true +op.reasoner = reasoner + +// create a heuristic and configure it +h.type = "multiheuristic" +h.expansionPenaltyFactor = 0.2 + +// create learning algorithm to run +alg.type = "ocel" +alg.reasoner = reasoner +alg.operator = op +alg.learningProblem = lp +alg.heuristic = h +alg.maxExecutionTimeInSeconds = 15 \ No newline at end of file Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2011-08-27 20:28:40 UTC (rev 3141) +++ trunk/interfaces/pom.xml 2011-08-27 20:37:40 UTC (rev 3142) @@ -168,7 +168,6 @@ <exclude>org/dllearner/configuration/spring/TestBean.java</exclude> <exclude>org/dllearner/test/SpringTest.java</exclude> <exclude>org/dllearner/test/junit/GeizhalsTest.java</exclude> - <exclude>org/dllearner/cli/FatherCLITest.java</exclude> </excludes> </configuration> </plugin> Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-27 20:28:40 UTC (rev 3141) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2011-08-27 20:37:40 UTC (rev 3142) @@ -66,7 +66,7 @@ BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); - Collection<IConfigurationProperty> properties = configuration.getConfigurationOptions(beanName); + Collection<IConfigurationProperty> properties = configuration.getConfigurationProperties(beanName); for (IConfigurationProperty property : properties) { Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-08-27 20:28:40 UTC (rev 3141) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConfiguration.java 2011-08-27 20:37:40 UTC (rev 3142) @@ -38,16 +38,6 @@ } @Override - public Object getObjectValue(String key) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public Properties getProperties() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override public Collection<String> getBeanNames() { Set<String> result = new HashSet<String>(); Map<String,List<ConfFileOption2>> beans = parser.getConfOptionsByBean(); @@ -95,22 +85,12 @@ } @Override - public Set<String> getPositiveExamples() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public Set<String> getNegativeExamples() { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override public String getBaseDir() { return baseDir; } @Override - public Collection<IConfigurationProperty> getConfigurationOptions(String beanName) { + public Collection<IConfigurationProperty> getConfigurationProperties(String beanName) { List<ConfFileOption2> confFileOptions = parser.getConfOptionsByBean(beanName); Collection<IConfigurationProperty> result = new ArrayList<IConfigurationProperty>(); Modified: trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-27 20:28:40 UTC (rev 3141) +++ trunk/interfaces/src/test/java/org/dllearner/cli/FatherCLITest.java 2011-08-27 20:37:40 UTC (rev 3142) @@ -22,52 +22,53 @@ * User: Chris * Date: 8/23/11 * Time: 5:21 AM - * + * <p/> * Test for the CLI Class */ public class FatherCLITest { - private static ApplicationContext context; - @BeforeClass - public static void setUp() throws IOException{ - + public ApplicationContext createApplicationContext(Resource confFile) throws IOException { ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); - /** The DL-Learner Config File */ - Resource confFile = new FileSystemResource("../examples/family/father.conf"); - -// confFile.getAbsoluteFile().getParent( - //Component Key Prefixes List<String> componentKeyPrefixes = new ArrayList<String>(); componentKeyPrefixes.add("component:"); componentKeyPrefixes.add(":"); //Spring Config Files List<Resource> springConfigResources = new ArrayList<Resource>(); -// springConfigResources.add(new ClassPathResource("/org/dllearner/configuration/spring/configuration-based-property-override-configurer-configuration.xml")); //DL-Learner Configuration Object IConfiguration configuration = new ConfParserConfiguration(confFile); //Build The Application Context - context = builder.buildApplicationContext(configuration, componentKeyPrefixes,springConfigResources); + ApplicationContext context = builder.buildApplicationContext(configuration, componentKeyPrefixes, springConfigResources); + return context; } @Test - public void testFatherConf(){ + public void testFatherConf() throws Exception { + Resource confFile = new FileSystemResource("../examples/family/father.conf"); + ApplicationContext context = createApplicationContext(confFile); + validateContext(context); + } + @Test + public void testFatherAutoWiredConf() throws Exception { + Resource confFile = new FileSystemResource("../examples/family/father_autowired.conf"); + ApplicationContext context = createApplicationContext(confFile); + validateContext(context); + } + + private void validateContext(ApplicationContext context) { PosNegLPStandard lp = context.getBean("lp", PosNegLPStandard.class); Assert.assertTrue(lp.getPositiveExamples().size() == 3); Assert.assertTrue(lp.getNegativeExamples().size() == 4); Assert.assertNotNull(lp.getReasoner()); - OCEL algorithm = context.getBean("alg",OCEL.class); + OCEL algorithm = context.getBean("alg", OCEL.class); Assert.assertNotNull(algorithm); algorithm.start(); - - - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |