public SVGAlignmentUpdate_ForceKarmaLayout(
     String vWorksheetId, String alignmentId, Alignment alignment, List<String> hNodeIdList) {
   super();
   this.vWorksheetId = vWorksheetId;
   this.alignmentId = alignmentId;
   this.tree = alignment.getSteinerTree();
   this.root = alignment.GetTreeRoot();
   this.hNodeIdList = hNodeIdList;
   this.alignment = alignment;
 }
Exemplo n.º 2
0
 private Map<String, ColumnNode> createColumnNodeMap() {
   Set<Node> alignmentColumnNodes = alignment.getNodesByType(NodeType.ColumnNode);
   Map<String, ColumnNode> hNodeIdToColumnNodeMap = new HashMap<>();
   if (alignmentColumnNodes == null) return hNodeIdToColumnNodeMap;
   for (Node cNode : alignmentColumnNodes) {
     ColumnNode columnNode = (ColumnNode) cNode;
     hNodeIdToColumnNodeMap.put(columnNode.getHNodeId(), columnNode);
   }
   return hNodeIdToColumnNodeMap;
 }
Exemplo n.º 3
0
 private Map<String, SemanticTypeNode> createDomainNodeMap() {
   Map<String, SemanticTypeNode> hNodeIdToDomainNodeMap = new HashMap<>();
   Set<Node> alignmentColumnNodes = alignment.getNodesByType(NodeType.ColumnNode);
   if (alignmentColumnNodes == null) return hNodeIdToDomainNodeMap;
   for (Node cNode : alignmentColumnNodes) {
     Set<LabeledLink> incomingLinks = alignment.getCurrentIncomingLinksToNode(cNode.getId());
     if (incomingLinks != null && !incomingLinks.isEmpty()) {
       LabeledLink incomingLink =
           alignment.getCurrentIncomingLinksToNode(cNode.getId()).iterator().next();
       if (incomingLink != null && incomingLink.getSource() instanceof InternalNode) {
         String hNodeId = ((ColumnNode) cNode).getHNodeId();
         if (incomingLink instanceof DataPropertyOfColumnLink
             || incomingLink instanceof ObjectPropertySpecializationLink) {
           String id;
           if (incomingLink instanceof DataPropertyOfColumnLink)
             id = ((DataPropertyOfColumnLink) incomingLink).getSpecializedLinkId();
           else id = ((ObjectPropertySpecializationLink) incomingLink).getSpecializedLinkId();
           hNodeIdToDomainNodeMap.put(
               hNodeId,
               new SemanticTypeNode(
                   id,
                   id,
                   id,
                   incomingLink.getLabel().getRdfsLabel(),
                   incomingLink.getLabel().getRdfsComment()));
         } else {
           InternalNode source = (InternalNode) incomingLink.getSource();
           hNodeIdToDomainNodeMap.put(
               hNodeId,
               new SemanticTypeNode(
                   source.getId(),
                   source.getUri(),
                   source.getDisplayId(),
                   source.getLabel().getRdfsLabel(),
                   source.getLabel().getRdfsComment()));
         }
       }
     }
   }
   return hNodeIdToDomainNodeMap;
 }
