Example usage for org.apache.commons.io FileUtils openOutputStream

List of usage examples for org.apache.commons.io FileUtils openOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils openOutputStream.

Prototype

public static FileOutputStream openOutputStream(File file) throws IOException 

Source Link

Document

Opens a FileOutputStream for the specified file, checking and creating the parent directory if it does not exist.

Usage

From source file:com.textocat.textokit.morph.lemmatizer.util.GenerateNormalizedTextWriterDescriptor.java

public static void main(String[] args) throws ResourceInitializationException, IOException, SAXException {
    AnalysisEngineDescription anDesc = createEngineDescription(NormalizedTextWriter.class);
    try (FileOutputStream out = FileUtils.openOutputStream(new File(
            "src/main/resources/" + NormalizedTextWriter.class.getName().replace('.', '/') + ".xml"))) {
        anDesc.toXML(new BufferedOutputStream(out));
    }/*  w w  w  . j  a va  2  s .c  o m*/
}

From source file:com.textocat.textokit.segmentation.GenerateOSPLSplitterDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/" + OneSentencePerLineSplitter.class.getName().replace('.', '/')
            + ".xml";
    AnalysisEngineDescription desc = OneSentencePerLineSplitter.createDescription();
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {/*  ww w.j a  v a2s .  c  om*/
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.segmentation.GenerateParagraphSplitterDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/" + ParagraphSplitter.class.getName().replace('.', '/') + ".xml";
    TypeSystemDescription tsDesc = SentenceSplitterAPI.getTypeSystemDescription();
    AnalysisEngineDescription desc = createEngineDescription(ParagraphSplitter.class, tsDesc);
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {//w  ww .j av  a  2  s.co  m
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.segmentation.GenerateSentenceSplitterDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/" + SentenceSplitterAPI.AE_SENTENCE_SPLITTER.replace('.', '/')
            + ".xml";
    TypeSystemDescription tsDesc = SentenceSplitterAPI.getTypeSystemDescription();
    AnalysisEngineDescription desc = createEngineDescription(SentenceSplitter.class, tsDesc);
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {/*w  w  w  . j  a v a2 s. c  o  m*/
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.postagger.opennlp.GeneratePipelineDescriptorForOpenNLPPosTagger.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    if (args.length != 1) {
        System.err.println("Provide output path!");
        System.exit(1);/*from   w  ww  .  ja  v  a2s .  co  m*/
    }
    File outFile = new File(args[0]);
    //
    AnalysisEngineDescription outDesc = getDescription();
    OutputStream out = FileUtils.openOutputStream(outFile);
    try {
        outDesc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.segmentation.GenerateBasicAggregateDescriptor.java

/**
 * @param args//from  w  w  w  . j  av a 2s. c o m
 * @throws ResourceInitializationException
 */
public static void main(String[] args) throws UIMAException, IOException, SAXException {
    Map<String, MetaDataObject> aeDescriptions = Maps.newLinkedHashMap();
    aeDescriptions.put("tokenizer", TokenizerAPI.getAEImport());

    aeDescriptions.put("sentenceSplitter", SentenceSplitterAPI.getAEImport());

    String outputPath = "desc/basic-aggregate.xml";
    AnalysisEngineDescription desc = PipelineDescriptorUtils.createAggregateDescription(aeDescriptions);
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.dictmatcher.GenerateTypedDictionaryAnnotatorDesc.java

public static void main(String[] args) throws ResourceInitializationException, IOException, SAXException {
    String relOutPath = (DictionaryAnnotator.class.getName() + "-typed").replace('.', '/') + ".xml";
    TypeSystemDescription tsd = TypeSystemDescriptionFactory
            .createTypeSystemDescription("com.textocat.textokit.dictmatcher.ts-dictmatcher");
    AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription(DictionaryAnnotator.class,
            tsd, PARAM_CHUNK_ADAPTER_CLASS, TypedChunkAnnotationAdapter.class.getName());
    ConfigurationParameterFactory.addConfigurationParameters(desc, TypedChunkAnnotationAdapter.class);
    try (FileOutputStream os = FileUtils.openOutputStream(new File("src/main/resources/" + relOutPath))) {
        desc.toXML(os);/*from   w w w . jav  a 2  s.c o m*/
    }
}

From source file:com.textocat.textokit.dictmatcher.GenerateTaggedDictionaryAnnotatorDesc.java

public static void main(String[] args) throws ResourceInitializationException, IOException, SAXException {
    String relOutPath = (DictionaryAnnotator.class.getName() + "-tagged").replace('.', '/') + ".xml";
    TypeSystemDescription tsd = TypeSystemDescriptionFactory
            .createTypeSystemDescription("com.textocat.textokit.dictmatcher.ts-dictmatcher");
    AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription(DictionaryAnnotator.class,
            tsd, PARAM_CHUNK_ADAPTER_CLASS, TaggedChunkAnnotationAdapter.class.getName(),
            PARAM_RESULT_ANNOTATION_TYPE, DictionaryMatch.class.getName(), PARAM_TAG_FEATURE, "tag");
    try (FileOutputStream os = FileUtils.openOutputStream(new File("src/main/resources/" + relOutPath))) {
        desc.toXML(os);//from  ww  w . j a  v a  2  s . c  om
    }
}

From source file:com.textocat.textokit.morph.opencorpora.resource.XmlDictionaryParserLauncher.java

public static void main(String[] args) throws Exception {
    XmlDictionaryParserLauncher cfg = new XmlDictionaryParserLauncher();
    new JCommander(cfg, args);

    MorphDictionaryImpl dict = new MorphDictionaryImpl();
    DictionaryExtension ext = cfg.dictExtensionClass.newInstance();
    FileInputStream fis = FileUtils.openInputStream(cfg.dictXmlFile);
    try {/*  ww  w . j a v a  2  s  .c om*/
        new XmlDictionaryParser(dict, ext, fis).run();
    } finally {
        IOUtils.closeQuietly(fis);
    }

    log.info("Preparing to serialization...");
    long timeBefore = currentTimeMillis();
    OutputStream fout = new BufferedOutputStream(FileUtils.openOutputStream(cfg.outputFile), 8192 * 8);
    ObjectOutputStream out = new ObjectOutputStream(fout);
    try {
        out.writeObject(dict.getGramModel());
        out.writeObject(dict);
    } finally {
        out.close();
    }
    log.info("Serialization finished in {} ms.\nOutput size: {} bytes", currentTimeMillis() - timeBefore,
            cfg.outputFile.length());
}

From source file:com.textocat.textokit.morph.opencorpora.resource.XmlDictionaryPSP.java

public static void main(String[] args) throws Exception {
    XmlDictionaryPSP cfg = new XmlDictionaryPSP();
    new JCommander(cfg, args);

    MorphDictionaryImpl dict = new MorphDictionaryImpl();
    DictionaryExtension ext = cfg.dictExtensionClass.newInstance();
    FileInputStream fis = FileUtils.openInputStream(cfg.dictXmlFile);
    try {//  ww w.  j a  va  2  s.  co m
        new XmlDictionaryParser(dict, ext, fis).run();
    } finally {
        IOUtils.closeQuietly(fis);
    }

    System.out.println("Preparing to serialization...");
    long timeBefore = currentTimeMillis();
    OutputStream fout = new BufferedOutputStream(FileUtils.openOutputStream(cfg.outputJarFile), 8192 * 8);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
    manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_VERSION,
            dict.getVersion());
    manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_REVISION,
            dict.getRevision());
    manifest.getMainAttributes().putValue(OpencorporaMorphDictionaryAPI.ME_OPENCORPORA_DICTIONARY_VARIANT,
            cfg.variant);
    String dictEntryName = String.format(
            OpencorporaMorphDictionaryAPI.FILENAME_PATTERN_OPENCORPORA_SERIALIZED_DICT, dict.getVersion(),
            dict.getRevision(), cfg.variant);
    JarOutputStream jarOut = new JarOutputStream(fout, manifest);
    jarOut.putNextEntry(new ZipEntry(dictEntryName));
    ObjectOutputStream serOut = new ObjectOutputStream(jarOut);
    try {
        serOut.writeObject(dict.getGramModel());
        serOut.writeObject(dict);
    } finally {
        serOut.flush();
        jarOut.closeEntry();
        serOut.close();
    }
    System.out.println(String.format("Serialization finished in %s ms.\nOutput size: %s bytes",
            currentTimeMillis() - timeBefore, cfg.outputJarFile.length()));
}