コード例 #1
0
  public Element createEdgeElement(
      Document evtDom, Collaboration collaboration, int src, int tar, int index) {

    Element edge = evtDom.createElement("edge");
    edge.setAttribute("id", "e" + Integer.toString(index));
    edge.setAttribute("source", Integer.toString(src));
    edge.setAttribute("target", Integer.toString(tar));

    for (int row = 0; row < edgeAttr.length; row++) {
      Element data = evtDom.createElement("data");
      data.setAttribute("key", edgeAttr[row][0]);

      if (edgeAttr[row][0].equalsIgnoreCase("SourceContributorID"))
        data.setTextContent(Integer.toString(src));
      else if (edgeAttr[row][0].equalsIgnoreCase("TargetContributorID"))
        data.setTextContent(Integer.toString(tar));
      else if (edgeAttr[row][0].equalsIgnoreCase("NumOfCollaboration"))
        data.setTextContent(Integer.toString(collaboration.getCollaborationCount()));
      else if (edgeAttr[row][0].equalsIgnoreCase("FirstDate"))
        data.setTextContent(collaboration.getFirstDate());
      else if (edgeAttr[row][0].equalsIgnoreCase("LastDate"))
        data.setTextContent(collaboration.getLastDate());

      edge.appendChild(data);
    }
    return edge;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  public Document toGraphMLDOM_org(Document egoDom, String id, int radius, String graphType) {

    Collaborator collaborator = null;

    if (db.connect() == false) {
      throw new RuntimeException("Unable to connect to the database");
    }

    // add the graph element
    Element rootElement = egoDom.getDocumentElement();
    rootElement = createHeaderElements(egoDom, rootElement, graphType);

    Element graph = egoDom.createElement("graph");
    graph.setAttribute("id", "Contributor Network for organisation:" + " ( " + id + " )");
    graph.setAttribute("edgedefault", graphType);
    rootElement.appendChild(graph);

    network = getRawCollaboratorData_org(id, radius);

    if (network != null) {
      // add some additional required information for contributors
      collaborators = getCollaborators(network, "0");

      // get collaboration List
      collaborations = getCollaborations_org(id, network);
    } else return egoDom;

    // create node element in DOM
    for (int i = 0; i < collaborators.size(); i++) {
      Element node = createNodeElement(egoDom, i);
      graph.appendChild(node);
    }

    // we have a list of collaborations.
    // loop through the list, for each - create a collaboration
    //								  - create edge.

    // 1.iterate through the collaboration hashmap
    Iterator contributorIter = collaborations.values().iterator();
    int edgeIndex = 0;
    // collabCheck used to ensure no doubling up of collaborations. (pretty quick hack, ideally this
    // issue would be sorted before this point)
    Vector collabCheck = new Vector();

    while (contributorIter.hasNext()) {
      CollaborationList list = (CollaborationList) contributorIter.next();
      // get the actual collaborations
      if (list != null) {

        Iterator collaborationIter = list.getCollaborations().values().iterator();
        //	loop through the hashmap of collaborations
        while (collaborationIter.hasNext()) {

          Collaboration collaboration = (Collaboration) collaborationIter.next();

          if (!collabCheck.contains(
              collaboration.getPartner() + "-" + collaboration.getCollaborator())) {
            // create an edge for each of them
            Element edge =
                createEdgeElement(
                    egoDom,
                    collaboration,
                    Integer.parseInt(collaboration.getCollaborator()),
                    Integer.parseInt(collaboration.getPartner()),
                    edgeIndex);
            graph.appendChild(edge);
            //	add the collaboration to the list for checking.
            collabCheck.add(collaboration.getCollaborator() + "-" + collaboration.getPartner());
            edgeIndex++;
          }
        }
      }
    }

    return egoDom;
  }