@@ -25,8 +25,6 @@ public class InvertedImageIndex {
25
25
ListMultimap <String , Image > mainConceptIndex = ArrayListMultimap .create ();
26
26
ListMultimap <String , Image > mainKeywordIndex = ArrayListMultimap .create ();
27
27
28
- HashMap <String , Integer > concepts = new HashMap <String , Integer >();
29
-
30
28
public InvertedImageIndex (){}
31
29
32
30
public InvertedImageIndex (ImageCollection iCollection ){
@@ -44,13 +42,6 @@ public InvertedImageIndex(ImageCollection iCollection){
44
42
String conceptId = conceptEntry .getKey ();
45
43
Concept concept = conceptEntry .getValue ();
46
44
47
- // maintain a list of TF for concepts
48
- if (!concepts .containsKey (conceptId )) {
49
- concepts .put (conceptId , 0 );
50
- } else {
51
- concepts .put (conceptId , concepts .get (conceptId ) + 1 );
52
- }
53
-
54
45
// drop concepts where the score is 0
55
46
if (concept .getScore () > 0.0 ) {
56
47
this .putConceptImage (conceptId , image );
@@ -202,18 +193,17 @@ public List<Image> get() {
202
193
}
203
194
});
204
195
205
- double numConcepts = concepts .size ();
206
196
for (String conceptId : conceptList .keySet ()) {
207
197
208
- double weight = conceptList .get (conceptId ) * calculateIDF (numConcepts , concepts .get (conceptId ));
198
+ double weight = conceptList .get (conceptId ) * calculateIDF (mainConceptIndex . size (), mainConceptIndex .get (conceptId ). size ( ));
209
199
ranking = WeightedScorer .getInstance ().combine (ranking , findImageByConcept (conceptId , imageCollection ), weight );
210
200
211
201
}
212
202
return ranking ;
213
203
}
214
204
215
205
private double calculateIDF (double N , double n_t ) {
216
- return Math .log (N /n_t );
206
+ return Math .log (N /( n_t + 1 ) );
217
207
}
218
208
219
209
/**
0 commit comments