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
|
package com.wcohen.ss.expt;
import com.wcohen.ss.*;
import com.wcohen.ss.api.*;
import java.util.Collections;
/**
* Train a StringDistanceLearner.
*/
public class BasicTeacher extends StringDistanceTeacher
{
private DistanceInstanceIterator distanceExamplePool;
private DistanceInstanceIterator distanceInstancePool;
private StringWrapperIterator wrapperIterator;
/** Create a teacher from a blocker and a dataset.
* Will train from all blocked pairs.
*/
public BasicTeacher(final Blocker blocker,final MatchData data)
{
blocker.block(data);
wrapperIterator = data.getIterator();
distanceInstancePool = new BasicDistanceInstanceIterator(Collections.EMPTY_SET.iterator());
distanceExamplePool =
new DistanceInstanceIterator() {
private int cursor=0;
public boolean hasNext() { return cursor<blocker.size(); }
public Object next() { return blocker.getPair( cursor++ ); }
public void remove() { throw new UnsupportedOperationException(); }
public DistanceInstance nextDistanceInstance() { return (DistanceInstance)next();}
};
}
/**
* Create a teacher using specific values for the various iterators.
*/
public BasicTeacher(
StringWrapperIterator wrapperIterator,
DistanceInstanceIterator distanceInstancePool,
DistanceInstanceIterator distanceExamplePool
)
{
this.wrapperIterator = wrapperIterator;
this.distanceInstancePool = distanceInstancePool;
this.distanceExamplePool = distanceExamplePool;
}
public StringWrapperIterator stringWrapperIterator()
{
return wrapperIterator;
}
public DistanceInstanceIterator distanceInstancePool()
{
return distanceInstancePool;
}
public DistanceInstanceIterator distanceExamplePool()
{
return distanceExamplePool;
}
public DistanceInstance labelInstance(DistanceInstance distanceInstance)
{
return distanceInstance;
}
public boolean hasAnswers()
{
return true;
}
}
|