/** * An implementation of {@code read(String, Transformer<String, T>)}. This function reads the * lines in a file and returns them. * * @param fileName The name of the file to be read * @return An arraylist of the lines of the file. */ public static ArrayList<String> read(String fileName, String charsetName) throws FileNotFoundException { return read(fileName, charsetName, identityTransformer); }
/** * Creates a new ListFeatureExtractor * * @param listName The name of the list, which is emitted as the feature * @param listFile A file containing the elements of the list * @param caseSensitive Should the checking be case sensitive? * @throws java.io.FileNotFoundException */ public ListFeatureExtractor(String listName, String listFile, boolean caseSensitive) throws FileNotFoundException { this(listName, LineIO.read(listFile), caseSensitive); }
/** * An implementation of {@code read(String, Transformer<String, T>)}. This function reads the * lines in a file and returns them. * * @param fileName The name of the file to be read * @return An arraylist of the lines of the file. */ public static ArrayList<String> read(String fileName, String charsetName) throws FileNotFoundException { return read(fileName, charsetName, identityTransformer); }
/** * Creates a new ListFeatureExtractor * * @param listName The name of the list, which is emitted as the feature * @param listFile A file containing the elements of the list * @param caseSensitive Should the checking be case sensitive? * @throws java.io.FileNotFoundException */ public ListFeatureExtractor(String listName, String listFile, boolean caseSensitive) throws FileNotFoundException { this(listName, LineIO.read(listFile), caseSensitive); }
/** * This function reads a file line-by-line and converts each line into an object using a * transformer that is passed as a parameter. * * @param <T> Each line of the file represents an object of type T * @param fileName The name of the file to be read * @param transformer A transformer from String to type T * @return An {@code ArrayList} containing objects of type T, with one object corresponding to * each line. */ public static <T> ArrayList<T> read(String fileName, ITransformer<String, T> transformer) throws FileNotFoundException { return read(fileName, Charset.defaultCharset().name(), transformer); }
private void loadConversionMap(){ try { ArrayList<String> lines = LineIO.read("/shared/bronte/ctsai12/multilingual/2015data/t2s"); t2s = new HashMap<>(); for(String line: lines){ String[] tokens = line.split("\t"); if(tokens[0].length()==1 && tokens[1].length()==1 && tokens[0]!=tokens[1]) t2s.put(tokens[0], tokens[1]); } } catch (FileNotFoundException e) { e.printStackTrace(); } }
private void loadConversionMap(){ try { ArrayList<String> lines = LineIO.read("/shared/bronte/ctsai12/multilingual/2015data/t2s"); t2s = new HashMap<>(); for(String line: lines){ String[] tokens = line.split("\t"); if(tokens[0].length()==1 && tokens[1].length()==1 && tokens[0]!=tokens[1]) t2s.put(tokens[0], tokens[1]); } } catch (FileNotFoundException e) { e.printStackTrace(); } }
/** * An implementation of {@code read(String, Transformer<String, T>)}. This function reads the * lines in a file and returns them. * * @param fileName The name of the file to be read * @return An arraylist of the lines of the file. */ @AvoidUsing(reason = "Cannot be used for accessing files inside jars in the classpath", alternative = "readFromClasspath(String fileName)") public static ArrayList<String> read(String fileName) throws FileNotFoundException { return read(fileName, Charset.defaultCharset().name(), identityTransformer); }
public static List<Pair<String, String>> GetTabDelimitedPairs(String filename) throws FileNotFoundException { List<Pair<String, String>> result = new ArrayList<>(); for (String line : LineIO.read(filename)) { String[] pair = line.trim().split("\t"); if (pair.length != 2) continue; result.add(new Pair<>(pair[0].trim().toLowerCase(), pair[1].trim().toLowerCase())); } return result; }
/** * This searches for the file on the classpath before reading it. If it doesn't find the file, * it throws a {@code FileNotFoundException}. * * @param fileName The name of the file to be read * @return An arraylist of the lines of the file. */ public static ArrayList<String> readFromClasspath(String fileName) throws FileNotFoundException { return read(getInputStream(fileName), Charset.defaultCharset().name(), identityTransformer); }
public static List<Pair<String, String>> GetTabDelimitedPairs(String filename) throws FileNotFoundException { List<Pair<String, String>> result = new ArrayList<>(); for (String line : LineIO.read(filename)) { String[] pair = line.trim().split("\t"); if (pair.length != 2) continue; result.add(new Pair<>(pair[0].trim().toLowerCase(), pair[1].trim().toLowerCase())); } return result; }
/** * An implementation of {@code read(String, Transformer<String, T>)}. This function reads the * lines in a file and returns them. * * @param fileName The name of the file to be read * @return An arraylist of the lines of the file. */ @AvoidUsing(reason = "Cannot be used for accessing files inside jars in the classpath", alternative = "readFromClasspath(String fileName)") public static ArrayList<String> read(String fileName) throws FileNotFoundException { return read(fileName, Charset.defaultCharset().name(), identityTransformer); }
/** * This searches for the file on the classpath before reading it. If it doesn't find the file, * it throws a {@code FileNotFoundException}. * * @param fileName The name of the file to be read * @return An arraylist of the lines of the file. */ public static ArrayList<String> readFromClasspath(String fileName) throws FileNotFoundException { return read(getInputStream(fileName), Charset.defaultCharset().name(), identityTransformer); }
public void readFile(String fileName) { try { List<String> lines = LineIO.read(fileName); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String sentId = IOUtils.getFileName(fileName) + ":" + i; textAnnotations.add(createTextAnnotation(line, sentId)); } } catch (FileNotFoundException e) { logger.error("Could not read {}; unable to continue.", fileName); throw new RuntimeException(e); } }
/** * This is basically the reverse of the WriteProbs function. */ public void ReadProbs(String fname) throws FileNotFoundException { List<String> lines = LineIO.read(fname); probs = new SparseDoubleVector<>(); for(String line : lines){ String[] sline = line.trim().split("\t"); probs.put(new Production(sline[0], sline[1]), Double.parseDouble(sline[2])); } }
/** * This is basically the reverse of the WriteProbs function. */ public void ReadProbs(String fname) throws FileNotFoundException { List<String> lines = LineIO.read(fname); probs = new SparseDoubleVector<>(); for(String line : lines){ String[] sline = line.trim().split("\t"); probs.put(new Production(sline[0], sline[1]), Double.parseDouble(sline[2])); } }
private void readData() throws NumberFormatException, FileNotFoundException { String dataFile = dataHome + "/prop.txt"; for (String line : LineIO.read(dataFile)) { PropbankFields n = new PropbankFields(line); if (this.sections.contains(n.getSection())) { if (!this.goldFields.containsKey(n.getIdentifier())) { this.goldFields.put(n.getIdentifier(), new ArrayList<PropbankFields>()); } this.goldFields.get(n.getIdentifier()).add(n); } } }
private void readData() throws NumberFormatException, FileNotFoundException { String dataFile = dataHome + "/prop.txt"; for (String line : LineIO.read(dataFile)) { PropbankFields n = new PropbankFields(line); if (this.sections.contains(n.getSection())) { if (!this.goldFields.containsKey(n.getIdentifier())) { this.goldFields.put(n.getIdentifier(), new ArrayList<PropbankFields>()); } this.goldFields.get(n.getIdentifier()).add(n); } } }
private void readData() throws NumberFormatException, FileNotFoundException { String nombankFile = this.getDataFile(dataHome); for (String line : LineIO.read(nombankFile)) { Fields n = readFields(line); if (this.sections.contains(n.getSection())) { if (!this.goldFields.containsKey(n.getIdentifier())) { this.goldFields.put(n.getIdentifier(), new ArrayList<Fields>()); } this.goldFields.get(n.getIdentifier()).add(n); } } }
private void readData() throws NumberFormatException, FileNotFoundException { String nombankFile = this.getDataFile(dataHome); for (String line : LineIO.read(nombankFile)) { Fields n = readFields(line); if (this.sections.contains(n.getSection())) { if (!this.goldFields.containsKey(n.getIdentifier())) { this.goldFields.put(n.getIdentifier(), new ArrayList<Fields>()); } this.goldFields.get(n.getIdentifier()).add(n); } } }