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 org.apache.jena.query.ParameterizedSparqlString; 022import org.dllearner.core.ComponentAnn; 023import org.dllearner.kb.SparqlEndpointKS; 024import org.dllearner.learningproblems.AxiomScore; 025import org.semanticweb.owlapi.model.AxiomType; 026import org.semanticweb.owlapi.model.OWLDataProperty; 027import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom; 028 029import java.util.SortedSet; 030 031@ComponentAnn(name = "disjoint data properties axiom learner", shortName = "dpldisjoint", version = 0.1, description="A learning algorithm for disjoint data properties axioms.") 032public class DisjointDataPropertyAxiomLearner extends DataPropertyHierarchyAxiomLearner<OWLDisjointDataPropertiesAxiom> { 033 034 public DisjointDataPropertyAxiomLearner(SparqlEndpointKS ks) { 035 super(ks); 036 037 super.posExamplesQueryTemplate = new ParameterizedSparqlString( 038 "SELECT DISTINCT ?s ?o WHERE {?s ?p ?o. FILTER NOT EXISTS{?s ?p_dis ?o}}"); 039 super.negExamplesQueryTemplate = new ParameterizedSparqlString( 040 "SELECT DISTINCT ?s ?o WHERE {?s ?p ?o; ?p_dis ?o.}"); 041 042 axiomType = AxiomType.DISJOINT_DATA_PROPERTIES; 043 } 044 045 /* 046 * (non-Javadoc) 047 * 048 * @see 049 * org.dllearner.core.AbstractAxiomLearningAlgorithm#getExistingAxioms() 050 */ 051 @Override 052 protected void getExistingAxioms() { 053 SortedSet<OWLDataProperty> existingDisjointProperties = reasoner.getDisjointProperties(entityToDescribe); 054 if (existingDisjointProperties != null && !existingDisjointProperties.isEmpty()) { 055 for (OWLDataProperty disProp : existingDisjointProperties) { 056 existingAxioms.add(df.getOWLDisjointDataPropertiesAxiom(entityToDescribe, disProp)); 057 } 058 logger.info("Existing axioms:" + existingAxioms); 059 } 060 } 061 062 /* (non-Javadoc) 063 * @see org.dllearner.algorithms.properties.DataPropertyHierarchyAxiomLearner#getAxiom(org.semanticweb.owlapi.model.OWLDataProperty, org.semanticweb.owlapi.model.OWLDataProperty) 064 */ 065 @Override 066 public OWLDisjointDataPropertiesAxiom getAxiom(OWLDataProperty property, OWLDataProperty otherProperty) { 067 return df.getOWLDisjointDataPropertiesAxiom(property, otherProperty); 068 } 069 070 /* (non-Javadoc) 071 * @see org.dllearner.algorithms.properties.DataPropertyHierarchyAxiomLearner#computeScore(int, int, int) 072 */ 073 @Override 074 public AxiomScore computeScore(int candidatePopularity, int popularity, int overlap) { 075 AxiomScore score = super.computeScore(candidatePopularity, popularity, overlap); 076 077 // we need to invert the value 078 AxiomScore invertedScore = new AxiomScore( 079 1 - score.getAccuracy(), 080 1 - score.getConfidence(), 081 score.getNrOfPositiveExamples(), score.getNrOfNegativeExamples(), 082 score.isSampleBased()); 083 084 return invertedScore; 085 } 086}