001    /**
002     * Copyright (C) 2007-2011, 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     */
019    
020    package org.dllearner.core.owl;
021    
022    import java.util.Map;
023    
024    
025    /**
026     * Convenience class for boolean value restrictions.
027     * 
028     * @author Jens Lehmann
029     *
030     */
031    public class BooleanValueRestriction extends DatatypeValueRestriction {
032    
033            /**
034             * 
035             */
036            private static final long serialVersionUID = 1653555689466334140L;
037            private boolean booleanValue;
038            
039            /**
040             * TODO: Internally a typed constant with datatype boolean and 
041             * strings "true" or "false" is created. This is a clean way to
042             * implement boolean value restrictions. However, if they are
043             * created millions of times during the run of an algorithm, 
044             * this may cause unnecessary delays. 
045             * Possible Solution: It may be good to create a BooleanConstant 
046             * class, which just holds the boolean value and only performs 
047             * operations when requested.
048             * 
049             * @param restrictedPropertyExpression
050             * @param value
051             */
052            public BooleanValueRestriction(DatatypeProperty restrictedPropertyExpression, Boolean value) {
053                    super(restrictedPropertyExpression, new TypedConstant(value.toString(), OWL2Datatype.BOOLEAN.getDatatype()));
054                    booleanValue = value;
055            }
056    
057            public boolean getBooleanValue() {
058                    return booleanValue;
059            }
060    
061            /**
062             * Boolean value restrictions have length 2, because they encode two
063             * pieces of information: the property and the boolean value.
064             */
065            public int getLength() {
066                    return 2;
067            }
068            
069            @Override
070            public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) {
071                    String ret= "("+restrictedPropertyExpression.toKBSyntaxString(baseURI, prefixes) + " IS " + ((String)value.toKBSyntaxString(baseURI, prefixes)).toUpperCase()+")";
072                    return ret;
073                    
074            }
075    }