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.algorithms.gp; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.semanticweb.owlapi.model.OWLClassExpression; 025 026/** 027 * A tree-like datastructure for OWL class expressions. 028 * @author Lorenz Buehmann 029 * @since Feb 15, 2015 030 */ 031public class OWLClassExpressionTree implements Cloneable{ 032 033 private OWLClassExpressionTree parent; 034 private List<OWLClassExpressionTree> children; 035 private OWLClassExpression classExpression; 036 037 public OWLClassExpressionTree(OWLClassExpression ce) { 038 this(null, ce); 039 } 040 041 public OWLClassExpressionTree(OWLClassExpressionTree parent, OWLClassExpression ce) { 042 this(parent, new ArrayList<>(), ce); 043 } 044 045 public OWLClassExpressionTree(OWLClassExpressionTree parent, 046 List<OWLClassExpressionTree> children, OWLClassExpression ce) { 047 this.parent = parent; 048 this.children = children; 049 this.classExpression = ce; 050 } 051 052 public boolean isRoot() { 053 return parent == null; 054 } 055 056 /** 057 * @return the parent 058 */ 059 public OWLClassExpressionTree getParent() { 060 return parent; 061 } 062 063 /** 064 * @param parent the parent to set 065 */ 066 public void setParent(OWLClassExpressionTree parent) { 067 this.parent = parent; 068 } 069 070 /** 071 * @return the children 072 */ 073 public List<OWLClassExpressionTree> getChildren() { 074 return children; 075 } 076 077 public OWLClassExpressionTree getChild(int position) { 078 return children.get(position); 079 } 080 081 /* (non-Javadoc) 082 * @see java.lang.Object#clone() 083 */ 084 @Override 085 protected Object clone() throws CloneNotSupportedException { 086 List<OWLClassExpressionTree> childrenClone = new ArrayList<>(children.size()); 087 OWLClassExpressionTree parentClone = (OWLClassExpressionTree) parent.clone(); 088 OWLClassExpressionTree clone = new OWLClassExpressionTree(parentClone, childrenClone, classExpression); 089 clone.setParent(parent); 090 return clone; 091 } 092 093}