001 /**
002 * Copyright (C) 2007-2008, 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
021 package org.dllearner.tools.ore;
022
023 import java.awt.Color;
024 import java.awt.GridLayout;
025 import java.util.HashMap;
026 import java.util.HashSet;
027 import java.util.Map;
028 import java.util.Set;
029
030 import javax.swing.BorderFactory;
031 import javax.swing.ImageIcon;
032 import javax.swing.JLabel;
033 import javax.swing.JPanel;
034 import javax.swing.SwingUtilities;
035 import javax.swing.border.BevelBorder;
036
037 import org.dllearner.core.owl.Individual;
038 import org.dllearner.core.owl.NamedClass;
039 import org.dllearner.core.owl.ObjectPropertyAssertion;
040 import org.jdesktop.swingx.JXTaskPane;
041 import org.jdesktop.swingx.JXTaskPaneContainer;
042
043 /**
044 * Here are shown the name of the individual, class assertions and object properties of the individual which is selected to repair.
045 * @author Lorenz Buehmann
046 *
047 */
048 public class StatsPanel extends JPanel{
049
050 private static final long serialVersionUID = -8418286820511803278L;
051
052 private ORE ore;
053 private OntologyModifier modifier;
054 private Individual ind;
055 private Set<NamedClass> oldClasses;
056 private Set<ObjectPropertyAssertion> oldProperties;
057 private Map<String, Set<String>> oldPropMap;
058
059
060 private JXTaskPane indPane;
061 private JXTaskPane classPane;
062 private JXTaskPane propertyPane;
063
064 private JXTaskPaneContainer container;
065
066 private ImageIcon newIcon;
067
068 private String baseURI;
069 private Map<String, String> prefixes;
070
071 public StatsPanel(ORE ore, Individual ind){
072 super();
073 this.ore = ore;
074 this.modifier = ore.getModifier();
075 this.ind = ind;
076
077 }
078
079 /**
080 * Initializes the panel.
081 */
082 public void init(){
083 prefixes = ore.getPrefixes();
084 baseURI = ore.getBaseURI();
085
086 newIcon = new ImageIcon("src/dl-learner/org/dllearner/tools/ore/new.gif");
087
088 setLayout(new GridLayout());
089 setBackground(Color.WHITE);
090 setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
091
092
093 container = new JXTaskPaneContainer();
094
095
096
097 indPane = new JXTaskPane();
098 indPane.setTitle("Individual");
099 indPane.add(new JLabel(ind.toManchesterSyntaxString(baseURI, prefixes)));
100
101 classPane = new JXTaskPane();
102 classPane.setTitle("Classes");
103 oldClasses = ore.getOwlReasoner().getTypes(ind);
104 for(NamedClass nc : oldClasses){
105 classPane.add(new JLabel(nc.toManchesterSyntaxString(baseURI, prefixes)));
106 }
107 propertyPane = new JXTaskPane();
108 propertyPane.setTitle("Properties");
109
110 oldProperties = modifier.getObjectProperties(ind);
111 oldPropMap = new HashMap<String, Set<String>>();
112 for(ObjectPropertyAssertion ob : oldProperties){
113 String role = ob.getRole().toString(baseURI, prefixes);
114 String ind = ob.getIndividual2().toManchesterSyntaxString(baseURI, prefixes);
115 if(oldPropMap.containsKey(role)){
116 Set<String> oldSet = oldPropMap.get(role);
117 oldSet.add(ind);
118 oldPropMap.put(role, oldSet);
119 } else{
120 Set<String> newSet = new HashSet<String>();
121 newSet.add(ind);
122 oldPropMap.put(role, newSet);
123 }
124
125 }
126 for(String key : oldPropMap.keySet()){
127
128 JXTaskPane actionPane = new JXTaskPane();
129 actionPane.setTitle(key);
130 actionPane.setSpecial(true);
131 Set<String> value = (Set<String>) oldPropMap.get(key);
132 for(String i : value){
133 actionPane.add(new JLabel(i));
134 }
135 propertyPane.add(actionPane);
136 }
137
138
139 container.add(indPane);
140 container.add(classPane);
141 container.add(propertyPane);
142
143 add(container);
144
145
146 }
147
148 /**
149 * Updates the stats panel.
150 */
151 public void updatePanel(){
152
153 //update classesPanel
154 classPane.removeAll();
155
156 Set<String> newClassesString = new HashSet<String>();
157 for (NamedClass nc : ore.getOwlReasoner().getTypes(ind)){
158 newClassesString.add(nc.toManchesterSyntaxString(baseURI, prefixes));
159 }
160 Set<String> oldClassesString = new HashSet<String>();
161 for (NamedClass nc : oldClasses){
162 oldClassesString.add(nc.toManchesterSyntaxString(baseURI, prefixes));
163 }
164 for (String nc : oldClassesString){
165 if (!newClassesString.contains(nc)){
166 classPane.add(new JLabel("<html><strike>" + nc + "</strike></html>"));
167 } else{
168 classPane.add(new JLabel(nc));
169 }
170 }
171 for (String nc : newClassesString){
172 if (!oldClassesString.contains(nc)) {
173
174 JLabel lab = new JLabel(nc);
175 lab.setIcon(newIcon);
176 lab.setHorizontalTextPosition(JLabel.LEFT);
177 classPane.add(lab);
178 }
179 }
180
181 //update propertyPanel
182 propertyPane.removeAll();
183
184 Map<String, Set<String>> newPropMap = new HashMap<String, Set<String>>();
185 for(ObjectPropertyAssertion ob : modifier.getObjectProperties(ind)){
186 String role = ob.getRole().toString(baseURI, prefixes);
187 String ind = ob.getIndividual2().toManchesterSyntaxString(baseURI, prefixes);
188 if(newPropMap.containsKey(role)){
189 Set<String> oldSet = newPropMap.get(role);
190 oldSet.add(ind);
191 newPropMap.put(role, oldSet);
192 } else{
193 Set<String> newSet = new HashSet<String>();
194 newSet.add(ind);
195 newPropMap.put(role, newSet);
196 }
197
198 }
199
200 for(String key : oldPropMap.keySet()){
201 if (!newPropMap.keySet().contains(key)){
202 JXTaskPane actionPane = new JXTaskPane();
203 actionPane.setTitle("<html><strike>" + key + "</strike></html>");
204 actionPane.setSpecial(true);
205 Set<String> value = (Set<String>) oldPropMap.get(key);
206 for(String i : value){
207 actionPane.add(new JLabel("<html><strike>" + i + "</strike></html>"));
208 }
209 actionPane.setExpanded(false);
210 propertyPane.add(actionPane);
211 } else if(newPropMap.keySet().contains(key)){
212 JXTaskPane actionPane = new JXTaskPane();
213 actionPane.setTitle(key);
214 actionPane.setSpecial(true);
215 for(String value : oldPropMap.get(key)){
216 if(!newPropMap.get(key).contains(value)){
217 actionPane.add(new JLabel("<html><strike>" + value + "</strike></html>"));
218 } else{
219 actionPane.add(new JLabel(value));
220 }
221 }
222 for(String value : newPropMap.get(key)){
223 if(!oldPropMap.get(key).contains(value)){
224 JLabel newLab = new JLabel(value);
225 newLab.setIcon(newIcon);
226 newLab.setHorizontalTextPosition(JLabel.LEFT);
227 actionPane.add(newLab);
228 }
229 }
230 propertyPane.add(actionPane);
231 }
232 }
233 for(String key : newPropMap.keySet()){
234 if(!oldPropMap.keySet().contains(key)){
235 JXTaskPane actionPane = new JXTaskPane();
236 actionPane.setTitle(key);
237 actionPane.setSpecial(true);
238 // actionPane.setIcon(newIcon);
239 for(String value : newPropMap.get(key)){
240 JLabel newLab = new JLabel(value);
241 newLab.setIcon(newIcon);
242 newLab.setHorizontalTextPosition(JLabel.LEFT);
243 actionPane.add(newLab);
244 }
245 propertyPane.add(actionPane);
246 }
247
248 }
249
250
251
252 SwingUtilities.updateComponentTreeUI(this);
253
254 }
255 }