当前位置: 首页>>代码示例>>Java>>正文


Java DetectorFactory.loadProfile方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:exciteproject,项目名称:refext,代码行数:27,代码来源:LanguageAnalyzer.java

示例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();
}
 
开发者ID:ailab-uniud,项目名称:distiller-CORE,代码行数:34,代码来源:CybozuLanguageDetectorAnnotator.java

示例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);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:LangDetectLanguageIdentifierUpdateProcessorFactory.java

示例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);
    }
}
 
开发者ID:ShahNami,项目名称:Speech,代码行数:19,代码来源:SpeechFrame.java

示例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);
    }
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:21,代码来源:LanguageDetector.java

示例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());
    }
 
开发者ID:box,项目名称:mojito,代码行数:41,代码来源:LanguageDetectionService.java

示例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();
	}
}
 
开发者ID:MKLab-ITI,项目名称:simmo-stream-manager,代码行数:11,代码来源:LanguageDetector.java

示例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);
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:LangDetectLanguageIdentifierUpdateProcessorFactory.java

示例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();
	}
}
 
开发者ID:computermacgyver,项目名称:twitter-mapred,代码行数:35,代码来源:LanguageClassificationService.java

示例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();
	}
}
 
开发者ID:weizh,项目名称:geolocator-3.0,代码行数:11,代码来源:LangDetector.java

示例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;
}
 
开发者ID:deezer,项目名称:weslang,代码行数:16,代码来源:LanguageDetectionFilter.java

示例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());
}
 
开发者ID:diachron,项目名称:quality,代码行数:8,代码来源:CorrectLanguageTagTest.java

示例13: init

import com.cybozu.labs.langdetect.DetectorFactory; //导入方法依赖的package包/类
public void init(String profileDirectory) throws LangDetectException {
    DetectorFactory.loadProfile(profileDirectory);
}
 
开发者ID:NERD-project,项目名称:nerd-api,代码行数:4,代码来源:TDocument.java


注:本文中的com.cybozu.labs.langdetect.DetectorFactory.loadProfile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。