/** * Gets the id of an input edge. * @param edge an edge of the graph * @return id of the edge */ private Integer getEdgeId(Edge edge) { Integer id = null; for (Map.Entry<Edge, Integer> e : edgeToId.entrySet()) { boolean edgeEquals = true; for (int i = 0; i < edgeSchema.getColumnCount(); i++) { String colName = edgeSchema.getColumnName(i); if (!edge.get(colName).equals(e.getKey().get(colName))) { edgeEquals = false; break; } } if (edgeEquals) { id = e.getValue(); break; } } return id; }
/** * Adds an edge to the graph. * @param edge edge to add * @param source source node * @param target target node * @param edgeType unused parameter * @return true if added */ public boolean addEdge(Edge edge, Node source, Node target, obvious.data.Graph.EdgeType edgeType) { try { int edgeId = graph.addEdge(getNodeId(source), getNodeId(target)); for (int i = 0; i < edge.getSchema().getColumnCount(); i++) { if (edgeSchema.hasColumn(edge.getSchema().getColumnName(i))) { TypedFormat format = formatFactory.getFormat( edge.getSchema().getColumnType(i).getSimpleName()); StringBuffer v = format.format(edge.get(i), new StringBuffer(), new FieldPosition(0)); graph.getEdgeTable().setValueAt(v.toString(), edgeId, graph.getEdgeTable().indexOf(edge.getSchema().getColumnName(i))); } } edgeToId.put(edge, edgeId); fireNetworkEvent(edge.getRow(), edge.getRow(), 0, NetworkListener.INSERT_EDGE); return true; } catch (Exception e) { throw new ObviousRuntimeException(e); } }
for (int i = 0; i < edgeTable.getSchema().getColumnCount(); i++) { edgeTable.set(edgeId - 1, edge.getSchema().getColumnName(i), edge.get(i));
/** * Gets the id of an input edge. * @param edge an edge of the graph * @return id of the edge */ private Integer getEdgeId(Edge edge) { Integer id = null; for (Map.Entry<Edge, Integer> e : edgeToId.entrySet()) { boolean edgeEquals = true; for (int i = 0; i < edgeSchema.getColumnCount(); i++) { String colName = edgeSchema.getColumnName(i); if (graph.getEdgeTable().getColumn(colName) != null) { if (!edge.get(colName).equals(e.getKey().get(colName))) { edgeEquals = false; break; } } } if (edgeEquals) { id = e.getValue(); break; } } return id; }
TypedFormat format = formatFactory.getFormat( edgeSchema.getColumnType(i).getSimpleName()); StringBuffer value = format.format(edge.get(i), new StringBuffer(), new FieldPosition(0)); serializer.writeCharacters(value.toString());
Boolean graphCol = colName.equals(sourceKey) || colName.equals( targetKey); if (colName == null || edge.get(colName) == null) { break; if (graphCol && edge.get(colName).equals(sourceKey) && nodeKey != null) { prefEdge.set(colName, source.get(nodeKey)); } else if (graphCol && edge.get(colName).equals(targetKey) && nodeKey != null) { prefEdge.set(colName, target.get(nodeKey)); } else if (graphCol && edge.get(colName).equals(sourceKey) && nodeKey == null) { prefEdge.set(colName, source.getRow()); } else if (graphCol && edge.get(colName).equals(targetKey) && nodeKey == null) { prefEdge.set(colName, target.getRow()); } else { prefEdge.set(colName, edge.get(colName));
/** * 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; }