/** * Gets the id of an input node. * @param node a node of the graph * @return id of the node */ private Integer getNodeId(Node node) { Integer id = null; for (Map.Entry<Node, Integer> e : nodeToId.entrySet()) { boolean nodeEquals = true; for (int i = 0; i < nodeSchema.getColumnCount(); i++) { String colName = nodeSchema.getColumnName(i); if (!node.get(colName).equals(e.getKey().get(colName))) { nodeEquals = false; break; } } if (nodeEquals) { id = e.getValue(); break; } } return id; }
/** * Adds a given node to the current graph. * @param node node to add to the graph * @return true if the node is added */ public boolean addNode(Node node) { try { int rowId = graph.addVertex(); for (int i = 0; i < node.getSchema().getColumnCount(); i++) { if (nodeSchema.hasColumn(node.getSchema().getColumnName(i))) { TypedFormat format = formatFactory.getFormat( node.getSchema().getColumnType(i).getSimpleName()); StringBuffer v = format.format(node.get(i), new StringBuffer(), new FieldPosition(0)); graph.getVertexTable().setValueAt(v.toString(), rowId, graph.getVertexTable().indexOf( node.getSchema().getColumnName(i))); } } nodeToId.put(node, rowId); fireNetworkEvent(node.getRow(), node.getRow(), 0, NetworkListener.INSERT_NODE); return true; } catch (Exception e) { throw new ObviousRuntimeException(e); } }
/** * Adds a given node to the current graph. * @param node node to add to the graph * @return true if the node is added */ public boolean addNode(Node node) { try { // if prefNode (prefuse) tuple and node (obvious) tuple are compatible // i.e their schema are compatible. prefuse.data.Node prefNode = this.graph.addNode(); for (int i = 0; i < node.getTable().getSchema().getColumnCount(); i++) { prefNode.set(node.getSchema().getColumnName(i), node.get(i)); } int nodeId = prefNode.getRow(); fireNetworkEvent(nodeId, nodeId, 0, NetworkListener.INSERT_NODE); return true; } catch (Exception e) { throw new ObviousRuntimeException(e); } }
/** * Loads the table with the data of external CSV files. * @return an obvious network * @throws ObviousxException when exception occurs */ public Network loadGraph() throws ObviousxException { CSVTableImport nodeImport = new CSVTableImport(nodeFile, new TableImpl(nodeSchema), separator); CSVTableImport edgeImport = new CSVTableImport(edgeFile, new TableImpl(edgeSchema), separator); Table nodeTable = nodeImport.loadTable(); Table edgeTable = edgeImport.loadTable(); for (int i = 0; i < nodeTable.getRowCount(); i++) { Node node = new NodeImpl(nodeTable, i); network.addNode(node); if (nodeId == null) { idToNode.put(node.getRow(), node); } else { idToNode.put(node.get(nodeId), node); } } for (int i = 0; i < edgeTable.getRowCount(); i++) { Edge edge = new EdgeImpl(edgeTable, i); network.addEdge(edge, idToNode.get(edge.get(sourceCol)), idToNode.get(edge.get(targetCol)), network.getEdgeType(edge)); } return this.network; }
/** * Gets the id of an input node. * @param node a node of the graph * @return id of the node */ private Integer getNodeId(Node node) { Integer id = null; for (Map.Entry<Node, Integer> e : nodeToId.entrySet()) { boolean nodeEquals = true; for (int i = 0; i < nodeSchema.getColumnCount(); i++) { String colName = nodeSchema.getColumnName(i); if (!node.get(colName).equals(e.getKey().get(colName))) { nodeEquals = false; break; } } if (nodeEquals) { id = e.getValue(); break; } } return id; }
TypedFormat format = formatFactory.getFormat( nodeSchema.getColumnType(i).getSimpleName()); StringBuffer value = format.format(node.get(i), new StringBuffer(), new FieldPosition(0)); serializer.writeCharacters(value.toString());
network.addNode(node); for (Node n : network.getNodes()) { if (n.get(nodeId).equals(id)) { node = n; break;