From: <lor...@us...> - 2013-06-10 10:07:45
|
Revision: 3986 http://sourceforge.net/p/dl-learner/code/3986 Author: lorenz_b Date: 2013-06-10 10:07:42 +0000 (Mon, 10 Jun 2013) Log Message: ----------- Added class for mapping from URI to variable. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SetManipulation.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAxiomToSPARQLConverter.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/VariablesMapping.java 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-06-06 13:32:30 UTC (rev 3985) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -9,6 +9,7 @@ import java.util.TreeSet; import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.learningproblems.Heuristics; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -48,7 +49,7 @@ } } //compute score - double score = (trees.size() - uncoveredExamples.size()) / (double)trees.size(); + double score = Heuristics.getConfidenceInterval95WaldAverage(trees.size(), trees.size() - uncoveredExamples.size()); //add to todo list, if not already contained in todo list or solution list EvaluatedQueryTree<N> solution = new EvaluatedQueryTree<N>(lgg, uncoveredExamples, score); todo(solution); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2013-06-06 13:32:30 UTC (rev 3985) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -1158,6 +1158,10 @@ } } + + public void setSubsumptionHierarchy(ClassHierarchy subsumptionHierarchy) { + this.subsumptionHierarchy = subsumptionHierarchy; + } public List<ObjectProperty> getAtomicRolesList() { if (atomicRolesList == null) 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-06-06 13:32:30 UTC (rev 3985) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -346,7 +346,9 @@ // case 2: it is not allowed, so we try its super classes } else { Set<Description> tmp = subsumptionHierarchyUp.get(d); - superClasses.addAll(tmp); + if(tmp != null){ + superClasses.addAll(tmp); + } } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SetManipulation.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SetManipulation.java 2013-06-06 13:32:30 UTC (rev 3985) +++ trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SetManipulation.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -38,11 +38,11 @@ * @param set * @param limit */ - public static SortedSet<String> fuzzyShrink(SortedSet<String> set, int limit) { + public static <T> SortedSet<T> fuzzyShrink(SortedSet<T> set, int limit) { if (set.size() <= limit) { return set; } - SortedSet<String> ret = new TreeSet<String>(); + SortedSet<T> ret = new TreeSet<T>(); Random r = new Random(); double treshold = ((double) limit) / set.size(); // System.out.println("treshold"+howmany); @@ -50,7 +50,7 @@ // System.out.println("treshold"+treshold); while (ret.size() < limit) { - for (String oneInd : set) { + for (T oneInd : set) { if (r.nextDouble() < treshold) { ret.add(oneInd); if (ret.size() >= 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-06-06 13:32:30 UTC (rev 3985) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -36,16 +36,21 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.datastructures.SetManipulation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.base.Predicate; import com.google.common.collect.HashMultiset; import com.google.common.collect.Multiset; import com.google.common.collect.Multisets; +import com.google.common.collect.Sets; /** * * Utility class for automatically retrieving negative examples from a @@ -57,6 +62,8 @@ */ public class AutomaticNegativeExampleFinderSPARQL2 { + private static final Logger logger = LoggerFactory.getLogger(AutomaticNegativeExampleFinderSPARQL2.class.getSimpleName()); + public enum Strategy{ SUPERCLASS, SIBLING, RANDOM; } @@ -113,6 +120,27 @@ return negEx; } + public SortedSet<Individual> getNegativeExamples(NamedClass classToDescribe, Set<Individual> positiveExamples, int limit) { + return getNegativeExamples(classToDescribe, positiveExamples, Arrays.asList(SUPERCLASS, SIBLING, RANDOM), limit); + } + + public SortedSet<Individual> getNegativeExamples(NamedClass classToDescribe, 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(classToDescribe, positiveExamples, strategiesWithWeight, limit); + } + + public SortedSet<Individual> getNegativeExamples(NamedClass classToDescribe, Set<Individual> positiveExamples, Map<Strategy, Double> strategiesWithWeight, int maxNrOfReturnedInstances) { + //set class to describe as the type for each instance + Multiset<NamedClass> types = HashMultiset.create(); + types.add(classToDescribe); + + return computeNegativeExamples(types, strategiesWithWeight, maxNrOfReturnedInstances); + } + public SortedSet<Individual> getNegativeExamples(Set<Individual> positiveExamples, int limit) { return getNegativeExamples(positiveExamples, Arrays.asList(SUPERCLASS, SIBLING, RANDOM), limit); } @@ -127,8 +155,6 @@ } 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) { @@ -136,56 +162,89 @@ } //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); - } - }); - } + types = filterByNamespace(types); //keep the most specific types keepMostSpecificClasses(types); + return computeNegativeExamples(types, strategiesWithWeight, maxNrOfReturnedInstances); + } + + private SortedSet<Individual> computeNegativeExamples(Multiset<NamedClass> positiveExamplesTypes, Map<Strategy, Double> strategiesWithWeight, int maxNrOfReturnedInstances) { + SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); 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); + int strategyLimit = (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); + int maxFrequency = positiveExamplesTypes.entrySet().iterator().next().getCount(); + + if(strategy == SIBLING){//get sibling class based examples + SortedSet<Individual> siblingNegativeExamples = new TreeSet<Individual>(); + //for each type of the positive examples + for (NamedClass nc : positiveExamplesTypes.elementSet()) { + int frequency = positiveExamplesTypes.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); + siblingClasses = filterByNamespace(siblingClasses); + System.out.println("Sibling classes: " + siblingClasses); + + int limit = (int)Math.ceil(((double)frequency / positiveExamplesTypes.size()) / siblingClasses.size() * strategyLimit); + //get instances for each sibling class for (NamedClass siblingClass : siblingClasses) { - negEx.addAll(sr.getIndividualsExcluding(siblingClass, nc, v)); + siblingNegativeExamples.addAll(sr.getIndividualsExcluding(siblingClass, nc, limit)); } + } + siblingNegativeExamples = SetManipulation.fuzzyShrink(siblingNegativeExamples, strategyLimit); + negativeExamples.addAll(siblingNegativeExamples); + } else if(strategy == SUPERCLASS){//get super class based examples + SortedSet<Individual> superClassNegativeExamples = new TreeSet<Individual>(); + //for each type of the positive examples + for (NamedClass nc : positiveExamplesTypes.elementSet()) { + int frequency = positiveExamplesTypes.count(nc); + //get super classes + Set<Description> superClasses = sr.getSuperClasses(nc); + superClasses.remove(new NamedClass(Thing.instance.getURI())); + superClasses = filterByNamespace(superClasses); - } - } 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); + int limit = (int)Math.ceil(((double)frequency / positiveExamplesTypes.size()) / superClasses.size() * strategyLimit); + //get instances for each super class for (Description superClass : superClasses) { - negEx.addAll(sr.getIndividualsExcluding(superClass, nc, v)); + superClassNegativeExamples.addAll(sr.getIndividualsExcluding(superClass, nc, limit)); } } - } else if(strategy == RANDOM){ + superClassNegativeExamples = SetManipulation.fuzzyShrink(superClassNegativeExamples, strategyLimit); + negativeExamples.addAll(superClassNegativeExamples); + } else if(strategy == RANDOM){//get some random examples } } - return negEx; + return negativeExamples; } + private <T extends Description> Set<T> filterByNamespace(Set<T> classes){ + if(namespace != null){ + return Sets.filter(classes, new Predicate<T>() { + public boolean apply(T input){ + return input.toString().startsWith(namespace); + } + }); + } + return classes; + } + + private Multiset<NamedClass> filterByNamespace(Multiset<NamedClass> classes){ + if(namespace != null){ + return Multisets.filter(classes, new Predicate<NamedClass>() { + public boolean apply(NamedClass input){ + return input.getName().startsWith(namespace); + } + }); + } + return classes; + } + private void keepMostSpecificClasses(Multiset<NamedClass> classes){ HashMultiset<NamedClass> copy = HashMultiset.create(classes); final ClassHierarchy hierarchy = sr.getClassHierarchy(); Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAxiomToSPARQLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAxiomToSPARQLConverter.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAxiomToSPARQLConverter.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -0,0 +1,324 @@ +package org.dllearner.utilities.owl; + + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.ToStringRenderer; +import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLAxiomVisitor; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLDataRange; +import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom; +import org.semanticweb.owlapi.model.OWLDeclarationAxiom; +import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom; +import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; +import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLHasKeyAxiom; +import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObjectIntersectionOf; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLSameIndividualAxiom; +import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom; +import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.PrefixManager; +import org.semanticweb.owlapi.model.SWRLRule; +import org.semanticweb.owlapi.util.DefaultPrefixManager; + +import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.Syntax; + +public class OWLAxiomToSPARQLConverter implements OWLAxiomVisitor{ + + private String root = "?x"; + private String sparql; + private OWLClassExpressionToSPARQLConverter expressionConverter; + + public String convert(String rootVariable, OWLAxiom axiom){ + this.root = rootVariable; + sparql = ""; + expressionConverter = new OWLClassExpressionToSPARQLConverter(); + axiom.accept(this); + return sparql; + } + + public Query asQuery(String rootVariable, OWLAxiom axiom){ + String queryString = "SELECT DISTINCT " + rootVariable + " WHERE {"; + queryString += convert(rootVariable, axiom); + queryString += "}"; + return QueryFactory.create(queryString, Syntax.syntaxARQ); + } + + @Override + public void visit(OWLAnnotationAssertionAxiom axiom) { + } + + @Override + public void visit(OWLSubAnnotationPropertyOfAxiom axiom) { + } + + @Override + public void visit(OWLAnnotationPropertyDomainAxiom axiom) { + } + + @Override + public void visit(OWLAnnotationPropertyRangeAxiom axiom) { + } + + @Override + public void visit(OWLDeclarationAxiom axiom) { + } + + @Override + public void visit(OWLSubClassOfAxiom axiom) { + OWLClassExpression subClass = axiom.getSubClass(); + String subClassPattern = expressionConverter.convert(root, subClass); + sparql += subClassPattern; + + OWLClassExpression superClass = axiom.getSuperClass(); + String superClassPattern = expressionConverter.convert(root, superClass); + sparql += superClassPattern; + } + + @Override + public void visit(OWLNegativeObjectPropertyAssertionAxiom axiom) { + } + + @Override + public void visit(OWLAsymmetricObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLReflexiveObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLDisjointClassesAxiom axiom) { + } + + @Override + public void visit(OWLDataPropertyDomainAxiom axiom) { + } + + @Override + public void visit(OWLObjectPropertyDomainAxiom axiom) { + OWLSubClassOfAxiom subClassOfAxiom = axiom.asOWLSubClassOfAxiom(); + } + + @Override + public void visit(OWLEquivalentObjectPropertiesAxiom axiom) { + } + + @Override + public void visit(OWLNegativeDataPropertyAssertionAxiom axiom) { + } + + @Override + public void visit(OWLDifferentIndividualsAxiom axiom) { + } + + @Override + public void visit(OWLDisjointDataPropertiesAxiom axiom) { + } + + @Override + public void visit(OWLDisjointObjectPropertiesAxiom axiom) { + } + + @Override + public void visit(OWLObjectPropertyRangeAxiom axiom) { + } + + @Override + public void visit(OWLObjectPropertyAssertionAxiom axiom) { + } + + @Override + public void visit(OWLFunctionalObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLSubObjectPropertyOfAxiom axiom) { + } + + @Override + public void visit(OWLDisjointUnionAxiom axiom) { + } + + @Override + public void visit(OWLSymmetricObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLDataPropertyRangeAxiom axiom) { + } + + @Override + public void visit(OWLFunctionalDataPropertyAxiom axiom) { + } + + @Override + public void visit(OWLEquivalentDataPropertiesAxiom axiom) { + } + + @Override + public void visit(OWLClassAssertionAxiom axiom) { + } + + @Override + public void visit(OWLEquivalentClassesAxiom axiom) { + } + + @Override + public void visit(OWLDataPropertyAssertionAxiom axiom) { + } + + @Override + public void visit(OWLTransitiveObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLIrreflexiveObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLSubDataPropertyOfAxiom axiom) { + } + + @Override + public void visit(OWLInverseFunctionalObjectPropertyAxiom axiom) { + } + + @Override + public void visit(OWLSameIndividualAxiom axiom) { + } + + @Override + public void visit(OWLSubPropertyChainOfAxiom axiom) { + } + + @Override + public void visit(OWLInverseObjectPropertiesAxiom axiom) { + } + + @Override + public void visit(OWLHasKeyAxiom axiom) { + } + + @Override + public void visit(OWLDatatypeDefinitionAxiom axiom) { + } + + @Override + public void visit(SWRLRule rule) { + } + + public static void main(String[] args) throws Exception { + ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); + OWLAxiomToSPARQLConverter converter = new OWLAxiomToSPARQLConverter(); + + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLDataFactory df = man.getOWLDataFactory(); + PrefixManager pm = new DefaultPrefixManager("http://dbpedia.org/ontology/"); + + OWLClass clsA = df.getOWLClass("A", pm); + OWLClass clsB = df.getOWLClass("B", pm); + OWLClass clsC = df.getOWLClass("C", pm); + + OWLObjectProperty propR = df.getOWLObjectProperty("r", pm); + OWLObjectProperty propS = df.getOWLObjectProperty("s", pm); + + OWLDataProperty dpT = df.getOWLDataProperty("t", pm); + OWLDataRange booleanRange = df.getBooleanOWLDatatype(); + OWLLiteral lit = df.getOWLLiteral(1); + + OWLIndividual indA = df.getOWLNamedIndividual("a", pm); + OWLIndividual indB = df.getOWLNamedIndividual("b", pm); + + String rootVar = "?x"; + //NAMEDCLASS + OWLClassExpression subClass = clsA; + OWLClassExpression superClass = clsB; + OWLAxiom axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + String query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + //EXISTENTIAL RESTRICTION + superClass = df.getOWLObjectSomeValuesFrom(propR, clsB); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + //INTERSECTION + superClass = df.getOWLObjectIntersectionOf( + df.getOWLObjectSomeValuesFrom(propR, clsB), + clsB); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + //UNION + superClass = df.getOWLObjectUnionOf( + clsB, + clsC); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + //HAS VALUE + superClass = df.getOWLObjectHasValue(propR, indA); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + //UNIVERSAL RESTRICTION + superClass = df.getOWLObjectAllValuesFrom(propR, clsB); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + // ONE OF + superClass = df.getOWLObjectOneOf(indA, indB); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + //existential restriction with one of filler + superClass = df.getOWLObjectSomeValuesFrom(propR, df.getOWLObjectOneOf(indA, indB)); + axiom = df.getOWLSubClassOfAxiom(subClass, superClass); + query = converter.asQuery(rootVar, axiom).toString(); + System.out.println(axiom + "\n" + query); + + + + } + +} Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/VariablesMapping.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/VariablesMapping.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/VariablesMapping.java 2013-06-10 10:07:42 UTC (rev 3986) @@ -0,0 +1,38 @@ +package org.dllearner.utilities.owl; + +import java.util.HashMap; + +import org.semanticweb.owlapi.model.OWLEntity; + +public class VariablesMapping extends HashMap<OWLEntity, String>{ + + private int classCnt = 0; + private int propCnt = 0; + private int indCnt = 0; + + public String getVariable(OWLEntity entity){ + String var = 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 = "?s" + indCnt++; + } + put(entity, var); + } + return var; + } + + public String newIndividualVariable(){ + return "?s" + indCnt++; + } + + public void reset(){ + clear(); + classCnt = 0; + propCnt = 0; + indCnt = 0; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |