本文整理汇总了Java中edu.uw.easysrl.util.Util.readFileLineByLine方法的典型用法代码示例。如果您正苦于以下问题:Java Util.readFileLineByLine方法的具体用法?Java Util.readFileLineByLine怎么用?Java Util.readFileLineByLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uw.easysrl.util.Util
的用法示例。
在下文中一共展示了Util.readFileLineByLine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readCorpus
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
Table<String, Integer, TreebankParse> readCorpus(final File folder)
throws IOException {
final Table<String, Integer, TreebankParse> result = HashBasedTable
.create();
for (final File file : Util.findAllFiles(folder, ".*.(mrg|MRG)")) {
final String name = file.getName().substring(0,
file.getName().length() - 4).toLowerCase();
// System.out.println(name);
final Iterator<String> lines = Util.readFileLineByLine(file);
int sentenceNumber = 0;
while (lines.hasNext()) {
result.put(name, sentenceNumber, readParse(lines));
sentenceNumber++;
}
}
return result;
}
示例2: readCorpus
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
Table<String, Integer, SyntacticDependencyParse> readCorpus(File folder)
throws IOException {
Table<String, Integer, SyntacticDependencyParse> result = HashBasedTable
.create();
for (File file : Util.findAllFiles(folder, ".*.deps")) {
String name = file.getName().substring(0,
file.getName().indexOf("."));
// System.out.println(name);
Iterator<String> lines = Util.readFileLineByLine(file);
int sentenceNumber = 0;
while (lines.hasNext()) {
result.put(name, sentenceNumber, readParse(lines));
sentenceNumber++;
}
}
return result;
}
示例3: getDependencyParses
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
private static List<DependencyParse> getDependencyParses(final File autoFile, final File pargFile)
throws IOException {
final Iterator<String> autoLines = Util.readFileLineByLine(autoFile);
final Iterator<String> pargLines = Util.readFileLineByLine(pargFile);
final List<DependencyParse> result = new ArrayList<>();
while (autoLines.hasNext()) {
final SyntaxTreeNode autoParse = Rebanker.getParse(autoLines);
final DependencyParse depParse = CCGBankDependencies.getDependencyParseCCGBank(pargLines,
autoParse.getLeaves());
result.add(depParse);
}
return result;
}
示例4: loadMatrix
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
/**
* Loads the neural network weight matrix.
*/
private void loadMatrix(final Matrix matrix, final File file) throws IOException {
final Iterator<String> lines = Util.readFileLineByLine(file);
int row = 0;
while (lines.hasNext()) {
final String line = lines.next();
final String[] fields = line.split(" ");
for (int i = 0; i < fields.length; i++) {
matrix.set(row, i, Double.valueOf(fields[i]));
}
row++;
}
}
示例5: loadVector
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
private void loadVector(final Vector vector, final File file) throws IOException {
final Iterator<String> lines = Util.readFileLineByLine(file);
int row = 0;
while (lines.hasNext()) {
final String data = lines.next();
vector.set(row, Double.valueOf(data));
row++;
}
}
示例6: loadEmbeddings
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
/**
*
* @param normalize
* If true, words are lower-cased with numbers replaced
* @param embeddingsFiles
* @return
* @throws IOException
*/
private Map<String, double[]> loadEmbeddings(final boolean normalize, final File... embeddingsFiles)
throws IOException {
final Map<String, double[]> embeddingsMap = new HashMap<>();
// Allow sharded input, by allowing the embeddings to be split across
// multiple files.
for (final File embeddingsFile : embeddingsFiles) {
final Iterator<String> lines = Util.readFileLineByLine(embeddingsFile);
while (lines.hasNext()) {
final String line = lines.next();
// Lines have the format: word dim1 dim2 dim3 ...
String word = line.substring(0, line.indexOf(" "));
if (normalize) {
word = normalize(word);
}
if (!embeddingsMap.containsKey(word)) {
final String[] fields = line.split(" ");
final double[] embeddings = new double[fields.length - 1];
for (int i = 1; i < fields.length; i++) {
embeddings[i - 1] = Double.valueOf(fields[i]);
}
embeddingsMap.put(word, embeddings);
}
}
}
return embeddingsMap;
}
示例7: readFile
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
public Iterable<InputToParser> readFile(final File input) throws IOException {
final Iterator<String> inputIt = Util.readFileLineByLine(input);
return () -> new Iterator<InputToParser>() {
private InputToParser next = getNext();
@Override
public boolean hasNext() {
return next != null;
}
private InputToParser getNext() {
while (inputIt.hasNext()) {
final String nextLine = inputIt.next();
if (!nextLine.startsWith("#") && !nextLine.isEmpty()) {
// Skip commented or empty lines;
return readInput(nextLine);
}
}
return null;
}
@Override
public InputToParser next() {
final InputToParser result = next;
next = getNext();
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
示例8: readInput
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
public Iterator<InputToParser> readInput(final File file) throws IOException {
final Iterator<String> lines = Util.readFileLineByLine(file);
return new Iterator<InputToParser>() {
@Override
public boolean hasNext() {
return lines.hasNext();
}
@Override
public InputToParser next() {
return readInput(lines.next());
}
};
}
示例9: readCorpus
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
public static Collection<SRLParse> readCorpus() throws IOException {
final Collection<SRLParse> result = new ArrayList<>();
final Iterator<String> srlLines = Util.readFileLineByLine(propsFile);
final Iterator<String> wordsLines = Util.readFileLineByLine(wordsFile);
while (wordsLines.hasNext()) {
final List<String> words = readWords(wordsLines);
result.add(readSRLParse(words, srlLines));
}
return result;
}
示例10: parseMarkedUpFile
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
/**
* Loads co-indexation information from the specified file.
*/
public static void parseMarkedUpFile(final File file) throws IOException {
final Iterator<String> lines = Util.readFileLineByLine(file);
while (lines.hasNext()) {
String line = lines.next();
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
line = line.replaceAll(":B", "");
categoryToMarkedUpCategory.put(Category.valueOf(line), line);
}
}
示例11: loadCorpus
import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
public static Iterator<SyntaxTreeNode> loadCorpus(final File folder, final String regex) throws IOException {
final List<File> autoFilesList = Util.findAllFiles(folder, regex);
Collections.sort(autoFilesList);
return new Iterator<SyntaxTreeNode>() {
Iterator<File> autoFiles = ImmutableList.copyOf(autoFilesList).iterator();
Iterator<String> autoLines = Util.readFileLineByLine(autoFiles.next());
@Override
public boolean hasNext() {
return autoLines.hasNext() || autoFiles.hasNext();
}
@Override
public SyntaxTreeNode next() {
// Breaks if the last parse is a failure...
if (autoLines.hasNext()) {
String line = autoLines.next();
while (autoLines.hasNext() && line.startsWith("ID=")) {
line = autoLines.next();
}
if (!line.startsWith("ID=")) {
final SyntaxTreeNode result = parse(line);
return result;
} else {
return next();
}
} else {
final File autoFile = autoFiles.next();
try {
autoLines = Util.readFileLineByLine(autoFile);
} catch (final IOException e) {
throw new RuntimeException(e);
}
return next();
}
}
};
}