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.refinementoperators; 020 021import org.dllearner.core.ComponentInitException; 022import org.dllearner.utilities.owl.OWLClassExpressionLengthMetric; 023import org.semanticweb.owlapi.model.OWLClassExpression; 024 025import java.util.List; 026import java.util.Set; 027 028/** 029 * A wrapper class that makes the call of the refinement methods synchronized, i.e. 030 * it's supposed to provide a thread-safe implementation. 031 * 032 * TODO This only works if the used datastructures do not need additional 033 * synchronization. 034 * @author Lorenz Buehmann 035 * 036 */ 037// not for conf 038public class SynchronizedRefinementOperator extends AbstractRefinementOperator implements LengthLimitedRefinementOperator{ 039 040 private final LengthLimitedRefinementOperator delegate; 041 042 public SynchronizedRefinementOperator(LengthLimitedRefinementOperator delegate) { 043 this.delegate = delegate; 044 } 045 046 /* (non-Javadoc) 047 * @see org.dllearner.core.Component#init() 048 */ 049 @Override 050 public void init() throws ComponentInitException { 051 synchronized (delegate) { 052 delegate.init(); 053 } 054 055 initialized = true; 056 } 057 058 /* (non-Javadoc) 059 * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.semanticweb.owlapi.model.OWLClassExpression) 060 */ 061 @Override 062 public Set<OWLClassExpression> refine(OWLClassExpression description) { 063 synchronized (delegate) { 064 return delegate.refine(description); 065 } 066 } 067 068 /* (non-Javadoc) 069 * @see org.dllearner.refinementoperators.LengthLimitedRefinementOperator#refine(org.semanticweb.owlapi.model.OWLClassExpression, int) 070 */ 071 @Override 072 public Set<OWLClassExpression> refine(OWLClassExpression description, int maxLength) { 073 synchronized (delegate) { 074 return delegate.refine(description, maxLength); 075 } 076 } 077 078 /* (non-Javadoc) 079 * @see org.dllearner.refinementoperators.LengthLimitedRefinementOperator#refine(org.semanticweb.owlapi.model.OWLClassExpression, int, java.util.List) 080 */ 081 @Override 082 public Set<OWLClassExpression> refine(OWLClassExpression description, int maxLength, 083 List<OWLClassExpression> knownRefinements) { 084 synchronized (delegate) { 085 return delegate.refine(description, maxLength, knownRefinements); 086 } 087 } 088 089 @Override 090 public void setLengthMetric(OWLClassExpressionLengthMetric lengthMetric) { 091 synchronized (delegate) { 092 delegate.setLengthMetric(lengthMetric); 093 } 094 } 095 096 @Override 097 public OWLClassExpressionLengthMetric getLengthMetric() { 098 synchronized (delegate) { 099 return delegate.getLengthMetric(); 100 } 101 } 102 103 /** 104 * @return the wrapped refinement operator 105 */ 106 public LengthLimitedRefinementOperator getDelegate() { 107 return delegate; 108 } 109 110}