-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terrier weighting models expressed in Python (#215)
- Loading branch information
1 parent
507ae91
commit 6374c8b
Showing
14 changed files
with
408 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ ir_datasets>=0.3.2 | |
jinja2 | ||
statsmodels | ||
ir_measures==0.1.4 | ||
dill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
terrier-python-helper/src/main/java/org/terrier/python/CallableWeightingModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.terrier.python; | ||
import org.terrier.matching.models.WeightingModel; | ||
import org.terrier.structures.postings.Posting; | ||
import org.terrier.structures.EntryStatistics; | ||
import org.terrier.structures.CollectionStatistics; | ||
import java.io.IOException; | ||
import java.io.ObjectStreamException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.nio.ByteBuffer; | ||
|
||
/** A weighting model class that includes a Callback interface that can be implemented in Python. | ||
*/ | ||
public class CallableWeightingModel extends WeightingModel { | ||
|
||
public static interface Callback { | ||
public double score(double keyFrequency, Posting posting, EntryStatistics entryStats, CollectionStatistics collStats); | ||
public default double score1(Posting posting, EntryStatistics entryStats, CollectionStatistics collStats) { | ||
return score(1.0d, posting, entryStats, collStats); | ||
} | ||
public ByteBuffer serializeFn(); | ||
} | ||
|
||
public Callback scoringClass; | ||
|
||
private CallableWeightingModel() {} | ||
|
||
public CallableWeightingModel(Callback _scoringClass) { | ||
scoringClass = _scoringClass; | ||
} | ||
|
||
@Override | ||
public double score(Posting p) { | ||
return scoringClass.score(super.keyFrequency, p, super.es, super.cs); | ||
} | ||
|
||
@Override | ||
public double score(double a, double b) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String getInfo() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
private void writeObject(java.io.ObjectOutputStream out) throws IOException {} | ||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {} | ||
private void readObjectNoData() throws ObjectStreamException {} | ||
} |
Oops, something went wrong.