Changeset 36 for branches/localSpectral/src/data
- Timestamp:
- Jan 6, 2011, 9:41:42 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/localSpectral/src/data/GraphBuilder.java
r34 r36 2 2 package data; 3 3 4 import GraphType.DirectedDenseGraph; 4 5 import clustering.Edge; 5 import clustering.VertexString;6 6 import edu.uci.ics.jung.graph.DirectedSparseGraph; 7 7 import edu.uci.ics.jung.graph.Graph; 8 8 import edu.uci.ics.jung.graph.SparseGraph; 9 import java.io.BufferedInputStream;10 9 import java.io.BufferedReader; 11 10 import java.io.DataInputStream; … … 21 20 public class GraphBuilder { 22 21 23 Graph<String, Edge<String>> graph;22 Graph<String,Integer> graph; 24 23 25 24 public GraphBuilder(boolean directed){ 26 25 if (directed) 27 graph = new DirectedSparseGraph<String, Edge<String>>(); 26 graph = new DirectedDenseGraph<String, Integer>(); 27 //graph = new DirectedSparseGraph<String, Integer>(); 28 28 29 29 else 30 graph = new SparseGraph<String, Edge<String>>();30 graph = new SparseGraph<String, Integer>(); 31 31 } 32 32 33 public Graph<String, Edge<String>> getGraph() {33 public Graph<String, Integer> getGraph() { 34 34 return graph; 35 35 } 36 36 37 public void buildGraphFrom ARFF(String path, int maxreadline){37 public void buildGraphFromCVS(String path, int maxreadline){ 38 38 try { 39 39 FileInputStream fstream = new FileInputStream(path); … … 41 41 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 42 42 43 Set<String> vertex = new HashSet<String>();44 45 43 String read; 46 44 int edge=0; 47 int count=0; 48 while(((read = br.readLine()) != null) && (count < maxreadline)){ 49 count++; 50 if(!(read.contains("@DATA") || read.contains("@RELATION") || read.contains("@ATTRIBUTE") || read.trim().isEmpty())){ 51 String[] splitted = read.trim().split(","); 52 vertex.addAll(Arrays.asList(splitted)); 53 graph.addEdge(new Edge<String>(splitted[0], splitted[1]), splitted[0], splitted[1]); 45 String[] splitted; 46 while((read = br.readLine()) != null){ 47 if(!read.trim().isEmpty()){ 48 splitted = read.trim().split(","); 49 graph.addEdge(edge, splitted[0], splitted[1]); 54 50 edge++; 55 51 }
Note: See TracChangeset
for help on using the changeset viewer.