-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimporter.java
81 lines (69 loc) · 2.24 KB
/
importer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class importer {
//reads in information from external file and returns it as a connected network
public Graph ReadNetwork(String filename, int datanum){
Graph network = new Graph();
try{
FileReader file_reader = new FileReader(new File(filename));
BufferedReader buf_reader = new BufferedReader(file_reader);
String line = "";
int count = 0;
while((line = buf_reader.readLine()) != null && count<datanum){
String[] data = line.split("\t"); // in the input file, attributes are separated by "\t"
String name = data[0];
String connection = data[1];
//if we havent seen these names before we make new vertexes
if(network.isNew(name)){
network.newVertex(name);
}
if(network.isNew(connection)){
network.newVertex(connection);
}
//we then connect these vertexes
network.addAdjVertex(name, connection);
network.addAdjVertex(connection, name);
count++;
//provides a progress bar for larger input sizes
if(count%(datanum/10) == 0){
int percent = 10*(count/(datanum/10));
System.out.print("..." + percent +"%");
}
}
buf_reader.close();
}
catch(IOException e){
e.printStackTrace();
}
System.out.println();
return network;
}//end ReadNetwork
//reads in the file for the find_friends.txt, returns it as an array of names
public String[] ReadFinder(String filename, int datanum){
String[] friends = new String[10];
try{
FileReader file_reader = new FileReader(new File(filename));
BufferedReader buf_reader = new BufferedReader(file_reader);
String line = "";
int count = 0;
int position=0;
while((line = buf_reader.readLine()) != null && count<datanum){
String[] data = line.split("\t"); // in the input file, attributes are separated by ","
String name = data[0];
String connection = data[1];
friends[position] = name;
position++;
friends[position] = connection;
position++;
count++;
}
buf_reader.close();
}
catch(IOException e){
e.printStackTrace();
}
return friends;
}//end ReadFinder
}//end importer