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.utilities.statistics;
021
022
023 import java.util.HashMap;
024 import java.util.LinkedList;
025
026
027 public class Statistics {
028
029 private static String currentLabel="";
030 private static LinkedList<String> order = new LinkedList<String>();
031 private static HashMap<String, Integer> numberOfTriples = new HashMap<String, Integer>();
032 private static HashMap<String, Long> timeCollecting = new HashMap<String, Long>();
033 private static HashMap<String, Long> timeLearning = new HashMap<String, Long>();
034 private static HashMap<String, Long> timeTotal = new HashMap<String, Long>();
035
036
037 private static HashMap<String, Integer> numberOfSparqlQueries = new HashMap<String, Integer>();
038 private static HashMap<String, Integer> numberOfCachedSparqlQueries = new HashMap<String, Integer>();
039
040
041 public static void addTriples(int value) {
042
043 Integer current = numberOfTriples.get(currentLabel);
044 if(current==null)
045 numberOfTriples.put(currentLabel, new Integer(value));
046 else {
047 numberOfTriples.put(currentLabel, new Integer(current.intValue()+value));
048 }
049
050
051
052 }
053
054 public static void addTimeCollecting(long value) {
055 addTimeTotal(value);
056 Long current = timeCollecting.get(currentLabel);
057 if(current==null)
058 timeCollecting.put(currentLabel, new Long(value));
059 else {
060 timeCollecting.put(currentLabel, new Long(current.longValue()+value));
061 }
062
063
064 }
065
066 public static void addTimeTotal(long value) {
067 Long current = timeTotal.get(currentLabel);
068 if(current==null)
069 timeTotal.put(currentLabel, new Long(value));
070 else {
071 timeTotal.put(currentLabel, new Long(current.longValue()+value));
072 }
073
074 }
075
076 public static void addTimeLearning(long value) {
077 addTimeTotal(value);
078
079 Long current = timeLearning.get(currentLabel);
080 if(current==null)
081 timeLearning.put(currentLabel, new Long(value));
082 else {
083 timeLearning.put(currentLabel, new Long(current.longValue()+value));
084 }
085 }
086
087 public static void increaseCachedQuery() {
088 Integer current = numberOfCachedSparqlQueries.get(currentLabel);
089 if(current==null)
090 numberOfCachedSparqlQueries.put(currentLabel, new Integer(1));
091 else {
092 numberOfCachedSparqlQueries.put(currentLabel, new Integer(current.intValue()+1));
093 }
094 }
095
096 public static void increaseQuery() {
097 Integer current = numberOfSparqlQueries.get(currentLabel);
098 if(current==null)
099 numberOfSparqlQueries.put(currentLabel, new Integer(1));
100 else {
101 numberOfSparqlQueries.put(currentLabel, new Integer(current.intValue()+1));
102 }
103 }
104
105
106 public static void print(int number){
107
108 System.out.println("*****************TRIPLES");
109 printInt(numberOfTriples,"triples\t");
110 printIntAVG(numberOfTriples,number,"triples avg\t");
111
112 System.out.println("*****************TIME");
113
114 printLong(timeCollecting, "collecting\t");
115 printLongAVG(timeCollecting,number,"collecting avg\t");
116 printLong(timeLearning, "learning\t");
117 printLongAVG(timeLearning,number,"learning avg\t");
118
119 System.out.println("*****************Queries");
120 printInt(numberOfCachedSparqlQueries,"cached queries\t");
121 printInt(numberOfSparqlQueries,"total queries\t");
122
123
124
125 //printIntAVG(numberOfTriples,number,"triples avg\t");
126
127
128
129
130
131
132
133 }
134
135
136 public static String getAVGTriplesForRecursionDepth(int number){
137
138 String ret="#Label, i.e. rec depth \t avg number of triples\n";
139 for (int i = 0; i < order.size(); i++) {
140 String label=order.get(i);
141 try {
142 ret+=label+"\t"+ (numberOfTriples.get(label).intValue()/number)+"\n";
143 } catch (Exception e) { }
144 }
145 return ret;
146 }
147
148 public static String getAVGTimeLearning(int number){
149
150 String ret="#Label, i.e. rec depth \t avg time for learning including reasoning\n";
151 for (int i = 0; i < order.size(); i++) {
152 String label=order.get(i);
153 try {
154 ret+=label+"\t"+ (timeLearning.get(label).longValue()/number)+"\n";
155 } catch (Exception e) { }
156 }
157 return ret;
158 }
159
160 public static String getAVGTimeCollecting(int number){
161
162 String ret="#Label, i.e. rec depth \t avg time for extraction\n";
163 for (int i = 0; i < order.size(); i++) {
164 String label=order.get(i);
165 try {
166 ret+=label+"\t"+ (timeCollecting.get(label).longValue()/number)+"\n";
167 } catch (Exception e) { }
168 }
169 return ret;
170 }
171
172 public static String getAVGtotalTime(int number){
173
174 String ret="#Label, i.e. rec depth \t avg total time \n";
175 for (int i = 0; i < order.size(); i++) {
176 String label=order.get(i);
177 try {
178 ret+=label+"\t"+ (timeTotal.get(label).longValue()/number)+"\n";
179 } catch (Exception e) { }
180 }
181 return ret;
182 }
183
184 public static void printIntAVG(HashMap<String, Integer> hm, int number, String str){
185 for (int i = 0; i < order.size(); i++) {
186 String label=order.get(i);
187 try {
188 System.out.println(str+""+label+"\t"+ (hm.get(label).intValue()/number));
189 } catch (Exception e) { }
190 }
191 }
192
193 public static void printInt(HashMap<String, Integer> hm, String str){
194 for (int i = 0; i < order.size(); i++) {
195 String label=order.get(i);
196 try {
197 System.out.println(str+""+label+"\t"+hm.get(label));
198 } catch (Exception e) { }
199 }
200 }
201
202 public static void printLongAVG(HashMap<String, Long> hm, int number, String str){
203 for (int i = 0; i < order.size(); i++) {
204 String label=order.get(i);
205 try {
206 System.out.println(str+label+"\t"+ (hm.get(label).intValue()/number));
207 } catch (Exception e) { }
208 }
209 }
210
211 public static void printLong(HashMap<String, Long> hm,String str){
212 for (int i = 0; i < order.size(); i++) {
213 String label=order.get(i);
214 try {
215 System.out.println(str+label+"\t"+hm.get(label));
216 } catch (Exception e) { }
217 }
218 }
219
220
221 public static void setCurrentLabel(String label) {
222 currentLabel=label;
223 if (!order.contains(label))order.add(label);
224 }
225
226 public static String getCurrentLabel() {
227 return currentLabel;
228 }
229
230 public static void reset(){
231 currentLabel="";
232 order = new LinkedList<String>();
233 numberOfTriples = new HashMap<String, Integer>();
234 timeCollecting = new HashMap<String, Long>();
235 timeLearning = new HashMap<String, Long>();
236 timeTotal = new HashMap<String, Long>();
237
238 numberOfSparqlQueries = new HashMap<String, Integer>();
239 numberOfCachedSparqlQueries = new HashMap<String, Integer>();
240 System.out.println("xxxRESET");
241
242 }
243
244 //stats
245
246
247
248
249
250
251
252
253 }