-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageEntry.java
More file actions
132 lines (132 loc) · 2.75 KB
/
PageEntry.java
File metadata and controls
132 lines (132 loc) · 2.75 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.*;
import java.io.*;
public class PageEntry
{
public PageIndex pi=new PageIndex();
public AvlTree avtree=new AvlTree();
String na;
int wi,wi1;
float grp;
public PageEntry(String pageName)
{
try
{
na=pageName;
FileInputStream pe=new FileInputStream("webpages/"+pageName);
Scanner s=new Scanner(pe);
Scanner hs,hs2;
String w;
String[] sa={"a","an","the","they","these","this","for","is","are","was","of","or","and","does","will","whose"};
wi=0;
wi1=0;
while (s.hasNextLine())
{
hs=new Scanner(s.nextLine());
while (hs.hasNext())
{
hs2=new Scanner(modify(hs.next()));
while (hs2.hasNext())
{
w=hs2.next();
w=w.toLowerCase();
wi1++;
if (w.toLowerCase().equals("stacks"))
{
w="stack";
}
else if (w.toLowerCase().equals("applications"))
{
w="application";
}
else if (w.toLowerCase().equals("structures"))
{
w="structure";
}
int f=0;
for (int j=0;j<sa.length;j++)
{
if (w.equals(sa[j]))
{
f=1;
}
}
if (f==0)
{
wi++;
Position pos=new Position(this,wi1);
pi.addPositionForWord(w,pos);
}
}
}
}
Node<WordEntry> n1=pi.getWordEntries().header.getNext();
Node<Position> n2;
while (n1!=pi.getWordEntries().trailer)
{
n2=n1.getElement().getAllPositionsForThisWord().header.getNext();
while (n2!=n1.getElement().getAllPositionsForThisWord().trailer)
{
avtree.insert(n2.getElement(),n1.getElement().str);
n2=n2.getNext();
}
n1=n1.getNext();
}
}
catch(FileNotFoundException e1)
{
System.out.println("file not found");
}
}
int totalWords()
{
return wi;
}
float getRelevanceOfPage(String str[], boolean doTheseWordsRepresentAPhrase)
{
return grp;
}
String modify(String a)
{
char[] ca={'{','}','[',']','<','>','=','(',')','.',',',';','"','?','#','!','-',':','\''};
char[] st=new char[a.length()];
String re="";
for (int k=0;k<a.length();k++)
{
st[k]=a.charAt(k);
}
for (int i=0;i<a.length();i++)
{
if ((65<=(int)a.charAt(i))&&((int)a.charAt(i)<=90))
{
st[i]=(char)(((int)a.charAt(i))+32);
}
for (int j=0;j<ca.length;j++)
{
if (a.charAt(i)==ca[j])
{
st[i]=' ';
}
}
}
for (int k=0;k<st.length;k++)
{
re=re+st[k];
}
if (a.toLowerCase().equals("stacks"))
{
a="stack";
return a;
}
else if (a.toLowerCase().equals("applications"))
{
a="application";
return a;
}
else if (a.toLowerCase().equals("structures"))
{
a="structure";
return a;
}
return re;
}
}