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


Java CommonTextObjectFactories.forDetectingOnLargeText方法代码示例

本文整理汇总了Java中com.optimaize.langdetect.text.CommonTextObjectFactories.forDetectingOnLargeText方法的典型用法代码示例。如果您正苦于以下问题:Java CommonTextObjectFactories.forDetectingOnLargeText方法的具体用法?Java CommonTextObjectFactories.forDetectingOnLargeText怎么用?Java CommonTextObjectFactories.forDetectingOnLargeText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.optimaize.langdetect.text.CommonTextObjectFactories的用法示例。


在下文中一共展示了CommonTextObjectFactories.forDetectingOnLargeText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initLanguageDetector

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
private void initLanguageDetector() throws IOException {
    List<LanguageProfile> languageProfiles = new LanguageProfileReader().readAllBuiltIn();
    languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
            .withProfiles(languageProfiles)
            .build();
    textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
}
 
开发者ID:victorward,项目名称:recruitervision,代码行数:8,代码来源:ParsingServiceImpl.java

示例2: QALanguageDetector

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
public QALanguageDetector() throws IOException {
	languageProfiles = new LanguageProfileReader().readAllBuiltIn();

	//build language detector:
	languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
		.withProfiles(languageProfiles)
		.build();

	//create a text object factory
	textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
}
 
开发者ID:pkiraly,项目名称:metadata-qa-api,代码行数:12,代码来源:QALanguageDetector.java

示例3: doInitialize

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
@Override
public void doInitialize(UimaContext aContext) throws ResourceInitializationException {
	try{
		List<LanguageProfile> languageProfiles = new LanguageProfileReader().readAllBuiltIn();
		languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
				.withProfiles(languageProfiles)
				.build();
		
		textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
	}catch(IOException ioe){
		throw new ResourceInitializationException(ioe);
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:14,代码来源:DocumentLanguage.java

示例4: detectLang

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
/**
 * Language detection test for each file (--detectlang option)
 * 
 * <pre>
 * usage: --detectlang -d [profile directory] -a [alpha] -s [seed] [test file(s)]
 * </pre>
 * 
 */
public void detectLang() throws IOException {
    LanguageDetector languageDetector = makeDetector();
    TextObjectFactory textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();

    for (String filename: arglist) {
        try (BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "utf-8"))) {
            TextObject textObject = textObjectFactory.create().append(is);
            List<DetectedLanguage> probabilities = languageDetector.getProbabilities(textObject);
            System.out.println(filename + ":" + probabilities);
        }
    }
}
 
开发者ID:optimaize,项目名称:language-detector,代码行数:21,代码来源:CommandLineInterface.java

示例5: LanguageIdentifier

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
public LanguageIdentifier() {
  try {
    List<LanguageProfile> profiles = loadProfiles(getLanguageCodes());
    languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
            .minimalConfidence(MINIMAL_CONFIDENCE)
            .withProfiles(profiles)
            .build();
    textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
  } catch (IOException e) {
    throw new RuntimeException("Could not set up language identifier", e);
  }
}
 
开发者ID:languagetool-org,项目名称:languagetool,代码行数:13,代码来源:LanguageIdentifier.java

示例6: lazyInitialize

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
private void lazyInitialize() {
    // lazy initialization
    if (languageDetector == null) {
        logger.debug("Initializing language detector...");
        //load all languages:
        try {
            // read built-in profiles
            this.languageProfiles = new LanguageProfileReader().readAllBuiltIn();

            // read custom profiles

            List<String> profileFileNames = new ArrayList<>();

            // prevent FileSystemNotFoundException...
            final Map<String, String> env = new HashMap<>();
            final String[] array = this.getClass().getResource("/languageProfiles").toURI().toString().split("!");
            Path path;
            FileSystem fs = null;
            if (array.length > 1) {
                fs = FileSystems.newFileSystem(URI.create(array[0]), env);
                path = fs.getPath(array[1]);
            } else {
                path = Paths.get(this.getClass().getResource("/languageProfiles").toURI());
            }

            Files.walk(path)
                    .forEach(file -> {
                        if (!Files.isDirectory(file))
                            profileFileNames.add(file.getFileName().toString());
                    });

            if (fs != null)
                fs.close();
            // according to the documentation LanguageProfileReader#readAll should not be used for files within the .jar.
            this.languageProfiles.addAll(new LanguageProfileReader().read("languageProfiles", profileFileNames));
        } catch (IOException | URISyntaxException e) {
            logger.error("Error loading language profiles", e);
        }

        this.languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard()).withProfiles(languageProfiles).build();

        this.textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
        logger.debug("... language detector initialized");
    }
}
 
开发者ID:roberterdin,项目名称:thatsapp,代码行数:46,代码来源:LanguageDetectorOptimaize.java

示例7: checkIfNonEnglish

import com.optimaize.langdetect.text.CommonTextObjectFactories; //导入方法依赖的package包/类
public static String checkIfNonEnglish(Post post){


        List<LanguageProfile> languageProfiles;
        com.optimaize.langdetect.LanguageDetector optimaizeDetector;
        org.apache.tika.language.detect.LanguageDetector tikaDetector;
        TextObjectFactory textObjectFactory;

        String dataToCheck = stripTags(stripBody(post)).replaceAll("\\p{Punct}+", "");
        try {

            languageProfiles = new LanguageProfileReader().readAllBuiltIn();
            optimaizeDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
                    .withProfiles(languageProfiles)
                    .build();
            textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
            TextObject textObject = textObjectFactory.forText(dataToCheck);
            Optional<LdLocale> lang = optimaizeDetector.detect(textObject);
            if (!lang.isPresent()) {
                if(dataToCheck.length()>50) {
                   tikaDetector = new OptimaizeLangDetector().loadModels();
                   LanguageWriter writer = new LanguageWriter(tikaDetector);
                   writer.append(dataToCheck);
                   LanguageResult result = writer.getLanguage();
                   String tikaLang = result.getLanguage();
                   writer.close();

                   if (!tikaLang.toLowerCase().equals("")) {
                       return tikaLang;
                   }
                   else{
                       return null;
                   }
                }
                else if(dataToCheck.length()<50){
                    return null;
                }
                if(checkIfNoCodeBlock(post)){
                    return "Gibberish";
                }
                return null;
            }
            return lang.get().getLanguage();
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return null;
    }
 
开发者ID:SOBotics,项目名称:Natty,代码行数:50,代码来源:CheckUtils.java


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