Example usage for edu.stanford.nlp.util StringUtils printToFile

List of usage examples for edu.stanford.nlp.util StringUtils printToFile

Introduction

In this page you can find the example usage for edu.stanford.nlp.util StringUtils printToFile.

Prototype

public static void printToFile(String filename, String message, boolean append) 

Source Link

Document

Prints to a file.

Usage

From source file:opennlp.tools.parse_thicket.kernel_interface.MultiSentenceExtendedForestSearchResultsProcessorSetFormer.java

License:Apache License

private List<HitBase> formTreeForestDataSet(List<HitBase> hits, String query, boolean isPositive) {
    List<HitBase> newHitList = new ArrayList<HitBase>(), newHitListReRanked = new ArrayList<HitBase>();
    // form the training set from original documents. Since search results
    // are ranked, we set the first half as positive set,
    // and the second half as negative set.
    // after re-classification, being re-ranked, the search results might
    // end up in a different set
    List<String[]> treeBankBuffer = new ArrayList<String[]>();
    int count = 0;
    for (HitBase hit : hits) {
        count++;/*w  w w  .  ja v  a  2 s.  c  o  m*/
        // if orig content has been already set in HIT object, ok; otherwise
        // set it
        String searchResultText = hit.getPageContent();
        if (searchResultText == null) {
            try {
                HitBase hitWithFullSents = extractor.formTextFromOriginalPageGivenSnippet(hit);
                for (String paragraph : hitWithFullSents.getOriginalSentences()) {
                    List<String[]> res = formTreeKernelStructure(paragraph, count, hits, isPositive);
                    for (String[] rl : res) {
                        StringUtils.printToFile(new File(path + trainingFileName), rl[0] + " \n", true);
                    }
                    // treeBankBuffer.addAll(res);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        newHitList.add(hit);

    }
    // write the lits of samples to a file
    ProfileReaderWriter.appendReport(treeBankBuffer, path + trainingFileName, ' ');
    return newHitList;

}