Mercurial > hg > openmind
changeset 86:d4b456623d43
Updated XML export. Saves relation source-type and target-type. Expanded statistics with per-entity-type relation counts.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 05 Feb 2018 20:06:38 +0100 |
parents | 1aff84e5048d |
children | 8005f7011975 |
files | src/main/java/org/mpi/openmind/repository/bo/Node.java src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java src/main/java/org/mpi/openmind/repository/utils/XMLUtil.java |
diffstat | 3 files changed, 97 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/repository/bo/Node.java Fri Oct 20 12:48:31 2017 +0200 +++ b/src/main/java/org/mpi/openmind/repository/bo/Node.java Mon Feb 05 20:06:38 2018 +0100 @@ -334,6 +334,11 @@ return isPublic; } + /** + * Set the public state of this Node. + * + * @param isPublic + */ public void setIsPublic(Boolean isPublic) { this.isPublic = isPublic; }
--- a/src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java Fri Oct 20 12:48:31 2017 +0200 +++ b/src/main/java/org/mpi/openmind/repository/utils/OM4StreamWriter.java Mon Feb 05 20:06:38 2018 +0100 @@ -147,8 +147,19 @@ // write entity to XML writeEntity(ent, writer, ps, includeNorm, entStats); // add (source)relations to list - relList.addAll(ent.getSourceRelations()); - + List<Relation> rels = ent.getSourceRelations(); + relList.addAll(rels); + // update stats for relations + Map<String, Long> entRelStats = entStats.get(ent.getObjectClass()); + for (Relation rel: rels) { + // update source relations + updateRelStats(rel, true, entRelStats); + } + for (Relation rel: ent.getTargetRelations()) { + // update target relations + updateRelStats(rel, false, entRelStats); + } + // count entities counter++; } @@ -217,7 +228,9 @@ writer.writeAttribute(XMLUtil.CONTENT_TYPE, rel.getContentType()); } writer.writeAttribute(XMLUtil.RELATION_SOURCE_ID, defaultString(rel.getSourceId())); + writer.writeAttribute(XMLUtil.RELATION_SOURCE, defaultString(rel.getSourceObjectClass())); writer.writeAttribute(XMLUtil.RELATION_TARGET_ID, defaultString(rel.getTargetId())); + writer.writeAttribute(XMLUtil.RELATION_TARGET, defaultString(rel.getTargetObjectClass())); writer.writeAttribute(XMLUtil.VERSION, defaultString(rel.getVersion())); writer.writeAttribute(XMLUtil.MODIFICATION_TIME, defaultString(rel.getModificationTime())); if (rel.getUser() != null) { @@ -267,6 +280,7 @@ writer.writeStartElement((entity.getType().equals(Node.TYPE_TBOX)) ? XMLUtil.DEFINITION : XMLUtil.ENTITY); if (entity.isLightweight()) { + // make sure we have all attributes and relations entity = ps.getEntityContent(entity); } @@ -297,9 +311,9 @@ if (entity.getAttributes().size() > 0) { writer.writeStartElement(XMLUtil.ATTRIBUTES); for (Attribute att : entity.getAttributes()) { - // update stats - updateAttStats(att, attStats); - // write xml + // update stats + updateAttStats(att, attStats); + // write xml writeAttribute(att, writer, includeNorm); } writer.writeEndElement(); @@ -362,60 +376,65 @@ } - private static void writeStats(String statsTag, String entryTag, Map<String, Map<String, Long>> nodeStats, XMLStreamWriter writer) - throws XMLStreamException { - // write stats tag + private static void writeStats(String statsTag, String entryTag, Map<String, Map<String, Long>> nodeStats, + XMLStreamWriter writer) throws XMLStreamException { + // write stats tag writer.writeStartElement(statsTag); - + for (String nodeType : nodeStats.keySet()) { - Map<String, Long> attStats = nodeStats.get(nodeType); - Long nodeCnt = attStats.get(ENT_KEY); - // write tag for entity/attribute - writer.writeStartElement(entryTag); - writer.writeAttribute(XMLUtil.OBJECT_CLASS, (nodeType == null)?"null":nodeType); - writer.writeAttribute(XMLUtil.COUNT, nodeCnt.toString()); - - // write attributes - for (String attName : attStats.keySet()) { - // skip ENT_KEY - if (attName.equals(ENT_KEY)) continue; - // write attribute tag - writer.writeStartElement(XMLUtil.ATTRIBUTE); - writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, attName); - Long attCnt = attStats.get(attName); - writer.writeAttribute(XMLUtil.COUNT, attCnt.toString()); - writer.writeEndElement(); - } - // end of entity/attribute tag - writer.writeEndElement(); + Map<String, Long> attStats = nodeStats.get(nodeType); + Long nodeCnt = attStats.get(ENT_KEY); + // write tag for entity/attribute + writer.writeStartElement(entryTag); + writer.writeAttribute(XMLUtil.OBJECT_CLASS, (nodeType == null) ? "null" : nodeType); + writer.writeAttribute(XMLUtil.COUNT, nodeCnt.toString()); + + // write attributes + for (String attName : attStats.keySet()) { + // skip ENT_KEY + if (attName.equals(ENT_KEY)) + continue; + if (attName.contains("[")) { + // write relation tag + writer.writeStartElement(XMLUtil.RELATION); + } else { + // write attribute tag + writer.writeStartElement(XMLUtil.ATTRIBUTE); + } + writer.writeAttribute(XMLUtil.ATTRIBUTE_NAME, attName); + Long attCnt = attStats.get(attName); + writer.writeAttribute(XMLUtil.COUNT, attCnt.toString()); + writer.writeEndElement(); + } + // end of entity/attribute tag + writer.writeEndElement(); } // end of stats tag writer.writeEndElement(); - } - + } /** * @param objectClass * @param entStats * @return */ - protected static Map<String, Long> updateNodeStats(Node ent, Map<String, Map<String, Long>> entStats) { - String objectClass = ent.getObjectClass(); + protected static Map<String, Long> updateNodeStats(Node ent, Map<String, Map<String, Long>> entStats) { + String objectClass = ent.getObjectClass(); Map<String, Long> attStats = entStats.get(objectClass); if (attStats == null) { - // create new attribute stats entry - attStats = new HashMap<String, Long>(); - // add key to count entities - attStats.put(ENT_KEY, 1l); - // add to map - entStats.put(objectClass, attStats); + // create new attribute stats entry + attStats = new HashMap<String, Long>(); + // add key to count entities + attStats.put(ENT_KEY, 1l); + // add to map + entStats.put(objectClass, attStats); } else { - // increment entity count - Long entCnt = attStats.get(ENT_KEY); - attStats.put(ENT_KEY, entCnt + 1); + // increment entity count + Long entCnt = attStats.get(ENT_KEY); + attStats.put(ENT_KEY, entCnt + 1); } - return attStats; - } + return attStats; + } /** * @param att @@ -431,6 +450,30 @@ } } + /** + * Update relation statistics. + * + * Relation stats are saved like attribute stats but with "[entity-type]" before + * or after the relation name. + * + * @param rel + * @param relStats + */ + protected static void updateRelStats(Relation rel, boolean isSrcRel, Map<String, Long> relStats) { + String relName = rel.getObjectClass(); + if (isSrcRel) { + relName = relName + "[" + rel.getTargetObjectClass() + "]"; + } else { + relName = "[" + rel.getSourceObjectClass() + "]" + relName; + } + Long cnt = relStats.get(relName); + if (cnt == null) { + relStats.put(relName, 1l); + } else { + relStats.put(relName, cnt + 1); + } + } + }
--- a/src/main/java/org/mpi/openmind/repository/utils/XMLUtil.java Fri Oct 20 12:48:31 2017 +0200 +++ b/src/main/java/org/mpi/openmind/repository/utils/XMLUtil.java Mon Feb 05 20:06:38 2018 +0100 @@ -199,6 +199,11 @@ } catch (TransformerConfigurationException e) { System.out.println("Transformer configuration error: " + e.getMessage()); + try { + fos.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } return false; } DOMSource source = new DOMSource(doc);