Example usage for opennlp.tools.parser ParserModel ParserModel

List of usage examples for opennlp.tools.parser ParserModel ParserModel

Introduction

In this page you can find the example usage for opennlp.tools.parser ParserModel ParserModel.

Prototype

public ParserModel(URL modelURL) throws IOException 

Source Link

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpParser.java

@Override
public void initialize(UimaContext aContext) throws ResourceInitializationException {
    super.initialize(aContext);

    modelProvider = new CasConfigurableProviderBase<Parser>() {
        {//from  ww w.  ja  va 2s . c om
            setDefault(VERSION, "20120616.0");
            setDefault(GROUP_ID, "de.tudarmstadt.ukp.dkpro.core");
            setDefault(ARTIFACT_ID,
                    "de.tudarmstadt.ukp.dkpro.core.opennlp-model-parser-${language}-${variant}");

            setDefault(LOCATION, "classpath:/de/tudarmstadt/ukp/dkpro/core/opennlp/lib/"
                    + "parser-${language}-${variant}.bin");
            setDefault(VARIANT, "maxent");

            setOverride(LOCATION, modelLocation);
            setOverride(LANGUAGE, language);
            setOverride(VARIANT, variant);
        }

        @Override
        protected Parser produceResource(URL aUrl) throws IOException {
            InputStream is = null;
            try {
                is = aUrl.openStream();
                ParserModel model = new ParserModel(is);

                if (printTagSet) {
                    printTags("tagger", model.getParserTaggerModel().getPosModel());
                    printTags("parser", model.getParserChunkerModel().getChunkerModel());
                }

                return ParserFactory.create(model);
            } finally {
                closeQuietly(is);
            }
        }
    };

    mappingProvider = new MappingProvider();
    mappingProvider.setDefault(MappingProvider.LOCATION, "classpath:/de/tudarmstadt/ukp/dkpro/"
            + "core/api/lexmorph/tagset/${language}-${tagger.tagset}-tagger.map");
    mappingProvider.setDefault(MappingProvider.BASE_TYPE, POS.class.getName());
    mappingProvider.setDefault("tagger.tagset", "default");
    mappingProvider.setOverride(MappingProvider.LOCATION, mappingLocation);
    mappingProvider.setOverride(MappingProvider.LANGUAGE, language);
    mappingProvider.addImport("tagger.tagset", modelProvider);

}