verticesIndex.put(node, nodesIndexcounter++);
}
/*** Add the links ***/
Set<LabeledLink> links = alignmentGraph.edgeSet();
for (LabeledLink link : links) {
Node source = link.getSource();
Integer sourceIndex = verticesIndex.get(source);
Node target = link.getTarget();
Integer targetIndex = verticesIndex.get(target);
Set<LabeledLink> outEdges = alignmentGraph
.outgoingEdgesOf(target);
if (sourceIndex == null || targetIndex == null) {
logger.error("Edge vertex index not found!");
continue;
}
JSONObject linkObj = new JSONObject();
linkObj.put(JsonKeys.source.name(), sourceIndex);
linkObj.put(JsonKeys.target.name(), targetIndex);
linkObj.put(JsonKeys.sourceNodeId.name(), source.getId());
linkObj.put(JsonKeys.targetNodeId.name(), target.getId());
linkObj.put(JsonKeys.label.name(), link.getLabel()
.getLocalName());
linkObj.put(JsonKeys.id.name(), link.getId() + "");
linkObj.put(JsonKeys.linkStatus.name(), link.getStatus()
.name());
linkObj.put(JsonKeys.linkUri.name(), link.getLabel()
.getUri());
if (target.getType() == NodeType.ColumnNode
&& outEdges.isEmpty()) {
linkObj.put(JsonKeys.linkType.name(),
JsonValues.holderLink.name());
}
linksArr.put(linkObj);
if (link.getType() == LinkType.ClassInstanceLink
&& target instanceof ColumnNode) {
ColumnNode cNode = (ColumnNode) target;
// Add the holder vertex object and the link that
// attaches nodes to the columns
JSONArray hNodeIdsCoveredByVertex_holder = new JSONArray();
hNodeIdsCoveredByVertex_holder.put(cNode.getHNodeId());
JSONObject vertObj_holder = getNormalLayoutNodeJsonObject(
JsonValues.key.name(), source.getId()
+ "_holder",
NodeType.ColumnNode.name(), 0, false,
hNodeIdsCoveredByVertex_holder,
cNode.getHNodeId(), cNode.getLabel().getUri(), false);
nodesArr.put(vertObj_holder);
nodesIndexcounter++;
// Add the holder link
JSONObject linkObj_holder = getNormalLayoutLinkJsonObject(
JsonValues.key.name(), "", nodesIndexcounter,
nodesIndexcounter - 1, "", "", "", "");
linksArr.put(linkObj_holder);
}
if (link.getType() == LinkType.DataPropertyOfColumnLink) {
DataPropertyOfColumnLink dpLink = (DataPropertyOfColumnLink) link;
String startHNodeId = dpLink
.getSpecializedColumnHNodeId();
// Get height of the class instance node
int height = maxTreeHeight
- nodeHeightsMap.get(link.getSource());
// Add 2 more holder nodes
// Start node
JSONArray hNodeIdsCoveredByVertex_holder = new JSONArray();
boolean isSUri = false;
if(source instanceof LiteralNode) {
isSUri = ((LiteralNode)source).isUri();
}
hNodeIdsCoveredByVertex_holder.put(startHNodeId);
JSONObject startNode = getNormalLayoutNodeJsonObject("",
source.getId() + "_holder",
JsonValues.DataPropertyOfColumnHolder.name(),
height - 0.35, false,
hNodeIdsCoveredByVertex_holder, startHNodeId,
source.getLabel().getUri(), isSUri);
nodesArr.put(startNode);
nodesIndexcounter++;
// End node
String endHNodeId = ((ColumnNode) link.getTarget())
.getHNodeId();
JSONArray hNodeIdsCoveredByVertex_holder_2 = new JSONArray();
hNodeIdsCoveredByVertex_holder_2.put(endHNodeId);
boolean isTUri = false;
if(target instanceof LiteralNode) {
isTUri = ((LiteralNode)target).isUri();
}
JSONObject endNode = getNormalLayoutNodeJsonObject("",
target.getId() + "_holder",
JsonValues.DataPropertyOfColumnHolder.name(),
height - 0.35, false,
hNodeIdsCoveredByVertex_holder_2, endHNodeId,
target.getLabel().getUri(), isTUri);
nodesArr.put(endNode);
nodesIndexcounter++;
// Add the horizontal link
JSONObject linkObj_holder = getNormalLayoutLinkJsonObject("", "",
nodesIndexcounter - 2, nodesIndexcounter - 1,
JsonValues.horizontalDataPropertyLink.name(),
"", "", "");
linksArr.put(linkObj_holder);
} else if (link.getType() == LinkType.ObjectPropertySpecializationLink) {
ObjectPropertySpecializationLink opLink = (ObjectPropertySpecializationLink) link;
String specializedLinkId = opLink
.getSpecializedLinkId();
// Get height of the class instance node
Node specializedLinkTarget = this.alignment
.getNodeById(LinkIdFactory
.getLinkTargetId(specializedLinkId));
int height = nodeHeightsMap.get(specializedLinkTarget);
// Add 2 more holder nodes
// Start node