From: <lor...@us...> - 2013-10-03 08:51:00
|
Revision: 4113 http://sourceforge.net/p/dl-learner/code/4113 Author: lorenz_b Date: 2013-10-03 08:50:57 +0000 (Thu, 03 Oct 2013) Log Message: ----------- Minor bug fix in SPARQL reasoner. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SemanticAnnotator.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/SemanticIndex.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/simple/SimpleSemanticIndex.java trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java trunk/components-core/src/main/java/org/dllearner/parser/KBParser.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/GreedyCohaerencyExtractor.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETest.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/pom.xml 2013-10-03 08:50:57 UTC (rev 4113) @@ -308,6 +308,23 @@ <artifactId>commons-math3</artifactId> <version>3.1.1</version> </dependency> + <dependency> + <groupId>org.aksw.commons</groupId> + <artifactId>collections</artifactId> + </dependency> + <dependency> + <groupId>org.aksw.commons</groupId> + <artifactId>util</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-compress</artifactId> + <version>1.4.1</version> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> </dependencies> <dependencyManagement> <dependencies> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -42,11 +42,15 @@ import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DisjointClassesAxiom; +import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; +import org.semanticweb.owlapi.model.OWLClassExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -128,6 +132,8 @@ return; } + computeAllDisjointClassAxiomsOptimized(); + //at first get all existing classes in knowledge base allClasses = getAllClasses(); allClasses.remove(classToDescribe); @@ -177,7 +183,7 @@ int cnt = qs.getLiteral("cnt").getInt(); class2Overlap.put(cls, cnt); } - //for each property in knowledge base + //for each class in knowledge base for(NamedClass cls : allClasses){if(!cls.toString().equals("http://dbpedia.org/ontology/MotorcycleRider"))continue; //get the popularity int otherPopularity = reasoner.getPopularity(cls); @@ -353,7 +359,7 @@ EvaluatedDescription evalDesc; - //firstly, create disjoint classexpressions which not occur and give score of 1 + //firstly, create disjoint classexpressions which do not occur and give score of 1 for(NamedClass cls : completeDisjointclasses){ if(useClassPopularity){ int overlap = 0; @@ -413,6 +419,7 @@ } else { evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); } + evalDescs.add(evalDesc); } class2Count.put(classToDescribe, total); @@ -450,16 +457,142 @@ } } + private void computeAllDisjointClassAxiomsOptimized(){ + //get number of instances of A + int instanceCountA = reasoner.getPopularity(classToDescribe); + + //firstly, we compute the disjointness to all sibling classes + Set<EvaluatedDescription> disjointessOfSiblings = computeDisjointessOfSiblings(classToDescribe); + System.out.println(disjointessOfSiblings); + + //we go the hierarchy up + SortedSet<Description> superClasses = reasoner.getSuperClasses(classToDescribe); + for (Description sup : superClasses) { + Set<EvaluatedDescription> disjointessOfSuperClass = computeDisjointessOfSiblings(sup.asNamedClass()); + System.out.println(disjointessOfSuperClass); + } + } + + private Set<EvaluatedDescription> computeDisjointessOfSiblings(NamedClass cls){ + Set<EvaluatedDescription> evaluatedDescriptions = new HashSet<EvaluatedDescription>(); + + //get number of instances of A + int instanceCountA = reasoner.getPopularity(cls); + + if(instanceCountA > 0){ + //we compute the disjointness to all sibling classes + Set<NamedClass> siblingClasses = reasoner.getSiblingClasses(cls); + + for (NamedClass sib : siblingClasses) { + //get number of instances of B + int instanceCountB = reasoner.getPopularity(sib); + + if(instanceCountB > 0){ + //get number of instances of (A and B) + int instanceCountAB = reasoner.getPopularity(new Intersection(cls, sib)); + + //we compute the estimated precision + double precision = accuracy(instanceCountB, instanceCountAB); + //we compute the estimated recall + double recall = accuracy(instanceCountA, instanceCountAB); + //compute the overall score + double score = 1 - fMEasure(precision, recall); + + EvaluatedDescription evalDesc = new EvaluatedDescription(sib, new AxiomScore(score)); + evaluatedDescriptions.add(evalDesc); + } + } + } + + return evaluatedDescriptions; + } + + private EvaluatedAxiom computeDisjointess(NamedClass clsA, NamedClass clsB){ + logger.debug("Computing disjointness between " + clsA + " and " + clsB + "..."); + + double scoreValue = 0; + + //get number of instances of A + int instanceCountA = reasoner.getPopularity(clsA); + + //get number of instances of B + int instanceCountB = reasoner.getPopularity(clsB); + + if(instanceCountA > 0 && instanceCountB > 0){ + //get number of instances of (A and B) + int instanceCountAB = reasoner.getPopularity(new Intersection(clsA, clsB)); + + //we compute the estimated precision + double precision = accuracy(instanceCountB, instanceCountAB); + + //we compute the estimated recall + double recall = accuracy(instanceCountA, instanceCountAB); + + //compute the overall score + scoreValue = 1 - fMEasure(precision, recall); + + } + + AxiomScore score = new AxiomScore(scoreValue); + + return new EvaluatedAxiom(new DisjointClassesAxiom(clsA, clsB), score); + } + + public Set<EvaluatedAxiom> computeSchemaDisjointness(){ + Set<EvaluatedAxiom> axioms = new HashSet<EvaluatedAxiom>(); + + Set<NamedClass> classes = reasoner.getOWLClasses("http://dbpedia.org/ontology/"); + computeDisjointness(classes); + + //start from the top level classes, i.e. the classes whose direct super class is owl:Thing + SortedSet<Description> topLevelClasses = reasoner.getMostGeneralClasses(); + axioms.addAll(computeDisjointness(asNamedClasses(topLevelClasses))); + + for (Description cls : topLevelClasses) { + + } + + return axioms; + } + + public Set<EvaluatedAxiom> computeDisjointness(Set<NamedClass> classes){ + Set<EvaluatedAxiom> axioms = new HashSet<EvaluatedAxiom>(); + + for (NamedClass clsA : classes) { + for (NamedClass clsB : classes) { + if(!clsA.equals(clsB)){ + axioms.add(computeDisjointess(clsA, clsB)); + } + } + } + + return axioms; + } + + public static Set<NamedClass> asNamedClasses(Set<Description> descriptions){ + Set<NamedClass> classes = new TreeSet<NamedClass>(); + for (Description description : descriptions) { + if(description.isNamedClass()){ + classes.add(description.asNamedClass()); + } + } + return classes; + } + public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); - ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); DisjointClassesLearner l = new DisjointClassesLearner(ks); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Agent")); + SPARQLReasoner sparqlReasoner = new SPARQLReasoner(ks, "cache"); + sparqlReasoner.prepareSubsumptionHierarchy(); + sparqlReasoner.precomputeClassPopularity(); + l.setReasoner(sparqlReasoner); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Actor")); l.setMaxExecutionTimeInSeconds(60); l.init(); - l.getReasoner().prepareSubsumptionHierarchy(); - l.getReasoner().precomputeClassPopularity(); + l.computeSchemaDisjointness(); + // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SemanticAnnotator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SemanticAnnotator.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SemanticAnnotator.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -5,7 +5,7 @@ import java.util.Set; import org.dllearner.algorithms.isle.EntityCandidateGenerator; -import org.dllearner.algorithms.isle.WordSenseDisambiguation; +import org.dllearner.algorithms.isle.wsd.WordSenseDisambiguation; import org.dllearner.core.owl.Entity; /** Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/SemanticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/SemanticIndex.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/SemanticIndex.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -7,12 +7,12 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.isle.EntityCandidateGenerator; -import org.dllearner.algorithms.isle.WordSenseDisambiguation; import org.dllearner.algorithms.isle.index.AnnotatedDocument; import org.dllearner.algorithms.isle.index.LinguisticAnnotator; import org.dllearner.algorithms.isle.index.SemanticAnnotator; import org.dllearner.algorithms.isle.index.TextDocument; import org.dllearner.algorithms.isle.index.syntactic.SyntacticIndex; +import org.dllearner.algorithms.isle.wsd.WordSenseDisambiguation; import org.dllearner.core.owl.Entity; import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAnnotationProperty; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/simple/SimpleSemanticIndex.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/simple/SimpleSemanticIndex.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/semantic/simple/SimpleSemanticIndex.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -3,7 +3,6 @@ */ package org.dllearner.algorithms.isle.index.semantic.simple; -import org.dllearner.algorithms.isle.SimpleWordSenseDisambiguation; import org.dllearner.algorithms.isle.index.SemanticAnnotator; import org.dllearner.algorithms.isle.index.SimpleEntityCandidatesTrie; import org.dllearner.algorithms.isle.index.TrieEntityCandidateGenerator; @@ -11,6 +10,7 @@ import org.dllearner.algorithms.isle.index.semantic.SemanticIndex; import org.dllearner.algorithms.isle.index.syntactic.SyntacticIndex; import org.dllearner.algorithms.isle.textretrieval.RDFSLabelEntityTextRetriever; +import org.dllearner.algorithms.isle.wsd.SimpleWordSenseDisambiguation; import org.semanticweb.owlapi.model.OWLOntology; /** Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -212,6 +212,14 @@ return toKBSyntaxString(null, null); } + public boolean isNamedClass(){ + return this instanceof NamedClass; + } + + public NamedClass asNamedClass(){ + return (NamedClass)this; + } + /** * Returns all named entities. * @return Modified: trunk/components-core/src/main/java/org/dllearner/parser/KBParser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/parser/KBParser.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/parser/KBParser.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -36,7 +36,7 @@ return name; else return internalNamespace + name; - } + } public static Description parseConcept(String string) throws ParseException { // when just parsing the string as concept, we have no guarantee Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -42,6 +42,7 @@ 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.dllearner.core.ComponentAnn; import org.dllearner.core.IndividualReasoner; import org.dllearner.core.SchemaReasoner; @@ -69,6 +70,7 @@ import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -110,6 +112,7 @@ private boolean prepared = false; private ConceptComparator conceptComparator = new ConceptComparator(); + private OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter(); public SPARQLReasoner(SparqlEndpointKS ks) { @@ -145,6 +148,10 @@ } public SPARQLReasoner(SparqlEndpointKS ks, CacheCoreEx cacheBackend) { + this(ks, new CacheExImpl(cacheBackend)); + } + + public SPARQLReasoner(SparqlEndpointKS ks, CacheEx cache) { this.ks = ks; classPopularityMap = new HashMap<NamedClass, Integer>(); @@ -153,8 +160,7 @@ if(ks.isRemote()){ SparqlEndpoint endpoint = ks.getEndpoint(); qef = new QueryExecutionFactoryHttp(endpoint.getURL().toString(), endpoint.getDefaultGraphURIs()); - CacheEx cacheFrontend = new CacheExImpl(cacheBackend); - qef = new QueryExecutionFactoryCacheEx(qef, cacheFrontend); + qef = new QueryExecutionFactoryCacheEx(qef, cache); // qef = new QueryExecutionFactoryPaginated(qef, 10000); } else { qef = new QueryExecutionFactoryModel(((LocalModelBasedSparqlEndpointKS)ks).getModel()); @@ -287,6 +293,17 @@ } } + + public int getPopularity(Description description){ + if(classPopularityMap != null && classPopularityMap.containsKey(description)){ + return classPopularityMap.get(description); + } else { + String query = converter.asCountQuery(description).toString(); + ResultSet rs = executeSelectQuery(query); + int cnt = rs.next().getLiteral("cnt").getInt(); + return cnt; + } + } public int getPopularity(ObjectProperty op){ if(objectPropertyPopularityMap != null && objectPropertyPopularityMap.containsKey(op)){ @@ -503,22 +520,25 @@ */ public Model loadOWLSchema(){ Model schema = ModelFactory.createDefaultModel(); + String prefixes = + "PREFIX owl:<http://www.w3.org/2002/07/owl#> " + + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> "; //axioms according to owl:Class entities - String query = + String query = prefixes + "CONSTRUCT {" + "?s a owl:Class." + "?s rdfs:subClassOf ?sup." + "?s owl:equivalentClass ?equiv." + - "?s owl:djsointWith ?disj." + + "?s owl:disjointWith ?disj." + "} WHERE {" + - "?s a owl:Class." + - "OPTIONAL{?s rdfs:subClassOf ?sup.}" + - "OPTIONAL{?s owl:equivalentClass ?equiv.}" + - "OPTIONAL{?s owl:djsointWith ?disj.}" + + "?s a owl:Class. " + + "OPTIONAL{?s rdfs:subClassOf ?sup.} " + + "OPTIONAL{?s owl:equivalentClass ?equiv.} " + + "OPTIONAL{?s owl:disjointWith ?disj.}" + "}"; schema.add(loadIncrementally(query)); //axioms according to owl:ObjectProperty entities - query = + query = prefixes + "CONSTRUCT {" + "?s a owl:ObjectProperty." + "?s a ?type." + @@ -526,14 +546,14 @@ "?s rdfs:range ?range." + "} WHERE {" + "?s a owl:ObjectProperty." + - "?s a ?type." + - "OPTIONAL{?s rdfs:domain ?domain.}" + + "?s a ?type. " + + "OPTIONAL{?s rdfs:domain ?domain.} " + "OPTIONAL{?s rdfs:range ?range.}" + "}"; schema.add(loadIncrementally(query)); //axioms according to owl:ObjectProperty entities - query = + query = prefixes + "CONSTRUCT {" + "?s a owl:DatatypeProperty." + "?s a ?type." + @@ -541,8 +561,8 @@ "?s rdfs:range ?range." + "} WHERE {" + "?s a owl:DatatypeProperty." + - "?s a ?type." + - "OPTIONAL{?s rdfs:domain ?domain.}" + + "?s a ?type. " + + "OPTIONAL{?s rdfs:domain ?domain.} " + "OPTIONAL{?s rdfs:range ?range.}" + "}"; schema.add(loadIncrementally(query)); @@ -550,11 +570,13 @@ return schema; } - private Model loadIncrementally(String query){ - System.out.println(query); + private Model loadIncrementally(String query){System.err.println(query); + QueryExecutionFactory old = qef; + qef = new QueryExecutionFactoryPaginated(qef, 10000); QueryExecution qe = qef.createQueryExecution(query); Model model = qe.execConstruct(); qe.close(); + qef = old; return model; } @@ -693,9 +715,13 @@ return types; } - public Set<NamedClass> getOWLClasses(String namespace) { - Set<NamedClass> types = new HashSet<NamedClass>(); - String query = String.format("SELECT DISTINCT ?class WHERE {?class a <%s>. FILTER(REGEX(?class,'%s'))}",OWL.Class.getURI(), namespace); + public SortedSet<NamedClass> getOWLClasses(String namespace) { + SortedSet<NamedClass> types = new TreeSet<NamedClass>(); + String query = "SELECT DISTINCT ?class WHERE {?class a <" + OWL.Class.getURI() + ">."; + if(namespace != null){ + query += "FILTER(REGEX(STR(?class),'" + namespace + "'))"; + } + query += "}"; ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -716,7 +742,7 @@ Set<NamedClass> siblings = new TreeSet<NamedClass>(); String query = "SELECT ?sub WHERE { <" + cls.getName() + "> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super ."; query += "?sub <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?super ."; - query += "FILTER( !SAMETERM(?sub, <" + cls.getName() + ">)) . }";System.out.println(query); + query += "FILTER( !SAMETERM(?sub, <" + cls.getName() + ">)) . }"; ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1360,6 +1386,10 @@ public ClassHierarchy getClassHierarchy() { return hierarchy; } + + public SortedSet<Description> getMostGeneralClasses() { + return hierarchy.getMostGeneralClasses(); + } @Override public SortedSet<Description> getSuperClasses(Description description) { Modified: trunk/components-core/src/main/java/org/dllearner/utilities/GreedyCohaerencyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/GreedyCohaerencyExtractor.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/utilities/GreedyCohaerencyExtractor.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -12,10 +12,10 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import java.util.Map.Entry; -import java.util.Set; import org.apache.commons.collections15.BidiMap; import org.apache.commons.collections15.bidimap.DualHashBidiMap; 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-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -11,7 +11,7 @@ import java.util.Stack; import java.util.TreeSet; -import org.aksw.commons.collections.diff.ModelDiff; +import org.dllearner.core.owl.Description; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.ToStringRenderer; import org.semanticweb.owlapi.model.OWLClass; @@ -63,7 +63,6 @@ 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; @@ -96,6 +95,10 @@ public VariablesMapping getVariablesMapping() { return mapping; } + + public String convert(String rootVariable, Description description){ + return convert(rootVariable, OWLAPIConverter.getOWLAPIDescription(description)); + } public String convert(String rootVariable, OWLClassExpression expr){ this.expr = expr; @@ -129,6 +132,23 @@ return QueryFactory.create(queryString, Syntax.syntaxARQ); } + public Query asCountQuery(OWLClassExpression expr){ + String rootVariable = "?s"; + String queryString = "SELECT (COUNT(DISTINCT " + rootVariable + ") AS ?cnt) WHERE {"; + String triplePattern = convert(rootVariable, expr); + queryString += triplePattern; + queryString += "}"; + return QueryFactory.create(queryString, Syntax.syntaxARQ); + } + + public Query asCountQuery(Description description){ + return asCountQuery(OWLAPIConverter.getOWLAPIDescription(description)); + } + + public Query asQuery(String rootVariable, Description desc, boolean countQuery){ + return asQuery(rootVariable, OWLAPIConverter.getOWLAPIDescription(desc), countQuery); + } + public Query asQuery(String rootVariable, OWLClassExpression expr, Set<? extends OWLEntity> variableEntities){ return asQuery(rootVariable, expr, variableEntities, false); } Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETest.java 2013-09-23 12:22:30 UTC (rev 4112) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETest.java 2013-10-03 08:50:57 UTC (rev 4113) @@ -6,6 +6,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.io.Files; + import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.isle.index.*; import org.dllearner.algorithms.isle.index.semantic.SemanticIndex; @@ -17,6 +18,8 @@ import org.dllearner.algorithms.isle.metrics.RelevanceUtils; import org.dllearner.algorithms.isle.textretrieval.EntityTextRetriever; import org.dllearner.algorithms.isle.textretrieval.RDFSLabelEntityTextRetriever; +import org.dllearner.algorithms.isle.wsd.SimpleWordSenseDisambiguation; +import org.dllearner.algorithms.isle.wsd.WordSenseDisambiguation; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Entity; @@ -28,9 +31,12 @@ import org.junit.Before; import org.junit.Test; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyManager; + import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import java.io.File; @@ -245,4 +251,14 @@ } + @Test + public void testWordSenseDisambiguation() throws Exception { + Set<OWLEntity> context = StructuralEntityContext.getContext(ontology, df.getOWLClass(IRI.create(cls.getName()))); + System.out.println(context); + + Set<String> contextNL = StructuralEntityContext.getContextInNaturalLanguage(ontology, df.getOWLClass(IRI.create(cls.getName()))); + System.out.println(contextNL); + } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |