Search in sources :

Example 91 with RuntimeIOException

use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.

the class CRFClassifier method readEntityMatrices.

static Pair<double[][], double[][]> readEntityMatrices(String fileName, Index<String> tagIndex) {
    int numTags = tagIndex.size();
    int matrixSize = numTags - 1;
    String[] matrixLines = new String[matrixSize];
    String[] subMatrixLines = new String[matrixSize];
    try (BufferedReader br = IOUtils.readerFromString(fileName)) {
        int lineCount = 0;
        for (String line; (line = br.readLine()) != null; ) {
            line = line.trim();
            if (lineCount < matrixSize)
                matrixLines[lineCount] = line;
            else
                subMatrixLines[lineCount - matrixSize] = line;
            lineCount++;
        }
    } catch (Exception ex) {
        throw new RuntimeIOException(ex);
    }
    double[][] matrix = parseMatrix(matrixLines, tagIndex, matrixSize, true);
    double[][] subMatrix = parseMatrix(subMatrixLines, tagIndex, matrixSize, true);
    // In Jenny's paper, use the square root of non-log prob for matrix, but not for subMatrix
    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++) matrix[i][j] = matrix[i][j] / 2;
    }
    log.info("Matrix: ");
    log.info(ArrayUtils.toString(matrix));
    log.info("SubMatrix: ");
    log.info(ArrayUtils.toString(subMatrix));
    return new Pair<>(matrix, subMatrix);
}
Also used : RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

Example 92 with RuntimeIOException

use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.

the class SplittingGrammarExtractor method useNewBetas.

public boolean useNewBetas(boolean testConverged, TwoDimensionalMap<String, String, double[][]> tempUnaryBetas, ThreeDimensionalMap<String, String, String, double[][][]> tempBinaryBetas) {
    rescaleTemporaryBetas(tempUnaryBetas, tempBinaryBetas);
    // if we just split states, we have obviously not converged
    boolean converged = testConverged && testConvergence(tempUnaryBetas, tempBinaryBetas);
    unaryBetas = tempUnaryBetas;
    binaryBetas = tempBinaryBetas;
    wordIndex = tempWordIndex;
    tagIndex = tempTagIndex;
    lex = tempLex;
    if (DEBUG()) {
        System.out.println("LEXICON");
        try {
            OutputStreamWriter osw = new OutputStreamWriter(System.out, "utf-8");
            lex.writeData(osw);
            osw.flush();
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }
    tempWordIndex = null;
    tempTagIndex = null;
    tempLex = null;
    return converged;
}
Also used : RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

Example 93 with RuntimeIOException

use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.

the class CoNLLDocumentReader method getNextDocument.

public CoNLLDocument getNextDocument() {
    try {
        // DONE!
        if (curFileIndex >= fileList.size())
            return null;
        File curFile = fileList.get(curFileIndex);
        if (docIterator == null) {
            docIterator = new DocumentIterator(curFile.getAbsolutePath(), options);
        }
        while (!docIterator.hasNext()) {
            Redwood.log("debug-docreader", "Processed " + docIterator.docCnt + " documents in " + curFile.getAbsolutePath());
            docIterator.close();
            curFileIndex++;
            if (curFileIndex >= fileList.size()) {
                // DONE!
                return null;
            }
            curFile = fileList.get(curFileIndex);
            docIterator = new DocumentIterator(curFile.getAbsolutePath(), options);
        }
        CoNLLDocument next = docIterator.next();
        Redwood.log("debug-docreader", "Reading document: " + next.getDocumentID() + " part: " + next.getPartNo());
        return next;
    } catch (IOException ex) {
        throw new RuntimeIOException(ex);
    }
}
Also used : RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) IOException(java.io.IOException) File(java.io.File)

Example 94 with RuntimeIOException

use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.

the class Dictionaries method loadDemonymLists.

/**
 * The format of the demonyms file is
 *     countryCityOrState ( TAB demonym )*
 *  Lines starting with # are ignored
 *  The file is cased but stored in in-memory data structures uncased.
 *  The results are:
 *  demonyms is a has from each country (etc.) to a set of demonymic Strings;
 *  adjectiveNation is a set of demonymic Strings;
 *  demonymSet has all country (etc.) names and all demonymic Strings.
 */
private void loadDemonymLists(String demonymFile) {
    try (BufferedReader reader = IOUtils.readerFromString(demonymFile)) {
        for (String line; (line = reader.readLine()) != null; ) {
            line = line.toLowerCase(Locale.ENGLISH);
            String[] tokens = line.split("\t");
            if (tokens[0].startsWith("#"))
                continue;
            Set<String> set = Generics.newHashSet();
            for (String s : tokens) {
                set.add(s);
                demonymSet.add(s);
            }
            demonyms.put(tokens[0], set);
        }
        adjectiveNation.addAll(demonymSet);
        adjectiveNation.removeAll(demonyms.keySet());
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

Example 95 with RuntimeIOException

use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.

the class Dictionaries method loadAnimacyLists.

private void loadAnimacyLists(String animateWordsFile, String inanimateWordsFile) {
    try {
        getWordsFromFile(animateWordsFile, animateWords, false);
        getWordsFromFile(inanimateWordsFile, inanimateWords, false);
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException) IOException(java.io.IOException) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

Aggregations

RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)114 IOException (java.io.IOException)61 BufferedReader (java.io.BufferedReader)22 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)12 CoreLabel (edu.stanford.nlp.ling.CoreLabel)11 File (java.io.File)9 ArrayList (java.util.ArrayList)7 Tree (edu.stanford.nlp.trees.Tree)6 CoreMap (edu.stanford.nlp.util.CoreMap)5 BufferedWriter (java.io.BufferedWriter)5 Properties (java.util.Properties)5 Timing (edu.stanford.nlp.util.Timing)4 FileNotFoundException (java.io.FileNotFoundException)4 FileOutputStream (java.io.FileOutputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 PrintWriter (java.io.PrintWriter)4 CorefCoreAnnotations (edu.stanford.nlp.coref.CorefCoreAnnotations)3 Annotation (edu.stanford.nlp.pipeline.Annotation)3 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)3 ClassicCounter (edu.stanford.nlp.stats.ClassicCounter)3