Exemplo n.º 4
0
 private boolean isMetaProperty(Label type, ColumnNode alignmentColumnNode) {
   // Check for the case of DataPropertyOfColumnLink and ColumnSubClassLink
   boolean case1 =
       (type.getUri().equals(DataPropertyOfColumnLink.getFixedLabel().getUri())
           || type.getUri().equals(ColumnSubClassLink.getFixedLabel().getUri()));
   if (case1) return true;
   Set<LabeledLink> incomingLinks =
       alignment.getCurrentIncomingLinksToNode(alignmentColumnNode.getId());
   if (incomingLinks != null && !incomingLinks.isEmpty()) {
     LabeledLink incomingLink = incomingLinks.iterator().next();
     if (incomingLink != null
         && (incomingLink instanceof ClassInstanceLink)
         && incomingLink.getKeyType().equals(LinkKeyInfo.UriOfInstance)) return true;
   }
   return false;
 }
  @Override
  public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
    JSONObject topObj = new JSONObject();
    try {
      topObj.put(
          GenericJsonKeys.updateType.name(),
          SVGAlignmentUpdate_ForceKarmaLayout.class.getSimpleName());
      topObj.put(JsonKeys.alignmentId.name(), alignmentId);
      topObj.put(JsonKeys.worksheetId.name(), vWorksheetId);

      @SuppressWarnings("unchecked")
      DirectedWeightedMultigraph<Vertex, LabeledWeightedEdge> treeClone =
          (DirectedWeightedMultigraph<Vertex, LabeledWeightedEdge>) tree.clone();
      // Reversing the inverse links
      alignment.updateLinksDirections(this.root, null, treeClone);

      /** * Add the nodes and the links from the Steiner tree ** */
      List<String> hNodeIdsAdded = new ArrayList<String>();
      JSONArray vertArr = new JSONArray();
      JSONArray linksArr = new JSONArray();
      int maxTreeHeight = 0;

      if (tree != null && tree.vertexSet().size() != 0) {

        /** * Add the nodes ** */
        Set<Vertex> vertices = tree.vertexSet();
        HashMap<Vertex, Integer> verticesIndex = new HashMap<Vertex, Integer>();
        int nodesIndexcounter = 0;

        for (Vertex vertex : vertices) {
          JSONObject vertObj = new JSONObject();
          vertObj.put(JsonKeys.label.name(), vertex.getLocalID());
          vertObj.put(JsonKeys.id.name(), vertex.getID());
          vertObj.put(JsonKeys.nodeType.name(), vertex.getNodeType().name());

          List<Vertex> nodesWithSemTypesCovered = new ArrayList<Vertex>();
          int height = getHeight(vertex, nodesWithSemTypesCovered, treeClone);
          if (height >= maxTreeHeight) {
            maxTreeHeight = height;
          }

          vertObj.put(JsonKeys.height.name(), height);
          JSONArray hNodeIdsCoveredByVertex = new JSONArray();
          for (Vertex v : nodesWithSemTypesCovered)
            hNodeIdsCoveredByVertex.put(v.getSemanticType().getHNodeId());
          vertObj.put(JsonKeys.hNodesCovered.name(), hNodeIdsCoveredByVertex);

          // Add the semantic type information if required.
          if (vertex.getSemanticType() != null) {
            SemanticType type = vertex.getSemanticType();
            vertObj.put(JsonKeys.hNodeId.name(), type.getHNodeId());
            hNodeIdsAdded.add(type.getHNodeId());

            if (vertex.getNodeType() == NodeType.Class) {
              if (type.isPartOfKey()) {
                vertObj.put(JsonKeys.label.name(), vertex.getLocalID() + "*");
              }

              // Add the holder vertex object and the link that
              // attaches nodes to the columns
              JSONObject vertObj_holder = new JSONObject();
              vertObj_holder.put(JsonKeys.label.name(), JsonValues.key.name());
              vertObj_holder.put(JsonKeys.id.name(), vertex.getID() + "_holder");
              vertObj_holder.put(JsonKeys.nodeType.name(), NodeType.DataProperty.name());
              vertObj_holder.put(JsonKeys.hNodeId.name(), type.getHNodeId());

              JSONArray hNodeIdsCoveredByVertex_holder = new JSONArray();
              hNodeIdsCoveredByVertex_holder.put(vertex.getSemanticType().getHNodeId());
              vertObj_holder.put(JsonKeys.hNodesCovered.name(), hNodeIdsCoveredByVertex_holder);
              vertObj_holder.put(JsonKeys.height.name(), 0);
              vertArr.put(vertObj_holder);

              nodesIndexcounter++;

              // Add the holder link
              JSONObject linkObj = new JSONObject();
              linkObj.put(JsonKeys.source.name(), nodesIndexcounter);
              linkObj.put(JsonKeys.target.name(), nodesIndexcounter - 1);
              linkObj.put(JsonKeys.label.name(), JsonValues.key.name());
              linkObj.put(JsonKeys.id.name(), "");
              linksArr.put(linkObj);
            }
          }

          vertArr.put(vertObj);
          verticesIndex.put(vertex, nodesIndexcounter++);
        }

        /** * Add the links ** */
        Set<LabeledWeightedEdge> edges = tree.edgeSet();
        for (LabeledWeightedEdge edge : edges) {
          Vertex source = edge.getSource();
          Integer sourceIndex = verticesIndex.get(source);
          Vertex target = edge.getTarget();
          Integer targetIndex = verticesIndex.get(target);
          Set<LabeledWeightedEdge> outEdges = tree.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(), edge.getLocalLabel());
          linkObj.put(JsonKeys.id.name(), edge.getID() + "");
          linkObj.put(JsonKeys.linkStatus.name(), edge.getLinkStatus().name());

          if (target.getSemanticType() != null && outEdges.isEmpty()) {
            linkObj.put(JsonKeys.linkType.name(), JsonValues.holderLink.name());
            if (target.getSemanticType().isPartOfKey())
              linkObj.put(JsonKeys.label.name(), edge.getLocalLabel() + "*");
          }

          linksArr.put(linkObj);

          if (source.getNodeType() == NodeType.Class && target.getNodeType() == NodeType.Class) {
            linkObj.put(JsonKeys.linkType.name(), JsonValues.objPropertyLink.name());
          }
        }
      }

      // Add the vertices for the columns that were not in Steiner tree
      hNodeIdList.removeAll(hNodeIdsAdded);
      for (String hNodeId : hNodeIdList) {
        JSONObject vertObj = new JSONObject();
        vertObj.put(JsonKeys.id.name(), hNodeId);
        vertObj.put(JsonKeys.hNodeId.name(), hNodeId);
        vertObj.put(JsonKeys.nodeType.name(), JsonValues.Unassigned.name());
        vertArr.put(vertObj);
        vertObj.put(JsonKeys.height.name(), 0);
        JSONArray hNodeIdsCoveredByVertex = new JSONArray();
        hNodeIdsCoveredByVertex.put(hNodeId);
        vertObj.put(JsonKeys.hNodesCovered.name(), hNodeIdsCoveredByVertex);
      }

      topObj.put(JsonKeys.maxTreeHeight.name(), maxTreeHeight);
      topObj.put(JsonKeys.nodes.name(), vertArr);
      topObj.put(JsonKeys.links.name(), linksArr);

      pw.write(topObj.toString(4));
    } catch (JSONException e) {
      logger.error("Error occured while writing JSON!", e);
    }
  }
 public AlignmentSVGVisualizationUpdate(String worksheetId, Alignment alignment) {
   super();
   this.worksheetId = worksheetId;
   this.alignmentGraph = alignment.getSteinerTree();
 }
