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...> - 2013-06-06 13:32:33
|
Revision: 3985 http://sourceforge.net/p/dl-learner/code/3985 Author: lorenz_b Date: 2013-06-06 13:32:30 +0000 (Thu, 06 Jun 2013) Log Message: ----------- Updated LGG. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.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/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.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/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java trunk/components-core/src/main/resources/prefixes.csv Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/pom.xml 2013-06-06 13:32:30 UTC (rev 3985) @@ -320,6 +320,11 @@ <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> + <dependency> + <groupId>org.aksw.jena-sparql-api</groupId> + <artifactId>jena-sparql-api-core</artifactId> + <version>2.10.0-3</version> + </dependency> </dependencies> <dependencyManagement> <dependencies> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -55,6 +55,8 @@ QueryTree<N> getNodeById(int nodeId); + boolean sameType(QueryTree<N> tree); + boolean isLiteralNode(); void setLiteralNode(boolean isLiteralNode); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -124,6 +124,12 @@ addChild(subTree, tree.getEdge(child)); } } + + public boolean sameType(QueryTree<N> tree){ + return (isResourceNode && tree.isResourceNode()) || + (isVarNode() && tree.isVarNode()) || + (isLiteralNode && tree.isLiteralNode()); + } public N getUserObject() { return userObject; @@ -327,6 +333,9 @@ @Override public boolean isSubsumedBy(QueryTree<N> tree) { +// if(!sameType(tree)){ +// return false; +// } if(!(tree.getUserObject().equals("?") || tree.getUserObject().equals(this.userObject))){ return false; } 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 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -145,7 +145,7 @@ // } // } // } - if(!lgg.getUserObject().equals(tree2.getUserObject())){ + if(!lgg.sameType(tree2) || !lgg.getUserObject().equals(tree2.getUserObject())){ lgg.setUserObject((N)"?"); lgg.setLiteralNode(false); lgg.setResourceNode(false); 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 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.PriorityQueue; import java.util.Queue; @@ -11,6 +10,9 @@ import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + public class NoiseSensitiveLGG<N> { private LGGGenerator<N> lggGenerator = new LGGGeneratorImpl<N>(); @@ -22,19 +24,25 @@ } public List<EvaluatedQueryTree<N>> computeLGG(List<QueryTree<N>> trees){ + Monitor subMon = MonitorFactory.getTimeMonitor("subsumption-mon"); + Monitor lggMon = MonitorFactory.getTimeMonitor("lgg-mon"); init(trees); EvaluatedQueryTree<N> currentElement; - do{ + do{System.out.println("TODO list size: " + todoList.size()); //pick best element from todo list currentElement = todoList.poll(); for (QueryTree<N> example : currentElement.getUncoveredExamples()) { QueryTree<N> tree = currentElement.getTree(); //compute the LGG + lggMon.start(); QueryTree<N> lgg = lggGenerator.getLGG(tree, example); + lggMon.stop(); //compute examples which are not covered by LGG - Collection<QueryTree<N>> uncoveredExamples = new HashSet<QueryTree<N>>(); + Collection<QueryTree<N>> uncoveredExamples = new ArrayList<QueryTree<N>>(); for (QueryTree<N> queryTree : trees) { + subMon.start(); boolean subsumed = queryTree.isSubsumedBy(lgg); + subMon.stop(); if(!subsumed){ uncoveredExamples.add(queryTree); } @@ -45,6 +53,12 @@ EvaluatedQueryTree<N> solution = new EvaluatedQueryTree<N>(lgg, uncoveredExamples, score); todo(solution); } + System.out.println("LGG time: " + lggMon.getTotal() + "ms"); + System.out.println("Avg. LGG time: " + lggMon.getAvg() + "ms"); + System.out.println("#LGG computations: " + lggMon.getHits()); + System.out.println("Subsumption test time: " + subMon.getTotal() + "ms"); + System.out.println("Avg. subsumption test time: " + subMon.getAvg() + "ms"); + System.out.println("#Subsumption tests: " + subMon.getHits()); solutions.add(currentElement); // todoList.remove(currentElement); } while(!terminationCriteriaSatisfied()); @@ -57,8 +71,8 @@ // EvaluatedQueryTree<N> dummy = new EvaluatedQueryTree<N>(new QueryTreeImpl<N>((N)"TOP"), trees, 0d); // todoList.add(dummy); //compute distinct trees - Collection<QueryTree<N>> distinctTrees = new HashSet<QueryTree<N>>(); - for (QueryTree<N> queryTree : trees) { + Collection<QueryTree<N>> distinctTrees = new ArrayList<QueryTree<N>>(); + for (QueryTree<N> queryTree : trees) {//System.out.println(queryTree.getStringRepresentation()); boolean distinct = true; for (QueryTree<N> otherTree : distinctTrees) { if(queryTree.isSubsumedBy(otherTree)){ @@ -71,7 +85,7 @@ } } for (QueryTree<N> queryTree : distinctTrees) { - Collection<QueryTree<N>> uncoveredExamples = new HashSet<QueryTree<N>>(distinctTrees); + Collection<QueryTree<N>> uncoveredExamples = new ArrayList<QueryTree<N>>(distinctTrees); uncoveredExamples.remove(queryTree); double score = (trees.size() - uncoveredExamples.size()) / (double)trees.size(); todoList.add(new EvaluatedQueryTree<N>(queryTree, uncoveredExamples, score)); 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 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -1,16 +1,24 @@ package org.dllearner.kb.sparql; -import java.io.UnsupportedEncodingException; import java.sql.SQLException; import java.util.Iterator; import java.util.List; +import java.util.concurrent.TimeUnit; +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.aksw.jena_sparql_api.model.QueryExecutionFactoryModel; +import org.aksw.jena_sparql_api.pagination.core.QueryExecutionFactoryPaginated; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; //import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; public class ConciseBoundedDescriptionGeneratorImpl implements ConciseBoundedDescriptionGenerator{ @@ -25,6 +33,7 @@ private List<String> namespaces; private int maxRecursionDepth = 1; + private String cacheDir; public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, ExtractionDBCache cache) { this.endpoint = endpoint; @@ -37,8 +46,19 @@ this.maxRecursionDepth = maxRecursionDepth; } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, String cacheDir, int maxRecursionDepth) { + this.endpoint = endpoint; + this.cacheDir = cacheDir; + this.maxRecursionDepth = maxRecursionDepth; + } + + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, String cacheDir) { + this.endpoint = endpoint; + this.cacheDir = cacheDir; + } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint) { - this(endpoint, null); + this(endpoint, (String)null); } public ConciseBoundedDescriptionGeneratorImpl(Model model) { @@ -59,34 +79,28 @@ private Model getModelChunked(String resource, int depth){ String query = makeConstructQueryOptional(resource, chunkSize, 0, depth); - Model all = ModelFactory.createDefaultModel(); - try { - Model model; - if(cache == null){ - model = getModel(query); - } else { - model = cache.executeConstructQuery(endpoint, query); + QueryExecutionFactory qef; + if(endpoint != null){ + qef = new QueryExecutionFactoryHttp(endpoint.getURL().toString(), endpoint.getDefaultGraphURIs()); + if(cacheDir != null){ + try { + long timeToLive = TimeUnit.DAYS.toMillis(30); + CacheCoreEx cacheBackend = CacheCoreH2.create(cacheDir, timeToLive, true); + CacheEx cacheFrontend = new CacheExImpl(cacheBackend); + qef = new QueryExecutionFactoryCacheEx(qef, cacheFrontend); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } } - all.add(model); - int i = 1; - do{ -// while(model.size() == CHUNK_SIZE){ - query = makeConstructQueryOptional(resource, chunkSize, i * chunkSize, depth); - if(cache == null){ - model = getModel(query); - } else { - model = cache.executeConstructQuery(endpoint, query); - } - all.add(model); - i++; - } while(chunkSize > 0 && model.size() != 0); - } catch (UnsupportedEncodingException e) { - logger.error(e); - } catch (SQLException e) { - logger.error(e); + qef = new QueryExecutionFactoryPaginated(qef, 10000); + } else { + qef = new QueryExecutionFactoryModel(baseModel); } - - return all; + QueryExecution qe = qef.createQueryExecution(query); + Model model = qe.execConstruct(); + return model; } @Override @@ -151,36 +165,6 @@ return filter; } - private Model getModel(String query) throws UnsupportedEncodingException, SQLException{ - if(logger.isDebugEnabled()){ - logger.debug("Sending SPARQL query ..."); - logger.debug("Query:\n" + query.toString()); - } - - Model model; - if(baseModel == null){ - if(cache == null){ - QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); - for (String dgu : endpoint.getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : endpoint.getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - model = queryExecution.execConstruct(); - } else { - model = cache.executeConstructQuery(endpoint, query); - } - } else { - model = QueryExecutionFactory.create(query, baseModel).execConstruct(); - } - - if(logger.isDebugEnabled()){ - logger.debug("Got " + model.size() + " new triples in."); - } - return model; - } - public static void main(String[] args) { Logger.getRootLogger().setLevel(Level.DEBUG); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpedia()); Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -78,6 +78,10 @@ Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE IF NOT EXISTS QUERY_CACHE(QUERYHASH BINARY PRIMARY KEY,QUERY VARCHAR(20000), TRIPLES CLOB, STORE_TIME TIMESTAMP)"); } + + public String getCacheDirectory() { + return databaseDirectory; + } public ExtractionDBCache(String cacheDir) { databaseDirectory = cacheDir; Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -73,6 +73,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.Resource; @@ -494,7 +495,7 @@ Set<NamedClass> siblings = new HashSet<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( !SAMETERM(?sub, <" + cls.getName() + ">)) . }";System.out.println(query); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -590,7 +591,6 @@ * @author sherif */ public SortedSet<Individual> getIndividualsExcluding(Description wantedClass, Description excludeClass, int limit) { - if(!(wantedClass instanceof NamedClass)){ throw new UnsupportedOperationException("Only named classes are supported."); } @@ -598,7 +598,7 @@ String query = "SELECT DISTINCT ?ind WHERE {" + "?ind a <"+((NamedClass)wantedClass).getName() + "> . " + - "FILTER(NOT EXISTS { ?ind a <" + ((NamedClass)excludeClass).getName() + "> } )}"; + "FILTER NOT EXISTS { ?ind a <" + ((NamedClass)excludeClass).getName() + "> } }"; if(limit != 0) { query += " LIMIT " + limit; } 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 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -19,10 +19,22 @@ package org.dllearner.utilities.examples; +import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.RANDOM; +import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SIBLING; +import static org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2.Strategy.SUPERCLASS; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; @@ -30,6 +42,10 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.datastructures.Datastructures; +import com.google.common.base.Predicate; +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multiset; +import com.google.common.collect.Multisets; /** * * Utility class for automatically retrieving negative examples from a @@ -40,12 +56,18 @@ * */ public class AutomaticNegativeExampleFinderSPARQL2 { + + public enum Strategy{ + SUPERCLASS, SIBLING, RANDOM; + } private SparqlEndpoint se; // for re-using existing queries private SPARQLReasoner sr; private SPARQLTasks st; + + private String namespace; public AutomaticNegativeExampleFinderSPARQL2(SparqlEndpoint se) { this.se = se; @@ -54,6 +76,15 @@ st = new SPARQLTasks(se); } + public AutomaticNegativeExampleFinderSPARQL2(SPARQLReasoner reasoner, String namespace) { + this.sr = reasoner; + this.namespace = namespace; + } + + public AutomaticNegativeExampleFinderSPARQL2(SPARQLReasoner reasoner) { + this.sr = reasoner; + } + /** * Get negative examples when learning the description of a class, i.e. * all positives are from some known class. @@ -82,4 +113,92 @@ return negEx; } + public SortedSet<Individual> getNegativeExamples(Set<Individual> positiveExamples, int limit) { + return getNegativeExamples(positiveExamples, Arrays.asList(SUPERCLASS, SIBLING, RANDOM), limit); + } + + public SortedSet<Individual> getNegativeExamples(Set<Individual> positiveExamples, Collection<Strategy> strategies, int limit) { + Map<Strategy, Double> strategiesWithWeight = new HashMap<Strategy, Double>(); + double weight = 1d/strategies.size(); + for (Strategy strategy : strategies) { + strategiesWithWeight.put(strategy, weight); + } + return getNegativeExamples(positiveExamples, strategiesWithWeight, limit); + } + + public SortedSet<Individual> getNegativeExamples(Set<Individual> positiveExamples, Map<Strategy, Double> strategiesWithWeight, int maxNrOfReturnedInstances) { + SortedSet<Individual> negEx = new TreeSet<Individual>(); + + //get the types for each instance + Multiset<NamedClass> types = HashMultiset.create(); + for (Individual ex : positiveExamples) { + types.addAll(sr.getTypes(ex)); + } + + //remove types that do not have the given namespace + if(namespace != null){ + types = Multisets.filter(types, new Predicate<NamedClass>() { + public boolean apply(NamedClass input){ + return input.getName().startsWith(namespace); + } + }); + } + + //keep the most specific types + keepMostSpecificClasses(types); + + for (Entry<Strategy, Double> entry : strategiesWithWeight.entrySet()) { + Strategy strategy = entry.getKey(); + Double weight = entry.getValue(); + //the max number of instances returned by the current strategy + int limit = (int)(weight * maxNrOfReturnedInstances); + //the highest frequency value + int maxFrequency = types.entrySet().iterator().next().getCount(); + if(strategy == SIBLING){ + System.out.println("Sibling Classes Strategy"); + for (NamedClass nc : types.elementSet()) { + int frequency = types.count(nc); + //get sibling classes + Set<NamedClass> siblingClasses = sr.getSiblingClasses(nc); + int nrOfSiblings = siblingClasses.size(); + int v = (int)Math.ceil(((double)frequency / types.size()) / nrOfSiblings * limit); System.out.println(nc + ": " + v); + for (NamedClass siblingClass : siblingClasses) { + negEx.addAll(sr.getIndividualsExcluding(siblingClass, nc, v)); + } + + } + } else if(strategy == SUPERCLASS){ + System.out.println("Super Classes Strategy"); + for (NamedClass nc : types.elementSet()) { + int frequency = types.count(nc); + //get sibling classes + Set<Description> superClasses = sr.getSuperClasses(nc);System.out.println(superClasses); + int nrOfSuperClasses = superClasses.size(); + int v = (int)Math.ceil(((double)frequency / types.size()) / nrOfSuperClasses * limit); System.out.println(nc + ": " + v); + for (Description superClass : superClasses) { + negEx.addAll(sr.getIndividualsExcluding(superClass, nc, v)); + } + } + } else if(strategy == RANDOM){ + + } + } + return negEx; + } + + private void keepMostSpecificClasses(Multiset<NamedClass> classes){ + HashMultiset<NamedClass> copy = HashMultiset.create(classes); + final ClassHierarchy hierarchy = sr.getClassHierarchy(); + for (NamedClass nc1 : copy.elementSet()) { + for (NamedClass nc2 : copy.elementSet()) { + if(!nc1.equals(nc2)){ + //remove class nc1 if it is superclass of another class nc2 + if(hierarchy.isSubclassOf(nc2, nc1)){ + classes.remove(nc1, classes.count(nc1)); + break; + } + } + } + } + } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-06-06 13:32:30 UTC (rev 3985) @@ -73,12 +73,7 @@ private String sparql = ""; private Stack<String> variables = new Stack<String>(); - private Map<OWLEntity, String> variablesMapping = new HashMap<OWLEntity, String>(); - private int classCnt = 0; - private int propCnt = 0; - private int indCnt = 0; - private OWLDataFactory df = new OWLDataFactoryImpl(); private Multimap<Integer, OWLEntity> properties = HashMultimap.create(); @@ -86,8 +81,19 @@ private Map<Integer, Boolean> intersection; private Set<? extends OWLEntity> variableEntities = new HashSet<OWLEntity>(); + private VariablesMapping mapping; + + public OWLClassExpressionToSPARQLConverter(VariablesMapping mapping) { + this.mapping = mapping; + } + public OWLClassExpressionToSPARQLConverter() { + mapping = new VariablesMapping(); } + + public VariablesMapping getVariablesMapping() { + return mapping; + } public String convert(String rootVariable, OWLClassExpression expr){ reset(); @@ -132,7 +138,7 @@ queryString += rootVariable + " WHERE {"; } else { for (OWLEntity owlEntity : variableEntities) { - String var = variablesMapping.get(owlEntity); + String var = mapping.get(owlEntity); queryString += var + " "; } if(count){ @@ -149,7 +155,7 @@ if(count){ queryString += "GROUP BY "; for (OWLEntity owlEntity : variableEntities) { - String var = variablesMapping.get(owlEntity); + String var = mapping.get(owlEntity); queryString += var; } queryString += " ORDER BY DESC(?cnt)"; @@ -158,40 +164,14 @@ return QueryFactory.create(queryString, Syntax.syntaxARQ); } - public Map<OWLEntity, String> getVariablesMapping() { - return variablesMapping; - } - private void reset(){ - variablesMapping.clear(); variables.clear(); properties.clear(); - classCnt = 0; - propCnt = 0; - indCnt = 0; sparql = ""; intersection = new HashMap<Integer, Boolean>(); + mapping.reset(); } - private String getVariable(OWLEntity entity){ - String var = variablesMapping.get(entity); - if(var == null){ - if(entity.isOWLClass()){ - var = "?cls" + classCnt++; - } else if(entity.isOWLObjectProperty() || entity.isOWLDataProperty()){ - var = "?p" + propCnt++; - } else if(entity.isOWLNamedIndividual()){ - var = buildIndividualVariable(); - } - variablesMapping.put(entity, var); - } - return var; - } - - private String buildIndividualVariable(){ - return "?s" + indCnt++; - } - private int modalDepth(){ return variables.size(); } @@ -253,7 +233,7 @@ private String render(OWLEntity entity){ String s; if(variableEntities.contains(entity)){ - s = getVariable(entity); + s = mapping.getVariable(entity); } else { s = "<" + entity.toStringID() + ">"; } @@ -295,8 +275,8 @@ if(props.size() > 1){ Collection<String> vars = new TreeSet<String>(); for (OWLEntity p : props) { - if(variablesMapping.containsKey(p)){ - vars.add(variablesMapping.get(p)); + if(mapping.containsKey(p)){ + vars.add(mapping.get(p)); } } if(vars.size() == 2){ @@ -334,7 +314,7 @@ @Override public void visit(OWLObjectSomeValuesFrom ce) { - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLObjectPropertyExpression propertyExpression = ce.getProperty(); if(propertyExpression.isAnonymous()){ //property expression is inverse of a property @@ -356,7 +336,7 @@ @Override public void visit(OWLObjectAllValuesFrom ce) { String subject = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLObjectPropertyExpression propertyExpression = ce.getProperty(); OWLObjectProperty predicate = propertyExpression.getNamedProperty(); OWLClassExpression filler = ce.getFiller(); @@ -367,7 +347,7 @@ sparql += triple(variables.peek(), predicate, objectVariable); } - String var = buildIndividualVariable(); + String var = mapping.newIndividualVariable(); sparql += "{SELECT " + subject + " (COUNT(" + var + ") AS ?cnt1) WHERE {"; sparql += triple(subject, predicate, var); variables.push(var); @@ -375,7 +355,7 @@ variables.pop(); sparql += "} GROUP BY " + subject + "}"; - var = buildIndividualVariable(); + var = mapping.newIndividualVariable(); sparql += "{SELECT " + subject + " (COUNT(" + var + ") AS ?cnt2) WHERE {"; sparql += triple(subject, predicate, var); sparql += "} GROUP BY " + subject + "}"; @@ -399,7 +379,7 @@ @Override public void visit(OWLObjectMinCardinality ce) { String subjectVariable = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLObjectPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; @@ -411,7 +391,7 @@ } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ - String var = buildIndividualVariable(); + String var = mapping.newIndividualVariable(); variables.push(var); sparql += triple(objectVariable, "a", var); filler.accept(this); @@ -427,7 +407,7 @@ @Override public void visit(OWLObjectExactCardinality ce) { String subjectVariable = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLObjectPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; @@ -439,7 +419,7 @@ } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ - String var = buildIndividualVariable(); + String var = mapping.newIndividualVariable(); variables.push(var); sparql += triple(objectVariable, "a", var); filler.accept(this); @@ -454,7 +434,7 @@ @Override public void visit(OWLObjectMaxCardinality ce) { String subjectVariable = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLObjectPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; @@ -466,7 +446,7 @@ } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ - String var = buildIndividualVariable(); + String var = mapping.newIndividualVariable(); variables.push(var); sparql += triple(objectVariable, "a", var); filler.accept(this); @@ -506,7 +486,7 @@ @Override public void visit(OWLDataSomeValuesFrom ce) { - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLDataPropertyExpression propertyExpression = ce.getProperty(); sparql += triple(variables.peek(), propertyExpression.asOWLDataProperty(), objectVariable); OWLDataRange filler = ce.getFiller(); @@ -518,13 +498,13 @@ @Override public void visit(OWLDataAllValuesFrom ce) { String subject = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLDataPropertyExpression propertyExpression = ce.getProperty(); String predicate = propertyExpression.asOWLDataProperty().toStringID(); OWLDataRange filler = ce.getFiller(); sparql += triple(variables.peek(), predicate, objectVariable); - String var = buildIndividualVariable(); + String var = mapping.newIndividualVariable(); sparql += "{SELECT " + subject + " (COUNT(" + var + ") AS ?cnt1) WHERE {"; sparql += triple(subject, predicate, var); variables.push(var); @@ -532,7 +512,7 @@ variables.pop(); sparql += "} GROUP BY " + subject + "}"; - var = buildIndividualVariable(); + var = mapping.newIndividualVariable(); sparql += "{SELECT " + subject + " (COUNT(" + var + ") AS ?cnt2) WHERE {"; sparql += triple(subject, predicate, var); sparql += "} GROUP BY " + subject + "}"; @@ -550,7 +530,7 @@ @Override public void visit(OWLDataMinCardinality ce) { String subjectVariable = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLDataPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; @@ -566,7 +546,7 @@ @Override public void visit(OWLDataExactCardinality ce) { String subjectVariable = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLDataPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; @@ -582,7 +562,7 @@ @Override public void visit(OWLDataMaxCardinality ce) { String subjectVariable = variables.peek(); - String objectVariable = buildIndividualVariable(); + String objectVariable = mapping.newIndividualVariable(); OWLDataPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; @@ -774,7 +754,4 @@ System.out.println(expr + "\n" + query); } - - - } \ No newline at end of file Modified: trunk/components-core/src/main/resources/prefixes.csv =================================================================== --- trunk/components-core/src/main/resources/prefixes.csv 2013-05-24 09:16:41 UTC (rev 3984) +++ trunk/components-core/src/main/resources/prefixes.csv 2013-06-06 13:32:30 UTC (rev 3985) @@ -4,609 +4,963 @@ dbp,http://dbpedia.org/property/ owl,http://www.w3.org/2002/07/owl# dc,http://purl.org/dc/elements/1.1/ +rdfs,http://www.w3.org/2000/01/rdf-schema# dbo,http://dbpedia.org/ontology/ -rdfs,http://www.w3.org/2000/01/rdf-schema# -sc,http://umbel.org/umbel/sc/ rss,http://purl.org/rss/1.0/ +sc,http://purl.org/science/owl/sciencecommons/ +skos,http://www.w3.org/2004/02/skos/core# fb,http://rdf.freebase.com/ns/ geonames,http://www.geonames.org/ontology# -skos,http://www.w3.org/2004/02/skos/core# -cyc,http://sw.opencyc.org/concept/ geo,http://www.w3.org/2003/01/geo/wgs84_pos# sioc,http://rdfs.org/sioc/ns# +gr,http://purl.org/goodrelations/v1# +gldp,http://www.w3.org/ns/people# +cyc,http://sw.opencyc.org/concept/ akt,http://www.aktors.org/ontology/portal# +xsd,http://www.w3.org/2001/XMLSchema# dbpedia,http://dbpedia.org/resource/ +dcterms,http://purl.org/dc/terms/ +swrc,http://swrc.ontoware.org/ontology# +commerce,http://search.yahoo.com/searchmonkey/commerce/ admin,http://webns.net/mvcb/ -gr,http://purl.org/goodrelations/v1# -swrc,http://swrc.ontoware.org/ontology# -xsd,http://www.w3.org/2001/XMLSchema# -xhtml,http://www.w3.org/1999/xhtml/vocab# +content,http://purl.org/rss/1.0/modules/content/ doap,http://usefulinc.com/ns/doap# +void,http://rdfs.org/ns/void# +xhtml,http://www.w3.org/1999/xhtml# +bibo,http://purl.org/ontology/bibo/ +org,http://www.w3.org/ns/org# vcard,http://www.w3.org/2006/vcard/ns# -content,http://purl.org/rss/1.0/modules/content/ +gen,http://www.w3.org/2006/gen/ont# bill,http://www.rdfabout.com/rdf/schema/usbill/ -dcterms,http://purl.org/dc/terms/ -mo,http://purl.org/ontology/mo/ +aiiso,http://purl.org/vocab/aiiso/schema# wot,http://xmlns.com/wot/0.1/ -wn20schema,http://www.w3.org/2006/03/wn/wn20/schema/ -d2rq,http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1# -gen,http://www.w3.org/2006/gen/ont# +qb,http://purl.org/linked-data/cube# nie,http://www.semanticdesktop.org/ontologies/2007/01/19/nie# -void,http://rdfs.org/ns/void# test2,http://this.invalid/test2# -org,http://www.w3.org/ns/org# -movie,http://data.linkedmdb.org/resource/movie/ -ex,http://example.com/ +d2rq,http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1# rel,http://purl.org/vocab/relationship/ -bio,http://purl.org/vocab/bio/0.1/ +dcmit,http://purl.org/dc/dcmitype/ http,http://www.w3.org/2006/http# -dcmit,http://purl.org/dc/dcmitype/ -reco,http://purl.org/reco# cc,http://creativecommons.org/ns# -nfo,http://www.semanticdesktop.org/ontologies/2007/03/22/nfo# -ac,http://umbel.org/umbel/ac/ -xfn,http://vocab.sindice.com/xfn# +og,http://opengraphprotocol.org/schema/ +factbook,http://www4.wiwiss.fu-berlin.de/factbook/ns# +vann,http://purl.org/vocab/vann/ +ex,http://example.com/ +bio,http://purl.org/vocab/bio/0.1/ +mo,http://purl.org/ontology/mo/ +ad,http://schemas.talis.com/2005/address/schema# +media,http://purl.org/microformat/hmedia/ +event,http://purl.org/NET/c4dm/event.owl# earl,http://www.w3.org/ns/earl# -og,http://opengraphprotocol.org/schema/ +book,http://purl.org/NET/book/vocab# +cv,http://purl.org/captsolo/resume-rdf/0.2/cv# +ical,http://www.w3.org/2002/12/cal/ical# +botany,http://purl.org/NET/biol/botany# air,http://dig.csail.mit.edu/TAMI/2007/amord/air# -ical,http://www.w3.org/2002/12/cal/ical# -media,http://purl.org/media# -rev,http://purl.org/stuff/rev# -cv,http://rdfs.org/resume-rdf/ tag,http://www.holygoat.co.uk/owl/redwood/0.1/tags/ +dv,http://rdf.data-vocabulary.org/# +cld,http://purl.org/cld/terms/ swc,http://data.semanticweb.org/ns/swc/ontology# -botany,http://purl.org/NET/biol/botany# -bibo,http://purl.org/ontology/bibo/ -xf,http://www.w3.org/2002/xforms/ -factbook,http://www4.wiwiss.fu-berlin.de/factbook/ns# +drugbank,http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/ +musim,http://purl.org/ontology/similarity/ +dir,http://schemas.talis.com/2005/dir/schema# +reco,http://purl.org/reco# +rev,http://purl.org/stuff/rev# +biblio,http://purl.org/net/biblio# +ctag,http://commontag.org/ns# +af,http://purl.org/ontology/af/ days,http://ontologi.es/days# -cfp,http://sw.deri.org/2005/08/conf/cfp.owl# -sism,http://purl.oclc.org/NET/sism/0.1/ -vann,http://purl.org/vocab/vann/ +log,http://www.w3.org/2000/10/swap/log# +cs,http://purl.org/vocab/changeset/schema# +sd,http://www.w3.org/ns/sparql-service-description# osag,http://www.ordnancesurvey.co.uk/ontology/AdministrativeGeography/v2.0/AdministrativeGeography.rdf# -owlim,http://www.ontotext.com/trree/owlim# -dir,http://schemas.talis.com/2005/dir/schema# -cld,http://purl.org/cld/terms/ -afn,http://jena.hpl.hp.com/ARQ/function# -book,http://purl.org/NET/book/vocab# +xhv,http://www.w3.org/1999/xhtml/vocab# +rdfg,http://www.w3.org/2004/03/trix/rdfg-1/ +co,http://purl.org/ontology/co/core# fn,http://www.w3.org/2005/xpath-functions# -musim,http://purl.org/ontology/similarity/ -akts,http://www.aktors.org/ontology/support# -cs,http://purl.org/vocab/changeset/schema# -aiiso,http://purl.org/vocab/aiiso/schema# -ad,http://schemas.talis.com/2005/address/schema# +sism,http://purl.oclc.org/NET/sism/0.1/ mu,http://www.kanzaki.com/ns/music# -sd,http://www.w3.org/ns/sparql-service-description# -po,http://purl.org/ontology/po/ -biblio,http://purl.org/net/biblio# -event,http://purl.org/NET/c4dm/event.owl# -dv,http://rdf.data-vocabulary.org/# -drugbank,http://www4.wiwiss.fu-berlin.de/drugbank/resource/drugbank/ -uniprot,http://purl.uniprot.org/core/ memo,http://ontologies.smile.deri.ie/2009/02/27/memo# -dcn,http://www.w3.org/2007/uwa/context/deliverycontext.owl# -rdfg,http://www.w3.org/2004/03/trix/rdfg-1/ -log,http://www.w3.org/2000/10/swap/log# -co,http://purl.org/ontology/co/core# -qb,http://purl.org/linked-data/cube# ome,http://purl.org/ontomedia/core/expression# -af,http://purl.org/ontology/af/ +daia,http://purl.org/ontology/daia/ +cmp,http://www.ontologydesignpatterns.org/cp/owl/componency.owl# +owlim,http://www.ontotext.com/trree/owlim# +cfp,http://sw.deri.org/2005/08/conf/cfp.owl# +xfn,http://vocab.sindice.com/xfn# +afn,http://jena.hpl.hp.com/ARQ/function# +ok,http://okkam.org/terms# giving,http://ontologi.es/giving# +ir,http://www.ontologydesignpatterns.org/cp/owl/informationrealization.owl# +xf,http://www.w3.org/2002/xforms/ +dcn,http://www.w3.org/2007/uwa/context/deliverycontext.owl# swanq,http://purl.org/swan/1.2/qualifiers/ -cmp,http://www.ontologydesignpatterns.org/cp/owl/componency.owl# lomvoc,http://ltsc.ieee.org/rdf/lomv1p0/vocabulary# +math,http://www.w3.org/2000/10/swap/math# +swande,http://purl.org/swan/1.2/discourse-elements/ rif,http://www.w3.org/2007/rif# -ir,http://www.ontologydesignpatterns.org/cp/owl/informationrealization.owl# -ctag,http://commontag.org/ns# -ok,http://okkam.org/terms# -swande,http://purl.org/swan/1.2/discourse-elements/ -math,http://www.w3.org/2000/10/swap/math# -daia,http://purl.org/ontology/daia/ -sioct,http://rdfs.org/sioc/types# +sr,http://www.openrdf.org/config/repository/sail# jdbc,http://d2rq.org/terms/jdbc/ +tzont,http://www.w3.org/2006/timezone# myspace,http://purl.org/ontology/myspace# -sr,http://www.openrdf.org/config/repository/sail# -tzont,http://www.w3.org/2006/timezone# +con,http://www.w3.org/2000/10/swap/pim/contact# +sider,http://www4.wiwiss.fu-berlin.de/sider/resource/sider/ +wn20schema,http://www.w3.org/2006/03/wn/wn20/schema/ +cert,http://www.w3.org/ns/auth/cert# +pto,http://www.productontology.org/id/ +movie,http://data.linkedmdb.org/resource/movie/ +oo,http://purl.org/openorg/ +nfo,http://www.semanticdesktop.org/ontologies/nfo/# +ac,http://umbel.org/umbel/ac/ +po,http://purl.org/ontology/po/ +akts,http://www.aktors.org/ontology/support# +frbr,http://purl.org/vocab/frbr/core# +uniprot,http://purl.uniprot.org/core/ +dcat,http://www.w3.org/ns/dcat# +rsa,http://www.w3.org/ns/auth/rsa# +ov,http://open.vocab.org/terms/ +sioct,http://rdfs.org/sioc/types# +prv,http://purl.org/net/provenance/ns# +prov,http://www.w3.org/ns/prov# +granatum,http://chem.deri.ie/granatum/ +wo,http://purl.org/ontology/wo/ daml,http://www.daml.org/2001/03/daml+oil# -wo,http://purl.org/ontology/wo/ -politico,http://www.rdfabout.com/rdf/schema/politico/ +spacerel,http://data.ordnancesurvey.co.uk/ontology/spatialrelations/ +pc,http://purl.org/procurement/public-contracts# pmlj,http://inference-web.org/2.0/pml-justification.owl# +vs,http://www.w3.org/2003/06/sw-vocab-status/ns# usgov,http://www.rdfabout.com/rdf/schema/usgovt/ +acm,http://www.rkbexplorer.com/ontologies/acm# taxo,http://purl.org/rss/1.0/modules/taxonomy/ -lfm,http://purl.org/ontology/last-fm/ -vote,http://www.rdfabout.com/rdf/schema/vote/ -frbr,http://purl.org/vocab/frbr/core# -doac,http://ramonantonio.net/doac/0.1/# wn,http://xmlns.com/wordnet/1.6/ -affy,http://www.affymetrix.com/community/publications/affymetrix/tmsplice# -con,http://www.w3.org/2000/10/swap/pim/contact# -prv,http://purl.org/net/provenance/ns# -scot,http://scot-project.org/scot/ns# -irrl,http://www.ontologydesignpatterns.org/cp/owl/informationobjectsandrepresentationlanguages.owl# +wdrs,http://www.w3.org/2007/05/powder-s# scovo,http://purl.org/NET/scovo# -nco,http://www.semanticdesktop.org/ontologies/2007/03/22/nco# +oauth,http://demiblog.org/vocab/oauth# +politico,http://www.rdfabout.com/rdf/schema/politico/ lgd,http://linkedgeodata.org/ontology/ -wordmap,http://purl.org/net/ns/wordmap# +lode,http://linkedevents.org/ontology/ +acl,http://www.w3.org/ns/auth/acl# +ore,http://www.openarchives.org/ore/terms/ +abc,http://www.metadata.net/harmony/ABCSchemaV5Commented.rdf# omt,http://purl.org/ontomedia/ext/common/trait# -sider,http://www4.wiwiss.fu-berlin.de/sider/resource/sider/ +nao,http://www.semanticdesktop.org/ontologies/2007/08/15/nao# +omb,http://purl.org/ontomedia/ext/common/being# +loc,http://www.w3.org/2007/uwa/context/location.owl# +mit,http://purl.org/ontology/mo/mit# +skosxl,http://www.w3.org/2008/05/skos-xl# +spc,http://purl.org/ontomedia/core/space# +vote,http://www.rdfabout.com/rdf/schema/vote/ +lfm,http://purl.org/ontology/last-fm/ +irrl,http://www.ontologydesignpatterns.org/cp/owl/informationobjectsandrepresentationlanguages.owl# +rep,http://www.openrdf.org/config/repository# +chord,http://purl.org/ontology/chord/ +dcam,http://purl.org/dc/dcam/ user,http://schemas.talis.com/2005/user/schema# -ore,http://www.openarchives.org/ore/terms/ -lode,http://linkedevents.org/ontology/ -ecs,http://rdf.ecs.soton.ac.uk/ontology/ecs# -rep,http://www.openrdf.org/config/repository# -nao,http://www.semanticdesktop.org/ontologies/2007/08/15/nao# -spin,http://spinrdf.org/spin# +resex,http://resex.rkbexplorer.com/ontologies/resex# swrl,http://www.w3.org/2003/11/swrl# -lx,http://purl.org/NET/lx# +music,http://musicontology.com/ +doac,http://ramonantonio.net/doac/0.1/# +scot,http://scot-project.org/scot/ns# +irw,http://www.ontologydesignpatterns.org/ont/web/irw.owl# ti,http://www.ontologydesignpatterns.org/cp/owl/timeinterval.owl# -unit,http://qudt.org/vocab/unit# -spc,http://purl.org/ontomedia/core/space# -es,http://eulersharp.sourceforge.net/2003/03swap/log-rules# -zoology,http://purl.org/NET/biol/zoology# -swrlb,http://www.w3.org/2003/11/swrlb# +affy,http://www.affymetrix.com/community/publications/affymetrix/tmsplice# +lingvoj,http://www.lingvoj.org/ontology# +courseware,http://courseware.rkbexplorer.com/ontologies/courseware# +link,http://www.w3.org/2006/link# +video,http://purl.org/media/video# +tl,http://purl.org/NET/c4dm/timeline.owl# +nco,http://www.semanticdesktop.org/ontologies/2007/03/22/nco# fec,http://www.rdfabout.com/rdf/schema/usfec/ -lang,http://ontologi.es/lang/core# -coref,http://www.rkbexplorer.com/ontologies/coref# -doc,http://www.w3.org/2000/10/swap/pim/doc# -os,http://www.w3.org/2000/10/swap/os# -atomix,http://buzzword.org.uk/rdf/atomix# -ne,http://umbel.org/umbel/ne/ -omb,http://purl.org/ontomedia/ext/common/being# money,http://purl.org/net/rdf-money/ -hard,http://www.w3.org/2007/uwa/context/hardware.owl# -ov,http://open.vocab.org/terms/ -java,http://www.w3.org/2007/uwa/context/java.owl# -eztag,http://ontologies.ezweb.morfeo-project.org/eztag/ns# -abc,http://www.metadata.net/harmony/ABCSchemaV5Commented.rdf# -tmo,http://www.semanticdesktop.org/ontologies/2008/05/20/tmo# -vs,http://www.w3.org/2003/06/sw-vocab-status/ns# sede,http://eventography.org/sede/0.1/ +rec,http://purl.org/ontology/rec/core# +atom,http://www.w3.org/2005/Atom/ +atomix,http://buzzword.org.uk/rdf/atomix# +sit,http://www.ontologydesignpatterns.org/cp/owl/situation.owl# +powder,http://www.w3.org/2007/05/powder# +fresnel,http://www.w3.org/2004/09/fresnel# +rei,http://www.w3.org/2004/06/rei# +doc,http://www.w3.org/2000/10/swap/pim/doc# +coref,http://www.rkbexplorer.com/ontologies/coref# nrl,http://www.semanticdesktop.org/ontologies/2007/08/15/nrl# -ibis,http://purl.org/ibis# +spin,http://spinrdf.org/spin# +umbel,http://umbel.org/umbel# code,http://telegraphis.net/ontology/measurement/code# -omp,http://purl.org/ontomedia/ext/common/profession# -dcam,http://purl.org/dc/dcam/ +zoology,http://purl.org/NET/biol/zoology# +wordmap,http://purl.org/net/ns/wordmap# +lotico,http://www.lotico.com/resource/ +audio,http://purl.org/media/audio# +meta,http://www.openrdf.org/rdf/2009/metadata# +protege,http://protege.stanford.edu/system# +time,http://www.w3.org/2006/time# +sv,http://schemas.talis.com/2005/service/schema# +ya,http://blogs.yandex.ru/schema/foaf/ +bio2rdf,http://bio2rdf.org/ +biol,http://purl.org/NET/biol/ns# imm,http://schemas.microsoft.com/imm/ -xhe,http://buzzword.org.uk/rdf/xhtml-elements# +sp,http://spinrdf.org/sp# +exif,http://www.w3.org/2003/12/exif/ns# +swrlb,http://www.w3.org/2003/11/swrlb# +iswc,http://annotation.semanticweb.org/2004/iswc# +ecs,http://rdf.ecs.soton.ac.uk/ontology/ecs# +p3p,http://www.w3.org/2002/01/p3prdfv1# kwijibo,http://kwijibo.talis.com/ -sv,http://schemas.talis.com/2005/service/schema# -h5,http://buzzword.org.uk/rdf/h5# -space,http://purl.org/net/schemas/space/ -wdrs,http://www.w3.org/2007/05/powder-s# -video,http://purl.org/media/video# -wnschema,http://www.cogsci.princeton.edu/~wn/schema/ +eztag,http://ontologies.ezweb.morfeo-project.org/eztag/ns# +so,http://purl.org/ontology/symbolic-music/ +lang,http://ontologi.es/lang/core# +tmo,http://www.semanticdesktop.org/ontologies/2008/05/20/tmo# +airport,http://www.daml.org/2001/10/html/airport-ont# +java,http://www.w3.org/2007/uwa/context/java.owl# +acc,http://purl.org/NET/acc# +os,http://www.w3.org/2000/10/swap/os# +ne,http://umbel.org/umbel/ne/ +omp,http://purl.org/ontomedia/ext/common/profession# +lx,http://purl.org/NET/lx# +doclist,http://www.junkwork.net/xml/DocumentList# +lifecycle,http://purl.org/vocab/lifecycle/schema# +omc,http://purl.org/ontomedia/ext/common/bestiary# +dailymed,http://www4.wiwiss.fu-berlin.de/dailymed/resource/dailymed/ +ibis,http://purl.org/ibis# sail,http://www.openrdf.org/config/sail# -custom,http://www.openrdf.org/config/sail/custom# -acc,http://purl.org/NET/acc# -rsa,http://www.w3.org/ns/auth/rsa# -sit,http://www.ontologydesignpatterns.org/cp/owl/situation.owl# -wdr,http://www.w3.org/2007/05/powder# -airport,http://www.daml.org/2001/10/html/airport-ont# -rei,http://www.w3.org/2004/06/rei# -mit,http://purl.org/ontology/mo/mit# -phss,http://ns.poundhill.com/phss/1.0/ -ncal,http://www.semanticdesktop.org/ontologies/2007/04/02/ncal# osoc,http://web-semantics.org/ns/opensocial# +hard,http://www.w3.org/2007/uwa/context/hardware.owl# +grddl,http://www.w3.org/2003/g/data-view# ptr,http://www.w3.org/2009/pointers# -protege,http://protege.stanford.edu/system# -irw,http://www.ontologydesignpatterns.org/ont/web/irw.owl# -omc,http://purl.org/ontomedia/ext/common/bestiary# -tdb,http://jena.hpl.hp.com/2008/tdb# -meta,http://www.openrdf.org/rdf/2009/metadata# -iswc,http://annotation.semanticweb.org/2004/iswc# -lingvoj,http://www.lingvoj.org/ontology# -resex,http://resex.rkbexplorer.com/ontologies/resex# -chord,http://purl.org/ontology/chord/ -p3p,http://www.w3.org/2002/01/p3prdfv1# -oauth,http://demiblog.org/vocab/oauth# -acl,http://www.w3.org/ns/auth/acl# -tl,http://purl.org/NET/c4dm/timeline.owl# -xen,http://buzzword.org.uk/rdf/xen# -acm,http://www.rkbexplorer.com/ontologies/acm# -link,http://www.w3.org/2006/link# -umbel,http://umbel.org/umbel# -swh,http://plugin.org.uk/swh-plugins/ +spl,http://spinrdf.org/spl# +wnschema,http://www.cogsci.princeton.edu/~wn/schema/ +es,http://eulersharp.sourceforge.net/2003/03swap/log-rules# +unit,http://qudt.org/vocab/unit# +label,http://purl.org/net/vocab/2004/03/label# +moat,http://moat-project.org/ns# +hlisting,http://sindice.com/hlisting/0.1/ +test,http://test2.example.com/ lom,http://ltsc.ieee.org/rdf/lomv1p0/lom# -common,http://www.w3.org/2007/uwa/context/common.owl# -ya,http://blogs.yandex.ru/schema/foaf/ -frbre,http://purl.org/vocab/frbr/extended# +osgb,http://data.ordnancesurvey.co.uk/id/ +custom,http://www.openrdf.org/config/sail/custom# prj,http://purl.org/stuff/project/ +resist,http://www.rkbexplorer.com/ontologies/resist# +pmlp,http://inference-web.org/2.0/pml-provenance.owl# +smiley,http://www.smileyontology.com/ns# +formats,http://www.w3.org/ns/formats/ +h5,http://buzzword.org.uk/rdf/h5# +sdl,http://purl.org/vocab/riro/sdl# +space,http://purl.org/net/schemas/space/ +wv,http://vocab.org/waiver/terms/ +ncal,http://www.semanticdesktop.org/ontologies/2007/04/02/ncal# +ping,http://purl.org/net/pingback/ +list,http://www.w3.org/2000/10/swap/list# +sml,http://topbraid.org/sparqlmotionlib# +phss,http://ns.poundhill.com/phss/1.0/ +omm,http://purl.org/ontomedia/core/media# +meetup,http://www.lotico.com/meetup/ net,http://www.w3.org/2007/uwa/context/network.owl# -hlisting,http://sindice.com/hlisting/0.1/ -sdl,http://purl.org/vocab/riro/sdl# -trackback,http://madskills.com/public/xml/rss/module/trackback/ +qdoslf,http://foaf.qdos.com/lastfm/schema/ +xen,http://buzzword.org.uk/rdf/xen# +tdb,http://jena.hpl.hp.com/2008/tdb# +gold,http://purl.org/linguistics/gold/ nmo,http://www.semanticdesktop.org/ontologies/2007/03/22/nmo# -cert,http://www.w3.org/ns/auth/cert# -spl,http://spinrdf.org/spl# -sp,http://spinrdf.org/sp# -dailymed,http://www4.wiwiss.fu-berlin.de/dailymed/resource/dailymed/ -resist,http://www.rkbexplorer.com/ontologies/resist# +xhe,http://buzzword.org.uk/rdf/xhtml-elements# swp,http://www.w3.org/2004/03/trix/swp-2/ -fresnel,http://www.w3.org/2004/09/fresnel# -lt,http://diplomski.nelakolundzija.org/LTontology.rdf# -wv,http://vocab.org/waiver/terms/ product,http://purl.org/commerce/product# -test,http://test2.example.com/ -gold,http://purl.org/linguistics/gold/ -smiley,http://www.smileyontology.com/ns# +lfn,http://www.dotnetrdf.org/leviathan# +whois,http://www.kanzaki.com/ns/whois# +pr,http://ontologi.es/profiling# +biocore,http://bio2rdf.org/core# +cnt,http://www.w3.org/2008/content# swandr,http://purl.org/swan/1.2/discourse-relationships/ -ddc,http://purl.org/NET/decimalised# -soft,http://www.w3.org/2007/uwa/context/software.owl# +frbre,http://purl.org/vocab/frbr/extended# nexif,http://www.semanticdesktop.org/ontologies/2007/05/10/nexif# -skosxl,http://www.w3.org/2008/05/skos-xl# +sm,http://topbraid.org/sparqlmotion# +fed,http://www.openrdf.org/config/sail/federation# +oat,http://openlinksw.com/schemas/oat/ +c4n,http://vocab.deri.ie/c4n# +smf,http://topbraid.org/sparqlmotionfunctions# +trackback,http://madskills.com/public/xml/rss/module/trackback/ ire,http://www.ontologydesignpatterns.org/cpont/ire.owl# -fed,http://www.openrdf.org/config/sail/federation# -courseware,http://courseware.rkbexplorer.com/ontologies/courseware# -biol,http://purl.org/NET/biol/ns# +opm,http://openprovenance.org/ontology# +common,http://www.w3.org/2007/uwa/context/common.owl# gpt,http://purl.org/vocab/riro/gpt# +soft,http://www.w3.org/2007/uwa/context/software.owl# +bibtex,http://purl.oclc.org/NET/nknouf/ns/bibtex# +climb,http://climb.dataincubator.org/vocabs/climb/ +wisski,http://wiss-ki.eu/ +pmt,http://tipsy.googlecode.com/svn/trunk/vocab/pmt# +opensearch,http://a9.com/-/spec/opensearch/1.1/ +bsbm,http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/ sesame,http://www.openrdf.org/schema/sesame# -time,http://www.w3.org/2006/time# -atom,http://www.w3.org/2005/Atom/ -omm,http://purl.org/ontomedia/core/media# -lotico,http://www.lotico.com/resource/ +swh,http://plugin.org.uk/swh-plugins/ +mysql,http://web-semantics.org/ns/mysql/ +nid3,http://www.semanticdesktop.org/ontologies/2007/05/10/nid3# +lt,http://diplomski.nelakolundzija.org/LTontology.rdf# web,http://www.w3.org/2007/uwa/context/web.owl# -sm,http://topbraid.org/sparqlmotion# +like,http://ontologi.es/like# states,http://www.w3.org/2005/07/aaa# -moat,http://moat-project.org/ns# -pimo,http://www.semanticdesktop.org/ontologies/2007/11/01/pimo# -push,http://www.w3.org/2007/uwa/context/push.owl# -bio2rdf,http://bio2rdf.org/ -bsbm,http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/ -bibtex,http://purl.oclc.org/NET/nknouf/ns/bibtex# -music,http://musicontology.com/ +ddc,http://purl.org/NET/decimalised# +imreg,http://www.w3.org/2004/02/image-regions# +ddl,http://purl.org/vocab/riro/ddl# +cycann,http://sw.cyc.com/CycAnnotations_v1# dummy,http://hello.com/ -am,http://vocab.deri.ie/am# -wairole,http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy# -pmt,http://tipsy.googlecode.com/svn/trunk/vocab/pmt# -loc,http://www.w3.org/2007/uwa/context/location.owl# -doclist,http://www.junkwork.net/xml/DocumentList# -pmlr,http://inference-web.org/2.0/pml-relation.owl# -ddl,http://purl.org/vocab/riro/ddl# -audio,http://purl.org/media/audio# -qdoslf,http://foaf.qdos.com/lastfm/schema/ -uri,http://purl.org/NET/uri# +obj,http://www.openrdf.org/rdf/2009/object# +resource,http://purl.org/vocab/resourcelist/schema# +compass,http://purl.org/net/compass# +swanag,http://purl.org/swan/1.2/agents/ crypto,http://www.w3.org/2000/10/swap/crypto# -like,http://ontologi.es/like# -lfn,http://www.dotnetrdf.org/leviathan# +push,http://www.w3.org/2007/uwa/context/push.owl# +puc,http://purl.org/NET/puc# +rdfa,http://www.w3.org/ns/rdfa# xl,http://langegger.at/xlwrap/vocab# +xhtmlvocab,http://www.w3.org/1999/xhtml/vocab/ dady,http://purl.org/NET/dady# -sl,http://www.semanlink.net/2001/00/semanlink-schema# -wisski,http://wiss-ki.eu/ -pr,http://ontologi.es/profiling# -climb,http://climb.dataincubator.org/vocabs/climb/ +pmlr,http://inference-web.org/2.0/pml-relation.owl# +psych,http://purl.org/vocab/psychometric-profile/ +pimo,http://www.semanticdesktop.org/ontologies/2007/11/01/pimo# +string,http://www.w3.org/2000/10/swap/string# +urn,http://fliqz.com/ +coin,http://purl.org/court/def/2009/coin# +plink,http://buzzword.org.uk/rdf/personal-link-types# conserv,http://conserv.deri.ie/ontology# -sml,http://topbraid.org/sparqlmotionlib# -dcat,http://www.w3.org/ns/dcat# -formats,http://www.w3.org/ns/formats/ -label,http://purl.org/net/vocab/2004/03/label# -puc,http://purl.org/NET/puc# -list,http://www.w3.org/2000/10/swap/list# -lifecycle,http://purl.org/vocab/lifecycle/schema# -swanpav,http://purl.org/swan/1.2/pav/ -smf,http://topbraid.org/sparqlmotionfunctions# -grddl,http://www.w3.org/2003/g/data-view# -pmlp,http://inference-web.org/2.0/pml-provenance.owl# -opm,http://openprovenance.org/ontology# -cycann,http://sw.cyc.com/CycAnnotations_v1# -obj,http://www.openrdf.org/rdf/2009/object# -urn,http://fliqz.com/ +rooms,http://vocab.deri.ie/rooms# +cco,http://purl.org/ontology/cco/core# +xesam,http://freedesktop.org/standards/xesam/1.0/core# +am,http://vocab.deri.ie/am# play,http://uriplay.org/spec/ontology/# -ping,http://purl.org/net/pingback/ -c4n,http://vocab.deri.ie/c4n# -mysql,http://web-semantics.org/ns/mysql/ -rdfa,http://www.w3.org/ns/rdfa# -osgb,http://data.ordnancesurvey.co.uk/id/ -resource,http://purl.org/vocab/resourcelist/schema# -xesam,http://freedesktop.org/standards/xesam/1.0/core# -plink,http://buzzword.org.uk/rdf/personal-link-types# -so,http://purl.org/ontology/symbolic-music/ -commerce,http://purl.org/commerce# -opensearch,http://a9.com/-/spec/opensearch/1.1/ -exif,http://www.w3.org/2003/12/exif/ns# -psych,http://purl.org/vocab/psychometric-profile/ evset,http://dsnotify.org/vocab/eventset/0.1/ +mf,http://poshrdf.org/ns/mf# +geographis,http://telegraphis.net/ontology/geography/geography# sysont,http://ns.ontowiki.net/SysOnt/ -ldap,http://purl.org/net/ldap/ -string,http://www.w3.org/2000/10/swap/string# -swanag,http://purl.org/swan/1.2/agents/ -nid3,http://www.semanticdesktop.org/ontologies/2007/05/10/nid3# +sl,http://www.semanlink.net/2001/00/semanlink-schema# +uri,http://purl.org/NET/uri# +wairole,http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy# ttl,http://www.w3.org/2008/turtle# +swanpav,http://purl.org/swan/1.2/pav/ +bib,http://zeitkunst.org/bibtex/0.1/bibtex.owl# +tripfs,http://purl.org/tripfs/2010/02# swanco,http://purl.org/swan/1.2/swan-commons/ -tripfs,http://purl.org/tripfs/2010/02# -imreg,http://www.w3.org/2004/02/image-regions# -swanci,http://purl.org/swan/1.2/citations/ -meetup,http://www.lotico.com/meetup/ -cnt,http://www.w3.org/2008/content# +opo,http://online-presence.net/opo/ns# okkam,http://models.okkam.org/ENS-core-vocabulary# -mf,http://poshrdf.org/ns/mf# -rec,http://purl.org/ontology/rec/core# -xhtmlvocab,http://www.w3.org/1999/xhtml/vocab/ -coin,http://purl.org/court/def/2009/coin# -geographis,http://telegraphis.net/ontology/geography/geography# -opo,http://online-presence.net/opo/ns# +game,http://data.totl.net/game/ swivt,http://semantic-mediawiki.org/swivt/1.0# -rooms,http://vocab.deri.ie/rooms# -oat,http://openlinksw.com/schemas/oat/ -bib,http://zeitkunst.org/bibtex/0.1/bibtex.owl# +status,http://ontologi.es/status# +swanci,http://purl.org/swan/1.2/citations/ +olo,http://purl.org/ontology/olo/core# +txn,http://lod.taxonconcept.org/ontology/txn.owl# oc,http://opencoinage.org/rdf/ -status,http://ontologi.es/status# ezcontext,http://ontologies.ezweb.morfeo-project.org/ezcontext/ns# -swid,http://semanticweb.org/id/ -pmlt,http://inference-web.org/2.0/pml-trust.owl# +geoes,http://geo.linkeddata.es/ontology/ +xtypes,http://purl.org/xtypes/ +meteo,http://purl.org/ns/meteo# sparql,http://www.openrdf.org/config/repository/sparql# -txn,http://lod.taxonconcept.org/ontology/txn.owl# -oo,http://purl.org/openorg/ -ct,http://data.linkedct.org/resource/linkedct/ -wlp,http://weblab-project.org/core/model/property/processing/ -ufmedia,http://purl.org/microformat/hmedia/ -sioca,http://rdfs.org/sioc/actions# awol,http://bblfish.net/work/atom-owl/2006-06-06/# -pdo,http://ontologies.smile.deri.ie/pdo# -pto,http://www.productontology.org/id/ +evopat,http://ns.aksw.org/Evolution/ +sdmx,http://purl.org/linked-data/sdmx# +ldap,http://purl.org/net/ldap/ +isq,http://purl.org/ontology/is/quality/ +lark1,http://users.utcluj.ro/~raluca/ontology/Ontology1279614123500.owl# aifb,http://www.aifb.kit.edu/id/ -prot,http://www.proteinontology.info/po.owl# -evopat,http://ns.aksw.org/Evolution/ -meteo,http://purl.org/ns/meteo# +isi,http://purl.org/ontology/is/inst/ +ao,http://purl.org/ontology/ao/core# +wlp,http://weblab-project.org/core/model/property/processing/ +ct,http://data.linkedct.org/resource/linkedct/ tarot,http://data.totl.net/tarot/card/ +anca,http://users.utcluj.ro/~raluca/rdf_ontologies_ralu/ralu_modified_ontology_pizzas2_0# +kb,http://deductions.sf.net/ontology/knowledge_base.owl# +opmv,http://purl.org/net/opmv/ns# +pmlt,http://inference-web.org/2.0/pml-trust.owl# +xbrli,http://www.xbrl.org/2003/instance# ist,http://purl.org/ontology/is/types/ -anca,http://users.utcluj.ro/~raluca/rdf_ontologies_ralu/ralu_modified_ontology_pizzas2_0# -whois,http://www.kanzaki.com/ns/whois# +xro,http://purl.org/xro/ns# +postcode,http://data.ordnancesurvey.co.uk/id/postcodeunit/ +dayta,http://dayta.me/resource# +swid,http://semanticweb.org/id/ +prot,http://www.proteinontology.info/po.owl# +opus,http://lsdis.cs.uga.edu/projects/semdis/opus# +core,http://vivoweb.org/ontology/core# +geospecies,http://rdf.geospecies.org/ont/geospecies# +go,http://www.geneontology.org/go# sawsdl,http://www.w3.org/ns/sawsdl# +pdo,http://ontologies.smil... [truncated message content] |
From: <lor...@us...> - 2013-05-24 09:16:44
|
Revision: 3984 http://sourceforge.net/p/dl-learner/code/3984 Author: lorenz_b Date: 2013-05-24 09:16:41 +0000 (Fri, 24 May 2013) Log Message: ----------- Prepare reasoner only once. 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 2013-05-24 07:56:26 UTC (rev 3983) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-24 09:16:41 UTC (rev 3984) @@ -101,6 +101,8 @@ private Map<NamedClass, Integer> classPopularityMap; private Map<ObjectProperty, Integer> objectPropertyPopularityMap; private Map<DatatypeProperty, Integer> dataPropertyPopularityMap; + + private boolean prepared = false; public SPARQLReasoner(SparqlEndpointKS ks) { @@ -247,54 +249,57 @@ } public final ClassHierarchy prepareSubsumptionHierarchy() { - logger.info("Preparing subsumption hierarchy ..."); - long startTime = System.currentTimeMillis(); - ConceptComparator conceptComparator = new ConceptComparator(); - TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, SortedSet<Description>>( - conceptComparator); - TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( - conceptComparator); + if(!prepared){ + logger.info("Preparing subsumption hierarchy ..."); + long startTime = System.currentTimeMillis(); + ConceptComparator conceptComparator = new ConceptComparator(); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyUp = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); + TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( + conceptComparator); - // parents/children of top ... - SortedSet<Description> tmp = getSubClasses(Thing.instance); - subsumptionHierarchyUp.put(Thing.instance, new TreeSet<Description>(conceptComparator)); - subsumptionHierarchyDown.put(Thing.instance, tmp); + // parents/children of top ... + SortedSet<Description> tmp = getSubClasses(Thing.instance); + subsumptionHierarchyUp.put(Thing.instance, new TreeSet<Description>(conceptComparator)); + subsumptionHierarchyDown.put(Thing.instance, tmp); - // ... bottom ... - tmp = getSuperClasses(Nothing.instance); - subsumptionHierarchyUp.put(Nothing.instance, tmp); - subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>(conceptComparator)); + // ... bottom ... + tmp = getSuperClasses(Nothing.instance); + subsumptionHierarchyUp.put(Nothing.instance, tmp); + subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>(conceptComparator)); - // ... and named classes - Set<NamedClass> atomicConcepts; - if(ks.isRemote()){ - atomicConcepts = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); - } else { - atomicConcepts = new TreeSet<NamedClass>(); - for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().toList()){ - if(!cls.isAnon()){ - atomicConcepts.add(new NamedClass(cls.getURI())); + // ... and named classes + Set<NamedClass> atomicConcepts; + if(ks.isRemote()){ + atomicConcepts = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); + } else { + atomicConcepts = new TreeSet<NamedClass>(); + for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().toList()){ + if(!cls.isAnon()){ + atomicConcepts.add(new NamedClass(cls.getURI())); + } } } - } - for (NamedClass atom : atomicConcepts) { - tmp = getSubClasses(atom); - // quality control: we explicitly check that no reasoner implementation returns null here - if(tmp == null) { - logger.error("Class hierarchy: getSubClasses returned null instead of empty set."); - } - subsumptionHierarchyDown.put(atom, tmp); + for (NamedClass atom : atomicConcepts) { + tmp = getSubClasses(atom); + // quality control: we explicitly check that no reasoner implementation returns null here + if(tmp == null) { + logger.error("Class hierarchy: getSubClasses returned null instead of empty set."); + } + subsumptionHierarchyDown.put(atom, tmp); - tmp = getSuperClasses(atom); - // quality control: we explicitly check that no reasoner implementation returns null here - if(tmp == null) { - logger.error("Class hierarchy: getSuperClasses returned null instead of empty set."); - } - subsumptionHierarchyUp.put(atom, tmp); - } - logger.info("... done in {}ms", (System.currentTimeMillis()-startTime)); - hierarchy = new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); + tmp = getSuperClasses(atom); + // quality control: we explicitly check that no reasoner implementation returns null here + if(tmp == null) { + logger.error("Class hierarchy: getSuperClasses returned null instead of empty set."); + } + subsumptionHierarchyUp.put(atom, tmp); + } + logger.info("... done in {}ms", (System.currentTimeMillis()-startTime)); + hierarchy = new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); + prepared = true; + } return hierarchy; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-24 07:56:31
|
Revision: 3983 http://sourceforge.net/p/dl-learner/code/3983 Author: lorenz_b Date: 2013-05-24 07:56:26 +0000 (Fri, 24 May 2013) Log Message: ----------- Avoid NPE. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLEntityTypeAdder.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2013-05-22 15:35:39 UTC (rev 3982) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2013-05-24 07:56:26 UTC (rev 3983) @@ -164,7 +164,7 @@ public static void main(String[] args) throws Exception{ FunctionalObjectPropertyAxiomLearner l = new FunctionalObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/currency")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/property/father")); l.setMaxExecutionTimeInSeconds(20); l.setForceSPARQL_1_0_Mode(true); l.init(); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2013-05-22 15:35:39 UTC (rev 3982) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2013-05-24 07:56:26 UTC (rev 3983) @@ -203,18 +203,21 @@ if (subClass.equals(superClass)) { return true; } else { - for (Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { - - // search the upper classes of the subclass - if (moreGeneralClass instanceof NamedClass) { - if (isSubclassOf((NamedClass) moreGeneralClass, superClass)) { - return true; + SortedSet<Description> superClasses = subsumptionHierarchyUp.get(subClass); + if(superClasses != null){ + for (Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { + + // search the upper classes of the subclass + if (moreGeneralClass instanceof NamedClass) { + if (isSubclassOf((NamedClass) moreGeneralClass, superClass)) { + return true; + } + // we reached top, so we can return false (if top is a + // direct upper + // class, then no other upper classes can exist) + } else { + return false; } - // we reached top, so we can return false (if top is a - // direct upper - // class, then no other upper classes can exist) - } else { - return false; } } // we cannot reach the class via any of the upper classes, Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-22 15:35:39 UTC (rev 3982) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-24 07:56:26 UTC (rev 3983) @@ -651,7 +651,7 @@ String query = " SELECT DISTINCT ?ind WHERE {"+ - "?ind ?p ?o ."+ + "?ind a ?o .?o <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Class>"+ filterStr+ " }"; if(limit != 0) { query += " LIMIT " + limit; Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLEntityTypeAdder.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLEntityTypeAdder.java 2013-05-22 15:35:39 UTC (rev 3982) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLEntityTypeAdder.java 2013-05-24 07:56:26 UTC (rev 3983) @@ -3,7 +3,6 @@ import java.util.HashSet; import java.util.Set; -import com.google.common.collect.Sets; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -28,7 +27,8 @@ while(iterator.hasNext()){ Statement st = iterator.next(); Property predicate = st.getPredicate(); - if(!predicate.getURI().startsWith(RDF.getURI()) && !predicate.getURI().startsWith(RDFS.getURI())){ + if(!predicate.getURI().startsWith(RDF.getURI()) && !predicate.getURI().startsWith(RDFS.getURI()) + && !predicate.getURI().startsWith(OWL.getURI())){ RDFNode object = st.getObject(); if(object.isLiteral()){ dataPropertyPredicates.add(predicate); @@ -38,13 +38,6 @@ } } iterator.close(); - - for (Property property : Sets.difference(objectPropertyPredicates, dataPropertyPredicates)) { - model.add(property, RDF.type, OWL.ObjectProperty); - } - for (Property property : Sets.difference(dataPropertyPredicates, objectPropertyPredicates)) { - model.add(property, RDF.type, OWL.DatatypeProperty); - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <moa...@us...> - 2013-05-22 15:35:42
|
Revision: 3982 http://sourceforge.net/p/dl-learner/code/3982 Author: moahmedsherif Date: 2013-05-22 15:35:39 +0000 (Wed, 22 May 2013) Log Message: ----------- add getRandomIndividuals() 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 2013-05-17 15:47:53 UTC (rev 3981) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-22 15:35:39 UTC (rev 3982) @@ -22,6 +22,7 @@ import java.net.SocketTimeoutException; import java.net.URL; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -576,6 +577,37 @@ return individuals; } + /** + * @param wantedClass + * @param excludeClass + * @param limit + * @return get individual of class wantedClass excluding all individual of type excludeClass + * @author sherif + */ + public SortedSet<Individual> getIndividualsExcluding(Description wantedClass, Description excludeClass, int limit) { + + if(!(wantedClass instanceof NamedClass)){ + throw new UnsupportedOperationException("Only named classes are supported."); + } + SortedSet<Individual> individuals = new TreeSet<Individual>(); + String query = + "SELECT DISTINCT ?ind WHERE {" + + "?ind a <"+((NamedClass)wantedClass).getName() + "> . " + + "FILTER(NOT EXISTS { ?ind a <" + ((NamedClass)excludeClass).getName() + "> } )}"; + if(limit != 0) { + query += " LIMIT " + limit; + } + System.out.println("query: "+query); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + if(qs.get("ind").isURIResource()){ + individuals.add(new Individual(qs.getResource("ind").getURI())); + } + } + return individuals; + } /** * @param cls @@ -602,6 +634,40 @@ } return individuals; } + + /** + * @param cls + * @param limit + * @return Random Individuals not including any of the input classes individuals + * @author sherif + */ + public SortedSet<Individual> getRandomIndividuals(Set<NamedClass> cls, int limit) { + SortedSet<Individual> individuals = new TreeSet<Individual>(); + + String filterStr=""; + for(NamedClass nc : cls){ + filterStr = filterStr.concat("FILTER(NOT EXISTS { ?ind a <").concat(nc.getName()).concat("> } ) "); + } + + String query = + " SELECT DISTINCT ?ind WHERE {"+ + "?ind ?p ?o ."+ + filterStr+ " }"; + if(limit != 0) { + query += " LIMIT " + limit; + } + + System.out.println("!!!!!!!!!!!!!!!!!!!! "+query); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + if(qs.get("ind").isURIResource()){ + individuals.add(new Individual(qs.getResource("ind").getURI())); + } + } + return individuals; + } /** * @param cls @@ -618,9 +684,14 @@ " SELECT DISTINCT ?ind WHERE { "+ "?ind a <" + parentClass.getName() + "> ."+ "FILTER(NOT EXISTS { ?ind a <" + cls.getName() + "> } ) }"; + + if(limit != 0) { query += " LIMIT " + limit/parentClasses.size(); } + + System.out.println("---------------------------------------------- "+query); + ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -629,7 +700,10 @@ individuals.add(new Individual(qs.getResource("ind").getURI())); } } + System.out.println(individuals.size()); + System.out.println(individuals); } + return individuals; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <moa...@us...> - 2013-05-17 15:47:57
|
Revision: 3981 http://sourceforge.net/p/dl-learner/code/3981 Author: moahmedsherif Date: 2013-05-17 15:47:53 +0000 (Fri, 17 May 2013) Log Message: ----------- fix add parent class individuals and random individuals 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 2013-05-15 13:09:32 UTC (rev 3980) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-17 15:47:53 UTC (rev 3981) @@ -85,60 +85,60 @@ @ComponentAnn(name = "SPARQL Reasoner", shortName = "spr", version = 0.1) public class SPARQLReasoner implements SchemaReasoner, IndividualReasoner { - + private static final Logger logger = LoggerFactory.getLogger(SPARQLReasoner.class); - + @ConfigOption(name = "useCache", description = "Whether to use a DB cache", defaultValue = "true", required = false, propertyEditorClass = BooleanEditor.class) private boolean useCache = true; - + private ExtractionDBCache cache; - + private SparqlEndpointKS ks; private ClassHierarchy hierarchy; private OntModel model; - + private Map<NamedClass, Integer> classPopularityMap; private Map<ObjectProperty, Integer> objectPropertyPopularityMap; private Map<DatatypeProperty, Integer> dataPropertyPopularityMap; - - + + public SPARQLReasoner(SparqlEndpointKS ks) { this.ks = ks; - + if(useCache){ cache = new ExtractionDBCache("cache"); } classPopularityMap = new HashMap<NamedClass, Integer>(); objectPropertyPopularityMap = new HashMap<ObjectProperty, Integer>(); } - + public SPARQLReasoner(SparqlEndpointKS ks, ExtractionDBCache cache) { this.ks = ks; this.cache = cache; - + classPopularityMap = new HashMap<NamedClass, Integer>(); objectPropertyPopularityMap = new HashMap<ObjectProperty, Integer>(); } - + public SPARQLReasoner(OntModel model) { this.model = model; - + classPopularityMap = new HashMap<NamedClass, Integer>(); objectPropertyPopularityMap = new HashMap<ObjectProperty, Integer>(); } - + public void precomputePopularity(){ precomputeClassPopularity(); precomputeDataPropertyPopularity(); precomputeObjectPropertyPopularity(); } - + public void precomputeClassPopularity(){ logger.info("Precomputing class popularity ..."); - + Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>}"; - + ResultSet rs; for(NamedClass nc : classes){ rs = executeSelectQuery(String.format(queryTemplate, nc.getName())); @@ -146,14 +146,14 @@ classPopularityMap.put(nc, cnt); } } - + public void precomputeObjectPropertyPopularity(){ logger.info("Precomputing object property popularity ..."); objectPropertyPopularityMap = new HashMap<ObjectProperty, Integer>(); - + Set<ObjectProperty> properties = new SPARQLTasks(ks.getEndpoint()).getAllObjectProperties(); String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}"; - + ResultSet rs; for(ObjectProperty op : properties){ rs = executeSelectQuery(String.format(queryTemplate, op.getName())); @@ -161,14 +161,14 @@ objectPropertyPopularityMap.put(op, cnt); } } - + public void precomputeDataPropertyPopularity(){ logger.info("Precomputing data property popularity ..."); dataPropertyPopularityMap = new HashMap<DatatypeProperty, Integer>(); - + Set<DatatypeProperty> properties = new SPARQLTasks(ks.getEndpoint()).getAllDataProperties(); String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}"; - + ResultSet rs; for(DatatypeProperty dp : properties){ rs = executeSelectQuery(String.format(queryTemplate, dp.getName())); @@ -176,7 +176,7 @@ dataPropertyPopularityMap.put(dp, cnt); } } - + public int getSubjectCountForProperty(Property p, long timeout){ int cnt = -1; String query = String.format( @@ -186,10 +186,10 @@ if(rs.hasNext()){ cnt = rs.next().getLiteral("cnt").getInt(); } - + return cnt; } - + public int getObjectCountForProperty(ObjectProperty p, long timeout){ int cnt = -1; String query = String.format( @@ -199,52 +199,52 @@ if(rs.hasNext()){ cnt = rs.next().getLiteral("cnt").getInt(); } - + return cnt; } - + public int getPopularity(NamedClass nc){ if(classPopularityMap != null && classPopularityMap.containsKey(nc)){ return classPopularityMap.get(nc); } else { String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>}"; - + ResultSet rs = executeSelectQuery(String.format(queryTemplate, nc.getName())); int cnt = rs.next().getLiteral("cnt").getInt(); classPopularityMap.put(nc, cnt); return cnt; } - + } - + public int getPopularity(ObjectProperty op){ if(objectPropertyPopularityMap != null && objectPropertyPopularityMap.containsKey(op)){ return objectPropertyPopularityMap.get(op); } else { String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}"; - + ResultSet rs = executeSelectQuery(String.format(queryTemplate, op.getName())); int cnt = rs.next().getLiteral("cnt").getInt(); objectPropertyPopularityMap.put(op, cnt); return cnt; } - + } - + public int getPopularity(DatatypeProperty dp){ if(dataPropertyPopularityMap.containsKey(dp)){ return dataPropertyPopularityMap.get(dp); } else { String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}"; - + ResultSet rs = executeSelectQuery(String.format(queryTemplate, dp.getName())); int cnt = rs.next().getLiteral("cnt").getInt(); dataPropertyPopularityMap.put(dp, cnt); return cnt; } - + } - + public final ClassHierarchy prepareSubsumptionHierarchy() { logger.info("Preparing subsumption hierarchy ..."); long startTime = System.currentTimeMillis(); @@ -263,7 +263,7 @@ tmp = getSuperClasses(Nothing.instance); subsumptionHierarchyUp.put(Nothing.instance, tmp); subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>(conceptComparator)); - + // ... and named classes Set<NamedClass> atomicConcepts; if(ks.isRemote()){ @@ -276,7 +276,7 @@ } } } - + for (NamedClass atom : atomicConcepts) { tmp = getSubClasses(atom); // quality control: we explicitly check that no reasoner implementation returns null here @@ -296,7 +296,7 @@ hierarchy = new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); return hierarchy; } - + public final ClassHierarchy prepareSubsumptionHierarchyFast() { logger.info("Preparing subsumption hierarchy ..."); long startTime = System.currentTimeMillis(); @@ -305,7 +305,7 @@ conceptComparator); TreeMap<Description, SortedSet<Description>> subsumptionHierarchyDown = new TreeMap<Description, SortedSet<Description>>( conceptComparator); - + String queryTemplate = "SELECT * WHERE {?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sup} LIMIT <%d> OFFSET <%d>"; int limit = 1000; int offset = 0; @@ -337,15 +337,15 @@ } offset += limit; } - + logger.info("... done in {}ms", (System.currentTimeMillis()-startTime)); hierarchy = new ClassHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); return hierarchy; } - + public Model loadSchema(){ Model model = ModelFactory.createDefaultModel(); - + //load class hierarchy String query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o} WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o.FILTER(!REGEX(STR(?s), 'http://dbpedia.org/class/yago/'))}"; model.add(loadIncrementally(query)); @@ -372,7 +372,7 @@ "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; model.add(loadIncrementally(query)); query = "CONSTRUCT {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} " + - "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + "WHERE {?s <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?o. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; model.add(loadIncrementally(query)); query = "CONSTRUCT {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} " + "WHERE {?s <http://www.w3.org/2002/07/owl#equivalentProperty> ?o. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; @@ -391,7 +391,7 @@ model.add(loadIncrementally(query)); //load property characteristics Set<Resource> propertyCharacteristics = new HashSet<Resource>(); -// propertyCharacteristics.add(OWL.FunctionalProperty); + // propertyCharacteristics.add(OWL.FunctionalProperty); propertyCharacteristics.add(OWL.InverseFunctionalProperty); propertyCharacteristics.add(OWL.SymmetricProperty); propertyCharacteristics.add(OWL.TransitiveProperty); @@ -406,34 +406,34 @@ //for functional properties we have to distinguish between data and object properties, //i.e. we have to keep the property type information, otherwise conversion to OWLAPI ontology makes something curious query = "CONSTRUCT {?s a <%s>. ?s a <http://www.w3.org/2002/07/owl#ObjectProperty>} WHERE {?s a <%s>.?s a <http://www.w3.org/2002/07/owl#ObjectProperty>}". - replaceAll("%s", OWL.FunctionalProperty.getURI()); + replaceAll("%s", OWL.FunctionalProperty.getURI()); model.add(loadIncrementally(query)); query = "CONSTRUCT {?s a <%s>. ?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>} WHERE {?s a <%s>.?s a <http://www.w3.org/2002/07/owl#DatatypeProperty>}". - replaceAll("%s", OWL.FunctionalProperty.getURI()); + replaceAll("%s", OWL.FunctionalProperty.getURI()); model.add(loadIncrementally(query)); - - + + return model; } - + private Model loadIncrementally(String query){ System.out.println(StringUtils.md5Hash(query)); -// try { - QueryExecutionFactory f = new QueryExecutionFactoryHttp(ks.getEndpoint().getURL().toString(), ks.getEndpoint().getDefaultGraphURIs()); -// f = new QueryExecutionFactoryCache(f, new CacheImpl(CacheCoreH2.create("cache", 60 * 24 *5))); -// System.out.println("SPARQLReasoner.loadIncrementally needs to be rewritten for aksw-commons 0.1"); -// System.exit(0); - f = new QueryExecutionFactoryPaginated(f, 1000); - Model model = f.createQueryExecution(query).execConstruct(); - System.out.println(query); - System.out.println("Got " + model.size() + " triple."); - return model; -// } catch (ClassNotFoundException e) { -// e.printStackTrace(); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// return null; + // try { + QueryExecutionFactory f = new QueryExecutionFactoryHttp(ks.getEndpoint().getURL().toString(), ks.getEndpoint().getDefaultGraphURIs()); + // f = new QueryExecutionFactoryCache(f, new CacheImpl(CacheCoreH2.create("cache", 60 * 24 *5))); + // System.out.println("SPARQLReasoner.loadIncrementally needs to be rewritten for aksw-commons 0.1"); + // System.exit(0); + f = new QueryExecutionFactoryPaginated(f, 1000); + Model model = f.createQueryExecution(query).execConstruct(); + System.out.println(query); + System.out.println("Got " + model.size() + " triple."); + return model; + // } catch (ClassNotFoundException e) { + // e.printStackTrace(); + // } catch (SQLException e) { + // e.printStackTrace(); + // } + // return null; } @Override @@ -448,11 +448,11 @@ } return types; } - + public Set<NamedClass> getTypes() { return getTypes((String)null); } - + public Set<NamedClass> getTypes(String namespace) { Set<NamedClass> types = new TreeSet<NamedClass>(); String query = String.format("SELECT DISTINCT ?class WHERE {[] a ?class." + (namespace != null ? ("FILTER(REGEX(?class,'^" + namespace + "'))") : "") + "}"); @@ -464,7 +464,7 @@ } return types; } - + public Set<NamedClass> getOWLClasses() { Set<NamedClass> types = new HashSet<NamedClass>(); String query = String.format("SELECT DISTINCT ?class WHERE {?class a <%s>.}",OWL.Class.getURI()); @@ -476,7 +476,7 @@ } return types; } - + /** * Returns a set of classes which are siblings, i.e. on the same level * in the class hierarchy. @@ -516,7 +516,7 @@ } return parents; } - + /** * Returns a set of classes which are children of current class * in the class hierarchy. @@ -535,7 +535,7 @@ } return children; } - + @Override public boolean hasType(Description description, Individual individual) { if(!(description instanceof NamedClass)){ @@ -575,7 +575,64 @@ } return individuals; } + + /** + * @param cls + * @param limit + * @return Random Individuals not including any of the input class individuals + * @author sherif + */ + public SortedSet<Individual> getRandomIndividuals(NamedClass cls, int limit) { + SortedSet<Individual> individuals = new TreeSet<Individual>(); + String query = + " SELECT DISTINCT ?ind WHERE {"+ + "?ind ?p ?o ."+ + "FILTER(NOT EXISTS { ?ind a <" + cls.getName() + "> } ) }"; + if(limit != 0) { + query += " LIMIT " + limit; + } + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + if(qs.get("ind").isURIResource()){ + individuals.add(new Individual(qs.getResource("ind").getURI())); + } + } + return individuals; + } + + /** + * @param cls + * @param limit + * @return Super class of the input class Individuals not including any of the input class individuals + * @author sherif + */ + public SortedSet<Individual> getSuperClassIndividuals(NamedClass cls, int limit) { + SortedSet<Individual> individuals = new TreeSet<Individual>(); + Set<NamedClass> parentClasses = getParentClasses(cls); + + for(NamedClass parentClass : parentClasses){ + String query = + " SELECT DISTINCT ?ind WHERE { "+ + "?ind a <" + parentClass.getName() + "> ."+ + "FILTER(NOT EXISTS { ?ind a <" + cls.getName() + "> } ) }"; + if(limit != 0) { + query += " LIMIT " + limit/parentClasses.size(); + } + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + if(qs.get("ind").isURIResource()){ + individuals.add(new Individual(qs.getResource("ind").getURI())); + } + } + } + return individuals; + } + @Override public SortedSetTuple<Individual> doubleRetrieval(Description description) { throw new UnsupportedOperationException(); @@ -585,7 +642,7 @@ public Set<Individual> getRelatedIndividuals(Individual individual, ObjectProperty objectProperty) { Set<Individual> individuals = new HashSet<Individual>(); String query = String.format("SELECT ?ind WHERE {<%s> <%s> ?ind, FILTER(isIRI(?ind))}", individual.getName(), objectProperty.getName()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -608,7 +665,7 @@ "<%s> ?prop ?ind." + " FILTER(isIRI(?ind) && ?prop != <%s> && ?prop != <%s>)}", individual.getName(), RDF.type.getURI(), OWL.sameAs.getURI()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; Set<Individual> individuals; @@ -624,7 +681,7 @@ prop2individuals.put(property, individuals); } individuals.add(ind); - + } return prop2individuals; } @@ -636,7 +693,7 @@ "?s <%s> ?o." + " FILTER(isIRI(?o))}", objectProperty.getName()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; Individual sub; @@ -652,7 +709,7 @@ subject2objects.put(sub, objects); } objects.add(obj); - + } return subject2objects; } @@ -670,7 +727,7 @@ "?s <%s> ?o." + " FILTER(DATATYPE(?o) = <%s>)}", datatypeProperty.getName(), XSD.DOUBLE.toStringID()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; Individual sub; @@ -686,7 +743,7 @@ subject2objects.put(sub, objects); } objects.add(obj); - + } return subject2objects; } @@ -698,7 +755,7 @@ "?s <%s> ?o." + " FILTER(DATATYPE(?o) = <%s>)}", datatypeProperty.getName(), XSD.INT.toStringID()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; Individual sub; @@ -714,7 +771,7 @@ subject2objects.put(sub, objects); } objects.add(obj); - + } return subject2objects; } @@ -726,7 +783,7 @@ "?s <%s> ?o." + " FILTER(DATATYPE(?o) = <%s>)}", datatypeProperty.getName(), XSD.BOOLEAN.toStringID()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; Individual sub; @@ -742,7 +799,7 @@ subject2objects.put(sub, objects); } objects.add(obj); - + } return subject2objects; } @@ -755,13 +812,13 @@ " FILTER(isLiteral(?o) && DATATYPE(?o) = <%s> && ?o = %s)}", datatypeProperty.getName(), XSD.BOOLEAN.toStringID(), "\"true\"^^<" + XSD.BOOLEAN.toStringID() + ">"); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); members.add(new Individual(qs.getResource("ind").getURI())); - + } return members; } @@ -774,13 +831,13 @@ " FILTER(isLiteral(?o) && DATATYPE(?o) = <%s> && ?o = %s)}", datatypeProperty.getName(), XSD.BOOLEAN.toStringID(), "\"false\"^^<"+XSD.BOOLEAN.toStringID() + ">"); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); members.add(new Individual(qs.getResource("ind").getURI())); - + } return members; } @@ -802,14 +859,14 @@ "<%s> <%s> ?domain. FILTER(isIRI(?domain))" + "}", objectProperty.getName(), RDFS.domain.getURI()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; List<Description> domains = new ArrayList<Description>(); while(rs.hasNext()){ qs = rs.next(); domains.add(new NamedClass(qs.getResource("domain").getURI())); - + } if(domains.size() == 1){ return domains.get(0); @@ -825,14 +882,14 @@ "<%s> <%s> ?domain. FILTER(isIRI(?domain))" + "}", datatypeProperty.getName(), RDFS.domain.getURI()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; List<Description> domains = new ArrayList<Description>(); while(rs.hasNext()){ qs = rs.next(); domains.add(new NamedClass(qs.getResource("domain").getURI())); - + } if(domains.size() == 1){ return domains.get(0); @@ -848,14 +905,14 @@ "<%s> <%s> ?range. FILTER(isIRI(?range))" + "}", objectProperty.getName(), RDFS.range.getURI()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; List<Description> ranges = new ArrayList<Description>(); while(rs.hasNext()){ qs = rs.next(); ranges.add(new NamedClass(qs.getResource("range").getURI())); - + } if(ranges.size() == 1){ return ranges.get(0); @@ -864,13 +921,13 @@ } return null; } - + public boolean isObjectProperty(String propertyURI){ String query = String.format("ASK {<%s> a <%s>}", propertyURI, OWL.ObjectProperty.getURI()); boolean isObjectProperty = executeAskQuery(query); return isObjectProperty; } - + public boolean isObjectProperty(String propertyURI, boolean analyzeData){ String query = String.format("ASK {<%s> a <%s>}", propertyURI, OWL.ObjectProperty.getURI()); boolean isObjectProperty = executeAskQuery(query); @@ -880,14 +937,14 @@ } return isObjectProperty; } - + public boolean isDataProperty(String propertyURI){ if(propertyURI.equals("http://www.w3.org/2000/01/rdf-schema#label")) return true; String query = String.format("ASK {<%s> a <%s>}", propertyURI, OWL.DatatypeProperty.getURI()); boolean isDataProperty = executeAskQuery(query); return isDataProperty; } - + public boolean isDataProperty(String propertyURI, boolean analyzeData){ if(propertyURI.equals("http://www.w3.org/2000/01/rdf-schema#label")) return true; String query = String.format("ASK {<%s> a <%s>}", propertyURI, OWL.DatatypeProperty.getURI()); @@ -898,7 +955,7 @@ } return isDataProperty; } - + public int getIndividualsCount(NamedClass nc){ String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {" + "?s a <%s>." + @@ -907,17 +964,17 @@ ResultSet rs = executeSelectQuery(query); int cnt = rs.next().get(rs.getResultVars().get(0)).asLiteral().getInt(); return cnt; - + } - + public int getPropertyCount(ObjectProperty property){ String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o.}", property.getName()); ResultSet rs = executeSelectQuery(query); int cnt = rs.next().get(rs.getResultVars().get(0)).asLiteral().getInt(); return cnt; - + } - + public SortedSet<ObjectProperty> getInverseObjectProperties(ObjectProperty property){ SortedSet<ObjectProperty> inverseObjectProperties = new TreeSet<ObjectProperty>(); String query = "SELECT ?p WHERE {" + @@ -927,7 +984,7 @@ while(rs.hasNext()){ qs = rs.next(); inverseObjectProperties.add(new ObjectProperty(qs.getResource("p").getURI())); - + } return inverseObjectProperties; } @@ -938,14 +995,14 @@ "<%s> <%s> ?range. FILTER(isIRI(?range))" + "}", datatypeProperty.getName(), RDFS.range.getURI()); - + ResultSet rs = executeSelectQuery(query); QuerySolution qs; DataRange range = null; while(rs.hasNext()){ qs = rs.next(); range = new Datatype(qs.getResource("range").getURI()); - + } return range; } @@ -957,8 +1014,8 @@ } String query = String.format("ASK {<%s> <%s> <%s>.}", ((NamedClass)subClass).getURI().toString(), - RDFS.subClassOf.getURI(), - ((NamedClass)superClass).getURI().toString()); + RDFS.subClassOf.getURI(), + ((NamedClass)superClass).getURI().toString()); boolean superClassOf = executeAskQuery(query); return superClassOf; } @@ -970,8 +1027,8 @@ } String query = String.format("ASK {<%s> <%s> <%s>.}", ((NamedClass)class1).getURI().toString(), - OWL.equivalentClass.getURI(), - ((NamedClass)class2).getURI().toString()); + OWL.equivalentClass.getURI(), + ((NamedClass)class2).getURI().toString()); boolean equivalentClass = executeAskQuery(query); return equivalentClass; } @@ -984,7 +1041,7 @@ OWL.equivalentClass.getURI(), OWL.equivalentClass.getURI(), namedClass.getURI().toString() - ); + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1017,7 +1074,7 @@ String query = String.format("SELECT ?sup {<%s> <%s> ?sup. FILTER(isIRI(?sup))}", ((NamedClass)description).getURI().toString(), RDFS.subClassOf.getURI() - ); + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1027,7 +1084,7 @@ superClasses.remove(description); return superClasses; } - + public SortedSet<Description> getSuperClasses(Description description, boolean direct){ if(!(description instanceof NamedClass)){ throw new IllegalArgumentException("Only named classes are supported."); @@ -1038,9 +1095,9 @@ "{ SELECT ?x ?y WHERE { ?x rdfs:subClassOf ?y } }" + "OPTION ( TRANSITIVE, T_DISTINCT, t_in(?x), t_out(?y), t_step('path_id') as ?path, t_step(?x) as ?route, t_step('step_no') AS ?jump, T_DIRECTION 3 )" + "FILTER ( ?x = <%s> )}", ((NamedClass)description).getURI().toString()); - - - + + + return superClasses; } @@ -1048,7 +1105,7 @@ public SortedSet<Description> getSubClasses(Description description) { 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."); @@ -1064,8 +1121,8 @@ query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", RDFS.subClassOf.getURI(), ((NamedClass)description).getURI().toString() - - ); + + ); } ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -1076,13 +1133,13 @@ subClasses.remove(description); 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()); + "{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; } @@ -1098,7 +1155,7 @@ String query = String.format("SELECT ?sup {<%s> <%s> ?sup. FILTER(isIRI(?sup))}", objectProperty.getURI().toString(), RDFS.subPropertyOf.getURI() - ); + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1114,8 +1171,8 @@ String query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", RDFS.subPropertyOf.getURI(), objectProperty.getURI().toString() - - ); + + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1124,13 +1181,13 @@ } return subProperties; } - + public SortedSet<ObjectProperty> getEquivalentProperties(ObjectProperty objectProperty) { SortedSet<ObjectProperty> superProperties = new TreeSet<ObjectProperty>(); String query = String.format("SELECT ?equ {<%s> <%s> ?equ. FILTER(isIRI(?equ))}", objectProperty.getURI().toString(), OWL.equivalentProperty.getURI() - ); + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1139,13 +1196,13 @@ } return superProperties; } - + public SortedSet<DatatypeProperty> getEquivalentProperties(DatatypeProperty objectProperty) { SortedSet<DatatypeProperty> superProperties = new TreeSet<DatatypeProperty>(); String query = String.format("SELECT ?equ {<%s> <%s> ?equ. FILTER(isIRI(?equ))}", objectProperty.getURI().toString(), OWL.equivalentProperty.getURI() - ); + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1176,7 +1233,7 @@ String query = String.format("SELECT ?sup {<%s> <%s> ?sup. FILTER(isIRI(?sup))}", dataProperty.getURI().toString(), RDFS.subPropertyOf.getURI() - ); + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1192,8 +1249,8 @@ String query = String.format("SELECT ?sub {?sub <%s> <%s>. FILTER(isIRI(?sub))}", RDFS.subPropertyOf.getURI(), dataProperty.getURI().toString() - - ); + + ); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1212,7 +1269,7 @@ public TreeSet<DatatypeProperty> getMostSpecialDatatypeProperties() { throw new UnsupportedOperationException(); } - + private ResultSet executeSelectQuery(String query){ logger.debug("Sending query \n {}", query); ResultSet rs = null; @@ -1232,11 +1289,11 @@ } else { QueryExecution qExec = com.hp.hpl.jena.query.QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); rs = qExec.execSelect(); - + } return rs; } - + private ResultSet executeSelectQuery(String query, long timeout){ logger.debug("Sending query \n {}", query); ResultSet rs = null; @@ -1263,7 +1320,7 @@ } return rs; } - + /** * Returns TRUE if the class hierarchy was computed before. * @return @@ -1271,15 +1328,15 @@ public boolean isPrepared(){ return hierarchy != null; } - + public void setCache(ExtractionDBCache cache) { this.cache = cache; } - + public void setUseCache(boolean useCache) { this.useCache = useCache; } - + private boolean executeAskQuery(String query){ boolean ret; if(ks.isRemote()){ @@ -1291,35 +1348,35 @@ queryExecution.addNamedGraph(ngu); } ret = queryExecution.execAsk(); - + } else { QueryExecution qExec = com.hp.hpl.jena.query.QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); ret = qExec.execAsk(); } - + return ret; } - - + + public static void main(String[] args) throws Exception{ -// QueryEngineHTTP e = new QueryEngineHTTP("http://bibleontology.com/sparql/index.jsp", -// "SELECT DISTINCT ?type WHERE {?s a ?type) LIMIT 10"); -// e.addParam("type1", "xml");System.out.println(e.toString()); -// e.execSelect(); - - + // QueryEngineHTTP e = new QueryEngineHTTP("http://bibleontology.com/sparql/index.jsp", + // "SELECT DISTINCT ?type WHERE {?s a ?type) LIMIT 10"); + // e.addParam("type1", "xml");System.out.println(e.toString()); + // e.execSelect(); + + SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://live.dbpedia.org/sparql/"))); SPARQLReasoner r = new SPARQLReasoner(ks); long startTime = System.currentTimeMillis(); ClassHierarchy h = r.prepareSubsumptionHierarchyFast(); System.out.println(h.toString(false)); -// Model schema = r.loadSchema(); -// for(Statement st : schema.listStatements().toList()){ -// System.out.println(st); -// } + // Model schema = r.loadSchema(); + // for(Statement st : schema.listStatements().toList()){ + // System.out.println(st); + // } System.out.println(h.getSubClasses(new NamedClass("http://dbpedia.org/ontology/Bridge"), false)); System.out.println("Time needed: " + (System.currentTimeMillis()-startTime) + "ms"); - + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <moa...@us...> - 2013-05-15 13:09:35
|
Revision: 3980 http://sourceforge.net/p/dl-learner/code/3980 Author: moahmedsherif Date: 2013-05-15 13:09:32 +0000 (Wed, 15 May 2013) Log Message: ----------- add getParentClasses() and getChildClasses() 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 2013-05-10 21:55:32 UTC (rev 3979) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-05-15 13:09:32 UTC (rev 3980) @@ -498,6 +498,44 @@ return siblings; } + /** + * Returns a set of classes which are Parent of current class + * in the class hierarchy. + * @param cls + * @param limit + * @return + */ + public Set<NamedClass> getParentClasses(NamedClass cls) { + Set<NamedClass> parents = new HashSet<NamedClass>(); + String query = "SELECT DISTINCT ?parentClass WHERE { <" + cls.getName() + "> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?parentClass }"; + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + parents.add(new NamedClass(qs.getResource("parentClass").getURI())); + } + return parents; + } + + /** + * Returns a set of classes which are children of current class + * in the class hierarchy. + * @param cls + * @param limit + * @return + */ + public Set<NamedClass> getChildClasses(NamedClass cls) { + Set<NamedClass> children = new HashSet<NamedClass>(); + String query = "SELECT DISTINCT ?childClass WHERE { ?childClass <http://www.w3.org/2000/01/rdf-schema#subClassOf> <" + cls.getName() + ">}"; + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + children.add(new NamedClass(qs.getResource("childClass").getURI())); + } + return children; + } + @Override public boolean hasType(Description description, Individual individual) { if(!(description instanceof NamedClass)){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2013-05-10 21:55:35
|
Revision: 3979 http://sourceforge.net/p/dl-learner/code/3979 Author: jenslehmann Date: 2013-05-10 21:55:32 +0000 (Fri, 10 May 2013) Log Message: ----------- bug fix in F-beta Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java 2013-05-10 13:27:03 UTC (rev 3978) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java 2013-05-10 21:55:32 UTC (rev 3979) @@ -52,10 +52,10 @@ */ public static double getFScore(double recall, double precision, double beta) { return (precision + recall == 0) ? 0 : - ( (1+Math.sqrt(beta)) * (precision * recall) - / (Math.sqrt(beta) * precision + recall) ); + ( (1+ beta * beta) * (precision * recall) + / (beta * beta * precision + recall) ); } - + /** * Computes arithmetic mean of precision and recall, which is called "A-Score" * here (A=arithmetic), but is not an established notion in machine learning. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 13:27:06
|
Revision: 3978 http://sourceforge.net/p/dl-learner/code/3978 Author: lorenz_b Date: 2013-05-10 13:27:03 +0000 (Fri, 10 May 2013) Log Message: ----------- Write eval stats to DB. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 11:48:50 UTC (rev 3977) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 13:27:03 UTC (rev 3978) @@ -1132,25 +1132,33 @@ } else if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); } + //count subclass+superClass + Query query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, superClass), true);System.out.println(query); + rs = executeSelectQuery(query); + int overlap = rs.next().getLiteral("cnt").getInt(); //count subclass - Query query = converter.asQuery("?x", cls, true); + query = converter.asQuery("?x", cls, true); if(subClassCnt == -1){ System.out.println(query); rs = executeSelectQuery(query); subClassCnt = rs.next().getLiteral("cnt").getInt(); } + + //compute recall + double recall = wald(subClassCnt, overlap); + //if recall is too low we can skip the computation of the precision + if(recall < 0.2){ + logger.warn("Recall(" + recall + ") too low. Skipping precision computation."); + continue; + } //count superClass query = converter.asQuery("?x", superClass, true);System.out.println(query); rs = executeSelectQuery(query); int superClassCnt = rs.next().getLiteral("cnt").getInt(); - //count subclass+superClass - query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, superClass), true);System.out.println(query); - rs = executeSelectQuery(query); - int overlap = rs.next().getLiteral("cnt").getInt(); - + //compute precision double precision = wald(superClassCnt, overlap); - double recall = wald(subClassCnt, overlap); + double fScore = 0; if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ fScore = Heuristics.getFScore(recall, precision, 3); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 11:48:53
|
Revision: 3977 http://sourceforge.net/p/dl-learner/code/3977 Author: lorenz_b Date: 2013-05-10 11:48:50 +0000 (Fri, 10 May 2013) Log Message: ----------- Write eval stats to DB. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 10:01:19 UTC (rev 3976) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 11:48:50 UTC (rev 3977) @@ -7,11 +7,16 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.SQLException; import java.text.DecimalFormat; import java.util.ArrayList; @@ -29,6 +34,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.TimeUnit; +import java.util.prefs.Preferences; import joptsimple.OptionException; import joptsimple.OptionParser; @@ -51,6 +57,8 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; +import org.ini4j.IniPreferences; +import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.OWLObjectRenderer; import org.semanticweb.owlapi.io.ToStringRenderer; @@ -106,6 +114,8 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; import com.hp.hpl.jena.vocabulary.RDF; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; public class OWLAxiomPatternUsageEvaluation { @@ -139,6 +149,10 @@ private OWLOntology dbpediaOntology; private String ontologyURL = "http://downloads.dbpedia.org/3.8/dbpedia_3.8.owl.bz2"; private OWLReasoner reasoner; + + private Connection conn; + + private PreparedStatement ps; public OWLAxiomPatternUsageEvaluation() { try { @@ -153,8 +167,49 @@ } catch (IOException e) { e.printStackTrace(); } + + initDBConnection(); } + 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; + conn = DriverManager.getConnection(url, dbUser, dbPass); + + java.sql.Statement st = conn.createStatement(); + st.execute("CREATE TABLE IF NOT EXISTS Eval_Statistics (" + + "id MEDIUMINT NOT NULL AUTO_INCREMENT," + + "pattern TEXT NOT NULL," + + "pattern_pretty TEXT NOT NULL," + + "class TEXT NOT NULL," + + "runtime MEDIUMINT DEFAULT 0," + + "nrOfAxiomsLocal MEDIUMINT DEFAULT 0," + + "nrOfAxiomsGlobal MEDIUMINT DEFAULT 0," + + "PRIMARY KEY(id)," + + "INDEX(pattern(8000))) DEFAULT CHARSET=utf8"); + + ps = conn.prepareStatement("INSERT INTO Eval_Statistics (pattern, pattern_pretty, class, runtime, nrOfAxiomsLocal, nrOfAxiomsGlobal) VALUES(?,?,?,?,?,?)"); + } 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 runUsingFragmentExtraction(SparqlEndpoint endpoint, OWLOntology patternOntology, File outputFile, int maxNrOfTestedClasses){ ks = new SparqlEndpointKS(endpoint, cache); SPARQLReasoner reasoner = new SPARQLReasoner(ks, cache); @@ -170,7 +225,7 @@ Collections.shuffle(classesList, new Random(123)); classesList = classesList.subList(0, maxNrOfTestedClasses); classes = classesList; -// classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); + //classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); //get the maximum modal depth in the pattern axioms int maxModalDepth = maxModalDepth(patterns); @@ -193,7 +248,10 @@ } //for each pattern + Monitor patternTimeMon = MonitorFactory.getTimeMonitor("pattern-runtime"); for (OWLAxiom pattern : patterns) { + Monitor patternClassTimeMon = MonitorFactory.getTimeMonitor("class-pattern-runtime"); + patternTimeMon.start(); //run if not already exists a result on disk File file = new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations.ttl"); OWLOntology ontology = null; @@ -202,6 +260,7 @@ Set<OWLAxiom> learnedAxioms = new HashSet<OWLAxiom>(); // for each class for (NamedClass cls : classes) { + patternClassTimeMon.start(); logger.info("...on class " + cls + "..."); OWLClass owlClass = df.getOWLClass(IRI.create(cls.getName())); Model fragment = class2Fragment.get(cls); @@ -209,9 +268,14 @@ Set<OWLAxiom> annotatedAxioms = asAnnotatedAxioms(result); filterOutTrivialAxioms(annotatedAxioms); filterOutAxiomsBelowThreshold(annotatedAxioms, threshold); + int nrOfAxiomsLocal = annotatedAxioms.size(); annotatedAxioms = computeScoreGlobal(annotatedAxioms, owlClass); + filterOutAxiomsBelowThreshold(annotatedAxioms, threshold); + int nrOfAxiomsGlobal = annotatedAxioms.size(); learnedAxioms.addAll(annotatedAxioms); printAxioms(annotatedAxioms, threshold); + patternClassTimeMon.stop(); + write2DB(pattern, owlClass, patternClassTimeMon.getLastValue(), nrOfAxiomsLocal, nrOfAxiomsGlobal); } ontology = save(pattern, learnedAxioms, file); } else { @@ -222,6 +286,7 @@ e.printStackTrace(); } } + patternTimeMon.stop(); if(sampling){ List<OWLAxiom> sample = createSample(ontology);//, classes); List<String> lines = new ArrayList<String>(); @@ -789,6 +854,20 @@ return axioms2Score; } + private void write2DB(OWLAxiom pattern, OWLClass cls, double runtime, int nrOfAxiomsLocal, int nrOfAxiomsGlobal){ + try { + ps.setString(1, render(pattern)); + ps.setString(2, axiomRenderer.render(pattern)); + ps.setString(3, axiomRenderer.render(cls)); + ps.setDouble(4, runtime); + ps.setInt(5, nrOfAxiomsLocal); + ps.setInt(6, nrOfAxiomsGlobal); + ps.execute(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + private Map<OWLAxiom, Score> applyPattern2(OWLSubClassOfAxiom pattern, OWLClass cls, Model fragment) { Map<OWLAxiom, Score> axioms2Score = new HashMap<OWLAxiom, Score>(); @@ -950,6 +1029,11 @@ } } } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } } else { QueryExecution queryExecution = QueryExecutionFactory.create(query, ((LocalModelBasedSparqlEndpointKS)ks).getModel()); @@ -1029,51 +1113,60 @@ private Set<OWLAxiom> computeScoreGlobal(Set<OWLAxiom> axioms, OWLClass cls){ Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>(); + int subClassCnt = -1; + ResultSet rs; for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { - OWLAxiom axiom = iter.next(); - OWLClassExpression subClass; - OWLClassExpression superClass = null; - OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); - if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { - Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); - for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { - if (subClassOfAxiom.getSubClass().equals(cls)) { - superClass = subClassOfAxiom.getSuperClass(); - break; + try { + OWLAxiom axiom = iter.next(); + OWLClassExpression subClass; + OWLClassExpression superClass = null; + OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); + if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if (subClassOfAxiom.getSubClass().equals(cls)) { + superClass = subClassOfAxiom.getSuperClass(); + break; + } } + } else if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); } - } else if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ - superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); + //count subclass + Query query = converter.asQuery("?x", cls, true); + if(subClassCnt == -1){ + System.out.println(query); + rs = executeSelectQuery(query); + subClassCnt = rs.next().getLiteral("cnt").getInt(); + } + //count superClass + query = converter.asQuery("?x", superClass, true);System.out.println(query); + rs = executeSelectQuery(query); + int superClassCnt = rs.next().getLiteral("cnt").getInt(); + //count subclass+superClass + query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, superClass), true);System.out.println(query); + rs = executeSelectQuery(query); + int overlap = rs.next().getLiteral("cnt").getInt(); + + double precision = wald(superClassCnt, overlap); + double recall = wald(subClassCnt, overlap); + + double fScore = 0; + if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + fScore = Heuristics.getFScore(recall, precision, 3); + } else if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ + fScore = Heuristics.getFScore(recall, precision, 1); + } + + System.out.println(axiom); + System.out.println(subClassCnt + "|" + superClassCnt + "|" + overlap); + System.out.println("P=" + precision + "|R=" + recall +"|F=" + fScore); + + newAxioms.add(axiom.getAxiomWithoutAnnotations().getAnnotatedAxiom( + Collections.singleton(df.getOWLAnnotation(confidenceProperty, df.getOWLLiteral(fScore))))); + } catch (Exception e) { + e.printStackTrace(); } - //count subclass - Query query = converter.asQuery("?x", cls, true);System.out.println(query); - ResultSet rs = executeSelectQuery(query); - int subClassCnt = rs.next().getLiteral("cnt").getInt(); - //count subclass+superClass - query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, superClass), true);System.out.println(query); - rs = executeSelectQuery(query); - int overlap = rs.next().getLiteral("cnt").getInt(); - //count superClass - query = converter.asQuery("?x", superClass, true);System.out.println(query); - rs = executeSelectQuery(query); - int superClassCnt = rs.next().getLiteral("cnt").getInt(); - - double precision = wald(superClassCnt, overlap); - double recall = wald(subClassCnt, overlap); - - double fScore = 0; - if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ - fScore = Heuristics.getFScore(recall, precision, 3); - } else if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ - fScore = Heuristics.getFScore(recall, precision, 1); - } - - System.out.println(axiom); - System.out.println(subClassCnt + "|" + superClassCnt + "|" + overlap); - System.out.println("P=" + precision + "|R=" + recall +"|F=" + fScore); - - newAxioms.add(axiom.getAxiomWithoutAnnotations().getAnnotatedAxiom( - Collections.singleton(df.getOWLAnnotation(confidenceProperty, df.getOWLLiteral(fScore))))); } return newAxioms; @@ -1125,6 +1218,21 @@ return new AxiomScore(accuracy, confidence, total, success, total-success); } + private String render(OWLAxiom axiom){ + try { + 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; + } + public static void main(String[] args) throws Exception { ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 10:01:24
|
Revision: 3976 http://sourceforge.net/p/dl-learner/code/3976 Author: lorenz_b Date: 2013-05-10 10:01:19 +0000 (Fri, 10 May 2013) Log Message: ----------- Changed SPARQL converter. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-10 09:55:47 UTC (rev 3975) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-10 10:01:19 UTC (rev 3976) @@ -108,7 +108,16 @@ } public Query asQuery(String rootVariable, OWLClassExpression expr, boolean countQuery){ - return asQuery(rootVariable, expr, Collections.<OWLEntity>emptySet()); + String queryString = "SELECT "; + String triplePattern = convert(rootVariable, expr); + if(countQuery){ + queryString += "(COUNT(DISTINCT " + rootVariable + ") AS ?cnt) WHERE {"; + } else { + queryString += "DISTINCT " + rootVariable + " WHERE {"; + } + queryString += triplePattern; + queryString += "}"; + return QueryFactory.create(queryString, Syntax.syntaxARQ); } public Query asQuery(String rootVariable, OWLClassExpression expr, Set<? extends OWLEntity> variableEntities){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 09:55:51
|
Revision: 3975 http://sourceforge.net/p/dl-learner/code/3975 Author: lorenz_b Date: 2013-05-10 09:55:47 +0000 (Fri, 10 May 2013) Log Message: ----------- Continued filtering of trivial axioms in pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 07:59:48 UTC (rev 3974) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 09:55:47 UTC (rev 3975) @@ -97,6 +97,7 @@ import com.hp.hpl.jena.query.QueryExecutionFactory; 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.ModelFactory; @@ -131,7 +132,7 @@ private long maxExecutionTime = TimeUnit.SECONDS.toMillis(20); private int queryLimit = 10000; private boolean sampling = true; - private double sampleThreshold = 0.8; + private double sampleThreshold = 0.6; private int sampleSize = 100; private Set<String> entites2Ignore = Sets.newHashSet("subject", "Concept", "wikiPage"); //DBpedia schema @@ -169,7 +170,7 @@ Collections.shuffle(classesList, new Random(123)); classesList = classesList.subList(0, maxNrOfTestedClasses); classes = classesList; - //classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); +// classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); //get the maximum modal depth in the pattern axioms int maxModalDepth = maxModalDepth(patterns); @@ -202,11 +203,13 @@ // for each class for (NamedClass cls : classes) { logger.info("...on class " + cls + "..."); + OWLClass owlClass = df.getOWLClass(IRI.create(cls.getName())); Model fragment = class2Fragment.get(cls); - Map<OWLAxiom, Score> result = applyPattern(pattern, - df.getOWLClass(IRI.create(cls.getName())), fragment); + Map<OWLAxiom, Score> result = applyPattern(pattern, owlClass, fragment); Set<OWLAxiom> annotatedAxioms = asAnnotatedAxioms(result); filterOutTrivialAxioms(annotatedAxioms); + filterOutAxiomsBelowThreshold(annotatedAxioms, threshold); + annotatedAxioms = computeScoreGlobal(annotatedAxioms, owlClass); learnedAxioms.addAll(annotatedAxioms); printAxioms(annotatedAxioms, threshold); } @@ -248,7 +251,7 @@ return annotatedAxioms; } - private void printAxioms(Set<OWLAxiom> axioms, double threshold){ + private void printAxioms(Set<OWLAxiom> axioms, double threshold){OWLClassExpressionToSPARQLConverter c = new OWLClassExpressionToSPARQLConverter(); for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { OWLAxiom axiom = iter.next(); double accuracy = getAccuracy(axiom); @@ -341,6 +344,15 @@ return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); } + private void filterOutAxiomsBelowThreshold(Set<OWLAxiom> axioms, double threshold) { + for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { + OWLAxiom axiom = iter.next(); + if(getAccuracy(axiom) < threshold){ + iter.remove(); + } + } + } + private void filterOutTrivialAxioms(Set<OWLAxiom> axioms) { for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { OWLAxiom axiom = iter.next(); @@ -1015,6 +1027,94 @@ } } + private Set<OWLAxiom> computeScoreGlobal(Set<OWLAxiom> axioms, OWLClass cls){ + Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>(); + for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { + OWLAxiom axiom = iter.next(); + OWLClassExpression subClass; + OWLClassExpression superClass = null; + OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); + if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if (subClassOfAxiom.getSubClass().equals(cls)) { + superClass = subClassOfAxiom.getSuperClass(); + break; + } + } + } else if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); + } + //count subclass + Query query = converter.asQuery("?x", cls, true);System.out.println(query); + ResultSet rs = executeSelectQuery(query); + int subClassCnt = rs.next().getLiteral("cnt").getInt(); + //count subclass+superClass + query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, superClass), true);System.out.println(query); + rs = executeSelectQuery(query); + int overlap = rs.next().getLiteral("cnt").getInt(); + //count superClass + query = converter.asQuery("?x", superClass, true);System.out.println(query); + rs = executeSelectQuery(query); + int superClassCnt = rs.next().getLiteral("cnt").getInt(); + + double precision = wald(superClassCnt, overlap); + double recall = wald(subClassCnt, overlap); + + double fScore = 0; + if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + fScore = Heuristics.getFScore(recall, precision, 3); + } else if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ + fScore = Heuristics.getFScore(recall, precision, 1); + } + + System.out.println(axiom); + System.out.println(subClassCnt + "|" + superClassCnt + "|" + overlap); + System.out.println("P=" + precision + "|R=" + recall +"|F=" + fScore); + + newAxioms.add(axiom.getAxiomWithoutAnnotations().getAnnotatedAxiom( + Collections.singleton(df.getOWLAnnotation(confidenceProperty, df.getOWLLiteral(fScore))))); + + } + return newAxioms; + } + + private Score computeScoreGlobal(OWLAxiom axiom, OWLClass cls){ + OWLClassExpression subClass; + OWLClassExpression superClass = null; + OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); + if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if (subClassOfAxiom.getSubClass().equals(cls)) { + superClass = subClassOfAxiom.getSuperClass(); + break; + } + } + } else if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); + } + //count subclass+superClass + Query query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, superClass), true);System.out.println(query); + ResultSet rs = executeSelectQuery(query); + int subClassCnt = rs.next().getLiteral("cnt").getInt(); + //count superClass + query = converter.asQuery("?x", superClass, true);System.out.println(query); + rs = executeSelectQuery(query); + int superClassCnt = rs.next().getLiteral("cnt").getInt(); + + Score score = computeScore(superClassCnt, subClassCnt); + return score; + } + + private double wald(int total, int success){ + double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, success); + + double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + + return accuracy; + } + private Score computeScore(int total, int success){ double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, success); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 07:59:51
|
Revision: 3974 http://sourceforge.net/p/dl-learner/code/3974 Author: lorenz_b Date: 2013-05-10 07:59:48 +0000 (Fri, 10 May 2013) Log Message: ----------- Continued filtering of trivial axioms in pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 07:14:57 UTC (rev 3973) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 07:59:48 UTC (rev 3974) @@ -8,6 +8,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; @@ -33,6 +34,7 @@ import joptsimple.OptionParser; import joptsimple.OptionSet; +import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import org.apache.log4j.Logger; import org.coode.owlapi.turtle.TurtleOntologyFormat; import org.dllearner.core.EvaluatedAxiom; @@ -70,12 +72,14 @@ import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.util.OWLObjectDuplicator; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxOWLObjectRendererImpl; import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer; +import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.collect.HashMultiset; @@ -130,12 +134,26 @@ private double sampleThreshold = 0.8; private int sampleSize = 100; private Set<String> entites2Ignore = Sets.newHashSet("subject", "Concept", "wikiPage"); + //DBpedia schema + private OWLOntology dbpediaOntology; + private String ontologyURL = "http://downloads.dbpedia.org/3.8/dbpedia_3.8.owl.bz2"; + private OWLReasoner reasoner; public OWLAxiomPatternUsageEvaluation() { + try { + BZip2CompressorInputStream is = new BZip2CompressorInputStream(new URL(ontologyURL).openStream()); + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + dbpediaOntology = manager.loadOntologyFromOntologyDocument(is); + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbpediaOntology); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } } - - public void runUsingFragmentExtraction(SparqlEndpoint endpoint, OWLOntology patternOntology, File outputFile, int maxNrOfTestedClasses){ ks = new SparqlEndpointKS(endpoint, cache); SPARQLReasoner reasoner = new SPARQLReasoner(ks, cache); @@ -151,7 +169,7 @@ Collections.shuffle(classesList, new Random(123)); classesList = classesList.subList(0, maxNrOfTestedClasses); classes = classesList; - classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); + //classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); //get the maximum modal depth in the pattern axioms int maxModalDepth = maxModalDepth(patterns); @@ -202,7 +220,7 @@ } } if(sampling){ - List<OWLAxiom> sample = createSample(ontology);//createSample(ontology, classes); + List<OWLAxiom> sample = createSample(ontology);//, classes); List<String> lines = new ArrayList<String>(); for (OWLAxiom axiom : sample) { double accuracy = getAccuracy(axiom); @@ -283,11 +301,42 @@ NavigableSet<Double> keySet = (NavigableSet<Double>)accuracyWithAxioms.keySet(); Double score = keySet.first(); Collection<OWLAxiom> axiomsWithHighestScore = accuracyWithAxioms.get(score); - for (OWLAxiom ax : axiomsWithHighestScore) { - System.out.println(ax + ":" + getAccuracy(ax)); + Map<OWLAxiom, OWLClassExpression> superClasses = new HashMap<OWLAxiom, OWLClassExpression>(); + for (OWLAxiom axiom : axiomsWithHighestScore) { + if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if (subClassOfAxiom.getSubClass().equals(owlClass)) { + superClasses.put(axiom, subClassOfAxiom.getSuperClass()); + break; + } + } + } + if (axiom.isOfType(AxiomType.SUBCLASS_OF)) { + superClasses.put(axiom, ((OWLSubClassOfAxiom) axiom).getSuperClass()); + } } + + for (Entry<OWLAxiom, OWLClassExpression> entry : superClasses.entrySet()) { + OWLAxiom axiom1 = entry.getKey(); + OWLClassExpression ce1 = entry.getValue(); + boolean remove = false; + for (Entry<OWLAxiom, OWLClassExpression> entry2 : superClasses.entrySet()) { + OWLAxiom axiom2 = entry2.getKey(); + if(!axiom1.equals(axiom2)){ + OWLClassExpression ce2 = entry2.getValue(); + if(reasoner.isEntailed(df.getOWLSubClassOfAxiom(ce2, ce1))){ + remove = true; + break; + } + } + } + if(remove){ + axiomsWithHighestScore.remove(axiom1); + } + } + axiomList.addAll(axiomsWithHighestScore); } - Collections.shuffle(axiomList, new Random(123)); return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); } @@ -296,6 +345,10 @@ for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { OWLAxiom axiom = iter.next(); if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { + if(((OWLEquivalentClassesAxiom) axiom).getClassExpressions().size() == 1){ + iter.remove(); + continue; + } Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { if (!subClassOfAxiom.getSubClass().isAnonymous()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 07:15:01
|
Revision: 3973 http://sourceforge.net/p/dl-learner/code/3973 Author: lorenz_b Date: 2013-05-10 07:14:57 +0000 (Fri, 10 May 2013) Log Message: ----------- Added filtering of trivial axioms in pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 06:39:31 UTC (rev 3972) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 07:14:57 UTC (rev 3973) @@ -19,11 +19,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.NavigableSet; import java.util.Random; import java.util.Set; import java.util.TreeSet; @@ -79,8 +79,10 @@ import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.collect.HashMultiset; +import com.google.common.collect.Multimap; import com.google.common.collect.Multiset; import com.google.common.collect.Sets; +import com.google.common.collect.TreeMultimap; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; @@ -149,7 +151,7 @@ Collections.shuffle(classesList, new Random(123)); classesList = classesList.subList(0, maxNrOfTestedClasses); classes = classesList; -// classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); + classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); //get the maximum modal depth in the pattern axioms int maxModalDepth = maxModalDepth(patterns); @@ -187,6 +189,7 @@ df.getOWLClass(IRI.create(cls.getName())), fragment); Set<OWLAxiom> annotatedAxioms = asAnnotatedAxioms(result); filterOutTrivialAxioms(annotatedAxioms); + learnedAxioms.addAll(annotatedAxioms); printAxioms(annotatedAxioms, threshold); } ontology = save(pattern, learnedAxioms, file); @@ -199,7 +202,7 @@ } } if(sampling){ - List<OWLAxiom> sample = createSample(ontology); + List<OWLAxiom> sample = createSample(ontology);//createSample(ontology, classes); List<String> lines = new ArrayList<String>(); for (OWLAxiom axiom : sample) { double accuracy = getAccuracy(axiom); @@ -264,6 +267,31 @@ return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); } + private List<OWLAxiom> createSample(OWLOntology ontology, Collection<NamedClass> classes){ + List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>(); + for (NamedClass cls : classes) { + OWLClass owlClass = df.getOWLClass(IRI.create(cls.getName())); + Set<OWLAxiom> referencingAxioms = ontology.getReferencingAxioms(owlClass); + Multimap<Double, OWLAxiom> accuracyWithAxioms = TreeMultimap.create(); + for (OWLAxiom axiom : referencingAxioms) { + double accuracy = getAccuracy(axiom); + if(accuracy >= sampleThreshold){ + accuracyWithAxioms.put(accuracy, axiom); + } + } + //pick the set of axioms with highest score + NavigableSet<Double> keySet = (NavigableSet<Double>)accuracyWithAxioms.keySet(); + Double score = keySet.first(); + Collection<OWLAxiom> axiomsWithHighestScore = accuracyWithAxioms.get(score); + for (OWLAxiom ax : axiomsWithHighestScore) { + System.out.println(ax + ":" + getAccuracy(ax)); + } + } + + Collections.shuffle(axiomList, new Random(123)); + return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); + } + private void filterOutTrivialAxioms(Set<OWLAxiom> axioms) { for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { OWLAxiom axiom = iter.next(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-10 06:39:35
|
Revision: 3972 http://sourceforge.net/p/dl-learner/code/3972 Author: lorenz_b Date: 2013-05-10 06:39:31 +0000 (Fri, 10 May 2013) Log Message: ----------- Added filtering of trivial axioms in pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 15:57:17 UTC (rev 3971) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-10 06:39:31 UTC (rev 3972) @@ -49,7 +49,6 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; -import org.semanticweb.elk.reasoner.saturation.classes.SuperClassExpression; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.OWLObjectRenderer; import org.semanticweb.owlapi.io.ToStringRenderer; @@ -121,7 +120,7 @@ private double threshold = 0.6; private OWLAnnotationProperty confidenceProperty = df.getOWLAnnotationProperty(IRI.create("http://dl-learner.org/pattern/confidence")); - private long maxFragmentExtractionTime = TimeUnit.SECONDS.toMillis(10); + private long maxFragmentExtractionTime = TimeUnit.SECONDS.toMillis(60); private OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); private long maxExecutionTime = TimeUnit.SECONDS.toMillis(20); private int queryLimit = 10000; @@ -134,66 +133,6 @@ } - public void run(SparqlEndpoint endpoint, OWLOntology ontology, File outputFile, int maxNrOfTestedClasses){ - ks = new SparqlEndpointKS(endpoint, cache); - SPARQLReasoner reasoner = new SPARQLReasoner(ks, cache); - - //get the axiom patterns to evaluate - List<OWLAxiom> patterns = getPatternsToEvaluate(ontology); - - //get all classes in KB - Collection<NamedClass> classes = reasoner.getTypes(ns); - List<NamedClass> classesList = new ArrayList<NamedClass>(classes); - Collections.shuffle(classesList, new Random(123)); - classesList = classesList.subList(0, maxNrOfTestedClasses); - classes = classesList; - - //for each pattern - for (OWLAxiom pattern : patterns) { - File file = new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations.ttl"); - if(!file.exists()){ - //if pattern is equivalent classes axiom, we need to get the subclass axiom where the named class is the subclass - if(pattern.isOfType(AxiomType.EQUIVALENT_CLASSES)){ - Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)pattern).asOWLSubClassOfAxioms(); - for (OWLSubClassOfAxiom axiom : subClassOfAxioms) { - if(!axiom.getSubClass().isAnonymous()){ - pattern = axiom; - break; - } - } - } - if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ - logger.info("Processing " + pattern + "..."); - Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); - //for each class - int i = 1; - for (NamedClass cls : classes) { - logger.info("Processing " + cls + "..."); - - Map<OWLAxiom, Score> result = evaluateUsingFragmentExtraction(pattern, cls); - axioms2Score.putAll(result); - - for (Entry<OWLAxiom, Score> entry : result.entrySet()) { - OWLAxiom axiom = entry.getKey(); - Score score = entry.getValue(); - if(score.getAccuracy() >= threshold){ - logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); - } - } - - //wait some time to avoid flooding of endpoint - try { - Thread.sleep(waitingTime); - } catch (InterruptedException e) { - e.printStackTrace(); - } -// if(i++ == 3) break; - } - save(pattern, axioms2Score, file); - } - } - } - } public void runUsingFragmentExtraction(SparqlEndpoint endpoint, OWLOntology patternOntology, File outputFile, int maxNrOfTestedClasses){ ks = new SparqlEndpointKS(endpoint, cache); @@ -210,6 +149,7 @@ Collections.shuffle(classesList, new Random(123)); classesList = classesList.subList(0, maxNrOfTestedClasses); classes = classesList; +// classes = Collections.singleton(new NamedClass("http://dbpedia.org/ontology/ChristianBishop")); //get the maximum modal depth in the pattern axioms int maxModalDepth = maxModalDepth(patterns); @@ -238,26 +178,18 @@ OWLOntology ontology = null; if(!file.exists()){ logger.info("Applying pattern " + pattern + "..."); - // if pattern is equivalent classes axiom, we need to get the - // subclass axiom where the named class is the subclass - Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); + Set<OWLAxiom> learnedAxioms = new HashSet<OWLAxiom>(); // for each class for (NamedClass cls : classes) { logger.info("...on class " + cls + "..."); Model fragment = class2Fragment.get(cls); Map<OWLAxiom, Score> result = applyPattern(pattern, df.getOWLClass(IRI.create(cls.getName())), fragment); - axioms2Score.putAll(result); - - for (Entry<OWLAxiom, Score> entry : result.entrySet()) { - OWLAxiom axiom = entry.getKey(); - Score score = entry.getValue(); - if (score.getAccuracy() >= threshold) { - logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); - } - } + Set<OWLAxiom> annotatedAxioms = asAnnotatedAxioms(result); + filterOutTrivialAxioms(annotatedAxioms); + printAxioms(annotatedAxioms, threshold); } - ontology = save(pattern, axioms2Score, file); + ontology = save(pattern, learnedAxioms, file); } else { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); try { @@ -282,8 +214,32 @@ } } + private Set<OWLAxiom> asAnnotatedAxioms(Map<OWLAxiom, Score> axioms2Score){ + Set<OWLAxiom> annotatedAxioms = new HashSet<OWLAxiom>(); + for (Entry<OWLAxiom, Score> entry : axioms2Score.entrySet()) { + OWLAxiom axiom = entry.getKey(); + Score score = entry.getValue(); + if(score.getAccuracy() >= threshold){ + annotatedAxioms.add(axiom.getAnnotatedAxiom(Collections.singleton(df.getOWLAnnotation(confidenceProperty, df.getOWLLiteral(score.getAccuracy()))))); + + } + } + return annotatedAxioms; + } + + private void printAxioms(Set<OWLAxiom> axioms, double threshold){ + for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { + OWLAxiom axiom = iter.next(); + double accuracy = getAccuracy(axiom); + if (accuracy >= threshold) { + logger.info(axiom + "(" + format.format(accuracy) + ")"); + } + } + } + private List<OWLAxiom> createSample(OWLOntology ontology){ Set<OWLAxiom> axioms = ontology.getAxioms(); + filterOutTrivialAxioms(axioms); for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { OWLAxiom axiom = iter.next(); double accuracy = getAccuracy(axiom); @@ -300,49 +256,53 @@ } if(remove){ iter.remove(); - } else { - if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ - Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)axiom).asOWLSubClassOfAxioms(); - for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { - if(!subClassOfAxiom.getSubClass().isAnonymous()){ - axiom = subClassOfAxiom; + } + } + } + List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>(axioms); + Collections.shuffle(axiomList, new Random(123)); + return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); + } + + private void filterOutTrivialAxioms(Set<OWLAxiom> axioms) { + for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { + OWLAxiom axiom = iter.next(); + if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom) axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if (!subClassOfAxiom.getSubClass().isAnonymous()) { + axiom = subClassOfAxiom; + break; + } + } + } + // check for some trivial axioms + if (axiom.isOfType(AxiomType.SUBCLASS_OF)) { + OWLClassExpression subClass = ((OWLSubClassOfAxiom) axiom).getSubClass(); + OWLClassExpression superClass = ((OWLSubClassOfAxiom) axiom).getSuperClass(); + if (superClass.isOWLThing()) { + iter.remove(); + } else if (subClass.equals(superClass)) { + iter.remove(); + } else if (superClass instanceof OWLObjectIntersectionOf) { + List<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperandsAsList(); + + if (operands.size() == 1) {// how can this happen? + iter.remove(); + } else if (operands.size() > ((OWLObjectIntersectionOf) superClass).getOperands().size()) {// duplicates + iter.remove(); + } else { + for (OWLClassExpression op : operands) { + if (op.isOWLThing() || op.equals(subClass)) { + iter.remove(); break; } } } - //check for some trivial axioms - if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ - OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); - OWLClassExpression superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); - if(superClass.isOWLThing()){ - iter.remove(); - } else if(subClass.equals(superClass)){ - iter.remove(); - } else if(superClass instanceof OWLObjectIntersectionOf){ - List<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperandsAsList(); - - - if(operands.size() == 1){//how can this happen? - iter.remove(); - } else if(operands.size() > ((OWLObjectIntersectionOf) superClass).getOperands().size()){//duplicates - iter.remove(); - } else { - for (OWLClassExpression op : operands) { - if(op.isOWLThing() || op.equals(subClass)){ - iter.remove(); - break; - } - } - } - } - } } - } + } - List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>(axioms); - Collections.shuffle(axiomList, new Random(123)); - return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); } private double getAccuracy(OWLAxiom axiom){ @@ -432,12 +392,13 @@ } } logger.info("...got " + fragment.size() + " triples."); - class2Fragment.put(cls, fragment); try { fragment.write(new FileOutputStream(file), "TURTLE"); } catch (FileNotFoundException e) { e.printStackTrace(); } + filterModel(fragment); + class2Fragment.put(cls, fragment); } return class2Fragment; } @@ -453,6 +414,8 @@ } if(st.getPredicate().hasURI("http://xmlns.com/foaf/0.1/depiction") || st.getPredicate().hasURI("http://dbpedia.org/ontology/thumbnail")){ statements2Remove.add(st); + } else if(!st.getPredicate().equals(RDF.type) && !st.getPredicate().getURI().startsWith("http://dbpedia.org/ontology/")){ + statements2Remove.add(st); } } model.remove(statements2Remove); @@ -672,6 +635,9 @@ } else if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ patternSubClass = ((OWLSubClassOfAxiom) pattern).getSubClass(); patternSuperClass = ((OWLSubClassOfAxiom) pattern).getSuperClass(); + } else if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ + patternSubClass = ((OWLSubClassOfAxiom) pattern).getSubClass(); + patternSuperClass = ((OWLSubClassOfAxiom) pattern).getSuperClass(); } else { logger.warn("Pattern " + pattern + " not supported yet."); return axioms2Score; @@ -722,6 +688,7 @@ int total = resources.size(); for (OWLAxiom axiom : instantiations.elementSet()) { int frequency = instantiations.count(axiom); +// System.out.println(axiom + ":" + frequency); Score score = computeScore(total, Math.min(total, frequency)); axioms2Score.put(axiom, score); } @@ -825,19 +792,10 @@ return template.asQuery(); } - private OWLOntology save(OWLAxiom pattern, Map<OWLAxiom, Score> axioms2Score, File file){ + private OWLOntology save(OWLAxiom pattern, Set<OWLAxiom> learnedAxioms, File file){ try { - Set<OWLAxiom> annotatedAxioms = new HashSet<OWLAxiom>(); - for (Entry<OWLAxiom, Score> entry : axioms2Score.entrySet()) { - OWLAxiom axiom = entry.getKey(); - Score score = entry.getValue(); - if(score.getAccuracy() >= threshold){ - annotatedAxioms.add(axiom.getAnnotatedAxiom(Collections.singleton(df.getOWLAnnotation(confidenceProperty, df.getOWLLiteral(score.getAccuracy()))))); - - } - } OWLOntologyManager man = OWLManager.createOWLOntologyManager(); - OWLOntology ontology = man.createOntology(annotatedAxioms); + OWLOntology ontology = man.createOntology(learnedAxioms); man.saveOntology(ontology, new TurtleOntologyFormat(), new FileOutputStream(file)); return ontology; } catch (OWLOntologyCreationException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 15:57:21
|
Revision: 3971 http://sourceforge.net/p/dl-learner/code/3971 Author: lorenz_b Date: 2013-05-09 15:57:17 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 15:22:50 UTC (rev 3970) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 15:57:17 UTC (rev 3971) @@ -290,48 +290,54 @@ if(accuracy < sampleThreshold){ iter.remove(); } else { - if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ - Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)axiom).asOWLSubClassOfAxioms(); - for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { - if(!subClassOfAxiom.getSubClass().isAnonymous()){ - axiom = subClassOfAxiom; - break; + String axiomString = axiomRenderer.render(axiom); + boolean remove = false; + for (String s : entites2Ignore) { + if(axiomString.contains(s)){ + remove = true; + break; + } + } + if(remove){ + iter.remove(); + } else { + if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if(!subClassOfAxiom.getSubClass().isAnonymous()){ + axiom = subClassOfAxiom; + break; + } } } - } - //check for some trivial axioms - if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ - OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); - OWLClassExpression superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); - if(superClass.isOWLThing()){ - iter.remove(); - } else if(subClass.equals(superClass)){ - iter.remove(); - } else if(superClass instanceof OWLObjectIntersectionOf){ - List<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperandsAsList(); - - - if(operands.size() == 1){//how can this happen? + //check for some trivial axioms + if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); + OWLClassExpression superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); + if(superClass.isOWLThing()){ iter.remove(); - } else if(operands.size() > ((OWLObjectIntersectionOf) superClass).getOperands().size()){//duplicates + } else if(subClass.equals(superClass)){ iter.remove(); - } else { - for (OWLClassExpression op : operands) { - if(op.isOWLThing() || op.equals(subClass)){ - iter.remove(); - break; + } else if(superClass instanceof OWLObjectIntersectionOf){ + List<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperandsAsList(); + + + if(operands.size() == 1){//how can this happen? + iter.remove(); + } else if(operands.size() > ((OWLObjectIntersectionOf) superClass).getOperands().size()){//duplicates + iter.remove(); + } else { + for (OWLClassExpression op : operands) { + if(op.isOWLThing() || op.equals(subClass)){ + iter.remove(); + break; + } } } - } - } else { - String classString = superClass.toString(); - for (String s : entites2Ignore) { - if(classString.contains(s)){ - iter.remove(); - } - } + } } } + } } List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>(axioms); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 15:22:55
|
Revision: 3970 http://sourceforge.net/p/dl-learner/code/3970 Author: lorenz_b Date: 2013-05-09 15:22:50 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 14:04:53 UTC (rev 3969) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 15:22:50 UTC (rev 3970) @@ -317,7 +317,7 @@ iter.remove(); } else { for (OWLClassExpression op : operands) { - if(op.isOWLThing()){ + if(op.isOWLThing() || op.equals(subClass)){ iter.remove(); break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 14:04:57
|
Revision: 3969 http://sourceforge.net/p/dl-learner/code/3969 Author: lorenz_b Date: 2013-05-09 14:04:53 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 13:41:45 UTC (rev 3968) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 14:04:53 UTC (rev 3969) @@ -81,6 +81,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; +import com.google.common.collect.Sets; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; @@ -127,6 +128,7 @@ private boolean sampling = true; private double sampleThreshold = 0.8; private int sampleSize = 100; + private Set<String> entites2Ignore = Sets.newHashSet("subject", "Concept", "wikiPage"); public OWLAxiomPatternUsageEvaluation() { } @@ -321,8 +323,13 @@ } } } - } else if(superClass.toString().contains("Concept") || superClass.toString().contains("subject")){ - iter.remove(); + } else { + String classString = superClass.toString(); + for (String s : entites2Ignore) { + if(classString.contains(s)){ + iter.remove(); + } + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 13:41:49
|
Revision: 3968 http://sourceforge.net/p/dl-learner/code/3968 Author: lorenz_b Date: 2013-05-09 13:41:45 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 13:27:03 UTC (rev 3967) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 13:41:45 UTC (rev 3968) @@ -288,6 +288,15 @@ if(accuracy < sampleThreshold){ iter.remove(); } else { + if(axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)){ + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)axiom).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom subClassOfAxiom : subClassOfAxioms) { + if(!subClassOfAxiom.getSubClass().isAnonymous()){ + axiom = subClassOfAxiom; + break; + } + } + } //check for some trivial axioms if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); @@ -297,11 +306,19 @@ } else if(subClass.equals(superClass)){ iter.remove(); } else if(superClass instanceof OWLObjectIntersectionOf){ - Set<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperands(); - for (OWLClassExpression op : operands) { - if(op.isOWLThing()){ - iter.remove(); - break; + List<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperandsAsList(); + + + if(operands.size() == 1){//how can this happen? + iter.remove(); + } else if(operands.size() > ((OWLObjectIntersectionOf) superClass).getOperands().size()){//duplicates + iter.remove(); + } else { + for (OWLClassExpression op : operands) { + if(op.isOWLThing()){ + iter.remove(); + break; + } } } } else if(superClass.toString().contains("Concept") || superClass.toString().contains("subject")){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 13:27:06
|
Revision: 3967 http://sourceforge.net/p/dl-learner/code/3967 Author: lorenz_b Date: 2013-05-09 13:27:03 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 13:21:27 UTC (rev 3966) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 13:27:03 UTC (rev 3967) @@ -212,8 +212,22 @@ //get the maximum modal depth in the pattern axioms int maxModalDepth = maxModalDepth(patterns); + //check if we need the fragments + boolean fragmentsNeeded = false; + for (OWLAxiom pattern : patterns) { + //run if not already exists a result on disk + File file = new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations.ttl"); + if(!file.exists()){ + fragmentsNeeded = true; + break; + } + } + //extract fragment for each class only once - Map<NamedClass, Model> class2Fragment = extractFragments(classes, maxModalDepth); + Map<NamedClass, Model> class2Fragment = null; + if(fragmentsNeeded){ + class2Fragment = extractFragments(classes, maxModalDepth); + } //for each pattern for (OWLAxiom pattern : patterns) { @@ -273,25 +287,26 @@ double accuracy = getAccuracy(axiom); if(accuracy < sampleThreshold){ iter.remove(); - } - //check for some trivial axioms - if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ - OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); - OWLClassExpression superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); - if(superClass.isOWLThing()){ - iter.remove(); - } else if(subClass.equals(superClass)){ - iter.remove(); - } else if(superClass instanceof OWLObjectIntersectionOf){ - Set<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperands(); - for (OWLClassExpression op : operands) { - if(op.isOWLThing()){ - iter.remove(); - break; + } else { + //check for some trivial axioms + if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); + OWLClassExpression superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); + if(superClass.isOWLThing()){ + iter.remove(); + } else if(subClass.equals(superClass)){ + iter.remove(); + } else if(superClass instanceof OWLObjectIntersectionOf){ + Set<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperands(); + for (OWLClassExpression op : operands) { + if(op.isOWLThing()){ + iter.remove(); + break; + } } + } else if(superClass.toString().contains("Concept") || superClass.toString().contains("subject")){ + iter.remove(); } - } else if(superClass.toString().contains("Concept") || superClass.toString().contains("subject")){ - iter.remove(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 13:21:31
|
Revision: 3966 http://sourceforge.net/p/dl-learner/code/3966 Author: lorenz_b Date: 2013-05-09 13:21:27 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 03:51:49 UTC (rev 3965) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 13:21:27 UTC (rev 3966) @@ -6,6 +6,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.SocketTimeoutException; import java.net.URI; @@ -17,6 +18,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -47,11 +49,13 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; +import org.semanticweb.elk.reasoner.saturation.classes.SuperClassExpression; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.OWLObjectRenderer; import org.semanticweb.owlapi.io.ToStringRenderer; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAnnotationProperty; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; @@ -59,7 +63,9 @@ import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; +import org.semanticweb.owlapi.model.OWLLiteral; import org.semanticweb.owlapi.model.OWLObjectComplementOf; +import org.semanticweb.owlapi.model.OWLObjectIntersectionOf; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; @@ -71,11 +77,14 @@ import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxOWLObjectRendererImpl; import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer; +import com.google.common.base.Charsets; +import com.google.common.base.Joiner; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; +import com.google.common.io.Files; import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; @@ -115,6 +124,9 @@ private OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); private long maxExecutionTime = TimeUnit.SECONDS.toMillis(20); private int queryLimit = 10000; + private boolean sampling = true; + private double sampleThreshold = 0.8; + private int sampleSize = 100; public OWLAxiomPatternUsageEvaluation() { } @@ -181,12 +193,12 @@ } } - public void runUsingFragmentExtraction(SparqlEndpoint endpoint, OWLOntology ontology, File outputFile, int maxNrOfTestedClasses){ + public void runUsingFragmentExtraction(SparqlEndpoint endpoint, OWLOntology patternOntology, File outputFile, int maxNrOfTestedClasses){ ks = new SparqlEndpointKS(endpoint, cache); SPARQLReasoner reasoner = new SPARQLReasoner(ks, cache); //get the axiom patterns to evaluate - List<OWLAxiom> patterns = getPatternsToEvaluate(ontology); + List<OWLAxiom> patterns = getPatternsToEvaluate(patternOntology); //get all classes in KB Collection<NamedClass> classes = reasoner.getTypes(ns); @@ -207,6 +219,7 @@ for (OWLAxiom pattern : patterns) { //run if not already exists a result on disk File file = new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations.ttl"); + OWLOntology ontology = null; if(!file.exists()){ logger.info("Applying pattern " + pattern + "..."); // if pattern is equivalent classes axiom, we need to get the @@ -228,11 +241,75 @@ } } } - save(pattern, axioms2Score, file); + ontology = save(pattern, axioms2Score, file); + } else { + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + try { + ontology = man.loadOntologyFromOntologyDocument(file); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } } + if(sampling){ + List<OWLAxiom> sample = createSample(ontology); + List<String> lines = new ArrayList<String>(); + for (OWLAxiom axiom : sample) { + double accuracy = getAccuracy(axiom); + lines.add(axiomRenderer.render(axiom) + "," + format.format(accuracy)); + } + try { + Files.write(Joiner.on("\n").join(lines), new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations-sample.csv"), Charsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + } } } + private List<OWLAxiom> createSample(OWLOntology ontology){ + Set<OWLAxiom> axioms = ontology.getAxioms(); + for (Iterator<OWLAxiom> iter = axioms.iterator(); iter.hasNext();) { + OWLAxiom axiom = iter.next(); + double accuracy = getAccuracy(axiom); + if(accuracy < sampleThreshold){ + iter.remove(); + } + //check for some trivial axioms + if(axiom.isOfType(AxiomType.SUBCLASS_OF)){ + OWLClassExpression subClass = ((OWLSubClassOfAxiom)axiom).getSubClass(); + OWLClassExpression superClass = ((OWLSubClassOfAxiom)axiom).getSuperClass(); + if(superClass.isOWLThing()){ + iter.remove(); + } else if(subClass.equals(superClass)){ + iter.remove(); + } else if(superClass instanceof OWLObjectIntersectionOf){ + Set<OWLClassExpression> operands = ((OWLObjectIntersectionOf) superClass).getOperands(); + for (OWLClassExpression op : operands) { + if(op.isOWLThing()){ + iter.remove(); + break; + } + } + } else if(superClass.toString().contains("Concept") || superClass.toString().contains("subject")){ + iter.remove(); + } + } + } + List<OWLAxiom> axiomList = new ArrayList<OWLAxiom>(axioms); + Collections.shuffle(axiomList, new Random(123)); + return axiomList.subList(0, Math.min(sampleSize, axiomList.size())); + } + + private double getAccuracy(OWLAxiom axiom){ + Set<OWLAnnotation> annotations = axiom.getAnnotations(confidenceProperty); + if(!annotations.isEmpty()){ + OWLAnnotation annotation = annotations.iterator().next(); + double accuracy = ((OWLLiteral)annotation.getValue()).parseDouble(); + return accuracy; + } + return -1; + } + private int maxModalDepth(List<OWLAxiom> patterns) { int maxModalDepth = 1; for (OWLAxiom pattern : patterns) { @@ -329,6 +406,9 @@ if(st.getPredicate().equals(RDF.type) && !st.getObject().asResource().getURI().startsWith("http://dbpedia.org/ontology/")){ statements2Remove.add(st); } + if(st.getPredicate().hasURI("http://xmlns.com/foaf/0.1/depiction") || st.getPredicate().hasURI("http://dbpedia.org/ontology/thumbnail")){ + statements2Remove.add(st); + } } model.remove(statements2Remove); } @@ -700,7 +780,7 @@ return template.asQuery(); } - private void save(OWLAxiom pattern, Map<OWLAxiom, Score> axioms2Score, File file){ + private OWLOntology save(OWLAxiom pattern, Map<OWLAxiom, Score> axioms2Score, File file){ try { Set<OWLAxiom> annotatedAxioms = new HashSet<OWLAxiom>(); for (Entry<OWLAxiom, Score> entry : axioms2Score.entrySet()) { @@ -714,6 +794,7 @@ OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLOntology ontology = man.createOntology(annotatedAxioms); man.saveOntology(ontology, new TurtleOntologyFormat(), new FileOutputStream(file)); + return ontology; } catch (OWLOntologyCreationException e) { e.printStackTrace(); } catch (OWLOntologyStorageException e) { @@ -721,6 +802,7 @@ } catch (FileNotFoundException e) { e.printStackTrace(); } + return null; } private void save(Set<EvaluatedAxiom> evaluatedAxioms){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-09 03:51:52
|
Revision: 3965 http://sourceforge.net/p/dl-learner/code/3965 Author: lorenz_b Date: 2013-05-09 03:51:49 +0000 (Thu, 09 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 21:16:05 UTC (rev 3964) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-09 03:51:49 UTC (rev 3965) @@ -85,7 +85,6 @@ 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.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.sparql.engine.http.QueryEngineHTTP; @@ -137,44 +136,47 @@ //for each pattern for (OWLAxiom pattern : patterns) { - //if pattern is equivalent classes axiom, we need to get the subclass axiom where the named class is the subclass - if(pattern.isOfType(AxiomType.EQUIVALENT_CLASSES)){ - Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)pattern).asOWLSubClassOfAxioms(); - for (OWLSubClassOfAxiom axiom : subClassOfAxioms) { - if(!axiom.getSubClass().isAnonymous()){ - pattern = axiom; - break; + File file = new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations.ttl"); + if(!file.exists()){ + //if pattern is equivalent classes axiom, we need to get the subclass axiom where the named class is the subclass + if(pattern.isOfType(AxiomType.EQUIVALENT_CLASSES)){ + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)pattern).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom axiom : subClassOfAxioms) { + if(!axiom.getSubClass().isAnonymous()){ + pattern = axiom; + break; + } } } - } - if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ - logger.info("Processing " + pattern + "..."); - Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); - //for each class - int i = 1; - for (NamedClass cls : classes) { - logger.info("Processing " + cls + "..."); - - Map<OWLAxiom, Score> result = evaluateUsingFragmentExtraction(pattern, cls); - axioms2Score.putAll(result); - - for (Entry<OWLAxiom, Score> entry : result.entrySet()) { - OWLAxiom axiom = entry.getKey(); - Score score = entry.getValue(); - if(score.getAccuracy() >= threshold){ - logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); + if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ + logger.info("Processing " + pattern + "..."); + Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); + //for each class + int i = 1; + for (NamedClass cls : classes) { + logger.info("Processing " + cls + "..."); + + Map<OWLAxiom, Score> result = evaluateUsingFragmentExtraction(pattern, cls); + axioms2Score.putAll(result); + + for (Entry<OWLAxiom, Score> entry : result.entrySet()) { + OWLAxiom axiom = entry.getKey(); + Score score = entry.getValue(); + if(score.getAccuracy() >= threshold){ + logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); + } } + + //wait some time to avoid flooding of endpoint + try { + Thread.sleep(waitingTime); + } catch (InterruptedException e) { + e.printStackTrace(); + } +// if(i++ == 3) break; } - - //wait some time to avoid flooding of endpoint - try { - Thread.sleep(waitingTime); - } catch (InterruptedException e) { - e.printStackTrace(); - } -// if(i++ == 3) break; + save(pattern, axioms2Score, file); } - save(pattern, axioms2Score); } } } @@ -203,28 +205,31 @@ //for each pattern for (OWLAxiom pattern : patterns) { - logger.info("Applying pattern " + pattern + "..."); - // if pattern is equivalent classes axiom, we need to get the - // subclass axiom where the named class is the subclass - Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); - // for each class - for (NamedClass cls : classes) { - logger.info("...on class " + cls + "..."); - Model fragment = class2Fragment.get(cls); - Map<OWLAxiom, Score> result = applyPattern(pattern, - df.getOWLClass(IRI.create(cls.getName())), fragment); - axioms2Score.putAll(result); + //run if not already exists a result on disk + File file = new File(axiomRenderer.render(pattern).replace(" ", "_") + "-instantiations.ttl"); + if(!file.exists()){ + logger.info("Applying pattern " + pattern + "..."); + // if pattern is equivalent classes axiom, we need to get the + // subclass axiom where the named class is the subclass + Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); + // for each class + for (NamedClass cls : classes) { + logger.info("...on class " + cls + "..."); + Model fragment = class2Fragment.get(cls); + Map<OWLAxiom, Score> result = applyPattern(pattern, + df.getOWLClass(IRI.create(cls.getName())), fragment); + axioms2Score.putAll(result); - for (Entry<OWLAxiom, Score> entry : result.entrySet()) { - OWLAxiom axiom = entry.getKey(); - Score score = entry.getValue(); - if (score.getAccuracy() >= threshold) { - logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); + for (Entry<OWLAxiom, Score> entry : result.entrySet()) { + OWLAxiom axiom = entry.getKey(); + Score score = entry.getValue(); + if (score.getAccuracy() >= threshold) { + logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); + } } } + save(pattern, axioms2Score, file); } - save(pattern, axioms2Score); - } } @@ -695,7 +700,7 @@ return template.asQuery(); } - private void save(OWLAxiom pattern, Map<OWLAxiom, Score> axioms2Score){ + private void save(OWLAxiom pattern, Map<OWLAxiom, Score> axioms2Score, File file){ try { Set<OWLAxiom> annotatedAxioms = new HashSet<OWLAxiom>(); for (Entry<OWLAxiom, Score> entry : axioms2Score.entrySet()) { @@ -708,8 +713,7 @@ } OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLOntology ontology = man.createOntology(annotatedAxioms); - String filename = axiomRenderer.render(pattern).replace(" ", "_"); - man.saveOntology(ontology, new TurtleOntologyFormat(), new FileOutputStream(filename + "-instantiations.ttl")); + man.saveOntology(ontology, new TurtleOntologyFormat(), new FileOutputStream(file)); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } catch (OWLOntologyStorageException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-08 21:16:10
|
Revision: 3964 http://sourceforge.net/p/dl-learner/code/3964 Author: lorenz_b Date: 2013-05-08 21:16:05 +0000 (Wed, 08 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 21:03:43 UTC (rev 3963) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 21:16:05 UTC (rev 3964) @@ -204,44 +204,27 @@ //for each pattern for (OWLAxiom pattern : patterns) { logger.info("Applying pattern " + pattern + "..."); - //if pattern is equivalent classes axiom, we need to get the subclass axiom where the named class is the subclass - if(pattern.isOfType(AxiomType.EQUIVALENT_CLASSES)){ - Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)pattern).asOWLSubClassOfAxioms(); - for (OWLSubClassOfAxiom axiom : subClassOfAxioms) { - if(!axiom.getSubClass().isAnonymous()){ - pattern = axiom; - break; + // if pattern is equivalent classes axiom, we need to get the + // subclass axiom where the named class is the subclass + Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); + // for each class + for (NamedClass cls : classes) { + logger.info("...on class " + cls + "..."); + Model fragment = class2Fragment.get(cls); + Map<OWLAxiom, Score> result = applyPattern(pattern, + df.getOWLClass(IRI.create(cls.getName())), fragment); + axioms2Score.putAll(result); + + for (Entry<OWLAxiom, Score> entry : result.entrySet()) { + OWLAxiom axiom = entry.getKey(); + Score score = entry.getValue(); + if (score.getAccuracy() >= threshold) { + logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); } } } - if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ - Map<OWLAxiom, Score> axioms2Score = new LinkedHashMap<OWLAxiom, Score>(); - //for each class - int i = 1; - for (NamedClass cls : classes) { - logger.info("...on class " + cls + "..."); - Model fragment = class2Fragment.get(cls); - Map<OWLAxiom, Score> result = applyPattern((OWLSubClassOfAxiom) pattern, df.getOWLClass(IRI.create(cls.getName())), fragment); - axioms2Score.putAll(result); - - for (Entry<OWLAxiom, Score> entry : result.entrySet()) { - OWLAxiom axiom = entry.getKey(); - Score score = entry.getValue(); - if(score.getAccuracy() >= threshold){ - logger.info(axiom + "(" + format.format(score.getAccuracy()) + ")"); - } - } - - //wait some time to avoid flooding of endpoint - try { - Thread.sleep(waitingTime); - } catch (InterruptedException e) { - e.printStackTrace(); - } -// if(i++ == 3) break; - } - save(pattern, axioms2Score); - } + save(pattern, axioms2Score); + } } @@ -541,19 +524,32 @@ return axioms2Score; } - private Map<OWLAxiom, Score> applyPattern(OWLSubClassOfAxiom pattern, OWLClass cls, Model fragment) { + private Map<OWLAxiom, Score> applyPattern(OWLAxiom pattern, OWLClass cls, Model fragment) { Map<OWLAxiom, Score> axioms2Score = new HashMap<OWLAxiom, Score>(); - OWLClassExpression patternSubClass = pattern.getSubClass(); - OWLClassExpression patternSuperClass = pattern.getSuperClass(); + OWLClassExpression patternSubClass = null; + OWLClassExpression patternSuperClass = null; - patternSubClass = cls; + if(pattern.isOfType(AxiomType.EQUIVALENT_CLASSES)){ + Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)pattern).asOWLSubClassOfAxioms(); + for (OWLSubClassOfAxiom axiom : subClassOfAxioms) { + if(!axiom.getSubClass().isAnonymous()){ + patternSubClass = axiom.getSubClass(); + patternSuperClass = axiom.getSuperClass(); + break; + } + } + } else if(pattern.isOfType(AxiomType.SUBCLASS_OF)){ + patternSubClass = ((OWLSubClassOfAxiom) pattern).getSubClass(); + patternSuperClass = ((OWLSubClassOfAxiom) pattern).getSuperClass(); + } else { + logger.warn("Pattern " + pattern + " not supported yet."); + return axioms2Score; + } - - Set<OWLEntity> signature = patternSuperClass.getSignature(); - signature.remove(patternSubClass); - Query query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(patternSubClass, patternSuperClass), signature); + signature.remove(patternSubClass.asOWLClass()); + Query query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(cls, patternSuperClass), signature); logger.info("Running query\n" + query); Map<OWLEntity, String> variablesMapping = converter.getVariablesMapping(); com.hp.hpl.jena.query.ResultSet rs = QueryExecutionFactory.create(query, fragment).execSelect(); @@ -565,7 +561,7 @@ resources.add(qs.getResource("x").getURI()); // get the IRIs for each variable Map<OWLEntity, IRI> entity2IRIMap = new HashMap<OWLEntity, IRI>(); - entity2IRIMap.put(pattern.getSubClass().asOWLClass(), cls.getIRI()); + entity2IRIMap.put(patternSubClass.asOWLClass(), cls.getIRI()); boolean skip = false; for (OWLEntity entity : signature) { String var = variablesMapping.get(entity); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-08 21:03:48
|
Revision: 3963 http://sourceforge.net/p/dl-learner/code/3963 Author: lorenz_b Date: 2013-05-08 21:03:43 +0000 (Wed, 08 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-08 19:07:53 UTC (rev 3962) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-08 21:03:43 UTC (rev 3963) @@ -1,5 +1,7 @@ package org.dllearner.utilities.owl; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -7,6 +9,7 @@ import java.util.Map; import java.util.Set; import java.util.Stack; +import java.util.TreeSet; import org.aksw.commons.collections.diff.ModelDiff; import org.semanticweb.owlapi.apibinding.OWLManager; @@ -58,6 +61,10 @@ import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; +import com.google.common.collect.Sets; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.Syntax; @@ -74,6 +81,8 @@ private OWLDataFactory df = new OWLDataFactoryImpl(); + private Multimap<Integer, OWLEntity> properties = HashMultimap.create(); + private Map<Integer, Boolean> intersection; private Set<? extends OWLEntity> variableEntities = new HashSet<OWLEntity>(); @@ -147,6 +156,7 @@ private void reset(){ variablesMapping.clear(); variables.clear(); + properties.clear(); classCnt = 0; propCnt = 0; indCnt = 0; @@ -238,6 +248,9 @@ } else { s = "<" + entity.toStringID() + ">"; } + if(entity.isOWLObjectProperty()){ + properties.put(modalDepth(), entity); + } return s; } @@ -269,6 +282,19 @@ for (OWLClassExpression operand : operands) { operand.accept(this); } + Collection<OWLEntity> props = properties.get(modalDepth()); + if(props.size() > 1){ + Collection<String> vars = new TreeSet<String>(); + for (OWLEntity p : props) { + if(variablesMapping.containsKey(p)){ + vars.add(variablesMapping.get(p)); + } + } + if(vars.size() == 2){ + List<String> varList = new ArrayList<String>(vars); + sparql += "FILTER(" + varList.get(0) + "!=" + varList.get(1) + ")"; + } + } leaveIntersection(); } @@ -728,8 +754,14 @@ //variable entity expr = df.getOWLObjectIntersectionOf( df.getOWLObjectSomeValuesFrom(propR, clsB), + clsB, df.getOWLObjectSomeValuesFrom(propS, clsA)); + query = converter.asQuery(rootVar, expr, Sets.newHashSet(propR, propS)).toString(); + System.out.println(expr + "\n" + query); + + expr = df.getOWLObjectIntersectionOf( + df.getOWLObjectSomeValuesFrom(propR, df.getOWLObjectIntersectionOf(df.getOWLObjectSomeValuesFrom(propS, clsA), clsC)), clsB); - query = converter.asQuery(rootVar, expr, Collections.singleton(propR)).toString(); + query = converter.asQuery(rootVar, expr, Sets.newHashSet(propR, propS)).toString(); System.out.println(expr + "\n" + query); } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 19:07:53 UTC (rev 3962) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 21:03:43 UTC (rev 3963) @@ -6,14 +6,10 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; import java.text.DecimalFormat; import java.util.ArrayList; @@ -30,7 +26,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.TimeUnit; -import java.util.prefs.Preferences; import joptsimple.OptionException; import joptsimple.OptionParser; @@ -52,8 +47,6 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; -import org.ini4j.IniPreferences; -import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.OWLObjectRenderer; import org.semanticweb.owlapi.io.ToStringRenderer; @@ -92,7 +85,9 @@ 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.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.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; import com.hp.hpl.jena.vocabulary.RDF; @@ -298,6 +293,7 @@ } catch (FileNotFoundException e) { e.printStackTrace(); } + filterModel(fragment); class2Fragment.put(cls, fragment); logger.info("...got " + fragment.size() + " triples."); continue; @@ -336,6 +332,19 @@ return class2Fragment; } + private void filterModel(Model model){ + List<Statement> statements2Remove = new ArrayList<Statement>(); + for (Statement st : model.listStatements().toSet()) { + if(st.getObject().isLiteral()){ + statements2Remove.add(st); + } + if(st.getPredicate().equals(RDF.type) && !st.getObject().asResource().getURI().startsWith("http://dbpedia.org/ontology/")){ + statements2Remove.add(st); + } + } + model.remove(statements2Remove); + } + private Map<OWLAxiom, Score> evaluate1(OWLAxiom pattern, NamedClass cls){ Map<OWLAxiom, Score> axioms2Score = new HashMap<OWLAxiom, Score>(); @@ -540,15 +549,11 @@ patternSubClass = cls; - // 2. execute SPARQL query on local model - Query query = QueryFactory.create( - "SELECT (COUNT(DISTINCT ?x) AS ?cnt) WHERE {" + converter.convert("?x", patternSubClass) + "}", - Syntax.syntaxARQ); - int subClassCnt = QueryExecutionFactory.create(query, fragment).execSelect().next().getLiteral("cnt").getInt(); + Set<OWLEntity> signature = patternSuperClass.getSignature(); signature.remove(patternSubClass); - query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(patternSubClass, patternSuperClass), signature); + Query query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(patternSubClass, patternSuperClass), signature); logger.info("Running query\n" + query); Map<OWLEntity, String> variablesMapping = converter.getVariablesMapping(); com.hp.hpl.jena.query.ResultSet rs = QueryExecutionFactory.create(query, fragment).execSelect(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-08 19:07:57
|
Revision: 3962 http://sourceforge.net/p/dl-learner/code/3962 Author: lorenz_b Date: 2013-05-08 19:07:53 +0000 (Wed, 08 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 17:47:19 UTC (rev 3961) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 19:07:53 UTC (rev 3962) @@ -3,6 +3,7 @@ import static java.util.Arrays.asList; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -27,6 +28,7 @@ import java.util.Map.Entry; import java.util.Random; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.TimeUnit; import java.util.prefs.Preferences; @@ -34,7 +36,6 @@ import joptsimple.OptionParser; import joptsimple.OptionSet; -import org.aksw.commons.collections.diff.ModelDiff; import org.apache.log4j.Logger; import org.coode.owlapi.turtle.TurtleOntologyFormat; import org.dllearner.core.EvaluatedAxiom; @@ -79,6 +80,9 @@ import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; +import com.google.common.hash.HashCode; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; @@ -96,24 +100,18 @@ public class OWLAxiomPatternUsageEvaluation { - private static final Logger logger = Logger.getLogger(OWLAxiomPatternUsageEvaluation.AxiomTypeCategory.class - .getName()); + private static final Logger logger = Logger.getLogger(OWLAxiomPatternUsageEvaluation.class.getName()); - enum AxiomTypeCategory{ - TBox, RBox, ABox - } private OWLObjectRenderer axiomRenderer = new ManchesterOWLSyntaxOWLObjectRendererImpl(); private OWLDataFactory df = new OWLDataFactoryImpl(); - private Connection conn; - private ExtractionDBCache cache = new ExtractionDBCache("pattern-cache"); + private ExtractionDBCache cache = new ExtractionDBCache("pattern-cache/db"); private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); private SparqlEndpointKS ks = new SparqlEndpointKS(endpoint, cache);//new LocalModelBasedSparqlEndpointKS(model); private String ns = "http://dbpedia.org/ontology/"; - private boolean fancyLatex = false; private DecimalFormat format = new DecimalFormat("00.0%"); private long waitingTime = TimeUnit.SECONDS.toMillis(3); private double threshold = 0.6; @@ -125,33 +123,8 @@ private int queryLimit = 10000; public OWLAxiomPatternUsageEvaluation() { - initDBConnection(); } - 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; - conn = DriverManager.getConnection(url, dbUser, dbPass); - } 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(SparqlEndpoint endpoint, OWLOntology ontology, File outputFile, int maxNrOfTestedClasses){ ks = new SparqlEndpointKS(endpoint, cache); @@ -315,6 +288,21 @@ for (NamedClass cls : classes) { logger.info("Extracting fragment for " + cls + "..."); Model fragment = ModelFactory.createDefaultModel(); + //try to load from cache + HashFunction hf = Hashing.md5(); + HashCode hc = hf.newHasher().putString(cls.getName()).hash(); + File file = new File("pattern-cache/" + hc.toString() + ".ttl"); + if(file.exists()){ + try { + fragment.read(new FileInputStream(file), null, "TURTLE"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + class2Fragment.put(cls, fragment); + logger.info("...got " + fragment.size() + " triples."); + continue; + } + //build the CONSTRUCT query Query query = buildConstructQuery(cls, depth); query.setLimit(queryLimit); @@ -323,7 +311,8 @@ int offset = 0; boolean hasMoreResults = true; while(hasMoreResults && (System.currentTimeMillis() - startTime)<= maxFragmentExtractionTime){ - query.setOffset(offset);System.out.println(query); + query.setOffset(offset); + logger.info(query); Model m = executeConstructQuery(query); fragment.add(m); if(m.size() == 0){ @@ -338,6 +327,11 @@ } logger.info("...got " + fragment.size() + " triples."); class2Fragment.put(cls, fragment); + try { + fragment.write(new FileOutputStream(file), "TURTLE"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } } return class2Fragment; } @@ -554,6 +548,72 @@ Set<OWLEntity> signature = patternSuperClass.getSignature(); signature.remove(patternSubClass); + query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(patternSubClass, patternSuperClass), signature); + logger.info("Running query\n" + query); + Map<OWLEntity, String> variablesMapping = converter.getVariablesMapping(); + com.hp.hpl.jena.query.ResultSet rs = QueryExecutionFactory.create(query, fragment).execSelect(); + QuerySolution qs; + Set<String> resources = new HashSet<String>(); + Multiset<OWLAxiom> instantiations = HashMultiset.create(); + while (rs.hasNext()) { + qs = rs.next(); + resources.add(qs.getResource("x").getURI()); + // get the IRIs for each variable + Map<OWLEntity, IRI> entity2IRIMap = new HashMap<OWLEntity, IRI>(); + entity2IRIMap.put(pattern.getSubClass().asOWLClass(), cls.getIRI()); + boolean skip = false; + for (OWLEntity entity : signature) { + String var = variablesMapping.get(entity); + if(qs.get(var) == null){ + logger.warn("Variable " + var + " is not bound."); + skip = true; + break; + } + if(qs.get(var).isLiteral()){ + skip = true; + break; + } + Resource resource = qs.getResource(var); + if(entity.isOWLObjectProperty() && resource.hasURI(RDF.type.getURI())){ + skip = true; + break; + } + entity2IRIMap.put(entity, IRI.create(resource.getURI())); + } + if(!skip){ + // instantiate the pattern + OWLObjectDuplicator duplicator = new OWLObjectDuplicator(entity2IRIMap, df); + OWLAxiom patternInstantiation = duplicator.duplicateObject(pattern); + instantiations.add(patternInstantiation); + } + } + // compute the score + int total = resources.size(); + for (OWLAxiom axiom : instantiations.elementSet()) { + int frequency = instantiations.count(axiom); + Score score = computeScore(total, Math.min(total, frequency)); + axioms2Score.put(axiom, score); + } + + return axioms2Score; + } + + private Map<OWLAxiom, Score> applyPattern2(OWLSubClassOfAxiom pattern, OWLClass cls, Model fragment) { + Map<OWLAxiom, Score> axioms2Score = new HashMap<OWLAxiom, Score>(); + + OWLClassExpression patternSubClass = pattern.getSubClass(); + OWLClassExpression patternSuperClass = pattern.getSuperClass(); + + patternSubClass = cls; + + // 2. execute SPARQL query on local model + Query query = QueryFactory.create( + "SELECT (COUNT(DISTINCT ?x) AS ?cnt) WHERE {" + converter.convert("?x", patternSubClass) + "}", + Syntax.syntaxARQ); + int subClassCnt = QueryExecutionFactory.create(query, fragment).execSelect().next().getLiteral("cnt").getInt(); + + Set<OWLEntity> signature = patternSuperClass.getSignature(); + signature.remove(patternSubClass); query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(patternSubClass, patternSuperClass), signature, true); logger.info("Running query\n" + query); Map<OWLEntity, String> variablesMapping = converter.getVariablesMapping(); @@ -679,7 +739,7 @@ public List<OWLAxiom> getPatternsToEvaluate(OWLOntology ontology){ List<OWLAxiom> axiomPatterns = new ArrayList<OWLAxiom>(); - axiomPatterns.addAll(ontology.getLogicalAxioms()); + axiomPatterns.addAll(new TreeSet<OWLAxiom>(ontology.getLogicalAxioms())); return axiomPatterns; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-08 17:47:24
|
Revision: 3961 http://sourceforge.net/p/dl-learner/code/3961 Author: lorenz_b Date: 2013-05-08 17:47:19 +0000 (Wed, 08 May 2013) Log Message: ----------- Refactored pattern eval. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 16:37:49 UTC (rev 3960) +++ trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java 2013-05-08 17:47:19 UTC (rev 3961) @@ -551,12 +551,11 @@ "SELECT (COUNT(DISTINCT ?x) AS ?cnt) WHERE {" + converter.convert("?x", patternSubClass) + "}", Syntax.syntaxARQ); int subClassCnt = QueryExecutionFactory.create(query, fragment).execSelect().next().getLiteral("cnt").getInt(); - System.out.println(subClassCnt); Set<OWLEntity> signature = patternSuperClass.getSignature(); signature.remove(patternSubClass); query = converter.asQuery("?x", df.getOWLObjectIntersectionOf(patternSubClass, patternSuperClass), signature, true); - System.out.println(query); + logger.info("Running query\n" + query); Map<OWLEntity, String> variablesMapping = converter.getVariablesMapping(); com.hp.hpl.jena.query.ResultSet rs = QueryExecutionFactory.create(query, fragment).execSelect(); QuerySolution qs; @@ -568,6 +567,11 @@ boolean skip = false; for (OWLEntity entity : signature) { String var = variablesMapping.get(entity); + if(qs.get(var) == null){ + logger.warn("Variable " + var + " is not bound."); + skip = true; + break; + } if(qs.get(var).isLiteral()){ skip = true; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |