@Override public boolean write(String filename, String key) { Filewriter fw = new Filewriter(filename); // CLASS fw.writeComment(Config.get("GRAPH_PROPERTY_CLASS")); fw.writeln(this.getClass().getCanonicalName().toString()); // KEY fw.writeComment(Config.get("GRAPH_PROPERTY_KEY")); fw.writeln(key); // # MODULUS fw.writeComment("Modulus"); fw.writeln(this.modulus); // # WRAP-AROUND fw.writeComment("Wrap-around"); fw.writeln(this.wrapAround + ""); // # PARTITIONS fw.writeComment("Partitions"); fw.writeln(this.partitions.length); fw.writeln(); // PARTITIONS int index = 0; for (RingPartition p : this.partitions) { fw.writeln(index++ + ":" + p.toString()); } return fw.close(); }
/* * (non-Javadoc) * * @see gtna.io.graphReader.GraphReader#read(java.lang.String) */ @Override public Graph read(String filename) { String sep1 = Config.get("SNAP_SEPARATOR_1"); String ffd = Config.get("FILESYSTEM_FOLDER_DELIMITER"); SNAPFileReader fr = new SNAPFileReader(filename); try { String line = null; String name = filename.substring(filename.lastIndexOf(ffd) + 1); Graph graph = new Graph(name); Map<Integer, Integer> idMapping = new HashMap<Integer, Integer>(); int nodecounter = 0; LinkedList<String> edges = new LinkedList<String>(); graphtype type = null; line = fr.readLine(); type = (line.contains("Directed graph")) ? graphtype.DIRECTED : graphtype.UNDIRECTED; while (!line.contains("FromNodeId") && !line.contains("ToNodeId")) { line = fr.readLine(); } nodecounter = parseEdges(sep1, fr, idMapping, nodecounter, edges, type); Node[] nodes = Node.init(idMapping.size(), graph); Edges e = new Edges(nodes, edges.size()); ListIterator<String> edgeIterator = edges.listIterator(); while (edgeIterator.hasNext()) { String[] pair = edgeIterator.next().split("-"); e.add(Integer.parseInt(pair[0]), Integer.parseInt(pair[1])); } e.fill(); graph.setNodes(nodes); return graph; } catch (Exception e) { return null; } finally { fr.close(); } }
/** Returns number of nodes in the graph, expects a line: # Nodes: nodecount Edges: edgecount */ @Override public int nodes(String filename) { String sep1 = Config.get("SNAP_SEPARATOR_1"); SNAPFileReader fr = new SNAPFileReader(filename); String line = fr.readLine(); while (!line.contains("Nodes:")) { line = fr.readLine(); } String[] sl = line.split(sep1); return Integer.parseInt(sl[1]); }
@Override public Graph read(String filename) { String delimiter = Config.get("GRAPH_WRITER_DELIMITER"); Filereader fr = new Filereader(filename); String name = fr.readLine(); int N = Integer.parseInt(fr.readLine()); int E = Integer.parseInt(fr.readLine()); Graph graph = new Graph(name); Node[] nodes = Node.init(N, graph); Edges edges = new Edges(nodes, E); String line = null; while ((line = fr.readLine()) != null) { String[] temp = line.split(delimiter); edges.add(Integer.parseInt(temp[0]), Integer.parseInt(temp[1])); } edges.fill(); graph.setNodes(nodes); fr.close(); return graph; }
public static boolean getWOT(int y, int m, int d) { String Y = "" + y; String M = m < 10 ? "0" + m : "" + m; String D = d < 10 ? "0" + d : "" + d; String fetchOut = Config.get("WOT_READER_FETCH_OUT"); String fetchFolder = Config.get("WOT_READER_FETCH_FOLDER"); String fetchCmd = Config.get("WOT_READER_FETCH_CMD"); fetchOut = replace(fetchOut, Y, M, D); fetchFolder = replace(fetchFolder, Y, M, D); fetchCmd = replace(fetchCmd, Y, M, D); fetchCmd = fetchCmd.replace("%OUT", fetchOut); String unzipOut = Config.get("WOT_READER_UNZIP_OUT"); String unzipFolder = Config.get("WOT_READER_UNZIP_FOLDER"); String unzipCmd = Config.get("WOT_READER_UNZIP_CMD"); unzipOut = replace(unzipOut, Y, M, D); unzipFolder = replace(unzipFolder, Y, M, D); unzipCmd = replace(unzipCmd, Y, M, D); unzipCmd = unzipCmd.replace("%WOT", fetchOut); unzipCmd = unzipCmd.replace("%OUT", unzipOut); String wot = fetchFolder + fetchOut; String unzipped = unzipFolder + unzipOut; String filename = Config.get("WOT_READER_GRAPH_OUT"); filename = replace(filename, Y, M, D); execute(fetchCmd, fetchFolder); if (!(new File(wot)).exists()) { return false; } execute(unzipCmd, unzipFolder); if (!(new File(unzipped)).exists()) { return false; } try { Graph g = WOTReader.read(unzipped); GraphWriter.write(g, filename); if (Config.getBoolean("WOT_READER_DELETE_WOT_FILE")) { String deleteFolder = Config.get("WOT_READER_DELETE_WOT_FOLDER"); String deleteCmd = Config.get("WOT_READER_DELETE_WOT_CMD"); deleteCmd = replace(deleteCmd, Y, M, D); execute(deleteCmd, deleteFolder); } if (Config.getBoolean("WOT_READER_DELETE_UNZIPPED_FILE")) { String deleteFolder = Config.get("WOT_READER_DELETE_UNZIPPED_FOLDER"); String deleteCmd = Config.get("WOT_READER_DELETE_UNZIPPED_CMD"); deleteCmd = replace(deleteCmd, Y, M, D); execute(deleteCmd, deleteFolder); } return true; } catch (Exception e) { e.printStackTrace(); } return false; }