A WordFeaturizer is just this interface:
trait WordFeaturizer[W] {
def anchor(words: IndexedSeq[W]):WordFeatureAnchoring[W]
}
and WordFeatureAnchoring is just this interface:
trait WordFeatureAnchoring[W] {
def words: IndexedSeq[W]
def featuresForWord(pos: Int):Array[Feature]
}
So you want something like:
case class MyFeature(f: String) extends Feature
class MyFeaturizer(features: Map[String, Seq[String]]) extends WordFeaturizer[String] {
def anchor(w: IndexedSeq[W]) = new WordFeatureAnchoring[String] {
def words = w
def featuresForWord(pos: Int) = if(pos < 0 || pos >= length) Array.empty else features(words(pos)).map(MyFeature).toArray
}
}