-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkAnalysis.java
More file actions
110 lines (98 loc) · 2.45 KB
/
LinkAnalysis.java
File metadata and controls
110 lines (98 loc) · 2.45 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package edu.asu.irs13;
import java.io.*;
public class LinkAnalysis {
public static final String linksFile = "IntLinks.txt";
public static final String citationsFile = "IntCitations.txt";
public static int numDocs = 25053;
private int[][] links;
private int[][] citations;
public LinkAnalysis()
{
try
{
// Read in the links file
links = new int[numDocs][];
BufferedReader br = new BufferedReader(new FileReader(linksFile));
String s = "";
while ((s = br.readLine())!=null)
{
String[] words = s.split("->"); // split the src->dest1,dest2,dest3 string
int src = Integer.parseInt(words[0]);
if (words.length > 1 && words[1].length() > 0)
{
String[] dest = words[1].split(",");
links[src] = new int[dest.length];
for (int i=0; i<dest.length; i++)
{
links[src][i] = Integer.parseInt(dest[i]);
}
}
else
{
links[src] = new int[0];
}
}
br.close();
// Read in the citations file
citations = new int[numDocs][];
br = new BufferedReader(new FileReader(citationsFile));
s = "";
while ((s = br.readLine())!=null)
{
String[] words = s.split("->"); // split the src->dest1,dest2,dest3 string
int src = Integer.parseInt(words[0]);
if (words.length > 1 && words[1].length() > 0)
{
String[] dest = words[1].split(",");
citations[src] = new int[dest.length];
for (int i=0; i<dest.length; i++)
{
citations[src][i] = Integer.parseInt(dest[i]);
}
}
else
{
citations[src] = new int[0];
}
}
br.close();
}
catch(NumberFormatException e)
{
System.err.println("links file is corrupt: ");
e.printStackTrace();
}
catch(IOException e)
{
System.err.println("Failed to open links file: ");
e.printStackTrace();
}
}
public int[] getLinks(int docNumber)
{
return links[docNumber];
}
public int[] getCitations(int docNumber)
{
return citations[docNumber];
}
public static void main(String[] args)
{
LinkAnalysis.numDocs = 25054;
LinkAnalysis l = new LinkAnalysis();
// Find all the document numbers that doc #3 points to
System.out.print("Document number 3 points to: ");
int[] links3 = l.getLinks(100);
for(int pb:links3)
{
System.out.print(pb + ",");
}
// Find all the document numbers that point to doc #3
System.out.print("\nDocument number 3 is pointed by: ");
int[] cit3 = l.getCitations(3);
for(int pb:cit3)
{
System.out.print(pb + ",");
}
}
}