本文整理汇总了Java中com.cybozu.labs.langdetect.DetectorFactory.loadProfile方法的典型用法代码示例。如果您正苦于以下问题:Java DetectorFactory.loadProfile方法的具体用法?Java DetectorFactory.loadProfile怎么用?Java DetectorFactory.loadProfile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cybozu.labs.langdetect.DetectorFactory
的用法示例。
在下文中一共展示了DetectorFactory.loadProfile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LanguageAnalyzer
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public LanguageAnalyzer() throws LangDetectException, IOException {
// solution for loading detector profiles from jar taken from:
// http://stackoverflow.com/a/15332031
String dirname = "profiles/";
Enumeration<URL> en = Detector.class.getClassLoader().getResources(dirname);
List<String> profiles = new ArrayList<>();
if (en.hasMoreElements()) {
URL url = en.nextElement();
JarURLConnection urlcon = (JarURLConnection) url.openConnection();
try (JarFile jar = urlcon.getJarFile();) {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
String entry = entries.nextElement().getName();
if (entry.startsWith(dirname)) {
try (InputStream in = Detector.class.getClassLoader().getResourceAsStream(entry);) {
profiles.add(IOUtils.toString(in, Charset.defaultCharset()));
}
}
}
}
}
if (DetectorFactory.getLangList().isEmpty()) {
DetectorFactory.loadProfile(profiles);
}
}
示例2: detect
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
/**
* Wraps the Cybozu lybrary and detects the language over a specified
* text.
*
* @param text the text to analyze.
* @return the code of the language detected
* @throws LangDetectException when the model can't be loaded
*/
public String detect(String text) throws LangDetectException {
if (detector == null) {
// retrieve the language database embedded in the jar
// load the models inside an array then put them in
// the library
String[] models = new String[profiles.length];
for (int i = 0; i < profiles.length; i++) {
InputStream s = getClass().getClassLoader().
getResourceAsStream("cybozu/" + profiles[i]);
try {
models[i] = IOUtils.toString(s, "UTF-8");
} catch (IOException ex) {
Logger.getLogger(CybozuLanguageDetectorAnnotator.class.getName()).log(
Level.SEVERE, "Cannot load cybozu model " + profiles[i], ex);
}
}
DetectorFactory.loadProfile(Arrays.asList(models));
}
detector = DetectorFactory.create();
detector.append(text);
return detector.detect();
}
示例3: loadData
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public static synchronized void loadData() throws IOException, LangDetectException {
if (loaded) {
return;
}
loaded = true;
List<String> profileData = new ArrayList<String>();
Charset encoding = Charset.forName("UTF-8");
for (String language : languages) {
InputStream stream = LangDetectLanguageIdentifierUpdateProcessor.class.getResourceAsStream("langdetect-profiles/" + language);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, encoding));
profileData.add(new String(IOUtils.toCharArray(reader)));
reader.close();
}
DetectorFactory.loadProfile(profileData);
DetectorFactory.setSeed(0);
}
示例4: SpeechFrame
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
/**
* Creates new form speechFrame
*/
public SpeechFrame() {
try {
//System.out.println(db.toString());
initComponents();
txtLog.setEnabled(false);
cbxEditMode.setSelected(false);
btnSave.setEnabled(false);
btnDelete.setEnabled(false);
setStatus(bundle.getString("TO START, CLICK ON 'NEW LOG'"));
//System.out.println(Constants.PATH_TO_PROFILES);
DetectorFactory.loadProfile(Constants.PATH_TO_PROFILES);
} catch (LangDetectException ex) {
Logger.getLogger(SpeechFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例5: initProfiles
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
/**
* Initialise the language profiles needed by the detector. This
* initialisation has to be performed only once.
*/
private void initProfiles() {
PathMatchingResourcePatternResolver resolver =
new PathMatchingResourcePatternResolver();
List<String> profiles = new ArrayList<>();
DetectorFactory.setSeed(0L);
try {
for (Resource rs : resolver.getResources(profilePath)) {
StringWriter writer = new StringWriter();
IOUtils.copy(rs.getInputStream(), writer);
profiles.add(writer.toString());
}
DetectorFactory.loadProfile(profiles);
} catch (IOException | LangDetectException ex) {
LOGGER.warn(ex);
}
}
示例6: LanguageDetectionService
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public LanguageDetectionService() {
if (DetectorFactory.getLangList().isEmpty()) {
logger.debug("Initialize langdetect with profiles");
List<String> jsonProfiles = new ArrayList<>();
Resource[] resources;
try {
PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
resources = pathMatchingResourcePatternResolver.getResources("profiles/*");
} catch (IOException ex) {
throw new RuntimeException("Cannot get the list of resources maching langdetect profiles", ex);
}
for (Resource resource : resources) {
String filename = resource.getFilename();
logger.debug("Add profile for: {}", filename);
try {
jsonProfiles.add(Resources.toString(resource.getURL(), StandardCharsets.UTF_8));
} catch (Exception e) {
throw new RuntimeException("Cannot load langdetect profile for " + filename, e);
}
}
try {
logger.debug("Load profiles");
DetectorFactory.loadProfile(jsonProfiles);
} catch (LangDetectException lde) {
throw new RuntimeException("Cannot load langdetect profiles", lde);
}
} else {
logger.debug("langdetect profiles are already initialized");
}
logger.debug("Sets langdetect supported languages");
supportedLanguages = Collections.unmodifiableList(DetectorFactory.getLangList());
}
示例7: LanguageDetector
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public LanguageDetector(Configuration configuration) {
super(configuration);
String profileDirectory = configuration.getParameter("profileDirectory",
"profiles.sm");
try {
DetectorFactory.loadProfile(profileDirectory);
} catch (LangDetectException e) {
e.printStackTrace();
}
}
示例8: loadData
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public static synchronized void loadData() throws IOException, LangDetectException {
if (loaded) {
return;
}
loaded = true;
List<String> profileData = new ArrayList<>();
for (String language : languages) {
InputStream stream = LangDetectLanguageIdentifierUpdateProcessor.class.getResourceAsStream("langdetect-profiles/" + language);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
profileData.add(new String(IOUtils.toCharArray(reader)));
reader.close();
}
DetectorFactory.loadProfile(profileData);
DetectorFactory.setSeed(0);
}
示例9: LanguageClassificationService
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public LanguageClassificationService() {
try {
DetectorFactory.clear();
URL jar=DetectorFactory.class.getProtectionDomain().getCodeSource().getLocation();
ZipInputStream zip = new ZipInputStream(jar.openStream());
ZipEntry ze = null;
List<String> profiles = new ArrayList<String>();
while( ( ze = zip.getNextEntry() ) != null ) {
if ( ze.getName().startsWith(PROFILES_FOLDER)) {
InputStream is=DetectorFactory.class.getResourceAsStream("/" + ze.getName());
if (is!=null) {
BufferedReader br= new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
line=sb.toString();
if (line!=null && !"".equals(line)) {
profiles.add(sb.toString());
}
br.close();
}
}
}
DetectorFactory.loadProfile(profiles);
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: LangDetector
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public LangDetector(String f) {
try {
DetectorFactory.loadProfile(f);
System.err.println("Language detector contructor is run.");
} catch (LangDetectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例11: setConf
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void setConf(Configuration conf) {
if (this.conf == null) {
try {
DetectorFactory.loadProfile(conf.get("langdetect.profile.dir"));
textsize_upper_limit = conf.getInt("langdetect.textsize", TEXTSIZE_UPPER_LIMIT_DEFAULT);
} catch (LangDetectException e) {
// afterward throw when filter() is called
cause = e;
}
}
this.conf = conf;
}
示例12: main
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public static void main (String [] args) throws LangDetectException{
DetectorFactory.loadProfile("/Users/jeremy/Documents/Workspaces/eis/quality/lod-qualitymetrics/lod-qualitymetrics-intrinsic/src/test/resources/profiles");
Detector detector = DetectorFactory.create();
detector.append("apple I eat");
System.out.println(detector.detect());
}
示例13: init
import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public void init(String profileDirectory) throws LangDetectException {
DetectorFactory.loadProfile(profileDirectory);
}