Exemplo n.º 7
0
  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    final OntologyManager ontMgr = workspace.getOntologyManager();
    Set<LabeledLink> properties = new HashSet<>();

    logger.debug(
        "GetPropertiesCommand:"
            + propertiesRange
            + ":"
            + classURI
            + ","
            + domainURI
            + ", "
            + rangeURI);

    if (propertiesRange == INTERNAL_PROP_RANGE.allObjectProperties) {
      HashMap<String, Label> linkList = ontMgr.getObjectProperties();
      if (linkList != null) {
        for (Label label : linkList.values()) {
          properties.add(new DataPropertyLink(label.getUri(), label));
        }
      }
    } else if (propertiesRange == INTERNAL_PROP_RANGE.allDataProperties) {
      HashMap<String, Label> linkList = ontMgr.getDataProperties();
      for (Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
    } else if (propertiesRange == INTERNAL_PROP_RANGE.propertiesWithDomainRange) {
      Map<String, Label> linkList =
          ontMgr.getObjectPropertiesByDomainRange(domainURI, rangeURI, true);
      for (Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
    } else if (propertiesRange == INTERNAL_PROP_RANGE.dataPropertiesForClass) {
      Map<String, Label> linkList = ontMgr.getDataPropertiesByDomain(classURI, true);
      for (Label label : linkList.values()) {
        properties.add(new DataPropertyLink(label.getUri(), label));
      }
    } else if (propertiesRange == INTERNAL_PROP_RANGE.existingProperties) {
      Alignment alignment =
          AlignmentManager.Instance()
              .getAlignmentOrCreateIt(workspace.getId(), worksheetId, ontMgr);
      Set<String> steinerTreeNodeIds = new HashSet<String>();
      if (alignment != null && !alignment.isEmpty()) {
        DirectedWeightedMultigraph<Node, LabeledLink> steinerTree = alignment.getSteinerTree();
        for (Node node : steinerTree.vertexSet()) {
          if (node.getType() == NodeType.InternalNode) {
            steinerTreeNodeIds.add(node.getId());
          }
        }

        List<LabeledLink> specializedLinks = new ArrayList<LabeledLink>();
        Set<LabeledLink> temp = null;
        temp = alignment.getLinksByType(LinkType.DataPropertyLink);
        if (temp != null) specializedLinks.addAll(temp);
        for (LabeledLink link : steinerTree.edgeSet())
          if (link instanceof ObjectPropertyLink) specializedLinks.add(link);

        // Store the data property links for specialized edge link options
        properties.addAll(specializedLinks);
      }
    }

    logger.debug("Got back " + properties.size() + " results");
    final Set<LabeledLink> finalProperties = properties;

    UpdateContainer upd =
        new UpdateContainer(
            new AbstractUpdate() {
              @Override
              public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) {
                JSONObject obj = new JSONObject();
                JSONArray resultArray = new JSONArray();

                try {
                  obj.put(JsonKeys.updateType.name(), "PropertyList");

                  for (LabeledLink link : finalProperties) {
                    Label linkLabel = link.getLabel();
                    String edgeLabelStr = linkLabel.getDisplayName();
                    JSONObject edgeObj = new JSONObject();
                    if (linkLabel.getUri() != null
                        && linkLabel.getNs() != null
                        && linkLabel.getUri().equalsIgnoreCase(linkLabel.getNs())) {
                      edgeLabelStr = linkLabel.getUri();
                    }

                    edgeObj.put(JsonKeys.label.name(), edgeLabelStr);
                    edgeObj.put(JsonKeys.uri.name(), linkLabel.getUri());
                    edgeObj.put(JsonKeys.id.name(), link.getId());
                    resultArray.put(edgeObj);
                  }

                  obj.put(JsonKeys.properties.name(), resultArray);
                  pw.println(obj.toString());
                } catch (Exception e) {
                  logger.error("Exception:", e);
                  e.printStackTrace();
                }
              }
            });
    return upd;
  }