/
striping.java
95 lines (84 loc) · 3.22 KB
/
striping.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
import java.util.Map; // Superclass of HashMap
import java.util.TreeMap; // A container that supports quick retrieval
import java.util.Iterator;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.StringTokenizer;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
public class striping {
public static void main(String argv[])
{
try{
BufferedReader buf1 = new BufferedReader(new FileReader("./index/pIndex"));
FileOutputStream out=new FileOutputStream("finalindex");
PrintStream p = new PrintStream(out);
String nline1,nline2,term1,term2,term3,term,t1,t2;
StringBuffer sbuff = new StringBuffer();
StringBuffer sbuff1;
long df,postings=0,line=0;
String []id;int flag=0;
while(true)
{
nline1=buf1.readLine();
// System.out.println(nline1);
if(nline1==null) break;
line++;
String[] words = nline1.split(" ");
String search_word = words[0];
char ch = search_word.charAt(0);
//System.out.println("c"+ch);
id = words[1].split(",");
df = id.length;
flag=0;
sbuff1 = new StringBuffer(); //System.out.println(df);
if(df>30000&&((ch=='t')||ch=='o'||ch=='c'))
{
int count=0;postings=0;
System.out.println("before df"+df+";line"+line); // System.out.println("here\n");
while(count<df)
{
String temp1=id[count];
String temp[]=temp1.split(":");
int t=Integer.parseInt(temp[1]);
// System.out.println("t:"+t);
if(t!=1)
{
if(flag==0)
{
// System.out.println("here\n");
sbuff1.append(search_word);
sbuff1.append(" ");
sbuff1.append(temp1);
flag=1;
}
else
{
sbuff1.append(",");
sbuff1.append(temp1);
postings++;
}
}
count++;
}
//System.out.println(sbuff1);
System.out.println("postings size after:"+postings+";line"+line);
p.println(sbuff1.toString());
p.flush();
}
else
{
p.println(nline1);
p.flush();
}
}
}
catch(IOException E){}
}
}