Sha256: 1ceb9402c463083a5eef2f7aab0260933668ed49e5f2b420254fd5de9d241dad

Contents?: true

Size: 1.76 KB

Versions: 45

Compression:

Stored size: 1.76 KB

Contents

package lingscope.io;

import generalutils.FileOperations;
import lingscope.structures.AnnotatedSentence;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Reads and writes annotated sentences
 * @author shashank
 */
public class AnnotatedSentencesIO {

    /**
     * Reads and returns the list of {@link AnnotatedSentence} from the given
     * file
     * @param fileToRead
     * @return
     */
    public static List<AnnotatedSentence> read(String fileToRead) {
        List<AnnotatedSentence> sentences = null;
        try {
            List<String> rawSentences = FileOperations.readFile(fileToRead);
            sentences = new ArrayList<AnnotatedSentence>(rawSentences.size());
            for (String rawSentence : rawSentences) {
                sentences.add(new AnnotatedSentence(rawSentence));
            }
        } catch (Exception ex) {
            Logger.getLogger(AnnotatedSentencesIO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sentences;
    }

    /**
     * Writes the given list of annotated sentences to the given fileToWrite
     * @param fileToWrite
     * @param annotatedSentences
     */
    public static void write(String fileToWrite, List<AnnotatedSentence> annotatedSentences) {
        List<String> rawSentences = new ArrayList<String>(annotatedSentences.size());
        for (AnnotatedSentence annotatedSentence : annotatedSentences) {
            rawSentences.add(annotatedSentence.getRawText());
        }
        try {
            FileOperations.writeFile(fileToWrite, rawSentences);
        } catch (Exception ex) {
            Logger.getLogger(AnnotatedSentencesIO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
abstractor-4.4.7 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.6 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.5 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.4 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.3 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.2 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.1 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.4.0 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.3.3 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.3.2 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.3.1 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.3.0 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.2.3 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.2.2 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.2.1 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.2.0 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.1.5 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.1.4 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.1.3 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java
abstractor-4.1.2 lib/lingscope/src/lingscope/io/AnnotatedSentencesIO.java