Mercurial > hg > openmind
annotate src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java @ 82:90f9a1c45b15
small change to xml format.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 10 Jul 2017 17:15:34 +0200 |
parents | b0aebac0780a |
children | d4b456623d43 |
rev | line source |
---|---|
1 | 1 package org.mpi.openmind.repository.utils; |
2 | |
3 import java.io.FileOutputStream; | |
4 import java.io.IOException; | |
5 import java.io.OutputStreamWriter; | |
6 import java.text.DecimalFormat; | |
7 import java.util.ArrayList; | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
8 import java.util.HashMap; |
1 | 9 import java.util.List; |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
10 import java.util.Map; |
1 | 11 |
29 | 12 import javax.xml.stream.XMLOutputFactory; |
13 import javax.xml.stream.XMLStreamException; | |
14 import javax.xml.stream.XMLStreamWriter; | |
1 | 15 |
16 import org.apache.commons.lang.StringUtils; | |
17 import org.apache.log4j.Logger; | |
18 import org.mpi.openmind.repository.bo.Attribute; | |
19 import org.mpi.openmind.repository.bo.Entity; | |
20 import org.mpi.openmind.repository.bo.Node; | |
21 import org.mpi.openmind.repository.bo.Relation; | |
22 import org.mpi.openmind.repository.services.PersistenceService; | |
23 | |
31 | 24 /** |
25 * Export all entities and relations and definitions to XML. | |
26 * | |
75 | 27 * Saves (content) entities and relations (i.e. assertions) and definitions |
31 | 28 * (i.e. definition entities and relations) in separate files. |
29 * | |
30 * @author jurzua, casties | |
31 * | |
32 */ | |
1 | 33 public class OM4StreamWriter { |
34 | |
29 | 35 private static Logger logger = Logger.getLogger(OM4StreamWriter.class); |
36 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
37 private static final int itemsPerPage = 500; |
77 | 38 |
39 /** Include normalized own-values. */ | |
78 | 40 public static boolean includeNormalizations = true; |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
41 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
42 /** key for entity count in attribute counts map */ |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
43 private static final String ENT_KEY = "<entity-count>"; |
29 | 44 |
45 /** | |
46 * Return the object's string representation or "null" if its null. | |
47 * | |
48 * @param s | |
49 * @return | |
50 */ | |
31 | 51 private static String defaultString(Object s) { |
29 | 52 if (s == null) { |
53 return "null"; | |
54 } else { | |
55 return s.toString(); | |
56 } | |
57 } | |
58 | |
59 | |
75 | 60 /** |
61 * Saves all content Entities with their Attributes and Relations in a XML file with the given fileName. | |
62 * | |
63 * @param fileName | |
64 * @param ps | |
65 */ | |
29 | 66 public static void backupEntities(String fileName, PersistenceService ps) { |
78 | 67 writeEntsAndRels(fileName, ps, Node.TYPE_ABOX, includeNormalizations); |
29 | 68 } |
69 | |
75 | 70 /** |
71 * Saves all definitions in a XML file with the given fileName. | |
72 * | |
73 * @param fileName | |
74 * @param ps | |
75 */ | |
29 | 76 public static void backupDefinitions(String fileName, PersistenceService ps) { |
78 | 77 writeEntsAndRels(fileName, ps, Node.TYPE_TBOX, false); |
29 | 78 } |
79 | |
80 /** | |
81 * Writes all entities of the given type and their relations to the XML file at fileName. | |
82 * | |
75 | 83 * Type is either TYPE_TBOX or TYPE_ABOX. |
84 * | |
29 | 85 * @param fileName |
86 * @param ps | |
75 | 87 * @param type |
29 | 88 */ |
78 | 89 private static void writeEntsAndRels(String fileName, PersistenceService ps, String type, boolean includeNorm) { |
29 | 90 OutputStreamWriter out; |
91 try { | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
92 // statistics collection Maps |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
93 Map<String, Map<String, Long>> entStats = new HashMap<String, Map<String, Long>>(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
94 Map<String, Map<String, Long>> relStats = new HashMap<String, Map<String, Long>>(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
95 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
96 // setup xml writer |
29 | 97 FileOutputStream fileOut = new FileOutputStream(fileName); |
98 out = new OutputStreamWriter(fileOut, "UTF-8"); | |
99 XMLOutputFactory factory = XMLOutputFactory.newInstance(); | |
100 XMLStreamWriter writer = factory.createXMLStreamWriter(out); | |
101 | |
102 int entitiesCount = 0; | |
103 | |
104 writer.writeStartDocument("UTF-8", "1.0"); | |
105 | |
106 if (type.equals(Node.TYPE_ABOX)) { | |
107 writer.writeStartElement(XMLUtil.OPENMIND_DATA); | |
82
90f9a1c45b15
small change to xml format.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
79
diff
changeset
|
108 writer.writeAttribute("version", "4.6"); |
75 | 109 // get number of content Entities |
29 | 110 entitiesCount = ps.getEntityCount(null).intValue(); |
111 } else { | |
112 writer.writeStartElement(XMLUtil.META_DATA); | |
82
90f9a1c45b15
small change to xml format.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
79
diff
changeset
|
113 writer.writeAttribute("version", "4.6"); |
75 | 114 // get number of definition Entities |
29 | 115 entitiesCount = ps.getEntityCount(Node.TYPE_TBOX).intValue(); |
116 } | |
117 | |
118 int numberOfPages = entitiesCount / itemsPerPage; | |
119 // debug: int numberOfPages = 1; | |
120 int counter = 0; | |
121 long start = System.currentTimeMillis(); | |
122 DecimalFormat df = new DecimalFormat("#.##"); | |
1 | 123 |
75 | 124 // list of Relations (filled from Entities) |
29 | 125 List<Relation> relList = new ArrayList<Relation>(); |
126 | |
127 /* | |
128 * write entities | |
129 */ | |
130 writer.writeStartElement((type.equals(Node.TYPE_TBOX)) ? XMLUtil.DEFINITIONS : XMLUtil.ENTITIES); | |
82
90f9a1c45b15
small change to xml format.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
79
diff
changeset
|
131 writer.writeAttribute("count", Integer.toString(entitiesCount)); |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
132 // iterate database by pages |
29 | 133 for (int currentPage = 0; currentPage <= numberOfPages; currentPage++) { |
134 int startRecord = currentPage * itemsPerPage; | |
135 List<Entity> entities; | |
136 | |
137 if (type.equals(Node.TYPE_ABOX)) { | |
75 | 138 // get page of content Entities |
29 | 139 entities = ps.getEntityPage(null, startRecord, itemsPerPage); |
140 } else { | |
75 | 141 // get page of definition Entities |
29 | 142 entities = ps.getEntityPage(Node.TYPE_TBOX, startRecord, itemsPerPage); |
143 } | |
144 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
145 // iterate entities |
29 | 146 for (Entity ent : entities) { |
75 | 147 // write entity to XML |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
148 writeEntity(ent, writer, ps, includeNorm, entStats); |
29 | 149 // add (source)relations to list |
150 relList.addAll(ent.getSourceRelations()); | |
151 | |
152 counter++; | |
153 } | |
154 | |
155 long runtime = System.currentTimeMillis() - start; | |
156 double percent = ((double) counter / (double) entitiesCount) * 100.0; | |
157 logger.debug("(" + df.format(percent) + "%) \t[" + counter + "/" + entitiesCount + "]\t"); | |
158 logger.debug("Speed[ents/s]: " + df.format((double) counter / ((double) runtime / 1000))); | |
159 writer.flush(); | |
160 } | |
161 writer.writeEndElement(); | |
162 | |
163 /* | |
164 * write relations (from list) | |
165 */ | |
166 writer.writeStartElement(XMLUtil.RELATIONS); | |
82
90f9a1c45b15
small change to xml format.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
79
diff
changeset
|
167 writer.writeAttribute("count", Integer.toString(relList.size())); |
29 | 168 for (Relation rel : relList) { |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
169 writeRelation(rel, writer, includeNorm, relStats); |
29 | 170 } |
171 writer.writeEndElement(); | |
172 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
173 /* |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
174 * write statistics |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
175 */ |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
176 // entity stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
177 writeStats(XMLUtil.ENTITY_STATS, XMLUtil.ENTITY, entStats, writer); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
178 // relation stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
179 writeStats(XMLUtil.RELATION_STATS, XMLUtil.RELATION, relStats, writer); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
180 |
29 | 181 // end file. |
182 writer.writeEndElement(); | |
183 | |
184 writer.flush(); | |
185 writer.close(); | |
186 | |
187 logger.info("END Stream Writer"); | |
188 } catch (IOException e) { | |
75 | 189 logger.error(e); |
29 | 190 } catch (XMLStreamException e) { |
75 | 191 logger.error(e); |
29 | 192 } |
193 } | |
1 | 194 |
29 | 195 /** |
196 * Write OpenMind relation to XML. | |
197 * | |
198 * @param rel | |
199 * @param writer | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
200 * @param relStats |
29 | 201 * @throws XMLStreamException |
202 */ | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
203 private static void writeRelation(Relation rel, XMLStreamWriter writer, boolean includeNorm, |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
204 Map<String, Map<String, Long>> relStats) throws XMLStreamException { |
29 | 205 writer.writeStartElement(XMLUtil.RELATION); |
206 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
207 // update stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
208 Map<String, Long> attStats = updateNodeStats(rel, relStats); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
209 |
29 | 210 /* |
211 * write XML-attributes | |
212 */ | |
213 writer.writeAttribute(XMLUtil.OBJECT_CLASS, defaultString(rel.getObjectClass())); | |
214 writer.writeAttribute(XMLUtil.ID, defaultString(rel.getId())); | |
215 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(rel.getRowId())); | |
75 | 216 if (StringUtils.isNotEmpty(rel.getContentType())) { |
29 | 217 writer.writeAttribute(XMLUtil.CONTENT_TYPE, rel.getContentType()); |
75 | 218 } |
29 | 219 writer.writeAttribute(XMLUtil.RELATION_SOURCE_ID, defaultString(rel.getSourceId())); |
220 writer.writeAttribute(XMLUtil.RELATION_TARGET_ID, defaultString(rel.getTargetId())); | |
221 writer.writeAttribute(XMLUtil.VERSION, defaultString(rel.getVersion())); | |
222 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(rel.getModificationTime())); | |
75 | 223 if (rel.getUser() != null) { |
29 | 224 writer.writeAttribute(XMLUtil.USER, rel.getUser()); |
75 | 225 } |
226 if (rel.getIsPublic()) { | |
29 | 227 writer.writeAttribute(XMLUtil.PUBLIC, "true"); |
75 | 228 } |
29 | 229 |
230 /* | |
231 * write OpenMind attributes of this relation as XML tags | |
232 */ | |
233 if (rel.getAttributes().size() > 0) { | |
234 writer.writeStartElement(XMLUtil.ATTRIBUTES); | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
235 for (Attribute att : rel.getAttributes()) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
236 // update stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
237 updateAttStats(att, attStats); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
238 // write xml |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
239 writeAttribute(att, writer, includeNorm); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
240 } |
29 | 241 writer.writeEndElement(); |
242 } | |
1 | 243 |
29 | 244 /* |
245 * write own value as content | |
246 */ | |
75 | 247 if (StringUtils.isNotEmpty(rel.getOwnValue())) { |
29 | 248 writer.writeCharacters(rel.getOwnValue()); |
75 | 249 } |
29 | 250 |
251 writer.writeEndElement(); | |
252 } | |
253 | |
254 /** | |
255 * Write OpenMind entity to XML. | |
256 * | |
257 * @param entity | |
258 * @param writer | |
259 * @param ps | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
260 * @param entStats |
29 | 261 * @throws XMLStreamException |
262 */ | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
263 private static void writeEntity(Entity entity, XMLStreamWriter writer, PersistenceService ps, boolean includeNorm, |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
264 Map<String, Map<String, Long>> entStats) |
29 | 265 throws XMLStreamException { |
1 | 266 |
29 | 267 writer.writeStartElement((entity.getType().equals(Node.TYPE_TBOX)) ? XMLUtil.DEFINITION : XMLUtil.ENTITY); |
268 | |
269 if (entity.isLightweight()) { | |
270 entity = ps.getEntityContent(entity); | |
271 } | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
272 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
273 // update stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
274 Map<String, Long> attStats = updateNodeStats(entity, entStats); |
29 | 275 |
276 /* | |
277 * write XML attributes | |
278 */ | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
279 writer.writeAttribute(XMLUtil.OBJECT_CLASS, defaultString(entity.getObjectClass())); |
29 | 280 writer.writeAttribute(XMLUtil.ID, defaultString(entity.getId())); |
281 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(entity.getRowId())); | |
75 | 282 if (StringUtils.isNotEmpty(entity.getContentType())) { |
29 | 283 writer.writeAttribute(XMLUtil.CONTENT_TYPE, entity.getContentType()); |
75 | 284 } |
29 | 285 writer.writeAttribute(XMLUtil.VERSION, defaultString(entity.getVersion())); |
286 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(entity.getModificationTime())); | |
75 | 287 if (entity.getUser() != null) { |
29 | 288 writer.writeAttribute(XMLUtil.USER, entity.getUser()); |
75 | 289 } |
290 if (entity.getIsPublic()) { | |
29 | 291 writer.writeAttribute(XMLUtil.PUBLIC, "true"); |
75 | 292 } |
1 | 293 |
29 | 294 /* |
295 * write OpenMind attributes of this entity as XML tags | |
296 */ | |
297 if (entity.getAttributes().size() > 0) { | |
298 writer.writeStartElement(XMLUtil.ATTRIBUTES); | |
299 for (Attribute att : entity.getAttributes()) { | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
300 // update stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
301 updateAttStats(att, attStats); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
302 // write xml |
78 | 303 writeAttribute(att, writer, includeNorm); |
29 | 304 } |
305 writer.writeEndElement(); | |
306 } | |
307 | |
308 /* | |
309 * write own value | |
310 */ | |
77 | 311 String ov = entity.getOwnValue(); |
312 if (StringUtils.isNotEmpty(ov)) { | |
313 writer.writeCharacters(ov); | |
314 String nov = entity.getNormalizedOwnValue(); | |
315 if (includeNorm && StringUtils.isNotEmpty(nov) && !ov.equals(nov)) { | |
316 // write normalized value | |
317 writer.writeStartElement(XMLUtil.NORMALIZED); | |
318 writer.writeCharacters(nov); | |
319 writer.writeEndElement(); | |
320 } | |
75 | 321 } |
29 | 322 |
323 writer.writeEndElement(); | |
324 } | |
325 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
326 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
327 private static void writeAttribute(Attribute att, XMLStreamWriter writer, boolean includeNorm) throws XMLStreamException { |
29 | 328 writer.writeStartElement(XMLUtil.ATTRIBUTE); |
329 | |
330 /* | |
331 * write XML attributes | |
332 */ | |
333 writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, defaultString(att.getName())); | |
334 writer.writeAttribute(XMLUtil.ID, defaultString(att.getId())); | |
335 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(att.getRowId())); | |
336 writer.writeAttribute(XMLUtil.CONTENT_TYPE, defaultString(att.getContentType())); | |
337 writer.writeAttribute(XMLUtil.VERSION, defaultString(att.getVersion())); | |
338 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(att.getModificationTime())); | |
75 | 339 if (att.getUser() != null) { |
29 | 340 writer.writeAttribute(XMLUtil.USER, att.getUser()); |
75 | 341 } |
342 if (att.getIsPublic()) { | |
29 | 343 writer.writeAttribute(XMLUtil.PUBLIC, "true"); |
75 | 344 } |
345 | |
29 | 346 /* |
347 * write value as content | |
348 */ | |
77 | 349 String ov = att.getValue(); |
350 if (StringUtils.isNotEmpty(ov)) { | |
351 writer.writeCharacters(ov); | |
352 String nov = att.getNormalizedOwnValue(); | |
353 if (includeNorm && StringUtils.isNotEmpty(nov) && !ov.equals(nov)) { | |
354 // write normalized value | |
355 writer.writeStartElement(XMLUtil.NORMALIZED); | |
356 writer.writeCharacters(nov); | |
357 writer.writeEndElement(); | |
358 } | |
75 | 359 } |
1 | 360 |
29 | 361 writer.writeEndElement(); |
362 } | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
363 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
364 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
365 private static void writeStats(String statsTag, String entryTag, Map<String, Map<String, Long>> nodeStats, XMLStreamWriter writer) |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
366 throws XMLStreamException { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
367 // write stats tag |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
368 writer.writeStartElement(statsTag); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
369 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
370 for (String nodeType : nodeStats.keySet()) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
371 Map<String, Long> attStats = nodeStats.get(nodeType); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
372 Long nodeCnt = attStats.get(ENT_KEY); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
373 // write tag for entity/attribute |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
374 writer.writeStartElement(entryTag); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
375 writer.writeAttribute(XMLUtil.OBJECT_CLASS, (nodeType == null)?"null":nodeType); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
376 writer.writeAttribute(XMLUtil.COUNT, nodeCnt.toString()); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
377 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
378 // write attributes |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
379 for (String attName : attStats.keySet()) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
380 // skip ENT_KEY |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
381 if (attName.equals(ENT_KEY)) continue; |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
382 // write attribute tag |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
383 writer.writeStartElement(XMLUtil.ATTRIBUTE); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
384 writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, attName); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
385 Long attCnt = attStats.get(attName); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
386 writer.writeAttribute(XMLUtil.COUNT, attCnt.toString()); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
387 writer.writeEndElement(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
388 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
389 // end of entity/attribute tag |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
390 writer.writeEndElement(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
391 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
392 // end of stats tag |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
393 writer.writeEndElement(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
394 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
395 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
396 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
397 /** |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
398 * @param objectClass |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
399 * @param entStats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
400 * @return |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
401 */ |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
402 protected static Map<String, Long> updateNodeStats(Node ent, Map<String, Map<String, Long>> entStats) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
403 String objectClass = ent.getObjectClass(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
404 Map<String, Long> attStats = entStats.get(objectClass); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
405 if (attStats == null) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
406 // create new attribute stats entry |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
407 attStats = new HashMap<String, Long>(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
408 // add key to count entities |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
409 attStats.put(ENT_KEY, 1l); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
410 // add to map |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
411 entStats.put(objectClass, attStats); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
412 } else { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
413 // increment entity count |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
414 Long entCnt = attStats.get(ENT_KEY); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
415 attStats.put(ENT_KEY, entCnt + 1); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
416 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
417 return attStats; |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
418 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
419 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
420 /** |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
421 * @param att |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
422 * @param attStats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
423 */ |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
424 protected static void updateAttStats(Attribute att, Map<String, Long> attStats) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
425 String attName = att.getName(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
426 Long cnt = attStats.get(attName); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
427 if (cnt == null) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
428 attStats.put(attName, 1l); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
429 } else { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
430 attStats.put(attName, cnt + 1); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
431 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
432 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
433 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
434 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
435 |
1 | 436 } |