opennlp.tools.langdetect.LanguageDetectorModel Java Examples

The following examples show how to use opennlp.tools.langdetect.LanguageDetectorModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LanguageDetectorAndTrainingDataUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenLanguageDictionary_whenLanguageDetect_thenLanguageIsDetected() throws FileNotFoundException, IOException {
    InputStreamFactory dataIn = new MarkableFileInputStreamFactory(new File("src/main/resources/models/DoccatSample.txt"));
    ObjectStream lineStream = new PlainTextByLineStream(dataIn, "UTF-8");
    LanguageDetectorSampleStream sampleStream = new LanguageDetectorSampleStream(lineStream);
    TrainingParameters params = new TrainingParameters();
    params.put(TrainingParameters.ITERATIONS_PARAM, 100);
    params.put(TrainingParameters.CUTOFF_PARAM, 5);
    params.put("DataIndexer", "TwoPass");
    params.put(TrainingParameters.ALGORITHM_PARAM, "NAIVEBAYES");

    LanguageDetectorModel model = LanguageDetectorME.train(sampleStream, params, new LanguageDetectorFactory());

    LanguageDetector ld = new LanguageDetectorME(model);
    Language[] languages = ld.predictLanguages("estava em uma marcenaria na Rua Bruno");
    
    assertThat(Arrays.asList(languages)).extracting("lang", "confidence").contains(tuple("pob", 0.9999999950605625),
             tuple("ita", 4.939427661577956E-9), tuple("spa", 9.665954064665144E-15),
            tuple("fra", 8.250349924885834E-25));
}
 
Example #2
Source File: OpenNLPLangDetectUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void loadModel() throws IOException {
  InputStream is = null;
  try{
    if (modelFile != null) {
      is = solrResourceLoader.openResource(modelFile);
      model = new LanguageDetectorModel(is);
    }
  }
  finally{
    IOUtils.closeQuietly(is);
  }
}
 
Example #3
Source File: OpenNLPLangDetectUpdateProcessor.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public OpenNLPLangDetectUpdateProcessor(SolrQueryRequest req, SolrQueryResponse rsp,
    UpdateRequestProcessor next, LanguageDetectorModel model) {
  super(req, rsp, next);
  this.model = model;
}
 
Example #4
Source File: LanguageDetectorResource.java    From newsleak with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Gets the openNLP language detection model.
 *
 * @return the model
 */
public LanguageDetectorModel getModel() {
	return model;
}