public class classifyTweet {
public static class MapClass
extends Mapper<LongWritable, Text, Text, Text> {
static final Configuration conf = new Configuration();
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
StandardNaiveBayesClassifier classifier = new StandardNaiveBayesClassifier(NaiveBayesModel.materialize(new Path(modelPath), conf));
}
}
}
我只想初始化分类器变量一次,materialize 方法抛出 IOEception,如果我在 map 方法之外声明它并且像配置对象初始化一样,它会给出 IOException 的编译错误。我怎样才能只初始化一次?