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. |