Java Reference
In-Depth Information
}
}
The output is as follows:
Type: time Entity: [8:00] Score: 1.0
Type: time Entity: [4:30] Score: 1.0+95
Alternately, we can declare a simple class to encapsulate the regular expression, which
lends itself for reuse in other situations. Next, the TimeRegexChunker class is de-
clared and it supports the identification of time entities:
public class TimeRegexChunker extends RegExChunker {
private final static String TIME_RE =
"(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?";
private final static String CHUNK_TYPE = "time";
private final static double CHUNK_SCORE = 1.0;
public TimeRegexChunker() {
super(TIME_RE,CHUNK_TYPE,CHUNK_SCORE);
}
}
To use this class, replace this section's initial declaration of chunker with the following
declaration:
Chunker chunker = new TimeRegexChunker();
The output will be the same as before.
Search WWH ::




Custom Search