-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageIndex.java
executable file
·79 lines (60 loc) · 1.47 KB
/
PageIndex.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
public class PageIndex {
MyLinkedList<WordEntry> WordEntries;
double score;
public PageIndex() {
// TODO Auto-generated constructor stub
this.WordEntries=new MyLinkedList<WordEntry>();
score=0.00;
}
public void addPositionForWord(String str,Position p) throws LinkedListOutofBoundsException
{
int i=0;
while(i<WordEntries.getSize())
{
if(WordEntries.get(i).getData().getWord().equals(str))
{
WordEntries.get(i).getData().addPosition(p);
return;
}
i++;
}
WordEntry toAdd=new WordEntry(str);
toAdd.addPosition(p);
this.WordEntries.add(toAdd);
}
public MyLinkedList<WordEntry> getWordEntries()
{
return this.WordEntries;
}
public double getScore(String word)
{
if(score!=0.00){return score;}
Node<WordEntry> it=this.WordEntries.head;
while(it.getData()!=null && !it.getData().getWord().equals(word))
{
it=it.next;
}
if(it.getData()==null)
{
return 0;
}
else
{
WordEntry we=it.getData();
MyLinkedList<Position> temp=we.getAllPositionsForThisWord();
Node<Position> iter=temp.head;
double sum=0.0000000;
while(iter.getData()!=null)
{
if(iter.getData().getPageEntry().getPageIndex().equals(this))
{
double t=( (iter.getData().getWordIndex() ) * (iter.getData().getWordIndex()) );
sum += 1.0/t;
}
iter=iter.next;
}
score=sum;
return sum;
}
}
}