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. |