base code extracted from crf++
base code extracted from crf++