From: <lor...@us...> - 2013-04-30 11:05:16
|
Revision: 3929 http://sourceforge.net/p/dl-learner/code/3929 Author: lorenz_b Date: 2013-04-30 11:05:12 +0000 (Tue, 30 Apr 2013) Log Message: ----------- Removed experimental classes.Updated LGG. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 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/impl/QueryTreeFactoryImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIConverter.java Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternAxiomToSPARQLConverter.java trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternExpressionToSPARQLConverter.java Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternAxiomToSPARQLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternAxiomToSPARQLConverter.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternAxiomToSPARQLConverter.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -1,286 +0,0 @@ -package org.dllearner.algorithms.pattern; - -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.OWLDataPropertyAssertionAxiom; -import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; -import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; -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.OWLNegativeDataPropertyAssertionAxiom; -import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom; -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 PatternAxiomToSPARQLConverter implements OWLAxiomVisitor { - - private String root = "?x"; - private PatternExpressionToSPARQLConverter expressionConverter; - private String sparql; - - public PatternAxiomToSPARQLConverter() { - } - - public Query convert(OWLAxiom axiom) { - expressionConverter = new PatternExpressionToSPARQLConverter(); - - sparql = "SELECT " + root + " WHERE {\n"; - axiom.accept(this); - sparql += "}"; - - return QueryFactory.create(sparql, 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(); - sparql += expressionConverter.convert(root, subClass); - OWLClassExpression superClass = axiom.getSuperClass(); - sparql += expressionConverter.convert(root, superClass); - } - - @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) { - } - - @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 axiom) { - } - - public static void main(String[] args) throws Exception { - ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); - PatternAxiomToSPARQLConverter converter = new PatternAxiomToSPARQLConverter(); - - OWLOntologyManager man = OWLManager.createOWLOntologyManager(); - OWLDataFactory df = man.getOWLDataFactory(); - PrefixManager pm = new DefaultPrefixManager("http://examples.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); - - OWLIndividual indA = df.getOWLNamedIndividual("a", pm); - OWLIndividual indB = df.getOWLNamedIndividual("b", pm); - - OWLAxiom axiom = df.getOWLSubClassOfAxiom( - clsA, - clsB); - Query query = converter.convert(axiom); - System.out.println(axiom + "\n" + query); - - axiom = df.getOWLSubClassOfAxiom( - clsA, - df.getOWLObjectSomeValuesFrom(propR, clsB)); - query = converter.convert(axiom); - System.out.println(axiom + "\n" + query); - - axiom = df.getOWLSubClassOfAxiom( - clsA, - df.getOWLObjectIntersectionOf( - df.getOWLObjectSomeValuesFrom(propR, clsB), - clsB)); - query = converter.convert(axiom); - System.out.println(axiom + "\n" + query); - - axiom = df.getOWLSubClassOfAxiom( - clsA, - df.getOWLObjectAllValuesFrom(propR, clsB)); - query = converter.convert(axiom); - System.out.println(axiom + "\n" + query); - - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternExpressionToSPARQLConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternExpressionToSPARQLConverter.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/PatternExpressionToSPARQLConverter.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -1,207 +0,0 @@ -package org.dllearner.algorithms.pattern; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.Stack; - -import org.semanticweb.owlapi.model.OWLClass; -import org.semanticweb.owlapi.model.OWLClassExpression; -import org.semanticweb.owlapi.model.OWLClassExpressionVisitor; -import org.semanticweb.owlapi.model.OWLDataAllValuesFrom; -import org.semanticweb.owlapi.model.OWLDataExactCardinality; -import org.semanticweb.owlapi.model.OWLDataHasValue; -import org.semanticweb.owlapi.model.OWLDataMaxCardinality; -import org.semanticweb.owlapi.model.OWLDataMinCardinality; -import org.semanticweb.owlapi.model.OWLDataProperty; -import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; -import org.semanticweb.owlapi.model.OWLEntity; -import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; -import org.semanticweb.owlapi.model.OWLObjectComplementOf; -import org.semanticweb.owlapi.model.OWLObjectExactCardinality; -import org.semanticweb.owlapi.model.OWLObjectHasSelf; -import org.semanticweb.owlapi.model.OWLObjectHasValue; -import org.semanticweb.owlapi.model.OWLObjectIntersectionOf; -import org.semanticweb.owlapi.model.OWLObjectInverseOf; -import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; -import org.semanticweb.owlapi.model.OWLObjectMinCardinality; -import org.semanticweb.owlapi.model.OWLObjectOneOf; -import org.semanticweb.owlapi.model.OWLObjectProperty; -import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; -import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; -import org.semanticweb.owlapi.model.OWLObjectUnionOf; -import org.semanticweb.owlapi.model.OWLPropertyExpressionVisitor; - -public class PatternExpressionToSPARQLConverter implements OWLClassExpressionVisitor, OWLPropertyExpressionVisitor{ - - private String sparql = ""; - private Stack<String> variables = new Stack<String>(); - private Map<OWLEntity, String> variablesMapping; - - private int classCnt = 0; - private int propCnt = 0; - private int indCnt = 0; - - public PatternExpressionToSPARQLConverter() { - variablesMapping = new HashMap<OWLEntity, String>(); - } - - public String convert(String root, OWLClassExpression expr){ - sparql = ""; - variables.push(root); - expr.accept(this); - return sparql; - } - - 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 String triple(String subject, String predicate, String object){ - return subject + " " + predicate + " " + object + ".\n"; - } - - @Override - public void visit(OWLClass expr) { - sparql += variables.peek() + " a " + getVariable(expr) +".\n"; - } - - @Override - public void visit(OWLObjectProperty property) { - - } - - @Override - public void visit(OWLDataProperty property) { - } - - @Override - public void visit(OWLObjectIntersectionOf expr) { - Set<OWLClassExpression> operands = expr.getOperands(); - String variable = variables.peek(); - for (OWLClassExpression operand : operands) { - sparql += convert(variable, operand); - } - } - - @Override - public void visit(OWLObjectUnionOf expr) { - } - - @Override - public void visit(OWLObjectComplementOf expr) { - } - - @Override - public void visit(OWLObjectSomeValuesFrom expr) { - String variable = variables.peek(); - OWLObjectPropertyExpression property = expr.getProperty(); - if(!property.isAnonymous()){ - String objectVariable = buildIndividualVariable(); - variables.push(objectVariable); - //build the triple for the property - sparql += triple(variable, getVariable(property.asOWLObjectProperty()), objectVariable); - //build the rest according to the role filler - OWLClassExpression filler = expr.getFiller(); - filler.accept(this); - variables.pop(); - - } else { - System.err.println("TODO: complex property expressions"); - } - - } - - @Override - public void visit(OWLObjectAllValuesFrom expr) { - String variable = variables.peek(); - OWLObjectPropertyExpression property = expr.getProperty(); - if(!property.isAnonymous()){ - String objectVariable = buildIndividualVariable(); - variables.push(objectVariable); - //build the triple for the property - sparql += triple(variable, getVariable(property.asOWLObjectProperty()), objectVariable); - OWLClassExpression filler = expr.getFiller(); - filler.accept(this); - //build the rest according to the role filler - sparql += "FILTER NOT EXISTS{"; - objectVariable = buildIndividualVariable(); - variables.push(objectVariable); - sparql += triple(variable, getVariable(property.asOWLObjectProperty()), objectVariable); - variables.pop(); - sparql += "}"; - - - } else { - System.err.println("TODO: complex property expressions"); - } - } - - @Override - public void visit(OWLObjectHasValue expr) { - } - - @Override - public void visit(OWLObjectMinCardinality expr) { - } - - @Override - public void visit(OWLObjectExactCardinality expr) { - } - - @Override - public void visit(OWLObjectMaxCardinality expr) { - } - - @Override - public void visit(OWLObjectHasSelf expr) { - } - - @Override - public void visit(OWLObjectOneOf expr) { - } - - @Override - public void visit(OWLDataSomeValuesFrom expr) { - } - - @Override - public void visit(OWLDataAllValuesFrom expr) { - } - - @Override - public void visit(OWLDataHasValue expr) { - } - - @Override - public void visit(OWLDataMinCardinality expr) { - } - - @Override - public void visit(OWLDataExactCardinality expr) { - } - - @Override - public void visit(OWLDataMaxCardinality expr) { - } - - @Override - public void visit(OWLObjectInverseOf property) { - } - -} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -146,6 +146,17 @@ // this.configurator = new QTLConfigurator(this); } + public QTL(AbstractLearningProblem learningProblem, SparqlEndpointKS endpointKS, ExtractionDBCache cache) throws LearningProblemUnsupportedException{ + if(!(learningProblem instanceof PosOnlyLP || learningProblem instanceof PosNegLP)){ + throw new LearningProblemUnsupportedException(learningProblem.getClass(), getClass()); + } + this.learningProblem = learningProblem; + this.endpointKS = endpointKS; + this.cache = cache; + +// this.configurator = new QTLConfigurator(this); + } + public QTL(SPARQLEndpointEx endpoint, ExtractionDBCache cache) { this.endpoint = endpoint; this.cache = cache; @@ -162,6 +173,22 @@ negExampleTrees = new ArrayList<QueryTree<String>>(); } + public QTL(SparqlEndpointKS endpointKS, ExtractionDBCache cache) { + this.endpointKS = endpointKS; + this.cache = cache; + + treeCache = new QueryTreeCache(); + cbdGenerator = new CachingConciseBoundedDescriptionGenerator(new ConciseBoundedDescriptionGeneratorImpl(endpoint, cache)); + cbdGenerator.setRecursionDepth(maxQueryTreeDepth); + + lggGenerator = new LGGGeneratorImpl<String>(); + nbr = new NBR<String>(endpoint, cache); + nbr.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + + posExampleTrees = new ArrayList<QueryTree<String>>(); + negExampleTrees = new ArrayList<QueryTree<String>>(); + } + public QTL(Model model) { this.model = model; @@ -280,16 +307,20 @@ Model model; QueryTree<String> tree; for(String resource : resources){ - logger.info("Generating tree for " + resource); - model = cbdGenerator.getConciseBoundedDescription(resource); - applyFilters(model); - tree = treeCache.getQueryTree(resource, model); - if(logger.isDebugEnabled()){ - logger.debug("Tree for resource " + resource); - logger.debug(tree.getStringRepresentation()); - + try { + logger.debug("Generating tree for " + resource); + model = cbdGenerator.getConciseBoundedDescription(resource); + applyFilters(model); + tree = treeCache.getQueryTree(resource, model); + if(logger.isDebugEnabled()){ + logger.debug("Tree for resource " + resource); + logger.debug(tree.getStringRepresentation()); + + } + trees.add(tree); + } catch (Exception e) { + logger.error("Failed to create tree for resource " + resource + ".", e); } - trees.add(tree); } return trees; } @@ -367,7 +398,9 @@ if(logger.isDebugEnabled()){ logger.debug("LGG: \n" + lgg.getStringRepresentation()); } - logger.info(lgg.toSPARQLQueryString(true, enableNumericLiteralFilters, prefixes)); + if(logger.isInfoEnabled()){ + logger.info(lgg.toSPARQLQueryString(true, enableNumericLiteralFilters, prefixes)); + } } public void setEnableNumericLiteralFilters(boolean enableNumericLiteralFilters) { @@ -421,6 +454,10 @@ return list; } + public QueryTree<String> getLgg() { + return lgg; + } + public static void main(String[] args) throws Exception { Set<String> positiveExamples = new HashSet<String>(); positiveExamples.add("http://dbpedia.org/resource/Liverpool_F.C."); 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-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -26,6 +26,7 @@ import java.util.Set; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; +import org.semanticweb.owlapi.model.OWLClassExpression; import com.hp.hpl.jena.datatypes.RDFDatatype; import com.hp.hpl.jena.query.Query; @@ -136,6 +137,8 @@ Query toSPARQLQuery(); + OWLClassExpression asOWLClassExpression(); + int getTriplePatternCount(); Query toQuery(); 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-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -21,7 +21,6 @@ import java.io.PrintWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -41,7 +40,16 @@ import org.dllearner.algorithms.qtl.datastructures.NodeRenderer; import org.dllearner.algorithms.qtl.datastructures.QueryTree; import org.dllearner.algorithms.qtl.filters.Filters; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.vocab.OWL2Datatype; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + import com.hp.hpl.jena.datatypes.BaseDatatype; import com.hp.hpl.jena.datatypes.RDFDatatype; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; @@ -53,6 +61,7 @@ import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.sparql.syntax.ElementGroup; import com.hp.hpl.jena.sparql.syntax.ElementTriplesBlock; +import com.hp.hpl.jena.vocabulary.RDF; /** * @@ -80,6 +89,7 @@ private boolean isLiteralNode = false; private boolean isResourceNode = false; + private boolean isBlankNode = false; private List<Literal> literals = new ArrayList<Literal>(); @@ -163,6 +173,14 @@ this.isLiteralNode = isLiteralNode; } + public void setBlankNode(boolean isBlankNode) { + this.isBlankNode = isBlankNode; + } + + public boolean isBlankNode() { + return isBlankNode; + } + @Override public boolean isResourceNode() { return isResourceNode; @@ -728,7 +746,7 @@ for(String filter : filters){ sb.append(filter).append("\n"); } - sb.append("}");System.out.println(sb.toString()); + sb.append("}"); Query query = QueryFactory.create(sb.toString(), Syntax.syntaxARQ); query.setPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); query.setPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); @@ -869,9 +887,9 @@ } else if(objectLabel.startsWith("http:")){ object = Node.createURI(objectLabel); } else { - System.out.println(objectLabel); +// System.out.println(objectLabel); String[] split = objectLabel.split("@"); - System.out.println(Arrays.toString(split)); +// System.out.println(Arrays.toString(split)); if(split.length == 2){ object = Node.createLiteral(split[0], split[1], null); } else { @@ -917,5 +935,73 @@ } } + public OWLClassExpression asOWLClassExpression(){ + OWLDataFactory df = new OWLDataFactoryImpl(); + QueryTree<N> root = getRoot(); + Set<OWLClassExpression> classExpressions = buildOWLClassExpressions(df, root); + if(classExpressions.size() == 1){ + return classExpressions.iterator().next(); + } else { + return df.getOWLObjectIntersectionOf(classExpressions); + } + } + + private Set<OWLClassExpression> buildOWLClassExpressions(OWLDataFactory df, QueryTree<N> tree){ + Set<OWLClassExpression> classExpressions = new HashSet<OWLClassExpression>(); + + List<QueryTree<N>> children = tree.getChildren(); + for(QueryTree<N> child : children){ + String childLabel = (String) child.getUserObject(); + String predicateString = (String) tree.getEdge(child); + if(predicateString.equals(RDF.type.getURI())){ + classExpressions.add(df.getOWLClass(IRI.create(childLabel))); + } else { + if(child.isLiteralNode()){ + OWLDataProperty p = df.getOWLDataProperty(IRI.create((String) tree.getEdge(child))); + if(childLabel.equals("?")){ + List<Literal> literals = child.getLiterals(); + Literal lit = literals.iterator().next(); + RDFDatatype datatype = lit.getDatatype(); + String datatypeURI; + if(datatype == null){ + datatypeURI = OWL2Datatype.RDF_PLAIN_LITERAL.getURI().toString(); + } else { + datatypeURI = datatype.getURI(); + } + classExpressions.add(df.getOWLDataSomeValuesFrom(p, df.getOWLDatatype(IRI.create(datatypeURI)))); + } else { + List<Literal> literals = child.getLiterals(); + Literal lit = literals.iterator().next(); + RDFDatatype datatype = lit.getDatatype(); + OWLLiteral owlLiteral; + if(datatype == null){ + owlLiteral = df.getOWLLiteral(lit.getLexicalForm(), lit.getLanguage()); + } else { + owlLiteral = df.getOWLLiteral(lit.getLexicalForm(), df.getOWLDatatype(IRI.create(datatype.getURI()))); + } + classExpressions.add(df.getOWLDataHasValue(p, owlLiteral)); + } + } else { + OWLObjectProperty p = df.getOWLObjectProperty(IRI.create((String) tree.getEdge(child))); + OWLClassExpression filler; + if(child.isVarNode()){ + Set<OWLClassExpression> fillerClassExpressions = buildOWLClassExpressions(df, child); + if(fillerClassExpressions.isEmpty()){ + filler = df.getOWLThing(); + } else if(fillerClassExpressions.size() == 1){ + filler = fillerClassExpressions.iterator().next(); + } else { + filler = df.getOWLObjectIntersectionOf(fillerClassExpressions); + } + classExpressions.add(df.getOWLObjectSomeValuesFrom(p, filler)); + } else { + classExpressions.add(df.getOWLObjectHasValue(p, df.getOWLNamedIndividual(IRI.create(childLabel)))); + } + } + } + } + return classExpressions; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -250,12 +250,12 @@ || lit.getDatatype() == XSDDatatype.XSDint || lit.getDatatype() == XSDDatatype.XSDdecimal){ subTree.addLiteral(lit); + } else { + subTree.addLiteral(lit); } + tree.addChild(subTree, st.getPredicate().toString()); } else if(objectFilter.isRelevantResource(object.asResource().getURI())){ - if(object.asResource().isAnon()){ - System.out.println(object); - } if(!tree.getUserObjectPathToRoot().contains(st.getObject().toString())){ subTree = new QueryTreeImpl<String>(st.getObject().toString()); subTree.setResourceNode(true); @@ -263,6 +263,9 @@ if(depth < maxDepth){ fillTree(subTree, resource2Statements, depth); } + if(object.isAnon()){ + subTree.setBlankNode(true); + } } } else if(object.isAnon()){ 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-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -121,7 +121,10 @@ } QueryTree<N> lgg = new QueryTreeImpl<N>(tree1.getUserObject()); - lgg.setLiteralNode(tree1.isLiteralNode()); + if(tree1.isResourceNode() && tree2.isResourceNode()){ + lgg.setResourceNode(true); + + } // if(!lgg.getUserObject().equals(tree2.getUserObject())){ // lgg.setUserObject((N)"?"); @@ -144,15 +147,19 @@ // } if(!lgg.getUserObject().equals(tree2.getUserObject())){ lgg.setUserObject((N)"?"); + lgg.setLiteralNode(false); + lgg.setResourceNode(false); } if(tree1.isLiteralNode() && tree2.isLiteralNode()){ RDFDatatype d1 = tree1.getDatatype(); RDFDatatype d2 = tree2.getDatatype(); - if(d1 != null && d2 != null && d1 == d2){ +// if(d1 != null && d2 != null && d1 == d2){ + if(d1 == d2){ ((QueryTreeImpl<N>)lgg).addLiterals(((QueryTreeImpl<N>)tree1).getLiterals()); ((QueryTreeImpl<N>)lgg).addLiterals(((QueryTreeImpl<N>)tree2).getLiterals()); } + lgg.setLiteralNode(true); } Set<QueryTreeImpl<N>> addedChildren; Modified: trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/core/EvaluatedAxiom.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -21,8 +21,8 @@ import java.io.PrintWriter; import java.io.StringWriter; +import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,8 +30,8 @@ import org.apache.commons.codec.digest.DigestUtils; import org.dllearner.core.owl.Axiom; import org.dllearner.utilities.EnrichmentVocabulary; +import org.dllearner.utilities.PrefixCCMap; import org.dllearner.utilities.owl.OWLAPIConverter; -import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAxiom; @@ -46,6 +46,8 @@ public class EvaluatedAxiom { + private static DecimalFormat df = new DecimalFormat("##0.0"); + private Axiom axiom; private Score score; @@ -113,5 +115,26 @@ return ind2Axioms; } + public static String prettyPrint(List<EvaluatedAxiom> learnedAxioms) { + String str = "suggested axioms and their score in percent:\n"; + if(learnedAxioms.isEmpty()) { + return " no axiom suggested\n"; + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + str += " " + prettyPrint(learnedAxiom) + "\n"; + } + } + return str; + } + + public static String prettyPrint(EvaluatedAxiom axiom) { + double acc = axiom.getScore().getAccuracy() * 100; + String accs = df.format(acc); + if(accs.length()==3) { accs = " " + accs; } + if(accs.length()==4) { accs = " " + accs; } + String str = accs + "%\t" + axiom.getAxiom().toManchesterSyntaxString(null, PrefixCCMap.getInstance()); + return str; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -720,8 +720,11 @@ // convert data back to DL-Learner structures SortedSet<Individual> is = new TreeSet<Individual>(); - for (OWLNamedIndividual oi : inds) - is.add(new Individual(oi.toStringID())); + for (OWLNamedIndividual oi : inds){ + if(oi != null){ + is.add(new Individual(oi.toStringID())); + } + } map.put(i, is); } return map; Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -84,7 +84,7 @@ import com.hp.hpl.jena.vocabulary.RDFS; @ComponentAnn(name = "SPARQL Reasoner", shortName = "spr", version = 0.1) -public class SPARQLReasoner implements SchemaReasoner, IndividualReasoner{ +public class SPARQLReasoner implements SchemaReasoner, IndividualReasoner { private static final Logger logger = LoggerFactory.getLogger(SPARQLReasoner.class); @@ -450,7 +450,7 @@ } public Set<NamedClass> getTypes() { - Set<NamedClass> types = new HashSet<NamedClass>(); + Set<NamedClass> types = new TreeSet<NamedClass>(); String query = String.format("SELECT DISTINCT ?class WHERE {[] a ?class.}"); ResultSet rs = executeSelectQuery(query); QuerySolution qs; @@ -519,7 +519,7 @@ throw new UnsupportedOperationException("Only named classes are supported."); } SortedSet<Individual> individuals = new TreeSet<Individual>(); - String query = String.format("SELECT ?ind WHERE {?ind a <%s>}", ((NamedClass)description).getName()); + String query = String.format("SELECT DISTINCT ?ind WHERE {?ind a <%s>}", ((NamedClass)description).getName()); if(limit != 0) { query += " LIMIT " + limit; } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIConverter.java 2013-04-25 08:12:24 UTC (rev 3928) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIConverter.java 2013-04-30 11:05:12 UTC (rev 3929) @@ -51,6 +51,8 @@ import org.semanticweb.owlapi.model.OWLNamedIndividual; import org.semanticweb.owlapi.model.OWLObjectProperty; +import eu.trowl.vocab.RDF; + /** * A collection of methods for exchanging objects between OWL API and * DL-Learner. @@ -191,7 +193,9 @@ return OWL2Datatype.DATE.getDatatype(); else if(iri.equals(OWL2Datatype.DATETIME.getIRI())) return OWL2Datatype.DATETIME.getDatatype(); - throw new Error("Unsupported datatype " + dataType + ". Please inform a DL-Learner developer to add it."); + else + return new Datatype(dataType.getIRI().toString()); +// throw new Error("Unsupported datatype " + dataType + ". Please inform a DL-Learner developer to add it."); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-02 07:36:03
|
Revision: 3931 http://sourceforge.net/p/dl-learner/code/3931 Author: lorenz_b Date: 2013-05-02 07:35:58 +0000 (Thu, 02 May 2013) Log Message: ----------- Some improvements in pattern detection workflow. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/OWLAxiomPatternFinder.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/OWLAxiomPatternFinder.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/OWLAxiomPatternFinder.java 2013-04-30 11:06:03 UTC (rev 3930) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/pattern/OWLAxiomPatternFinder.java 2013-05-02 07:35:58 UTC (rev 3931) @@ -14,9 +14,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Queue; +import java.util.Set; import java.util.prefs.Preferences; import org.dllearner.kb.dataset.OWLOntologyDataset; @@ -26,6 +28,7 @@ import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.OWLObjectRenderer; +import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; @@ -70,6 +73,7 @@ private Connection conn; private PreparedStatement selectOntologyIdPs; private PreparedStatement insertOntologyPs; + private PreparedStatement insertOntologyErrorPs; private PreparedStatement selectPatternIdPs; private PreparedStatement insertPatternIdPs; private PreparedStatement insertOntologyPatternPs; @@ -91,7 +95,9 @@ createTables(); try { selectOntologyIdPs = conn.prepareStatement("SELECT id FROM Ontology WHERE url=?"); - insertOntologyPs = conn.prepareStatement("INSERT INTO Ontology (url, iri, repository) VALUES(?,?,?)"); + insertOntologyPs = conn.prepareStatement("INSERT INTO Ontology (url, iri, repository, logical_axioms, tbox_axioms, rbox_axioms" + + ", abox_axioms, classes, object_properties, data_properties, individuals) VALUES(?,?,?,?,?,?,?,?,?,?,?)"); + insertOntologyErrorPs = conn.prepareStatement("INSERT INTO Ontology (url, iri, repository) VALUES(?,?,?)"); selectPatternIdPs = conn.prepareStatement("SELECT id FROM Pattern WHERE pattern=?"); insertPatternIdPs = conn.prepareStatement("INSERT INTO Pattern (pattern,pattern_pretty) VALUES(?,?)"); insertOntologyPatternPs = conn.prepareStatement("INSERT INTO Ontology_Pattern (ontology_id, pattern_id, occurrences) VALUES(?,?,?)"); @@ -156,6 +162,14 @@ + "url VARCHAR(2000) NOT NULL," + "iri VARCHAR(2000) NOT NULL," + "repository VARCHAR(200) NOT NULL," + + "logical_axioms MEDIUMINT DEFAULT 0," + + "tbox_axioms MEDIUMINT DEFAULT 0," + + "rbox_axioms MEDIUMINT DEFAULT 0," + + "abox_axioms MEDIUMINT DEFAULT 0," + + "classes MEDIUMINT DEFAULT 0," + + "object_properties MEDIUMINT DEFAULT 0," + + "data_properties MEDIUMINT DEFAULT 0," + + "individuals MEDIUMINT DEFAULT 0," + "PRIMARY KEY(id)," + "INDEX(url)) DEFAULT CHARSET=utf8"); @@ -222,10 +236,10 @@ String url = physicalURI.toString(); //add ontology loading/parsing/... error entry try { - insertOntologyPs.setString(1, url); - insertOntologyPs.setString(2, "ERROR:" + ex.getClass().getSimpleName() + "->" + ex.getMessage()); - insertOntologyPs.setString(3, repository.getName()); - insertOntologyPs.execute(); + insertOntologyErrorPs.setString(1, url); + insertOntologyErrorPs.setString(2, "ERROR:" + ex.getClass().getSimpleName() + (ex.getMessage() != null ? ("->" + ex.getMessage()) : "")); + insertOntologyErrorPs.setString(3, repository.getName()); + insertOntologyErrorPs.execute(); } catch (SQLException e) { e.printStackTrace(); } @@ -233,7 +247,10 @@ private int addOntology(URI physicalURI, OWLOntology ontology){ String url = physicalURI.toString(); - String ontologyIRI = ontology.getOntologyID().getOntologyIRI().toString(); + String ontologyIRI = "Anonymous"; + if(!ontology.getOntologyID().isAnonymous()){ + ontologyIRI = ontology.getOntologyID().getOntologyIRI().toString(); + } //check for existing entry try { selectOntologyIdPs.setString(1, url); @@ -249,6 +266,20 @@ insertOntologyPs.setString(1, url); insertOntologyPs.setString(2, ontologyIRI); insertOntologyPs.setString(3, repository.getName()); + Set<OWLAxiom> logicalAxioms = new HashSet<OWLAxiom>(); + logicalAxioms.addAll(ontology.getLogicalAxioms()); + Set<OWLAxiom> tbox = AxiomType.getAxiomsOfTypes(logicalAxioms, new ArrayList<AxiomType>(AxiomType.TBoxAxiomTypes).toArray(new AxiomType[AxiomType.TBoxAxiomTypes.size()])); + Set<OWLAxiom> rbox = AxiomType.getAxiomsOfTypes(logicalAxioms, new ArrayList<AxiomType>(AxiomType.RBoxAxiomTypes).toArray(new AxiomType[AxiomType.RBoxAxiomTypes.size()])); + Set<OWLAxiom> abox = AxiomType.getAxiomsOfTypes(logicalAxioms, new ArrayList<AxiomType>(AxiomType.ABoxAxiomTypes).toArray(new AxiomType[AxiomType.ABoxAxiomTypes.size()])); + + insertOntologyPs.setInt(4, ontology.getLogicalAxiomCount()); + insertOntologyPs.setInt(5, tbox.size()); + insertOntologyPs.setInt(6, rbox.size()); + insertOntologyPs.setInt(7, abox.size()); + insertOntologyPs.setInt(8, ontology.getClassesInSignature(true).size()); + insertOntologyPs.setInt(9, ontology.getObjectPropertiesInSignature(true).size()); + insertOntologyPs.setInt(10, ontology.getDataPropertiesInSignature(true).size()); + insertOntologyPs.setInt(11, ontology.getIndividualsInSignature(true).size()); insertOntologyPs.execute(); } catch (SQLException e) { e.printStackTrace(); @@ -293,9 +324,11 @@ Multiset<OWLAxiom> allAxiomPatterns = HashMultiset.create(); for (OntologyRepositoryEntry entry : entries) { URI uri = entry.getPhysicalURI(); +// if(uri.toString().startsWith("http://rest.bioontology.org/bioportal/ontologies/download/42764")){ if (!ontologyProcessed(uri)) { System.out.println("Loading \"" + entry.getOntologyShortName() + "\" from "+ uri); try { + manager = OWLManager.createOWLOntologyManager(); OWLOntology ontology = manager.loadOntology(IRI.create(uri)); Multiset<OWLAxiom> axiomPatterns = HashMultiset.create(); for (OWLLogicalAxiom axiom : ontology.getLogicalAxioms()) { 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-04-30 11:06:03 UTC (rev 3930) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-02 07:35:58 UTC (rev 3931) @@ -1,8 +1,10 @@ package org.dllearner.utilities.owl; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Stack; import org.aksw.commons.collections.diff.ModelDiff; @@ -31,6 +33,7 @@ import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLIndividual; import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; import org.semanticweb.owlapi.model.OWLObjectComplementOf; import org.semanticweb.owlapi.model.OWLObjectExactCardinality; @@ -62,7 +65,7 @@ private String sparql = ""; private Stack<String> variables = new Stack<String>(); - private Map<OWLEntity, String> variablesMapping; + private Map<OWLEntity, String> variablesMapping = new HashMap<OWLEntity, String>(); private int classCnt = 0; private int propCnt = 0; @@ -71,6 +74,7 @@ private OWLDataFactory df = new OWLDataFactoryImpl(); private Map<Integer, Boolean> intersection; + private Set<? extends OWLEntity> variableEntities; public OWLClassExpressionToSPARQLConverter() { } @@ -90,13 +94,37 @@ } public Query asQuery(String rootVariable, OWLClassExpression expr){ - String queryString = "SELECT DISTINCT " + rootVariable + " WHERE {"; - queryString += convert(rootVariable, expr); + return asQuery(rootVariable, expr, Collections.<OWLEntity>emptySet()); + } + + public Query asQuery(String rootVariable, OWLClassExpression expr, Set<? extends OWLEntity> variableEntities){ + this.variableEntities = variableEntities; + String queryString = "SELECT DISTINCT "; + String triplePattern = convert(rootVariable, expr); + if(variableEntities.isEmpty()){ + queryString += rootVariable + " WHERE {"; + } else { + for (OWLEntity owlEntity : variableEntities) { + String var = variablesMapping.get(owlEntity); + queryString += var + " "; + } + queryString += "COUNT(" + rootVariable + ") WHERE {"; + } + + queryString += triplePattern; queryString += "}"; + if(!variableEntities.isEmpty()){ + queryString += "GROUP BY "; + for (OWLEntity owlEntity : variableEntities) { + String var = variablesMapping.get(owlEntity); + queryString += var; + } + }System.out.println(queryString); return QueryFactory.create(queryString, Syntax.syntaxARQ); } private void reset(){ + variablesMapping.clear(); variables.clear(); classCnt = 0; propCnt = 0; @@ -143,7 +171,7 @@ private String triple(String subject, String predicate, String object){ return (subject.startsWith("?") ? subject : "<" + subject + ">") + " " + (predicate.startsWith("?") || predicate.equals("a") ? predicate : "<" + predicate + ">") + " " + - (object.startsWith("?") ? object : "<" + object + ">") + ".\n"; + (object.startsWith("?") ? object : object) + ".\n"; } private String triple(String subject, String predicate, OWLLiteral object){ @@ -152,12 +180,46 @@ render(object) + ".\n"; } + private String triple(String subject, String predicate, OWLEntity object){ + return (subject.startsWith("?") ? subject : "<" + subject + ">") + " " + + (predicate.startsWith("?") || predicate.equals("a") ? predicate : "<" + predicate + ">") + " " + + render(object) + ".\n"; + } + + private String triple(String subject, OWLEntity predicate, OWLEntity object){ + return (subject.startsWith("?") ? subject : "<" + subject + ">") + " " + + render(predicate) + " " + + render(object) + ".\n"; + } + + private String triple(String subject, OWLEntity predicate, String object){ + return (subject.startsWith("?") ? subject : "<" + subject + ">") + " " + + render(predicate) + " " + + object + ".\n"; + } + + private String triple(String subject, OWLEntity predicate, OWLLiteral object){ + return (subject.startsWith("?") ? subject : "<" + subject + ">") + " " + + render(predicate) + " " + + render(object) + ".\n"; + } + private String triple(String subject, String predicate, OWLIndividual object){ return (subject.startsWith("?") ? subject : "<" + subject + ">") + " " + (predicate.startsWith("?") || predicate.equals("a") ? predicate : "<" + predicate + ">") + " " + "<" + object.toStringID() + ">.\n"; } + private String render(OWLEntity entity){ + String s; + if(variableEntities.contains(entity)){ + s = getVariable(entity); + } else { + s = "<" + entity.toStringID() + ">"; + } + return s; + } + private String render(OWLLiteral literal){ return "\"" + literal + "\"^^<" + literal.getDatatype().toStringID() + ">"; } @@ -176,7 +238,7 @@ @Override public void visit(OWLClass ce) { - sparql += triple(variables.peek(), "a", ce.toStringID()); + sparql += triple(variables.peek(), "a", render(ce)); } @Override @@ -220,9 +282,9 @@ OWLObjectPropertyExpression propertyExpression = ce.getProperty(); if(propertyExpression.isAnonymous()){ //property expression is inverse of a property - sparql += triple(objectVariable, propertyExpression.getNamedProperty().toStringID(), variables.peek()); + sparql += triple(objectVariable, propertyExpression.getNamedProperty(), variables.peek()); } else { - sparql += triple(variables.peek(), propertyExpression.getNamedProperty().toStringID(), objectVariable); + sparql += triple(variables.peek(), propertyExpression.getNamedProperty(), objectVariable); } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ @@ -230,7 +292,7 @@ filler.accept(this); variables.pop(); } else { - sparql += triple(objectVariable, "a", filler.asOWLClass().toStringID()); + sparql += triple(objectVariable, "a", filler.asOWLClass()); } } @@ -240,7 +302,7 @@ String subject = variables.peek(); String objectVariable = buildIndividualVariable(); OWLObjectPropertyExpression propertyExpression = ce.getProperty(); - String predicate = propertyExpression.getNamedProperty().toStringID(); + OWLObjectProperty predicate = propertyExpression.getNamedProperty(); OWLClassExpression filler = ce.getFiller(); if(propertyExpression.isAnonymous()){ //property expression is inverse of a property @@ -269,12 +331,12 @@ @Override public void visit(OWLObjectHasValue ce) { OWLObjectPropertyExpression propertyExpression = ce.getProperty(); - OWLIndividual value = ce.getValue(); + OWLNamedIndividual value = ce.getValue().asOWLNamedIndividual(); if(propertyExpression.isAnonymous()){ //property expression is inverse of a property - sparql += triple(value.toStringID(), propertyExpression.getNamedProperty().toStringID(), variables.peek()); + sparql += triple(value.toStringID(), propertyExpression.getNamedProperty(), variables.peek()); } else { - sparql += triple(variables.peek(), propertyExpression.getNamedProperty().toStringID(), value.toStringID()); + sparql += triple(variables.peek(), propertyExpression.getNamedProperty(), value); } } @@ -287,9 +349,9 @@ sparql += "{SELECT " + subjectVariable + " WHERE {"; if(propertyExpression.isAnonymous()){ //property expression is inverse of a property - sparql += triple(objectVariable, propertyExpression.getNamedProperty().toStringID(), subjectVariable); + sparql += triple(objectVariable, propertyExpression.getNamedProperty(), subjectVariable); } else { - sparql += triple(subjectVariable, propertyExpression.getNamedProperty().toStringID(), objectVariable); + sparql += triple(subjectVariable, propertyExpression.getNamedProperty(), objectVariable); } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ @@ -299,7 +361,7 @@ filler.accept(this); variables.pop(); } else { - sparql += triple(objectVariable, "a", filler.asOWLClass().toStringID()); + sparql += triple(objectVariable, "a", filler.asOWLClass()); } sparql += "} GROUP BY " + subjectVariable + " HAVING(COUNT(" + objectVariable + ")>=" + cardinality + ")}"; @@ -315,9 +377,9 @@ sparql += "{SELECT " + subjectVariable + " WHERE {"; if(propertyExpression.isAnonymous()){ //property expression is inverse of a property - sparql += triple(objectVariable, propertyExpression.getNamedProperty().toStringID(), subjectVariable); + sparql += triple(objectVariable, propertyExpression.getNamedProperty(), subjectVariable); } else { - sparql += triple(subjectVariable, propertyExpression.getNamedProperty().toStringID(), objectVariable); + sparql += triple(subjectVariable, propertyExpression.getNamedProperty(), objectVariable); } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ @@ -327,7 +389,7 @@ filler.accept(this); variables.pop(); } else { - sparql += triple(objectVariable, "a", filler.asOWLClass().toStringID()); + sparql += triple(objectVariable, "a", filler.asOWLClass()); } sparql += "} GROUP BY " + subjectVariable + " HAVING(COUNT(" + objectVariable + ")=" + cardinality + ")}"; @@ -342,9 +404,9 @@ sparql += "{SELECT " + subjectVariable + " WHERE {"; if(propertyExpression.isAnonymous()){ //property expression is inverse of a property - sparql += triple(objectVariable, propertyExpression.getNamedProperty().toStringID(), subjectVariable); + sparql += triple(objectVariable, propertyExpression.getNamedProperty(), subjectVariable); } else { - sparql += triple(subjectVariable, propertyExpression.getNamedProperty().toStringID(), objectVariable); + sparql += triple(subjectVariable, propertyExpression.getNamedProperty(), objectVariable); } OWLClassExpression filler = ce.getFiller(); if(filler.isAnonymous()){ @@ -354,7 +416,7 @@ filler.accept(this); variables.pop(); } else { - sparql += triple(objectVariable, "a", filler.asOWLClass().toStringID()); + sparql += triple(objectVariable, "a", filler.asOWLClass()); } sparql += "} GROUP BY " + subjectVariable + " HAVING(COUNT(" + objectVariable + ")<=" + cardinality + ")}"; @@ -364,7 +426,7 @@ public void visit(OWLObjectHasSelf ce) { String subject = variables.peek(); OWLObjectPropertyExpression property = ce.getProperty(); - sparql += triple(subject, property.getNamedProperty().toStringID(), subject); + sparql += triple(subject, property.getNamedProperty(), subject); } @Override @@ -390,7 +452,7 @@ public void visit(OWLDataSomeValuesFrom ce) { String objectVariable = buildIndividualVariable(); OWLDataPropertyExpression propertyExpression = ce.getProperty(); - sparql += triple(variables.peek(), propertyExpression.asOWLDataProperty().toStringID(), objectVariable); + sparql += triple(variables.peek(), propertyExpression.asOWLDataProperty(), objectVariable); OWLDataRange filler = ce.getFiller(); variables.push(objectVariable); filler.accept(this); @@ -426,7 +488,7 @@ public void visit(OWLDataHasValue ce) { OWLDataPropertyExpression propertyExpression = ce.getProperty(); OWLLiteral value = ce.getValue(); - sparql += triple(variables.peek(), propertyExpression.asOWLDataProperty().toStringID(), value); + sparql += triple(variables.peek(), propertyExpression.asOWLDataProperty(), value); } @Override @@ -436,7 +498,7 @@ OWLDataPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; - sparql += triple(subjectVariable, propertyExpression.asOWLDataProperty().toStringID(), objectVariable); + sparql += triple(subjectVariable, propertyExpression.asOWLDataProperty(), objectVariable); OWLDataRange filler = ce.getFiller(); variables.push(objectVariable); filler.accept(this); @@ -452,7 +514,7 @@ OWLDataPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; - sparql += triple(subjectVariable, propertyExpression.asOWLDataProperty().toStringID(), objectVariable); + sparql += triple(subjectVariable, propertyExpression.asOWLDataProperty(), objectVariable); OWLDataRange filler = ce.getFiller(); variables.push(objectVariable); filler.accept(this); @@ -468,7 +530,7 @@ OWLDataPropertyExpression propertyExpression = ce.getProperty(); int cardinality = ce.getCardinality(); sparql += "{SELECT " + subjectVariable + " WHERE {"; - sparql += triple(subjectVariable, propertyExpression.asOWLDataProperty().toStringID(), objectVariable); + sparql += triple(subjectVariable, propertyExpression.asOWLDataProperty(), objectVariable); OWLDataRange filler = ce.getFiller(); variables.push(objectVariable); filler.accept(this); @@ -642,6 +704,13 @@ query = converter.asQuery(rootVar, expr).toString(); System.out.println(expr + "\n" + query); + //variable entity + expr = df.getOWLObjectIntersectionOf( + df.getOWLObjectSomeValuesFrom(propR, clsB), + clsB); + query = converter.asQuery(rootVar, expr, Collections.singleton(propR)).toString(); + System.out.println(expr + "\n" + query); + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-05-02 08:43:10
|
Revision: 3932 http://sourceforge.net/p/dl-learner/code/3932 Author: lorenz_b Date: 2013-05-02 08:43:07 +0000 (Thu, 02 May 2013) Log Message: ----------- Added noise aware LGG generator. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2013-05-02 08:43:07 UTC (rev 3932) @@ -0,0 +1,42 @@ +package org.dllearner.algorithms.qtl.operations.lgg; + +import java.util.Collection; + +import org.dllearner.algorithms.qtl.datastructures.QueryTree; + +public class EvaluatedQueryTree<N> implements Comparable<EvaluatedQueryTree<N>>{ + + private QueryTree<N> tree; + private Collection<QueryTree<N>> uncoveredExamples; + private double score; + + public EvaluatedQueryTree(QueryTree<N> tree, Collection<QueryTree<N>> uncoveredExamples, double score) { + this.tree = tree; + this.uncoveredExamples = uncoveredExamples; + this.score = score; + } + + public QueryTree<N> getTree() { + return tree; + } + + public Collection<QueryTree<N>> getUncoveredExamples() { + return uncoveredExamples; + } + + public double getScore() { + return score; + } + + @Override + public int compareTo(EvaluatedQueryTree<N> other) { + double diff = score - other.getScore(); + if(diff == 0){ + return -1; + } else if(diff > 0){ + return -1; + } else { + return 1; + } + } +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/NoiseSensitiveLGG.java 2013-05-02 08:43:07 UTC (rev 3932) @@ -0,0 +1,111 @@ +package org.dllearner.algorithms.qtl.operations.lgg; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.algorithms.qtl.datastructures.QueryTree; + +public class NoiseSensitiveLGG<N> { + + private LGGGenerator<N> lggGenerator = new LGGGeneratorImpl<N>(); + + private Queue<EvaluatedQueryTree<N>> todoList; + private SortedSet<EvaluatedQueryTree<N>> solutions; + + public NoiseSensitiveLGG() { + } + + public List<EvaluatedQueryTree<N>> computeLGG(List<QueryTree<N>> trees){ + init(trees); + EvaluatedQueryTree<N> currentElement; + do{ + //pick best element from todo list + currentElement = todoList.poll(); + for (QueryTree<N> example : currentElement.getUncoveredExamples()) { + QueryTree<N> tree = currentElement.getTree(); + //compute the LGG + QueryTree<N> lgg = lggGenerator.getLGG(tree, example); + //compute examples which are not covered by LGG + Collection<QueryTree<N>> uncoveredExamples = new HashSet<QueryTree<N>>(); + for (QueryTree<N> queryTree : trees) { + boolean subsumed = queryTree.isSubsumedBy(lgg); + if(!subsumed){ + uncoveredExamples.add(queryTree); + } + } + //compute score + double score = (trees.size() - uncoveredExamples.size()) / (double)trees.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); + } + solutions.add(currentElement); +// todoList.remove(currentElement); + } while(!terminationCriteriaSatisfied()); + return new ArrayList<EvaluatedQueryTree<N>>(solutions); + } + + private void init(List<QueryTree<N>> trees){ + todoList = new PriorityQueue<EvaluatedQueryTree<N>>(); + solutions = new TreeSet<EvaluatedQueryTree<N>>(); +// 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) { + boolean distinct = true; + for (QueryTree<N> otherTree : distinctTrees) { + if(queryTree.isSubsumedBy(otherTree)){ + distinct = false; + break; + } + } + if(distinct){ + distinctTrees.add(queryTree); + } + } + for (QueryTree<N> queryTree : distinctTrees) { + Collection<QueryTree<N>> uncoveredExamples = new HashSet<QueryTree<N>>(distinctTrees); + uncoveredExamples.remove(queryTree); + double score = (trees.size() - uncoveredExamples.size()) / (double)trees.size(); + todoList.add(new EvaluatedQueryTree<N>(queryTree, uncoveredExamples, score)); + } + } + + /** + * Add tree to todo list if not already contained in that list or the solutions. + * @param solution + */ + private void todo(EvaluatedQueryTree<N> solution){ + //check if not already contained in todo list + for (EvaluatedQueryTree<N> evTree : todoList) { + if(sameTrees(solution.getTree(), evTree.getTree())){ + return; + } + } + //check if not already contained in solutions + for (EvaluatedQueryTree<N> evTree : solutions) { + if(sameTrees(solution.getTree(), evTree.getTree())){ + return; + } + } + todoList.add(solution); + } + + private boolean sameTrees(QueryTree<N> tree1, QueryTree<N> tree2){ + return tree1.isSubsumedBy(tree2) && tree2.isSubsumedBy(tree1); + } + + private boolean terminationCriteriaSatisfied(){ + return todoList.isEmpty(); + } + + + +} 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-02 07:35:58 UTC (rev 3931) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLClassExpressionToSPARQLConverter.java 2013-05-02 08:43:07 UTC (rev 3932) @@ -119,7 +119,7 @@ String var = variablesMapping.get(owlEntity); queryString += var; } - }System.out.println(queryString); + } return QueryFactory.create(queryString, Syntax.syntaxARQ); } 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: <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. |
From: <lor...@us...> - 2013-06-11 13:07:45
|
Revision: 3988 http://sourceforge.net/p/dl-learner/code/3988 Author: lorenz_b Date: 2013-06-11 13:07:42 +0000 (Tue, 11 Jun 2013) Log Message: ----------- Added QueryExecutionFactory using TURTLE for CONSTRUCT queries. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.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 trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLEntityTypeAdder.java 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-06-11 13:06:13 UTC (rev 3987) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2013-06-11 13:07:42 UTC (rev 3988) @@ -11,7 +11,7 @@ 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.http.QueryExecutionFactoryHttp; import org.aksw.jena_sparql_api.model.QueryExecutionFactoryModel; import org.aksw.jena_sparql_api.pagination.core.QueryExecutionFactoryPaginated; import org.apache.log4j.Level; Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-06-11 13:06:13 UTC (rev 3987) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-06-11 13:07:42 UTC (rev 3988) @@ -492,7 +492,7 @@ * @return */ public Set<NamedClass> getSiblingClasses(NamedClass cls) { - Set<NamedClass> siblings = new HashSet<NamedClass>(); + 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); 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-11 13:06:13 UTC (rev 3987) +++ trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/SetManipulation.java 2013-06-11 13:07:42 UTC (rev 3988) @@ -90,27 +90,25 @@ } return ret; } - + /** * shrinks a set to the limit takes the first elements up to limit * * @param set * @param limit */ - public static SortedSet<String> stableShrink(SortedSet<String> set, + public static <T> SortedSet<T> stableShrink(SortedSet<T> set, int limit) { if (set.size() <= limit) { return set; } - SortedSet<String> ret = new TreeSet<String>(); + SortedSet<T> ret = new TreeSet<T>(); - for (String oneInd : set) { + for (T oneInd : set) { ret.add(oneInd); if (ret.size() >= limit) break; - } - return ret; } 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-11 13:06:13 UTC (rev 3987) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java 2013-06-11 13:07:42 UTC (rev 3988) @@ -196,7 +196,7 @@ siblingNegativeExamples.addAll(sr.getIndividualsExcluding(siblingClass, nc, limit)); } } - siblingNegativeExamples = SetManipulation.fuzzyShrink(siblingNegativeExamples, strategyLimit); + siblingNegativeExamples = SetManipulation.stableShrink(siblingNegativeExamples, strategyLimit); negativeExamples.addAll(siblingNegativeExamples); } else if(strategy == SUPERCLASS){//get super class based examples SortedSet<Individual> superClassNegativeExamples = new TreeSet<Individual>(); @@ -214,7 +214,7 @@ superClassNegativeExamples.addAll(sr.getIndividualsExcluding(superClass, nc, limit)); } } - superClassNegativeExamples = SetManipulation.fuzzyShrink(superClassNegativeExamples, strategyLimit); + superClassNegativeExamples = SetManipulation.stableShrink(superClassNegativeExamples, strategyLimit); negativeExamples.addAll(superClassNegativeExamples); } else if(strategy == RANDOM){//get some random examples 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-06-11 13:06:13 UTC (rev 3987) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLEntityTypeAdder.java 2013-06-11 13:07:42 UTC (rev 3988) @@ -38,6 +38,16 @@ } } iterator.close(); + for (Property property : dataPropertyPredicates) { + if(!objectPropertyPredicates.contains(property)){ + model.add(property, RDF.type, OWL.DatatypeProperty); + } + } + for (Property property : objectPropertyPredicates) { + if(!dataPropertyPredicates.contains(property)){ + model.add(property, RDF.type, OWL.ObjectProperty); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-06-12 07:34:34
|
Revision: 3989 http://sourceforge.net/p/dl-learner/code/3989 Author: lorenz_b Date: 2013-06-12 07:34:30 +0000 (Wed, 12 Jun 2013) Log Message: ----------- Added class for query execution. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/QueryExecutionFactoryHttp.java 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-11 13:07:42 UTC (rev 3988) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2013-06-12 07:34:30 UTC (rev 3989) @@ -71,6 +71,8 @@ } public SortedSet<Description> getSubClasses(Description concept) { + String s= concept.toString(); + SortedSet<Description> result = subsumptionHierarchyDown.get(concept); if(result == null) { logger.error("Query for sub class of " + concept + " in subsumption hierarchy, but the class is not contained in the (downward) hierarchy, e.g. because the class does not exist or is ignored. Returning empty result instead."); Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/QueryExecutionFactoryHttp.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/QueryExecutionFactoryHttp.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/QueryExecutionFactoryHttp.java 2013-06-12 07:34:30 UTC (rev 3989) @@ -0,0 +1,60 @@ +package org.dllearner.kb.sparql; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.aksw.jena_sparql_api.core.QueryExecutionFactoryBackString; + +import com.google.common.base.Joiner; +import com.hp.hpl.jena.query.QueryExecution; + +/** + * @author Claus Stadler + * <p/> + * Date: 7/23/11 + * Time: 9:47 PM + */ +public class QueryExecutionFactoryHttp + extends QueryExecutionFactoryBackString +{ + private String service; + + private List<String> defaultGraphs = new ArrayList<String>(); + + public QueryExecutionFactoryHttp(String service) { + this(service, Collections.<String>emptySet()); + } + + public QueryExecutionFactoryHttp(String service, String defaultGraphName) { + this(service, Collections.singleton(defaultGraphName)); + } + + public QueryExecutionFactoryHttp(String service, Collection<String> defaultGraphs) { + this.service = service; + this.defaultGraphs = new ArrayList<String>(defaultGraphs); + Collections.sort(this.defaultGraphs); + } + + @Override + public String getId() { + return service; + } + + @Override + public String getState() { + return Joiner.on("|").join(defaultGraphs); + } + + @Override + public QueryExecution createQueryExecution(String queryString) { + QueryEngineHTTP result = new QueryEngineHTTP(service, queryString); + result.setDefaultGraphURIs(defaultGraphs); + + //QueryExecution result = QueryExecutionWrapper.wrap(engine); + + return result; + } +} + Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2013-06-11 13:07:42 UTC (rev 3988) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2013-06-12 07:34:30 UTC (rev 3989) @@ -310,6 +310,9 @@ // System.out.println("FIC: " + description + " " + individual); if (description instanceof NamedClass) { + if(((NamedClass) description).getURI().equals(Thing.instance.getURI())){ + return true; + } else if(!atomicConcepts.contains(description)) { throw new ReasoningMethodUnsupportedException("Class " + description + " is not contained in knowledge base."); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-06-11 13:07:42 UTC (rev 3988) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-06-12 07:34:30 UTC (rev 3989) @@ -104,6 +104,8 @@ private Map<DatatypeProperty, Integer> dataPropertyPopularityMap; private boolean prepared = false; + + private ConceptComparator conceptComparator = new ConceptComparator(); public SPARQLReasoner(SparqlEndpointKS ks) { @@ -602,7 +604,6 @@ if(limit != 0) { query += " LIMIT " + limit; } - System.out.println("query: "+query); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -1149,16 +1150,22 @@ if(description instanceof Nothing){ description = new NamedClass("http://www.w3.org/2002/07/owl#Nothing"); } - SortedSet<Description> superClasses = new TreeSet<Description>(); + SortedSet<Description> superClasses = new TreeSet<Description>(conceptComparator); 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; + String uri = null; while(rs.hasNext()){ qs = rs.next(); - superClasses.add(new NamedClass(qs.getResource("sup").getURI())); + uri = qs.getResource("sup").getURI(); + if(uri.equals(Thing.instance.getURI().toString())){ + superClasses.add(Thing.instance); + } else { + superClasses.add(new NamedClass(uri)); + } } superClasses.remove(description); return superClasses; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2013-09-05 07:22:41
|
Revision: 4080 http://sourceforge.net/p/dl-learner/code/4080 Author: andremelo Date: 2013-09-05 07:22:38 +0000 (Thu, 05 Sep 2013) Log Message: ----------- Fixing PrefixTrie IndexOutOfBounds and NullPointerEnception Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java 2013-09-04 16:44:09 UTC (rev 4079) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java 2013-09-05 07:22:38 UTC (rev 4080) @@ -55,7 +55,8 @@ @Override public String getLongestMatch(String s) { - return trie.getLongestMatch(s).toString(); + CharSequence match = trie.getLongestMatch(s); + return (match!=null) ? trie.getLongestMatch(s).toString() : null; } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java 2013-09-04 16:44:09 UTC (rev 4079) +++ trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java 2013-09-05 07:22:38 UTC (rev 4080) @@ -116,7 +116,10 @@ break; } } - return s.subSequence(0, i-1); + if (i<=0) + return null; + else + return s.subSequence(0, i-1); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2013-09-05 08:52:51
|
Revision: 4086 http://sourceforge.net/p/dl-learner/code/4086 Author: andremelo Date: 2013-09-05 08:52:49 +0000 (Thu, 05 Sep 2013) Log Message: ----------- Fixing getLongestMatch method and adding toString to SimpleEntityCandidatesTrie Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java 2013-09-05 08:42:59 UTC (rev 4085) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java 2013-09-05 08:52:49 UTC (rev 4086) @@ -63,17 +63,23 @@ return (match!=null) ? trie.getLongestMatch(s).toString() : null; } - public void printTrie() { - System.out.println("Printing tree content:"); + public String toString() { + String output = ""; Map<String,Set<Entity>> trieMap = trie.toMap(); List<String> termsList = new ArrayList(trieMap.keySet()); Collections.sort(termsList); for (String key : termsList) { - System.out.println(key); + output += key + ": ("; for (Entity candidate: trieMap.get(key)) { - System.out.println("\t"+candidate); + output += "\t"+candidate+"\n"; } } + return output; } + + public void printTrie() { + System.out.println(this.toString()); + + } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java 2013-09-05 08:42:59 UTC (rev 4085) +++ trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java 2013-09-05 08:52:49 UTC (rev 4086) @@ -104,6 +104,7 @@ } public CharSequence getLongestMatch(CharSequence s) { + Node<T> deepestWithValue = root; Node<T> current = root; int i; for (i = 0; i < s.length(); i++) { @@ -115,8 +116,11 @@ if (current == null) { break; } + if (current.value != null) { + deepestWithValue = current; + } } - if (i<=1) + if (i<=1 || deepestWithValue==root) return null; else return s.subSequence(1, i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2013-09-05 09:26:49
|
Revision: 4089 http://sourceforge.net/p/dl-learner/code/4089 Author: andremelo Date: 2013-09-05 09:26:44 +0000 (Thu, 05 Sep 2013) Log Message: ----------- Adding contains to PrefixTrie and fixing addEntry in SimpleEntityCandidatesTrie Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java 2013-09-05 09:21:08 UTC (rev 4088) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/SimpleEntityCandidatesTrie.java 2013-09-05 09:26:44 UTC (rev 4089) @@ -43,8 +43,10 @@ @Override public void addEntry(String s, Entity e) { - Set<Entity> candidates = trie.get(s); - if (candidates==null) + Set<Entity> candidates; + if (trie.contains(s)) + candidates = trie.get(s); + else candidates = new HashSet<Entity>(); candidates.add(e); @@ -69,7 +71,7 @@ List<String> termsList = new ArrayList(trieMap.keySet()); Collections.sort(termsList); for (String key : termsList) { - output += key + ": ("; + output += key + ":\n"; for (Entity candidate: trieMap.get(key)) { output += "\t"+candidate+"\n"; } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java 2013-09-05 09:21:08 UTC (rev 4088) +++ trunk/components-core/src/main/java/org/dllearner/utilities/datastructures/PrefixTrie.java 2013-09-05 09:26:44 UTC (rev 4089) @@ -82,6 +82,21 @@ current.value = value; return oldValue; } + + public boolean contains(CharSequence s) { + Node<T> current = root; + for (int i = 0; i < s.length(); i++) { + int nodeIndex = s.charAt(i) - rangeOffset; + if (nodeIndex < 0 || rangeSize <= nodeIndex) { + return false; + } + current = current.next[nodeIndex]; + if (current == null) { + return false; + } + } + return (current.value!=null); + } /** {@inheritDoc} */ public T get(CharSequence s) { @@ -120,10 +135,10 @@ deepestWithValue = current; } } - if (i<=1 || deepestWithValue==root) + if (i<=1 || deepestWithValue==root || deepestWithValue.value==null) return null; else - return s.subSequence(1, i); + return s.subSequence(0, i); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-10-03 10:30:58
|
Revision: 4116 http://sourceforge.net/p/dl-learner/code/4116 Author: lorenz_b Date: 2013-10-03 10:30:55 +0000 (Thu, 03 Oct 2013) Log Message: ----------- Added equals + hashcode to disjointness axiom. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-10-03 09:14:35 UTC (rev 4115) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-10-03 10:30:55 UTC (rev 4116) @@ -132,8 +132,6 @@ return; } - computeAllDisjointClassAxiomsOptimized(); - //at first get all existing classes in knowledge base allClasses = getAllClasses(); allClasses.remove(classToDescribe); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2013-10-03 09:14:35 UTC (rev 4115) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2013-10-03 10:30:55 UTC (rev 4116) @@ -119,6 +119,39 @@ } sb.append(")"); return sb.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((descriptions == null) ? 0 : descriptions.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DisjointClassesAxiom other = (DisjointClassesAxiom) obj; + if (descriptions == null) { + if (other.descriptions != null) + return false; + } else if (!descriptions.equals(other.descriptions)) + return false; + return true; } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-10-04 21:00:15
|
Revision: 4117 http://sourceforge.net/p/dl-learner/code/4117 Author: lorenz_b Date: 2013-10-04 21:00:12 +0000 (Fri, 04 Oct 2013) Log Message: ----------- Adapted log levels. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-10-03 10:30:55 UTC (rev 4116) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-10-04 21:00:12 UTC (rev 4117) @@ -505,9 +505,19 @@ return evaluatedDescriptions; } - private EvaluatedAxiom computeDisjointess(NamedClass clsA, NamedClass clsB){ + public EvaluatedAxiom computeDisjointess(NamedClass clsA, NamedClass clsB){ logger.debug("Computing disjointness between " + clsA + " and " + clsB + "..."); + //if clsA = clsB + if(clsA.equals(clsB)){ + return new EvaluatedAxiom(new DisjointClassesAxiom(clsA, clsB), new AxiomScore(0d, 1d)); + }; + + //if the classes are connected via subsumption we assume that they are not disjoint + if(reasoner.isSuperClassOf(clsA, clsB) || reasoner.isSuperClassOf(clsB, clsA)){ + return new EvaluatedAxiom(new DisjointClassesAxiom(clsA, clsB), new AxiomScore(0d, 1d)); + }; + double scoreValue = 0; //get number of instances of A Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2013-10-03 10:30:55 UTC (rev 4116) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2013-10-04 21:00:12 UTC (rev 4117) @@ -278,7 +278,7 @@ } protected Model executeConstructQuery(String query) { - logger.debug("Sending query\n{} ...", query); + logger.trace("Sending query\n{} ...", query); if(ks.isRemote()){ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), @@ -315,7 +315,7 @@ } protected ResultSet executeSelectQuery(String query) { - logger.info("Sending query\n{} ...", query); + logger.trace("Sending query\n{} ...", query); if(ks.isRemote()){ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), @@ -347,7 +347,7 @@ } protected ResultSet executeSelectQuery(String query, Model model) { - logger.debug("Sending query on local model\n{} ...", query); + logger.trace("Sending query on local model\n{} ...", query); QueryExecution qexec = QueryExecutionFactory.create(QueryFactory.create(query, Syntax.syntaxARQ), model); ResultSet rs = qexec.execSelect();; @@ -355,7 +355,7 @@ } protected boolean executeAskQuery(String query){ - logger.debug("Sending query\n{} ...", query); + logger.trace("Sending query\n{} ...", query); if(ks.isRemote()){ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-10-03 10:30:55 UTC (rev 4116) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-10-04 21:00:12 UTC (rev 4117) @@ -592,6 +592,22 @@ } return types; } + + public Set<NamedClass> getTypes(Individual individual, String namespace) { + Set<NamedClass> types = new HashSet<NamedClass>(); + String query = "SELECT DISTINCT ?class WHERE {<" + individual.getName() + "> a ?class."; + if(namespace != null){ + query += "FILTER(REGEX(STR(?class),'^" + namespace + "'))"; + } + query += "}"; + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + types.add(new NamedClass(qs.getResource("class").getURI())); + } + return types; + } public Set<NamedClass> getTypes() { return getTypes((String)null); @@ -1638,14 +1654,14 @@ } private ResultSet executeSelectQuery(String query){ - logger.debug("Sending query \n {}", query); + logger.trace("Sending query \n {}", query); QueryExecution qe = qef.createQueryExecution(query); ResultSet rs = qe.execSelect(); return rs; } private ResultSet executeSelectQuery(String query, long timeout){ - logger.debug("Sending query \n {}", query); + logger.trace("Sending query \n {}", query); QueryExecution qe = qef.createQueryExecution(query); qe.setTimeout(timeout); ResultSet rs = qe.execSelect(); @@ -1653,7 +1669,7 @@ } private boolean executeAskQuery(String query){ - logger.debug("Sending query \n {}", query); + logger.trace("Sending query \n {}", query); QueryExecution qe = qef.createQueryExecution(query); boolean ret = qe.execAsk(); return ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-05-23 12:03:42
|
Revision: 4271 http://sourceforge.net/p/dl-learner/code/4271 Author: lorenz_b Date: 2014-05-23 12:03:39 +0000 (Fri, 23 May 2014) Log Message: ----------- Added support for inter min max datarange. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java 2014-05-22 11:04:32 UTC (rev 4270) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java 2014-05-23 12:03:39 UTC (rev 4271) @@ -58,11 +58,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " <= " + value; + return "integer[<= " + value + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " <= " + value; + return "integer[<= " + value + "]"; } public void accept(KBElementVisitor visitor) { @@ -74,7 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " <= " + value; + return "integer[<= " + value + "]"; } /* (non-Javadoc) @@ -85,4 +85,12 @@ return false; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return toString(null, null); + } + } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java 2014-05-22 11:04:32 UTC (rev 4270) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java 2014-05-23 12:03:39 UTC (rev 4271) @@ -58,11 +58,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " >= " + value; + return "integer[>= " + value + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " >= " + value; + return "integer[>= " + value + "]"; } public void accept(KBElementVisitor visitor) { @@ -74,7 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " >= " + value; + return "integer[>= " + value + "]"; } /* (non-Javadoc) @@ -84,4 +84,12 @@ public boolean isDatatype() { return false; } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return toString(null, null); + } } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-05-22 11:04:32 UTC (rev 4270) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-05-23 12:03:39 UTC (rev 4271) @@ -53,6 +53,8 @@ import org.dllearner.core.owl.DoubleMinValue; import org.dllearner.core.owl.Entity; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.IntMaxValue; +import org.dllearner.core.owl.IntMinValue; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; @@ -73,8 +75,6 @@ import org.dllearner.parser.ParseException; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptTransformation; -import org.semanticweb.owlapi.owllink.builtin.requests.IsDataPropertySatisfiable; -import org.semanticweb.owlapi.vocab.OWL2Datatype; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.propertyeditors.StringTrimmerEditor; @@ -563,22 +563,39 @@ } else { return false; } - } - SortedSet<Double> values = dd.get(dp).get(individual); + } else { + if(dr instanceof IntMaxValue || dr instanceof IntMinValue){ + SortedSet<Integer> values = id.get(dp).get(individual); - // if there is no filler for this individual and property we - // need to return false - if (values == null) { - return false; - } + // if there is no filler for this individual and property we + // need to return false + if (values == null) { + return false; + } + if (dr instanceof IntMaxValue) { + return (values.first() <= ((IntMaxValue) dr).getValue()); + } else if (dr instanceof IntMinValue) { + return (values.last() >= ((IntMinValue) dr).getValue()); + } + } else { + SortedSet<Double> values = dd.get(dp).get(individual); - if (dr instanceof DoubleMaxValue) { - return (values.first() <= ((DoubleMaxValue) dr).getValue()); - } else if (dr instanceof DoubleMinValue) { - return (values.last() >= ((DoubleMinValue) dr).getValue()); - } else if (dr instanceof DoubleMinMaxRange){ - return (values.first() <= ((DoubleMinMaxRange) dr).getMaxValue()) && (values.last() >= ((DoubleMinMaxRange) dr).getMinValue()); + // if there is no filler for this individual and property we + // need to return false + if (values == null) { + return false; + } + if (dr instanceof DoubleMaxValue) { + return (values.first() <= ((DoubleMaxValue) dr).getValue()); + } else if (dr instanceof DoubleMinValue) { + return (values.last() >= ((DoubleMinValue) dr).getValue()); + } else if (dr instanceof DoubleMinMaxRange){ + return (values.first() <= ((DoubleMinMaxRange) dr).getMaxValue()) && (values.last() >= ((DoubleMinMaxRange) dr).getMinValue()); + } + } + } + } else if (description instanceof DatatypeValueRestriction) { Constant value = ((DatatypeValueRestriction)description).getValue(); DatatypeProperty dp = ((DatatypeValueRestriction)description).getRestrictedPropertyExpression(); Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-05-22 11:04:32 UTC (rev 4270) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-05-23 12:03:39 UTC (rev 4271) @@ -53,6 +53,8 @@ import org.dllearner.core.owl.DoubleMaxValue; import org.dllearner.core.owl.DoubleMinValue; import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.IntMaxValue; +import org.dllearner.core.owl.IntMinValue; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; @@ -96,8 +98,10 @@ public class RhoDRDown extends RefinementOperatorAdapter implements Component, CustomHierarchyRefinementOperator, CustomStartRefinementOperator, ReasoningBasedRefinementOperator { private static Logger logger = Logger - .getLogger(RhoDRDown.class); + .getLogger(RhoDRDown.class); + private static final NamedClass OWL_THING = new NamedClass(Thing.uri); + private AbstractReasonerComponent reasoner; // hierarchies @@ -152,18 +156,21 @@ private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); private Map<NamedClass, Set<DatatypeProperty>> appSD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appID = new TreeMap<NamedClass, Set<DatatypeProperty>>(); // most general applicable properties private Map<NamedClass,Set<ObjectProperty>> mgr = new TreeMap<NamedClass,Set<ObjectProperty>>(); private Map<NamedClass,Set<DatatypeProperty>> mgbd = new TreeMap<NamedClass,Set<DatatypeProperty>>(); private Map<NamedClass,Set<DatatypeProperty>> mgdd = new TreeMap<NamedClass,Set<DatatypeProperty>>(); private Map<NamedClass,Set<DatatypeProperty>> mgsd = new TreeMap<NamedClass,Set<DatatypeProperty>>(); + private Map<NamedClass,Set<DatatypeProperty>> mgid = new TreeMap<NamedClass,Set<DatatypeProperty>>(); // concept comparator private ConceptComparator conceptComparator = new ConceptComparator(); - // splits for double datatype properties in ascening order + // splits for double datatype properties in ascending order private Map<DatatypeProperty,List<Double>> splits = new TreeMap<DatatypeProperty,List<Double>>(); + private Map<DatatypeProperty,List<Integer>> splitsInt = new TreeMap<DatatypeProperty,List<Integer>>(); private int maxNrOfSplits = 10; // data structure for a simple frequent pattern matching preprocessing phase @@ -330,6 +337,11 @@ computeSplits(dp); } + // compute splits for integer datatype properties + for (DatatypeProperty dp : reasoner.getIntDatatypeProperties()) { + computeSplitsInt(dp); + } + // determine the maximum number of fillers for each role // (up to a specified cardinality maximum) if(useCardinalityRestrictions) { @@ -457,7 +469,7 @@ tmp = subHierarchy.getSuperClasses(description.getChild(0)); for(Description c : tmp) { - if(!(c instanceof Thing)) + if(!(c instanceof Thing) && !c.equals(OWL_THING)) refinements.add(new Negation(c)); } @@ -674,6 +686,31 @@ DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,min); refinements.add(newDSR); } + } if(dr instanceof IntMaxValue) { + int value = ((IntMaxValue)dr).getValue(); + // find out which split value was used + int splitIndex = splitsInt.get(dp).lastIndexOf(value); + if(splitIndex == -1) + throw new Error("split error"); + int newSplitIndex = splitIndex - 1; + if(newSplitIndex >= 0) { + IntMaxValue max = new IntMaxValue(splitsInt.get(dp).get(newSplitIndex)); + DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,max); + refinements.add(newDSR); +// System.out.println(description + " => " + newDSR); + } + } else if(dr instanceof IntMinValue) { + int value = ((IntMinValue)dr).getValue(); + // find out which split value was used + int splitIndex = splitsInt.get(dp).lastIndexOf(value); + if(splitIndex == -1) + throw new Error("split error"); + int newSplitIndex = splitIndex + 1; + if(newSplitIndex < splitsInt.get(dp).size()) { + IntMinValue min = new IntMinValue(splitsInt.get(dp).get(newSplitIndex)); + DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,min); + refinements.add(newDSR); + } } } else if (description instanceof StringValueRestriction) { StringValueRestriction svr = (StringValueRestriction) description; @@ -786,6 +823,10 @@ TreeSet<DatatypeProperty> occuredDP = new TreeSet<DatatypeProperty>(); // rule 4: no double occurences of hasValue restrictions TreeSet<ObjectProperty> occuredVR = new TreeSet<ObjectProperty>(); + // rule 5: max. restrictions at most once + boolean maxIntOccurence = false; + // rule 6: min restrictions at most once + boolean minIntOccurence = false; for(Description child : intersection.getChildren()) { if(child instanceof DatatypeSomeRestriction) { @@ -800,6 +841,16 @@ return false; else minDoubleOccurence = true; + } else if(dr instanceof IntMaxValue) { + if(maxIntOccurence) + return false; + else + maxIntOccurence = true; + } else if(dr instanceof IntMinValue) { + if(minIntOccurence) + return false; + else + minIntOccurence = true; } } else if(child instanceof BooleanValueRestriction) { DatatypeProperty dp = (DatatypeProperty) ((BooleanValueRestriction)child).getRestrictedPropertyExpression(); @@ -978,7 +1029,7 @@ if(useNegation) { Set<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing()); for(Description c : m2tmp) { - if(!(c instanceof Thing)) { + if(!(c instanceof Thing) && !c.equals(OWL_THING)) { m2.add(new Negation(c)); } } @@ -1024,6 +1075,18 @@ } } + if(useIntDatatypes) { + Set<DatatypeProperty> intDPs = reasoner.getIntDatatypeProperties(); + for(DatatypeProperty dp : intDPs) { + if(splitsInt.get(dp).size() > 0) { + IntMaxValue max = new IntMaxValue(splitsInt.get(dp).get(splitsInt.get(dp).size()-1)); + IntMinValue min = new IntMinValue(splitsInt.get(dp).get(0)); + m3.add(new DatatypeSomeRestriction(dp,max)); + m3.add(new DatatypeSomeRestriction(dp,min)); + } + } + } + if(useDataHasValueConstructor) { Set<DatatypeProperty> stringDPs = reasoner.getStringDatatypeProperties(); for(DatatypeProperty dp : stringDPs) { @@ -1161,8 +1224,21 @@ m3.add(new DatatypeSomeRestriction(dp,min)); } } - } + } + if(useIntDatatypes) { + Set<DatatypeProperty> intDPs = mgid.get(nc); + + for(DatatypeProperty dp : intDPs) { + if(splitsInt.get(dp).size() > 0) { + IntMaxValue max = new IntMaxValue(splitsInt.get(dp).get(splitsInt.get(dp).size()-1)); + IntMinValue min = new IntMinValue(splitsInt.get(dp).get(0)); + m3.add(new DatatypeSomeRestriction(dp,max)); + m3.add(new DatatypeSomeRestriction(dp,min)); + } + } + } + if(useDataHasValueConstructor) { Set<DatatypeProperty> stringDPs = mgsd.get(nc); for(DatatypeProperty dp : stringDPs) { @@ -1257,7 +1333,7 @@ // System.out.println("index " + index + " lower class " + lowerClass); for(Description candidate : subHierarchy.getSuperClasses(lowerClass)) { - if(!(candidate instanceof Thing)) { + if(!(candidate instanceof Thing) && !candidate.equals(OWL_THING)) { // System.out.println("candidate: " + candidate); // check disjointness with index/range (should not be disjoint otherwise not useful) if(!isDisjoint(new Negation(candidate),index)) { @@ -1293,6 +1369,7 @@ mgbd.put(domain, new TreeSet<DatatypeProperty>()); mgdd.put(domain, new TreeSet<DatatypeProperty>()); mgsd.put(domain, new TreeSet<DatatypeProperty>()); + mgid.put(domain, new TreeSet<DatatypeProperty>()); SortedSet<ObjectProperty> mostGeneral = reasoner.getMostGeneralProperties(); computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); @@ -1302,9 +1379,11 @@ Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, reasoner.getBooleanDatatypeProperties()); Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, reasoner.getDoubleDatatypeProperties()); Set<DatatypeProperty> mostGeneralSDP = Helper.intersection(mostGeneralDP, reasoner.getStringDatatypeProperties()); + Set<DatatypeProperty> mostGeneralIDP = Helper.intersection(mostGeneralDP, reasoner.getIntDatatypeProperties()); computeMgbdRecursive(domain, mostGeneralBDP, mgbd.get(domain)); computeMgddRecursive(domain, mostGeneralDDP, mgdd.get(domain)); computeMgsdRecursive(domain, mostGeneralSDP, mgsd.get(domain)); + computeMgidRecursive(domain, mostGeneralIDP, mgid.get(domain)); } private void computeMgrRecursive(NamedClass domain, Set<ObjectProperty> currProperties, Set<ObjectProperty> mgrTmp) { @@ -1343,6 +1422,15 @@ } } + private void computeMgidRecursive(NamedClass domain, Set<DatatypeProperty> currProperties, Set<DatatypeProperty> mgidTmp) { + for(DatatypeProperty prop : currProperties) { + if(appID.get(domain).contains(prop)) + mgidTmp.add(prop); + else + computeMgidRecursive(domain, reasoner.getSubProperties(prop), mgidTmp); + } + } + // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { // object properties @@ -1390,7 +1478,19 @@ if(!isDisjoint(domain,d)) applicableSDPs.add(role); } - appSD.put(domain, applicableSDPs); + appSD.put(domain, applicableSDPs); + + // integer datatype properties + Set<DatatypeProperty> mostGeneralIDPs = reasoner.getIntDatatypeProperties(); + Set<DatatypeProperty> applicableIDPs = new TreeSet<DatatypeProperty>(); + for(DatatypeProperty role : mostGeneralIDPs) { +// Description d = (NamedClass) rs.getDomain(role); + Description d = reasoner.getDomain(role); +// System.out.println("domain: " + d); + if(!isDisjoint(domain,d)) + applicableIDPs.add(role); + } + appID.put(domain, applicableIDPs); } // returns true of the intersection contains elements disjoint @@ -1541,6 +1641,37 @@ // System.out.println(splits); // System.exit(0); } + + private void computeSplitsInt(DatatypeProperty dp) { + Set<Integer> valuesSet = new TreeSet<Integer>(); +// Set<Individual> individuals = rs.getIndividuals(); + Map<Individual,SortedSet<Integer>> valueMap = reasoner.getIntDatatypeMembers(dp); + // add all values to the set (duplicates will be remove automatically) + for(Entry<Individual,SortedSet<Integer>> e : valueMap.entrySet()) + valuesSet.addAll(e.getValue()); + // convert set to a list where values are sorted + List<Integer> values = new LinkedList<Integer>(valuesSet); + Collections.sort(values); + + int nrOfValues = values.size(); + // create split set + List<Integer> splitsDP = new LinkedList<Integer>(); + for(int splitNr=0; splitNr < Math.min(maxNrOfSplits,nrOfValues-1); splitNr++) { + int index; + if(nrOfValues<=maxNrOfSplits) + index = splitNr; + else + index = (int) Math.floor(splitNr * (double)nrOfValues/(maxNrOfSplits+1)); + + int value = values.get(index); + splitsDP.add(value); + } + splitsInt.put(dp, splitsDP); + +// System.out.println(values); +// System.out.println(splits); +// System.exit(0); + } public int getFrequencyThreshold() { return frequencyThreshold; Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java 2014-05-22 11:04:32 UTC (rev 4270) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java 2014-05-23 12:03:39 UTC (rev 4271) @@ -24,9 +24,12 @@ import java.util.TreeMap; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.owl.DataRange; +import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.IntMaxValue; +import org.dllearner.core.owl.IntMinValue; import org.dllearner.core.owl.Intersection; -import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectAllRestriction; @@ -59,7 +62,7 @@ } /** - * Method which minimzes the input description. The algorithm does not + * Method which minimizes the input description. The algorithm does not * replace subdescriptions with named classes, e.g. * if the description "male \sqcap \exists hasChild.\top" is passed to the * algorithm and a class "father" is defined in the obvious way @@ -241,6 +244,15 @@ } private boolean isSubclassOf(Description d1, Description d2) { + if(beautify && (d1 instanceof DatatypeSomeRestriction) && (d2 instanceof DatatypeSomeRestriction)){ + DataRange dr1 = ((DatatypeSomeRestriction)d1).getDataRange(); + DataRange dr2 = ((DatatypeSomeRestriction)d2).getDataRange(); + if(dr1 instanceof IntMinValue && dr2 instanceof IntMinValue){ + return ((IntMinValue)dr1).getValue() >= ((IntMinValue)dr2).getValue(); + } else if(dr1 instanceof IntMaxValue && dr2 instanceof IntMaxValue){ + return ((IntMaxValue)dr1).getValue() <= ((IntMaxValue)dr2).getValue(); + } + } if(!(d1.isNamedClass() && d2.isNamedClass())) return false; // check whether we have cached this query Map<Description,Boolean> tmp = cachedSubclassOf.get(d1); @@ -249,7 +261,8 @@ tmp2 = tmp.get(d2); if(tmp2==null) { - Boolean result = reasoner.isSuperClassOf(d2, d1); + + Boolean result = reasoner.isSuperClassOf(d2, d1); // create new entry if necessary Map<Description,Boolean> map1 = new TreeMap<Description,Boolean>(conceptComparator); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-05-27 12:58:43
|
Revision: 4274 http://sourceforge.net/p/dl-learner/code/4274 Author: lorenz_b Date: 2014-05-27 12:58:39 +0000 (Tue, 27 May 2014) Log Message: ----------- Added equals for complex descriptions. Modified Paths: -------------- 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/rendering/Edge.java trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectValueRestriction.java trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java 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 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -1581,7 +1581,7 @@ for (QueryTree<N> child : children) { Vertex childVertex = new Vertex(child.getId(), prefixed(prefixes, child.getUserObject().toString())); graph.addVertex(childVertex); - Edge edge = new Edge(Integer.valueOf(parent.getId() + "000" + childVertex.getId()), prefixed(prefixes, tree.getEdge(child).toString())); + Edge edge = new Edge(Long.valueOf(parent.getId() + "0" + childVertex.getId()), prefixed(prefixes, tree.getEdge(child).toString())); graph.addEdge(parent, childVertex, edge); buildGraph(graph, child); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/rendering/Edge.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/rendering/Edge.java 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/rendering/Edge.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -1,10 +1,10 @@ package org.dllearner.algorithms.qtl.datastructures.rendering; public class Edge { - int id; + long id; String label; - public Edge(int id, String label) { + public Edge(long id, String label) { this.id = id; this.label = label; } @@ -12,7 +12,7 @@ /** * @return the id */ - public int getId() { + public long getId() { return id; } @@ -27,7 +27,7 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + id; + result = prime * result + (int) (id ^ (id >>> 32)); return result; } @@ -44,4 +44,6 @@ return false; return true; } + + } \ No newline at end of file Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -111,6 +111,8 @@ return true; if (obj == null) return false; + if(obj==Thing.instance && name.equals(Thing.uri.toString())) + return true; if (getClass() != obj.getClass()) return false; NamedClass other = (NamedClass) obj; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -33,9 +33,6 @@ */ public class ObjectProperty extends ObjectPropertyExpression implements Property, Comparable<ObjectProperty>{ - /** - * - */ private static final long serialVersionUID = -3343070247923446690L; public ObjectProperty(String name) { Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -61,5 +61,37 @@ public void accept(KBElementVisitor visitor) { visitor.visit(this); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getChild(0) == null) ? 0 : getChild(0).hashCode()); + result = prime * result + ((getRole() == null) ? 0 : getRole().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ObjectSomeRestriction other = (ObjectSomeRestriction) obj; + if (getChild(0) == null) { + if (other.getChild(0) != null) + return false; + } else if (!getChild(0).equals(other.getChild(0))) + return false; + if (getRole() == null) { + if (other.getRole() != null) + return false; + } else if (!getRole().equals(other.getRole())) + return false; + return true; } + } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectValueRestriction.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectValueRestriction.java 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectValueRestriction.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -30,9 +30,6 @@ */ public class ObjectValueRestriction extends ValueRestriction { - /** - * - */ private static final long serialVersionUID = 2437223709767096950L; /** @@ -87,5 +84,36 @@ public void accept(KBElementVisitor visitor) { visitor.visit(this); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getRestrictedPropertyExpression() == null) ? 0 : getRestrictedPropertyExpression().hashCode()); + result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ObjectValueRestriction other = (ObjectValueRestriction) obj; + if (getRestrictedPropertyExpression() == null) { + if (other.getRestrictedPropertyExpression() != null) + return false; + } else if (!getRestrictedPropertyExpression().equals(other.getRestrictedPropertyExpression())) + return false; + if (getValue() == null) { + if (other.getValue() != null) + return false; + } else if (!getValue().equals(other.getValue())) + return false; + return true; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java 2014-05-27 12:57:42 UTC (rev 4273) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Thing.java 2014-05-27 12:58:39 UTC (rev 4274) @@ -37,9 +37,6 @@ */ public class Thing extends Description { - /** - * - */ private static final long serialVersionUID = -880276915058868775L; public static final Thing instance = new Thing(); @@ -87,5 +84,25 @@ visitor.visit(this); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if(obj.getClass() == getClass()){ + return true; + } + if (obj.getClass() == NamedClass.class && ((NamedClass)obj).getName().equals(uri.toString())) + return true; + return false; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2014-06-24 09:35:48
|
Revision: 4277 http://sourceforge.net/p/dl-learner/code/4277 Author: kirdie Date: 2014-06-24 09:35:44 +0000 (Tue, 24 Jun 2014) Log Message: ----------- dl-learner works again by removing plugin version. clearer exception message in one case. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2014-06-23 12:57:22 UTC (rev 4276) +++ trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2014-06-24 09:35:44 UTC (rev 4277) @@ -154,6 +154,11 @@ public void setSupportsSPARQL_1_1(boolean supportsSPARQL_1_1) { this.supportsSPARQL_1_1 = supportsSPARQL_1_1; + } + + @Override public String toString() + { + return endpoint.toString(); } } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-06-23 12:57:22 UTC (rev 4276) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2014-06-24 09:35:44 UTC (rev 4277) @@ -33,7 +33,6 @@ import java.util.TreeMap; import java.util.TreeSet; 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; @@ -75,7 +74,6 @@ import org.dllearner.utilities.owl.OWLClassExpressionToSPARQLConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import com.clarkparsia.owlapiv3.XSD; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -89,6 +87,7 @@ 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.sparql.engine.http.QueryExceptionHTTP; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.OWL2; import com.hp.hpl.jena.vocabulary.RDF; @@ -1758,8 +1757,15 @@ private ResultSet executeSelectQuery(String query){ logger.trace("Sending query \n {}", query); QueryExecution qe = qef.createQueryExecution(query); + try + { ResultSet rs = qe.execSelect(); return rs; + } + catch(QueryExceptionHTTP e) + { + throw new QueryExceptionHTTP("Error sending query \""+query+"\" to endpoint "+ks,e); + } } private ResultSet executeSelectQuery(String query, long timeout){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |