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.List;
023 import java.util.Map;
024
025 public class Union extends Description {
026
027 /**
028 *
029 */
030 private static final long serialVersionUID = -4475957631228826618L;
031
032 public Union() {
033
034 }
035
036 public Union(Description... children) {
037 for(Description child : children) {
038 addChild(child);
039 }
040 }
041
042 // Kinder müssen in einer Liste sein, sonst ist nicht garantiert,
043 // dass die Ordnung der Kinder die gleiche wie im Argument ist
044 public Union(List<Description> children) {
045 for(Description child : children) {
046 addChild(child);
047 }
048 }
049
050 @Override
051 public int getArity() {
052 return children.size();
053 }
054
055 public int getLength() {
056 int length = 0;
057 for(Description child : children) {
058 length += child.getLength();
059 }
060 return length + children.size() - 1;
061 }
062
063 public String toString(String baseURI, Map<String,String> prefixes) {
064 if(children.size()==0)
065 return "EMPTY_OR";
066
067 String ret = "(";
068 for(int i=0; i<children.size()-1; i++) {
069 ret += children.get(i).toString(baseURI, prefixes) + " OR ";
070 }
071 ret += children.get(children.size()-1).toString(baseURI, prefixes) + ")";
072 return ret;
073 }
074
075 public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) {
076
077 if(children.size()==0)
078 return "EMPTY_OR";
079
080 String ret = "(";
081 String bracketCollect = "";
082 for(int i=0; i<children.size()-1; i++) {
083 ret += children.get(i).toKBSyntaxString(baseURI, prefixes) + " OR ";
084 if( i != (children.size()-2) ) {
085 ret += "(";
086 bracketCollect += ")";
087 }
088 }
089 ret += children.get(children.size()-1).toKBSyntaxString(baseURI, prefixes) + ")";
090 ret += bracketCollect;
091 return ret;
092 }
093
094 @Override
095 public String toManchesterSyntaxString(String baseURI, Map<String,String> prefixes) {
096 if(children.size()==0)
097 return "EMPTY_OR";
098
099 String ret = "(";
100 for(int i=0; i<children.size()-1; i++) {
101 ret += children.get(i).toManchesterSyntaxString(baseURI, prefixes) + " or ";
102 }
103 ret += children.get(children.size()-1).toManchesterSyntaxString(baseURI, prefixes) + ")";
104 return ret;
105 }
106
107 public String toStringOld() {
108 String ret = "MULTI_OR [";
109 for(Description child : children) {
110 ret += child.toString() + ",";
111 }
112 ret += "]";
113 return ret;
114 }
115
116 /* (non-Javadoc)
117 * @see org.dllearner.core.owl.Description#accept(org.dllearner.core.owl.DescriptionVisitor)
118 */
119 @Override
120 public void accept(DescriptionVisitor visitor) {
121 visitor.visit(this);
122 }
123
124 public void accept(KBElementVisitor visitor) {
125 visitor.visit(this);
126 }
127 }