Skip to content

Instantly share code, notes, and snippets.

@jjfiv
Created May 30, 2014 18:05
Show Gist options
  • Select an option

  • Save jjfiv/48ab448f215a3e5e0909 to your computer and use it in GitHub Desktop.

Select an option

Save jjfiv/48ab448f215a3e5e0909 to your computer and use it in GitHub Desktop.
example class
package edu.umass.ciir.proteus.athena.experiment.iter;
import org.lemurproject.galago.core.retrieval.iterator.*;
import org.lemurproject.galago.core.retrieval.processing.ScoringContext;
import org.lemurproject.galago.core.retrieval.query.AnnotatedNode;
import org.lemurproject.galago.core.retrieval.query.NodeParameters;
import org.lemurproject.galago.tupleflow.Parameters;
import java.io.IOException;
/**
* @author jfoley.
*/
public class LengthThresholdIterator extends TransformIterator implements IndicatorIterator {
private final int minLength;
private final LengthsIterator lengths;
private final int maxLength;
private ScoringContext fakeScoringContext;
public LengthThresholdIterator(NodeParameters np, LengthsIterator lengths) throws IOException {
super(lengths);
this.lengths = lengths;
this.minLength = (int) np.get("minLength", np.get("default", 2));
this.maxLength = (int) np.get("maxLength", Integer.MAX_VALUE);
this.fakeScoringContext = new ScoringContext();
}
@Override
public boolean indicator(ScoringContext c) {
int length = lengths.length(c);
return length >= minLength && length <= maxLength;
}
@Override
public boolean hasAllCandidates() {
return false;
}
@Override
public boolean hasMatch(long id) {
if(!lengths.hasMatch(id))
return false;
fakeScoringContext.document = id;
return indicator(fakeScoringContext);
}
@Override
public AnnotatedNode getAnnotatedNode(ScoringContext sc) throws IOException {
return null;
}
public static void addTo(Parameters argp) {
if(!argp.containsKey("operators")) {
argp.put("operators", new Parameters());
}
argp.getMap("operators").put("lenthresh", LengthThresholdIterator.class.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment