当前位置: 首页>>代码示例>>Java>>正文


Java Util.readFileLineByLine方法代码示例

本文整理汇总了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;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:19,代码来源:PennTreebank.java

示例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;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:19,代码来源:DependencyTreebank.java

示例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;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:17,代码来源:CCGBankDependencies.java

示例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++;
	}
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:17,代码来源:TaggerEmbeddings.java

示例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++;
	}
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:11,代码来源:TaggerEmbeddings.java

示例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;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:37,代码来源:TaggerEmbeddings.java

示例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();
		}
	};
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:37,代码来源:InputReader.java

示例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());
		}
	};
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:16,代码来源:InputReader.java

示例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;

}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:15,代码来源:BrownPropbankReader.java

示例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);
	}
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:16,代码来源:Coindexation.java

示例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();
			}
		}
	};

}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:46,代码来源:CCGBankParseReader.java


注:本文中的edu.uw.easysrl.util.Util.readFileLineByLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。