1. Place the HANLP data (including dictionaries and models) on the HDFs and configure the root path in the project configuration file hanlp.properties, for example:
root=hdfs://localhost:9000/tmp/
2. Implement Com.hankcs.hanlp.corpus.io.IIOAdapter Interface:
public static class Hadoopfileioadapter implements Iioadapter {
@Override public
InputStream Open (String path) Throws IOException {
Configuration conf = new Configuration ();
FileSystem fs = Filesystem.get (uri.create (path), conf);
Return Fs.open (new path);
}
@Override Public
outputstream Create (String path) throws IOException {
Configuration conf = new Configuration ();
filesystem fs = Filesystem.get (uri.create (path), conf);
OutputStream out = fs.create (new path);
return out;
}
3. Set Ioadapter, create word breaker:
private static Segment Segment;
static {
HanLP.Config.IOAdapter = new Hadoopfileioadapter ();
Segment = new Crfsegment ();
}
Then, you can use segment to spark in the operation of the word.