forked from HEXOGEN616/MySearchEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Record.java
95 lines (80 loc) · 1.85 KB
/
Record.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.*;
public class Record
{
private String term;
private Hashtable<String, Integer> docIdTfList;
private int df;
private double idf;
public Record()
{
term = "";
docIdTfList = new Hashtable<String, Integer>();
df = 0;
idf = 0.0;
}
public Record(String newTerm, Hashtable<String, Integer> newDocIdTfList, int newDf, double newIdf)
{
term = newTerm;
docIdTfList = newDocIdTfList;
df = newDf;
idf = newIdf;
}
public String getTerm()
{
return term;
}
public void setTerm(String newTerm)
{
term = newTerm;
}
public Hashtable<String, Integer> getDocIdTfList()
{
return docIdTfList;
}
public void setDocIdTfList(Hashtable<String, Integer> newDocIdTfList)
{
docIdTfList = newDocIdTfList;
}
public int getTf(String docId)
{
int tf = docIdTfList.get(docId).intValue();
return tf;
}
public void addTfByOne(String docId)
{
int tf = docIdTfList.get(docId).intValue();
docIdTfList.put(docId, tf + 1);
}
private Integer[] setDocIdTf(int newDocId, int newTf)
{
Integer[] docIdTf = new Integer[2];
docIdTf[0] = newDocId;
docIdTf[1] = newTf;
return docIdTf;
}
public void addDocIdTf(String newDocId, int newTf)
{
docIdTfList.put(newDocId, newTf);
}
public int getDf()
{
return df;
}
public void setDf(int newDf)
{
df = newDf;
}
public double getIdf()
{
return idf;
}
public void setIdf(double newIdf)
{
idf = newIdf;
}
public double caculateIdf(int N)
{
idf = Math.log((double)N / ((double)df + 1));
return idf;
}
}