|
From: <lor...@us...> - 2014-07-29 13:55:41
|
Revision: 4281
http://sourceforge.net/p/dl-learner/code/4281
Author: lorenz_b
Date: 2014-07-29 13:55:31 +0000 (Tue, 29 Jul 2014)
Log Message:
-----------
Added punning test.
Added Paths:
-----------
trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/ClassExpressionLiteralCombination.java
trunk/components-core/src/main/java/org/dllearner/reasoning/Materialization.java
trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java
trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java
trunk/components-core/src/test/java/org/dllearner/test/junit/PunningTest.java
trunk/components-core/src/test/resources/log4j.properties
trunk/components-core/src/test/resources/punning_example.ttl
Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/ClassExpressionLiteralCombination.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/ClassExpressionLiteralCombination.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/ClassExpressionLiteralCombination.java 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,336 @@
+/**
+ *
+ */
+package org.dllearner.algorithms.qtl.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.dllearner.algorithms.pattern.ManchesterOWLSyntaxOWLObjectRendererImpl;
+import org.semanticweb.owlapi.io.ToStringRenderer;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLClassExpression;
+import org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx;
+import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
+import org.semanticweb.owlapi.model.OWLDataComplementOf;
+import org.semanticweb.owlapi.model.OWLDataExactCardinality;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLDataHasValue;
+import org.semanticweb.owlapi.model.OWLDataIntersectionOf;
+import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
+import org.semanticweb.owlapi.model.OWLDataMinCardinality;
+import org.semanticweb.owlapi.model.OWLDataOneOf;
+import org.semanticweb.owlapi.model.OWLDataProperty;
+import org.semanticweb.owlapi.model.OWLDataRange;
+import org.semanticweb.owlapi.model.OWLDataRangeVisitorEx;
+import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
+import org.semanticweb.owlapi.model.OWLDataUnionOf;
+import org.semanticweb.owlapi.model.OWLDatatype;
+import org.semanticweb.owlapi.model.OWLDatatypeRestriction;
+import org.semanticweb.owlapi.model.OWLFacetRestriction;
+import org.semanticweb.owlapi.model.OWLLiteral;
+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.OWLObjectMaxCardinality;
+import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
+import org.semanticweb.owlapi.model.OWLObjectOneOf;
+import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
+import org.semanticweb.owlapi.model.OWLObjectUnionOf;
+import org.semanticweb.owlapi.model.PrefixManager;
+import org.semanticweb.owlapi.util.DefaultPrefixManager;
+import org.semanticweb.owlapi.vocab.OWLFacet;
+
+import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl;
+
+/**
+ * @author Lorenz Buehmann
+ *
+ */
+public class ClassExpressionLiteralCombination implements OWLClassExpressionVisitorEx<Set<OWLClassExpression>>, OWLDataRangeVisitorEx<Set<OWLDataRange>>{
+
+ private OWLDataFactory df = new OWLDataFactoryImpl();
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLClass)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLClass ce) {
+ Set<OWLClassExpression> expressions = new HashSet<OWLClassExpression>(1);
+ expressions.add(ce);
+ return expressions;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectIntersectionOf)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectIntersectionOf ce) {
+ Set<OWLClassExpression> expressions = new HashSet<OWLClassExpression>();
+ Set<Set<OWLClassExpression>> combinations = new HashSet<Set<OWLClassExpression>>();
+ for (int i = 0; i < ce.getOperands().size(); i++) {
+ Set<OWLClassExpression> tmp = new HashSet<OWLClassExpression>();
+ combinations.add(tmp);
+ }
+ for (OWLClassExpression operand : ce.getOperands()) {
+ Set<Set<OWLClassExpression>> combinationsTmp = new HashSet<Set<OWLClassExpression>>();
+ Set<OWLClassExpression> newOperands = operand.accept(this);
+ for (Set<OWLClassExpression> set : combinations) {
+ for (OWLClassExpression newOp : newOperands) {
+ Set<OWLClassExpression> tmp = new HashSet<OWLClassExpression>();
+ tmp.addAll(set);
+ tmp.add(newOp);
+ combinationsTmp.add(tmp);
+ }
+ }
+ combinations = combinationsTmp;
+ }
+ for (Set<OWLClassExpression> combination : combinations) {
+ expressions.add(df.getOWLObjectIntersectionOf(combination));
+ }
+ return expressions;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectUnionOf)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectUnionOf ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectComplementOf)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectComplementOf ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectSomeValuesFrom ce) {
+ Set<OWLClassExpression> expressions = new HashSet<OWLClassExpression>();
+ Set<OWLClassExpression> newFillers = ce.getFiller().accept(this);
+ for (OWLClassExpression newFiller : newFillers) {
+ expressions.add(df.getOWLObjectSomeValuesFrom(ce.getProperty(), newFiller));
+ }
+ return expressions;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectAllValuesFrom)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectAllValuesFrom ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectHasValue)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectHasValue ce) {
+ Set<OWLClassExpression> expressions = new HashSet<OWLClassExpression>();
+ expressions.add(ce);
+ return expressions;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectMinCardinality)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectMinCardinality ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectExactCardinality)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectExactCardinality ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectMaxCardinality)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectMaxCardinality ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectHasSelf)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectHasSelf ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLObjectOneOf)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLObjectOneOf ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataSomeValuesFrom)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLDataSomeValuesFrom ce) {
+ Set<OWLClassExpression> expressions = new HashSet<OWLClassExpression>();
+ Set<OWLDataRange> newDataRanges = ce.getFiller().accept(this);
+ for (OWLDataRange newDataRange : newDataRanges) {
+ expressions.add(df.getOWLDataSomeValuesFrom(ce.getProperty(), newDataRange));
+ }
+ return expressions;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataAllValuesFrom)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLDataAllValuesFrom ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataHasValue)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLDataHasValue ce) {
+ Set<OWLClassExpression> expressions = new HashSet<OWLClassExpression>();
+ expressions.add(ce);
+ return expressions;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataMinCardinality)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLDataMinCardinality ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataExactCardinality)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLDataExactCardinality ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataMaxCardinality)
+ */
+ @Override
+ public Set<OWLClassExpression> visit(OWLDataMaxCardinality ce) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitorEx#visit(org.semanticweb.owlapi.model.OWLDatatype)
+ */
+ @Override
+ public Set<OWLDataRange> visit(OWLDatatype dr) {
+ Set<OWLDataRange> dataRanges = new HashSet<OWLDataRange>();
+ dataRanges.add(dr);
+ return dataRanges;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataOneOf)
+ */
+ @Override
+ public Set<OWLDataRange> visit(OWLDataOneOf dr) {
+ Set<OWLDataRange> dataRanges = new HashSet<OWLDataRange>();
+ dataRanges.add(dr);
+ return dataRanges;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataComplementOf)
+ */
+ @Override
+ public Set<OWLDataRange> visit(OWLDataComplementOf dr) {
+ Set<OWLDataRange> dataRanges = new HashSet<OWLDataRange>();
+ dataRanges.add(dr);
+ return dataRanges;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataIntersectionOf)
+ */
+ @Override
+ public Set<OWLDataRange> visit(OWLDataIntersectionOf dr) {
+ Set<OWLDataRange> dataRanges = new HashSet<OWLDataRange>();
+ dataRanges.add(dr);
+ return dataRanges;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitorEx#visit(org.semanticweb.owlapi.model.OWLDataUnionOf)
+ */
+ @Override
+ public Set<OWLDataRange> visit(OWLDataUnionOf dr) {
+ Set<OWLDataRange> dataRanges = new HashSet<OWLDataRange>();
+ dataRanges.add(dr);
+ return dataRanges;
+ }
+
+ /* (non-Javadoc)
+ * @see org.semanticweb.owlapi.model.OWLDataRangeVisitorEx#visit(org.semanticweb.owlapi.model.OWLDatatypeRestriction)
+ */
+ @Override
+ public Set<OWLDataRange> visit(OWLDatatypeRestriction dr) {
+ Set<OWLDataRange> dataRanges = new HashSet<OWLDataRange>();
+ Set<OWLFacetRestriction> facetRestrictions = dr.getFacetRestrictions();
+ OWLLiteral min = null;
+ OWLLiteral max = null;
+ for (OWLFacetRestriction facetRestriction : facetRestrictions) {
+ OWLFacet facet = facetRestriction.getFacet();
+ if(facet == OWLFacet.MIN_INCLUSIVE){
+ min = facetRestriction.getFacetValue();
+ } else if(facet == OWLFacet.MAX_INCLUSIVE){
+ max = facetRestriction.getFacetValue();
+ } else {
+ throw new IllegalArgumentException("Facet not allowed for transformation.");
+ }
+ }
+// dataRanges.add(dr);
+ dataRanges.add(df.getOWLDatatypeRestriction(dr.getDatatype(), df.getOWLFacetRestriction(OWLFacet.MIN_INCLUSIVE, min)));
+ dataRanges.add(df.getOWLDatatypeRestriction(dr.getDatatype(), df.getOWLFacetRestriction(OWLFacet.MAX_INCLUSIVE, max)));
+// dataRanges.add(dr.getDatatype());
+ return dataRanges;
+ }
+
+
+ public static void main(String[] args) throws Exception {
+ ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl());
+ OWLDataFactoryImpl df = new OWLDataFactoryImpl();
+ PrefixManager pm = new DefaultPrefixManager(":");
+ OWLClass A = df.getOWLClass("A", pm );
+ OWLDataProperty s = df.getOWLDataProperty("s", pm);
+ OWLDataProperty t = df.getOWLDataProperty("t", pm);
+ OWLDatatypeRestriction dr1 = df.getOWLDatatypeMinMaxInclusiveRestriction(1.0, 2.0);
+ OWLDatatypeRestriction dr2 = df.getOWLDatatypeMinMaxInclusiveRestriction(15, 100);
+ OWLClassExpression ce = df.getOWLObjectIntersectionOf(A,
+ df.getOWLDataSomeValuesFrom(s, dr1),
+ df.getOWLDataSomeValuesFrom(t, dr2)
+ );
+ Set<OWLClassExpression> expressions = ce.accept(new ClassExpressionLiteralCombination());
+ for (OWLClassExpression expr : expressions) {
+ System.out.println(expr);
+ }
+ }
+
+
+}
Added: trunk/components-core/src/main/java/org/dllearner/reasoning/Materialization.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/reasoning/Materialization.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/reasoning/Materialization.java 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,37 @@
+package org.dllearner.reasoning;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.dllearner.core.owl.Constant;
+import org.dllearner.core.owl.DatatypeProperty;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
+
+class Materialization implements Serializable{
+ // we use sorted sets (map indices) here, because they have only log(n)
+ // complexity for checking whether an element is contained in them
+ // instances of classes
+ public Map<NamedClass, TreeSet<Individual>> classInstancesPos = new TreeMap<NamedClass, TreeSet<Individual>>();
+ public Map<NamedClass, TreeSet<Individual>> classInstancesNeg = new TreeMap<NamedClass, TreeSet<Individual>>();
+ // object property mappings
+ public Map<ObjectProperty, Map<Individual, SortedSet<Individual>>> opPos = new TreeMap<ObjectProperty, Map<Individual, SortedSet<Individual>>>();
+ // data property mappings
+ public Map<DatatypeProperty, Map<Individual, SortedSet<Constant>>> dpPos = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<Constant>>>();
+
+
+ // datatype property mappings
+ // for boolean data properties we have one mapping for true and false for efficiency reasons
+ public Map<DatatypeProperty, TreeSet<Individual>> bdPos = new TreeMap<DatatypeProperty, TreeSet<Individual>>();
+ public Map<DatatypeProperty, TreeSet<Individual>> bdNeg = new TreeMap<DatatypeProperty, TreeSet<Individual>>();
+ //double datatype property mappings
+ public Map<DatatypeProperty, Map<Individual, SortedSet<Double>>> dd = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<Double>>>();
+ //int datatype property
+ public Map<DatatypeProperty, Map<Individual, SortedSet<Integer>>> id = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<Integer>>>();
+ //string datatype property
+ public Map<DatatypeProperty, Map<Individual, SortedSet<String>>> sd = new TreeMap<DatatypeProperty, Map<Individual, SortedSet<String>>>();
+ }
\ No newline at end of file
Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java (rev 0)
+++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,903 @@
+package org.dllearner.utilities.owl;
+
+/*
+ * This file is part of the OWL API.
+ *
+ * The contents of this file are subject to the LGPL License, Version 3.0.
+ *
+ * Copyright (C) 2011, The University of Manchester
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ *
+ *
+ * Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0
+ * in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
+ *
+ * Copyright 2011, The University of Manchester
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import static org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntax.FACET_RESTRICTION_SEPARATOR;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.AND;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.BOTTOM;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.COMMA;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.COMP;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.DISJOINT_WITH;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.EQUAL;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.EQUIVALENT_TO;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.EXISTS;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.FORALL;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.IMPLIES;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.IN;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.INVERSE;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.MAX;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.MIN;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.NOT;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.NOT_EQUAL;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.OR;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.SELF;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.SUBCLASS;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.TOP;
+import static uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax.WEDGE;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeSet;
+
+import org.semanticweb.owlapi.io.OWLObjectRenderer;
+import org.semanticweb.owlapi.model.*;
+import org.semanticweb.owlapi.util.IRIShortFormProvider;
+import org.semanticweb.owlapi.util.ShortFormProvider;
+import org.semanticweb.owlapi.util.SimpleIRIShortFormProvider;
+import org.semanticweb.owlapi.util.SimpleShortFormProvider;
+
+import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntax;
+
+/**
+ * Extended version of the DLSyntaxObjectRenderer class in OWL API. Extension is
+ * done for data range facets, e.g. double[<=1.5].
+ *
+ * Renders objects in unicode DL syntax.
+ *
+ * @author Matthew Horridge, The University Of Manchester, Bio-Health
+ * Informatics Group, Date: 10-Feb-2008
+ */
+public class DLSyntaxObjectRenderer implements OWLObjectRenderer, OWLObjectVisitor {
+
+ private ShortFormProvider shortFormProvider;
+ private IRIShortFormProvider iriShortFormProvider;
+ private StringBuilder buffer;
+ private OWLObject focusedObject;
+
+ /** default constructor */
+ public DLSyntaxObjectRenderer() {
+ shortFormProvider = new SimpleShortFormProvider();
+ iriShortFormProvider = new SimpleIRIShortFormProvider();
+ buffer = new StringBuilder();
+ }
+
+ /**
+ * @param focusedObject
+ * focusedObject
+ */
+ public void setFocusedObject(OWLObject focusedObject) {
+ this.focusedObject = focusedObject;
+ }
+
+ /**
+ * @param obj
+ * obj
+ * @return true if focused
+ */
+ public boolean isFocusedObject(OWLObject obj) {
+ if (focusedObject == null) {
+ return false;
+ }
+ return focusedObject.equals(obj);
+ }
+
+ @Override
+ public void setShortFormProvider(ShortFormProvider shortFormProvider) {
+ this.shortFormProvider = shortFormProvider;
+ }
+
+ @Override
+ public String render(OWLObject object) {
+ buffer = new StringBuilder();
+ object.accept(this);
+ return buffer.toString();
+ }
+
+ @Override
+ public void visit(OWLOntology ontology) {
+ for (OWLAxiom ax : new TreeSet<OWLAxiom>(ontology.getLogicalAxioms())) {
+ ax.accept(this);
+ write("\n");
+ }
+ }
+
+ protected void write(String s) {
+ buffer.append(s);
+ }
+
+ protected String renderEntity(OWLEntity entity) {
+ return shortFormProvider.getShortForm(entity);
+ }
+
+ protected void writeEntity(OWLEntity entity) {
+ write(renderEntity(entity));
+ }
+
+ protected void write(DLSyntax keyword) {
+ write(keyword.toString());
+ }
+
+ protected void write(int i) {
+ write(Integer.toString(i));
+ }
+
+ protected void writeNested(OWLObject object) {
+ if (isBracketedIfNested(object)) {
+ write("(");
+ }
+ object.accept(this);
+ if (isBracketedIfNested(object)) {
+ write(")");
+ }
+ }
+
+ protected boolean isBracketedIfNested(OWLObject object) {
+ // if(object instanceof OWLObjectComplementOf) {
+ // if(!((OWLObjectComplementOf) object).getOperand().isAnonymous()) {
+ // return false;
+ // }
+ // }
+ // return object instanceof OWLClassExpression && !((OWLClassExpression)
+ // object).isClassExpressionLiteral();
+ return !(object instanceof OWLEntity);
+ }
+
+ private void writeObject(OWLObject object, boolean nest) {
+ if (nest) {
+ writeNested(object);
+ } else {
+ object.accept(this);
+ }
+ }
+
+ protected void write(Collection<? extends OWLObject> objects, DLSyntax delim, boolean nest) {
+ if (objects.size() == 2) {
+ Iterator<? extends OWLObject> it = objects.iterator();
+ OWLObject o1 = it.next();
+ OWLObject o2 = it.next();
+ if (isFocusedObject(o1) || !isFocusedObject(o2)) {
+ writeObject(o1, nest);
+ writeSpace();
+ write(delim);
+ writeSpace();
+ writeObject(o2, nest);
+ } else {
+ writeObject(o2, nest);
+ writeSpace();
+ write(delim);
+ writeSpace();
+ writeObject(o1, nest);
+ }
+ } else {
+ for (Iterator<? extends OWLObject> it = objects.iterator(); it.hasNext();) {
+ OWLObject o = it.next();
+ writeObject(o, nest);
+ if (it.hasNext()) {
+ writeSpace();
+ write(delim);
+ writeSpace();
+ }
+ }
+ }
+ }
+
+ // protected void write(Collection<? extends OWLObject> objects, DLSyntax
+ // keyword, boolean nest) {
+ // write(objects, keyword, nest);
+ // }
+ @Override
+ public void visit(OWLSubClassOfAxiom axiom) {
+ axiom.getSubClass().accept(this);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ axiom.getSuperClass().accept(this);
+ }
+
+ private void writePropertyAssertion(OWLPropertyAssertionAxiom<?, ?> ax) {
+ if (ax instanceof OWLNegativeObjectPropertyAssertionAxiom
+ || ax instanceof OWLNegativeDataPropertyAssertionAxiom) {
+ write(NOT);
+ }
+ ax.getProperty().accept(this);
+ write("(");
+ ax.getSubject().accept(this);
+ write(", ");
+ ax.getObject().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(OWLNegativeObjectPropertyAssertionAxiom axiom) {
+ write(NOT);
+ writePropertyAssertion(axiom);
+ }
+
+ @Override
+ public void visit(OWLAsymmetricObjectPropertyAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLReflexiveObjectPropertyAxiom axiom) {
+ write(TOP);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ write(EXISTS);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ write(" .");
+ write(SELF);
+ }
+
+ @Override
+ public void visit(OWLDisjointClassesAxiom axiom) {
+ List<OWLClassExpression> descs = new ArrayList<OWLClassExpression>(axiom.getClassExpressions());
+ for (int i = 0; i < descs.size(); i++) {
+ for (int j = i + 1; j < descs.size(); j++) {
+ descs.get(i).accept(this);
+ writeSpace();
+ write(DISJOINT_WITH);
+ writeSpace();
+ descs.get(j).accept(this);
+ if (j < descs.size() - 1) {
+ write(", ");
+ }
+ }
+ }
+ // write(axiom.getClassExpressions(), DISJOINT_WITH, true);
+ }
+
+ private void writeDomainAxiom(OWLPropertyDomainAxiom<?> axiom) {
+ write(EXISTS);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ writeRestrictionSeparator();
+ write(TOP);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ writeNested(axiom.getDomain());
+ }
+
+ private void writeRestrictionSeparator() {
+ write(".");
+ }
+
+ @Override
+ public void visit(OWLDataPropertyDomainAxiom axiom) {
+ writeDomainAxiom(axiom);
+ }
+
+ @Override
+ public void visit(OWLObjectPropertyDomainAxiom axiom) {
+ writeDomainAxiom(axiom);
+ }
+
+ @Override
+ public void visit(OWLEquivalentObjectPropertiesAxiom axiom) {
+ write(axiom.getProperties(), EQUIVALENT_TO, false);
+ }
+
+ @Override
+ public void visit(OWLNegativeDataPropertyAssertionAxiom axiom) {
+ write(NOT);
+ writePropertyAssertion(axiom);
+ }
+
+ @Override
+ public void visit(OWLDifferentIndividualsAxiom axiom) {
+ write(axiom.getIndividuals(), NOT_EQUAL, false);
+ }
+
+ @Override
+ public void visit(OWLDisjointDataPropertiesAxiom axiom) {
+ write(axiom.getProperties(), DISJOINT_WITH, false);
+ }
+
+ @Override
+ public void visit(OWLDisjointObjectPropertiesAxiom axiom) {
+ write(axiom.getProperties(), DISJOINT_WITH, false);
+ }
+
+ private void writeRangeAxiom(OWLPropertyRangeAxiom<?, ?> axiom) {
+ write(TOP);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ write(FORALL);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ writeRestrictionSeparator();
+ writeNested(axiom.getRange());
+ }
+
+ @Override
+ public void visit(OWLObjectPropertyRangeAxiom axiom) {
+ writeRangeAxiom(axiom);
+ }
+
+ @Override
+ public void visit(OWLObjectPropertyAssertionAxiom axiom) {
+ writePropertyAssertion(axiom);
+ }
+
+ private void writeFunctionalProperty(OWLPropertyExpression<?, ?> property) {
+ write(TOP);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ write(MAX);
+ writeSpace();
+ write(1);
+ writeSpace();
+ property.accept(this);
+ }
+
+ @Override
+ public void visit(OWLFunctionalObjectPropertyAxiom axiom) {
+ writeFunctionalProperty(axiom.getProperty());
+ }
+
+ @Override
+ public void visit(OWLSubObjectPropertyOfAxiom axiom) {
+ axiom.getSubProperty().accept(this);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ axiom.getSuperProperty().accept(this);
+ }
+
+ @Override
+ public void visit(OWLDisjointUnionAxiom axiom) {
+ axiom.getOWLClass().accept(this);
+ write(EQUAL);
+ write(axiom.getClassExpressions(), OR, false);
+ }
+
+ @Override
+ public void visit(OWLDeclarationAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLAnnotationAssertionAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLSymmetricObjectPropertyAxiom axiom) {
+ axiom.getProperty().accept(this);
+ writeSpace();
+ write(EQUIVALENT_TO);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ write(INVERSE);
+ }
+
+ private void writeSpace() {
+ write(" ");
+ }
+
+ @Override
+ public void visit(OWLDataPropertyRangeAxiom axiom) {
+ writeRangeAxiom(axiom);
+ }
+
+ @Override
+ public void visit(OWLFunctionalDataPropertyAxiom axiom) {
+ writeFunctionalProperty(axiom.getProperty());
+ }
+
+ @Override
+ public void visit(OWLEquivalentDataPropertiesAxiom axiom) {
+ write(axiom.getProperties(), EQUIVALENT_TO, false);
+ }
+
+ @Override
+ public void visit(OWLClassAssertionAxiom axiom) {
+ if (axiom.getClassExpression().isAnonymous()) {
+ write("(");
+ }
+ axiom.getClassExpression().accept(this);
+ if (axiom.getClassExpression().isAnonymous()) {
+ write(")");
+ }
+ write("(");
+ axiom.getIndividual().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(OWLEquivalentClassesAxiom axiom) {
+ write(axiom.getClassExpressions(), EQUIVALENT_TO, false);
+ }
+
+ @Override
+ public void visit(OWLDataPropertyAssertionAxiom axiom) {
+ writePropertyAssertion(axiom);
+ }
+
+ @Override
+ public void visit(OWLTransitiveObjectPropertyAxiom axiom) {
+ axiom.getProperty().accept(this);
+ writeSpace();
+ write(IN);
+ writeSpace();
+ write("R");
+ write("\u207A");
+ }
+
+ @Override
+ public void visit(OWLIrreflexiveObjectPropertyAxiom axiom) {
+ write(TOP);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ write(NOT);
+ write(EXISTS);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ write(" .");
+ write(SELF);
+ }
+
+ @Override
+ public void visit(OWLSubDataPropertyOfAxiom axiom) {
+ axiom.getSubProperty().accept(this);
+ write(SUBCLASS);
+ axiom.getSuperProperty().accept(this);
+ }
+
+ @Override
+ public void visit(OWLInverseFunctionalObjectPropertyAxiom axiom) {
+ write(TOP);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ write(MAX);
+ writeSpace();
+ write(1);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ write(INVERSE);
+ }
+
+ @Override
+ public void visit(OWLSameIndividualAxiom axiom) {
+ write(axiom.getIndividuals(), EQUAL, false);
+ }
+
+ @Override
+ public void visit(OWLSubPropertyChainOfAxiom axiom) {
+ write(axiom.getPropertyChain(), COMP, false);
+ writeSpace();
+ write(SUBCLASS);
+ writeSpace();
+ axiom.getSuperProperty().accept(this);
+ }
+
+ @Override
+ public void visit(OWLInverseObjectPropertiesAxiom axiom) {
+ OWLObject o1 = axiom.getFirstProperty();
+ OWLObject o2 = axiom.getSecondProperty();
+ OWLObject first, second;
+ if (isFocusedObject(o1) || !isFocusedObject(o2)) {
+ first = o1;
+ second = o2;
+ } else {
+ first = o2;
+ second = o1;
+ }
+ first.accept(this);
+ writeSpace();
+ write(EQUIVALENT_TO);
+ writeSpace();
+ second.accept(this);
+ write(INVERSE);
+ }
+
+ @Override
+ public void visit(SWRLRule rule) {
+ write(rule.getHead(), WEDGE, false);
+ writeSpace();
+ write(IMPLIES);
+ writeSpace();
+ write(rule.getBody(), WEDGE, false);
+ }
+
+ @Override
+ public void visit(OWLClass desc) {
+ if (desc.isOWLThing()) {
+ write(TOP);
+ } else if (desc.isOWLNothing()) {
+ write(BOTTOM);
+ } else {
+ writeEntity(desc);
+ }
+ }
+
+ @Override
+ public void visit(OWLObjectIntersectionOf desc) {
+ write(desc.getOperands(), AND, true);
+ }
+
+ @Override
+ public void visit(OWLObjectUnionOf desc) {
+ write(desc.getOperands(), OR, true);
+ }
+
+ @Override
+ public void visit(OWLObjectComplementOf desc) {
+ write(NOT);
+ writeNested(desc.getOperand());
+ }
+
+ private void writeCardinalityRestriction(OWLDataCardinalityRestriction restriction, DLSyntax keyword) {
+ write(keyword);
+ writeSpace();
+ write(restriction.getCardinality());
+ writeSpace();
+ restriction.getProperty().accept(this);
+ // if (restriction.isQualified()) {
+ writeRestrictionSeparator();
+ writeNested(restriction.getFiller());
+ // }
+ }
+
+ private void writeCardinalityRestriction(OWLObjectCardinalityRestriction restriction, DLSyntax keyword) {
+ write(keyword);
+ writeSpace();
+ write(restriction.getCardinality());
+ writeSpace();
+ restriction.getProperty().accept(this);
+ // if (restriction.isQualified()) {
+ writeRestrictionSeparator();
+ writeNested(restriction.getFiller());
+ // }
+ }
+
+ private void writeQuantifiedRestriction(OWLQuantifiedDataRestriction restriction, DLSyntax keyword) {
+ write(keyword);
+ writeSpace();
+ restriction.getProperty().accept(this);
+ writeRestrictionSeparator();
+ writeNested(restriction.getFiller());
+ }
+
+ private void writeQuantifiedRestriction(OWLQuantifiedObjectRestriction restriction, DLSyntax keyword) {
+ write(keyword);
+ writeSpace();
+ restriction.getProperty().accept(this);
+ writeRestrictionSeparator();
+ writeNested(restriction.getFiller());
+ }
+
+ @Override
+ public void visit(OWLObjectSomeValuesFrom desc) {
+ writeQuantifiedRestriction(desc, EXISTS);
+ }
+
+ @Override
+ public void visit(OWLObjectAllValuesFrom desc) {
+ writeQuantifiedRestriction(desc, FORALL);
+ }
+
+ private <R extends OWLPropertyRange, P extends OWLPropertyExpression<R, P>, V extends OWLObject> void writeValueRestriction(
+ OWLHasValueRestriction<R, P, V> restriction) {
+ write(EXISTS);
+ writeSpace();
+ restriction.getProperty().accept(this);
+ writeRestrictionSeparator();
+ write("{");
+ restriction.getValue().accept(this);
+ write("}");
+ }
+
+ @Override
+ public void visit(OWLObjectHasValue desc) {
+ writeValueRestriction(desc);
+ }
+
+ @Override
+ public void visit(OWLObjectMinCardinality desc) {
+ writeCardinalityRestriction(desc, MIN);
+ }
+
+ @Override
+ public void visit(OWLObjectExactCardinality desc) {
+ writeCardinalityRestriction(desc, EQUAL);
+ }
+
+ @Override
+ public void visit(OWLObjectMaxCardinality desc) {
+ writeCardinalityRestriction(desc, MAX);
+ }
+
+ @Override
+ public void visit(OWLObjectHasSelf desc) {
+ write(EXISTS);
+ writeSpace();
+ desc.getProperty().accept(this);
+ write(" .");
+ write(SELF);
+ }
+
+ @Override
+ public void visit(OWLObjectOneOf desc) {
+ for (Iterator<OWLIndividual> it = desc.getIndividuals().iterator(); it.hasNext();) {
+ write("{");
+ it.next().accept(this);
+ write("}");
+ if (it.hasNext()) {
+ write(" ");
+ write(OR);
+ write(" ");
+ }
+ }
+ }
+
+ @Override
+ public void visit(OWLDataSomeValuesFrom desc) {
+ writeQuantifiedRestriction(desc, EXISTS);
+ }
+
+ @Override
+ public void visit(OWLDataAllValuesFrom desc) {
+ writeQuantifiedRestriction(desc, FORALL);
+ }
+
+ @Override
+ public void visit(OWLDataHasValue desc) {
+ writeValueRestriction(desc);
+ }
+
+ @Override
+ public void visit(OWLDataMinCardinality desc) {
+ writeCardinalityRestriction(desc, MIN);
+ }
+
+ @Override
+ public void visit(OWLDataExactCardinality desc) {
+ writeCardinalityRestriction(desc, EQUAL);
+ }
+
+ @Override
+ public void visit(OWLDataMaxCardinality desc) {
+ writeCardinalityRestriction(desc, MAX);
+ }
+
+ // /////////////////////////////////////////////////////////////////////////////////////////////
+ //
+ // Data stuff
+ //
+ // /////////////////////////////////////////////////////////////////////////////////////////////
+
+ public void visit(OWLDataIntersectionOf node) {
+ write("(");
+ write(node.getOperands(), AND, false);
+ write(")");
+ }
+
+ public void visit(OWLDataUnionOf node) {
+ write("(");
+ write(node.getOperands(), OR, false);
+ write(")");
+ }
+
+ public void visit(OWLDatatypeRestriction node) {
+ node.getDatatype().accept(this);
+ write("[");
+ for (OWLFacetRestriction facetRestriction : node.getFacetRestrictions()) {
+ facetRestriction.accept(this);
+ write(" " + FACET_RESTRICTION_SEPARATOR.toString() + " ");
+ }
+ write("]");
+ }
+
+ public void visit(OWLFacetRestriction node) {
+ write(node.getFacet().getSymbolicForm());
+ writeSpace();
+ node.getFacetValue().accept(this);
+ }
+
+ @Override
+ public void visit(OWLDatatype node) {
+ write(shortFormProvider.getShortForm(node));
+ }
+
+ @Override
+ public void visit(OWLDataComplementOf node) {
+ write(NOT);
+ node.getDataRange().accept(this);
+ }
+
+ @Override
+ public void visit(OWLDataOneOf node) {
+ for (Iterator<OWLLiteral> it = node.getValues().iterator(); it.hasNext();) {
+ write("{");
+ it.next().accept(this);
+ write("}");
+ if (it.hasNext()) {
+ write(OR);
+ }
+ }
+ }
+
+ @Override
+ public void visit(OWLLiteral node) {
+ write(node.getLiteral());
+ }
+
+ @Override
+ public void visit(OWLObjectProperty property) {
+ writeEntity(property);
+ }
+
+ @Override
+ public void visit(OWLObjectInverseOf property) {
+ property.getInverse().accept(this);
+ write(INVERSE);
+ }
+
+ @Override
+ public void visit(OWLDataProperty property) {
+ writeEntity(property);
+ }
+
+ @Override
+ public void visit(OWLNamedIndividual individual) {
+ writeEntity(individual);
+ }
+
+ @Override
+ public void visit(OWLDatatypeDefinitionAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLHasKeyAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLAnnotationPropertyDomainAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLAnnotationPropertyRangeAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLSubAnnotationPropertyOfAxiom axiom) {
+ }
+
+ @Override
+ public void visit(OWLAnnotationProperty property) {
+ }
+
+ @Override
+ public void visit(OWLAnonymousIndividual individual) {
+ }
+
+ @Override
+ public void visit(IRI iri) {
+ }
+
+ @Override
+ public void visit(OWLAnnotation node) {
+ }
+
+ @Override
+ public void visit(SWRLClassAtom node) {
+ node.getPredicate().accept(this);
+ write("(");
+ node.getArgument().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(SWRLDataRangeAtom node) {
+ node.getPredicate().accept(this);
+ write("(");
+ node.getArgument().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(SWRLObjectPropertyAtom node) {
+ node.getPredicate().accept(this);
+ write("(");
+ node.getFirstArgument().accept(this);
+ write(", ");
+ node.getSecondArgument().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(SWRLDataPropertyAtom node) {
+ node.getPredicate().accept(this);
+ write("(");
+ node.getFirstArgument().accept(this);
+ write(", ");
+ node.getSecondArgument().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(SWRLBuiltInAtom node) {
+ write(node.getPredicate().toString());
+ write("(");
+ write(node.getArguments(), COMMA, true);
+ write(")");
+ }
+
+ @Override
+ public void visit(SWRLVariable node) {
+ write("?");
+ write(iriShortFormProvider.getShortForm(node.getIRI()));
+ }
+
+ @Override
+ public void visit(SWRLIndividualArgument node) {
+ node.getIndividual().accept(this);
+ }
+
+ @Override
+ public void visit(SWRLLiteralArgument node) {
+ node.getLiteral().accept(this);
+ }
+
+ @Override
+ public void visit(SWRLSameIndividualAtom node) {
+ write("sameAs(");
+ node.getFirstArgument().accept(this);
+ write(", ");
+ node.getSecondArgument().accept(this);
+ write(")");
+ }
+
+ @Override
+ public void visit(SWRLDifferentIndividualsAtom node) {
+ write("differentFrom(");
+ node.getFirstArgument().accept(this);
+ write(", ");
+ node.getSecondArgument().accept(this);
+ write(")");
+ }
+}
Added: trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java
===================================================================
--- trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java (rev 0)
+++ trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,155 @@
+/**
+ *
+ */
+package org.dllearner.test;
+
+import java.io.ByteArrayInputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.dllearner.algorithms.celoe.CELOE;
+import org.dllearner.core.AbstractCELA;
+import org.dllearner.core.AbstractLearningProblem;
+import org.dllearner.core.AbstractReasonerComponent;
+import org.dllearner.core.ComponentInitException;
+import org.dllearner.core.KnowledgeSource;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.kb.OWLAPIOntology;
+import org.dllearner.learningproblems.PosNegLPStandard;
+import org.dllearner.reasoning.FastInstanceChecker;
+import org.dllearner.utilities.owl.OWLAPIConverter;
+import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor;
+import org.junit.Assert;
+import org.junit.Test;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLNamedIndividual;
+import org.semanticweb.owlapi.model.OWLObjectProperty;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+
+import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl;
+
+import com.google.common.collect.Sets;
+
+/**
+ * @author Lorenz Buehmann
+ *
+ */
+public class PunningTest {
+
+
+ public OWLOntology makeExampleKB() throws OWLOntologyCreationException{
+ String kb = "@prefix owl:<http://www.w3.org/2002/07/owl#> . @prefix :<http://foo.org/> .";
+ kb += ":p a owl:ObjectProperty .";
+
+ for (int i = 1; i <= 5; i++) {
+ kb += ":r" + i + " a owl:ObjectProperty .";
+ }
+
+ kb += ":A a owl:Class; :r1 :o1; :r2 :o2 .";
+ kb += ":B a owl:Class; :r1 :o3; :r3 :o2 .";
+
+ for (int i = 1; i <= 10; i++) {
+ kb += ":x" + i + " a owl:NamedIndividual .";
+ }
+
+ int m = 5;
+ int n = 5;
+
+ //m instances of A
+ for (int i = 1; i <= m; i++) {
+ kb += ":x" + i + " a :A .";
+ }
+
+ //n instances of B
+ for (int i = 1; i <= n; i++) {
+ kb += ":x" + i + " a :A .";
+ }
+
+ OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new ByteArrayInputStream(kb.getBytes()));
+ return ontology;
+ }
+
+ public OWLOntology loadExample() throws OWLOntologyCreationException{
+ OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(this.getClass().getClassLoader().getResourceAsStream("punning_example.ttl"));
+ return ontology;
+ }
+
+ @Test
+ public void testPunning() throws OWLOntologyCreationException, ComponentInitException{
+ OWLOntology ontology = makeExampleKB();
+ OWLDataFactory df = new OWLDataFactoryImpl();
+
+ //check that A and B are both, individual and class
+ OWLClass clsA = df.getOWLClass(IRI.create("http://foo.org/A"));
+ OWLClass clsB = df.getOWLClass(IRI.create("http://foo.org/B"));
+ OWLIndividual indA = df.getOWLNamedIndividual(IRI.create("http://foo.org/A"));
+ OWLIndividual indB = df.getOWLNamedIndividual(IRI.create("http://foo.org/B"));
+
+ Set<OWLClass> classes = ontology.getClassesInSignature();
+ Set<OWLObjectProperty> properties = ontology.getObjectPropertiesInSignature();
+ Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
+
+ System.out.println("Classes:" + classes);
+ System.out.println("Properties:" + properties);
+ System.out.println("Individuals:" + individuals);
+
+ Assert.assertTrue(
+ ontology.getClassesInSignature().contains(clsA) &&
+ ontology.getClassesInSignature().contains(clsB) &&
+ ontology.getIndividualsInSignature().contains(indA) &&
+ ontology.getIndividualsInSignature().contains(indB)
+ );
+
+ KnowledgeSource ks = new OWLAPIOntology(ontology);
+ ks.init();
+
+ AbstractReasonerComponent rc = new FastInstanceChecker(ks);
+ rc.init();
+
+ AbstractLearningProblem lp = new PosNegLPStandard(rc);
+ lp.init();
+
+ AbstractCELA la = new CELOE(lp, rc);
+ la.init();
+
+ la.start();
+ }
+
+ @Test
+ public void testPunning2() throws OWLOntologyCreationException, ComponentInitException{
+ OWLOntology ontology = loadExample();
+ OWLDataFactory df = new OWLDataFactoryImpl();
+
+ //check that A and B are both, individual and class
+ Set<Individual> posExamples = new HashSet<Individual>();
+ for (String uri : Sets.newHashSet("http://ex.org/TRABANT601#1234", "http://ex.org/S51#2345", "http://ex.org/MIFA23#3456")) {
+ posExamples.add(new Individual(uri));
+ }
+ Set<Individual> negExamples = new HashSet<Individual>();
+ for (String uri : Sets.newHashSet("http://ex.org/CLIPSO90MG#4567", "http://ex.org/SIEMENS425#567", "http://ex.org/TATRAT3#678")) {
+ negExamples.add(new Individual(uri));
+ }
+
+ KnowledgeSource ks = new OWLAPIOntology(ontology);
+ ks.init();
+
+ AbstractReasonerComponent rc = new FastInstanceChecker(ks);
+ rc.init();
+
+ PosNegLPStandard lp = new PosNegLPStandard(rc);
+ lp.setPositiveExamples(posExamples);
+ lp.setNegativeExamples(negExamples);
+ lp.init();
+
+ AbstractCELA la = new CELOE(lp, rc);
+ la.init();
+
+ la.start();
+ }
+
+}
Added: trunk/components-core/src/test/java/org/dllearner/test/junit/PunningTest.java
===================================================================
--- trunk/components-core/src/test/java/org/dllearner/test/junit/PunningTest.java (rev 0)
+++ trunk/components-core/src/test/java/org/dllearner/test/junit/PunningTest.java 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,64 @@
+/**
+ *
+ */
+package org.dllearner.test.junit;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+
+import org.dllearner.core.AbstractReasonerComponent;
+import org.dllearner.core.KnowledgeSource;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.kb.OWLAPIOntology;
+import org.dllearner.reasoning.FastInstanceChecker;
+import org.junit.Test;
+import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.model.IRI;
+import org.semanticweb.owlapi.model.OWLClass;
+import org.semanticweb.owlapi.model.OWLDataFactory;
+import org.semanticweb.owlapi.model.OWLNamedIndividual;
+import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.OWLOntologyChange;
+import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.reasoner.OWLReasoner;
+import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
+
+import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+
+/**
+ * @author Lorenz Buehmann
+ *
+ */
+public class PunningTest {
+
+ @Test
+ public void test() throws Exception {
+ String triples = "@prefix owl:<http://www.w3.org/2002/07/owl#> . @prefix : <http://other.example.org/ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ."
+ + ":A a owl:NamedIndividual. :A a owl:Class. :A a :B . :B rdfs:subClassOf :A .";
+ System.out.println(triples);
+ ModelFactory.createDefaultModel().read(new ByteArrayInputStream(triples.getBytes()), null, "TURTLE");
+
+ OWLOntologyManager man = OWLManager.createOWLOntologyManager();
+ OWLDataFactory df = man.getOWLDataFactory();
+ OWLOntology ontology = man.loadOntologyFromOntologyDocument(new ByteArrayInputStream(triples.getBytes()));
+ System.out.println(ontology.getIndividualsInSignature());
+ System.out.println(ontology.getClassesInSignature());
+ OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
+ OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ontology);
+ OWLClass c = df.getOWLClass(IRI.create("http://other.example.org/ns#A"));
+ OWLNamedIndividual i = df.getOWLNamedIndividual(IRI.create("http://other.example.org/ns#A"));
+ System.out.println(reasoner.getInstances(c, false));
+ KnowledgeSource ks = new OWLAPIOntology(ontology);
+ AbstractReasonerComponent rc = new FastInstanceChecker(ks);
+ rc.init();
+ NamedClass cls = new NamedClass("http://other.example.org/ns#A");
+ System.out.println(rc.getIndividuals(cls));
+ Individual ind = new Individual("http://other.example.org/ns#A");
+ System.out.println(rc.hasType(cls, ind));
+ }
+
+}
Added: trunk/components-core/src/test/resources/log4j.properties
===================================================================
--- trunk/components-core/src/test/resources/log4j.properties (rev 0)
+++ trunk/components-core/src/test/resources/log4j.properties 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,20 @@
+# Direct log messages to stdout
+# Root logger option
+log4j.rootLogger=INFO,stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %p [%c] %L - %m%n
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} [%c] - %m%n
+
+#File Appender
+log4j.appender.FA=org.apache.log4j.FileAppender
+log4j.appender.FA.File=REX.log
+log4j.appender.FA.layout=org.apache.log4j.PatternLayout
+log4j.appender.FA.layout.ConversionPattern=%d{ABSOLUTE} %p [%c] %L - %m%n
+
+
+log4j.category.org.dllearner.algorithms=INFO
+log4j.category.org.dllearner.algorithms.isle=DEBUG
+log4j.category.org.dllearner.algorithms.qtl=INFO
+log4j.category.org.dllearner.algorithms.qtl.lgg=INFO
Property changes on: trunk/components-core/src/test/resources/log4j.properties
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/components-core/src/test/resources/punning_example.ttl
===================================================================
--- trunk/components-core/src/test/resources/punning_example.ttl (rev 0)
+++ trunk/components-core/src/test/resources/punning_example.ttl 2014-07-29 13:55:31 UTC (rev 4281)
@@ -0,0 +1,67 @@
+#Solution \exists bereifung.\top \sqcap Fahrzeug
+
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix ex: <http://ex.org/> .
+
+ex:Gummireifen a owl:Class .
+ex:bereifung a owl:ObjectProperty .
+
+ex:Transporthilfe a owl:Class .
+
+ex:Schubkarre
+ a owl:Class ;
+ rdfs:subClassOf ex:Transporthilfe .
+
+ex:Fahrzeug a owl:Class .
+ex:Fahrzeug owl:disjointWith ex:Transporthilfe .
+
+ex:Tram
+ a owl:Class ;
+ rdfs:subClassOf ex:Fahrzeug .
+
+ex:Bahn
+ a owl:Class ;
+ rdfs:subClassOf ex:Fahrzeug .
+
+ex:Auto
+ a owl:Class ;
+ rdfs:subClassOf ex:Fahrzeug .
+
+ex:Moped
+ a owl:Class ;
+ rdfs:subClassOf ex:Fahrzeug .
+
+ex:Fahrrad
+ a owl:Class ;
+ rdfs:subClassOf ex:Fahrzeug .
+
+ex:BRIDGESTONE_XYZ a ex:Gummireifen .
+ex:PNEUMANT_4711 a ex:Gummireifen .
+ex:HEIDENAU_K36 a ex:Gummireifen .
+ex:DEMA_ABC23 a ex:Gummireifen .
+
+ex:Auto ex:bereifung ex:BRIDGESTONE_XYZ .
+ex:Moped ex:bereifung ex:HEIDENAU_K36 .
+ex:Fahrrad ex:bereifung ex:PNEUMANT_4711 .
+ex:Schubkarre ex:bereifung ex:DEMA_ABC23 .
+
+# positive individuals
+<http://ex.org/TRABANT601#1234> a ex:Auto .
+<http://ex.org/S51#2345> a ex:Moped .
+<http://ex.org/MIFA23#3456> a ex:Fahrrad .
+
+# negative individuals
+<http://ex.org/CLIPSO90MG#4567> a ex:Schubkarre .
+<http://ex.org/SIEMENS425#567> a ex:Bahn .
+<http://ex.org/TATRAT3#678> a ex:Tram .
+
+# punning workaround
+ex:p a owl:ObjectProperty .
+<http://ex.org/TRABANT601#1234> ex:p ex:Auto .
+<http://ex.org/S51#2345> ex:p ex:Moped .
+<http://ex.org/MIFA23#3456> ex:p ex:Fahrrad .
+<http://ex.org/CLIPSO90MG#4567> ex:p ex:Schubkarre .
+<http://ex.org/SIEMENS425#567> ex:p ex:Bahn .
+<http://ex.org/TATRAT3#678> ex:p ex:Tram .
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|