-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvertedPageIndex.java
107 lines (100 loc) · 3.42 KB
/
InvertedPageIndex.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
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
import java.util.*;
import java.io.*;
public class InvertedPageIndex {
MyHashTable ftable = new MyHashTable();
Myset<PageEntry> set = new Myset<PageEntry>();
public InvertedPageIndex(){
}
public void addPage(PageEntry p) throws IOException{
PageEntry newEntry = new PageEntry(p.fileName);
set.addElement(p);
for(int uq=0;uq<p.getPageIndex().wordEntry.getSize();uq++){
// System.out.println("for loop of addPage");
ftable.addPositionsForWord(p.getPageIndex().wordEntry.list1.get(uq));
}
}
public Myset<PageEntry> getPagesWhichContainWord(String str1){
//System.out.println("getPagesWhichContainWord me hu");
Myset<PageEntry> x = new Myset<PageEntry>();
int fuck = ftable.getHashIndex(str1);
//System.out.println(fuck);
int cool = ftable.hashtable[fuck].list1.size();
//System.out.println(cool);
for(int bc=0;bc<cool;bc++){
if(ftable.hashtable[fuck].getElem(bc).str.equals(str1)){
WordEntry xd = ftable.hashtable[fuck].getElem(bc);
MyLinkedList<Position> pos = xd.getAllPositionsForThisWord();
for(int xp=0;xp<pos.getSize();xp++){
Position xs = pos.getElem(xp);
if(x.isMember(xs.getPageEntry())!=true){
x.addElement(xs.getPageEntry());
}
}
}
}
//System.out.println(x.set1.list1.size());
return x;
}
public Myset<PageEntry> getPagesWhichContainAllWords(String drf[]){
int c = drf.length;
Myset<PageEntry> xy = new Myset<PageEntry>();
xy = getPagesWhichContainWord(drf[0]);
for(int vg=1;vg<c;vg++){
xy = xy.intersection(getPagesWhichContainWord(drf[vg]), xy);
}
return xy;
}
public Myset<PageEntry> getPagesWhichContainAtLeastOneWord(String drf[]){
int c = drf.length;
Myset<PageEntry> xy = new Myset<PageEntry>();
xy = getPagesWhichContainWord(drf[0]);
for(int k=1;k<drf.length;k++){
xy = xy.union(getPagesWhichContainWord(drf[k]), xy);
}
return xy;
}
public Myset<PageEntry> getPagesWhichContainPhrase(String drf[]){
//System.out.println("imside the func");
Myset<PageEntry> xy = new Myset<PageEntry>();
xy = getPagesWhichContainWord(drf[0]);
for(int vg=1;vg<drf.length;vg++){
xy = xy.intersection(getPagesWhichContainWord(drf[vg]), xy);
}
Myset<PageEntry> thug = new Myset<PageEntry>();
for(int nj=0;nj<xy.getSizeSet();nj++){
//System.out.println("first for");
for(int z=0;z<xy.getElement(nj).getPageIndex().getWordEntries().list1.size();z++){
//System.out.println("second for");
if(xy.getElement(nj).getPageIndex().getWordEntries().getElem(z).str.equals(drf[0])){
// System.out.println("first if");
MyLinkedList<WordEntry> kl = new MyLinkedList<WordEntry>();
for(int i=0;i<drf.length;i++){
if((z+i)<xy.getElement(nj).getPageIndex().getWordEntries().list1.size())
kl.addElem(xy.getElement(nj).getPageIndex().getWordEntries().getElem(z+i));
else{
kl=null;
break;
}
}
// System.out.println(kl.list1.size());
if(kl!=null){
int k=0;
for(int y=0;y<drf.length;y++){
// System.out.println("kl wala for");
if(kl.getElem(y).str.equals(drf[y])){
// System.out.println("seonf if");
k++;
// System.out.println(k);
// System.out.println(drf.length);
}
}
if(k==drf.length){
thug.addElement(xy.getElement(nj));
}
}
}
}
}
return thug;
}
}