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.core; 020 021import org.dllearner.core.annotations.NoConfigOption; 022import org.dllearner.core.config.ConfigOption; 023import org.dllearner.learningproblems.ExampleLoader; 024import org.dllearner.utilities.ReasoningUtils; 025import org.semanticweb.owlapi.model.OWLClassExpression; 026import org.semanticweb.owlapi.model.OWLDataFactory; 027import org.springframework.beans.factory.annotation.Autowired; 028import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; 029 030/** 031 * Base class for all class expression learning problems. 032 * 033 * @author Lorenz Buehmann 034 * 035 */ 036public abstract class AbstractClassExpressionLearningProblem<T extends Score> 037 extends AbstractLearningProblem<T, OWLClassExpression, EvaluatedDescription<T>> 038 implements LearningProblem { 039 040 protected OWLDataFactory dataFactory = new OWLDataFactoryImpl(); 041 @ConfigOption(description = "load examples via class expression selector") 042 protected ExampleLoader exampleLoaderHelper = null; 043 044 public AbstractClassExpressionLearningProblem(){ 045 046 } 047 048 @NoConfigOption 049 protected ReasoningUtils reasoningUtil; 050 protected static Class reasoningUtilsClass = ReasoningUtils.class; 051 052 private void setReasonerAndUtil(AbstractReasonerComponent reasoner) { 053 if (this.reasoner != reasoner) { 054 if (this.reasoningUtil == null) { 055 this.reasoningUtil = newReasoningUtils(reasoner); 056 } else { 057 this.reasoningUtil.setReasoner(reasoner); 058 } 059 060 this.reasoningUtil.init(); 061 } 062 this.reasoner = reasoner; 063 } 064 065 /** 066 * Factory method to get problem-specific reasoning utils 067 * @param reasoner the current reasoner 068 * @return a reasoning util (by default the generic one) 069 */ 070 protected ReasoningUtils newReasoningUtils(AbstractReasonerComponent reasoner) { 071 return new ReasoningUtils(reasoner); 072 } 073 074 /** 075 * Constructs a learning problem using a reasoning service for 076 * querying the background knowledge. It can be used for 077 * evaluating solution candidates. 078 * @param reasoner The reasoning service used as 079 * background knowledge. 080 */ 081 public AbstractClassExpressionLearningProblem(AbstractReasonerComponent reasoner) { 082 setReasonerAndUtil(reasoner); 083 } 084 085 @Override 086 @Autowired(required=false) 087 public void setReasoner(AbstractReasonerComponent reasoner) { 088 setReasonerAndUtil(reasoner); 089 } 090 091 @Override 092 public void changeReasonerComponent(AbstractReasonerComponent reasoner) { 093 setReasonerAndUtil(reasoner); 094 } 095 096 public ReasoningUtils getReasoningUtil() { 097 return reasoningUtil; 098 } 099 100 public void setReasoningUtil(ReasoningUtils reasoningUtil) { 101 this.reasoningUtil = reasoningUtil; 102 } 103 104 public ExampleLoader getExampleLoaderHelper() { 105 return exampleLoaderHelper; 106 } 107 108 @Autowired(required = false) 109 public void setExampleLoaderHelper(ExampleLoader exampleLoaderHelper) { 110 this.exampleLoaderHelper = exampleLoaderHelper; 111 } 112}