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