001/* 002 * To change this license header, choose License Headers in Project Properties. 003 * To change this template file, choose Tools | Templates 004 * and open the template in the editor. 005 */ 006package org.dllearner.core.probabilistic.unife; 007 008import java.util.Arrays; 009import java.util.Collections; 010import java.util.HashSet; 011import java.util.Set; 012import org.apache.log4j.Logger; 013import org.dllearner.core.AbstractComponent; 014import org.dllearner.core.ComponentInitException; 015import org.dllearner.core.KnowledgeSource; 016import unife.bundle.logging.BundleLoggerFactory; 017import org.dllearner.reasoning.unife.ProbabilisticReasonerType; 018import org.dllearner.utils.unife.OWLUtils; 019import org.semanticweb.owlapi.model.OWLOntology; 020import org.springframework.beans.factory.annotation.Autowired; 021 022/** 023 * 024 * @author Giuseppe Cota <giuseppe.cota@unife.it>, Riccardo Zese 025 * <riccardo.zese@unife.it> 026 */ 027public abstract class AbstractProbabilisticReasonerComponent extends AbstractComponent implements ProbabilisticReasoner { 028 029 public static Logger logger = Logger.getLogger(AbstractProbabilisticReasonerComponent.class.getName(), 030 new BundleLoggerFactory()); 031 032 /** 033 * The underlying knowledge sources. 034 */ 035 protected Set<KnowledgeSource> sources; 036 037 OWLOntology ontology; 038 039 public AbstractProbabilisticReasonerComponent() { 040 041 } 042 043 /** 044 * Constructs a new reasoner component. 045 * 046 * @param sources The underlying knowledge sources. 047 */ 048 public AbstractProbabilisticReasonerComponent(Set<KnowledgeSource> sources) { 049 this.sources = sources; 050 } 051 052 public AbstractProbabilisticReasonerComponent(KnowledgeSource source) { 053 this(Collections.singleton(source)); 054 } 055 056 057 public void init() throws ComponentInitException { 058 ontology = OWLUtils.mergeOntologies(sources); 059 060 initialized = true; 061 } 062 063 /** 064 * Gets the knowledge sources used by this reasoner. 065 * 066 * @return The underlying knowledge sources. 067 */ 068 public Set<KnowledgeSource> getSources() { 069 return sources; 070 } 071 072 @Autowired 073 public void setSources(Set<KnowledgeSource> sources) { 074 this.sources = sources; 075 } 076 077 @Autowired 078 public void setSources(KnowledgeSource... sources) { 079 this.sources = new HashSet<KnowledgeSource>(Arrays.asList(sources)); 080 } 081 082 /** 083 * Method to exchange the reasoner underlying the learning problem. 084 * Implementations, which do not only use the provided sources class 085 * variable, must make sure that a call to this method indeed changes them. 086 * 087 * @param sources The new knowledge sources. 088 */ 089 public void changeSources(Set<KnowledgeSource> sources) { 090 this.sources = sources; 091 } 092 093 /** 094 * Gets the type of the underlying probabilistic reasoner. Although rarely necessary, 095 * applications can use this to adapt their behaviour to the reasoner. 096 * 097 * @return The probabilistic reasoner type. 098 */ 099 public abstract ProbabilisticReasonerType getReasonerType(); 100 101 /** 102 * @return the ontology 103 */ 104 public OWLOntology getOntology() { 105 return ontology; 106 } 107}