-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchPostingList.java
executable file
·83 lines (82 loc) · 2.25 KB
/
fetchPostingList.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
import java.io.*;
import java.util.*;
public class fetchPostingList{
private String file;
private String word;
public fetchPostingList(String file)
{
this.file = file;
}
public TreeMap<String,String> run(HashSet<String> word) throws IOException
{
String ans = "";
TreeMap<String,String> newt = new TreeMap<String,String>();
for(String s1:word){
String a2f = "$.txt";
if(s1.length()!=1)
a2f = s1.substring(0,2);
String a1f = "" + s1.charAt(0);
String file1 = "index/"+a1f+".txt";
String file2 = "index/"+a2f+".txt";
File f1 = new File(file1);
File f2 = new File(file2);
if(f2.exists() && !f2.isDirectory())
{
file = file2;
}
else if(f1.exists() && !f1.isDirectory())
{
file = file1;
}
else
{
word.remove(s1);
continue;
}
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
for(String line; (line = br.readLine()) != null; ) {
String line_head = line.substring(0,line.indexOf(':'));
String line_foot = line.substring(line.indexOf(':')+1);
if(word.contains(line_head))
{
newt.put(line_head, line_foot);
}
// process the line.
}
// line is not visible here.
}
}
//System.out.println(newt.toString());
return newt;
}
public TreeMap<String,String> fetchDocTitle(List<String> word) throws IOException
{
String ans = "";
TreeMap<String,String> newt = new TreeMap<String,String>();
try(BufferedReader br = new BufferedReader(new FileReader("temp/mappings.txt"))) {
for(String line; (line = br.readLine()) != null; ) {
String line_head = line.substring(0,line.indexOf(' '));
String line_foot = line.substring(line.indexOf(' ')+1);
if(word.contains(line_head))
{
newt.put(line_head, line_foot);
}
// process the line.
}
// line is not visible here.
}
//System.out.println(newt.toString());
return newt;
}
public static String readFromFile(final File file, long byteStart,
int length) throws IOException {
final FileInputStream fis = new FileInputStream(file);
fis.skip(byteStart);
final BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = br.readLine();
line =line.substring(0,line.indexOf("$"));
br.close();
fis.close();
return line;
}
}