Ignore:
Timestamp:
Jan 6, 2011, 9:41:42 AM (14 years ago)
Author:
toshi
Message:

ultimo commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/localSpectral/src/data/GraphBuilder.java

    r34 r36  
    22package data;
    33
     4import GraphType.DirectedDenseGraph;
    45import clustering.Edge;
    5 import clustering.VertexString;
    66import edu.uci.ics.jung.graph.DirectedSparseGraph;
    77import edu.uci.ics.jung.graph.Graph;
    88import edu.uci.ics.jung.graph.SparseGraph;
    9 import java.io.BufferedInputStream;
    109import java.io.BufferedReader;
    1110import java.io.DataInputStream;
     
    2120public class GraphBuilder {
    2221
    23     Graph<String,Edge<String>> graph;
     22    Graph<String,Integer> graph;
    2423
    2524    public GraphBuilder(boolean directed){
    2625        if (directed)
    27            graph = new DirectedSparseGraph<String, Edge<String>>();
     26            graph = new DirectedDenseGraph<String, Integer>();
     27           //graph = new DirectedSparseGraph<String, Integer>();
    2828
    2929        else
    30             graph = new SparseGraph<String, Edge<String>>();
     30            graph = new SparseGraph<String, Integer>();
    3131    }
    3232
    33     public Graph<String, Edge<String>> getGraph() {
     33    public Graph<String, Integer> getGraph() {
    3434        return graph;
    3535    }
    3636
    37     public void buildGraphFromARFF(String path, int maxreadline){
     37    public void buildGraphFromCVS(String path, int maxreadline){
    3838        try {
    3939            FileInputStream fstream = new FileInputStream(path);
     
    4141            BufferedReader br = new BufferedReader(new InputStreamReader(in));
    4242
    43             Set<String> vertex = new HashSet<String>();
    44 
    4543            String read;
    4644            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]);
    5450                    edge++;
    5551                }
Note: See TracChangeset for help on using the changeset viewer.