You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <lor...@us...> - 2014-02-20 13:04:24
|
Revision: 4235 http://sourceforge.net/p/dl-learner/code/4235 Author: lorenz_b Date: 2014-02-20 13:04:20 +0000 (Thu, 20 Feb 2014) Log Message: ----------- Improved script. Modified Paths: -------------- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 12:56:46 UTC (rev 4234) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 13:04:20 UTC (rev 4235) @@ -5,7 +5,6 @@ import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SIBLING; import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SUPERCLASS; -import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.RANDOM; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -94,7 +93,6 @@ import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; -import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; import org.semanticweb.owlapi.model.OWLOntology; @@ -102,9 +100,6 @@ import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.util.OWLEntityRemover; -import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; - -import com.clarkparsia.owlapi.explanation.PelletExplanation; import com.google.common.base.Charsets; import com.google.common.collect.Sets; import com.google.common.hash.HashCode; @@ -201,13 +196,13 @@ relevanceMetrics = new ArrayList<>(); relevanceMetrics.add(new PMIRelevanceMetric(syntacticIndex)); -// relevanceMetrics.add(new ChiSquareRelevanceMetric(syntacticIndex)); -// relevanceMetrics.add(new DiceRelevanceMetric(syntacticIndex)); -// relevanceMetrics.add(new JaccardRelevanceMetric(syntacticIndex)); -// relevanceMetrics.add(new LLRRelevanceMetric(syntacticIndex)); -// relevanceMetrics.add(new SCIRelevanceMetric(syntacticIndex)); -// relevanceMetrics.add(new SignificantPMIRelevanceMetric(syntacticIndex, 0.5)); -// relevanceMetrics.add(new TTestRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new ChiSquareRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new DiceRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new JaccardRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new LLRRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new SCIRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new SignificantPMIRelevanceMetric(syntacticIndex, 0.5)); + relevanceMetrics.add(new TTestRelevanceMetric(syntacticIndex)); resultsFolder.mkdirs(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-20 12:56:49
|
Revision: 4234 http://sourceforge.net/p/dl-learner/code/4234 Author: lorenz_b Date: 2014-02-20 12:56:46 +0000 (Thu, 20 Feb 2014) Log Message: ----------- Improved script. Modified Paths: -------------- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 12:50:37 UTC (rev 4233) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 12:56:46 UTC (rev 4234) @@ -296,7 +296,7 @@ for (final NamedClass cls : classes) { try { File resultsFile = new File(resultsFolder, URLEncoder.encode(cls.getName(), "UTF-8") + ".csv"); - if(resultsFile.exists()){ + if(!overwrite && resultsFile.exists()){ continue; } } catch (UnsupportedEncodingException e1) { @@ -348,11 +348,11 @@ OWLOntology knowledgebaseSample = loadKnowledgebaseSample(cls, Sets.union(positiveExamples, negativeExamples)); - PelletExplanation expGen = new PelletExplanation(knowledgebaseSample); - OWLDataFactory df = new OWLDataFactoryImpl(); - OWLClassAssertionAxiom ax = df.getOWLClassAssertionAxiom(df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Person")), df.getOWLNamedIndividual(IRI.create("http://dbpedia.org/resource/Ontario_Australian_Football_League"))); - Set<OWLAxiom> explanation = expGen.getEntailmentExplanation(ax); - System.out.println(explanation); +// PelletExplanation expGen = new PelletExplanation(knowledgebaseSample); +// OWLDataFactory df = new OWLDataFactoryImpl(); +// OWLClassAssertionAxiom ax = df.getOWLClassAssertionAxiom(df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Person")), df.getOWLNamedIndividual(IRI.create("http://dbpedia.org/resource/Ontario_Australian_Football_League"))); +// Set<OWLAxiom> explanation = expGen.getEntailmentExplanation(ax); +// System.out.println(explanation); // try { // Thread.sleep(2000); // } catch (InterruptedException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-20 12:50:41
|
Revision: 4233 http://sourceforge.net/p/dl-learner/code/4233 Author: lorenz_b Date: 2014-02-20 12:50:37 +0000 (Thu, 20 Feb 2014) Log Message: ----------- Added fixed version of DBpedia. Modified Paths: -------------- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 12:42:04 UTC (rev 4232) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 12:50:37 UTC (rev 4233) @@ -154,15 +154,15 @@ private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; final int minNrOfPositiveExamples = 3; - final int maxNrOfPositiveExamples = 10; - final int maxNrOfNegativeExamples = 20; + final int maxNrOfPositiveExamples = 100; + final int maxNrOfNegativeExamples = 200; List<Strategy> negExampleStrategies = Arrays.asList(SIBLING, SUPERCLASS); boolean posOnly = false; int maxCBDDepth = 1; //learning algorithm settings private int maxNrOfResults = 100; - private int maxExecutionTimeInSeconds = 10; + private int maxExecutionTimeInSeconds = 60; private double noiseInPercentage = 50; private boolean useNegation = false; private boolean useAllConstructor = false; @@ -277,7 +277,7 @@ public void run(){ Set<NamedClass> classes = getClasses(); classes = sparqlReasoner.getMostSpecificClasses(); - List<NamedClass> classList = new ArrayList<>(classes); +// List<NamedClass> classList = new ArrayList<>(classes); // Collections.reverse(classList); // classList = classList.subList(0, 2); // classList = Lists.newArrayList( @@ -286,10 +286,14 @@ // new NamedClass("http://dbpedia.org/ontology/Book")); // new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); // System.exit(0); + run(classes, true); + } + + public void run(Set<NamedClass> classes, boolean overwrite){ ExecutorService executor = Executors.newFixedThreadPool(6); - for (final NamedClass cls : classList) { + for (final NamedClass cls : classes) { try { File resultsFile = new File(resultsFolder, URLEncoder.encode(cls.getName(), "UTF-8") + ".csv"); if(resultsFile.exists()){ @@ -822,10 +826,12 @@ DBpediaExperiment experiment = new DBpediaExperiment(); long start = System.currentTimeMillis(); if(args.length == 1){ + Set<NamedClass> classes = new HashSet<>(); List<String> lines = Files.readLines(new File(args[0]), Charsets.UTF_8); for (String line : lines) { - experiment.run(new NamedClass(line.trim()), true); + classes.add(new NamedClass(line.trim())); } + experiment.run(classes, true); } else { experiment.run(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-20 12:42:10
|
Revision: 4232 http://sourceforge.net/p/dl-learner/code/4232 Author: lorenz_b Date: 2014-02-20 12:42:04 +0000 (Thu, 20 Feb 2014) Log Message: ----------- Added fixed version of DBpedia. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java 2014-02-18 09:50:49 UTC (rev 4231) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java 2014-02-20 12:42:04 UTC (rev 4232) @@ -27,14 +27,18 @@ double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; + Entity minE=null; + Entity maxE=null; for (Entity e : hmEntity2Score.keySet()) { double value = hmEntity2Score.get(e); if (value < min) { - min = value; + min = value;minE = e; } else if (value > max) { - max = value; + max = value;maxE = e; } } +// System.err.println("Max: " + max + "-" + maxE); +// System.err.println("Min: " + min + "-" + minE); // System.out.println( "min="+ dMin +" max="+ dMax ); for (Entity e : hmEntity2Score.keySet()) { double value = hmEntity2Score.get(e); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2014-02-18 09:50:49 UTC (rev 4231) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2014-02-20 12:42:04 UTC (rev 4232) @@ -237,8 +237,14 @@ lggInstances = getResources(lgg); nbr.setLGGInstances(lggInstances); - String question = nbr.getQuestion(lgg, negExampleTrees, getKnownResources()); + String question; + if(negExamples.isEmpty()){ + question = nbr.getQuestion(lgg, negExampleTrees, getKnownResources()); + } else { + question = nbr.getQuestion(lgg, negExampleTrees, getKnownResources()); + } + return question; } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2014-02-18 09:50:49 UTC (rev 4231) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2014-02-20 12:42:04 UTC (rev 4232) @@ -197,7 +197,7 @@ private String createNamespacesFilter(String targetVar){ String filter = ""; - if(namespaces != null){ + if(namespaces != null && !namespaces.isEmpty()){ filter += "FILTER("; for(Iterator<String> iter = namespaces.iterator(); iter.hasNext();){ String ns = iter.next(); @@ -213,10 +213,10 @@ public static void main(String[] args) { Logger.getRootLogger().setLevel(Level.DEBUG); - ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpedia()); + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); cbdGen = new CachingConciseBoundedDescriptionGenerator(cbdGen); // cbdGen.setRestrictToNamespaces(Arrays.asList(new String[]{"http://dbpedia.org/ontology/", RDF.getURI(), RDFS.getURI()})); - Model cbd = cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 3); + Model cbd = cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 1); System.out.println(cbd.size()); } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-02-18 09:50:49 UTC (rev 4231) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-02-20 12:42:04 UTC (rev 4232) @@ -23,6 +23,8 @@ import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SIBLING; import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SUPERCLASS; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -31,8 +33,15 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.concurrent.TimeUnit; -import org.dllearner.core.owl.ClassHierarchy; +import org.aksw.jena_sparql_api.cache.core.QueryExecutionFactoryCacheEx; +import org.aksw.jena_sparql_api.cache.extra.CacheCoreEx; +import org.aksw.jena_sparql_api.cache.extra.CacheCoreH2; +import org.aksw.jena_sparql_api.cache.extra.CacheEx; +import org.aksw.jena_sparql_api.cache.extra.CacheExImpl; +import org.aksw.jena_sparql_api.core.QueryExecutionFactory; +import org.aksw.jena_sparql_api.http.QueryExecutionFactoryHttp; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -50,6 +59,9 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Multisets; import com.google.common.collect.Sets; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; /** * * Utility class for automatically retrieving negative examples from a @@ -67,21 +79,35 @@ SUPERCLASS, SIBLING, RANDOM; } - private SparqlEndpoint se; // for re-using existing queries private SPARQLReasoner sr; private String namespace; + private String cacheDirectory = "cache"; + private QueryExecutionFactory qef; public AutomaticNegativeExampleFinderSPARQL2(SparqlEndpoint se, SPARQLReasoner reasoner) { this(se, reasoner, null); } public AutomaticNegativeExampleFinderSPARQL2(SparqlEndpoint se, SPARQLReasoner reasoner, String namespace) { - this.se = se; this.sr = reasoner; this.namespace = namespace; + + qef = new QueryExecutionFactoryHttp(se.getURL().toString(), se.getDefaultGraphURIs()); + if(cacheDirectory != null){ + try { + long timeToLive = TimeUnit.DAYS.toMillis(30); + CacheCoreEx cacheBackend = CacheCoreH2.create(cacheDirectory, timeToLive, true); + CacheEx cacheFrontend = new CacheExImpl(cacheBackend); + qef = new QueryExecutionFactoryCacheEx(qef, cacheFrontend); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } } public AutomaticNegativeExampleFinderSPARQL2(SparqlEndpoint se) { @@ -119,7 +145,7 @@ Multiset<NamedClass> types = HashMultiset.create(); types.add(classToDescribe); - return computeNegativeExamples(types, strategiesWithWeight, maxNrOfReturnedInstances); + return computeNegativeExamples(classToDescribe, types, strategiesWithWeight, maxNrOfReturnedInstances); } public SortedSet<Individual> getNegativeExamples(Set<Individual> positiveExamples, int limit) { @@ -147,10 +173,10 @@ //keep the most specific types keepMostSpecificClasses(types); - return computeNegativeExamples(types, strategiesWithWeight, maxNrOfReturnedInstances); + return computeNegativeExamples(null, types, strategiesWithWeight, maxNrOfReturnedInstances); } - private SortedSet<Individual> computeNegativeExamples(Multiset<NamedClass> positiveExamplesTypes, Map<Strategy, Double> strategiesWithWeight, int maxNrOfReturnedInstances) { + private SortedSet<Individual> computeNegativeExamples(NamedClass classToDescribe, Multiset<NamedClass> positiveExamplesTypes, Map<Strategy, Double> strategiesWithWeight, int maxNrOfReturnedInstances) { SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); for (Entry<Strategy, Double> entry : strategiesWithWeight.entrySet()) { @@ -212,7 +238,29 @@ logger.info("Negative examples(" + superClassNegativeExamples.size() + "): " + superClassNegativeExamples); negativeExamples.addAll(superClassNegativeExamples); } else if(strategy == RANDOM){//get some random examples - String query = "SELECT ?s WHERE {?s a ?type. FILTER NOT EXIST{?s a <> }} ORDER BY RAND() LIMIT " + maxNrOfReturnedInstances; + logger.info("Applying random strategy..."); + SortedSet<Individual> randomNegativeExamples = new TreeSet<Individual>(); + String query = "SELECT DISTINCT ?s WHERE {?s a ?type."; + if(classToDescribe != null){ + query += "FILTER NOT EXISTS{?s a <" + classToDescribe + "> }"; + } else { + for (NamedClass nc : positiveExamplesTypes.elementSet()) { + + } + throw new UnsupportedOperationException("Currently it's not possible to get random examples for unknown class to describe."); + } + + query += "} ORDER BY RAND() LIMIT " + maxNrOfReturnedInstances; + QueryExecution qe = qef.createQueryExecution(query); + ResultSet rs = qe.execSelect(); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + randomNegativeExamples.add(new Individual(qs.getResource("s").getURI())); + } + randomNegativeExamples.removeAll(negativeExamples); + negativeExamples.addAll(new ArrayList<>(randomNegativeExamples).subList(0, Math.min(randomNegativeExamples.size(), maxNrOfReturnedInstances - negativeExamples.size()))); + logger.info("Negative examples(" + randomNegativeExamples.size() + "): " + randomNegativeExamples); } } return negativeExamples; Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-18 09:50:49 UTC (rev 4231) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-20 12:42:04 UTC (rev 4232) @@ -5,6 +5,7 @@ import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SIBLING; import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SUPERCLASS; +import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.RANDOM; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -84,6 +85,7 @@ import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.PrefixCCMap; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy; import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; @@ -92,6 +94,7 @@ import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; import org.semanticweb.owlapi.model.OWLOntology; @@ -99,8 +102,10 @@ import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.util.OWLEntityRemover; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +import com.clarkparsia.owlapi.explanation.PelletExplanation; import com.google.common.base.Charsets; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; @@ -149,17 +154,19 @@ private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; final int minNrOfPositiveExamples = 3; - final int maxNrOfPositiveExamples = 100; - final int maxNrOfNegativeExamples = 200; + final int maxNrOfPositiveExamples = 10; + final int maxNrOfNegativeExamples = 20; + List<Strategy> negExampleStrategies = Arrays.asList(SIBLING, SUPERCLASS); boolean posOnly = false; int maxCBDDepth = 1; //learning algorithm settings private int maxNrOfResults = 100; - private int maxExecutionTimeInSeconds = 60; + private int maxExecutionTimeInSeconds = 10; private double noiseInPercentage = 50; private boolean useNegation = false; private boolean useAllConstructor = false; + private int maxClassExpressionDepth = 4; String experimentsFolder = "experiments/isle/"; File resultsFolder = new File(experimentsFolder + "result/"); @@ -170,8 +177,9 @@ private List<RelevanceMetric> relevanceMetrics; - private PreparedStatement ps; - + private PreparedStatement addPS; + private PreparedStatement removePS; + public DBpediaExperiment() { try { @@ -193,13 +201,13 @@ relevanceMetrics = new ArrayList<>(); relevanceMetrics.add(new PMIRelevanceMetric(syntacticIndex)); - relevanceMetrics.add(new ChiSquareRelevanceMetric(syntacticIndex)); - relevanceMetrics.add(new DiceRelevanceMetric(syntacticIndex)); - relevanceMetrics.add(new JaccardRelevanceMetric(syntacticIndex)); - relevanceMetrics.add(new LLRRelevanceMetric(syntacticIndex)); - relevanceMetrics.add(new SCIRelevanceMetric(syntacticIndex)); - relevanceMetrics.add(new SignificantPMIRelevanceMetric(syntacticIndex, 0.5)); - relevanceMetrics.add(new TTestRelevanceMetric(syntacticIndex)); +// relevanceMetrics.add(new ChiSquareRelevanceMetric(syntacticIndex)); +// relevanceMetrics.add(new DiceRelevanceMetric(syntacticIndex)); +// relevanceMetrics.add(new JaccardRelevanceMetric(syntacticIndex)); +// relevanceMetrics.add(new LLRRelevanceMetric(syntacticIndex)); +// relevanceMetrics.add(new SCIRelevanceMetric(syntacticIndex)); +// relevanceMetrics.add(new SignificantPMIRelevanceMetric(syntacticIndex, 0.5)); +// relevanceMetrics.add(new TTestRelevanceMetric(syntacticIndex)); resultsFolder.mkdirs(); @@ -249,7 +257,10 @@ sql += ",?"; } sql += ")"; - ps = conn.prepareStatement(sql); + addPS = conn.prepareStatement(sql); + + sql = "DELETE FROM ISLE_Evaluation WHERE class=?"; + removePS = conn.prepareStatement(sql); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { @@ -291,7 +302,7 @@ @Override public void run() { try { - DBpediaExperiment.this.run(cls); + DBpediaExperiment.this.run(cls, true); } catch (Exception e) { logger.error("Error when learning class " + cls, e); } @@ -306,7 +317,16 @@ } } - public void run(NamedClass cls){ + public void run(NamedClass cls, boolean overwrite){ + //first of all, remove existing entries from database + if(overwrite){ + try { + removeFromDB(cls); + } catch (SQLException e) { + e.printStackTrace(); + } + } + logger.info("Learning description of class " + cls); //get some positive examples SortedSet<Individual> positiveExamples = getPositiveExamples(cls); @@ -322,6 +342,13 @@ //generate a sample of the knowledge base based on the examples OWLOntology knowledgebaseSample = loadKnowledgebaseSample(cls, Sets.union(positiveExamples, negativeExamples)); + + + PelletExplanation expGen = new PelletExplanation(knowledgebaseSample); + OWLDataFactory df = new OWLDataFactoryImpl(); + OWLClassAssertionAxiom ax = df.getOWLClassAssertionAxiom(df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Person")), df.getOWLNamedIndividual(IRI.create("http://dbpedia.org/resource/Ontario_Australian_Football_League"))); + Set<OWLAxiom> explanation = expGen.getEntailmentExplanation(ax); + System.out.println(explanation); // try { // Thread.sleep(2000); // } catch (InterruptedException e) { @@ -372,6 +399,7 @@ ((ELLearningAlgorithm)la).setClassToDescribe(cls); ((ELLearningAlgorithm)la).setTreeSearchTimeSeconds(maxExecutionTimeInSeconds); ((ELLearningAlgorithm)la).setMaxNrOfResults(maxNrOfResults); + ((ELLearningAlgorithm)la).setMaxClassExpressionDepth(maxClassExpressionDepth); // la = new ELLearningAlgorithmDisjunctive(lp, reasoner); } else { //build CELOE la @@ -449,6 +477,8 @@ } } + + /** * Computes a better start class instead of owl:Thing. * @param operator @@ -550,7 +580,7 @@ private SortedSet<Individual> getNegativeExamples(NamedClass classToDescribe, Set<Individual> positiveExamples){ logger.info("Generating positive examples..."); - SortedSet<Individual> individuals = negativeExampleFinder.getNegativeExamples(classToDescribe, positiveExamples, Arrays.asList(SIBLING, SUPERCLASS), maxNrOfNegativeExamples); + SortedSet<Individual> individuals = negativeExampleFinder.getNegativeExamples(classToDescribe, positiveExamples, negExampleStrategies, maxNrOfNegativeExamples); logger.info("Done. Got " + individuals.size() + ": " + individuals); return individuals; } @@ -765,45 +795,41 @@ .hash(); String id = hc.toString(); double fMeasure = ((PosNegLPStandard)lp).getAccuracyOrTooWeakExact(ed.getDescription(), noiseInPercentage/100d); - ps.setString(1, id); - ps.setString(2, cls.getName()); - ps.setInt(3, position++); - ps.setString(4, expression); - ps.setDouble(5, fMeasure); - ps.setInt(6, ed.getDescriptionLength()); + addPS.setString(1, id); + addPS.setString(2, cls.getName()); + addPS.setInt(3, position++); + addPS.setString(4, expression); + addPS.setDouble(5, fMeasure); + addPS.setInt(6, ed.getDescriptionLength()); int col = 7; for (RelevanceMetric metric : relevanceMetrics) { double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevances.get(metric)); - ps.setDouble(col++, relevanceScore); + addPS.setDouble(col++, relevanceScore); } - ps.setString(col, render(new EquivalentClassesAxiom(cls, ed.getDescription()))); + addPS.setString(col, render(new EquivalentClassesAxiom(cls, ed.getDescription()))); - ps.addBatch(); + addPS.addBatch(); } - ps.executeBatch(); + addPS.executeBatch(); } + private synchronized void removeFromDB(NamedClass cls) throws SQLException{ + removePS.setString(1, cls.getName()); + removePS.execute(); + } + public static void main(String[] args) throws Exception { -// ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); -// String cls = "http://dbpedia.org/ontology/Astronaut"; -// OWLDataFactory df = new OWLDataFactoryImpl(); -// OWLAxiom pattern = df.getOWLSubClassOfAxiom( -// df.getOWLClass(IRI.create("http://dllearner.org/pattern/A")), -// df.getOWLObjectIntersectionOf( -// df.getOWLClass(IRI.create("http://dllearner.org/pattern/B")), -// df.getOWLObjectSomeValuesFrom( -// df.getOWLObjectProperty(IRI.create("http://dllearner.org/pattern/p")), -// df.getOWLClass(IRI.create("http://dllearner.org/pattern/C"))))); -// PatternBasedAxiomLearningAlgorithm la = new PatternBasedAxiomLearningAlgorithm(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()), "cache", FragmentExtractionStrategy.INDIVIDUALS); -// la.setClass(new NamedClass(cls)); -// la.setPattern(DLLearnerAxiomConvertVisitor.getDLLearnerAxiom(pattern)); -// la.start(); - + DBpediaExperiment experiment = new DBpediaExperiment(); long start = System.currentTimeMillis(); -// new DBpediaExperiment().run(); - new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Astronaut")); + if(args.length == 1){ + List<String> lines = Files.readLines(new File(args[0]), Charsets.UTF_8); + for (String line : lines) { + experiment.run(new NamedClass(line.trim()), true); + } + } else { + experiment.run(); + } long end = System.currentTimeMillis(); logger.info("Operation took " + (end - start) + "ms"); - } } Modified: trunk/components-core/src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl =================================================================== --- trunk/components-core/src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl 2014-02-18 09:50:49 UTC (rev 4231) +++ trunk/components-core/src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl 2014-02-20 12:42:04 UTC (rev 4232) @@ -1,20914 +1,33403 @@ -<rdf:RDF - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:owl="http://www.w3.org/2002/07/owl#" - xmlns:xsd="http://www.w3.org/2001/XMLSchema#" - xmlns="http://dbpedia.org/ontology/" - xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > - <rdf:Description rdf:about="http://dbpedia.org/ontology/oclc"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/WrittenWork"/> - <rdfs:comment xml:lang="en">Online Computer Library Center number</rdfs:comment> - <rdfs:label xml:lang="en">OCLC</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/foundingDate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:label xml:lang="de">Gründungsdatum</rdfs:label> - <rdfs:label xml:lang="pl">data założenia</rdfs:label> - <rdfs:label xml:lang="ja">創立日</rdfs:label> - <rdfs:label xml:lang="en">founding date</rdfs:label> - <rdfs:label xml:lang="el">ημερομηνία ίδρυσης</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/secondPopularVote"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:label xml:lang="en">secondPopularVote</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/costumeDesigner"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Film"/> - <rdfs:comment xml:lang="en">the person who is responsible for the film costume design</rdfs:comment> - <rdfs:label xml:lang="it">costumista</rdfs:label> - <rdfs:label xml:lang="en">costume designer</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/nisCode"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:comment xml:lang="en">Indexing code used by the Belgium National Statistical Institute to identify populated places.</rdfs:comment> - <rdfs:label xml:lang="en">NIS code</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/kanjiName"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">kanji name</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/MotorcycleRider"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Athlete"/> - <rdfs:label xml:lang="el">μοτοσυκλετιστής</rdfs:label> - <rdfs:label xml:lang="en">motorcycle rider</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/englishName"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Settlement"/> - <rdfs:label xml:lang="en">English name</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/approximateCalories"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Food"/> - <rdfs:comment xml:lang="el">Kατά προσέγγιση θερμίδες ανά μερίδα.</rdfs:comment> - <rdfs:comment xml:lang="en">Approximate calories per serving.</rdfs:comment> - <rdfs:label xml:lang="el">κατά προσέγγιση θερμίδες (J)</rdfs:label> - <rdfs:label xml:lang="en">approximate calories (J)</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/industry"> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Company"/> - <rdfs:label xml:lang="fr">industrie</rdfs:label> - <rdfs:label xml:lang="en">industry</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Curler"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Athlete"/> - <rdfs:label xml:lang="en">curler</rdfs:label> - <rdfs:label xml:lang="nl">curlingspeler</rdfs:label> - <rdfs:label xml:lang="el">μπικουτί</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/conservationStatus"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Species"/> - <rdfs:label xml:lang="ja">保全状況</rdfs:label> - <rdfs:label xml:lang="en">conservation status</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/endDate"> - <owl:equivalentProperty rdf:resource="http://schema.org/endDate"/> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Event"/> - <rdfs:comment xml:lang="en">The end date of the event.</rdfs:comment> - <rdfs:label xml:lang="es">fecha de fin</rdfs:label> - <rdfs:label xml:lang="fr">date de fin</rdfs:label> - <rdfs:label xml:lang="nl">einddatum</rdfs:label> - <rdfs:label xml:lang="en">end date</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/designCompany"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Company"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/MeanOfTransportation"/> - <rdfs:label xml:lang="en">designer company</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Priest"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Cleric"/> - <rdfs:label xml:lang="de">priester</rdfs:label> - <rdfs:label xml:lang="nl">priester</rdfs:label> - <rdfs:label xml:lang="ja">司祭</rdfs:label> - <rdfs:label xml:lang="it">prete</rdfs:label> - <rdfs:label xml:lang="en">priest</rdfs:label> - <rdfs:label xml:lang="fr">prêtre</rdfs:label> - <rdfs:label xml:lang="el">παπάς</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/highestMountain"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Mountain"/> - <rdfs:label xml:lang="en">highest mountain</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/careerPoints"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/FormulaOneRacer"/> - <rdfs:label xml:lang="en">career points</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/leader"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:label xml:lang="pt">lider</rdfs:label> - <rdfs:label xml:lang="el">ηγέτης</rdfs:label> - <rdfs:label xml:lang="nl">leider</rdfs:label> - <rdfs:label xml:lang="en">leader</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/season"> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/SoccerClub"/> - <rdfs:label xml:lang="el">σαιζόν</rdfs:label> - <rdfs:label xml:lang="en">season</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/budgetYear"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Place"/> - <rdfs:label xml:lang="en">budget year</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Locality"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">Locality</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Dog"> - <owl:disjointWith rdf:resource="http://dbpedia.org/ontology/Fish"/> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Mammal"/> - <rdfs:label xml:lang="nl">hond</rdfs:label> - <rdfs:label xml:lang="de">Hund</rdfs:label> - <rdfs:label xml:lang="fr">chien</rdfs:label> - <rdfs:label xml:lang="en">dog</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/governmentType"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/GovernmentType"/> - <rdfs:comment xml:lang="en">broadly, the type of structure of its government</rdfs:comment> - <rdfs:label xml:lang="pt">tipo de governo</rdfs:label> - <rdfs:label xml:lang="nl">staatsvorm</rdfs:label> - <rdfs:label xml:lang="en">government type</rdfs:label> - <rdfs:label xml:lang="de">Staatsform</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/startYearOfSales"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#gYear"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Sales"/> - <rdfs:label xml:lang="en">start year of sales</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/nndbId"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:label xml:lang="en">NNDB id</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/RaceTrack"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/SportFacility"/> - <rdfs:label xml:lang="fr">circuit de course</rdfs:label> - <rdfs:label xml:lang="el">πίστα αγώνων</rdfs:label> - <rdfs:label xml:lang="en">race track</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/mouthState"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/River"/> - <rdfs:label xml:lang="en">mouth state</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/officialLanguage"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Language"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">official language</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/visitorStatisticsAsOf"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#gYear"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/ArchitecturalStructure"/> - <rdfs:comment xml:lang="en">Year visitor information was gathered.</rdfs:comment> - <rdfs:label xml:lang="en">visitor statistics as of</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/diseasesdb"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Disease"/> - <rdfs:label xml:lang="ja">DiseasesDB</rdfs:label> - <rdfs:label xml:lang="nl">DiseasesDB</rdfs:label> - <rdfs:label xml:lang="en">DiseasesDB</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/serviceNumber"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/MilitaryPerson"/> - <rdfs:comment xml:lang="en">The service number held by the individual during military service.</rdfs:comment> - <rdfs:label xml:lang="en">service number</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/notifyDate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/SiteOfSpecialScientificInterest"/> - <rdfs:label xml:lang="en">notify date</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/cmykCoordinateMagenta"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Colour"/> - <rdfs:label xml:lang="en">magenta coordinate in the CMYK space</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/namedAfter"> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/SpaceShuttle"/> - <rdfs:label xml:lang="en">named after</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/musicType"> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/MusicalWork"/> - <rdfs:comment xml:lang="nl">Type is te algemeen. We moeten soorten muziek van soorten gebouwen kunnen onderscheiden</rdfs:comment> - <rdfs:comment xml:lang="en">Type is too general. We should be able to distinguish types of music from types of architecture</rdfs:comment> - <rdfs:label xml:lang="nl">soort muziekwerk</rdfs:label> - <rdfs:label xml:lang="en">musicType</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Judge"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:label xml:lang="de">richter</rdfs:label> - <rdfs:label xml:lang="nl">rechter</rdfs:label> - <rdfs:label xml:lang="ja">裁判官</rdfs:label> - <rdfs:label xml:lang="it">giudice</rdfs:label> - <rdfs:label xml:lang="en">judge</rdfs:label> - <rdfs:label xml:lang="fr">juge</rdfs:label> - <rdfs:label xml:lang="el">δικαστής</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/alpsSubgroup"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/MountainRange"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Mountain"/> - <rdfs:comment xml:lang="en">the Alps subgroup to which the mountain belongs, according to the SOIUSA classification</rdfs:comment> - <rdfs:label xml:lang="it">sottogruppo alpino</rdfs:label> - <rdfs:label xml:lang="el">υποομάδα των άλπεων</rdfs:label> - <rdfs:label xml:lang="en">Alps subgroup</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/sharingOutPopulation"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">sharing out population</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/goldenCalfAward"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Award"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Actor"/> - <rdfs:label xml:lang="en">Golden Calf Award</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/WorldHeritageSite"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Place"/> - <rdfs:comment xml:lang="en">A UNESCO World Heritage Site is a site (such as a forest, mountain, lake, desert, monument, building, complex, or city) that is on the list that is maintained by the international World Heritage Programme administered by the UNESCO World Heritage Committee, composed of 21 state parties which are elected by their General Assembly for a four-year term. A World Heritage Site is a place of either cultural or physical significance.</rdfs:comment> - <rdfs:label xml:lang="ko">세계유산</rdfs:label> - <rdfs:label xml:lang="ja">世界遺産</rdfs:label> - <rdfs:label xml:lang="en">World Heritage Site</rdfs:label> - <rdfs:label xml:lang="fr">site du patrimoine mondial</rdfs:label> - <rdfs:label xml:lang="el">Μνημείο Παγκόσμιας Πολιτιστικής Κληρονομιάς (Πληροφορίες ΠΠΚ)</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/explorer"> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Galaxy"/> - <rdfs:label xml:lang="tr">kaşif</rdfs:label> - <rdfs:label xml:lang="en">explorer</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/licenceNumberLabel"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">licence number label</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/NationalFootballLeagueSeason"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/FootballLeagueSeason"/> - <rdfs:label xml:lang="en">national football league season</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/nationalTopographicSystemMapNumber"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Place"/> - <rdfs:label xml:lang="en">National Topographic System map number</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/WomensTennisAssociationTournament"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/SportsEvent"/> - <rdfs:label xml:lang="fr">Tournoi de la Women's Tennis Association</rdfs:label> - <rdfs:label xml:lang="en">Women's Tennis Association tournament</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/isPeerReviewed"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/AcademicJournal"/> - <rdfs:comment xml:lang="en">In academia peer review is often used to determine an academic papers suitability for publication.</rdfs:comment> - <rdfs:label xml:lang="en">is peer reviewed</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/redSkiPisteNumber"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Place"/> - <rdfs:label xml:lang="en">red ski piste number</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Station"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Infrastructure"/> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - <rdfs:label xml:lang="pt">estação</rdfs:label> - <rdfs:comment xml:lang="en">Public transport station (eg. railway station, metro station, bus station).</rdfs:comment> - <rdfs:label xml:lang="nl">station</rdfs:label> - <rdfs:label xml:lang="en">station</rdfs:label> - <rdfs:label xml:lang="fr">station</rdfs:label> - <rdfs:label xml:lang="el">Σταθμός</rdfs:label> - <rdfs:label xml:lang="ja">駅</rdfs:label> - <rdfs:label xml:lang="ru">станция</rdfs:label> - <rdfs:comment xml:lang="ru">Остановка общественного транспорта (например: железнодорожная станция, станция метро, автостанция).</rdfs:comment> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/runwayDesignation"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Airport"/> - <rdfs:label xml:lang="en">designation of runway</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/SpaceMission/lunarEvaTime"> - <rdfs:range rdf:resource="http://dbpedia.org/datatype/hour"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/SpaceMission"/> - <rdfs:label xml:lang="en">lunar EVA time (ω)</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/year"> - <rdfs:label xml:lang="es">año</rdfs:label> - <rdfs:label xml:lang="nl">jaar</rdfs:label> - <rdfs:label xml:lang="fr">année</rdfs:label> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Sales"/> - <rdfs:label xml:lang="el">έτος</rdfs:label> - <rdfs:label xml:lang="en">year</rdfs:label> - <rdfs:label xml:lang="it">anno</rdfs:label> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#gYear"/> - <rdfs:label xml:lang="de">Jahr</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/center"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/NorwaySettlement"/> - <rdfs:label xml:lang="en">norwegian center</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/dateCompleted"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Canal"/> - <rdfs:label xml:lang="el">ολοκλήρωση</rdfs:label> - <rdfs:label xml:lang="en">date completed</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/sardinianName"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">city sardinian name</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Tunnel"> - <rdfs:label xml:lang="ja">トンネル</rdfs:label> - <rdfs:comment xml:lang="el">Ένα τούνελ μπορεί να είναι για πεζούς ή για αυτοκινητόδρομους,για σιδηρόδρομους,ή για κανάλια στο νερό.Μερικά τούνελ είναι υδραγωγεία για να παρέχουν νερό προς κατανάλωση ή για υδροηλεκτικούς σταθμούς ή είναι υπόνομοι.</rdfs:comment> - <rdfs:comment xml:lang="fr">Un tunnel est une galerie souterraine livrant passage à une voie de communication (chemin de fer, canal, route, chemin piétonnier). (http://fr.wikipedia.org/wiki/Tunnel).</rdfs:comment> - <rdfs:comment xml:lang="en">A tunnel may be for foot or vehicular road traffic, for rail traffic, or for a canal. Some tunnels are aqueducts to supply water for consumption or for hydroelectric stations or are sewers (http://en.wikipedia.org/wiki/Tunnel).</rdfs:comment> - <rdfs:label xml:lang="nl">tunnel</rdfs:label> - <rdfs:label xml:lang="en">tunnel</rdfs:label> - <rdfs:label xml:lang="fr">tunnel</rdfs:label> - <rdfs:label xml:lang="de">Tunnel</rdfs:label> - <rdfs:comment xml:lang="de">Ein Tunnel (auch Tunell) ist eine künstliche Passage, die Berge, Gewässer oder andere Hindernisse (in der Regel als Verkehrsweg) unterquert (http://de.wikipedia.org/wiki/Tunnel).</rdfs:comment> - <rdfs:label xml:lang="el">τούνελ</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/RouteOfTransportation"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/championInDoubleMale"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Athlete"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/SportsEvent"/> - <rdfs:comment xml:lang="en">winner of a competition in the male double session (as in tennis)</rdfs:comment> - <rdfs:label xml:lang="es">Campeón en doble hombres</rdfs:label> - <rdfs:label xml:lang="fr">champion en double hommes</rdfs:label> - <rdfs:label xml:lang="en">champion in double male</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/port1UndockingDate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Spacecraft"/> - <rdfs:label xml:lang="en">port1 undocking date</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/mayorArticle"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Place"/> - <rdfs:label xml:lang="en">mayor article</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/MouseGene"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Gene"/> - <rdfs:label xml:lang="ja">マウス遺伝子</rdfs:label> - <rdfs:label xml:lang="el">γονίδιο ποντικιού</rdfs:label> - <rdfs:label xml:lang="en">MouseGene</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/previousPopulationTotal"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">previous population total</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/crownDependency"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/City"/> - <rdfs:label xml:lang="en">crown dependency</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/procedure"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Case"/> - <rdfs:comment xml:lang="nl">De naam die verwijst naar de formele definitie van een verzameling stappen die in de juiste volgorde leiden tot de afronding van de zaak</rdfs:comment> - <rdfs:comment xml:lang="en">The name designating a formal collection of steps to be taken to complete the case</rdfs:comment> - <rdfs:label xml:lang="nl">procedure</rdfs:label> - <rdfs:label xml:lang="en">procedure</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/canton"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Settlement"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Settlement"/> - <rdfs:label xml:lang="fr">canton</rdfs:label> - <rdfs:label xml:lang="nl">kanton</rdfs:label> - <rdfs:label xml:lang="en">canton</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/pluviometry"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="en">pluviometry</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/doctoralStudent"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Scientist"/> - <rdfs:label xml:lang="nl">doctoraalstudent</rdfs:label> - <rdfs:label xml:lang="el">διδακτορικοί_φοιτητές</rdfs:label> - <rdfs:label xml:lang="en">doctoral student</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/GivenName"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Name"/> - <rdfs:label xml:lang="de">Vorname</rdfs:label> - <rdfs:label xml:lang="pl">imię</rdfs:label> - <rdfs:label xml:lang="nl">voornaam</rdfs:label> - <rdfs:label xml:lang="ja">名</rdfs:label> - <rdfs:label xml:lang="en">given name</rdfs:label> - <rdfs:label xml:lang="fr">prénom</rdfs:label> - <rdfs:label xml:lang="el">όνομα</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/ascentDate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#gYear"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Mountain"/> - <rdfs:label xml:lang="el">ημερομηνία ανάβασης</rdfs:label> - <rdfs:label xml:lang="en">access date</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/spokenIn"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Language"/> - <rdfs:label xml:lang="nl">gesproken in</rdfs:label> - <rdfs:label xml:lang="en">spoken in</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/shape"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Community"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Intercommunality"/> - <rdfs:label xml:lang="en">intercommunality shape</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/OldTerritory"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Territory"/> - <rdfs:label xml:lang="en">old territory</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/winsAtLPGA"> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/GolfPlayer"/> - <rdfs:label xml:lang="en">wins at LPGA</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/mouthPlace"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/River"/> - <rdfs:label xml:lang="en">mouth place</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/CanadianFootballPlayer"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/GridironFootballPlayer"/> - <rdfs:label xml:lang="pt">jogador de futebol canadense</rdfs:label> - <rdfs:label xml:lang="it">giocatore di football canadese</rdfs:label> - <rdfs:label xml:lang="en">canadian football player</rdfs:label> - <rdfs:label xml:lang="fr">joueur de football canadien</rdfs:label> - <rdfs:label xml:lang="el">καναδός παίκτης ποδοσφαίρου</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/requirement"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:label xml:lang="en">requirement</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/reservations"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Restaurant"/> - <rdfs:comment xml:lang="en">Are reservations required for the establishment or event?</rdfs:comment> - <rdfs:label xml:lang="en">reservations</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/campusType"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/School"/> - <rdfs:label xml:lang="en">campus type</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/PrimeMinister"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Politician"/> - <rdfs:label xml:lang="de">Premierminister</rdfs:label> - <rdfs:label xml:lang="nl">eerste minister</rdfs:label> - <rdfs:label xml:lang="en">prime minister</rdfs:label> - <rdfs:label xml:lang="fr">premier ministre</rdfs:label> - <rdfs:label xml:lang="el">πρωθυπουργός</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/lifeExpectancy"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/PopulatedPlace"/> - <rdfs:label xml:lang="pt">expectativa de vida</rdfs:label> - <rdfs:label xml:lang="en">life expectancy</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/Race"> - <rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/SportsEvent"/> - <rdfs:label xml:lang="de">Rennen</rdfs:label> - <rdfs:label xml:lang="ja">レース</rdfs:label> - <rdfs:label xml:lang="en">race</rdfs:label> - <rdfs:label xml:lang="fr">course</rdfs:label> - <rdfs:label xml:lang="el">αγώνας</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/GeopoliticalOrganisation/areaMetro"> - <rdfs:range rdf:resource="http://dbpedia.org/datatype/squareKilometre"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/GeopoliticalOrganisation"/> - <rdfs:label xml:lang="el">περιοχή μετρό (km2)</rdfs:label> - <rdfs:label xml:lang="en">area metro (km2)</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/authorityMandate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Place"/> - <rdfs:label xml:lang="en">authority mandate</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/patron"> - <rdfs:range rdf:resource="http://dbpedia.org/ontology/Person"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/MilitaryUnit"/> - <rdfs:label xml:lang="pt">patrono</rdfs:label> - <rdfs:label xml:lang="en">patron</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/pccSecretary"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/> - <rdfs:label xml:lang="en">pcc secretary</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/serviceEndDate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/MilitaryPerson"/> - <rdfs:label xml:lang="en">service end date</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/> - </rdf:Description> - <rdf:Description rdf:about="http://dbpedia.org/ontology/beatifiedDate"> - <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/> - <rdfs:domain rdf:resource="http://dbpedia.org/ontology/Saint"/> - <rdfs:label xml:lang="nl">zalig verklaard datum</rdfs:label> - <rdfs:label xml:lang="en">beatified date</rdfs:label> - <rdf:type rdf:resource="http://www.w3.org... [truncated message content] |
From: <lor...@us...> - 2014-02-18 09:50:54
|
Revision: 4231 http://sourceforge.net/p/dl-learner/code/4231 Author: lorenz_b Date: 2014-02-18 09:50:49 +0000 (Tue, 18 Feb 2014) Log Message: ----------- Small fix in eval. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIDescriptionConvertVisitor.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java 2014-02-17 23:35:23 UTC (rev 4230) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java 2014-02-18 09:50:49 UTC (rev 4231) @@ -38,7 +38,7 @@ private static final Logger logger = Logger.getLogger(RelevanceMapGenerator.class.getName()); public static String cacheDirectory = "cache/relevance"; - public static Map<Entity, Double> generateRelevanceMap(NamedClass cls, OWLOntology ontology, RelevanceMetric relevanceMetric, boolean cached){ + public static synchronized Map<Entity, Double> generateRelevanceMap(NamedClass cls, OWLOntology ontology, RelevanceMetric relevanceMetric, boolean cached){ logger.info("Relevance Metric: " + relevanceMetric.getClass().getSimpleName()); Map<Entity, Double> relevanceMap = null; File folder = new File(cacheDirectory); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2014-02-17 23:35:23 UTC (rev 4230) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2014-02-18 09:50:49 UTC (rev 4231) @@ -4,6 +4,7 @@ package org.dllearner.algorithms.isle.metrics; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -36,9 +37,9 @@ * @param metric * @return */ - public static Map<Entity, Double> getRelevantEntities(final Entity entity, Set<Entity> otherEntities, final RelevanceMetric metric){ + public static synchronized Map<Entity, Double> getRelevantEntities(final Entity entity, Set<Entity> otherEntities, final RelevanceMetric metric){ logger.info("Get relevant entities for " + entity); - final Map<Entity, Double> relevantEntities = new HashMap<Entity, Double>(); + final Map<Entity, Double> relevantEntities = Collections.synchronizedMap(new HashMap<Entity, Double>()); ExecutorService executor = Executors.newFixedThreadPool(maxNrOfThreads); @@ -46,10 +47,14 @@ executor.submit(new Runnable() { @Override public void run() { -// double relevance = metric.getNormalizedRelevance(entity, otherEntity); - double relevance = metric.getRelevance(entity, otherEntity); -// logger.info(otherEntity + ":" + relevance); - relevantEntities.put(otherEntity, relevance); + try { +// double relevance = metric.getNormalizedRelevance(entity, otherEntity); + double relevance = metric.getRelevance(entity, otherEntity); +// logger.info(otherEntity + ":" + relevance); + relevantEntities.put(otherEntity, relevance); + } catch (Exception e) { + e.printStackTrace(); + } } }); } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-02-17 23:35:23 UTC (rev 4230) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-02-18 09:50:49 UTC (rev 4231) @@ -212,7 +212,7 @@ logger.info("Negative examples(" + superClassNegativeExamples.size() + "): " + superClassNegativeExamples); negativeExamples.addAll(superClassNegativeExamples); } else if(strategy == RANDOM){//get some random examples - String query = "SELECT ?s WHERE {?s a ?type. FILTER NOT EXIST{?type rdfs:subClassOf* }}"; + String query = "SELECT ?s WHERE {?s a ?type. FILTER NOT EXIST{?s a <> }} ORDER BY RAND() LIMIT " + maxNrOfReturnedInstances; } } return negativeExamples; Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIDescriptionConvertVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIDescriptionConvertVisitor.java 2014-02-17 23:35:23 UTC (rev 4230) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIDescriptionConvertVisitor.java 2014-02-18 09:50:49 UTC (rev 4231) @@ -25,6 +25,7 @@ import org.dllearner.algorithms.gp.ADC; import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; import org.dllearner.core.owl.DatatypeMaxCardinalityRestriction; @@ -312,20 +313,31 @@ // TODO: currently works only for double min/max DatatypeProperty dp = (DatatypeProperty) description.getRestrictedPropertyExpression(); - // currently only double restrictions implemented - SimpleDoubleDataRange dr = (SimpleDoubleDataRange) description.getDataRange(); - double value = dr.getValue(); - OWLDatatype doubleDataType = factory.getOWLDatatype(XSDVocabulary.DOUBLE.getIRI()); - OWLLiteral constant = factory.getOWLLiteral(value); + //convert the datarange + OWLDataRange owlDataRange; + DataRange dataRange = description.getDataRange(); + if(dataRange.isDatatype()){ + owlDataRange = factory.getOWLDatatype(IRI.create(dataRange.toString())); + } else if(dataRange instanceof SimpleDoubleDataRange){ + // currently only double restrictions implemented + SimpleDoubleDataRange dr = (SimpleDoubleDataRange) description.getDataRange(); + double value = dr.getValue(); + + OWLDatatype doubleDataType = factory.getOWLDatatype(XSDVocabulary.DOUBLE.getIRI()); + OWLLiteral constant = factory.getOWLLiteral(value); - OWLFacet facet; - if(dr instanceof DoubleMinValue) - facet = OWLFacet.MIN_INCLUSIVE; - else - facet = OWLFacet.MAX_INCLUSIVE; - - OWLDataRange owlDataRange = factory.getOWLDatatypeRestriction(doubleDataType, facet, constant); + OWLFacet facet; + if(dr instanceof DoubleMinValue) + facet = OWLFacet.MIN_INCLUSIVE; + else + facet = OWLFacet.MAX_INCLUSIVE; + + owlDataRange = factory.getOWLDatatypeRestriction(doubleDataType, facet, constant); + } else { + throw new UnsupportedOperationException("Can not convert " + description); + } + OWLDataProperty odp = factory.getOWLDataProperty(IRI.create(dp.getName())); OWLClassExpression d = factory.getOWLDataSomeValuesFrom(odp, owlDataRange); Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 23:35:23 UTC (rev 4230) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-18 09:50:49 UTC (rev 4231) @@ -12,6 +12,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; @@ -58,11 +59,13 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.EquivalentClassesAxiom; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -81,11 +84,13 @@ import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.PrefixCCMap; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; +import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; @@ -143,6 +148,7 @@ private SPARQLReasoner sparqlReasoner; private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; + final int minNrOfPositiveExamples = 3; final int maxNrOfPositiveExamples = 100; final int maxNrOfNegativeExamples = 200; boolean posOnly = false; @@ -228,6 +234,7 @@ for (RelevanceMetric metric : relevanceMetrics) { sql += metric.getClass().getSimpleName().replace("RelevanceMetric", "") + " DECIMAL(8,6) NOT NULL,"; } + sql += "axiom TEXT NOT NULL,"; sql += "PRIMARY KEY(id)," + "INDEX(class(200))) DEFAULT CHARSET=utf8"; st.execute(sql); @@ -236,7 +243,8 @@ for (RelevanceMetric metric : relevanceMetrics) { sql += "," + metric.getClass().getSimpleName().replace("RelevanceMetric", ""); } - sql += ") VALUES(?,?,?,?,?,?"; + sql += ",axiom"; + sql += ") VALUES(?,?,?,?,?,?,?"; for(int i = 0 ; i < relevanceMetrics.size(); i++){ sql += ",?"; } @@ -265,8 +273,8 @@ // new NamedClass("http://dbpedia.org/ontology/Comics"), // new NamedClass("http://dbpedia.org/ontology/Actor"), // new NamedClass("http://dbpedia.org/ontology/Book")); - new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); - System.exit(0); +// new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); +// System.exit(0); ExecutorService executor = Executors.newFixedThreadPool(6); @@ -303,8 +311,8 @@ //get some positive examples SortedSet<Individual> positiveExamples = getPositiveExamples(cls); - //we can stop if there are no positive examples - if(positiveExamples.isEmpty()){ + //we can stop if there are not at least x positive examples + if(positiveExamples.size() < minNrOfPositiveExamples){ logger.info("Empty class."); return; } @@ -725,6 +733,27 @@ return classes; } + /** + * Rewrite OWLAxiom into OWL Functional style syntax. + * @param axiom + * @return + */ + private String render(Axiom dllearnerAxiom){ + try { + OWLAxiom axiom = OWLAPIConverter.getOWLAPIAxiom(dllearnerAxiom); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = man.createOntology(); + man.addAxiom(ontology, axiom); + StringWriter sw = new StringWriter(); + org.coode.owlapi.functionalrenderer.OWLObjectRenderer r = new org.coode.owlapi.functionalrenderer.OWLObjectRenderer(man, ontology, sw); + axiom.accept(r); + return sw.toString(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } + return null; + } + private synchronized void write2DB(FastInstanceChecker reasoner, AbstractLearningProblem lp, NamedClass cls, TreeSet<? extends EvaluatedDescription> evaluatedDescriptions, Map<RelevanceMetric, Map<Entity, Double>> entityRelevances) throws SQLException{ int position = 1; for(EvaluatedDescription ed : evaluatedDescriptions.descendingSet()) { @@ -747,6 +776,7 @@ double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevances.get(metric)); ps.setDouble(col++, relevanceScore); } + ps.setString(col, render(new EquivalentClassesAxiom(cls, ed.getDescription()))); ps.addBatch(); } @@ -770,8 +800,8 @@ // la.start(); long start = System.currentTimeMillis(); - new DBpediaExperiment().run(); -// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Comics")); +// new DBpediaExperiment().run(); + new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Astronaut")); long end = System.currentTimeMillis(); logger.info("Operation took " + (end - start) + "ms"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <far...@us...> - 2014-02-17 23:35:27
|
Revision: 4230 http://sourceforge.net/p/dl-learner/code/4230 Author: farshadbadie Date: 2014-02-17 23:35:23 +0000 (Mon, 17 Feb 2014) Log Message: ----------- FuzzyCELOE extension test Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/pom.xml Added Paths: ----------- trunk/test/fuzzydll/FuzzyDL.jar trunk/test/fuzzydll/fuzzy_trains.conf trunk/test/fuzzydll/gurobi-5.0.1.jar 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 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2014-02-17 23:35:23 UTC (rev 4230) @@ -26,6 +26,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -448,6 +449,8 @@ // chose best node according to heuristics nextNode = getNextNodeToExpand(); + if(nextNode == null) + break; int horizExp = nextNode.getHorizontalExpansion(); // apply operator @@ -561,7 +564,15 @@ // this should practically never be called, since for any reasonable learning // task, we will always have at least one node with less than 100% accuracy - return nodes.last(); + // *** patch start *** + FuzzyOENode last; + try { + last = nodes.last(); + } catch (NoSuchElementException e) { + return null; + } + return last; + // *** patch end *** } // expand node horizontically Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/interfaces/pom.xml 2014-02-17 23:35:23 UTC (rev 4230) @@ -606,6 +606,10 @@ <version>2.8.0</version> </dependency> + <dependency> + <groupId>gurobi</groupId> + <artifactId>gurobi</artifactId> + </dependency> </dependencies> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-02-17 23:35:23 UTC (rev 4230) @@ -215,7 +215,7 @@ // Get the Root Error Message logger.error("An Error Has Occurred During Processing."); - logger.error(primaryCause.getMessage()); +// logger.error(primaryCause.getMessage()); logger.debug("Stack Trace: ", e); logger.error("Terminating DL-Learner...and writing stacktrace to: " + stacktraceFileName); FileOutputStream fos = new FileOutputStream(stacktraceFileName); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/pom.xml 2014-02-17 23:35:23 UTC (rev 4230) @@ -508,8 +508,13 @@ <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> - - </dependencies> + + <dependency> + <groupId>gurobi</groupId> + <artifactId>gurobi</artifactId> + <version>5.0.1</version> + </dependency> + </dependencies> </dependencyManagement> <repositories> Added: trunk/test/fuzzydll/FuzzyDL.jar =================================================================== (Binary files differ) Index: trunk/test/fuzzydll/FuzzyDL.jar =================================================================== --- trunk/test/fuzzydll/FuzzyDL.jar 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/test/fuzzydll/FuzzyDL.jar 2014-02-17 23:35:23 UTC (rev 4230) Property changes on: trunk/test/fuzzydll/FuzzyDL.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/test/fuzzydll/fuzzy_trains.conf =================================================================== --- trunk/test/fuzzydll/fuzzy_trains.conf (rev 0) +++ trunk/test/fuzzydll/fuzzy_trains.conf 2014-02-17 23:35:23 UTC (rev 4230) @@ -0,0 +1,22 @@ + +// declare some prefixes to use as abbreviations +prefixes = [ ("ex","http://www.example.com/fuzzyTrains.owl#") ] + +// knowledge source definition +ks.type = "OWL File" +ks.fileName = "fuzzyTrains_v5.0.owl" + +// reasoner +reasoner.type = "Fuzzy OWL API Reasoner" +reasoner.sources = { ks } + +// learning problem +problem.type = "fuzzyPosNeg" +problem.positiveExamples = { } +problem.negativeExamples = { } +problem.fuzzyEx = [("ex:east1",0.7),("ex:east2",0.5),("ex:west8",0.3),("ex:west9",0.1)] +problem.reasoner = reasoner + +// algorithm +algorithm.type = "Fuzzy CELOE" +algorithm.reasoner = reasoner \ No newline at end of file Added: trunk/test/fuzzydll/gurobi-5.0.1.jar =================================================================== (Binary files differ) Index: trunk/test/fuzzydll/gurobi-5.0.1.jar =================================================================== --- trunk/test/fuzzydll/gurobi-5.0.1.jar 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/test/fuzzydll/gurobi-5.0.1.jar 2014-02-17 23:35:23 UTC (rev 4230) Property changes on: trunk/test/fuzzydll/gurobi-5.0.1.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-17 15:51:45
|
Revision: 4229 http://sourceforge.net/p/dl-learner/code/4229 Author: lorenz_b Date: 2014-02-17 15:51:37 +0000 (Mon, 17 Feb 2014) Log Message: ----------- Simplified index creation. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/TextDocumentGenerator.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/AnnotationEntityTextRetriever.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/EntityTextRetriever.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/TextDocumentGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/TextDocumentGenerator.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/TextDocumentGenerator.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -1,5 +1,6 @@ package org.dllearner.algorithms.isle; +import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -26,11 +27,16 @@ private static TextDocumentGenerator instance; private StanfordCoreNLP pipeline; + private StanfordCoreNLP pipelineSimple; private final String punctuationPattern = "\\p{Punct}"; private final StopWordFilter stopWordFilter = new StopWordFilter(); private TextDocumentGenerator(){ Properties props = new Properties(); + props.put("annotators", "tokenize, ssplit");//, pos, lemma, parse"); + pipelineSimple = new StanfordCoreNLP(props); + + props = new Properties(); props.put("annotators", "tokenize, ssplit, pos, lemma, parse"); pipeline = new StanfordCoreNLP(props); } @@ -95,8 +101,7 @@ String lemma = label.get(LemmaAnnotation.class); //check if token is punctuation boolean isPunctuation = word.matches(punctuationPattern) - || pos.equalsIgnoreCase("-lrb-") - || pos.equalsIgnoreCase("-rrb-") + || (pos != null && (pos.equalsIgnoreCase("-lrb-") || pos.equalsIgnoreCase("-rrb-"))) || word.startsWith("'") ; //check if it is a stop word @@ -115,6 +120,33 @@ return document; } + public List<String> generateDocumentSimple(String text) { + List<String> tokens = new ArrayList<>(); + + // create an empty Annotation just with the given text + Annotation annotatedDocument = new Annotation(text); + + // run all Annotators on this text + pipelineSimple.annotate(annotatedDocument); + + // these are all the sentences in this document + // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types + List<CoreMap> sentences = annotatedDocument.get(SentencesAnnotation.class); + + for(CoreMap sentence: sentences) { + + + for (CoreLabel label: sentence.get(TokensAnnotation.class)) { + // this is the text of the token + String word = label.get(TextAnnotation.class); + + tokens.add(word); + } + } + + return tokens; + } + public static void main(String[] args) throws Exception { TextDocument document = TextDocumentGenerator.getInstance().generateDocument("And he said, Amos, what seest thou? And I said, A basket of summer fruit. Then said the LORD unto me, The end is come upon my people of Israel; I will not again pass by them any more. "); System.out.println(document); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -64,7 +64,7 @@ long totalNumberOfDocuments = -1; - Map<Set<Entity>, Long> cache = new HashMap<>(); + Map<Set<Entity>, Long> cache = Collections.synchronizedMap(new HashMap<Set<Entity>, Long>()); private OWLOntology ontology; public SolrSyntacticIndex(OWLOntology ontology, String solrServerURL, String searchField) { @@ -84,6 +84,15 @@ } } logger.info("...done."); + Entity e = new NamedClass("http://dbpedia.org/ontology/Comics"); + int i = 0; + for (Set<Entity> entities : cache.keySet()) { + if(entities.contains(e)){ + System.out.println(entities); + i++; + } + } + System.out.println(i); } public void buildIndex(Collection<NamedClass> classes){ @@ -103,7 +112,6 @@ final Set<Entity> otherEntities = OWLAPIConverter.getEntities(owlEntities); otherEntities.addAll(classes); for (final Entity entity : otherEntities) { - logger.info(entity); executor.submit(new Runnable() { @Override @@ -214,17 +222,13 @@ if(cache.containsKey(entitySet)){ return cache.get(entitySet); } - Map<List<Token>, Double> relevantText = textRetriever.getRelevantText(entity); + Map<String, Double> relevantText = textRetriever.getRelevantTextSimple(entity); String queryString = "("; Set<String> terms = new HashSet<>(); - for (Entry<List<Token>, Double> entry : relevantText.entrySet()) { - List<Token> tokens = entry.getKey(); - String phrase = ""; - for (Token token : tokens) { -// terms.add(token.getRawForm()); - phrase += token.getRawForm() + " "; - } + for (Entry<String, Double> entry : relevantText.entrySet()) { + String tokens = entry.getKey(); + String phrase = tokens; phrase.trim(); terms.add(quotedString(phrase)); } @@ -256,17 +260,13 @@ Set<String> queryStringParts = new HashSet<>(); for (Entity entity : entities) { - Map<List<Token>, Double> relevantText = textRetriever.getRelevantText(entity); + Map<String, Double> relevantText = textRetriever.getRelevantTextSimple(entity); String queryString = "("; Set<String> terms = new HashSet<>(); - for (Entry<List<Token>, Double> entry : relevantText.entrySet()) { - List<Token> tokens = entry.getKey(); - String phrase = ""; - for (Token token : tokens) { -// terms.add(token.getRawForm()); - phrase += token.getRawForm() + " "; - } + for (Entry<String, Double> entry : relevantText.entrySet()) { + String tokens = entry.getKey(); + String phrase = tokens; phrase.trim(); terms.add(quotedString(phrase)); } @@ -330,10 +330,10 @@ String searchField = "comment"; OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl")); SolrSyntacticIndex index = new SolrSyntacticIndex(ontology, solrServerURL, searchField); - index.loadCache(new File("frequencies.obj")); - long n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Abbey")); + index.loadCache(new File("entity_frequencies.obj")); + long n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Comics")); System.out.println(n); - n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Abbey"), new ObjectProperty("http://dbpedia.org/ontology/largestCity")); + n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Comics"), new ObjectProperty("http://dbpedia.org/ontology/largestCity")); System.out.println(n); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/AnnotationEntityTextRetriever.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/AnnotationEntityTextRetriever.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/AnnotationEntityTextRetriever.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -98,7 +98,11 @@ } //remove content in brackets like (...) label = label.replaceAll("\\s?\\((.*?)\\)", ""); - textWithWeight.put(TextDocumentGenerator.getInstance().generateDocument(label, determineHeadNoun), weight); + try { + textWithWeight.put(TextDocumentGenerator.getInstance().generateDocument(label, determineHeadNoun), weight); + } catch (Exception e1) { + e1.printStackTrace(); + } } } } @@ -114,6 +118,45 @@ return textWithWeight; } + @Override + public Map<String, Double> getRelevantTextSimple(Entity entity) { + Map<String, Double> textWithWeight = new HashMap<String, Double>(); + + OWLEntity e = OWLAPIConverter.getOWLAPIEntity(entity); + + for (OWLAnnotationProperty property : properties) { + Set<OWLAnnotation> annotations = e.getAnnotations(ontology, property); + for (OWLAnnotation annotation : annotations) { + if (annotation.getValue() instanceof OWLLiteral) { + OWLLiteral val = (OWLLiteral) annotation.getValue(); + if (val.hasLang(language)) { + //trim + String label = val.getLiteral().trim(); + if(entity instanceof NamedClass){ + label = label.toLowerCase(); + } + //remove content in brackets like (...) + label = label.replaceAll("\\s?\\((.*?)\\)", ""); + try { + textWithWeight.put(label, weight); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + } + } + + if(textWithWeight.isEmpty() && useShortFormFallback){ + String shortForm = sfp.getShortForm(IRI.create(entity.getURI())); + shortForm = Joiner.on(" ").join(LinguisticUtil.getInstance().getWordsFromCamelCase(shortForm)); + shortForm = Joiner.on(" ").join(LinguisticUtil.getInstance().getWordsFromUnderscored(shortForm)).trim(); + textWithWeight.put(shortForm, weight); + } + + return textWithWeight; + } + /** * Returns for each entity in the ontology all relevant text, i.e. either the annotations or the short form of the IRI as fallback. * @return Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/EntityTextRetriever.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/EntityTextRetriever.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/textretrieval/EntityTextRetriever.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -50,5 +50,11 @@ public Map<List<Token>, Double> getRelevantText(Entity entity); public Map<Entity, Set<List<Token>>> getRelevantText(OWLOntology ontology); + + /** + * @param entity + * @return + */ + Map<String, Double> getRelevantTextSimple(Entity entity); } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -80,29 +80,36 @@ return name.compareTo(o.name); } + /* (non-Javadoc) + * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) + */ @Override - public boolean equals(Object nc) { - // standard equals code - always return true for object identity and - // false if classes differ - if(nc == this) { - return true; - } else if(getClass() != nc.getClass()) { - return false; - } - // compare on URIs - return ((DatatypeProperty)nc).name.equals(name); + public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { + return Helper.getAbbreviatedString(name, baseURI, prefixes); } - + @Override public int hashCode() { - return name.hashCode(); + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; } - /* (non-Javadoc) - * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) - */ @Override - public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return Helper.getAbbreviatedString(name, baseURI, prefixes); + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DatatypeProperty other = (DatatypeProperty) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -71,24 +71,6 @@ return name.compareTo(o.name); } - @Override - public boolean equals(Object nc) { - // standard equals code - always return true for object identity and - // false if classes differ - if(nc == this) { - return true; - } else if(getClass() != nc.getClass()) { - return false; - } - // compare on URIs - return ((ObjectProperty)nc).name.equals(name); - } - - @Override - public int hashCode() { - return name.hashCode(); - } - /* (non-Javadoc) * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) */ Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -44,5 +44,30 @@ public String getName() { return name; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ObjectPropertyExpression other = (ObjectPropertyExpression) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 13:55:46 UTC (rev 4228) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 15:51:37 UTC (rev 4229) @@ -95,6 +95,7 @@ import org.semanticweb.owlapi.util.OWLEntityRemover; import com.google.common.base.Charsets; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; @@ -260,10 +261,13 @@ List<NamedClass> classList = new ArrayList<>(classes); // Collections.reverse(classList); // classList = classList.subList(0, 2); +// classList = Lists.newArrayList( +// new NamedClass("http://dbpedia.org/ontology/Comics"), +// new NamedClass("http://dbpedia.org/ontology/Actor"), +// new NamedClass("http://dbpedia.org/ontology/Book")); + new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); + System.exit(0); -// new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); -// System.exit(0); - ExecutorService executor = Executors.newFixedThreadPool(6); for (final NamedClass cls : classList) { @@ -316,7 +320,6 @@ // e.printStackTrace(); // } - /** //set up the learning try { // set KB @@ -436,7 +439,6 @@ } catch (ComponentInitException e) { e.printStackTrace(); } - */ } /** @@ -697,7 +699,8 @@ private Index getSyntacticIndex(){ SolrSyntacticIndex index = new SolrSyntacticIndex(schema, solrServerURL, searchField); // try { -// index.loadCache(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_entity_frequencies.obj")); +//// index.loadCache(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_entity_frequencies.obj")); +// index.loadCache(new File("frequencies.obj")); // } catch (IOException e) { // e.printStackTrace(); // } @@ -767,8 +770,8 @@ // la.start(); long start = System.currentTimeMillis(); -// new DBpediaExperiment().run(); - new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Book")); + new DBpediaExperiment().run(); +// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Comics")); long end = System.currentTimeMillis(); logger.info("Operation took " + (end - start) + "ms"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-17 13:55:51
|
Revision: 4228 http://sourceforge.net/p/dl-learner/code/4228 Author: lorenz_b Date: 2014-02-17 13:55:46 +0000 (Mon, 17 Feb 2014) Log Message: ----------- Optimized frequency cache creation. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-17 12:43:55 UTC (rev 4227) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-17 13:55:46 UTC (rev 4228) @@ -99,38 +99,41 @@ final Map<Set<Entity>, Long> frequencyCache = Collections.synchronizedMap(new HashMap<Set<Entity>, Long>()); - - for (final NamedClass cls : classes) { + //fA resp. fB + final Set<Entity> otherEntities = OWLAPIConverter.getEntities(owlEntities); + otherEntities.addAll(classes); + for (final Entity entity : otherEntities) { + logger.info(entity); executor.submit(new Runnable() { @Override public void run() { - Set<Entity> entities; - logger.info(cls); - Set<Entity> otherEntities = OWLAPIConverter.getEntities(owlEntities); - otherEntities.remove(cls); - //fA - long fA = getNumberOfDocumentsFor(cls); - entities = new HashSet<>(); - entities.add(cls); - frequencyCache.put(entities, fA); - for (Entity entity : otherEntities) { - //fB - long fB = getNumberOfDocumentsFor(entity); - entities = new HashSet<>(); - entities.add(entity); - frequencyCache.put(entities, fB); - //fAB - long fAB = getNumberOfDocumentsFor(cls, entity); - entities = new HashSet<>(); - entities.add(cls); - entities.add(entity); - frequencyCache.put(entities, fAB); - - } + Set<Entity> entities = new HashSet<>(); + entities.add(entity); + long f = getNumberOfDocumentsFor(entity); + frequencyCache.put(entities, f); } }); } + //fAB + for (final NamedClass cls : classes) { + logger.info(cls); + for (final Entity entity : otherEntities) { + if(!cls.equals(entity)){ + executor.submit(new Runnable() { + + @Override + public void run() { + Set<Entity> entities = new HashSet<>(); + entities.add(cls); + entities.add(entity); + long fAB = getNumberOfDocumentsFor(cls, entity); + frequencyCache.put(entities, fAB); + } + }); + } + } + } executor.shutdown(); try { executor.awaitTermination(10, TimeUnit.DAYS); @@ -139,7 +142,7 @@ } logger.info("Cache size: " + frequencyCache.size()); try { - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("frequencies.obj")); + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("entity_frequencies.obj")); oos.writeObject(frequencyCache); oos.close(); } catch (FileNotFoundException e) { Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 12:43:55 UTC (rev 4227) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 13:55:46 UTC (rev 4228) @@ -602,7 +602,6 @@ "OPTIONAL{?x ?p ?o1. " + "FILTER NOT EXISTS{?x a <" + cls.getName() + ">.}}} " + "GROUP BY ?p ORDER BY DESC(?cnt)", Syntax.syntaxARQ); - System.out.println(query); System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, model).execSelect())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-17 12:44:00
|
Revision: 4227 http://sourceforge.net/p/dl-learner/code/4227 Author: lorenz_b Date: 2014-02-17 12:43:55 +0000 (Mon, 17 Feb 2014) Log Message: ----------- Modified tree ranking - now via score. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-02-17 10:58:16 UTC (rev 4226) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-02-17 12:43:55 UTC (rev 4227) @@ -237,7 +237,7 @@ } else { node.setCoveredNegatives(negCovers); } -// node.setScore(accuracy); + node.setScore(accuracy); // System.out.println(description + ":" + accuracy); // link to parent (unless start node) if(parentNode == null) { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java 2014-02-17 10:58:16 UTC (rev 4226) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java 2014-02-17 12:43:55 UTC (rev 4227) @@ -37,7 +37,7 @@ public int compare(SearchTreeNode o1, SearchTreeNode o2) { int diff = o2.getCoveredNegatives() - o1.getCoveredNegatives(); -// diff = Double.compare(o1.getScore(), o2.getScore()); + diff = Double.compare(o1.getScore(), o2.getScore()); if(diff>0) { return 1; } else if(diff<0) { Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 10:58:16 UTC (rev 4226) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 12:43:55 UTC (rev 4227) @@ -142,14 +142,14 @@ private SPARQLReasoner sparqlReasoner; private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; - final int maxNrOfPositiveExamples = 10; - final int maxNrOfNegativeExamples = 20; + final int maxNrOfPositiveExamples = 100; + final int maxNrOfNegativeExamples = 200; boolean posOnly = false; int maxCBDDepth = 1; //learning algorithm settings private int maxNrOfResults = 100; - private int maxExecutionTimeInSeconds = 10; + private int maxExecutionTimeInSeconds = 60; private double noiseInPercentage = 50; private boolean useNegation = false; private boolean useAllConstructor = false; @@ -221,7 +221,9 @@ + "class TEXT NOT NULL," + "position TINYINT NOT NULL," + "expression TEXT NOT NULL," - + "fscore DECIMAL(8,6) NOT NULL,"; + + "fscore DECIMAL(8,6) NOT NULL," + + "expression_length TINYINT NOT NULL,"; + for (RelevanceMetric metric : relevanceMetrics) { sql += metric.getClass().getSimpleName().replace("RelevanceMetric", "") + " DECIMAL(8,6) NOT NULL,"; } @@ -229,11 +231,11 @@ + "INDEX(class(200))) DEFAULT CHARSET=utf8"; st.execute(sql); - sql = "INSERT INTO ISLE_Evaluation (id, class, position, expression, fscore"; + sql = "INSERT INTO ISLE_Evaluation (id, class, position, expression, fscore, expression_length"; for (RelevanceMetric metric : relevanceMetrics) { sql += "," + metric.getClass().getSimpleName().replace("RelevanceMetric", ""); } - sql += ") VALUES(?,?,?,?,?"; + sql += ") VALUES(?,?,?,?,?,?"; for(int i = 0 ; i < relevanceMetrics.size(); i++){ sql += ",?"; } @@ -259,8 +261,8 @@ // Collections.reverse(classList); // classList = classList.subList(0, 2); - new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); - System.exit(0); +// new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); +// System.exit(0); ExecutorService executor = Executors.newFixedThreadPool(6); @@ -314,6 +316,7 @@ // e.printStackTrace(); // } + /** //set up the learning try { // set KB @@ -433,6 +436,7 @@ } catch (ComponentInitException e) { e.printStackTrace(); } + */ } /** @@ -598,7 +602,7 @@ "OPTIONAL{?x ?p ?o1. " + "FILTER NOT EXISTS{?x a <" + cls.getName() + ">.}}} " + "GROUP BY ?p ORDER BY DESC(?cnt)", Syntax.syntaxARQ); - + System.out.println(query); System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, model).execSelect())); } @@ -735,7 +739,8 @@ ps.setInt(3, position++); ps.setString(4, expression); ps.setDouble(5, fMeasure); - int col = 6; + ps.setInt(6, ed.getDescriptionLength()); + int col = 7; for (RelevanceMetric metric : relevanceMetrics) { double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevances.get(metric)); ps.setDouble(col++, relevanceScore); @@ -763,8 +768,8 @@ // la.start(); long start = System.currentTimeMillis(); - new DBpediaExperiment().run(); -// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Case")); +// new DBpediaExperiment().run(); + new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Book")); long end = System.currentTimeMillis(); logger.info("Operation took " + (end - start) + "ms"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-17 10:58:19
|
Revision: 4226 http://sourceforge.net/p/dl-learner/code/4226 Author: lorenz_b Date: 2014-02-17 10:58:16 +0000 (Mon, 17 Feb 2014) Log Message: ----------- Added frequency cache loading. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-16 18:55:19 UTC (rev 4225) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-17 10:58:16 UTC (rev 4226) @@ -4,22 +4,24 @@ package org.dllearner.algorithms.isle.index.syntactic; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import java.util.TreeSet; -import java.util.Map.Entry; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import java.util.Set; import org.apache.log4j.Logger; import org.apache.solr.client.solrj.SolrQuery; @@ -62,8 +64,7 @@ long totalNumberOfDocuments = -1; - Map<Entity, Long> cache = new HashMap<>(); - Map<List<Entity>, Long> cache2 = new HashMap<>(); + Map<Set<Entity>, Long> cache = new HashMap<>(); private OWLOntology ontology; public SolrSyntacticIndex(OWLOntology ontology, String solrServerURL, String searchField) { @@ -73,8 +74,21 @@ textRetriever = new RDFSLabelEntityTextRetriever(ontology); } - public void buildIndex(Set<NamedClass> classes){ + public void loadCache(File file) throws IOException{ + logger.info("Loading cache..."); + try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))){ + try { + cache = Collections.synchronizedMap((Map<Set<Entity>, Long>) ois.readObject()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + logger.info("...done."); + } + + public void buildIndex(Collection<NamedClass> classes){ logger.info("Building cache..."); + logger.info("#Classes: " + classes.size()); ExecutorService executor = Executors.newFixedThreadPool(6); @@ -83,7 +97,7 @@ owlEntities.addAll(ontology.getDataPropertiesInSignature()); owlEntities.addAll(ontology.getObjectPropertiesInSignature()); - final Map<Set<Entity>, Long> cache = Collections.synchronizedMap(new HashMap<Set<Entity>, Long>()); + final Map<Set<Entity>, Long> frequencyCache = Collections.synchronizedMap(new HashMap<Set<Entity>, Long>()); for (final NamedClass cls : classes) { @@ -99,19 +113,20 @@ long fA = getNumberOfDocumentsFor(cls); entities = new HashSet<>(); entities.add(cls); - cache.put(entities, fA); + frequencyCache.put(entities, fA); for (Entity entity : otherEntities) { //fB long fB = getNumberOfDocumentsFor(entity); entities = new HashSet<>(); entities.add(entity); - cache.put(entities, fB); + frequencyCache.put(entities, fB); //fAB long fAB = getNumberOfDocumentsFor(cls, entity); entities = new HashSet<>(); entities.add(cls); entities.add(entity); - cache.put(entities, fAB); + frequencyCache.put(entities, fAB); + } } }); @@ -122,9 +137,11 @@ } catch (InterruptedException e) { e.printStackTrace(); } + logger.info("Cache size: " + frequencyCache.size()); try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("frequencies.obj")); - oos.writeObject(cache); + oos.writeObject(frequencyCache); + oos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { @@ -190,8 +207,9 @@ */ @Override public synchronized long getNumberOfDocumentsFor(Entity entity) { - if(cache.containsKey(entity)){ - return cache.get(entity); + HashSet<Entity> entitySet = Sets.newHashSet(entity); + if(cache.containsKey(entitySet)){ + return cache.get(entitySet); } Map<List<Token>, Double> relevantText = textRetriever.getRelevantText(entity); @@ -214,7 +232,7 @@ try { QueryResponse response = solr.query(query); SolrDocumentList list = response.getResults(); - cache.put(entity, list.getNumFound()); + cache.put(entitySet, list.getNumFound()); return list.getNumFound(); } catch (SolrServerException e) { e.printStackTrace(); @@ -227,9 +245,9 @@ */ @Override public synchronized long getNumberOfDocumentsFor(Entity... entities) { - List<Entity> entitiesList = Arrays.asList(entities); - if(cache2.containsKey(entitiesList)){ - return cache2.get(entitiesList); + Set<Entity> entitiesSet = Sets.newHashSet(entities); + if(cache.containsKey(entitiesSet)){ + return cache.get(entitiesSet); } Set<String> queryStringParts = new HashSet<>(); @@ -261,7 +279,7 @@ try { QueryResponse response = solr.query(query); SolrDocumentList list = response.getResults(); - cache2.put(entitiesList, list.getNumFound()); + cache.put(entitiesSet, list.getNumFound()); return list.getNumFound(); } catch (SolrServerException e) { e.printStackTrace(); @@ -271,8 +289,6 @@ public long getNumberOfDocumentsForTyped(NamedClass resourceClass, Entity entity) { - - Map<List<Token>, Double> relevantText = textRetriever.getRelevantText(entity); String queryString = "("; @@ -311,19 +327,11 @@ String searchField = "comment"; OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl")); SolrSyntacticIndex index = new SolrSyntacticIndex(ontology, solrServerURL, searchField); - long n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://schema.org/Canal")); + index.loadCache(new File("frequencies.obj")); + long n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Abbey")); System.out.println(n); - n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://schema.org/Canal")); + n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Abbey"), new ObjectProperty("http://dbpedia.org/ontology/largestCity")); System.out.println(n); - n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://dbpedia.org/ontology/nationality")); - System.out.println(n); - n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://dbpedia.org/ontology/birthPlace")); - System.out.println(n); - - System.out.println(index.getNumberOfDocumentsFor( - new NamedClass("http://dbpedia.org/ontology/Person"), new ObjectProperty("http://dbpedia.org/ontology/birthPlace"))); - System.out.println(index.getNumberOfDocumentsFor( - new NamedClass("http://dbpedia.org/ontology/Person"), new ObjectProperty("http://dbpedia.org/ontology/birthPlace"))); } } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-16 18:55:19 UTC (rev 4225) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-17 10:58:16 UTC (rev 4226) @@ -142,8 +142,8 @@ private SPARQLReasoner sparqlReasoner; private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; - final int maxNrOfPositiveExamples = 100; - final int maxNrOfNegativeExamples = 200; + final int maxNrOfPositiveExamples = 10; + final int maxNrOfNegativeExamples = 20; boolean posOnly = false; int maxCBDDepth = 1; @@ -257,9 +257,10 @@ classes = sparqlReasoner.getMostSpecificClasses(); List<NamedClass> classList = new ArrayList<>(classes); // Collections.reverse(classList); -// classList = classList.subList(0, 10); +// classList = classList.subList(0, 2); - new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classes); + new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classList); + System.exit(0); ExecutorService executor = Executors.newFixedThreadPool(6); @@ -313,8 +314,6 @@ // e.printStackTrace(); // } - return; - /** //set up the learning try { // set KB @@ -434,7 +433,6 @@ } catch (ComponentInitException e) { e.printStackTrace(); } - */ } /** @@ -694,7 +692,13 @@ } private Index getSyntacticIndex(){ - return new SolrSyntacticIndex(schema, solrServerURL, searchField); + SolrSyntacticIndex index = new SolrSyntacticIndex(schema, solrServerURL, searchField); +// try { +// index.loadCache(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_entity_frequencies.obj")); +// } catch (IOException e) { +// e.printStackTrace(); +// } + return index; } private Index getSemanticIndex(){ @@ -760,7 +764,7 @@ long start = System.currentTimeMillis(); new DBpediaExperiment().run(); -// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); +// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Case")); long end = System.currentTimeMillis(); logger.info("Operation took " + (end - start) + "ms"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-16 18:55:23
|
Revision: 4225 http://sourceforge.net/p/dl-learner/code/4225 Author: lorenz_b Date: 2014-02-16 18:55:19 +0000 (Sun, 16 Feb 2014) Log Message: ----------- Small modification in script. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-16 15:59:43 UTC (rev 4224) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-16 18:55:19 UTC (rev 4225) @@ -83,7 +83,7 @@ owlEntities.addAll(ontology.getDataPropertiesInSignature()); owlEntities.addAll(ontology.getObjectPropertiesInSignature()); - final Map<Set<Entity>, Long> cache = new HashMap<>(); + final Map<Set<Entity>, Long> cache = Collections.synchronizedMap(new HashMap<Set<Entity>, Long>()); for (final NamedClass cls : classes) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-16 15:59:46
|
Revision: 4224 http://sourceforge.net/p/dl-learner/code/4224 Author: lorenz_b Date: 2014-02-16 15:59:43 +0000 (Sun, 16 Feb 2014) Log Message: ----------- Added ISLE experiments. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/core/EvaluatedDescription.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.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 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -19,7 +19,10 @@ package org.dllearner.algorithms.celoe; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; @@ -29,6 +32,7 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.algorithms.elcopy.ELLearningAlgorithm; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractHeuristic; import org.dllearner.core.AbstractKnowledgeSource; @@ -45,6 +49,7 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; +import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; @@ -62,9 +67,19 @@ import org.dllearner.utilities.owl.ConceptTransformation; import org.dllearner.utilities.owl.DescriptionMinimizer; import org.dllearner.utilities.owl.EvaluatedDescriptionSet; +import org.dllearner.utilities.owl.OWLEntityTypeAdder; import org.dllearner.utilities.owl.PropertyContext; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLOntology; import org.springframework.beans.factory.annotation.Autowired; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -578,6 +593,7 @@ // System.out.println("refining: " + node); int horizExp = node.getHorizontalExpansion(); TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); + System.out.println(refinements); node.incHorizontalExpansion(); node.setRefinementCount(refinements.size()); nodes.add(node); @@ -1120,16 +1136,44 @@ } public static void main(String[] args) throws Exception{ - AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); + String cls = "http://purl.org/procurement/public-contracts#Tender"; + String file = "/home/me/work/datasets/e-procurement/dl-learner-sample-with-classes-pco.rdf"; + Model model = ModelFactory.createDefaultModel(); + model.read(new FileInputStream(file), null); + OWLEntityTypeAdder.addEntityTypes(model); + Query query = QueryFactory.create("SELECT (COUNT(distinct ?s) as ?cnt) WHERE {" + + "?s a <" + cls + ">.}", Syntax.syntaxARQ); + System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, model).execSelect())); + query = QueryFactory.create("SELECT ?p (COUNT(distinct ?s) AS ?cnt) WHERE {" + + "?s ?p ?o. ?p a <http://www.w3.org/2002/07/owl#ObjectProperty>." + + "?s a <" + cls + ">. " + +// "OPTIONAL{?x ?p ?o1. " + +// "FILTER NOT EXISTS{?x a <" + cls + ">.}}" + + + "}GROUP BY ?p ORDER BY DESC(?cnt)", Syntax.syntaxARQ); + + System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, model).execSelect())); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + model.write(baos, "TURTLE"); + OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new ByteArrayInputStream(baos.toByteArray())); + + AbstractKnowledgeSource ks = new OWLAPIOntology(ontology); ks.init(); AbstractReasonerComponent rc = new FastInstanceChecker(ks); rc.init(); ClassLearningProblem lp = new ClassLearningProblem(rc); - lp.setClassToDescribe(new NamedClass("http://example.com/father#father")); + lp.setClassToDescribe(new NamedClass("http://purl.org/procurement/public-contracts#Tender")); lp.init(); +// ELLearningAlgorithm alg = new ELLearningAlgorithm(lp, rc); +// alg.setNoisePercentage(30); +// alg.setClassToDescribe(new NamedClass("http://purl.org/procurement/public-contracts#Tender")); +// alg.init(); + + CELOE alg = new CELOE(lp, rc); alg.setMaxExecutionTimeInSeconds(10); alg.init(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -117,7 +117,6 @@ // private TreeSet<Description> descriptions; private SortedSet<Description> descriptions; - private EvaluatedDescriptionSet bestEvaluatedDescriptions; // if true, then each solution is evaluated exactly instead of approximately // private boolean exactBestDescriptionEvaluation = false; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -47,6 +47,7 @@ import org.dllearner.learningproblems.ScorePosNeg; import org.dllearner.refinementoperators.ELDown3; import org.dllearner.utilities.Helper; +import org.dllearner.utilities.owl.EvaluatedDescriptionSet; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -88,6 +89,10 @@ @ConfigOption(name = "startClass", defaultValue="owl:Thing", description="You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.") private Description startClass; + private int maxClassExpressionDepth = 2; + + private int maxNrOfResults = 10; + private Set<NamedClass> ignoredConcepts = null; private NamedClass classToDescribe; @@ -155,8 +160,11 @@ } operator = new ELDown3(reasoner, instanceBasedDisjoints); + operator.setMaxClassExpressionDepth(maxClassExpressionDepth); noise = noisePercentage/100d; + + bestEvaluatedDescriptions = new EvaluatedDescriptionSet(maxNrOfResults); } @Override @@ -229,7 +237,8 @@ } else { node.setCoveredNegatives(negCovers); } - node.setScore(accuracy); +// node.setScore(accuracy); +// System.out.println(description + ":" + accuracy); // link to parent (unless start node) if(parentNode == null) { startNode = node; @@ -481,5 +490,19 @@ public void setTreeSearchTimeSeconds(double treeSearchTimeSeconds) { this.treeSearchTimeSeconds = treeSearchTimeSeconds; } + + /** + * @param maxNrOfResults the maxNrOfResults to set + */ + public void setMaxNrOfResults(int maxNrOfResults) { + this.maxNrOfResults = maxNrOfResults; + } + + /** + * @param maxClassExpressionDepth the maxClassExpressionDepth to set + */ + public void setMaxClassExpressionDepth(int maxClassExpressionDepth) { + this.maxClassExpressionDepth = maxClassExpressionDepth; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -242,9 +242,13 @@ // form union of trees found so far with if(treeCount==0) { bestEvaluatedDescription = learningProblem.evaluate(bestDescription); + bestEvaluatedDescriptions.add(bestEvaluatedDescription); } else { - bestCombinedDescription = new Union(bestEvaluatedDescription.getDescription(), bestDescription); + if(!bestEvaluatedDescription.equals(Thing.instance)){ + bestCombinedDescription = new Union(bestEvaluatedDescription.getDescription(), bestDescription); + } bestEvaluatedDescription = learningProblem.evaluate(bestCombinedDescription); + bestEvaluatedDescriptions.add(bestEvaluatedDescription); } // remove already covered examples @@ -405,7 +409,7 @@ // return (bestNode.getCoveredNegatives() == 0); // stop if there are no more positive examples to cover - if(currentPosExamples.size()==0) { + if(stopOnFirstDefinition && currentPosExamples.size()==0) { return true; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -36,8 +36,8 @@ @Override public int compare(SearchTreeNode o1, SearchTreeNode o2) { - double diff = o2.getScore() - o1.getScore(); -// diff = -diff; + int diff = o2.getCoveredNegatives() - o1.getCoveredNegatives(); +// diff = Double.compare(o1.getScore(), o2.getScore()); if(diff>0) { return 1; } else if(diff<0) { Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -8,6 +8,11 @@ import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.apache.log4j.Logger; @@ -17,7 +22,6 @@ import org.dllearner.core.owl.NamedClass; import org.semanticweb.owlapi.model.OWLOntology; -import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; @@ -35,12 +39,13 @@ public static String cacheDirectory = "cache/relevance"; public static Map<Entity, Double> generateRelevanceMap(NamedClass cls, OWLOntology ontology, RelevanceMetric relevanceMetric, boolean cached){ + logger.info("Relevance Metric: " + relevanceMetric.getClass().getSimpleName()); Map<Entity, Double> relevanceMap = null; File folder = new File(cacheDirectory); folder.mkdirs(); File file = null; try { - file = new File(folder, URLEncoder.encode(cls.getName(), "UTF-8") + ".rel"); + file = new File(folder, URLEncoder.encode(cls.getName() + "-" + relevanceMetric.getClass().getSimpleName(), "UTF-8") + ".rel"); } catch (UnsupportedEncodingException e2) { e2.printStackTrace(); } @@ -69,6 +74,22 @@ return relevanceMap; } + public static Map<RelevanceMetric, Map<Entity, Double>> generateRelevanceMaps(NamedClass cls, OWLOntology ontology, List<RelevanceMetric> relevanceMetrics, boolean cached){ + Map<RelevanceMetric, Map<Entity, Double>> metric2Map = new LinkedHashMap<>(); + for (RelevanceMetric relevanceMetric : relevanceMetrics) { + try { + long start = System.currentTimeMillis(); + metric2Map.put(relevanceMetric, generateRelevanceMap(cls, ontology, relevanceMetric, cached)); + long end = System.currentTimeMillis(); + logger.info("Operation took " + (end - start) + "ms"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + return metric2Map; + } + public static Map<Entity, Double> generateRelevanceMap(NamedClass cls, OWLOntology ontology, RelevanceMetric relevanceMetric){ return generateRelevanceMap(cls, ontology, relevanceMetric, false); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -4,14 +4,24 @@ package org.dllearner.algorithms.isle.index.syntactic; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.TreeSet; import java.util.Map.Entry; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.Set; +import org.apache.log4j.Logger; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; @@ -28,11 +38,14 @@ import org.dllearner.algorithms.isle.textretrieval.RDFSLabelEntityTextRetriever; import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.utilities.owl.OWLAPIConverter; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; import com.google.common.base.Joiner; +import com.google.common.collect.Sets; /** * @author Lorenz Buehmann @@ -40,6 +53,8 @@ */ public class SolrSyntacticIndex implements Index{ + private static final Logger logger = Logger.getLogger(SolrSyntacticIndex.class.getName()); + private SolrServer solr; private AnnotationEntityTextRetriever textRetriever; private String searchField; @@ -48,13 +63,78 @@ long totalNumberOfDocuments = -1; Map<Entity, Long> cache = new HashMap<>(); + Map<List<Entity>, Long> cache2 = new HashMap<>(); + private OWLOntology ontology; public SolrSyntacticIndex(OWLOntology ontology, String solrServerURL, String searchField) { + this.ontology = ontology; this.searchField = searchField; solr = new HttpSolrServer(solrServerURL); textRetriever = new RDFSLabelEntityTextRetriever(ontology); } + public void buildIndex(Set<NamedClass> classes){ + logger.info("Building cache..."); + + ExecutorService executor = Executors.newFixedThreadPool(6); + + final Set<OWLEntity> owlEntities = new TreeSet<OWLEntity>(); + owlEntities.addAll(ontology.getClassesInSignature()); + owlEntities.addAll(ontology.getDataPropertiesInSignature()); + owlEntities.addAll(ontology.getObjectPropertiesInSignature()); + + final Map<Set<Entity>, Long> cache = new HashMap<>(); + + + for (final NamedClass cls : classes) { + executor.submit(new Runnable() { + + @Override + public void run() { + Set<Entity> entities; + logger.info(cls); + Set<Entity> otherEntities = OWLAPIConverter.getEntities(owlEntities); + otherEntities.remove(cls); + //fA + long fA = getNumberOfDocumentsFor(cls); + entities = new HashSet<>(); + entities.add(cls); + cache.put(entities, fA); + for (Entity entity : otherEntities) { + //fB + long fB = getNumberOfDocumentsFor(entity); + entities = new HashSet<>(); + entities.add(entity); + cache.put(entities, fB); + //fAB + long fAB = getNumberOfDocumentsFor(cls, entity); + entities = new HashSet<>(); + entities.add(cls); + entities.add(entity); + cache.put(entities, fAB); + } + } + }); + } + executor.shutdown(); + try { + executor.awaitTermination(10, TimeUnit.DAYS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("frequencies.obj")); + oos.writeObject(cache); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + /* (non-Javadoc) * @see org.dllearner.algorithms.isle.index.Index#getDocuments(org.dllearner.core.owl.Entity) */ @@ -109,7 +189,7 @@ * @see org.dllearner.algorithms.isle.index.Index#getNumberOfDocumentsFor(org.dllearner.core.owl.Entity) */ @Override - public long getNumberOfDocumentsFor(Entity entity) { + public synchronized long getNumberOfDocumentsFor(Entity entity) { if(cache.containsKey(entity)){ return cache.get(entity); } @@ -146,7 +226,11 @@ * @see org.dllearner.algorithms.isle.index.Index#getNumberOfDocumentsFor(org.dllearner.core.owl.Entity[]) */ @Override - public long getNumberOfDocumentsFor(Entity... entities) { + public synchronized long getNumberOfDocumentsFor(Entity... entities) { + List<Entity> entitiesList = Arrays.asList(entities); + if(cache2.containsKey(entitiesList)){ + return cache2.get(entitiesList); + } Set<String> queryStringParts = new HashSet<>(); @@ -177,6 +261,7 @@ try { QueryResponse response = solr.query(query); SolrDocumentList list = response.getResults(); + cache2.put(entitiesList, list.getNumFound()); return list.getNumFound(); } catch (SolrServerException e) { e.printStackTrace(); @@ -234,6 +319,11 @@ System.out.println(n); n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://dbpedia.org/ontology/birthPlace")); System.out.println(n); + + System.out.println(index.getNumberOfDocumentsFor( + new NamedClass("http://dbpedia.org/ontology/Person"), new ObjectProperty("http://dbpedia.org/ontology/birthPlace"))); + System.out.println(index.getNumberOfDocumentsFor( + new NamedClass("http://dbpedia.org/ontology/Person"), new ObjectProperty("http://dbpedia.org/ontology/birthPlace"))); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -7,7 +7,7 @@ import java.util.Map; import org.dllearner.algorithms.isle.index.Index; -import org.semanticweb.owlapi.model.OWLEntity; +import org.dllearner.core.owl.Entity; /** * @author Lorenz Buehmann @@ -20,33 +20,32 @@ public AbstractRelevanceMetric(Index index) { this.index = index; } - - public Map<OWLEntity,Double> normalizeMinMax( Map<OWLEntity,Double> hmEntity2Score ){ - Map<OWLEntity,Double> hmEntity2Norm = new HashMap<OWLEntity,Double>(); - double dMin = Double.MAX_VALUE; - Double dMax = Double.MIN_VALUE; - for( OWLEntity e : hmEntity2Score.keySet() ) - { - double dValue = hmEntity2Score.get(e); - if( dValue < dMin ){ - dMin = dValue; + + public static Map<Entity, Double> normalizeMinMax(Map<Entity, Double> hmEntity2Score) { + Map<Entity, Double> hmEntity2Norm = new HashMap<Entity, Double>(); + + double min = Double.MAX_VALUE; + double max = Double.MIN_VALUE; + + for (Entity e : hmEntity2Score.keySet()) { + double value = hmEntity2Score.get(e); + if (value < min) { + min = value; + } else if (value > max) { + max = value; } - else if( dValue > dMax ){ - dMax = dValue; - } } // System.out.println( "min="+ dMin +" max="+ dMax ); - for( OWLEntity e : hmEntity2Score.keySet() ) - { - double dValue = hmEntity2Score.get(e); - double dNorm = 0; - if( dMin == dMax ){ - dNorm = dValue; - } - else { - dNorm = ( dValue - dMin ) / ( dMax - dMin ); + for (Entity e : hmEntity2Score.keySet()) { + double value = hmEntity2Score.get(e); + double normalized = 0; + if (min == max) { + normalized = value; + normalized = 0.5; + } else { + normalized = (value - min) / (max - min); } - hmEntity2Norm.put( e, dNorm ); + hmEntity2Norm.put(e, normalized); } return hmEntity2Norm; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -17,7 +17,7 @@ } @Override - public synchronized double getRelevance(Entity entityA, Entity entityB){ + public double getRelevance(Entity entityA, Entity entityB){ long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); long nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); @@ -28,13 +28,17 @@ double pB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsB / (double) nrOfDocuments); double pAB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsAB / (double) nrOfDocuments); + if(pAB == 0 || (pA * pB) == 0){ + return 0; + } + double pmi = Math.log(pAB / pA * pB); return pmi; } @Override - public synchronized double getNormalizedRelevance(Entity entityA, Entity entityB){ + public double getNormalizedRelevance(Entity entityA, Entity entityB){ long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); long nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -3,10 +3,12 @@ */ package org.dllearner.algorithms.isle.metrics; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -25,6 +27,7 @@ private static final Logger logger = Logger.getLogger(RelevanceUtils.class.getName()); static int maxNrOfThreads = Math.max(1, Runtime.getRuntime().availableProcessors() - 1); + static boolean normalize = true; /** * Returns a map containing the relevance score based on the given metric between the entity and each other entity. @@ -43,8 +46,9 @@ executor.submit(new Runnable() { @Override public void run() { - double relevance = metric.getNormalizedRelevance(entity, otherEntity); - logger.info(otherEntity + ":" + relevance); +// double relevance = metric.getNormalizedRelevance(entity, otherEntity); + double relevance = metric.getRelevance(entity, otherEntity); +// logger.info(otherEntity + ":" + relevance); relevantEntities.put(otherEntity, relevance); } }); @@ -55,17 +59,21 @@ } catch (InterruptedException e) { e.printStackTrace(); } - + //normalize the values + if(normalize){ + return AbstractRelevanceMetric.normalizeMinMax(relevantEntities); + } return relevantEntities; } public static Map<Entity, Double> getRelevantEntities(Entity entity, OWLOntology ontology, RelevanceMetric metric){ - Set<OWLEntity> owlEntities = new HashSet<OWLEntity>(); + Set<OWLEntity> owlEntities = new TreeSet<OWLEntity>(); owlEntities.addAll(ontology.getClassesInSignature()); owlEntities.addAll(ontology.getDataPropertiesInSignature()); owlEntities.addAll(ontology.getObjectPropertiesInSignature()); Set<Entity> otherEntities = OWLAPIConverter.getEntities(owlEntities); +// Set<Entity> otherEntities = OWLAPIConverter.getEntities(new HashSet<OWLEntity>(new ArrayList<OWLEntity>(owlEntities).subList(0, 20))); otherEntities.remove(entity); return getRelevantEntities(entity, otherEntities, metric); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -34,6 +34,10 @@ double N = index.getTotalNumberOfDocuments(); + if(fA == 0 || fB == 0 || fAB == 0){ + return 0; + } + double pmi = Math.log(fAB / (fA*fB/N + Math.sqrt(fA)*Math.sqrt(Math.log(delta)/-2))); return pmi; Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedDescription.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedDescription.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -24,6 +24,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; +import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLAPIRenderers; import org.json.JSONException; @@ -37,12 +38,13 @@ * @author Jens Lehmann * */ -public class EvaluatedDescription implements Serializable{ +public class EvaluatedDescription implements Serializable, Comparable<EvaluatedDescription>{ /** * */ private static final long serialVersionUID = 1106431570510815033L; + private static ConceptComparator conceptComparator = new ConceptComparator(); protected Description description; protected Score score; @@ -139,4 +141,16 @@ return description.toString() + " " + dfPercent.format(getAccuracy()); } + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(EvaluatedDescription o) { + int diff = Double.compare(score.getAccuracy(), o.score.getAccuracy()); + if(diff == 0){ + conceptComparator.compare(description, o.getDescription()); + } + return diff; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -61,6 +61,12 @@ qef = new QueryExecutionFactoryPaginated(qef, 10000); } + public ConciseBoundedDescriptionGeneratorImpl(Model model, int maxRecursionDepth) { + this.maxRecursionDepth = maxRecursionDepth; + + qef = new QueryExecutionFactoryModel(model); + } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, String cacheDir) { this(endpoint, cacheDir, MAX_RECURSION_DEPTH_DEFAULT); } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -504,6 +504,43 @@ } return new SparqlEndpoint(u); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((defaultGraphURIs == null) ? 0 : defaultGraphURIs.hashCode()); + result = prime * result + ((namedGraphURIs == null) ? 0 : namedGraphURIs.hashCode()); + result = prime * result + ((url == null) ? 0 : url.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SparqlEndpoint other = (SparqlEndpoint) obj; + if (defaultGraphURIs == null) { + if (other.defaultGraphURIs != null) + return false; + } else if (!defaultGraphURIs.equals(other.defaultGraphURIs)) + return false; + if (namedGraphURIs == null) { + if (other.namedGraphURIs != null) + return false; + } else if (!namedGraphURIs.equals(other.namedGraphURIs)) + return false; + if (url == null) { + if (other.url != null) + return false; + } else if (!url.equals(other.url)) + return false; + return true; + } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -554,7 +554,9 @@ DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); DataRange dr = dsr.getDataRange(); - if(dr.isDatatype() && ((Datatype)dr).isTopDatatype()){ + if(dr.isDatatype() +// && ((Datatype)dr).isTopDatatype() + ){ if(dpPos.get(dp).containsKey(individual)){ return true; } else { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -82,6 +82,7 @@ import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -657,7 +658,7 @@ String query = String.format( "SELECT ?type WHERE {<%s> a ?type . " + "FILTER NOT EXISTS{<%s> a ?moreSpecificType ." - + "?moreSpecificType <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ ?type.}}", individual.getName(), individual.getName()); + + "?moreSpecificType <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?type.}}", individual.getName(), individual.getName()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -858,7 +859,8 @@ Set<NamedClass> siblings = new TreeSet<NamedClass>(); String query = "SELECT ?sub WHERE { <" + cls.getName() + "> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super ."; query += "?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super ."; - query += "FILTER( !SAMETERM(?sub, <" + cls.getName() + ">)) . }"; +// query += "FILTER NOT EXISTS{?sub2 <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super. ?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super.}"; + query += "FILTER( !SAMETERM(?sub, <" + cls.getName() + ">) && !SAMETERM(?super, <http://www.w3.org/2000/01/rdf-schema#Resource>)) . }"; ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -111,6 +111,8 @@ private ELDescriptionTreeComparator treeComp = new ELDescriptionTreeComparator(); private ELDescriptionEdgeComparator edgeComp = new ELDescriptionEdgeComparator(); private TreeAndRoleSetComparator mComp = new TreeAndRoleSetComparator(); + + private int maxClassExpressionDepth = 2; public ELDown3(AbstractReasonerComponent rs) { this(rs, true); @@ -180,7 +182,7 @@ refinements.addAll(refineLabel(tree, v, position)); } refinements.addAll(refineEdge(tree, v, position)); - if(v.isClassNode() && v.getLevel() < 4){ + if(v.isClassNode() && v.getLevel() <= maxClassExpressionDepth){ refinements.addAll(attachSubtree2(tree, v, position)); refinements.addAll(attachSubtreeDatatypeProperties(tree, v, position)); } @@ -655,6 +657,13 @@ } return false; } + + /** + * @param maxClassExpressionDepth the maxClassExpressionDepth to set + */ + public void setMaxClassExpressionDepth(int maxClassExpressionDepth) { + this.maxClassExpressionDepth = maxClassExpressionDepth; + } @Override public void init() throws ComponentInitException { Modified: trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -194,6 +194,7 @@ Set<Description> superClasses = sr.getSuperClasses(nc); superClasses.remove(new NamedClass(Thing.instance.getURI())); superClasses.remove(Thing.instance); + superClasses.remove(new NamedClass("http://www.w3.org/2000/01/rdf-schema#Resource")); superClasses = filterByNamespace(superClasses); logger.info("Super classes: " + superClasses); @@ -211,7 +212,7 @@ logger.info("Negative examples(" + superClassNegativeExamples.size() + "): " + superClassNegativeExamples); negativeExamples.addAll(superClassNegativeExamples); } else if(strategy == RANDOM){//get some random examples - + String query = "SELECT ?s WHERE {?s a ?type. FILTER NOT EXIST{?type rdfs:subClassOf* }}"; } } return negativeExamples; Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -9,9 +9,17 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; import java.net.URLEncoder; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; @@ -23,19 +31,27 @@ import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.prefs.Preferences; import org.apache.log4j.Logger; -import org.coode.owlapi.rdfxml.parser.DataSomeValuesFromTranslator; import org.dllearner.algorithms.celoe.CELOE; -import org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive; import org.dllearner.algorithms.elcopy.ELLearningAlgorithm; import org.dllearner.algorithms.isle.index.Index; import org.dllearner.algorithms.isle.index.RelevanceMapGenerator; import org.dllearner.algorithms.isle.index.syntactic.SolrSyntacticIndex; +import org.dllearner.algorithms.isle.metrics.ChiSquareRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.DiceRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.JaccardRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.LLRRelevanceMetric; import org.dllearner.algorithms.isle.metrics.PMIRelevanceMetric; import org.dllearner.algorithms.isle.metrics.RelevanceMetric; +import org.dllearner.algorithms.isle.metrics.SCIRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.SignificantPMIRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.TTestRelevanceMetric; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; @@ -65,6 +81,8 @@ import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.PrefixCCMap; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; +import org.ini4j.IniPreferences; +import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; @@ -78,6 +96,7 @@ import com.google.common.base.Charsets; import com.google.common.collect.Sets; +import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; import com.google.common.io.Files; @@ -108,9 +127,9 @@ private static final Logger logger = Logger.getLogger(DBpediaExperiment.class.getName()); private DecimalFormat dfPercent = new DecimalFormat("0.00%"); - HashFunction hf = Hashing.md5(); + final HashFunction hf = Hashing.md5(); - SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); String namespace = "http://dbpedia.org/ontology/"; OWLOntology schema; @@ -120,7 +139,7 @@ String cacheDirectory = "cache/isle"; String testFolder = "experiments/isle/logs/"; - private SPARQLReasoner reasoner; + private SPARQLReasoner sparqlReasoner; private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; final int maxNrOfPositiveExamples = 100; @@ -129,25 +148,33 @@ int maxCBDDepth = 1; //learning algorithm settings - private int maxNrOfResults = 50; + private int maxNrOfResults = 100; private int maxExecutionTimeInSeconds = 10; - private double noiseInPercentage = 70; + private double noiseInPercentage = 50; private boolean useNegation = false; private boolean useAllConstructor = false; - private RelevanceMetric relevanceMetric; - String experimentsFolder = "experiments/isle/"; File resultsFolder = new File(experimentsFolder + "result/"); private boolean useEL = true; private boolean forceLongDescriptions = true; + + private List<RelevanceMetric> relevanceMetrics; + + private PreparedStatement ps; public DBpediaExperiment() { - reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cacheDirectory); - negativeExampleFinder = new AutomaticNegativeExampleFinderSPARQL2(endpoint, reasoner); + try { + endpoint = new SparqlEndpoint(new URL("http://[2001:638:902:2010:0:168:35:138]/sparql"), "http://dbpedia.org"); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + sparqlReasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cacheDirectory); + negativeExampleFinder = new AutomaticNegativeExampleFinderSPARQL2(endpoint, sparqlReasoner); KnowledgebaseSampleGenerator.maxCBDDepth = maxCBDDepth; new File(experimentsFolder + "samples/").mkdirs(); KnowledgebaseSampleGenerator.cacheDir = experimentsFolder + "samples/"; @@ -155,18 +182,88 @@ loadSchema(); - relevanceMetric = new PMIRelevanceMetric(getSyntacticIndex()); + Index syntacticIndex = getSyntacticIndex(); + relevanceMetrics = new ArrayList<>(); + relevanceMetrics.add(new PMIRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new ChiSquareRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new DiceRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new JaccardRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new LLRRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new SCIRelevanceMetric(syntacticIndex)); + relevanceMetrics.add(new SignificantPMIRelevanceMetric(syntacticIndex, 0.5)); + relevanceMetrics.add(new TTestRelevanceMetric(syntacticIndex)); + resultsFolder.mkdirs(); + + initDBConnection(); } + /** + * Setup the database connection, create the table if not exists and prepare the INSERT statement. + */ + private void initDBConnection() { + try { + InputStream is = this.getClass().getClassLoader().getResourceAsStream("db_settings.ini"); + Preferences prefs = new IniPreferences(is); + String dbServer = prefs.node("database").get("server", null); + String dbName = prefs.node("database").get("name", null); + String dbUser = prefs.node("database").get("user", null); + String dbPass = prefs.node("database").get("pass", null); + + Class.forName("com.mysql.jdbc.Driver"); + String url = "jdbc:mysql://" + dbServer + "/" + dbName; + Connection conn = DriverManager.getConnection(url, dbUser, dbPass); + + java.sql.Statement st = conn.createStatement(); + String sql = "CREATE TABLE IF NOT EXISTS ISLE_Evaluation (" + + "id VARCHAR(100)," + + "class TEXT NOT NULL," + + "position TINYINT NOT NULL," + + "expression TEXT NOT NULL," + + "fscore DECIMAL(8,6) NOT NULL,"; + for (RelevanceMetric metric : relevanceMetrics) { + sql += metric.getClass().getSimpleName().replace("RelevanceMetric", "") + " DECIMAL(8,6) NOT NULL,"; + } + sql += "PRIMARY KEY(id)," + + "INDEX(class(200))) DEFAULT CHARSET=utf8"; + st.execute(sql); + + sql = "INSERT INTO ISLE_Evaluation (id, class, position, expression, fscore"; + for (RelevanceMetric metric : relevanceMetrics) { + sql += "," + metric.getClass().getSimpleName().replace("RelevanceMetric", ""); + } + sql += ") VALUES(?,?,?,?,?"; + for(int i = 0 ; i < relevanceMetrics.size(); i++){ + sql += ",?"; + } + sql += ")"; + ps = conn.prepareStatement(sql); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (InvalidFileFormatException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void run(){ Set<NamedClass> classes = getClasses(); - classes = reasoner.getMostSpecificClasses(); + classes = sparqlReasoner.getMostSpecificClasses(); List<NamedClass> classList = new ArrayList<>(classes); // Collections.reverse(classList); +// classList = classList.subList(0, 10); - for (NamedClass cls : classList) { + new SolrSyntacticIndex(schema, solrServerURL, searchField).buildIndex(classes); + + ExecutorService executor = Executors.newFixedThreadPool(6); + + for (final NamedClass cls : classList) { try { File resultsFile = new File(resultsFolder, URLEncoder.encode(cls.getName(), "UTF-8") + ".csv"); if(resultsFile.exists()){ @@ -175,12 +272,23 @@ } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } - try { - run(cls); - } catch (Exception e) { - logger.error("Error when learning class " + cls, e); - } + executor.submit(new Runnable() { + @Override + public void run() { + try { + DBpediaExperiment.this.run(cls); + } catch (Exception e) { + logger.error("Error when learning class " + cls, e); + } + } + }); } + executor.shutdown(); + try { + executor.awaitTermination(10, TimeUnit.DAYS); + } catch (InterruptedException e) { + e.printStackTrace(); + } } public void run(NamedClass cls){ @@ -198,14 +306,15 @@ SortedSet<Individual> negativeExamples = getNegativeExamples(cls, positiveExamples); //generate a sample of the knowledge base based on the examples - OWLOntology knowledgebaseSample = loadKnowledgebaseSample(Sets.union(positiveExamples, negativeExamples)); -// Map<Entity, Double> entityRelevance = RelevanceMapGenerator.generateRelevanceMap(cls, schema, relevanceMetric, true); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - + OWLOntology knowledgebaseSample = loadKnowledgebaseSample(cls, Sets.union(positiveExamples, negativeExamples)); +// try { +// Thread.sleep(2000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + + return; + /** //set up the learning try { // set KB @@ -230,22 +339,6 @@ } lp.init(); - /** - Monitor mon = MonitorFactory.getTimeMonitor("time"); - Individual ex = positiveExamples.iterator().next(); - Description r = new DatatypeSomeRestriction(new DatatypeProperty("http://dbpedia.org/ontology/Astronaut/timeInSpace"), new Datatype("http://www.w3.org/2000/01/rdf-schema#Literal")); - mon.start(); - reasoner.hasType(r, ex); -// lp.getAccuracyOrTooWeak(r, 0.3d); - mon.stop(); - System.out.println(mon.getLastValue()); - r = new ObjectSomeRestriction(new ObjectProperty("http://dbpedia.org/ontology/nationality"), new NamedClass("http://dbpedia.org/ontology/Country")); - mon.start(); - reasoner.hasType(r, ex); -// lp.getAccuracyOrTooWeak(r, 0.3d); - mon.stop(); - System.out.println(mon.getLastValue()); - **/ // 1. run basic algorithm //set up the refinement operator and the allowed OWL constructs @@ -265,6 +358,7 @@ ((ELLearningAlgorithm)la).setIgnoredConcepts(Sets.newHashSet(cls)); ((ELLearningAlgorithm)la).setClassToDescribe(cls); ((ELLearningAlgorithm)la).setTreeSearchTimeSeconds(maxExecutionTimeInSeconds); + ((ELLearningAlgorithm)la).setMaxNrOfResults(maxNrOfResults); // la = new ELLearningAlgorithmDisjunctive(lp, reasoner); } else { //build CELOE la @@ -273,6 +367,7 @@ laTmp.setOperator(rop); laTmp.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); laTmp.setStartClass(startClass); + laTmp.setNoisePercentage(noiseInPercentage); new File(testFolder).mkdirs(); laTmp.setSearchTreeFile(testFolder + "searchTree.txt"); laTmp.setWriteSearchTree(true); @@ -285,19 +380,36 @@ } la.init(); la.start(); - Map<Entity, Double> entityRelevance = RelevanceMapGenerator.generateRelevanceMap(cls, schema, relevanceMetric, true); - + //compute the relevance scores + Map<RelevanceMetric, Map<Entity, Double>> entityRelevances = RelevanceMapGenerator.generateRelevanceMaps(cls, schema, relevanceMetrics, true); + //Write to DB + try { + write2DB(reasoner, lp, cls, la.getCurrentlyBestEvaluatedDescriptions(), entityRelevances); + } catch (SQLException e1) { + e1.printStackTrace(); + } + //write to CSV file int current = 1; StringBuilder sb = new StringBuilder(); + //the header line + sb.append("class expression,fmeasure"); + for (RelevanceMetric metric : relevanceMetrics) { + sb.append(",").append(metric.getClass().getSimpleName()); + } + sb.append("\n"); + //the entries for(EvaluatedDescription ed : la.getCurrentlyBestEvaluatedDescriptions().descendingSet()) { if(lp instanceof PosNegLPStandard) { double fMeasure = ((PosNegLPStandard)lp).getFMeasureOrTooWeakExact(ed.getDescription(),1); sb.append(replaceDataPropertyRanges(ed.getDescription()).toManchesterSyntaxString(reasoner.getBaseURI(), reasoner.getPrefixes()) + "," // + ((PosNegLPStandard)lp).getPredAccuracyOrTooWeakExact(ed.getDescription(),1) + "," + fMeasure); - double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevance); - sb.append(",").append(relevanceScore); - sb.append(",").append(fMeasure + relevanceScore); + for (RelevanceMetric metric : relevanceMetrics) { + double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevances.get(metric)); + sb.append(",").append(relevanceScore); + } + +// sb.append(",").append(fMeasure + relevanceScore); sb.append("\n"); } @@ -322,6 +434,7 @@ } catch (ComponentInitException e) { e.printStackTrace(); } + */ } /** @@ -414,7 +527,7 @@ private SortedSet<Individual> getPositiveExamples(NamedClass cls){ logger.info("Generating positive examples..."); - SortedSet<Individual> individuals = reasoner.getIndividuals(cls, 1000); + SortedSet<Individual> individuals = sparqlReasoner.getIndividuals(cls, 1000); List<Individual> individualsList = new ArrayList<>(individuals); // Collections.shuffle(individualsList, new Random(1234)); individuals.clear(); @@ -440,15 +553,14 @@ logger.info("Done. Number of logical axioms: " + schema.getLogicalAxiomCount()); } - private OWLOntology loadKnowledgebaseSample(Set<Individual> individuals){ + private OWLOntology loadKnowledgebaseSample(NamedClass nc, Set<Individual> individuals){ logger.info("Generating knowledge base sample..."); Model sampleModel = KnowledgebaseSampleGenerator.createKnowledgebaseSample(endpoint, namespace, individuals); sampleModel.setNsPrefix("dbo", "http://dbpedia.org/ontology/"); logger.info("Done. Size: " + sampleModel.size() + " triples"); cleanUp(sampleModel); logger.info("Clean up. Size: " + sampleModel.size() + " triples"); -// Query query = QueryFactory.create("SELECT ?p (COUNT(distinct ?s) AS ?cnt) WHERE {?s ?p ?o. ?s a <http://dbpedia.org/ontology/Cardinal>} GROUP BY ?p ORDER BY DESC(?cnt)", Syntax.syntaxARQ); -// System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, sampleModel).execSelect())); + showPropertyDistribution(nc, sampleModel); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -462,6 +574,7 @@ man.removeAxioms(ontology, ontology.getAxioms(AxiomType.DATA_PROPERTY_RANGE)); man.removeAxioms(ontology, ontology.getAxioms(AxiomType.DISJOINT_CLASSES)); man.removeAxioms(ontology, ontology.getAxioms(AxiomType.SAME_INDIVIDUAL)); +// man.removeAxioms(ontology, ontology.getAxioms(AxiomType.OBJECT_PROPERTY_RANGE)); man.removeAxiom(ontology, df.getOWLObjectPropertyDomainAxiom( df.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/mission")), df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Aircraft")))); @@ -480,6 +593,17 @@ return null; } + private void showPropertyDistribution(NamedClass cls, Model model){ + Query query = QueryFactory.create("SELECT ?p (COUNT(distinct ?s) AS ?cnt) (COUNT(distinct ?x) AS ?negCnt) WHERE {" + + "?s ?p ?o. {?p a <http://www.w3.org/2002/07/owl#ObjectProperty>} UNION {?p a <http://www.w3.org/2002/07/owl#DatatypeProperty>}" + + "?s a <" + cls.getName() + ">. " + + "OPTIONAL{?x ?p ?o1. " + + "FILTER NOT EXISTS{?x a <" + cls.getName() + ">.}}} " + + "GROUP BY ?p ORDER BY DESC(?cnt)", Syntax.syntaxARQ); + + System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, model).execSelect())); + } + private void cleanUp(Model model){ String dbo = "http://dbpedia.org/ontology/"; Set<String> blackList = Sets.newHashSet( @@ -591,6 +715,33 @@ return classes; } + private synchronized void write2DB(FastInstanceChecker reasoner, AbstractLearningProblem lp, NamedClass cls, TreeSet<? extends EvaluatedDescription> evaluatedDescriptions, Map<RelevanceMetric, Map<Entity, Double>> entityRelevances) throws SQLException{ + int position = 1; + for(EvaluatedDescription ed : evaluatedDescriptions.descendingSet()) { + String clsName = cls.getName(); + String expression = replaceDataPropertyRanges(ed.getDescription()).toManchesterSyntaxString(reasoner.getBaseURI(), reasoner.getPrefixes()); + HashCode hc = hf.newHasher() + .putString(clsName, Charsets.UTF_8) + .putString(expression, Charsets.UTF_8) + .hash(); + String id = hc.toString(); + double fMeasure = ((PosNegLPStandard)lp).getAccuracyOrTooWeakExact(ed.getDescription(), noiseInPercentage/100d); + ps.setString(1, id); + ps.setString(2, cls.getName()); + ps.setInt(3, position++); + ps.setString(4, expression); + ps.setDouble(5, fMeasure); + int col = 6; + for (RelevanceMetric metric : relevanceMetrics) { + double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevances.get(metric)); + ps.setDouble(col++, relevanceScore); + } + + ps.addBatch(); + } + ps.executeBatch(); + } + public static void main(String[] args) throws Exception { // ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); // String cls = "http://dbpedia.org/ontology/Astronaut"; @@ -607,8 +758,11 @@ // la.setPattern(DLLearnerAxiomConvertVisitor.getDLLearnerAxiom(pattern)); // la.start(); + long start = System.currentTimeMillis(); + new DBpediaExperiment().run(); +// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); + long end = System.currentTimeMillis(); + logger.info("Operation took " + (end - start) + "ms"); - new DBpediaExperiment().run(); -// new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Astronaut")); } } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -136,7 +136,7 @@ Model cbd; for (Individual individual : individuals) { try { - Thread.sleep(500); + Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java 2014-02-13 11:47:52 UTC (rev 4223) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java 2014-02-16 15:59:43 UTC (rev 4224) @@ -62,7 +62,7 @@ relevance = metric.getRelevance(entity1, entity2); System.out.println(relevance); - // dbo:Person and dbo:Animal + // dbo:Person and dbo:birthPlace entity1 = new NamedClass(DBPEDIA_NS + "Person"); entity2 = new ObjectProperty(DBPEDIA_NS + "birthPlace"); relevance = metric.getRelevance(entity1, entity2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2014-02-13 11:47:58
|
Revision: 4223 http://sourceforge.net/p/dl-learner/code/4223 Author: andremelo Date: 2014-02-13 11:47:52 +0000 (Thu, 13 Feb 2014) Log Message: ----------- Preventing NaN values for the relevance measures Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java 2014-02-12 13:58:05 UTC (rev 4222) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) @@ -18,16 +18,20 @@ } private double chiSquareIteration(double fXY, double e_fXY) { - return Math.pow(fXY - e_fXY,2)/e_fXY; + return Math.pow(fXY - e_fXY, 2)/e_fXY; } @Override public synchronized double getRelevance(Entity entityA, Entity entityB){ double fA = index.getNumberOfDocumentsFor(entityA); double fB = index.getNumberOfDocumentsFor(entityB); - double fAB = index.getNumberOfDocumentsFor(entityA, entityB); double N = index.getTotalNumberOfDocuments(); + if (N==0 || fA==0 || fB==0) + return 0; + + double fAB = index.getNumberOfDocumentsFor(entityA, entityB); + double e_fAB = fA*fB/N; // Expected frequency of A and B assuming independence double chi2 = 0; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java 2014-02-12 13:58:05 UTC (rev 4222) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) @@ -17,6 +17,10 @@ public double getRelevance(Entity entityA, Entity entityB) { double nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); double nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + + if (nrOfDocumentsA==0 || nrOfDocumentsB==0) + return 0; + double nrOfDocumentsAandB = index.getNumberOfDocumentsFor(entityA, entityB); double dice = 2 * nrOfDocumentsAandB / (nrOfDocumentsA + nrOfDocumentsB); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java 2014-02-12 13:58:05 UTC (rev 4222) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) @@ -17,12 +17,13 @@ public double getRelevance(Entity entityA, Entity entityB) { long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + + if (nrOfDocumentsA==0 || nrOfDocumentsB==0) + return 0; + double nrOfDocumentsAandB = index.getNumberOfDocumentsFor(entityA, entityB); double nrOfDocumentsAorB = nrOfDocumentsA + nrOfDocumentsB - nrOfDocumentsAandB; - if (nrOfDocumentsAorB==0) - return 1.0; - double jaccard = nrOfDocumentsAandB / nrOfDocumentsAorB; return jaccard; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java 2014-02-12 13:58:05 UTC (rev 4222) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) @@ -18,6 +18,8 @@ } private double llrIteration(double pXY, double pX, double pY) { + if (pXY==0 || pX==0 || pY==0) + return 0; return pXY * Math.log(pXY/(pX*pY)); } @@ -25,9 +27,14 @@ public synchronized double getRelevance(Entity entityA, Entity entityB){ double fA = index.getNumberOfDocumentsFor(entityA); double fB = index.getNumberOfDocumentsFor(entityB); + double N = index.getTotalNumberOfDocuments(); double fAB = index.getNumberOfDocumentsFor(entityA, entityB); - double N = index.getTotalNumberOfDocuments(); + if (N==0 || fA==0 || fB==0) + return 0; + + + double pA = fA/N; double pB = fB/N; double pAB = fAB/N; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java 2014-02-12 13:58:05 UTC (rev 4222) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) @@ -18,16 +18,19 @@ @Override public synchronized double getRelevance(Entity entityA, Entity entityB){ - long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); - long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); - long nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); + double fA = index.getNumberOfDocumentsFor(entityA); + double fB = index.getNumberOfDocumentsFor(entityB); + double fAB = index.getNumberOfDocumentsFor(entityA, entityB); + double N = index.getTotalNumberOfDocuments(); - long nrOfDocuments = index.getTotalNumberOfDocuments(); + if (fA==0 || fB==0 || fAB==0) + return 0; - double pA = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsA / (double) nrOfDocuments); - double pB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsB / (double) nrOfDocuments); - double pAB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsAB / (double) nrOfDocuments); + double pA = fA / N; + double pB = fB / N; + double pAB = fAB / N; + double sci = pAB / (pA * Math.sqrt(pB)); return sci; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java 2014-02-12 13:58:05 UTC (rev 4222) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java 2014-02-13 11:47:52 UTC (rev 4223) @@ -23,7 +23,10 @@ double nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); double nrOfDocuments = index.getTotalNumberOfDocuments(); - + + if (nrOfDocumentsA==0 || nrOfDocumentsB==0 || nrOfDocumentsAB==0) + return 0; + double ttest = (nrOfDocumentsAB - (nrOfDocumentsA*nrOfDocumentsB)/nrOfDocuments) / Math.sqrt(nrOfDocumentsAB*(1-nrOfDocumentsAB/nrOfDocuments)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-12 13:58:08
|
Revision: 4222 http://sourceforge.net/p/dl-learner/code/4222 Author: lorenz_b Date: 2014-02-12 13:58:05 +0000 (Wed, 12 Feb 2014) Log Message: ----------- Added method to get non empty classes. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-11 16:48:02 UTC (rev 4221) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-12 13:58:05 UTC (rev 4222) @@ -791,6 +791,18 @@ return types; } + public Set<NamedClass> getNonEmptyOWLClasses() { + Set<NamedClass> types = new HashSet<NamedClass>(); + String query = String.format("SELECT DISTINCT ?class WHERE {?class a <%s>. FILTER EXISTS{?a a ?class}}",OWL.Class.getURI()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + types.add(new NamedClass(qs.getResource("class").getURI())); + } + return types; + } + public SortedSet<NamedClass> getOWLClasses(String namespace) { SortedSet<NamedClass> types = new TreeSet<NamedClass>(); String query = "SELECT DISTINCT ?class WHERE {?class a <" + OWL.Class.getURI() + ">."; @@ -851,7 +863,9 @@ QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); - siblings.add(new NamedClass(qs.getResource("sub").getURI())); + if(qs.get("sub").isURIResource()){ + siblings.add(new NamedClass(qs.getResource("sub").getURI())); + } } return siblings; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2014-02-11 16:48:05
|
Revision: 4221 http://sourceforge.net/p/dl-learner/code/4221 Author: andremelo Date: 2014-02-11 16:48:02 +0000 (Tue, 11 Feb 2014) Log Message: ----------- Adding relevance measures from http://www.cse.iitb.ac.in/~damani/papers/conll13.pdf Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/ChiSquareRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,52 @@ +/** + * + */ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * Chi Squared + * @author Andre Melo + * + */ +public class ChiSquareRelevanceMetric extends AbstractRelevanceMetric { + + public ChiSquareRelevanceMetric(Index index) { + super(index); + } + + private double chiSquareIteration(double fXY, double e_fXY) { + return Math.pow(fXY - e_fXY,2)/e_fXY; + } + + @Override + public synchronized double getRelevance(Entity entityA, Entity entityB){ + double fA = index.getNumberOfDocumentsFor(entityA); + double fB = index.getNumberOfDocumentsFor(entityB); + double fAB = index.getNumberOfDocumentsFor(entityA, entityB); + double N = index.getTotalNumberOfDocuments(); + + double e_fAB = fA*fB/N; // Expected frequency of A and B assuming independence + + double chi2 = 0; + + // X=A and Y=B + chi2 += chiSquareIteration(fAB, e_fAB); + // X=A and Y=not B + chi2 += chiSquareIteration(fA-fAB, fA-e_fAB); + // X=not A and Y=B + chi2 += chiSquareIteration(fB-fAB, fB-e_fAB); + // X=not A and Y=not B + chi2 += chiSquareIteration(N-fA-fB+fAB, N-fA-fB+e_fAB); + + return chi2; + } + + @Override + public synchronized double getNormalizedRelevance(Entity entityA, Entity entityB){ + return Double.NaN; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/DiceRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,33 @@ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * @author Andre Melo + * + */ +public class DiceRelevanceMetric extends AbstractRelevanceMetric{ + + public DiceRelevanceMetric(Index index) { + super(index); + } + + @Override + public double getRelevance(Entity entityA, Entity entityB) { + double nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); + double nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + double nrOfDocumentsAandB = index.getNumberOfDocumentsFor(entityA, entityB); + + double dice = 2 * nrOfDocumentsAandB / (nrOfDocumentsA + nrOfDocumentsB); + + return dice; + } + + @Override + public double getNormalizedRelevance(Entity entity1, Entity entity2) { + return getRelevance(entity1, entity2); + } + + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/JaccardRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,37 @@ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * @author Andre Melo + * + */ +public class JaccardRelevanceMetric extends AbstractRelevanceMetric{ + + public JaccardRelevanceMetric(Index index) { + super(index); + } + + @Override + public double getRelevance(Entity entityA, Entity entityB) { + long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); + long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + double nrOfDocumentsAandB = index.getNumberOfDocumentsFor(entityA, entityB); + double nrOfDocumentsAorB = nrOfDocumentsA + nrOfDocumentsB - nrOfDocumentsAandB; + + if (nrOfDocumentsAorB==0) + return 1.0; + + double jaccard = nrOfDocumentsAandB / nrOfDocumentsAorB; + + return jaccard; + } + + @Override + public double getNormalizedRelevance(Entity entity1, Entity entity2) { + return getRelevance(entity1, entity2); + } + + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/LLRRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,54 @@ +/** + * + */ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * Log Likelihood Ratio + * @author Andre Melo + * + */ +public class LLRRelevanceMetric extends AbstractRelevanceMetric { + + public LLRRelevanceMetric(Index index) { + super(index); + } + + private double llrIteration(double pXY, double pX, double pY) { + return pXY * Math.log(pXY/(pX*pY)); + } + + @Override + public synchronized double getRelevance(Entity entityA, Entity entityB){ + double fA = index.getNumberOfDocumentsFor(entityA); + double fB = index.getNumberOfDocumentsFor(entityB); + double fAB = index.getNumberOfDocumentsFor(entityA, entityB); + double N = index.getTotalNumberOfDocuments(); + + double pA = fA/N; + double pB = fB/N; + double pAB = fAB/N; + + double llr = 0; + + // X=A and Y=B + llr += llrIteration( pAB, pA, pB ); + // X=A and Y=not B + llr += llrIteration( pA-pAB, pA, 1-pB ); + // X=not A and Y=B + llr += llrIteration( pB-pAB, 1-pA, pB ); + // X=not A and Y=not B + llr += llrIteration( 1-pA-pB+pAB,1-pA, 1-pB ); + + return llr; + } + + @Override + public synchronized double getNormalizedRelevance(Entity entityA, Entity entityB){ + return Double.NaN; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SCIRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,42 @@ +/** + * + */ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * @author Andre Melo + * + */ +public class SCIRelevanceMetric extends AbstractRelevanceMetric { + + public SCIRelevanceMetric(Index index) { + super(index); + } + + @Override + public synchronized double getRelevance(Entity entityA, Entity entityB){ + long nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); + long nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + long nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); + + long nrOfDocuments = index.getTotalNumberOfDocuments(); + + double pA = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsA / (double) nrOfDocuments); + double pB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsB / (double) nrOfDocuments); + double pAB = nrOfDocuments == 0 ? 0 : ((double) nrOfDocumentsAB / (double) nrOfDocuments); + + double sci = pAB / (pA * Math.sqrt(pB)); + + return sci; + } + + @Override + public synchronized double getNormalizedRelevance(Entity entityA, Entity entityB){ + //TODO + return Double.NaN; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/SignificantPMIRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,48 @@ +/** + * + */ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * @author Lorenz Buehmann + * + */ +public class SignificantPMIRelevanceMetric extends AbstractRelevanceMetric { + + protected final double delta; + + /** + * + * @param index: semantic index + * @param delta: parameter varying from 0 to 1 + */ + public SignificantPMIRelevanceMetric(Index index, double delta) { + super(index); + if (delta<0 ||delta>1) + throw new IllegalArgumentException("Delta parameter should be in [0,1]"); + this.delta = delta; + } + + @Override + public synchronized double getRelevance(Entity entityA, Entity entityB){ + double fA = index.getNumberOfDocumentsFor(entityA); + double fB = index.getNumberOfDocumentsFor(entityB); + double fAB = index.getNumberOfDocumentsFor(entityA, entityB); + + double N = index.getTotalNumberOfDocuments(); + + double pmi = Math.log(fAB / (fA*fB/N + Math.sqrt(fA)*Math.sqrt(Math.log(delta)/-2))); + + return pmi; + } + + @Override + public synchronized double getNormalizedRelevance(Entity entityA, Entity entityB){ + //TODO + return Double.NaN; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/TTestRelevanceMetric.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,39 @@ +/** + * + */ +package org.dllearner.algorithms.isle.metrics; + +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Entity; + +/** + * @author Andre Melo + * + */ +public class TTestRelevanceMetric extends AbstractRelevanceMetric { + + public TTestRelevanceMetric(Index index) { + super(index); + } + + @Override + public synchronized double getRelevance(Entity entityA, Entity entityB){ + double nrOfDocumentsA = index.getNumberOfDocumentsFor(entityA); + double nrOfDocumentsB = index.getNumberOfDocumentsFor(entityB); + double nrOfDocumentsAB = index.getNumberOfDocumentsFor(entityA, entityB); + + double nrOfDocuments = index.getTotalNumberOfDocuments(); + + double ttest = (nrOfDocumentsAB - (nrOfDocumentsA*nrOfDocumentsB)/nrOfDocuments) / + Math.sqrt(nrOfDocumentsAB*(1-nrOfDocumentsAB/nrOfDocuments)); + + return ttest; + } + + @Override + public synchronized double getNormalizedRelevance(Entity entityA, Entity entityB){ + //TODO + return Double.NaN; + } + +} Added: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java 2014-02-11 16:48:02 UTC (rev 4221) @@ -0,0 +1,140 @@ +/** + * + */ +package org.dllearner.algorithms.isle.metrics; + +import static org.junit.Assert.fail; + +import java.io.BufferedInputStream; +import java.io.InputStream; +import java.net.URL; + +import org.apache.commons.compress.compressors.CompressorInputStream; +import org.apache.commons.compress.compressors.CompressorStreamFactory; +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.algorithms.isle.index.syntactic.SolrSyntacticIndex; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.junit.Test; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLOntology; + +/** + * @author Lorenz Buehmann + * + */ +public class RelevanceMetricsTest { + + AbstractRelevanceMetric metric; + Index index; + static final String solrServerURL = "http://solr.aksw.org/en_dbpedia_resources/"; + static final String searchField = "comment"; + static final String DBPEDIA_NS = "http://dbpedia.org/ontology/"; + + /** + * + */ + public RelevanceMetricsTest() { + OWLOntology ontology = null; + try { + URL url = new URL("http://downloads.dbpedia.org/3.9/dbpedia_3.9.owl.bz2"); + InputStream is = new BufferedInputStream(url.openStream()); + CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(in); + } catch (Exception e){ + e.printStackTrace(); + } + index = new SolrSyntacticIndex(ontology, solrServerURL, searchField); + + } + + private void computeRelevanceScores(AbstractRelevanceMetric metric) { + //dbo:Person and dbo:Film + Entity entity1 = new NamedClass(DBPEDIA_NS + "Person"); + Entity entity2 = new NamedClass(DBPEDIA_NS + "Film"); + double relevance = metric.getRelevance(entity1, entity2); + System.out.println(relevance); + + //dbo:Person and dbo:Animal + entity1 = new NamedClass(DBPEDIA_NS + "Person"); + entity2 = new NamedClass(DBPEDIA_NS + "Animal"); + relevance = metric.getRelevance(entity1, entity2); + System.out.println(relevance); + + // dbo:Person and dbo:Animal + entity1 = new NamedClass(DBPEDIA_NS + "Person"); + entity2 = new ObjectProperty(DBPEDIA_NS + "birthPlace"); + relevance = metric.getRelevance(entity1, entity2); + System.out.println(relevance); + } + + /** + * Test method for {@link org.dllearner.algorithms.isle.metrics.PMIRelevanceMetric#getRelevance(org.dllearner.core.owl.Entity, org.dllearner.core.owl.Entity)}. + */ + @Test + public void testGetRelevanceJaccard() { + System.out.println("JACCARD: "); + metric = new JaccardRelevanceMetric(index); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevancePMI() { + System.out.println("PMI: "); + metric = new PMIRelevanceMetric(index); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevanceSignificantPMI() { + System.out.println("SignificantPMI: "); + double delta = 0.5; + metric = new SignificantPMIRelevanceMetric(index,delta); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevanceDice() { + System.out.println("DICE: "); + metric = new DiceRelevanceMetric(index); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevanceSCI() { + System.out.println("SCI: "); + metric = new SCIRelevanceMetric(index); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevanceTTest() { + System.out.println("T-TEST: "); + metric = new TTestRelevanceMetric(index); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevanceChiSquared() { + System.out.println("CHI^2: "); + metric = new ChiSquareRelevanceMetric(index); + computeRelevanceScores(metric); + } + + @Test + public void testGetRelevanceLLR() { + System.out.println("LLR: "); + metric = new LLRRelevanceMetric(index); + computeRelevanceScores(metric); + } + + /** + * Test method for {@link org.dllearner.algorithms.isle.metrics.PMIRelevanceMetric#getNormalizedRelevance(org.dllearner.core.owl.Entity, org.dllearner.core.owl.Entity)}. + */ + @Test + public void testGetNormalizedRelevance() { + fail("Not yet implemented"); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-08 12:46:51
|
Revision: 4220 http://sourceforge.net/p/dl-learner/code/4220 Author: lorenz_b Date: 2014-02-08 12:46:48 +0000 (Sat, 08 Feb 2014) Log Message: ----------- Added method to get properties used by instances of given class. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-03 14:41:54 UTC (rev 4219) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-08 12:46:48 UTC (rev 4220) @@ -150,6 +150,10 @@ } } + public SPARQLReasoner(SparqlEndpoint endpoint, String cacheDirectory) { + this(new SparqlEndpointKS(endpoint), cacheDirectory); + } + public SPARQLReasoner(SparqlEndpointKS ks, CacheCoreEx cacheBackend) { this(ks, new CacheExImpl(cacheBackend)); } @@ -1301,6 +1305,34 @@ return null; } + public Set<ObjectProperty> getObjectPropertiesWithDomain(NamedClass domain) { + Set<ObjectProperty> properties = new TreeSet<>(); + + String query = "SELECT ?p WHERE {?p <http://www.w3.org/2000/01/rdf-schema#domain> <" + domain + ">.}"; + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + properties.add(new ObjectProperty(qs.getResource("p").getURI())); + } + + return properties; + } + + public Set<ObjectProperty> getObjectProperties(NamedClass cls) { + Set<ObjectProperty> properties = new TreeSet<>(); + + String query = "SELECT DISTINCT ?p WHERE {?s a <" + cls + ">. ?s ?p ?o}"; + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + properties.add(new ObjectProperty(qs.getResource("p").getURI())); + } + + return properties; + } + public SortedSet<NamedClass> getDomains(ObjectProperty objectProperty) { String query = String.format("SELECT ?domain WHERE {" + "<%s> <%s> ?domain. FILTER(isIRI(?domain))" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-03 14:41:57
|
Revision: 4219 http://sourceforge.net/p/dl-learner/code/4219 Author: lorenz_b Date: 2014-02-03 14:41:54 +0000 (Mon, 03 Feb 2014) Log Message: ----------- Added method to get transitive closure of sublcasses via SPARQL 1.1 Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-03 14:37:33 UTC (rev 4218) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-03 14:41:54 UTC (rev 4219) @@ -1587,15 +1587,16 @@ } public SortedSet<Description> getSubClasses(Description description, boolean direct) { - SortedSet<Description> subClasses = new TreeSet<Description>(); + SortedSet<Description> subClasses = new TreeSet<Description>(conceptComparator); String query; if(direct){ query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", - RDFS.subClassOf.getURI(), - ((NamedClass)description).getURI().toString()); + RDFS.subClassOf.getURI(), ((description instanceof Thing) ? Thing.uri.toString() : ((NamedClass)description).getURI().toString()) + ); } else { query = String.format("SELECT ?sub {?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <%s>. }", - ((NamedClass)description).getURI().toString()); + ((description instanceof Thing) ? Thing.uri.toString() : ((NamedClass)description).getURI().toString()) + ); } ResultSet rs = executeSelectQuery(query); QuerySolution qs; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-03 14:37:37
|
Revision: 4218 http://sourceforge.net/p/dl-learner/code/4218 Author: lorenz_b Date: 2014-02-03 14:37:33 +0000 (Mon, 03 Feb 2014) Log Message: ----------- Added method to get transitive closure of sublcasses via SPARQL 1.1 Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-03 14:04:40 UTC (rev 4217) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-03 14:37:33 UTC (rev 4218) @@ -1583,7 +1583,7 @@ @Override public SortedSet<Description> getSubClasses(Description description) { - return getSubClasses(description, false); + return getSubClasses(description, true); } public SortedSet<Description> getSubClasses(Description description, boolean direct) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-02-03 14:04:44
|
Revision: 4217 http://sourceforge.net/p/dl-learner/code/4217 Author: lorenz_b Date: 2014-02-03 14:04:40 +0000 (Mon, 03 Feb 2014) Log Message: ----------- Added method to get transitive closure of sublcasses via SPARQL 1.1 Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.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/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -229,6 +229,7 @@ } else { node.setCoveredNegatives(negCovers); } + node.setScore(accuracy); // link to parent (unless start node) if(parentNode == null) { startNode = node; @@ -316,6 +317,17 @@ if(occursOnFirstLevel(description, classToDescribe)) { return false; } + + //non of the equivalent classes must occur on the first level + TreeSet<Description> toTest = new TreeSet<Description>(descriptionComparator); + toTest.add(classToDescribe); + while(!toTest.isEmpty()) { + Description d = toTest.pollFirst(); + if(occursOnFirstLevel(description, d)) { + return false; + } + toTest.addAll(reasoner.getEquivalentClasses(d)); + } } else { // none of the superclasses of the class to learn must appear on the // outermost property level Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -38,6 +38,7 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; import org.dllearner.learningproblems.PosNegLP; @@ -94,12 +95,13 @@ private boolean isRunning = false; private boolean stop = false; - private Description startClass; private SearchTreeNode startNode; private ELHeuristic heuristic; private TreeSet<SearchTreeNode> candidates; // all trees (for fast redundancy check) private TreeSet<ELDescriptionTree> trees; + private NamedClass classToDescribe; + private double noise; @ConfigOption(name = "treeSearchTimeSeconds", defaultValue = "1.0", description="Specifies how long the algorithm should search for a partial solution (a tree).") private double treeSearchTimeSeconds = 1.0; @@ -107,6 +109,16 @@ @ConfigOption(name = "tryFullCoverage", defaultValue = "false", description="If yes, then the algorithm tries to cover all positive examples. Note that while this improves accuracy on the testing set, it may lead to overfitting.") private boolean tryFullCoverage = false; + @ConfigOption(name = "stopOnFirstDefinition", defaultValue="false", description="algorithm will terminate immediately when a correct definition is found") + private boolean stopOnFirstDefinition = false; + + @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") + private double noisePercentage = 0.0; + + // the class with which we start the refinement process + @ConfigOption(name = "startClass", defaultValue="owl:Thing", description="You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.") + private Description startClass; + // private double noise = 0; private List<ELDescriptionTree> currentSolution = new LinkedList<ELDescriptionTree>(); private EvaluatedDescription bestEvaluatedDescription; @@ -170,6 +182,8 @@ prefixes = reasoner.getPrefixes(); minimizer = new DescriptionMinimizer(reasoner); + + noise = noisePercentage/100d; } @Override @@ -483,5 +497,25 @@ public void setTryFullCoverage(boolean tryFullCoverage) { this.tryFullCoverage = tryFullCoverage; } - + + /** + * @return the noisePercentage + */ + public double getNoisePercentage() { + return noisePercentage; + } + + /** + * @param noisePercentage the noisePercentage to set + */ + public void setNoisePercentage(double noisePercentage) { + this.noisePercentage = noisePercentage; + } + + /** + * @param classToDescribe the classToDescribe to set + */ + public void setClassToDescribe(NamedClass classToDescribe) { + this.classToDescribe = classToDescribe; + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -36,8 +36,8 @@ @Override public int compare(SearchTreeNode o1, SearchTreeNode o2) { - double diff = o2.getCoveredNegatives() - o1.getCoveredNegatives(); - + double diff = o2.getScore() - o1.getScore(); +// diff = -diff; if(diff>0) { return 1; } else if(diff<0) { Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -54,6 +54,8 @@ import org.dllearner.utilities.owl.OWLVocabulary; import org.dllearner.utilities.owl.RoleComparator; +import com.google.common.collect.Sets; + /** * Abstract component representing a reasoner. Only a few reasoning operations * are guaranteed to be implemented by the underlying reasoner, while a @@ -926,8 +928,12 @@ protected SortedSet<Description> getSubClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); - } + } + public final SortedSet<Description> getEquivalentClasses(Description concept) { + return new TreeSet<>(Sets.intersection(getClassHierarchy().getSubClasses(concept), getClassHierarchy().getSuperClasses(concept))); + } + @Override public final SortedSet<ObjectProperty> getSuperProperties(ObjectProperty role) { return getObjectPropertyHierarchy().getMoreGeneralRoles(role); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -912,7 +912,7 @@ @Override protected SortedSet<Description> getSubClassesImpl(Description concept) throws ReasoningMethodUnsupportedException { return rc.getSubClassesImpl(concept); - } + } @Override protected SortedSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) throws ReasoningMethodUnsupportedException { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -565,6 +565,15 @@ return getFirstClasses(classes); } + + protected SortedSet<Description> getEquivalentClassesImpl(Description concept) { + SortedSet<Description> equivalentclasses = new TreeSet<>(conceptComparator); + OWLClass cls = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept).asOWLClass(); + for (OWLClass eqCls : reasoner.getEquivalentClasses(cls).getEntitiesMinus(cls)) { + equivalentclasses.add(new NamedClass(eqCls.toStringID())); + } + return equivalentclasses; + } @Override protected TreeSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -647,6 +647,23 @@ } return types; } + + public Set<NamedClass> getMostSpecificTypes(Individual individual) { + Set<NamedClass> types = new HashSet<NamedClass>(); + String query = String.format( + "SELECT ?type WHERE {<%s> a ?type . " + + "FILTER NOT EXISTS{<%s> a ?moreSpecificType ." + + "?moreSpecificType <http://www.w3.org/2000/01/rdf-schema#subClassOf>+ ?type.}}", individual.getName(), individual.getName()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + types.add(new NamedClass(qs.getResource("type").getURI())); + } + return types; + } + + public Set<NamedClass> getTypes() { return getTypes((String)null); @@ -1569,23 +1586,16 @@ return getSubClasses(description, false); } - public SortedSet<Description> getSubClasses(Description description, boolean useVirtuoso) { - if(!(description instanceof NamedClass || description instanceof Thing)){ - throw new IllegalArgumentException("Only named classes are supported."); - } - if(description instanceof Thing){ - description = new NamedClass(Thing.instance.getURI()); - } + public SortedSet<Description> getSubClasses(Description description, boolean direct) { SortedSet<Description> subClasses = new TreeSet<Description>(); String query; - if(useVirtuoso){ - query = getAllSubClassesVirtuosoQuery(description); - } else { + if(direct){ query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", RDFS.subClassOf.getURI(), - ((NamedClass)description).getURI().toString() - - ); + ((NamedClass)description).getURI().toString()); + } else { + query = String.format("SELECT ?sub {?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <%s>. }", + ((NamedClass)description).getURI().toString()); } ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -1597,15 +1607,6 @@ return subClasses; } - private String getAllSubClassesVirtuosoQuery(Description description){ - String query = String.format( - "SELECT DISTINCT ?sub WHERE {"+ - "{SELECT ?sub ?o where {?sub rdfs:subClassOf ?o.}}"+ - "OPTION ( TRANSITIVE, t_distinct, t_in(?sub), t_out(?o), t_min (1), t_max (8), t_step ('step_no') as ?dist ) ."+ - "FILTER(?o = <%s>)}", description.toString()); - return query; - } - @Override public ObjectPropertyHierarchy getObjectPropertyHierarchy() { // TODO Auto-generated method stub Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -180,7 +180,7 @@ refinements.addAll(refineLabel(tree, v, position)); } refinements.addAll(refineEdge(tree, v, position)); - if(v.isClassNode() && v.getLevel() < 2){ + if(v.isClassNode() && v.getLevel() < 4){ refinements.addAll(attachSubtree2(tree, v, position)); refinements.addAll(attachSubtreeDatatypeProperties(tree, v, position)); } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -27,7 +27,9 @@ import java.util.concurrent.Executors; import org.apache.log4j.Logger; +import org.coode.owlapi.rdfxml.parser.DataSomeValuesFromTranslator; import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive; import org.dllearner.algorithms.elcopy.ELLearningAlgorithm; import org.dllearner.algorithms.isle.index.Index; import org.dllearner.algorithms.isle.index.RelevanceMapGenerator; @@ -40,6 +42,9 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.owl.DataRange; +import org.dllearner.core.owl.Datatype; +import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; @@ -65,9 +70,11 @@ import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.util.OWLEntityRemover; import com.google.common.base.Charsets; import com.google.common.collect.Sets; @@ -75,8 +82,11 @@ import com.google.common.hash.Hashing; import com.google.common.io.Files; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Property; @@ -94,12 +104,13 @@ */ public class DBpediaExperiment { + private static final Logger logger = Logger.getLogger(DBpediaExperiment.class.getName()); private DecimalFormat dfPercent = new DecimalFormat("0.00%"); HashFunction hf = Hashing.md5(); - SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpediaLOD2Cloud(); + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); String namespace = "http://dbpedia.org/ontology/"; OWLOntology schema; @@ -112,14 +123,15 @@ private SPARQLReasoner reasoner; private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; - final int maxNrOfPositiveExamples = 20; - final int maxNrOfNegativeExamples = 50; + final int maxNrOfPositiveExamples = 100; + final int maxNrOfNegativeExamples = 200; boolean posOnly = false; int maxCBDDepth = 1; //learning algorithm settings private int maxNrOfResults = 50; private int maxExecutionTimeInSeconds = 10; + private double noiseInPercentage = 70; private boolean useNegation = false; private boolean useAllConstructor = false; @@ -149,11 +161,10 @@ } public void run(){ - ExecutorService es = Executors.newFixedThreadPool(6); - Set<NamedClass> classes = getClasses(); + Set<NamedClass> classes = getClasses(); classes = reasoner.getMostSpecificClasses(); List<NamedClass> classList = new ArrayList<>(classes); - Collections.reverse(classList); +// Collections.reverse(classList); for (NamedClass cls : classList) { try { @@ -189,7 +200,12 @@ //generate a sample of the knowledge base based on the examples OWLOntology knowledgebaseSample = loadKnowledgebaseSample(Sets.union(positiveExamples, negativeExamples)); // Map<Entity, Double> entityRelevance = RelevanceMapGenerator.generateRelevanceMap(cls, schema, relevanceMetric, true); - + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + //set up the learning try { // set KB @@ -230,6 +246,7 @@ mon.stop(); System.out.println(mon.getLastValue()); **/ + // 1. run basic algorithm //set up the refinement operator and the allowed OWL constructs RhoDRDown rop = new RhoDRDown(); @@ -243,7 +260,7 @@ AbstractCELA la; if(useEL){ la = new ELLearningAlgorithm(lp, reasoner); - ((ELLearningAlgorithm)la).setNoisePercentage(30); + ((ELLearningAlgorithm)la).setNoisePercentage(noiseInPercentage); ((ELLearningAlgorithm)la).setStartClass(startClass); ((ELLearningAlgorithm)la).setIgnoredConcepts(Sets.newHashSet(cls)); ((ELLearningAlgorithm)la).setClassToDescribe(cls); @@ -275,7 +292,7 @@ for(EvaluatedDescription ed : la.getCurrentlyBestEvaluatedDescriptions().descendingSet()) { if(lp instanceof PosNegLPStandard) { double fMeasure = ((PosNegLPStandard)lp).getFMeasureOrTooWeakExact(ed.getDescription(),1); - sb.append(ed.getDescription().toManchesterSyntaxString(reasoner.getBaseURI(), reasoner.getPrefixes()) + "," + sb.append(replaceDataPropertyRanges(ed.getDescription()).toManchesterSyntaxString(reasoner.getBaseURI(), reasoner.getPrefixes()) + "," // + ((PosNegLPStandard)lp).getPredAccuracyOrTooWeakExact(ed.getDescription(),1) + "," + fMeasure); double relevanceScore = getRelevanceScore(ed.getDescription(), entityRelevance); @@ -430,10 +447,8 @@ logger.info("Done. Size: " + sampleModel.size() + " triples"); cleanUp(sampleModel); logger.info("Clean up. Size: " + sampleModel.size() + " triples"); -// String query = "SELECT distinct ?s WHERE {?s a <http://dbpedia.org/ontology/Astronaut>. ?s <http://dbpedia.org/ontology/mission> ?o.}"; +// Query query = QueryFactory.create("SELECT ?p (COUNT(distinct ?s) AS ?cnt) WHERE {?s ?p ?o. ?s a <http://dbpedia.org/ontology/Cardinal>} GROUP BY ?p ORDER BY DESC(?cnt)", Syntax.syntaxARQ); // System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, sampleModel).execSelect())); -// query = "SELECT distinct ?s WHERE {?s a <http://dbpedia.org/ontology/Astronaut>. ?s <http://dbpedia.org/ontology/timeInSpace> ?o. }"; -// System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query, sampleModel).execSelect())); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -445,10 +460,19 @@ man.removeAxioms(ontology, ontology.getAxioms(AxiomType.FUNCTIONAL_DATA_PROPERTY)); man.removeAxioms(ontology, ontology.getAxioms(AxiomType.FUNCTIONAL_OBJECT_PROPERTY)); man.removeAxioms(ontology, ontology.getAxioms(AxiomType.DATA_PROPERTY_RANGE)); + man.removeAxioms(ontology, ontology.getAxioms(AxiomType.DISJOINT_CLASSES)); man.removeAxioms(ontology, ontology.getAxioms(AxiomType.SAME_INDIVIDUAL)); man.removeAxiom(ontology, df.getOWLObjectPropertyDomainAxiom( df.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/mission")), df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Aircraft")))); + OWLEntityRemover remover = new OWLEntityRemover(man, Sets.newHashSet(ontology)); + for (OWLClass cls : ontology.getClassesInSignature()) { + if(!cls.toStringID().startsWith("http://dbpedia.org/ontology/")){ + cls.accept(remover); + } + } + man.applyChanges(remover.getChanges()); + return ontology; } catch (Exception e) { e.printStackTrace(); @@ -462,7 +486,7 @@ dbo + "wikiPageDisambiguates", dbo + "wikiPageExternalLink", dbo + "wikiPageID", dbo + "wikiPageInterLanguageLink", dbo + "wikiPageRedirects", dbo + "wikiPageRevisionID", - dbo + "wikiPageWikiLink", dbo + "thumbnail", dbo + "abstract");System.out.println(blackList); + dbo + "wikiPageWikiLink", dbo + "thumbnail", dbo + "abstract"); // filter out triples with String literals, as therein often occur // some syntax errors and they are not relevant for learning List<Statement> statementsToRemove = new ArrayList<Statement>(); @@ -528,6 +552,23 @@ // } } + private Description replaceDataPropertyRanges(Description d){ + Description description = d.clone(); + List<Description> children = description.getChildren(); + for(int i=0; i < children.size(); i++) { + Description child = children.get(i); + if(child instanceof DatatypeSomeRestriction){ + Set<OWLDataPropertyRangeAxiom> rangeAxioms = schema.getDataPropertyRangeAxioms(schema.getOWLOntologyManager().getOWLDataFactory().getOWLDataProperty(IRI.create(((DatatypeSomeRestriction) child).getRole().getName()))); + if(!rangeAxioms.isEmpty()){ + DataRange range = new Datatype(rangeAxioms.iterator().next().getRange().asOWLDatatype().toStringID()); + description.replaceChild(i, new DatatypeSomeRestriction(((DatatypeSomeRestriction) child).getRole(), range)); + } + + } + } + return description; + } + private Index getSyntacticIndex(){ return new SolrSyntacticIndex(schema, solrServerURL, searchField); } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java 2014-01-30 08:43:49 UTC (rev 4216) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java 2014-02-03 14:04:40 UTC (rev 4217) @@ -136,6 +136,11 @@ Model cbd; for (Individual individual : individuals) { try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { cbd = cbdGen.getConciseBoundedDescription(individual.getName(), maxCBDDepth, true); model.add(cbd); } catch (Exception e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-01-30 08:43:51
|
Revision: 4216 http://sourceforge.net/p/dl-learner/code/4216 Author: lorenz_b Date: 2014-01-30 08:43:49 +0000 (Thu, 30 Jan 2014) Log Message: ----------- fixed bug. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-01-29 14:25:19 UTC (rev 4215) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-01-30 08:43:49 UTC (rev 4216) @@ -89,7 +89,7 @@ } public AutomaticNegativeExampleFinderSPARQL2(SparqlEndpoint se, String namespace) { - this(se, new SPARQLReasoner(new SparqlEndpointKS(se))); + this(se, new SPARQLReasoner(new SparqlEndpointKS(se)), namespace); } public AutomaticNegativeExampleFinderSPARQL2(SPARQLReasoner reasoner, String namespace) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-01-29 14:25:23
|
Revision: 4215 http://sourceforge.net/p/dl-learner/code/4215 Author: lorenz_b Date: 2014-01-29 14:25:19 +0000 (Wed, 29 Jan 2014) Log Message: ----------- Some modifications due to refactoring of neg. examples finder. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java trunk/test/isle/swore/ontology_with_comments.owl Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -205,7 +205,7 @@ cli.setContext(context); cli.setConfFile(file); cli.run(); - } catch (Exception e) { + } catch (Exception e) {e.printStackTrace(); String stacktraceFileName = "log/error.log"; // e.printStackTrace(); Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -879,7 +879,7 @@ } private void filter(Model model) { - // filter out triples with String literals, as there often occur + // filter out triples with String literals, as therein often occur // some syntax errors and they are not relevant for learning List<Statement> statementsToRemove = new ArrayList<Statement>(); List<Statement> statementsToAdd = new ArrayList<Statement>(); Modified: trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -436,12 +436,10 @@ long startTime = System.currentTimeMillis(); System.out.print("finding negatives ... "); AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.fuzzyShrink(negExStr, 20); - SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, 20); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); long runTime = System.currentTimeMillis() - startTime; - System.out.println("done (" + negExStr.size()+ " examples fround in " + runTime + " ms)"); + System.out.println("done (" + negExamples.size()+ " examples fround in " + runTime + " ms)"); SparqlKnowledgeSource ks2; AbstractReasonerComponent rc; Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -639,18 +639,14 @@ // get instances of class as positive examples SPARQLReasoner sr = new SPARQLReasoner(ks); SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); - SortedSet<String> posExStr = Helper.getStringSet(posExamples); // get negative examples via various strategies System.out.print("finding negatives ... "); AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.fuzzyShrink(negExStr, 20); - SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, 20); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + System.out.println("done (" + negExamples.size()+ ")"); - System.out.println("done (" + negExStr.size()+ ")"); - ComponentManager cm = ComponentManager.getInstance(); SparqlKnowledgeSource ks2 = cm.knowledgeSource(SparqlKnowledgeSource.class); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -645,20 +645,16 @@ private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, NamedClass nc, boolean equivalence) throws ComponentInitException { // get instances of class as positive examples - SPARQLReasoner sr = new SPARQLReasoner(ks); - SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); - SortedSet<String> posExStr = Helper.getStringSet(posExamples); + SPARQLReasoner sr = new SPARQLReasoner(ks); + SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); + + // get negative examples via various strategies + System.out.print("finding negatives ... "); + AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, 20); + SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + System.out.println("done (" + negExamples.size()+ ")"); - // get negative examples via various strategies - System.out.print("finding negatives ... "); - AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.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); Modified: trunk/test/isle/swore/ontology_with_comments.owl =================================================================== --- trunk/test/isle/swore/ontology_with_comments.owl 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/test/isle/swore/ontology_with_comments.owl 2014-01-29 14:25:19 UTC (rev 4215) @@ -430,11 +430,20 @@ <!-- http://purl.org/dc/elements/1.1/description --> - <owl:ObjectProperty rdf:about="&dc;description"> + <owl:DatatypeProperty rdf:about="&dc;description"> + <rdf:type rdf:resource="&owl;FunctionalProperty"/> <rdfs:label rdf:datatype="&xsd;string">description</rdfs:label> <rdfs:label xml:lang="de">Beschreibung</rdfs:label> <rdfs:range rdf:resource="&xsd;string"/> - </owl:ObjectProperty> + <rdfs:domain> + <owl:Class> + <owl:unionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&req;Goal"/> + <rdf:Description rdf:about="&req;Requirement"/> + </owl:unionOf> + </owl:Class> + </rdfs:domain> + </owl:DatatypeProperty> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-01-29 14:24:21
|
Revision: 4214 http://sourceforge.net/p/dl-learner/code/4214 Author: lorenz_b Date: 2014-01-29 14:24:16 +0000 (Wed, 29 Jan 2014) Log Message: ----------- Added copy of EL algorithm able to handle data properties. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.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/fuzzydll/FuzzyCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java trunk/components-core/src/main/java/org/dllearner/core/owl/BooleanDataRange.java trunk/components-core/src/main/java/org/dllearner/core/owl/DataRange.java trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypePropertyHierarchy.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeQuantorRestriction.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeSomeRestriction.java trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/CachingConciseBoundedDescriptionGenerator.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGenerator.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SymmetricConciseBoundedDescriptionGeneratorImpl.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/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/Utility.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/ConceptComparator.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETestCorpus.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETestNoCorpus.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/SemanticBibleExperiment.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DisjunctiveHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdge.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdgeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNodeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionTreeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/SearchTreeNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/Simulation.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/StableHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/TreeAndRoleSet.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/TreeAndRoleSetComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/TreeTuple.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/package.html trunk/components-core/src/main/java/org/dllearner/refinementoperators/ELDown3.java Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaPlainExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaSemanticIndexExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaSyntacticIndexBasedExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/Experiment.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 2014-01-21 12:49:51 UTC (rev 4213) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -20,12 +20,10 @@ package org.dllearner.algorithms.celoe; import java.io.File; -import java.text.DecimalFormat; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -50,7 +48,6 @@ import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.CustomHierarchyRefinementOperator; @@ -108,7 +105,6 @@ // all descriptions in the search tree plus those which were too weak (for fast redundancy check) private TreeSet<Description> descriptions; - private EvaluatedDescriptionSet bestEvaluatedDescriptions; // if true, then each solution is evaluated exactly instead of approximately // private boolean exactBestDescriptionEvaluation = false; @@ -140,10 +136,6 @@ private boolean forceMutualDifference = false; // utility variables - private String baseURI; - private Map<String, String> prefixes; - private DecimalFormat dfPercent = new DecimalFormat("0.00%"); - private ConceptComparator descriptionComparator = new ConceptComparator(); // statistical variables private int expressionTests = 0; @@ -305,8 +297,7 @@ } // operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); - baseURI = reasoner.getBaseURI(); - prefixes = reasoner.getPrefixes(); + if(writeSearchTree) { File f = new File(searchTreeFile ); Files.clearFile(f); @@ -797,7 +788,7 @@ // check whether the node is a potential solution candidate private Description rewriteNode(OENode node) { Description description = node.getDescription(); - // minimize description (expensive!) - also performes some human friendly rewrites + // minimize description (expensive!) - also performs some human friendly rewrites Description niceDescription; if(useMinimizer) { niceDescription = minimizer.minimizeClone(description); @@ -809,6 +800,21 @@ return niceDescription; } + // check whether the node is a potential solution candidate + private Description rewriteNodeSimple(OENode node) { + Description description = node.getDescription(); + // minimize description (expensive!) - also performs some human friendly rewrites + Description niceDescription; + if(useMinimizer) { + niceDescription = minimizer.minimizeClone(description); + } else { + niceDescription = description; + } + // replace \exists r.\top with \exists r.range(r) which is easier to read for humans + ConceptTransformation.replaceRange(niceDescription, reasoner); + return niceDescription; + } + private boolean terminationCriteriaSatisfied() { return stop || @@ -843,33 +849,12 @@ return startNode; } - // central function for printing description - private String descriptionToString(Description description) { - return description.toManchesterSyntaxString(baseURI, prefixes); - } - @SuppressWarnings("unused") private String bestDescriptionToString() { EvaluatedDescription best = bestEvaluatedDescriptions.getBest(); return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()) + ")"; } - private String getSolutionString() { - int current = 1; - String str = ""; - for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) { - // temporary code - if(learningProblem instanceof PosNegLPStandard) { - str += current + ": " + descriptionToString(ed.getDescription()) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(ed.getDescription(),1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(ed.getDescription(),1)) + ")\n"; - } else { - str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n"; -// System.out.println(ed); - } - current++; - } - return str; - } - // private String getTemporaryString(Description description) { // return descriptionToString(description) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(description,1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(description,1)) + ")"; // } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2014-01-21 12:49:51 UTC (rev 4213) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -20,15 +20,12 @@ package org.dllearner.algorithms.celoe; import java.io.File; -import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -41,7 +38,6 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; -import org.dllearner.algorithms.celoe.PCELOE.Worker; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractLearningProblem; @@ -60,7 +56,6 @@ import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.CustomHierarchyRefinementOperator; @@ -153,11 +148,6 @@ // but it can also suppress quite useful expressions private boolean forceMutualDifference = false; - // utility variables - private String baseURI; - private Map<String, String> prefixes; - private DecimalFormat dfPercent = new DecimalFormat("0.00%"); - private ConceptComparator descriptionComparator = new ConceptComparator(); // statistical variables private int expressionTests = 0; @@ -804,33 +794,12 @@ return startNode; } - // central function for printing description - private String descriptionToString(Description description) { - return description.toManchesterSyntaxString(baseURI, prefixes); - } - @SuppressWarnings("unused") private String bestDescriptionToString() { EvaluatedDescription best = bestEvaluatedDescriptions.getBest(); return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()) + ")"; } - private String getSolutionString() { - int current = 1; - String str = ""; - for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) { - // temporary code - if(learningProblem instanceof PosNegLPStandard) { - str += current + ": " + descriptionToString(ed.getDescription()) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(ed.getDescription(),1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(ed.getDescription(),1)) + ")\n"; - } else { - str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n"; -// System.out.println(ed); - } - current++; - } - return str; - } - // private String getTemporaryString(Description description) { // return descriptionToString(description) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(description,1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(description,1)) + ")"; // } 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 2014-01-21 12:49:51 UTC (rev 4213) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -34,6 +34,9 @@ import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; @@ -62,16 +65,22 @@ private boolean isRunning = false; private boolean stop = false; - private double treeSearchTimeSeconds = 1.0; + private double treeSearchTimeSeconds = 10.0; private long treeStartTime; // "instanceBasedDisjoints", "Specifies whether to use real disjointness checks or instance based ones (no common instances) in the refinement operator." @ConfigOption(name="instanceBasedDisjoints", required=false, defaultValue="true", description="Specifies whether to use real disjointness checks or instance based ones (no common instances) in the refinement operator.", propertyEditorClass=BooleanEditor.class) private boolean instanceBasedDisjoints = true; + @ConfigOption(name = "stopOnFirstDefinition", defaultValue="false", description="algorithm will terminate immediately when a correct definition is found") + private boolean stopOnFirstDefinition = false; + + @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") + private double noisePercentage = 0.0; + + private double noise; + // a set with limited size (currently the ordering is defined in the class itself) - private EvaluatedDescriptionSet bestEvaluatedDescriptions = new EvaluatedDescriptionSet(AbstractCELA.MAX_NR_OF_RESULTS); - private SearchTreeNode startNode; private ELHeuristic heuristic; private TreeSet<SearchTreeNode> candidates; @@ -80,7 +89,7 @@ } - public ELLearningAlgorithm(PosNegLP problem, AbstractReasonerComponent reasoner) { + public ELLearningAlgorithm(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) { super(problem, reasoner); // configurator = new ELLearningAlgorithmConfigurator(this); } @@ -116,6 +125,8 @@ candidates = new TreeSet<SearchTreeNode>(heuristic); operator = new ELDown2(reasoner, instanceBasedDisjoints); + + noise = noisePercentage/100d; } @Override @@ -151,29 +162,29 @@ } // print solution(s) - logger.info("solution : " + bestEvaluatedDescriptions.getBest() + " [time: " + Helper.prettyPrintNanoSeconds(System.nanoTime()-treeStartTime) + "]"); + logger.info("solutions[time: " + Helper.prettyPrintNanoSeconds(System.nanoTime()-treeStartTime) + "]\n" + getSolutionString()); isRunning = false; } // evaluates a description in tree form private void addDescriptionTree(ELDescriptionTree descriptionTree, SearchTreeNode parentNode) { - // create search tree node SearchTreeNode node = new SearchTreeNode(descriptionTree); // convert tree to standard description Description description = descriptionTree.transformToDescription(); + description = getNiceDescription(description); -// double accuracy = getLearningProblem().getAccuracyOrTooWeak(description, 0); + double accuracy = getLearningProblem().getAccuracyOrTooWeak(description, noise); int negCovers = ((PosNegLP)getLearningProblem()).coveredNegativeExamplesOrTooWeak(description); - if(negCovers == -1) { -// if(accuracy == -1) { +// if(negCovers == -1) { + if(accuracy == -1) { node.setTooWeak(); } else { node.setCoveredNegatives(negCovers); } - +// System.out.println(descriptionTree.transformToDescription() + "|" + negCovers); // link to parent (unless start node) if(parentNode == null) { startNode = node; @@ -205,6 +216,26 @@ } + private Description getNiceDescription(Description d){ + Description description = d.clone(); + List<Description> children = description.getChildren(); + for(int i=0; i<children.size(); i++) { + description.replaceChild(i, getNiceDescription(children.get(i))); + } + if(children.size()==0) { + return description; + } else if(description instanceof ObjectSomeRestriction) { + // \exists r.\bot \equiv \bot + if(description.getChild(0) instanceof Thing) { + Description range = reasoner.getRange((ObjectProperty) ((ObjectSomeRestriction) description).getRole()); + description.replaceChild(0, range); + } else { + description.replaceChild(0, getNiceDescription(description.getChild(0))); + } + } + return description; + } + private boolean stoppingCriteriaSatisfied() { // in some cases, there could be no candidate left ... if(candidates.isEmpty()) { @@ -222,7 +253,7 @@ // stop if we have a node covering all positives and none of the negatives SearchTreeNode bestNode = candidates.last(); - return (bestNode.getCoveredNegatives() == 0); + return stopOnFirstDefinition && (bestNode.getCoveredNegatives() == 0); } private void reset() { @@ -270,11 +301,40 @@ return bestEvaluatedDescriptions.getSet(); } + /** + * @param stopOnFirstDefinition the stopOnFirstDefinition to set + */ + public void setStopOnFirstDefinition(boolean stopOnFirstDefinition) { + this.stopOnFirstDefinition = stopOnFirstDefinition; + } + + /** + * @return the stopOnFirstDefinition + */ + public boolean isStopOnFirstDefinition() { + return stopOnFirstDefinition; + } + + /** * @return the startNode */ public SearchTreeNode getStartNode() { return startNode; } + + /** + * @return the noisePercentage + */ + public double getNoisePercentage() { + return noisePercentage; + } + + /** + * @param noisePercentage the noisePercentage to set + */ + public void setNoisePercentage(double noisePercentage) { + this.noisePercentage = noisePercentage; + } } 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 2014-01-21 12:49:51 UTC (rev 4213) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -130,7 +130,7 @@ } - public ELLearningAlgorithmDisjunctive(PosNegLP problem, AbstractReasonerComponent reasoner) { + public ELLearningAlgorithmDisjunctive(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) { super(problem, reasoner); } Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DisjunctiveHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DisjunctiveHeuristic.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DisjunctiveHeuristic.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -0,0 +1,38 @@ +/** + * 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.algorithms.elcopy; + +public class DisjunctiveHeuristic implements ELHeuristic { + + ELDescriptionTreeComparator edt = new ELDescriptionTreeComparator(); + + public int compare(SearchTreeNode tree1, SearchTreeNode tree2) { + double diff = tree1.getScore()-tree2.getScore(); + if(diff < 0.00001 && diff > -0.00001) { + return edt.compare(tree1.getDescriptionTree(), tree2.getDescriptionTree()); + } else if(diff > 0){ + return 1; +// return (int)Math.signum(diff); + } else { + return -1; + } + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdge.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdge.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdge.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -0,0 +1,79 @@ +/** + * 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.algorithms.elcopy; + +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Property; + +/** + * A (directed) edge in an EL description tree. It consists of an edge + * label, which is an object property, and the EL description tree + * the edge points to. + * + * @author Jens Lehmann + * + */ +public class ELDescriptionEdge { + + private Property label; + + private ELDescriptionNode node; + + /** + * Constructs and edge given a label and an EL description tree. + * @param label The label of this edge. + * @param tree The tree the edge points to (edges are directed). + */ + public ELDescriptionEdge(Property label, ELDescriptionNode tree) { + this.label = label; + this.node = tree; + } + + /** + * @param label the label to set + */ + public void setLabel(Property label) { + this.label = label; + } + + /** + * @return The label of this edge. + */ + public Property getLabel() { + return label; + } + + /** + * @return The EL description tree + */ + public ELDescriptionNode getNode() { + return node; + } + + public boolean isObjectProperty(){ + return label instanceof ObjectProperty; + } + + @Override + public String toString() { + return "--" + label + "--> " + node.toDescriptionString(); + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdgeComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdgeComparator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionEdgeComparator.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -0,0 +1,47 @@ +/** + * 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.algorithms.elcopy; + +import java.util.Comparator; + +/** + * @author Jens Lehmann + * + */ +public class ELDescriptionEdgeComparator implements Comparator<ELDescriptionEdge> { + + private ELDescriptionNodeComparator nodeComp; + + public ELDescriptionEdgeComparator() { + nodeComp = new ELDescriptionNodeComparator(); + } + + @Override + public int compare(ELDescriptionEdge edge1, ELDescriptionEdge edge2) { + // perform string comparison on node labels + int comp = edge1.getLabel().getURI().compareTo(edge2.getLabel().getURI()); + if(comp==0) { + return nodeComp.compare(edge1.getNode(), edge2.getNode()); + } else { + return comp; + } + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNode.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNode.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -0,0 +1,768 @@ +/** + * 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.algorithms.elcopy; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.NavigableSet; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.core.owl.DataRange; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypeSomeRestriction; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Property; +import org.dllearner.core.owl.Thing; + +/** + * Represents an EL description tree, which corresponds to a + * description in the EL description logic. Note that an EL description tree + * can be a subtree of another EL description tree. In general, + * an EL description tree is a tree where the node label is a set + * of named classes and the edges are labelled with a property. + * + * In the documentation below "this node" refers to the root node + * of this EL description (sub-)tree. One tree cannot be reused, + * i.e. used as subtree in several description trees, as some of + * the associated variables (level, simulation) depend on the overall + * tree. + * + * @author Jens Lehmann + * + */ +@SuppressWarnings("unused") +public class ELDescriptionNode { + + // the reference tree for storing values, must not be null + protected ELDescriptionTree tree; + + protected TreeSet<NamedClass> label = new TreeSet<NamedClass>(); + + protected List<ELDescriptionEdge> edges = new LinkedList<ELDescriptionEdge>(); + + protected int level; + + // parent node in the tree; + // null indicates that this node is a root node + protected ELDescriptionNode parent = null; + + // simulation information (list or set?) + protected Set<ELDescriptionNode> in = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> inSC1 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> inSC2 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> out = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> outSC1 = new HashSet<ELDescriptionNode>(); + protected Set<ELDescriptionNode> outSC2 = new HashSet<ELDescriptionNode>(); + + protected boolean isClassNode; + protected DataRange dataRange; + + /** + * Internal constructor used for cloning nodes. + */ + protected ELDescriptionNode() { + + } + + /** + * Constructs an EL description tree with empty root label. + */ + public ELDescriptionNode(ELDescriptionTree tree) { + this(tree, new TreeSet<NamedClass>()); + } + + // convenience constructor + public ELDescriptionNode(ELDescriptionTree tree, NamedClass... label) { + this(tree, new TreeSet<NamedClass>(Arrays.asList(label))); + } + + /** + * Constructs an EL description tree given its root label. + * @param label Label of the root node. + */ + public ELDescriptionNode(ELDescriptionTree tree, TreeSet<NamedClass> label) { + this.label = label; + this.edges = new LinkedList<ELDescriptionEdge>(); + this.tree = tree; + level = 1; + parent = null; + // this is the root node of the overall tree + tree.rootNode = this; + tree.addNodeToLevel(this, level); + tree.size += label.size(); + + isClassNode = true; + } + + /** + * Constructs an EL description tree given its root label. + * @param label Label of the root node. + */ + public ELDescriptionNode(ELDescriptionTree tree, DataRange dataRange) { + this.dataRange = dataRange; + this.edges = new LinkedList<ELDescriptionEdge>(); + this.tree = tree; + level = 1; + parent = null; + // this is the root node of the overall tree + tree.rootNode = this; + tree.addNodeToLevel(this, level); + tree.size += label.size(); + + isClassNode = false; + } + + // convenience constructor + public ELDescriptionNode(ELDescriptionNode parentNode, Property parentProperty, NamedClass... label) { + this(parentNode, parentProperty, new TreeSet<NamedClass>(Arrays.asList(label))); + } + + public ELDescriptionNode(ELDescriptionNode parentNode, Property parentProperty, Set<NamedClass> label) { +// this.label = label; + // we first need to add the edge and update the simulation and then add + // all classes iteratively to the label (each time updating the simulation again) + this.edges = new LinkedList<ELDescriptionEdge>(); + parent = parentNode; + // the reference tree is the same as for the parent tree + tree = parentNode.tree; + // level increases by 1 + level = parentNode.level + 1; + // we add an edge from the parent to this node + ELDescriptionEdge edge = new ELDescriptionEdge(parentProperty, this); + parent.edges.add(edge); + // we need to update the set of nodes on a particular level + tree.addNodeToLevel(this, level); + + // simulation update +// Monitor mon = MonitorFactory.start("simulation update"); + // the nodes, which need to be updated + Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); + + // loop over all nodes on the same level, which are not in the in set + Set<ELDescriptionNode> nodes = tree.getNodesOnLevel(level); + for(ELDescriptionNode w : nodes) { + // to save space, we do not add reflexive relations + if(w != this) { + // (w,v') is automatically added + tree.extendSimulation(w, this); + + // check conditions for (v',w) + boolean sc1 = false, sc2 = false; + + if(w.label.size() == 0) { + tree.extendSimulationSC1(this, w); + sc1 = true; + } + + if(w.edges.size() == 0) { + tree.extendSimulationSC2(this, w); + sc2 = true; + } + + if(sc1 && sc2) { + tree.extendSimulationSC12(this, w); + } + + update.add(w.parent); + } + } + update.add(this.parent); + +// if(inSC1.contains(w) && tree.checkSC2(this, w)) { +// tree.extendSimulation(this, w); +// update.add(w.parent); +// } + + // loop over all nodes in out set +// for(ELDescriptionNode w : out) { +// if(!tree.checkSC1(this, w)) { +// tree.shrinkSimulation(this, w); +// update.add(w.parent); +// } +// } + +// System.out.println(update); + + // apply updates recursively top-down + tree.updateSimulation(update); +// mon.stop(); + + // add all classes in label + for(NamedClass nc : label) { + extendLabel(nc); + } + + // 1 for the edge (labels are already taken care of by extendLabel) + tree.size += 1; + + isClassNode = true; + } + + public ELDescriptionNode(ELDescriptionNode parentNode, Property parentProperty, DataRange dataRange) { + this.dataRange = dataRange; + // this.label = label; + // we first need to add the edge and update the simulation and then add + // all classes iteratively to the label (each time updating the simulation again) + this.edges = new LinkedList<ELDescriptionEdge>(); + parent = parentNode; + // the reference tree is the same as for the parent tree + tree = parentNode.tree; + // level increases by 1 + level = parentNode.level + 1; + // we add an edge from the parent to this node + ELDescriptionEdge edge = new ELDescriptionEdge(parentProperty, this); + parent.edges.add(edge); + // we need to update the set of nodes on a particular level + tree.addNodeToLevel(this, level); + + // simulation update +// Monitor mon = MonitorFactory.start("simulation update"); + // the nodes, which need to be updated + Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); + + // loop over all nodes on the same level, which are not in the in set + Set<ELDescriptionNode> nodes = tree.getNodesOnLevel(level); + for(ELDescriptionNode w : nodes) { + // to save space, we do not add reflexive relations + if(w != this) { + // (w,v') is automatically added + tree.extendSimulation(w, this); + + // check conditions for (v',w) + boolean sc1 = false, sc2 = false; + + if(w.label.size() == 0) { + tree.extendSimulationSC1(this, w); + sc1 = true; + } + + if(w.edges.size() == 0) { + tree.extendSimulationSC2(this, w); + sc2 = true; + } + + if(sc1 && sc2) { + tree.extendSimulationSC12(this, w); + } + + update.add(w.parent); + } + } + update.add(this.parent); + +// if(inSC1.contains(w) && tree.checkSC2(this, w)) { +// tree.extendSimulation(this, w); +// update.add(w.parent); +// } + + // loop over all nodes in out set +// for(ELDescriptionNode w : out) { +// if(!tree.checkSC1(this, w)) { +// tree.shrinkSimulation(this, w); +// update.add(w.parent); +// } +// } + +// System.out.println(update); + + // apply updates recursively top-down + tree.updateSimulation(update); +// mon.stop(); + + + // 1 for the edge (labels are already taken care of by extendLabel) + tree.size += 1; + + isClassNode = false; + } + + /** + * @return the isClassNode + */ + public boolean isClassNode() { + return isClassNode; + } + + /** + * @return the dataRange + */ + public DataRange getDataRange() { + return dataRange; + } + + + /** + * Constructs an EL description tree given its root label and edges. + * @param label Label of the root node. + * @param edges Edges connected to the root node. + */ +// TODO: probably delete as this constructor is not straightforward to +// implement within the new structure +// public ELDescriptionNode(SortedSet<NamedClass> label, List<ELDescriptionEdge> edges) { +// this.label = label; +// this.edges = edges; +// } + + /** + * Checks whether this node has a parent. If the parent link + * is null, the node is considered to be a root node. + * @return True of this is the root node and false otherwise. + */ + public boolean isRoot() { + return parent == null; + } + + /** + * Traverses the EL description tree upwards until it finds + * the root and returns it. + * @return The root node of this EL description tree. + */ + public ELDescriptionNode getRoot() { + ELDescriptionNode root = this; + while(root.parent != null) { + root = parent; + } + return root; + } + + /** + * Traverses the tree until the root node and counts how + * many edges are traversed. If this node does not have a parent, + * zero is returned. This method is used for checking the integrity + * of the tree in unit tests. Use {@link #getLevel()} to get the + * level of the tree. + * @return The level of this node (or more specifically the root + * node of this subtree) within the overall EL description tree. + */ + public int computeLevel() { + ELDescriptionNode root = this; + int level = 0; + while(root.parent != null) { + root = parent; + level++; + } + return level; + } + + /** + * This method transform the tree to an EL description. The + * node labels are transformed to an {@link Intersection} + * of {@link NamedClass}. Each edge is transformed to an + * {@link ObjectSomeRestriction}, where the property is the edge + * label and the child description the subtree the edge points + * to. Edges are also added to the intersection. If the intersection + * is empty, {@link Thing} is returned. + * @return The description corresponding to this EL description tree. + */ + public Description transformToDescription() { + int nrOfElements = label.size() + edges.size(); + // leaf labeled with \emptyset stands for owl:Thing + if(nrOfElements == 0) { + return new Thing(); + // we want to avoid intersections with only 1 element, so in this + // case we return either the NamedClass or ObjectSomeRestriction directly + } else if(nrOfElements == 1) { + if(label.size()==1) { + return label.first(); + } else { + ELDescriptionEdge edge = edges.get(0); + if(edge.isObjectProperty()){ + Description child = edge.getNode().transformToDescription(); + return new ObjectSomeRestriction((ObjectProperty) edge.getLabel(), child); + } else { + DataRange range = edge.getNode().getDataRange(); + return new DatatypeSomeRestriction((DatatypeProperty) edge.getLabel(), range); + } + + } + // return an intersection of labels and edges + } else { + Intersection is = new Intersection(); + for(NamedClass nc : label) { + is.addChild(nc); + } + for(ELDescriptionEdge edge : edges) { + if(edge.isObjectProperty()){ + Description child = edge.getNode().transformToDescription(); + ObjectSomeRestriction osr = new ObjectSomeRestriction((ObjectProperty) edge.getLabel(),child); + is.addChild(osr); + } else { + DataRange range = edge.getNode().getDataRange(); + DatatypeSomeRestriction dsr = new DatatypeSomeRestriction((DatatypeProperty) edge.getLabel(), range); + is.addChild(dsr); + } + } + return is; + } + } + + /** + * Gets a list describing the position of this node within the + * tree. If the list is e.g. [2,5,1], then the node can be reached + * by picking the second child of the root node, then picking the + * 5th child of this node and finally selecting the first child of + * the previous node. + * @return The position number of this node within the tree as described above. + */ + public int[] getCurrentPosition() { + int[] position = new int[level-1]; + ELDescriptionNode root = this; + while(root.parent != null) { + position[root.level-2] = root.getChildNumber(); + root = root.parent; + } + return position; + } + + // returns the child number of this node, i.e. whether it is + // the first, second, third etc. child; + // TODO: might be a bit faster to store this explicitly + private int getChildNumber() { + int count = 0; + for(ELDescriptionEdge edge : parent.edges) { + if(edge.getNode() == this) { + return count; + } + count++; + } + throw new RuntimeException("Inconsistent tree. Child tree not reachable from parent."); + } + + /** + * Replaces an entry in the node label. + * @param oldClass Class to remove from label. + * @param newClass Class to add to label. + */ + public void replaceInLabel(NamedClass oldClass, NamedClass newClass) { + label.remove(oldClass); + label.add(newClass); + labelSimulationUpdate(); + } + + /** + * Adds an entry to the node label. + * @param newClass Class to add to label. + */ + public void extendLabel(NamedClass newClass) { + label.add(newClass); + labelSimulationUpdate(); + tree.size += 1; +// System.out.println(tree); +// System.out.println(tree.size); + } + + // simulation update when extending or refining label + // (same in both cases) + private void labelSimulationUpdate() { +// Monitor mon = MonitorFactory.start("simulation update"); + // compute the nodes, which need to be updated + Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); + + Set<ELDescriptionNode> tmp = tree.getNodesOnLevel(level); + for(ELDescriptionNode w : tmp) { + if(w != this) { + // SC1(v,w) can only change from false to true + if(!inSC1.contains(w) && tree.checkSC1(this, w)) { + tree.extendSimulationSC1(this, w); + if(inSC2.contains(w)) { + tree.extendSimulationSC12(this, w); + } + update.add(w.getParent()); + } + // SC1(w,v) can only change from true to false + if(outSC1.contains(w) && !tree.checkSC1(w, this)) { + tree.shrinkSimulationSC1(w, this); + if(outSC2.contains(w)) { + tree.shrinkSimulationSC12(w, this); + } + update.add(w.getParent()); + } + } + } + if(parent != null) { + update.add(parent); + } + + /* + // loop over all nodes on the same level, which are not in the in set + Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level)); + tmp.removeAll(in); + for(ELDescriptionNode w : tmp) { + if(w != this) { + // we only need to recompute SC1 + if(inSC1.contains(w) && tree.checkSC2(this, w)) { + System.out.println("satisfied"); + tree.extendSimulation(this, w); + update.add(w.parent); + } + } + } + + // loop over all nodes in out set (we make a copy, because out + // is potentially modified, so we cannot safely iterate over it) + tmp = new HashSet<ELDescriptionNode>(out); + for(ELDescriptionNode w : tmp) { + if(w != this) { + if(!tree.checkSC1(w, this)) { +// tree.shrinkSimulation(w, this); + tree.shrinkSimulationSC1(w, this); + tree.shrinkSimulationSC12(w, this); + update.add(w.parent); + } + } + } + */ + + // apply updates recursively top-down + tree.updateSimulation(update); +// mon.stop(); + } + + public void refineEdge(int edgeNumber, Property op) { + edges.get(edgeNumber).setLabel(op); + +// Monitor mon = MonitorFactory.start("simulation update"); + // compute the nodes, which need to be updated + Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>(); + update.add(this); + + /* + // loop over all nodes on the same level, which are not in the in set + Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level)); + tmp.removeAll(in); + for(ELDescriptionNode w : tmp) { + if(w != this) { + // we only need to recompute SC1 + if(inSC2.contains(w) && tree.checkSC1(this, w)) { + tree.extendSimulation(this, w); + update.add(w.parent); + } + } + } + + // loop over all nodes in out set + for(ELDescriptionNode w : out) { + if(w != this) { + if(!tree.checkSC2(this, w)) { + tree.shrinkSimulation(this, w); + update.add(w.parent); + } + } + } + */ + +// update.add(this.parent); + + // apply updates recursively top-down + tree.updateSimulation(update); +// mon.stop(); + } + + /** + * Gets the label of this node. Do not modify the returned object, + * but use the provided methods instead! + * @return The label of root node of this subtree. + */ + public NavigableSet<NamedClass> getLabel() { + return label; + } + + /** + * Gets the edges of this node. Do not modify the + * returned object, but use the provided methods instead! + * @return The outgoing edges of this subtree. + */ + public List<ELDescriptionEdge> getEdges() { + return edges; + } + + /** + * Gets the level (distance from root) of this node. The root node + * has level 1. + * @return The level of the (root node of) this subtree in the overall tree. + */ + public int getLevel() { + return level; + } + + @Override + public String toString() { + return toString(0); + } + + private String toString(int indent) { + String indentString = ""; + for(int i=0; i<indent; i++) + indentString += " "; + + String str = indentString + label.toString() + "\n"; + for(ELDescriptionEdge edge : edges) { + str += indentString + "-- " + edge.getLabel() + " -->\n"; + str += edge.getNode().toString(indent + 2); + } + return str; + } + + public String toDescriptionString() { + String str = ""; + if(isClassNode()){ + if(label.isEmpty()) { + str = "TOP"; + } else { + Iterator<NamedClass> it = label.iterator(); + while(it.hasNext()) { + NamedClass nc = it.next(); + if(it.hasNext()) { + str += nc.toString() + " AND "; + } else { + str += nc.toString(); + } + } + } + } else { + str += dataRange; + } + for(ELDescriptionEdge edge : edges) { + str += " AND EXISTS " + edge.getLabel().toString() + ".("; + str += edge.getNode().toDescriptionString() + ")"; + } + return str; + } + + private String toDescriptionString(Set<ELDescriptionNode> nodes) { + String str = ""; + // comma separated list of descriptions + for(ELDescriptionNode node : nodes) { + str += node.toDescriptionString() + ","; + } + // remove last comma + if(str.length() > 0) { + str = str.substring(0, str.length()-1); + } + return str; + } + + public String toSimulationString() { + String str = ""; + str += "in: " + toDescriptionString(in) + "\n"; + str += "inSC1: " + toDescriptionString(inSC1) + "\n"; + str += "inSC2: " + toDescriptionString(inSC2) + "\n"; + str += "out: " + toDescriptionString(out) + "\n"; + str += "outSC1: " + toDescriptionString(outSC1) + "\n"; + str += "outSC2: " + toDescriptionString(outSC2) + "\n"; + return str; + } + + /** + * A convenience method (for debugging purposes) to get a comma separated list of nodes, where the + * nodes are given names (to make them readable). + * @param nodes The node objects. + * @param nodeNames A mapping to node names. + * @return A comma separated list of the node names. + */ + public static String toString(Set<ELDescriptionNode> nodes, Map<ELDescriptionNode,String> nodeNames) { + String str = ""; + // comma separated list of descriptions + for(ELDescriptionNode node : nodes) { + str += nodeNames.get(node) + ","; + } + // remove last comma + if(str.length() > 0) { + str = str.substring(0, str.length()-1); + } + return str; + } + + public String toSimulationString(Map<ELDescriptionNode,String> nodeNames) { + String str = ""; + str += " in: " + toString(in, nodeNames) + "\n"; + str += " inSC1: " + toString(inSC1, nodeNames) + "\n"; + str += " inSC2: " + toString(inSC2, nodeNames) + "\n"; + str += " out: " + toString(out, nodeNames) + "\n"; + str += " outSC1: " + toString(outSC1, nodeNames) + "\n"; + str += " outSC2: " + toString(outSC2, nodeNames) + "\n"; + return str; + } + + public ELDescriptionNode getParent() { + return parent; + } + + public ELDescriptionEdge getParentEdge() { + int childNr = getChildNumber(); + return parent.edges.get(childNr); + } + + /** + * @return the in + */ + public Set<ELDescriptionNode> getIn() { + return in; + } + + /** + * @return the inSC1 + */ + public Set<ELDescriptionNode> getInSC1() { + return inSC1; + } + + /** + * @return the inSC2 + */ + public Set<ELDescriptionNode> getInSC2() { + return inSC2; + } + + /** + * @return the out + */ + public Set<ELDescriptionNode> getOut() { + return out; + } + + /** + * @return the outSC1 + */ + public Set<ELDescriptionNode> getOutSC1() { + return outSC1; + } + + /** + * @return the outSC2 + */ + public Set<ELDescriptionNode> getOutSC2() { + return outSC2; + } + + public ELDescriptionTree getTree() { + return tree; + } +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNodeComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNodeComparator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionNodeComparator.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -0,0 +1,103 @@ +/** + * 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.algorithms.elcopy; + +import java.util.Comparator; +import java.util.Iterator; + +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Property; + +/** + * Compares two EL description trees. It is a lexicographic order + * according to the following criteria: + * - number of children + * - size of label + * - string comparison for each class in the label + * - recursive call on each child (first compare edge label, then child node) + * + * @author Jens Lehmann + * + */ +public class ELDescriptionNodeComparator implements Comparator<ELDescriptionNode> { + + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public int compare(ELDescriptionNode node1, ELDescriptionNode node2) { + int nrOfChildren1 = node1.getEdges().size(); + int nrOfChildren2 = node2.getEdges().size(); + if(nrOfChildren1 > nrOfChildren2) { + return 1; + } else if(nrOfChildren1 < nrOfChildren2) { + return -1; + } else { + int labelSize1 = node1.getLabel().size(); + int labelSize2 = node2.getLabel().size(); + if(labelSize1 > labelSize2) { + return 1; + } else if(labelSize1 < labelSize2) { + return -1; + } else { + int compare = 0; + if(node1.isClassNode() && node2.isClassNode()){ + // navigate through both labels + Iterator<NamedClass> it1 = node1.getLabel().descendingIterator(); + Iterator<NamedClass> it2 = node2.getLabel().descendingIterator(); + while(it1.hasNext()) { + NamedClass nc1 = it1.next(); + NamedClass nc2 = it2.next(); + compare = nc1.getName().compareTo(nc2.getName()); + + } + } else if(!node1.isClassNode() && !node2.isClassNode()){ + compare = node1.getDataRange().toString().compareTo(node2.getDataRange().toString()); + } else { + compare = -1; + } + + if(compare != 0) + return compare; + + // recursively compare all edges + for(int i=0; i<nrOfChildren1; i++) { + // compare by edge name + Property op1 = node1.getEdges().get(i).getLabel(); + Property op2 = node2.getEdges().get(i).getLabel(); + int compare1 = op1.getName().compareTo(op2.getName()); + if(compare1 != 0) + return compare1; + + // compare child nodes + ELDescriptionNode child1 = node1.getEdges().get(i).getNode(); + ELDescriptionNode child2 = node2.getEdges().get(i).getNode(); + int compare2 = compare(child1, child2); + if(compare2 != 0) + return compare2; + } + + // trees are identical + return 0; + } + } + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionTree.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELDescriptionTree.java 2014-01-29 14:24:16 UTC (rev 4214) @@ -0,0 +1,621 @@ +/** + * 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.algorithms.elcopy; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NavigableSet; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypeSomeRestriction; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyHierarchy; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Property; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.UnsupportedLanguageException; + +/** + * Represents an EL description tree. Unlike {@link ELDescriptionNode}, this is + * a tree-wide structure, i.e. it does not implement the tree structure itself, + * but is used to store information about the tree. + * + * @author Jens Lehmann + * + */ +public class ELDescriptionTree implements Cloneable { + + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(ELDescriptionTree.class); + + // to simplify equivalence checks and minimisation, we + // attach a simulation relation to the description tree + // private Simulation simulation; + + // max level = 0 means that there is no tree at all + // (max level = 1 means the root node exists) + private int maxLevel = 0; + + protected int size = 1; + + protected ELDescriptionNode rootNode; + + // the set of all nodes in the tree + private Collection<ELDescriptionNode> nodes = new LinkedList<ELDescriptionNode>(); + + // nodes on a given level of the tree + private Map<Integer, Set<ELDescriptionNode>> levelNodeMapping = new HashMap<Integer, Set<ELDescriptionNode>>(); + + // the background knowledge (we need to have it explicitly here, + // since we store simulation information in the tree and simulation + // updates depend on background knowledge) + protected AbstractReasonerComponent rs; + protected ClassHierarchy subsumptionHierarchy; + protected ObjectPropertyHierarchy roleHierarchy; + + public ELDescriptionTree(AbstractReasonerComponent rs) { + this.rs = rs; + subsumptionHierarchy = rs.getClassHierarchy(); + roleHierarchy = rs.getObjectPropertyHierarchy(); + } + + /** + * Constructs an EL description tree from an EL description. + * + * @param description + * A description + */ + public ELDescriptionTree(AbstractReasonerComponent rs, Description description) { + this(rs); + // construct root node and recursively build the tree + rootNode = new ELDescriptionNode(this); + constructTree(description, rootNode); + } + + private void constructTree(Description description, ELDescriptionNode node) { + if (description instanceof NamedClass) { + node.extendLabel((NamedClass) description); + } else if (description instanceof ObjectSomeRestriction) { + ObjectProperty op = (ObjectProperty) ((ObjectSomeRestriction) description).getRole(); + ELDescriptionNode newNode = new ELDescriptionNode(node, op, new TreeSet<NamedClass>()); + constructTree(description.getChild(0), newNode); + } else if (description instanceof DatatypeSomeRestriction) { + DatatypeProperty op = (DatatypeProperty) ((DatatypeSomeRestriction) description).getRole(); + ELDescriptionNode newNode = new ELDescriptionNode(node, op, ((DatatypeSomeRestriction) description).getDataRange()); + } else if (description instanceof Thing) { + // nothing needs to be done as an empty set is owl:Thing + } else if (description instanceof Intersection) { + // loop through all elements of the intersection + for (Description child : description.getChildren()) { + if (child instanceof NamedClass) { + node.extendLabel((NamedClass) child); + } else if (child instanceof ObjectSomeRestriction) { + ObjectProperty op = (ObjectProperty) ((ObjectSomeRestriction) child).getRole(); + ELDescriptionNode newNode = new ELDescriptionNode(node, op, + new TreeSet<NamedClass>()); + constructTree(child.getChild(0), newNode); + } else { + throw new UnsupportedLanguageException(description + " specifically " + child, + "EL"); + } + } + } else { + throw new UnsupportedLanguageException(description.toString(), "EL"); + } + } + + /** + * Gets the nodes on a specific level of the tree. This information is + * cached here for performance reasons. + * + * @param level + * ... [truncated message content] |
From: <lor...@us...> - 2014-01-21 12:49:55
|
Revision: 4213 http://sourceforge.net/p/dl-learner/code/4213 Author: lorenz_b Date: 2014-01-21 12:49:51 +0000 (Tue, 21 Jan 2014) Log Message: ----------- Continued DBpedia experiment. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/NLPHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternBasedAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.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/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaCorpusGenerator.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaPlainExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaSyntacticIndexBasedExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/Experiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/KnowledgebaseSampleGenerator.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QALDExperiment.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java trunk/components-core/src/main/java/org/dllearner/core/AbstractHeuristic.java trunk/components-core/src/main/java/org/dllearner/core/Heuristic.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/FixDBpediaOntology.java trunk/components-core/src/test/resources/org/dllearner/algorithms/ trunk/components-core/src/test/resources/org/dllearner/algorithms/isle/ trunk/components-core/src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl 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 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -32,6 +32,7 @@ import org.apache.log4j.Logger; import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractHeuristic; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; @@ -57,7 +58,6 @@ import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.ReasoningBasedRefinementOperator; -import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; @@ -98,7 +98,7 @@ // all nodes in the search tree (used for selecting most promising node) private TreeSet<OENode> nodes; - private OEHeuristicRuntime heuristic; // = new OEHeuristicRuntime(); + private AbstractHeuristic heuristic; // = new OEHeuristicRuntime(); // root of search tree private OENode startNode; // the class with which we start the refinement process @@ -132,7 +132,7 @@ // important parameters (non-config options but internal) private double noise; - private boolean filterFollowsFromKB; + private boolean filterFollowsFromKB = false; // less important parameters // forces that one solution cannot be subexpression of another expression; this option is useful to get diversity @@ -207,6 +207,7 @@ @SuppressWarnings("unused") private long timeLastImprovement = 0; + private boolean expandAccuracy100Nodes = false; // public CELOEConfigurator getConfigurator() { // return configurator; @@ -563,8 +564,12 @@ Iterator<OENode> it = nodes.descendingIterator(); while(it.hasNext()) { OENode node = it.next(); - if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength()) { - return node; + if (isExpandAccuracy100Nodes() && node.getHorizontalExpansion() < node.getDescription().getLength()) { + return node; + } else { + if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength()) { + return node; + } } } @@ -693,7 +698,9 @@ // System.out.println(bestEvaluatedDescriptions); } } - + +// bestEvaluatedDescriptions.add(node.getDescription(), accuracy, learningProblem); + // System.out.println(bestEvaluatedDescriptions.getSet().size()); } @@ -1040,12 +1047,12 @@ this.useMinimizer = useMinimizer; } - public OEHeuristicRuntime getHeuristic() { + public AbstractHeuristic getHeuristic() { return heuristic; } @Autowired(required=false) - public void setHeuristic(OEHeuristicRuntime heuristic) { + public void setHeuristic(AbstractHeuristic heuristic) { this.heuristic = heuristic; } @@ -1113,6 +1120,20 @@ return totalRuntimeNs; } + /** + * @return the expandAccuracy100Nodes + */ + public boolean isExpandAccuracy100Nodes() { + return expandAccuracy100Nodes; + } + + /** + * @param expandAccuracy100Nodes the expandAccuracy100Nodes to set + */ + public void setExpandAccuracy100Nodes(boolean expandAccuracy100Nodes) { + this.expandAccuracy100Nodes = expandAccuracy100Nodes; + } + public static void main(String[] args) throws Exception{ AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); ks.init(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OEHeuristicRuntime.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -19,9 +19,7 @@ package org.dllearner.algorithms.celoe; -import java.util.Comparator; - -import org.dllearner.core.Component; +import org.dllearner.core.AbstractHeuristic; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.config.ConfigOption; @@ -36,8 +34,9 @@ * */ @ComponentAnn(name = "OEHeuristicRuntime", shortName = "celoe_heuristic", version = 0.5) -public class OEHeuristicRuntime implements Component, Comparator<OENode>{ +public class OEHeuristicRuntime extends AbstractHeuristic{ + // strong penalty for long descriptions private double expansionPenaltyFactor = 0.1; // bonus for being better than parent node @@ -59,24 +58,6 @@ public void init() throws ComponentInitException { } - - @Override - public int compare(OENode node1, OENode node2) { -// System.out.println("node1 " + node1); -// System.out.println("score: " + getNodeScore(node1)); -// System.out.println("node2 " + node2); -// System.out.println("score: " + getNodeScore(node2)); - - double diff = getNodeScore(node1) - getNodeScore(node2); - - if(diff>0) { - return 1; - } else if(diff<0) { - return -1; - } else { - return conceptComparator.compare(node1.getDescription(), node2.getDescription()); - } - } public double getNodeScore(OENode node) { // accuracy as baseline Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -206,6 +206,7 @@ @SuppressWarnings("unused") private long timeLastImprovement = 0; + private boolean expandAccuracy100Nodes = false; // public CELOEConfigurator getConfigurator() { // return configurator; @@ -562,8 +563,12 @@ Iterator<OENode> it = nodes.descendingIterator(); while(it.hasNext()) { OENode node = it.next(); - if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength()) { + if (isExpandAccuracy100Nodes()) { return node; + } else { + if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength()) { + return node; + } } } @@ -1112,6 +1117,20 @@ return totalRuntimeNs; } + /** + * @return the expandAccuracy100Nodes + */ + public boolean isExpandAccuracy100Nodes() { + return expandAccuracy100Nodes; + } + + /** + * @param expandAccuracy100Nodes the expandAccuracy100Nodes to set + */ + public void setExpandAccuracy100Nodes(boolean expandAccuracy100Nodes) { + this.expandAccuracy100Nodes = expandAccuracy100Nodes; + } + public static void main(String[] args) throws Exception{ AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); ks.init(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/NLPHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/NLPHeuristic.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/NLPHeuristic.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -19,21 +19,15 @@ package org.dllearner.algorithms.isle; -import java.util.Comparator; -import java.util.HashSet; import java.util.Map; import java.util.Set; import org.dllearner.algorithms.celoe.OENode; -import org.dllearner.core.Component; -import org.dllearner.core.ComponentInitException; +import org.dllearner.core.AbstractHeuristic; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Entity; import org.dllearner.utilities.owl.ConceptComparator; -import org.dllearner.utilities.owl.OWLAPIConverter; -import org.semanticweb.owlapi.model.OWLClassExpression; -import org.semanticweb.owlapi.model.OWLEntity; /** * @@ -42,7 +36,7 @@ * @author Jens Lehmann * */ -public class NLPHeuristic implements Component, Comparator<OENode>{ +public class NLPHeuristic extends AbstractHeuristic{ // strong penalty for long descriptions private double expansionPenaltyFactor = 0.1; @@ -67,29 +61,6 @@ this.entityRelevance = entityRelevance; } - @Override - public void init() throws ComponentInitException { - - } - - @Override - public int compare(OENode node1, OENode node2) { -// System.out.println("node1 " + node1); -// System.out.println("score: " + getNodeScore(node1)); -// System.out.println("node2 " + node2); -// System.out.println("score: " + getNodeScore(node2)); - - double diff = getNodeScore(node1) - getNodeScore(node2); - - if(diff>0) { - return 1; - } else if(diff<0) { - return -1; - } else { - return conceptComparator.compare(node1.getDescription(), node2.getDescription()); - } - } - public double getNodeScore(OENode node) { // accuracy as baseline double score = node.getAccuracy(); @@ -124,38 +95,6 @@ return score; } - public double getExpansionPenaltyFactor() { - return expansionPenaltyFactor; - } - - public double getGainBonusFactor() { - return gainBonusFactor; - } - - public void setGainBonusFactor(double gainBonusFactor) { - this.gainBonusFactor = gainBonusFactor; - } - - public double getNodeRefinementPenalty() { - return nodeRefinementPenalty; - } - - public void setNodeRefinementPenalty(double nodeRefinementPenalty) { - this.nodeRefinementPenalty = nodeRefinementPenalty; - } - - public void setExpansionPenaltyFactor(double expansionPenaltyFactor) { - this.expansionPenaltyFactor = expansionPenaltyFactor; - } - - public double getStartNodeBonus() { - return startNodeBonus; - } - - public void setStartNodeBonus(double startNodeBonus) { - this.startNodeBonus = startNodeBonus; - } - /** * @param entityRelevance the entityRelevance to set */ Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/RelevanceMapGenerator.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -0,0 +1,75 @@ +package org.dllearner.algorithms.isle.index; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.isle.metrics.RelevanceMetric; +import org.dllearner.algorithms.isle.metrics.RelevanceUtils; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.NamedClass; +import org.semanticweb.owlapi.model.OWLOntology; + +import com.google.common.hash.HashCode; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; + +/** + * Interface for an index which is able to resolve a given entity's URI to the set of documents containing + * this entity, i.e., documents which contain words disambiguated to the given entity. + * + * @author Lorenz Buehmann + * @author Daniel Fleischhacker + */ +public abstract class RelevanceMapGenerator { + + static HashFunction hf = Hashing.md5(); + private static final Logger logger = Logger.getLogger(RelevanceMapGenerator.class.getName()); + public static String cacheDirectory = "cache/relevance"; + + public static Map<Entity, Double> generateRelevanceMap(NamedClass cls, OWLOntology ontology, RelevanceMetric relevanceMetric, boolean cached){ + Map<Entity, Double> relevanceMap = null; + File folder = new File(cacheDirectory); + folder.mkdirs(); + File file = null; + try { + file = new File(folder, URLEncoder.encode(cls.getName(), "UTF-8") + ".rel"); + } catch (UnsupportedEncodingException e2) { + e2.printStackTrace(); + } + if(cached && file.exists()){ + try { + logger.info("Loading relevance map from disk..."); + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); + relevanceMap = (Map<Entity, Double>) ois.readObject(); + ois.close(); + logger.info("...done."); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + logger.info("Building relevance map..."); + relevanceMap = RelevanceUtils.getRelevantEntities(cls, ontology, relevanceMetric); + try { + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); + oos.writeObject(relevanceMap); + oos.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + logger.info("...done."); + } + return relevanceMap; + } + + public static Map<Entity, Double> generateRelevanceMap(NamedClass cls, OWLOntology ontology, RelevanceMetric relevanceMetric){ + return generateRelevanceMap(cls, ontology, relevanceMetric, false); + } +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/SolrSyntacticIndex.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -3,6 +3,7 @@ */ package org.dllearner.algorithms.isle.index.syntactic; +import java.io.File; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -26,7 +27,10 @@ import org.dllearner.algorithms.isle.textretrieval.AnnotationEntityTextRetriever; import org.dllearner.algorithms.isle.textretrieval.RDFSLabelEntityTextRetriever; import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.NamedClass; +import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; import com.google.common.base.Joiner; @@ -39,6 +43,7 @@ private SolrServer solr; private AnnotationEntityTextRetriever textRetriever; private String searchField; + private String typesField = "types"; long totalNumberOfDocuments = -1; @@ -49,7 +54,7 @@ solr = new HttpSolrServer(solrServerURL); textRetriever = new RDFSLabelEntityTextRetriever(ontology); } - + /* (non-Javadoc) * @see org.dllearner.algorithms.isle.index.Index#getDocuments(org.dllearner.core.owl.Entity) */ @@ -120,7 +125,7 @@ phrase += token.getRawForm() + " "; } phrase.trim(); - terms.add(phrase); + terms.add(quotedString(phrase)); } queryString += Joiner.on("OR").join(terms); queryString += ")"; @@ -136,7 +141,7 @@ } return -1; } - + /* (non-Javadoc) * @see org.dllearner.algorithms.isle.index.Index#getNumberOfDocumentsFor(org.dllearner.core.owl.Entity[]) */ @@ -158,7 +163,7 @@ phrase += token.getRawForm() + " "; } phrase.trim(); - terms.add(phrase); + terms.add(quotedString(phrase)); } queryString += Joiner.on("OR").join(terms); queryString += ")"; @@ -178,5 +183,57 @@ } return -1; } + + + public long getNumberOfDocumentsForTyped(NamedClass resourceClass, Entity entity) { + + + Map<List<Token>, Double> relevantText = textRetriever.getRelevantText(entity); + + String queryString = "("; + Set<String> terms = new HashSet<>(); + for (Entry<List<Token>, Double> entry : relevantText.entrySet()) { + List<Token> tokens = entry.getKey(); + String phrase = ""; + for (Token token : tokens) { +// terms.add(token.getRawForm()); + phrase += token.getRawForm() + " "; + } + phrase.trim(); + terms.add(quotedString(phrase)); + } + queryString += Joiner.on("OR").join(terms); + queryString += ")";System.out.println(queryString); + + SolrQuery query = new SolrQuery( + searchField + ":" + queryString + " AND " + typesField + ":" + quotedString(resourceClass.getName()));//System.out.println(query); + try { + QueryResponse response = solr.query(query); + SolrDocumentList list = response.getResults(); + return list.getNumFound(); + } catch (SolrServerException e) { + e.printStackTrace(); + } + return -1; + } + + private String quotedString(String s){ + return "\"" + s.trim() + "\""; + } + + public static void main(String[] args) throws Exception { + String solrServerURL = "http://solr.aksw.org/en_dbpedia_resources/"; + String searchField = "comment"; + OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl")); + SolrSyntacticIndex index = new SolrSyntacticIndex(ontology, solrServerURL, searchField); + long n = index.getNumberOfDocumentsFor(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://schema.org/Canal")); + System.out.println(n); + n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://schema.org/Canal")); + System.out.println(n); + n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://dbpedia.org/ontology/nationality")); + System.out.println(n); + n = index.getNumberOfDocumentsForTyped(new NamedClass("http://dbpedia.org/ontology/Person"), new NamedClass("http://dbpedia.org/ontology/birthPlace")); + System.out.println(n); + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceUtils.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -7,6 +7,9 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; import org.dllearner.core.owl.Entity; @@ -20,38 +23,52 @@ */ public class RelevanceUtils { - private static final Logger logger = Logger.getLogger(RelevanceUtils.class.getName()); + static int maxNrOfThreads = Math.max(1, Runtime.getRuntime().availableProcessors() - 1); - public static Map<Entity, Double> getRelevantEntities(Entity entity, Set<Entity> otherEntities, RelevanceMetric metric){ - Map<Entity, Double> relevantEntities = new HashMap<Entity, Double>(); + /** + * Returns a map containing the relevance score based on the given metric between the entity and each other entity. + * @param entity + * @param otherEntities + * @param metric + * @return + */ + public static Map<Entity, Double> getRelevantEntities(final Entity entity, Set<Entity> otherEntities, final RelevanceMetric metric){ + logger.info("Get relevant entities for " + entity); + final Map<Entity, Double> relevantEntities = new HashMap<Entity, Double>(); - for (Entity otherEntity : otherEntities) { - double relevance = metric.getRelevance(entity, otherEntity); - relevantEntities.put(otherEntity, relevance); + ExecutorService executor = Executors.newFixedThreadPool(maxNrOfThreads); + + for (final Entity otherEntity : otherEntities) { + executor.submit(new Runnable() { + @Override + public void run() { + double relevance = metric.getNormalizedRelevance(entity, otherEntity); + logger.info(otherEntity + ":" + relevance); + relevantEntities.put(otherEntity, relevance); + } + }); } + executor.shutdown(); + try { + executor.awaitTermination(1, TimeUnit.DAYS); + } catch (InterruptedException e) { + e.printStackTrace(); + } return relevantEntities; } public static Map<Entity, Double> getRelevantEntities(Entity entity, OWLOntology ontology, RelevanceMetric metric){ - logger.info("Get relevant entities for " + entity); - Map<Entity, Double> relevantEntities = new HashMap<Entity, Double>(); - Set<OWLEntity> owlEntities = new HashSet<OWLEntity>(); owlEntities.addAll(ontology.getClassesInSignature()); owlEntities.addAll(ontology.getDataPropertiesInSignature()); owlEntities.addAll(ontology.getObjectPropertiesInSignature()); + Set<Entity> otherEntities = OWLAPIConverter.getEntities(owlEntities); - otherEntities.remove(entity); - for (Entity otherEntity : otherEntities) { - double relevance = metric.getNormalizedRelevance(entity, otherEntity); - logger.info(otherEntity + ":" + relevance); - relevantEntities.put(otherEntity, relevance); - } - return relevantEntities; + return getRelevantEntities(entity, otherEntities, metric); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternBasedAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternBasedAxiomLearningAlgorithm.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternBasedAxiomLearningAlgorithm.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -111,7 +111,7 @@ logger.info("Pattern: " + pattern); //get the maximum modal depth in the pattern axioms - int modalDepth = MaximumModalDepthDetector.getMaxModalDepth(OWLAPIAxiomConvertVisitor.convertAxiom(pattern)); + int modalDepth = MaximumModalDepthDetector.getMaxModalDepth(OWLAPIAxiomConvertVisitor.convertAxiom(pattern));modalDepth++; logger.info("Modal depth: " + modalDepth); //extract fragment @@ -119,7 +119,9 @@ //try to find instantiation of the pattern with confidence above threshold Set<OWLAxiom> instantiations = applyPattern(OWLAPIAxiomConvertVisitor.convertAxiom(pattern), dataFactory.getOWLClass(IRI.create(cls.getName())), fragment); - System.out.println(instantiations); + for (OWLAxiom instantiation : instantiations) { + System.out.println(instantiation); + } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -143,10 +143,9 @@ } //if NO we have to create a new tree as LGG and compute the LGG for the all child node pairs having the same edge to the parent nodes lgg = new QueryTreeImpl<N>(tree1.getUserObject()); - if(tree1.isResourceNode() && tree2.isResourceNode()){ - lgg.setIsResourceNode(true); - - } +// if(tree1.isResourceNode() && tree2.isResourceNode()){ +// lgg.setIsResourceNode(true); +// } // if(!lgg.getUserObject().equals(tree2.getUserObject())){ // lgg.setUserObject((N)"?"); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -31,6 +31,9 @@ private List<QueryTree<N>> posExamples; private List<QueryTree<N>> negExamples; + + private double coverageWeight = 0.6; + private double specifityWeight = 0.4; public NoiseSensitiveLGG() { } @@ -53,6 +56,7 @@ logger.trace("TODO list size: " + todoList.size()); //pick best element from todo list currentElement = todoList.poll(); + //generate the LGG between the chosen tree and each uncovered positive example for (QueryTree<N> example : currentElement.getFalseNegatives()) { QueryTree<N> tree = currentElement.getTree(); //compute the LGG @@ -63,7 +67,7 @@ //evaluate the LGG EvaluatedQueryTree<N> solution = evaluate(lgg); - if(solution.getScore() > currentlyBestScore){ + if(solution.getScore() >= currentlyBestScore){ //add to todo list, if not already contained in todo list or solution list todo(solution); currentlyBestScore = solution.getScore(); @@ -83,6 +87,7 @@ } private EvaluatedQueryTree<N> evaluate(QueryTree<N> lgg){ + //1. get a score for the coverage = recall oriented //compute positive examples which are not covered by LGG Collection<QueryTree<N>> uncoveredPositiveExamples = getUncoveredTrees(lgg, posExamples); //compute negative examples which are covered by LGG @@ -94,8 +99,20 @@ ? 0 : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExamples.size()); - double score = Heuristics.getFScore(recall, precision); + double coverageScore = recall;//Heuristics.getFScore(recall, precision); + //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + int numberOfSpecificNodes = 0; + for (QueryTree<N> childNode : lgg.getChildrenClosure()) { + if(!childNode.getUserObject().equals("?")){ + numberOfSpecificNodes++; + } + } + double specifityScore = Math.log(numberOfSpecificNodes); + + //3.compute the total score + double score = coverageWeight * coverageScore + specifityWeight * specifityScore; + EvaluatedQueryTree<N> solution = new EvaluatedQueryTree<N>(lgg, uncoveredPositiveExamples, coveredNegativeExamples, score); return solution; Added: trunk/components-core/src/main/java/org/dllearner/core/AbstractHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractHeuristic.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractHeuristic.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -0,0 +1,112 @@ +/** + * 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; + +import java.util.Comparator; + +import org.dllearner.algorithms.celoe.OENode; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.utilities.owl.ConceptComparator; + +/** + * Search algorithm heuristic for the ontology engineering algorithm. The heuristic + * has a strong bias towards short descriptions (i.e. the algorithm is likely to be + * less suitable for learning complex descriptions). + * + * @author Jens Lehmann + * + */ +@ComponentAnn(name = "OEHeuristicRuntime", shortName = "celoe_heuristic", version = 0.5) +public abstract class AbstractHeuristic extends AbstractComponent implements Heuristic, Comparator<OENode>{ + + // strong penalty for long descriptions + private double expansionPenaltyFactor = 0.1; + // bonus for being better than parent node + private double gainBonusFactor = 0.3; + // penalty if a node description has very many refinements since exploring + // such a node is computationally very expensive + private double nodeRefinementPenalty = 0.0001; + // syntactic comparison as final comparison criterion + private ConceptComparator conceptComparator = new ConceptComparator(); + + @ConfigOption(name = "startNodeBonus", defaultValue="0.1") + private double startNodeBonus = 0.1; + + public AbstractHeuristic() { + + } + + @Override + public void init() throws ComponentInitException { + + } + + @Override + public int compare(OENode node1, OENode node2) { +// System.out.println("node1 " + node1); +// System.out.println("score: " + getNodeScore(node1)); +// System.out.println("node2 " + node2); +// System.out.println("score: " + getNodeScore(node2)); + + double diff = getNodeScore(node1) - getNodeScore(node2); + + if(diff>0) { + return 1; + } else if(diff<0) { + return -1; + } else { + return conceptComparator.compare(node1.getDescription(), node2.getDescription()); + } + } + + public abstract double getNodeScore(OENode node); + + public double getExpansionPenaltyFactor() { + return expansionPenaltyFactor; + } + + public double getGainBonusFactor() { + return gainBonusFactor; + } + + public void setGainBonusFactor(double gainBonusFactor) { + this.gainBonusFactor = gainBonusFactor; + } + + public double getNodeRefinementPenalty() { + return nodeRefinementPenalty; + } + + public void setNodeRefinementPenalty(double nodeRefinementPenalty) { + this.nodeRefinementPenalty = nodeRefinementPenalty; + } + + public void setExpansionPenaltyFactor(double expansionPenaltyFactor) { + this.expansionPenaltyFactor = expansionPenaltyFactor; + } + + public double getStartNodeBonus() { + return startNodeBonus; + } + + public void setStartNodeBonus(double startNodeBonus) { + this.startNodeBonus = startNodeBonus; + } +} Added: trunk/components-core/src/main/java/org/dllearner/core/Heuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/Heuristic.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/core/Heuristic.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -0,0 +1,12 @@ +/** + * + */ +package org.dllearner.core; + +/** + * @author Lorenz Buehmann + * + */ +public interface Heuristic extends Component{ + +} Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -1016,6 +1016,17 @@ public Map<String, String> getPrefixes() { return rc.getPrefixes(); } + + public void setPrefixes(Map<String, String> prefixes) { + rc.setPrefixes(prefixes); + } + + /** + * @param baseURI the baseURI to set + */ + public void setBaseURI(String baseURI) { + rc.setBaseURI(baseURI); + } @Override public Description getDomainImpl(ObjectProperty objectProperty) { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -434,6 +434,20 @@ public SortedSet<Individual> getIndividuals() { return individuals; } + + /** + * @param prefixes the prefixes to set + */ + public void setPrefixes(Map<String, String> prefixes) { + this.prefixes = prefixes; + } + + /** + * @param baseURI the baseURI to set + */ + public void setBaseURI(String baseURI) { + this.baseURI = baseURI; + } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getReasonerType() Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -1505,6 +1505,19 @@ public SortedSet<Description> getMostGeneralClasses() { return hierarchy.getMostGeneralClasses(); } + + public SortedSet<NamedClass> getMostSpecificClasses() { + SortedSet<NamedClass> classes = new TreeSet<>(conceptComparator); + String query = "SELECT ?cls WHERE {?cls a <http://www.w3.org/2002/07/owl#Class>. " + + "FILTER NOT EXISTS{?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?cls. FILTER(?sub != <http://www.w3.org/2002/07/owl#Nothing>)}}"; + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + classes.add(new NamedClass(qs.getResource("cls").getURI())); + } + return classes; + } @Override public SortedSet<Description> getSuperClasses(Description description) { Modified: trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -181,6 +181,7 @@ int maxFrequency = positiveExamplesTypes.entrySet().iterator().next().getCount(); if(strategy == SIBLING){//get sibling class based examples + logger.info("Applying sibling classes strategy..."); SortedSet<Individual> siblingNegativeExamples = new TreeSet<Individual>(); //for each type of the positive examples for (NamedClass nc : positiveExamplesTypes.elementSet()) { @@ -188,17 +189,22 @@ //get sibling classes Set<NamedClass> siblingClasses = sr.getSiblingClasses(nc); siblingClasses = filterByNamespace(siblingClasses); - System.out.println("Sibling classes: " + siblingClasses); + logger.info("Sibling classes: " + siblingClasses); int limit = (int)Math.ceil(((double)frequency / positiveExamplesTypes.size()) / siblingClasses.size() * strategyLimit); //get instances for each sibling class for (NamedClass siblingClass : siblingClasses) { - siblingNegativeExamples.addAll(sr.getIndividualsExcluding(siblingClass, nc, limit)); + SortedSet<Individual> individuals = sr.getIndividualsExcluding(siblingClass, nc, maxNrOfReturnedInstances); + individuals.removeAll(siblingNegativeExamples); + SetManipulation.stableShrink(individuals, limit); + siblingNegativeExamples.addAll(individuals); } } siblingNegativeExamples = SetManipulation.stableShrink(siblingNegativeExamples, strategyLimit); + logger.info("Negative examples(" + siblingNegativeExamples.size() + "): " + siblingNegativeExamples); negativeExamples.addAll(siblingNegativeExamples); } else if(strategy == SUPERCLASS){//get super class based examples + logger.info("Applying super class strategy..."); SortedSet<Individual> superClassNegativeExamples = new TreeSet<Individual>(); //for each type of the positive examples for (NamedClass nc : positiveExamplesTypes.elementSet()) { @@ -206,15 +212,22 @@ //get super classes Set<Description> superClasses = sr.getSuperClasses(nc); superClasses.remove(new NamedClass(Thing.instance.getURI())); + superClasses.remove(Thing.instance); superClasses = filterByNamespace(superClasses); + logger.info("Super classes: " + superClasses); int limit = (int)Math.ceil(((double)frequency / positiveExamplesTypes.size()) / superClasses.size() * strategyLimit); //get instances for each super class for (Description superClass : superClasses) { - superClassNegativeExamples.addAll(sr.getIndividualsExcluding(superClass, nc, limit)); + SortedSet<Individual> individuals = sr.getIndividualsExcluding(superClass, nc, maxNrOfReturnedInstances); + individuals.removeAll(negativeExamples); + individuals.removeAll(superClassNegativeExamples); + SetManipulation.stableShrink(individuals, limit); + superClassNegativeExamples.addAll(individuals); } } superClassNegativeExamples = SetManipulation.stableShrink(superClassNegativeExamples, strategyLimit); + logger.info("Negative examples(" + superClassNegativeExamples.size() + "): " + superClassNegativeExamples); negativeExamples.addAll(superClassNegativeExamples); } else if(strategy == RANDOM){//get some random examples Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaCorpusGenerator.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaCorpusGenerator.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaCorpusGenerator.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -25,6 +25,7 @@ import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; +import org.apache.log4j.Logger; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.sparql.SparqlEndpoint; import org.semanticweb.owlapi.apibinding.OWLManager; @@ -45,6 +46,8 @@ */ public class DBpediaCorpusGenerator { + private static final Logger logger = Logger.getLogger(DBpediaCorpusGenerator.class.getName()); + /** * Loads DBpedia ontology from remote URL. */ @@ -68,6 +71,7 @@ } public static Set<String> getDBpediaCorpusSample(String textProperty, int maxNrOfInstancesPerClass){ + logger.info("Generating DBpedia corpus based on " + textProperty + " for at most " + maxNrOfInstancesPerClass + " instances..."); Set<String> documents = new HashSet<>(); SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); @@ -115,10 +119,12 @@ } } } + logger.info("...done."); return documents; } public static Set<String> getDBpediaCorpusSample(String textProperty, Set<NamedClass> classes, int maxNrOfInstancesPerClass){ + logger.info("Generating DBpedia corpus based on " + textProperty + " for " + classes + " based on at most " + maxNrOfInstancesPerClass + " instances..."); Set<String> documents = new HashSet<>(); SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); @@ -163,6 +169,7 @@ } } } + logger.info("...done."); return documents; } Added: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -0,0 +1,425 @@ +/** + * + */ +package org.dllearner.algorithms.isle; + +import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SIBLING; +import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SUPERCLASS; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.algorithms.isle.index.RelevanceMapGenerator; +import org.dllearner.algorithms.isle.index.syntactic.SolrSyntacticIndex; +import org.dllearner.algorithms.isle.metrics.PMIRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.RelevanceMetric; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.OWLAPIOntology; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.refinementoperators.RhoDRDown; +import org.dllearner.utilities.PrefixCCMap; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; + +import com.google.common.base.Charsets; +import com.google.common.collect.Sets; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; +import com.google.common.io.Files; +import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.Property; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.Statement; +import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.RDFS; +import com.hp.hpl.jena.vocabulary.XSD; + +/** + * @author Lorenz Buehmann + * + */ +public class DBpediaExperiment { + + private static final Logger logger = Logger.getLogger(DBpediaExperiment.class.getName()); + + private DecimalFormat dfPercent = new DecimalFormat("0.00%"); + HashFunction hf = Hashing.md5(); + + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); + String namespace = "http://dbpedia.org/ontology/"; + OWLOntology schema; + + static final String solrServerURL = "http://solr.aksw.org/en_dbpedia_resources/"; + static final String searchField = "comment"; + + String cacheDirectory = "cache/isle"; + String testFolder = "experiments/logs/"; + + private SPARQLReasoner reasoner; + private AutomaticNegativeExampleFinderSPARQL2 negativeExampleFinder; + + final int maxNrOfPositiveExamples = 20; + final int maxNrOfNegativeExamples = 50; + boolean posOnly = false; + int maxCBDDepth = 1; + + //learning algorithm settings + private int maxNrOfResults = 50; + private int maxExecutionTimeInSeconds = 20; + private boolean useNegation = false; + private boolean useAllConstructor = false; + + private RelevanceMetric relevanceMetric; + + File resultsFolder = new File("experiments/isle/result3/"); + + + public DBpediaExperiment() { + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cacheDirectory); + negativeExampleFinder = new AutomaticNegativeExampleFinderSPARQL2(endpoint); + KnowledgebaseSampleGenerator.maxCBDDepth = maxCBDDepth; + RelevanceMapGenerator.cacheDirectory = "experiments/relevance/"; + + loadSchema(); + + relevanceMetric = new PMIRelevanceMetric(getSyntacticIndex()); + + resultsFolder.mkdirs(); + } + + public void run(){ + ExecutorService es = Executors.newFixedThreadPool(6); + Set<NamedClass> classes = getClasses(); + classes = reasoner.getMostSpecificClasses(); + List<NamedClass> classList = new ArrayList<>(classes); + Collections.reverse(classList); + + for (NamedClass cls : classList) { + try { + File resultsFile = new File(resultsFolder, URLEncoder.encode(cls.getName(), "UTF-8")); + if(resultsFile.exists()){ + continue; + } + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + try { + run(cls); + } catch (Exception e) { + logger.error("Error when learning class " + cls, e); + } + } + } + + public void run(NamedClass cls){ + logger.info("Learning description of class " + cls); + //get some positive examples + SortedSet<Individual> positiveExamples = getPositiveExamples(cls); + + //we can stop if there are no positive examples + if(positiveExamples.isEmpty()){ + logger.info("Empty class."); + return; + } + + //get some negative examples + SortedSet<Individual> negativeExamples = getNegativeExamples(cls, positiveExamples); + + //generate a sample of the knowledge base based on the examples + OWLOntology knowledgebaseSample = loadKnowledgebaseSample(Sets.union(positiveExamples, negativeExamples)); + + //set up the learning + try { + // set KB + KnowledgeSource ks = new OWLAPIOntology(knowledgebaseSample); + + // set reasoner + FastInstanceChecker reasoner = new FastInstanceChecker(ks); + reasoner.init(); + reasoner.setPrefixes(PrefixCCMap.getInstance()); + reasoner.setBaseURI("http://dbpedia.org/ontology/"); + + // set learning problem + AbstractLearningProblem lp; + if(posOnly){ + lp = new PosOnlyLP(reasoner); + ((PosOnlyLP)lp).setPositiveExamples(positiveExamples); + } else { +// lp = new ClassLearningProblem(reasoner); +// ((ClassLearningProblem)lp).setClassToDescribe(cls); +// ((ClassLearningProblem)lp).setEquivalence(true); + lp = new PosNegLPStandard(reasoner, positiveExamples, negativeExamples); + } + lp.init(); + + + RhoDRDown rop = new RhoDRDown(); + rop.setReasoner(reasoner); + rop.setUseNegation(useNegation); + rop.setUseAllConstructor(useAllConstructor); + rop.init(); + + // + Map<Entity, Double> entityRelevance = RelevanceMapGenerator.generateRelevanceMap(cls, schema, relevanceMetric, true); + + //get the start class for the learning algorithms +// Description startClass = getStartClass(cls, equivalence, true); + + // 1. run basic ISLE + CELOE la = new CELOE(lp, reasoner); + la.setMaxNrOfResults(maxNrOfResults); + la.setOperator(rop); + la.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); +// isle.setStartClass(startClass); + new File(testFolder).mkdirs(); + la.setSearchTreeFile(testFolder + "searchTreeISLE.txt"); + la.setWriteSearchTree(true); +// isle.setTerminateOnNoiseReached(true); + la.setIgnoredConcepts(Collections.singleton(cls)); + la.setReplaceSearchTree(true); + la.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + la.setExpandAccuracy100Nodes(true); + la.init(); + la.start(); + int current = 1; + StringBuilder sb = new StringBuilder(); + for(EvaluatedDescription ed : la.getCurrentlyBestEvaluatedDescriptions().descendingSet()) { + if(lp instanceof PosNegLPStandard) { + sb.append(current + ": " + ed.getDescription().toManchesterSyntaxString(reasoner.getBaseURI(), reasoner.getPrefixes()) + "," + + ((PosNegLPStandard)lp).getPredAccuracyOrTooWeakExact(ed.getDescription(),1) + "," + + ((PosNegLPStandard)lp).getFMeasureOrTooWeakExact(ed.getDescription(),1)); + } + sb.append(",").append(getRelevanceScore(ed.getDescription(), entityRelevance)); + sb.append("\n"); + + current++; + } + try { + Files.write(sb.toString(), new File(resultsFolder, URLEncoder.encode(cls.getName(), "UTF-8")), Charsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } +// System.exit(0); + +// //2. run with syntactic index +// Map<Entity, Double> entityRelevance = RelevanceMapGenerator.generateRelevanceMap(cls, schema, relevanceMetric, true); +// NLPHeuristic heuristic = new NLPHeuristic(entityRelevance); +// la.setHeuristic(heuristic); +// la.init(); +// la.start(); +// +// //3. run with semantic index + } catch (ComponentInitException e) { + e.printStackTrace(); + } + } + + private double getRelevanceScore(Description desc, Map<Entity, Double> entityRelevance){ + Set<Entity> entities = desc.getSignature(); + double score = 0; + for (Entity entity : entities) { + double relevance = entityRelevance.containsKey(entity) ? entityRelevance.get(entity) : 0;//System.out.println(entity + ":" + relevance); + if(!Double.isInfinite(relevance)){ + score += relevance; + } + } + return score; + } + + private SortedSet<Individual> getPositiveExamples(NamedClass cls){ + logger.info("Generating positive examples..."); + SortedSet<Individual> individuals = reasoner.getIndividuals(cls, maxNrOfPositiveExamples); + logger.info("Done. Got " + individuals.size() + ": " + individuals); + return individuals; + } + + private SortedSet<Individual> getNegativeExamples(NamedClass classToDescribe, Set<Individual> positiveExamples){ + logger.info("Generating positive examples..."); + SortedSet<Individual> individuals = negativeExampleFinder.getNegativeExamples(classToDescribe, positiveExamples, Arrays.asList(SUPERCLASS, SIBLING), maxNrOfNegativeExamples); + logger.info("Done. Got " + individuals.size() + ": " + individuals); + return individuals; + } + + private void loadSchema(){ + logger.info("Loading schema..."); + try { + schema = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("src/test/resources/org/dllearner/algorithms/isle/dbpedia_3.9.owl")); + } catch (OWLOntologyCreationException e1) { + e1.printStackTrace(); + } + logger.info("Done. Number of logical axioms: " + schema.getLogicalAxiomCount()); + } + + private OWLOntology loadKnowledgebaseSample(Set<Individual> individuals){ + logger.info("Generating knowledge base sample..."); + Model sampleModel = KnowledgebaseSampleGenerator.createKnowledgebaseSample(endpoint, namespace, individuals); + sampleModel.setNsPrefix("dbo", "http://dbpedia.org/ontology/"); + logger.info("Done. Size: " + sampleModel.size() + " triples"); + cleanUp(sampleModel); + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + sampleModel.write(baos, "TURTLE", null); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLDataFactory df = man.getOWLDataFactory(); + OWLOntology ontology = man.loadOntologyFromOntologyDocument(new ByteArrayInputStream(baos.toByteArray())); + man.addAxioms(ontology, schema.getAxioms()); + man.removeAxioms(ontology, ontology.getAxioms(AxiomType.FUNCTIONAL_DATA_PROPERTY)); + man.removeAxioms(ontology, ontology.getAxioms(AxiomType.FUNCTIONAL_OBJECT_PROPERTY)); + man.removeAxioms(ontology, ontology.getAxioms(AxiomType.DATA_PROPERTY_RANGE)); + man.removeAxioms(ontology, ontology.getAxioms(AxiomType.SAME_INDIVIDUAL)); + man.removeAxiom(ontology, df.getOWLObjectPropertyDomainAxiom( + df.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/mission")), + df.getOWLClass(IRI.create("http://dbpedia.org/ontology/Aircraft")))); + return ontology; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private void cleanUp(Model model){ + // filter out triples with String literals, as therein often occur + // some syntax errors and they are not relevant for learning + List<Statement> statementsToRemove = new ArrayList<Statement>(); + for (Iterator<Statement> iter = model.listStatements().toList().iterator(); iter.hasNext();) { + Statement st = iter.next(); + RDFNode object = st.getObject(); + if (object.isLiteral()) { + // statementsToRemove.add(st); + Literal lit = object.asLiteral(); + if (lit.getDatatype() == null || lit.getDatatype().equals(XSD.xstring)) { + st.changeObject("shortened", "en"); + } else if (lit.getDatatype().getURI().equals(XSD.gYear.getURI())) { + model.add(model.createStatement(st.getSubject(), st.getPredicate(), model.createTypedLiteral(1111, XSDDatatype.XSDgYear))); + statementsToRemove.add(st); + } else if (lit.getDatatype().getURI().equals(XSD.gYearMonth.getURI())) { + statementsToRemove.add(st); + } + } + //remove statements like <x a owl:Class> + if (st.getPredicate().equals(RDF.type)) { + if (object.equals(RDFS.Class.asNode()) || object.equals(OWL.Class.asNode()) || object.equals(RDFS.Literal.asNode()) + || object.equals(RDFS.Resource)) { + statementsToRemove.add(st); + } + } + + //remove unwanted properties + String dbo = "http://dbpedia.org/ontology/"; + Set<String> blackList = Sets.newHashSet(dbo + "wikiPageDisambiguates",dbo + "wikiPageExternalLink", + dbo + "wikiPageID", dbo + "wikiPageInterLanguageLink", dbo + "wikiPageRedirects", dbo + "wikiPageRevisionID", + dbo + "wikiPageWikiLink"); + for(String bl: blackList){ + if (st.getPredicate().getURI().equals(bl)) { + statementsToRemove.add(st); + } + } + } + + model.remove(statementsToRemove); + + statementsToRemove = new ArrayList<Statement>(); + for (Iterator<Statement> iter = model.listStatements().toList().iterator(); iter.hasNext();) { + Statement st = iter.next(); + Property predicate = st.getPredicate(); + if (predicate.equals(RDF.type)) { + Resource object = st.getObject().asResource(); + if (!object.getURI().startsWith(namespace) && !object.getURI().startsWith(OWL.NS)) { + statementsToRemove.add(st); + } else if (object.equals(OWL.FunctionalProperty.asNode())) { + statementsToRemove.add(st); + } + } else if (!predicate.equals(RDFS.subClassOf) && !predicate.equals(OWL.sameAs) && !predicate.asResource().getURI().startsWith(namespace)) { + statementsToRemove.add(st); + } + } + model.remove(statementsToRemove); + } + + private Index getSyntacticIndex(){ + return new SolrSyntacticIndex(schema, solrServerURL, searchField); + } + + private Index getSemanticIndex(){ + return null; + } + + /** + * Get the classes on which the experiment is applied. + * @return + */ + private Set<NamedClass> getClasses(){ + Set<NamedClass> classes = new HashSet<NamedClass>(); + + for(OWLClass cls : schema.getClassesInSignature()){ + classes.add(new NamedClass(cls.toStringID())); + } + + return classes; + } + + public static void main(String[] args) throws Exception { +// ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); +// String cls = "http://dbpedia.org/ontology/Astronaut"; +// OWLDataFactory df = new OWLDataFactoryImpl(); +// OWLAxiom pattern = df.getOWLSubClassOfAxiom( +// df.getOWLClass(IRI.create("http://dllearner.org/pattern/A")), +// df.getOWLObjectIntersectionOf( +// df.getOWLClass(IRI.create("http://dllearner.org/pattern/B")), +// df.getOWLObjectSomeValuesFrom( +// df.getOWLObjectProperty(IRI.create("http://dllearner.org/pattern/p")), +// df.getOWLClass(IRI.create("http://dllearner.org/pattern/C"))))); +// PatternBasedAxiomLearningAlgorithm la = new PatternBasedAxiomLearningAlgorithm(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()), "cache", FragmentExtractionStrategy.INDIVIDUALS); +// la.setClass(new NamedClass(cls)); +// la.setPattern(DLLearnerAxiomConvertVisitor.getDLLearnerAxiom(pattern)); +// la.start(); + + +// new DBpediaExperiment().run(); + new DBpediaExperiment().run(new NamedClass("http://dbpedia.org/ontology/Sales")); + } +} Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaPlainExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaPlainExperiment.java 2014-01-21 12:49:22 UTC (rev 4212) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaPlainExperiment.java 2014-01-21 12:49:51 UTC (rev 4213) @@ -3,29 +3,25 @@ */ package org.dllearner.algorithms.isle; -import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; +import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; -import org.apache.commons.compress.compressors.CompressorException; -import org.apache.commons.compress.compressors.CompressorInputStream; -import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.dllearner.algorithms.isle.index.Index; -import o... [truncated message content] |
From: <lor...@us...> - 2014-01-21 12:49:26
|
Revision: 4212 http://sourceforge.net/p/dl-learner/code/4212 Author: lorenz_b Date: 2014-01-21 12:49:22 +0000 (Tue, 21 Jan 2014) Log Message: ----------- Fixed bug in refinement operator when negation is disabled. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-01-12 16:56:24 UTC (rev 4211) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-01-21 12:49:22 UTC (rev 4212) @@ -608,11 +608,13 @@ int number = ((ObjectCardinalityRestriction)description).getCardinality(); if(description instanceof ObjectMaxCardinalityRestriction) { // rule 1: <= x r.C => <= x r.D - tmp = refine(description.getChild(0), maxLength-3, null, range); - - for(Description d : tmp) { - refinements.add(new ObjectMaxCardinalityRestriction(number,role,d)); - } + if(useNegation || number > 0){ + tmp = refine(description.getChild(0), maxLength-3, null, range); + + for(Description d : tmp) { + refinements.add(new ObjectMaxCardinalityRestriction(number,role,d)); + } + } // rule 2: <= x r.C => <= (x-1) r.C ObjectMaxCardinalityRestriction max = (ObjectMaxCardinalityRestriction) description; @@ -1033,7 +1035,7 @@ // zero fillers: <= -1 r.C does not make sense // one filler: <= 0 r.C is equivalent to NOT EXISTS r.C, // but we still keep it, because ALL r.NOT C may be difficult to reach - if(maxFillers > 0) + if((useNegation && maxFillers > 0) || (!useNegation && maxFillers > 1)) m4.add(new ObjectMaxCardinalityRestriction(maxFillers-1, r, new Thing())); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-01-12 16:56:28
|
Revision: 4211 http://sourceforge.net/p/dl-learner/code/4211 Author: lorenz_b Date: 2014-01-12 16:56:24 +0000 (Sun, 12 Jan 2014) Log Message: ----------- Continued QTL2 QALD eval script. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl2.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QALDExperiment.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java 2014-01-08 19:37:22 UTC (rev 4210) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java 2014-01-12 16:56:24 UTC (rev 4211) @@ -55,5 +55,7 @@ void addAllowedNamespaces(Set<String> allowedNamespaces); void addIgnoredPropperties(Set<String> ignoredProperties); + + void setMaxDepth(int maxDepth); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java 2014-01-08 19:37:22 UTC (rev 4210) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java 2014-01-12 16:56:24 UTC (rev 4211) @@ -34,6 +34,9 @@ import org.dllearner.algorithms.qtl.filters.Filters; import org.dllearner.algorithms.qtl.filters.QuestionBasedStatementFilter; import org.dllearner.algorithms.qtl.filters.ZeroFilter; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGenerator; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGeneratorImpl; +import org.dllearner.kb.sparql.SparqlEndpoint; import com.google.common.collect.Sets; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; @@ -81,6 +84,13 @@ this.objectFilter = filter; } + /** + * @param maxDepth the maxDepth to set + */ + public void setMaxDepth(int maxDepth) { + this.maxDepth = maxDepth; + } + @Override public void setStatementSelector(Selector selector) { this.statementSelector = selector; @@ -414,5 +424,14 @@ public void addIgnoredPropperties(Set<String> ignoredProperties) { this.ignoredProperties.addAll(ignoredProperties); } + + public static void main(String[] args) throws Exception { + QueryTreeFactoryImpl factory = new QueryTreeFactoryImpl(); + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpediaLOD2Cloud()); + String resourceURI = "http://dbpedia.org/resource/Athens"; + Model cbd = cbdGen.getConciseBoundedDescription(resourceURI, 0); + QueryTreeImpl<String> queryTree = factory.getQueryTree(resourceURI, cbd); + System.out.println(queryTree.toSPARQLQueryString()); + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl2.java 2014-01-08 19:37:22 UTC (rev 4210) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl2.java 2014-01-12 16:56:24 UTC (rev 4211) @@ -331,4 +331,11 @@ public void addIgnoredPropperties(Set<String> ignoredProperties) { } + /* (non-Javadoc) + * @see org.dllearner.algorithms.qtl.QueryTreeFactory#setMaxDepth(int) + */ + @Override + public void setMaxDepth(int maxDepth) { + } + } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QALDExperiment.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QALDExperiment.java 2014-01-08 19:37:22 UTC (rev 4210) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QALDExperiment.java 2014-01-12 16:56:24 UTC (rev 4211) @@ -29,9 +29,12 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.apache.log4j.Logger; import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; import org.dllearner.algorithms.qtl.impl.QueryTreeFactoryImpl; +import org.dllearner.algorithms.qtl.operations.lgg.EvaluatedQueryTree; import org.dllearner.algorithms.qtl.operations.lgg.LGGGenerator; import org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorImpl; +import org.dllearner.algorithms.qtl.operations.lgg.NoiseSensitiveLGG; import org.dllearner.kb.sparql.ConciseBoundedDescriptionGenerator; import org.dllearner.kb.sparql.ConciseBoundedDescriptionGeneratorImpl; import org.dllearner.kb.sparql.QueryExecutionFactoryHttp; @@ -43,16 +46,23 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import com.clarkparsia.pellet.rules.LiteralFilter; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import com.hp.hpl.jena.datatypes.RDFDatatype; +import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Triple; import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.sparql.core.Var; +import com.hp.hpl.jena.vocabulary.XSD; /** * @author Lorenz Buehmann @@ -64,9 +74,9 @@ private static final Logger logger = Logger.getLogger(QALDExperiment.class.getName()); List<String> datasetFiles = Lists.newArrayList( - "http://greententacle.techfak.uni-bielefeld.de/~cunger/qald1/dbpedia-train.xml" -// "http://greententacle.techfak.uni-bielefeld.de/~cunger/qald/3/dbpedia-train.xml", -// "http://greententacle.techfak.uni-bielefeld.de/~cunger/qald/3/dbpedia-test.xml" +// "http://greententacle.techfak.uni-bielefeld.de/~cunger/qald1/dbpedia-train.xml", + "http://greententacle.techfak.uni-bielefeld.de/~cunger/qald/3/dbpedia-train.xml", + "http://greententacle.techfak.uni-bielefeld.de/~cunger/qald/3/dbpedia-test.xml" ); SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); @@ -77,13 +87,14 @@ QueryExecutionFactory qef; String cacheDirectory = "cache"; - int minNrOfPositiveExamples = 3; + int minNrOfPositiveExamples = 5; int maxDepth = 2; - double noise = 0d; + double noise = 0.4d; QueryTreeFactory<String> queryTreeFactory; ConciseBoundedDescriptionGenerator cbdGen; - private LGGGenerator<String> lggGenerator; +// private LGGGenerator<String> lggGenerator; + private NoiseSensitiveLGG<String> lggGenerator; public QALDExperiment() { @@ -104,10 +115,12 @@ queryTreeFactory = new QueryTreeFactoryImpl(); queryTreeFactory.addAllowedNamespaces(allowedNamespaces); queryTreeFactory.addIgnoredPropperties(ignoredProperties); - cbdGen = new ConciseBoundedDescriptionGeneratorImpl(endpoint); + queryTreeFactory.setMaxDepth(maxDepth); + + cbdGen = new ConciseBoundedDescriptionGeneratorImpl(endpoint, cacheDirectory); cbdGen.setRecursionDepth(maxDepth); - lggGenerator = new LGGGeneratorImpl<String>(); + lggGenerator = new NoiseSensitiveLGG<>();// LGGGeneratorImpl<String>(); } public void run(){ @@ -120,21 +133,24 @@ for (String sparqlQuery : sparqlQueries) { try { - //generate a set of examples as input for the learning algorithm - Set<String> examples = generateExamples(sparqlQuery, noise); - - if(examples.size() >= minNrOfPositiveExamples){ logger.info("Processing query\n" + sparqlQuery); //convert examples to query trees - List<QueryTree<String>> queryTrees = getQueryTrees(examples); + List<QueryTree<String>> queryTrees = generateExamples(sparqlQuery, noise); + for (QueryTree<String> queryTree : queryTrees) { + logger.info(queryTree.getStringRepresentation()); + } //run LGG - QueryTree<String> lgg = lggGenerator.getLGG(queryTrees); - logger.info("Computed LGG:\n" + lgg.getStringRepresentation()); + List<EvaluatedQueryTree<String>> lggs = lggGenerator.computeLGG(queryTrees); + EvaluatedQueryTree<String> bestLGG = lggs.get(0); + logger.info("Got " + lggs.size() + " LGG query trees. Best computed LGG:\n" + bestLGG); + //find the best extensionally matching tree in the list + EvaluatedQueryTree<String> bestTree = findBestMatchingTree(lggs, sparqlQuery); + //convert to SPARQL query - String learnedSPARQLQuery = lgg.toSPARQLQueryString(true, false); + String learnedSPARQLQuery = bestLGG.getTree().toSPARQLQueryString(true, false); logger.info("Learned Query:\n" + learnedSPARQLQuery); @@ -148,7 +164,6 @@ fMeasureStats.addValue(fmeasure); logger.info(String.format("P=%f\nR=%f\nF-Score=%f", precision, recall, fmeasure)); - } } catch (Exception e) { logger.error("Error occured.", e); } @@ -158,9 +173,25 @@ logger.info("Overall FMeasure:\n" + fMeasureStats); } - private Set<String> generateExamples(String sparqlQuery, double noise){ - Set<String> examples = new TreeSet<>(); - + private EvaluatedQueryTree<String> findBestMatchingTree(List<EvaluatedQueryTree<String>> trees, String targetSPARQLQuery){ + logger.info("Finding best matching query tree..."); + //get the tree with the highest fmeasure + EvaluatedQueryTree<String> bestTree = null; + double bestFMeasure = -1; + for (EvaluatedQueryTree<String> tree : trees) { + String learnedSPARQLQuery = tree.getTree().toSPARQLQueryString(); + System.out.println(learnedSPARQLQuery); + System.out.println(tree.getScore()); + double fMeasure = fMeasure(targetSPARQLQuery, learnedSPARQLQuery); + if(fMeasure > bestFMeasure){ + bestTree = tree; + } + System.out.println(fMeasure); + } + return bestTree; + } + + private List<QueryTree<String>> generateExamples(String sparqlQuery, double noise){ //get all resources returned by the query List<String> resources = getResult(sparqlQuery); @@ -169,22 +200,81 @@ //pick some positive examples from the list List<String> positiveExamples = resources.subList(0, Math.min(minNrOfPositiveExamples, resources.size())); + if(positiveExamples.size() < minNrOfPositiveExamples){ + return new ArrayList<>(); + } - //add some noise - ///TODO + //convert examples to query trees + List<QueryTree<String>> queryTrees = getQueryTrees(positiveExamples); - examples.addAll(positiveExamples); - return examples; + //add some noise, i.e. + //a)add wrong negative examples + //b)take positive examples and modify relevant attributes + Random randomGen = new Random(123); + TriplePatternExtractor triplePatternExtractor = new TriplePatternExtractor(); + List<Triple> triplePatterns = new ArrayList<Triple>(triplePatternExtractor.extractTriplePattern(QueryFactory.create(sparqlQuery, Syntax.syntaxARQ))); + for (QueryTree<String> queryTree : queryTrees) { + double rnd = randomGen.nextDouble(); + if(rnd <= noise){ + //pick a random property to modify + Collections.shuffle(triplePatterns, randomGen); + Triple triplePattern = triplePatterns.get(0); + String predicate = triplePattern.getPredicate().getURI(); + Node object = triplePattern.getObject(); + logger.info("Modifying edge <" + queryTree + ", " + predicate + ", " + object + ">"); + //get the corresponding edge in the tree + Set<Object> edges = queryTree.getEdges(); + for (Object edge : edges) { + if (predicate.equals(edge)) { + List<QueryTree<String>> children = queryTree.getChildren(edge); + for (QueryTree<String> child : children) { + if (child.getUserObject().replace("<", "").replace(">", "").equals(object.toString())) { + if (child.isResourceNode()) { + QueryTree<String> similarTree = getSimilarTree(child, predicate, 1); + if (similarTree != null) { + int id = child.getId(); + queryTree.removeChild((QueryTreeImpl<String>) child); + similarTree.setId(id); + queryTree.addChild((QueryTreeImpl<String>) similarTree, edge); + } else { + child.setUserObject("http://dl-learner.org/qtl#noiseModification"); + } + } else if (child.isLiteralNode()) { + child.setUserObject("\"-999999\"^^<http://www.w3.org/2001/XMLSchema#integer>"); + child.getLiterals().clear(); + child.getLiterals().add(ResourceFactory.createTypedLiteral(-999999)); + } + } + } + } + } + } + } + + return queryTrees; } - private List<QueryTree<String>> getQueryTrees(Set<String> resources){ + private QueryTree<String> getSimilarTree(QueryTree<String> tree, String property, int maxTreeDepth){ + String query = "SELECT ?o WHERE {?s <" + property + "> ?o. FILTER(isURI(?o) && ?o != <" + tree.getUserObject() + ">)} LIMIT 1"; + QueryExecution qe = qef.createQueryExecution(query); + ResultSet rs = qe.execSelect(); + if(rs.hasNext()){ + String uri = rs.next().getResource("o").getURI(); + Model cbd = cbdGen.getConciseBoundedDescription(uri, maxTreeDepth); + QueryTree<String> similarTree = queryTreeFactory.getQueryTree(uri, cbd); + similarTree.setUserObject(uri); + return similarTree; + } + return null; + } + + private List<QueryTree<String>> getQueryTrees(List<String> resources){ List<QueryTree<String>> trees = new ArrayList<QueryTree<String>>(); for (String resource : resources) { Model cbd = cbdGen.getConciseBoundedDescription(resource); QueryTree<String> tree = queryTreeFactory.getQueryTree(resource, cbd); trees.add(tree); - System.out.println(tree.getStringRepresentation()); } return trees; @@ -232,7 +322,7 @@ Element questionNode = (Element) questionNodes.item(i); - int id = Integer.valueOf(questionNode.getAttribute("id")); if(id != 44)continue; + int id = Integer.valueOf(questionNode.getAttribute("id")); //if(id != 44)continue; // String answerType = questionNode.getAttribute("answerType"); boolean aggregation = false;//Boolean.valueOf(questionNode.getAttribute("aggregation")); boolean onlydbo = true;//Boolean.valueOf(questionNode.getAttribute("onlydbo")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |