/** * create a 1-d String array from a network, for easy transmission to R. triples (source, * edgeType, target) are filled in to an array of length 3 * # of interactions * * @param network a gaggle network * @return the edge attributes of the network as a string array */ protected String[] networkEdgeAttributesToStringArray(Network network) { Interaction[] interactions = network.getInteractions(); String source, target, type; String[] attributeNames = network.getEdgeAttributeNames(); ArrayList<String> list = new ArrayList<String>(); for (Interaction interaction : interactions) { source = interaction.getSource(); type = interaction.getType(); target = interaction.getTarget(); String edgeName = source + " (" + type + ") " + target; String terseEdgeName = source + "::" + target + "::" + type; for (String name : attributeNames) { HashMap hash = network.getEdgeAttributes(name); if (hash.containsKey(edgeName)) { Object value = hash.get(edgeName); StringBuffer sb = new StringBuffer(); sb.append(terseEdgeName); sb.append("::"); sb.append(name); sb.append("::"); sb.append(value.toString()); list.add(sb.toString()); } else { System.out.println("no " + name + " attribute for " + edgeName); } } // for a } // for r return list.toArray(new String[0]); } // networkEdgeAttributesToStringArray
/** * create a 1-d String array from a network, for easy transmission to R. each element in the array * is a string, with format sourceNode::targetNode::edgeType * * @param network the network to convert to a string * @return an array of strings representing a network */ protected String[] networkToStringArray(Network network) { Interaction[] interactions = network.getInteractions(); ArrayList<String> list = new ArrayList<String>(); // System.out.println ("networkToStringArray, interaction ount: " + interactions.length); for (Interaction interaction : interactions) { String source = interaction.getSource(); String target = interaction.getTarget(); String type = interaction.getType(); String combined = source + "::" + target + "::" + type; // System.out.println (" interaction: " + combined); list.add(combined); } // for i String[] orphanNodes = network.getOrphanNodes(); // System.out.println ("networkToStringArray, orphanCount: " + orphanNodes.length); for (String orphanNode : orphanNodes) { // System.out.println (" orphan: " + orphanNodes [i]); list.add(orphanNode); } return list.toArray(new String[0]); } // networkToStringArray