Example usage for edu.stanford.nlp.tagger.maxent MaxentTagger main

List of usage examples for edu.stanford.nlp.tagger.maxent MaxentTagger main

Introduction

In this page you can find the example usage for edu.stanford.nlp.tagger.maxent MaxentTagger main.

Prototype

public static void main(String[] args) throws Exception 

Source Link

Document

Command-line tagger interface.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordPosTaggerTrainer.java

License:Open Source License

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    if (out != null) {
        IOUtils.closeQuietly(out);//from  ww  w.j  av a 2  s . c  o m
    }

    // Load user-provided configuration
    Properties props = new Properties();
    try (InputStream is = new FileInputStream(parameterFile)) {
        props.load(is);
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }

    // Add/replace training file information
    props.setProperty("trainFile", "format=TSV,wordColumn=0,tagColumn=1," + tempData.getAbsolutePath());
    props.setProperty("model", targetLocation.getAbsolutePath());
    props.setProperty("encoding", "UTF-8");
    if (clusterFile != null) {
        String arch = props.getProperty("arch");
        arch = arch.replaceAll("\\$\\{distsimCluster\\}", clusterFile.getAbsolutePath());
        props.setProperty("arch", arch);
    }

    File tempConfig = null;
    try {
        // Write to a temporary location
        tempConfig = File.createTempFile("dkpro-stanford-pos-trainer", ".props");
        try (OutputStream os = new FileOutputStream(tempConfig)) {
            props.store(os, null);
        }

        // Train
        MaxentTagger.main(new String[] { "-props", tempConfig.getAbsolutePath() });
    } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
    } finally {
        // Clean up temporary parameter file
        if (tempConfig != null) {
            tempConfig.delete();
        }
    }
}