001/**
002 * Copyright (C) 2007 - 2016, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.dllearner.algorithms.properties;
020
021import java.util.SortedSet;
022
023import org.dllearner.core.ComponentAnn;
024import org.dllearner.kb.SparqlEndpointKS;
025import org.dllearner.learningproblems.AxiomScore;
026import org.semanticweb.owlapi.model.AxiomType;
027import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom;
028import org.semanticweb.owlapi.model.OWLObjectProperty;
029
030import org.apache.jena.query.ParameterizedSparqlString;
031
032@ComponentAnn(name = "disjoint object properties axiom learner", shortName = "opldisjoint", version = 0.1, description="A learning algorithm for disjoint object properties axioms.")
033public class DisjointObjectPropertyAxiomLearner extends ObjectPropertyHierarchyAxiomLearner<OWLDisjointObjectPropertiesAxiom> {
034
035        public DisjointObjectPropertyAxiomLearner(SparqlEndpointKS ks) {
036                super(ks);
037
038                super.posExamplesQueryTemplate = new ParameterizedSparqlString(
039                                "SELECT DISTINCT ?s ?o WHERE {?s ?p ?o. FILTER NOT EXISTS{?s ?p_other ?o}}");
040                super.negExamplesQueryTemplate = new ParameterizedSparqlString(
041                                "SELECT DISTINCT ?s ?o WHERE {?s ?p ?o; ?p_other ?o.}");
042                
043                axiomType = AxiomType.DISJOINT_OBJECT_PROPERTIES;
044        }
045
046        /*
047         * (non-Javadoc)
048         * 
049         * @see
050         * org.dllearner.core.AbstractAxiomLearningAlgorithm#getExistingAxioms()
051         */
052        @Override
053        protected void getExistingAxioms() {
054                SortedSet<OWLObjectProperty> existingDisjointProperties = reasoner.getDisjointProperties(entityToDescribe);
055                if (existingDisjointProperties != null && !existingDisjointProperties.isEmpty()) {
056                        for (OWLObjectProperty disProp : existingDisjointProperties) {
057                                existingAxioms.add(df.getOWLDisjointObjectPropertiesAxiom(entityToDescribe, disProp));
058                        }
059                        logger.info("Existing axioms:" + existingAxioms);
060                }
061        }
062        
063        /* (non-Javadoc)
064         * @see org.dllearner.algorithms.properties.ObjectPropertyHierarchyAxiomLearner#getAxiom(org.semanticweb.owlapi.model.OWLObjectProperty, org.semanticweb.owlapi.model.OWLObjectProperty)
065         */
066        @Override
067        public OWLDisjointObjectPropertiesAxiom getAxiom(OWLObjectProperty property, OWLObjectProperty otherProperty) {
068                return df.getOWLDisjointObjectPropertiesAxiom(property, otherProperty);
069        }
070        
071        @Override
072        public AxiomScore computeScore(int candidatePopularity, int popularity, int overlap) {
073                AxiomScore score = super.computeScore(candidatePopularity, popularity, overlap);
074
075                // we need to invert the value
076                AxiomScore invertedScore = new AxiomScore(
077                                1 - score.getAccuracy(),
078                                1 - score.getConfidence(),
079                                score.getNrOfPositiveExamples(), score.getNrOfNegativeExamples(),
080                                score.isSampleBased());
081
082                return invertedScore;
083        }
084}