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.core.ConsoleAxiomLearningProgressMonitor; 025import org.dllearner.kb.SparqlEndpointKS; 026import org.dllearner.kb.sparql.SparqlEndpoint; 027import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer; 028import org.semanticweb.owlapi.io.ToStringRenderer; 029import org.semanticweb.owlapi.model.AxiomType; 030import org.semanticweb.owlapi.model.IRI; 031import org.semanticweb.owlapi.model.OWLObjectProperty; 032import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom; 033import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl; 034 035@ComponentAnn(name = "object subproperty axiom learner", shortName = "oplsubprop", version = 0.1, description="A learning algorithm object subproperty axioms.") 036public class SubObjectPropertyOfAxiomLearner extends ObjectPropertyHierarchyAxiomLearner<OWLSubObjectPropertyOfAxiom>{ 037 038 private final double BETA = 3.0; 039 040 public SubObjectPropertyOfAxiomLearner(SparqlEndpointKS ks) { 041 super(ks); 042 043 setBeta(BETA); 044 045 axiomType = AxiomType.SUB_OBJECT_PROPERTY; 046 } 047 048 /* (non-Javadoc) 049 * @see org.dllearner.core.AbstractAxiomLearningAlgorithm#getExistingAxioms() 050 */ 051 @Override 052 protected void getExistingAxioms() { 053 SortedSet<OWLObjectProperty> existingSuperProperties = reasoner.getSuperProperties(entityToDescribe); 054 if (existingSuperProperties != null && !existingSuperProperties.isEmpty()) { 055 for (OWLObjectProperty supProp : existingSuperProperties) { 056 existingAxioms.add(df.getOWLSubObjectPropertyOfAxiom(entityToDescribe, supProp)); 057 } 058 logger.info("Existing axioms:" + existingAxioms); 059 } 060 } 061 062 /* (non-Javadoc) 063 * @see org.dllearner.algorithms.properties.ObjectPropertyHierarchyAxiomLearner#getAxiom(org.semanticweb.owlapi.model.OWLObjectProperty, org.semanticweb.owlapi.model.OWLObjectProperty) 064 */ 065 @Override 066 public OWLSubObjectPropertyOfAxiom getAxiom(OWLObjectProperty property, OWLObjectProperty otherProperty) { 067 return df.getOWLSubObjectPropertyOfAxiom(property, otherProperty); 068 } 069 070 public static void main(String[] args) throws Exception { 071 ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); 072 SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); 073 ks.init(); 074 075 SubObjectPropertyOfAxiomLearner la = new SubObjectPropertyOfAxiomLearner(ks); 076 la.setEntityToDescribe(new OWLObjectPropertyImpl(IRI.create("http://dbpedia.org/ontology/author"))); 077 la.setUseSampling(false); 078 la.setBatchMode(true); 079 la.setProgressMonitor(new ConsoleAxiomLearningProgressMonitor()); 080 la.init(); 081 082 la.start(); 083 084 la.getCurrentlyBestEvaluatedAxioms().forEach(ax -> { 085 System.out.println("---------------\n" + ax); 086 la.getPositiveExamples(ax).stream().limit(5).forEach(System.out::println); 087 }); 088 } 089}