Each detector provides information about the issues it can find, such as an explanation of how to fix the issue, the priority, the category, etc. It also has an id which is used to persistently identify a particular type of error.
NOTE: Detectors might be constructed just once and shared between lint runs, so any per-detector state should be initialized and reset via the before/after methods. NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.After appending a target text to the {@link Detector} instance with {@link #append(Reader)} or {@link #append(String)}, the detector provides the language detection results for target text via {@link #detect()} or {@link #getProbabilities()}. {@link #detect()} method returns a single language name which has the highest probability.{@link #getProbabilities()} methods returns a list of multiple languages and their probabilities.
The detector has some parameters for language detection. See {@link #setAlpha(double)}, {@link #setMaxTextLength(int)} and {@link #setPriorMap(HashMap)}.
import java.util.ArrayList; import com.cybozu.labs.langdetect.Detector; import com.cybozu.labs.langdetect.DetectorFactory; import com.cybozu.labs.langdetect.Language; class LangDetectSample { public void init(String profileDirectory) throws LangDetectException { DetectorFactory.loadProfile(profileDirectory); } public String detect(String text) throws LangDetectException { Detector detector = DetectorFactory.create(); detector.append(text); return detector.detect(); } public ArrayListdetectLangs(String text) throws LangDetectException { Detector detector = DetectorFactory.create(); detector.append(text); return detector.getProbabilities(); } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|