Mercurial > hg > openmind
annotate src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java @ 103:1149eb948036
add isodate tag to XML dump format 4.9.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 14 Nov 2018 18:31:55 +0100 |
parents | 734c0d8c7369 |
children | 93c7dbfaf062 |
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; | |
103
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
18 import org.joda.time.DateTime; |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
19 import org.joda.time.format.DateTimeFormatter; |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
20 import org.joda.time.format.ISODateTimeFormat; |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
21 import org.json.JSONException; |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
22 import org.json.JSONObject; |
1 | 23 import org.mpi.openmind.repository.bo.Attribute; |
24 import org.mpi.openmind.repository.bo.Entity; | |
25 import org.mpi.openmind.repository.bo.Node; | |
26 import org.mpi.openmind.repository.bo.Relation; | |
27 import org.mpi.openmind.repository.services.PersistenceService; | |
28 | |
31 | 29 /** |
30 * Export all entities and relations and definitions to XML. | |
31 * | |
75 | 32 * Saves (content) entities and relations (i.e. assertions) and definitions |
31 | 33 * (i.e. definition entities and relations) in separate files. |
34 * | |
35 * @author jurzua, casties | |
36 * | |
37 */ | |
1 | 38 public class OM4StreamWriter { |
39 | |
103
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
40 protected static final String FORMAT_VERSION = "4.9"; |
87
8005f7011975
update version number in xml.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
86
diff
changeset
|
41 |
29 | 42 private static Logger logger = Logger.getLogger(OM4StreamWriter.class); |
43 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
44 private static final int itemsPerPage = 500; |
77 | 45 |
46 /** Include normalized own-values. */ | |
78 | 47 public static boolean includeNormalizations = true; |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
48 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
49 /** 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
|
50 private static final String ENT_KEY = "<entity-count>"; |
29 | 51 |
103
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
52 /** formatter for isodate tag */ |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
53 public static DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
54 |
29 | 55 /** |
56 * Return the object's string representation or "null" if its null. | |
57 * | |
58 * @param s | |
59 * @return | |
60 */ | |
31 | 61 private static String defaultString(Object s) { |
29 | 62 if (s == null) { |
63 return "null"; | |
64 } else { | |
65 return s.toString(); | |
66 } | |
67 } | |
68 | |
69 | |
75 | 70 /** |
71 * Saves all content Entities with their Attributes and Relations in a XML file with the given fileName. | |
72 * | |
73 * @param fileName | |
74 * @param ps | |
75 */ | |
29 | 76 public static void backupEntities(String fileName, PersistenceService ps) { |
78 | 77 writeEntsAndRels(fileName, ps, Node.TYPE_ABOX, includeNormalizations); |
29 | 78 } |
79 | |
75 | 80 /** |
81 * Saves all definitions in a XML file with the given fileName. | |
82 * | |
83 * @param fileName | |
84 * @param ps | |
85 */ | |
29 | 86 public static void backupDefinitions(String fileName, PersistenceService ps) { |
78 | 87 writeEntsAndRels(fileName, ps, Node.TYPE_TBOX, false); |
29 | 88 } |
89 | |
90 /** | |
91 * Writes all entities of the given type and their relations to the XML file at fileName. | |
92 * | |
75 | 93 * Type is either TYPE_TBOX or TYPE_ABOX. |
94 * | |
29 | 95 * @param fileName |
96 * @param ps | |
75 | 97 * @param type |
29 | 98 */ |
78 | 99 private static void writeEntsAndRels(String fileName, PersistenceService ps, String type, boolean includeNorm) { |
29 | 100 OutputStreamWriter out; |
101 try { | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
102 // statistics collection Maps |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
103 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
|
104 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
|
105 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
106 // setup xml writer |
29 | 107 FileOutputStream fileOut = new FileOutputStream(fileName); |
108 out = new OutputStreamWriter(fileOut, "UTF-8"); | |
109 XMLOutputFactory factory = XMLOutputFactory.newInstance(); | |
110 XMLStreamWriter writer = factory.createXMLStreamWriter(out); | |
111 | |
112 int entitiesCount = 0; | |
113 | |
114 writer.writeStartDocument("UTF-8", "1.0"); | |
115 | |
116 if (type.equals(Node.TYPE_ABOX)) { | |
117 writer.writeStartElement(XMLUtil.OPENMIND_DATA); | |
87
8005f7011975
update version number in xml.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
86
diff
changeset
|
118 writer.writeAttribute("version", FORMAT_VERSION); |
75 | 119 // get number of content Entities |
29 | 120 entitiesCount = ps.getEntityCount(null).intValue(); |
121 } else { | |
122 writer.writeStartElement(XMLUtil.META_DATA); | |
87
8005f7011975
update version number in xml.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
86
diff
changeset
|
123 writer.writeAttribute("version", FORMAT_VERSION); |
75 | 124 // get number of definition Entities |
29 | 125 entitiesCount = ps.getEntityCount(Node.TYPE_TBOX).intValue(); |
126 } | |
127 | |
128 int numberOfPages = entitiesCount / itemsPerPage; | |
129 // debug: int numberOfPages = 1; | |
130 int counter = 0; | |
131 long start = System.currentTimeMillis(); | |
132 DecimalFormat df = new DecimalFormat("#.##"); | |
1 | 133 |
75 | 134 // list of Relations (filled from Entities) |
29 | 135 List<Relation> relList = new ArrayList<Relation>(); |
136 | |
137 /* | |
138 * write entities | |
139 */ | |
140 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
|
141 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
|
142 // iterate database by pages |
29 | 143 for (int currentPage = 0; currentPage <= numberOfPages; currentPage++) { |
144 int startRecord = currentPage * itemsPerPage; | |
145 List<Entity> entities; | |
146 | |
147 if (type.equals(Node.TYPE_ABOX)) { | |
75 | 148 // get page of content Entities |
29 | 149 entities = ps.getEntityPage(null, startRecord, itemsPerPage); |
150 } else { | |
75 | 151 // get page of definition Entities |
29 | 152 entities = ps.getEntityPage(Node.TYPE_TBOX, startRecord, itemsPerPage); |
153 } | |
154 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
155 // iterate entities |
29 | 156 for (Entity ent : entities) { |
75 | 157 // write entity to XML |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
158 writeEntity(ent, writer, ps, includeNorm, entStats); |
29 | 159 // add (source)relations to list |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
160 List<Relation> rels = ent.getSourceRelations(); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
161 relList.addAll(rels); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
162 // update stats for relations |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
163 Map<String, Long> entRelStats = entStats.get(ent.getObjectClass()); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
164 for (Relation rel: rels) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
165 // update source relations |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
166 updateRelStats(rel, true, entRelStats); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
167 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
168 for (Relation rel: ent.getTargetRelations()) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
169 // update target relations |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
170 updateRelStats(rel, false, entRelStats); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
171 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
172 // count entities |
29 | 173 counter++; |
174 } | |
175 | |
176 long runtime = System.currentTimeMillis() - start; | |
177 double percent = ((double) counter / (double) entitiesCount) * 100.0; | |
178 logger.debug("(" + df.format(percent) + "%) \t[" + counter + "/" + entitiesCount + "]\t"); | |
179 logger.debug("Speed[ents/s]: " + df.format((double) counter / ((double) runtime / 1000))); | |
180 writer.flush(); | |
181 } | |
182 writer.writeEndElement(); | |
183 | |
184 /* | |
185 * write relations (from list) | |
186 */ | |
187 writer.writeStartElement(XMLUtil.RELATIONS); | |
82
90f9a1c45b15
small change to xml format.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
79
diff
changeset
|
188 writer.writeAttribute("count", Integer.toString(relList.size())); |
29 | 189 for (Relation rel : relList) { |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
190 writeRelation(rel, writer, includeNorm, relStats); |
29 | 191 } |
192 writer.writeEndElement(); | |
193 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
194 /* |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
195 * write statistics |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
196 */ |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
197 // entity stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
198 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
|
199 // relation stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
200 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
|
201 |
29 | 202 // end file. |
203 writer.writeEndElement(); | |
204 | |
205 writer.flush(); | |
206 writer.close(); | |
207 | |
208 logger.info("END Stream Writer"); | |
209 } catch (IOException e) { | |
75 | 210 logger.error(e); |
29 | 211 } catch (XMLStreamException e) { |
75 | 212 logger.error(e); |
29 | 213 } |
214 } | |
1 | 215 |
29 | 216 /** |
217 * Write OpenMind relation to XML. | |
218 * | |
219 * @param rel | |
220 * @param writer | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
221 * @param relStats |
29 | 222 * @throws XMLStreamException |
223 */ | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
224 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
|
225 Map<String, Map<String, Long>> relStats) throws XMLStreamException { |
29 | 226 writer.writeStartElement(XMLUtil.RELATION); |
227 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
228 // update stats |
100
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
229 Map<String, Long> attStats = null; |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
230 if (relStats != null) { |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
231 attStats = updateNodeStats(rel, relStats); |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
232 } |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
233 |
29 | 234 /* |
235 * write XML-attributes | |
236 */ | |
237 writer.writeAttribute(XMLUtil.OBJECT_CLASS, defaultString(rel.getObjectClass())); | |
238 writer.writeAttribute(XMLUtil.ID, defaultString(rel.getId())); | |
239 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(rel.getRowId())); | |
75 | 240 if (StringUtils.isNotEmpty(rel.getContentType())) { |
29 | 241 writer.writeAttribute(XMLUtil.CONTENT_TYPE, rel.getContentType()); |
75 | 242 } |
29 | 243 writer.writeAttribute(XMLUtil.RELATION_SOURCE_ID, defaultString(rel.getSourceId())); |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
244 writer.writeAttribute(XMLUtil.RELATION_SOURCE, defaultString(rel.getSourceObjectClass())); |
29 | 245 writer.writeAttribute(XMLUtil.RELATION_TARGET_ID, defaultString(rel.getTargetId())); |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
246 writer.writeAttribute(XMLUtil.RELATION_TARGET, defaultString(rel.getTargetObjectClass())); |
29 | 247 writer.writeAttribute(XMLUtil.VERSION, defaultString(rel.getVersion())); |
248 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(rel.getModificationTime())); | |
75 | 249 if (rel.getUser() != null) { |
29 | 250 writer.writeAttribute(XMLUtil.USER, rel.getUser()); |
75 | 251 } |
252 if (rel.getIsPublic()) { | |
29 | 253 writer.writeAttribute(XMLUtil.PUBLIC, "true"); |
75 | 254 } |
29 | 255 |
256 /* | |
257 * write OpenMind attributes of this relation as XML tags | |
258 */ | |
259 if (rel.getAttributes().size() > 0) { | |
260 writer.writeStartElement(XMLUtil.ATTRIBUTES); | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
261 for (Attribute att : rel.getAttributes()) { |
100
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
262 if (attStats != null) { |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
263 // update stats |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
264 updateAttStats(att, attStats); |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
265 } |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
266 // write xml |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
267 writeAttribute(att, writer, includeNorm); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
268 } |
29 | 269 writer.writeEndElement(); |
270 } | |
1 | 271 |
29 | 272 /* |
273 * write own value as content | |
274 */ | |
75 | 275 if (StringUtils.isNotEmpty(rel.getOwnValue())) { |
29 | 276 writer.writeCharacters(rel.getOwnValue()); |
75 | 277 } |
29 | 278 |
279 writer.writeEndElement(); | |
280 } | |
281 | |
282 /** | |
283 * Write OpenMind entity to XML. | |
284 * | |
285 * @param entity | |
286 * @param writer | |
287 * @param ps | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
288 * @param entStats |
29 | 289 * @throws XMLStreamException |
290 */ | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
291 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
|
292 Map<String, Map<String, Long>> entStats) |
29 | 293 throws XMLStreamException { |
1 | 294 |
29 | 295 writer.writeStartElement((entity.getType().equals(Node.TYPE_TBOX)) ? XMLUtil.DEFINITION : XMLUtil.ENTITY); |
296 | |
297 if (entity.isLightweight()) { | |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
298 // make sure we have all attributes and relations |
29 | 299 entity = ps.getEntityContent(entity); |
300 } | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
301 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
302 // update stats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
303 Map<String, Long> attStats = updateNodeStats(entity, entStats); |
29 | 304 |
305 /* | |
306 * write XML attributes | |
307 */ | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
308 writer.writeAttribute(XMLUtil.OBJECT_CLASS, defaultString(entity.getObjectClass())); |
29 | 309 writer.writeAttribute(XMLUtil.ID, defaultString(entity.getId())); |
310 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(entity.getRowId())); | |
75 | 311 if (StringUtils.isNotEmpty(entity.getContentType())) { |
29 | 312 writer.writeAttribute(XMLUtil.CONTENT_TYPE, entity.getContentType()); |
75 | 313 } |
29 | 314 writer.writeAttribute(XMLUtil.VERSION, defaultString(entity.getVersion())); |
315 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(entity.getModificationTime())); | |
75 | 316 if (entity.getUser() != null) { |
29 | 317 writer.writeAttribute(XMLUtil.USER, entity.getUser()); |
75 | 318 } |
319 if (entity.getIsPublic()) { | |
29 | 320 writer.writeAttribute(XMLUtil.PUBLIC, "true"); |
75 | 321 } |
1 | 322 |
29 | 323 /* |
324 * write OpenMind attributes of this entity as XML tags | |
325 */ | |
326 if (entity.getAttributes().size() > 0) { | |
327 writer.writeStartElement(XMLUtil.ATTRIBUTES); | |
328 for (Attribute att : entity.getAttributes()) { | |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
329 // update stats |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
330 updateAttStats(att, attStats); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
331 // write xml |
78 | 332 writeAttribute(att, writer, includeNorm); |
29 | 333 } |
334 writer.writeEndElement(); | |
335 } | |
336 | |
337 /* | |
100
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
338 * write outgoing relations of this entity as XML tags |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
339 */ |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
340 if (entity.getSourceRelations().size() > 0) { |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
341 writer.writeStartElement(XMLUtil.RELATIONS); |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
342 for (Relation rel : entity.getSourceRelations()) { |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
343 // write xml (without stats) |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
344 writeRelation(rel, writer, includeNorm, null); |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
345 } |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
346 writer.writeEndElement(); |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
347 } |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
348 |
734c0d8c7369
add relations-tag with source relations for each entity to XML dump format 4.8.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
87
diff
changeset
|
349 /* |
29 | 350 * write own value |
351 */ | |
77 | 352 String ov = entity.getOwnValue(); |
353 if (StringUtils.isNotEmpty(ov)) { | |
354 writer.writeCharacters(ov); | |
355 String nov = entity.getNormalizedOwnValue(); | |
356 if (includeNorm && StringUtils.isNotEmpty(nov) && !ov.equals(nov)) { | |
357 // write normalized value | |
358 writer.writeStartElement(XMLUtil.NORMALIZED); | |
359 writer.writeCharacters(nov); | |
360 writer.writeEndElement(); | |
361 } | |
75 | 362 } |
29 | 363 |
364 writer.writeEndElement(); | |
365 } | |
366 | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
367 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
368 private static void writeAttribute(Attribute att, XMLStreamWriter writer, boolean includeNorm) throws XMLStreamException { |
29 | 369 writer.writeStartElement(XMLUtil.ATTRIBUTE); |
370 | |
371 /* | |
372 * write XML attributes | |
373 */ | |
374 writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, defaultString(att.getName())); | |
375 writer.writeAttribute(XMLUtil.ID, defaultString(att.getId())); | |
376 writer.writeAttribute(XMLUtil.ROW_ID, defaultString(att.getRowId())); | |
377 writer.writeAttribute(XMLUtil.CONTENT_TYPE, defaultString(att.getContentType())); | |
378 writer.writeAttribute(XMLUtil.VERSION, defaultString(att.getVersion())); | |
379 writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(att.getModificationTime())); | |
75 | 380 if (att.getUser() != null) { |
29 | 381 writer.writeAttribute(XMLUtil.USER, att.getUser()); |
75 | 382 } |
383 if (att.getIsPublic()) { | |
29 | 384 writer.writeAttribute(XMLUtil.PUBLIC, "true"); |
75 | 385 } |
386 | |
29 | 387 /* |
388 * write value as content | |
389 */ | |
77 | 390 String ov = att.getValue(); |
391 if (StringUtils.isNotEmpty(ov)) { | |
392 writer.writeCharacters(ov); | |
393 String nov = att.getNormalizedOwnValue(); | |
394 if (includeNorm && StringUtils.isNotEmpty(nov) && !ov.equals(nov)) { | |
395 // write normalized value | |
396 writer.writeStartElement(XMLUtil.NORMALIZED); | |
397 writer.writeCharacters(nov); | |
398 writer.writeEndElement(); | |
399 } | |
103
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
400 // convert date JSON into additional isodate |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
401 if (ov.startsWith("{")) { |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
402 try { |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
403 JSONObject json = new JSONObject(ov); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
404 JSONObject date = null; |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
405 if (json.has("date")) { |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
406 date = json.getJSONObject("date"); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
407 } else if (json.has("from")) { |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
408 date = json.getJSONObject("from"); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
409 } |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
410 if (date != null) { |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
411 int year = date.getInt("year"); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
412 int month = date.getInt("month"); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
413 int day = date.getInt("dayOfMonth"); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
414 DateTime dt = new DateTime(year, month, day, 0, 0); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
415 writer.writeStartElement(XMLUtil.ISODATE); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
416 writer.writeCharacters(dateFormatter.print(dt)); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
417 writer.writeEndElement(); |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
418 } |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
419 } catch (JSONException e) { |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
420 // maybe not JSON... |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
421 } |
1149eb948036
add isodate tag to XML dump format 4.9.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
100
diff
changeset
|
422 } |
75 | 423 } |
1 | 424 |
29 | 425 writer.writeEndElement(); |
426 } | |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
427 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
428 |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
429 private static void writeStats(String statsTag, String entryTag, Map<String, Map<String, Long>> nodeStats, |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
430 XMLStreamWriter writer) throws XMLStreamException { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
431 // write stats tag |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
432 writer.writeStartElement(statsTag); |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
433 |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
434 for (String nodeType : nodeStats.keySet()) { |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
435 Map<String, Long> attStats = nodeStats.get(nodeType); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
436 Long nodeCnt = attStats.get(ENT_KEY); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
437 // write tag for entity/attribute |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
438 writer.writeStartElement(entryTag); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
439 writer.writeAttribute(XMLUtil.OBJECT_CLASS, (nodeType == null) ? "null" : nodeType); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
440 writer.writeAttribute(XMLUtil.COUNT, nodeCnt.toString()); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
441 |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
442 // write attributes |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
443 for (String attName : attStats.keySet()) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
444 // skip ENT_KEY |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
445 if (attName.equals(ENT_KEY)) |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
446 continue; |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
447 if (attName.contains("[")) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
448 // write relation tag |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
449 writer.writeStartElement(XMLUtil.RELATION); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
450 } else { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
451 // write attribute tag |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
452 writer.writeStartElement(XMLUtil.ATTRIBUTE); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
453 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
454 writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, attName); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
455 Long attCnt = attStats.get(attName); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
456 writer.writeAttribute(XMLUtil.COUNT, attCnt.toString()); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
457 writer.writeEndElement(); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
458 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
459 // end of entity/attribute tag |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
460 writer.writeEndElement(); |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
461 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
462 // end of stats tag |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
463 writer.writeEndElement(); |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
464 } |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
465 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
466 /** |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
467 * @param objectClass |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
468 * @param entStats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
469 * @return |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
470 */ |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
471 protected static Map<String, Long> updateNodeStats(Node ent, Map<String, Map<String, Long>> entStats) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
472 String objectClass = ent.getObjectClass(); |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
473 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
|
474 if (attStats == null) { |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
475 // create new attribute stats entry |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
476 attStats = new HashMap<String, Long>(); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
477 // add key to count entities |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
478 attStats.put(ENT_KEY, 1l); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
479 // add to map |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
480 entStats.put(objectClass, attStats); |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
481 } else { |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
482 // increment entity count |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
483 Long entCnt = attStats.get(ENT_KEY); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
484 attStats.put(ENT_KEY, entCnt + 1); |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
485 } |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
486 return attStats; |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
487 } |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
488 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
489 /** |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
490 * @param att |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
491 * @param attStats |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
492 */ |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
493 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
|
494 String attName = att.getName(); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
495 Long cnt = attStats.get(attName); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
496 if (cnt == null) { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
497 attStats.put(attName, 1l); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
498 } else { |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
499 attStats.put(attName, cnt + 1); |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
500 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
501 } |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
502 |
86
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
503 /** |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
504 * Update relation statistics. |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
505 * |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
506 * Relation stats are saved like attribute stats but with "[entity-type]" before |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
507 * or after the relation name. |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
508 * |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
509 * @param rel |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
510 * @param relStats |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
511 */ |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
512 protected static void updateRelStats(Relation rel, boolean isSrcRel, Map<String, Long> relStats) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
513 String relName = rel.getObjectClass(); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
514 if (isSrcRel) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
515 relName = relName + "[" + rel.getTargetObjectClass() + "]"; |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
516 } else { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
517 relName = "[" + rel.getSourceObjectClass() + "]" + relName; |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
518 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
519 Long cnt = relStats.get(relName); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
520 if (cnt == null) { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
521 relStats.put(relName, 1l); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
522 } else { |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
523 relStats.put(relName, cnt + 1); |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
524 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
525 } |
d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
82
diff
changeset
|
526 |
79
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
527 |
b0aebac0780a
put statistics about number of entities, relations and attributes in xml dump.
casties
parents:
78
diff
changeset
|
528 |
1 | 529 } |