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 org.dllearner.core.ComponentAnn; 009import org.dllearner.core.ComponentInitException; 010import org.dllearner.core.config.ConfigOption; 011import org.dllearner.reasoning.unife.ProbabilisticReasonerType; 012import org.dllearner.utils.unife.OWLUtils; 013import org.semanticweb.owlapi.model.OWLAxiom; 014import org.semanticweb.owlapi.model.OWLException; 015import unife.bundle.Bundle; 016import unife.bundle.QueryResult; 017import unife.utilities.GeneralUtils; 018 019/** 020 * 021 * @author Giuseppe Cota <giuseppe.cota@unife.it>, Riccardo Zese 022 * <riccardo.zese@unife.it> 023 */ 024@ComponentAnn(name = "BUNDLE", shortName = "bundle", version = 1.0) 025public class BUNDLE extends AbstractProbabilisticReasonerComponent implements OWLProbabilisticExplanationReasoner { 026 027 private Bundle bundle = new Bundle(); 028 029 @ConfigOption(description = "max time allowed for the inference (format: [0-9]h[0-9]m[0-9]s)", defaultValue = "0s (infinite timeout)") 030 private String timeout = "0s"; 031 032 @ConfigOption(description = "the maximum number of explanations to find for each query", defaultValue = "" + Integer.MAX_VALUE) 033 private int maxExplanations = Integer.MAX_VALUE; 034 035 @ConfigOption(description = "accuracy used during the computation of the probabilistic values (number of digital places)", defaultValue = "5") 036 private int accuracy = 5; 037 038 @ConfigOption(description = "library used for BDD compilation", defaultValue = "buddy") 039 private String bddFType = "buddy"; 040 041 @Override 042 public ProbabilisticReasonerType getReasonerType() { 043 return ProbabilisticReasonerType.BUNDLE; 044 } 045 046 @Override 047 public void init() throws ComponentInitException { 048 super.init(); 049 bundle.setBddFType(bddFType); 050 bundle.setMaxExplanations(this.maxExplanations); 051 bundle.setMaxTime(this.timeout); 052 bundle.setLog(true); 053 bundle.setAccuracy(this.accuracy); 054 bundle.loadOntologies(ontology); 055 bundle.init(); 056 initialized = true; 057 } 058 059 @Override 060 public OWLProbExplanationReasonerResult computeQueryWithExplanations(OWLAxiom axiom) throws OWLException { 061 QueryResult result = bundle.computeQuery(axiom); 062 return new OWLProbExplanationReasonerResult( 063 axiom, 064 result.getQueryProbability().doubleValue(), 065 GeneralUtils.safe(result.getExplanations())); 066 } 067 068 @Override 069 public OWLProbReasonerResult computeQuery(OWLAxiom axiom) throws OWLException { 070 return computeQueryWithExplanations(axiom); 071 } 072 073 /** 074 * @param timeout the timeout to set 075 */ 076 public void setTimeout(String timeout) { 077 this.timeout = timeout; 078 } 079 080 /** 081 * @param maxExplanations the maxExplanations to set 082 */ 083 public void setMaxExplanations(int maxExplanations) { 084 this.maxExplanations = maxExplanations; 085 } 086 087 /** 088 * @param accuracy the accuracy to set 089 */ 090 public void setAccuracy(int accuracy) { 091 this.accuracy = accuracy; 092 } 093 094 /** 095 * @param bddFType the bddFType to set 096 */ 097 public void setBddFType(String bddFType) { 098 this.bddFType = bddFType; 099 } 100 101}