Example usage for opennlp.tools.doccat DoccatModel DoccatModel

List of usage examples for opennlp.tools.doccat DoccatModel DoccatModel

Introduction

In this page you can find the example usage for opennlp.tools.doccat DoccatModel DoccatModel.

Prototype

public DoccatModel(URL modelURL) throws IOException 

Source Link

Usage

From source file:com.tamingtext.classifier.maxent.TestMaxent.java

private static void execute(File[] inputFiles, File modelFile) throws IOException, FileNotFoundException {
    //<start id="maxent.examples.test.setup"/> 
    NameFinderFeatureGenerator nffg //<co id="tmx.feature"/>
            = new NameFinderFeatureGenerator();
    BagOfWordsFeatureGenerator bowfg = new BagOfWordsFeatureGenerator();

    InputStream modelStream = //<co id="tmx.modelreader"/>
            new FileInputStream(modelFile);
    DoccatModel model = new DoccatModel(modelStream);
    DocumentCategorizer categorizer //<co id="tmx.categorizer"/>
            = new DocumentCategorizerME(model, nffg, bowfg);
    Tokenizer tokenizer = SimpleTokenizer.INSTANCE;

    int catCount = categorizer.getNumberOfCategories();
    Collection<String> categories = new ArrayList<String>(catCount);
    for (int i = 0; i < catCount; i++) {
        categories.add(categorizer.getCategory(i));
    }//from   w w w. ja v  a  2s  . c  o  m
    ResultAnalyzer resultAnalyzer = //<co id="tmx.results"/>
            new ResultAnalyzer(categories, "unknown");
    runTest(inputFiles, categorizer, tokenizer, resultAnalyzer); //<co id="tmx.run"/>
    /*<calloutlist>
    <callout arearefs="tmx.feature">Setup Feature Generators</callout>
    <callout arearefs="tmx.modelreader">Load Model</callout>
    <callout arearefs="tmx.categorizer">Create Categorizer</callout>
    <callout arearefs="tmx.results">Prepare Result Analyzer</callout>
    <callout arearefs="tmx.run">Execute Test</callout>
    </calloutlist>*/
    //<end id="maxent.examples.test.setup"/>
}

From source file:org.wso2.uima.collectionProccesingEngine.analysisEngines.TrafficLevelAnalyser.java

@Override
public void initialize(UimaContext ctx) throws ResourceInitializationException {
    super.initialize(ctx);
    InputStream docStream = null;
    try {/*from w  ww  .  java2s  . c om*/

        docStream = getContext().getResourceAsStream("DoccatModel");
        DoccatModel doccatModel = new DoccatModel(docStream);
        documentCategorizer = new DocumentCategorizerME(doccatModel);
        docStream.close();

    } catch (Exception e) {
        logger.error("Error occurs when initializing resources");
        throw new ResourceInitializationException(e);
    } finally {
        IOUtils.closeQuietly(docStream);
        logger.info(TrafficLevelAnalyser.class.getSimpleName() + " Analysis Engine initialized successfully");
    }
}