-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdjacencyMatrix.java
More file actions
80 lines (67 loc) · 1.95 KB
/
AdjacencyMatrix.java
File metadata and controls
80 lines (67 loc) · 1.95 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
package edu.asu.irs13;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class AdjacencyMatrix {
public HashMap<Integer,TreeSet<Integer>> link;
public Set<Integer> node;
public AdjacencyMatrix(){
this.link = new HashMap<Integer,TreeSet<Integer>>();
this.node = new TreeSet<Integer>();
}
public ArrayList<ArrayList<Integer>> buildMatrix(Map<Integer,Double> doc){
ArrayList<ArrayList<Integer>> A = new ArrayList<ArrayList<Integer>>();
LinkAnalysis.numDocs = 25054;
LinkAnalysis l = new LinkAnalysis();
for(Map.Entry<Integer, Double> entry : doc.entrySet()){
Integer key = entry.getKey();
int[] out = l.getLinks(key);
int[] in = l.getCitations(key);
TreeSet<Integer> matrix;
if(link.containsKey(key))
matrix = link.get(key);
else
matrix=new TreeSet<Integer>();
for(int j=0; j< out.length ; j++){
matrix.add(out[j]);
node.add(out[j]);
}
link.put(entry.getKey(), matrix);
node.add(key);
TreeSet<Integer> outbound=new TreeSet<Integer>();
outbound.add(key);
for(int i=0; i< in.length; i++){
node.add(in[i]);
if(link.containsKey(in[i]))
outbound.addAll(link.get(in[i]));
link.put(in[i],outbound);
}
}
/* Constructing the adjacency matrix*/
Iterator<Integer> it = node.iterator();
while(it.hasNext()){
Integer key = it.next();
ArrayList<Integer> tmp = new ArrayList<Integer>();
if(link.containsKey(key)){
Iterator<Integer> iter = node.iterator();
TreeSet<Integer> t = link.get(key);
while(iter.hasNext()){
Integer column = iter.next();
if(t.contains(column))
tmp.add(1);
else
tmp.add(0);
}
}
else{
for(int i=0; i<node.size(); i++)
tmp.add(0);
}
A.add(tmp);
}
return A;
}
}