本文整理汇总了Java中edu.uw.easysrl.util.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于edu.uw.easysrl.util包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateStats
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
public void updateStats(final Set<ResolvedDependency> goldDependencies,
final List<Category> goldCategories,
final List<Util.Scored<SyntaxTreeNode>> predictedParses,
final DependencyEvaluator evaluator) {
sentenceCount.incrementAndGet();
if (predictedParses != null) {
parsableSentenceCount.incrementAndGet();
} else {
evaluator.evaluate(goldDependencies, null, overallStats);
return;
}
final SyntaxTreeNode topParse = predictedParses.get(0).getObject();
evaluator.evaluate(goldDependencies, topParse, overallStats);
final int numCorrect = (int) CollectionUtil.zip(
topParse.getLeaves().stream().map(SyntaxTreeNode::getCategory),
goldCategories.stream(), Object::equals).filter(Boolean::booleanValue).count();
correctlySupertaggedWords.addAndGet(numCorrect);
totalWords.addAndGet(goldCategories.size());
}
示例2: loadSpecialCombinators
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
public static Collection<Combinator> loadSpecialCombinators(final File file) throws IOException {
final Collection<Combinator> newCombinators = new ArrayList<>();
for (String line : Util.readFile(file)) {
// l , S[to]\NP NP\NP
if (line.indexOf("#") > -1) {
line = line.substring(0, line.indexOf("#"));
}
line = line.trim();
if (line.isEmpty()) {
continue;
}
final String[] fields = line.split(" ");
final boolean headIsLeft = fields[0].equals("l");
final Category left = Category.valueOf(fields[1]);
final Category right = Category.valueOf(fields[2]);
final Category result = Category.valueOf(fields[3]);
newCombinators.add(new SpecialCombinator(left, right, result, headIsLeft));
}
return newCombinators;
}
示例3: main
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
public static void main(final String[] args) {
final POSTagger postagger = POSTagger.getStanfordTagger(Util.getFile(args[0]));
final InputReader reader = InputReader.make(InputFormat.TOKENIZED);
final Scanner inputLines = new Scanner(System.in, "UTF-8");
while (inputLines.hasNext()) {
final String line = inputLines.nextLine();
final List<InputWord> words = postagger.tag(reader.readInput(line).getInputWords());
for (int i = 0; i < words.size(); i++) {
if (i > 0) {
System.out.print(" ");
}
System.out.print(words.get(i).word + "|" + words.get(i).pos);
}
System.out.println();
}
inputLines.close();
}
示例4: combineNodes
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
@Override
public AgendaItem combineNodes(final AgendaItem leftChild, final AgendaItem rightChild, final SyntaxTreeNode node) {
final int score = scoreNode(node);
if (rightChild.getParse().getHead().getWord().equals("around")) {
Util.debugHook();
}
int expectedDeps = 0;
for (final ResolvedDependency dep : gold) {
if (expected(leftChild, rightChild, dep) || expected(rightChild, leftChild, dep)) {
expectedDeps++;
}
}
final double insideScore = leftChild.getInsideScore() + rightChild.getInsideScore() + score;
return new AgendaItem(node, insideScore, leftChild.outsideScoreUpperbound + rightChild.outsideScoreUpperbound
- globalUpperBound - expectedDeps, leftChild.getStartOfSpan(), leftChild.getSpanLength()
+ rightChild.getSpanLength(), true);
}
示例5: getValues2
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
@Override
FunctionValues getValues2(final double[] featureWeights, final List<TrainingExample> trainingData) {
final double[] modelExpectation = new double[featureWeights.length];
final double[] goldExpectation = new double[featureWeights.length];
double loglikelihood = 0.0;
for (final TrainingExample trainingExample : trainingData) {
loglikelihood = loglikelihood
+ computeExpectationsForTrainingExample(trainingExample, featureWeights, modelExpectation,
goldExpectation);
}
final double[] gradient = Util.subtract(goldExpectation, modelExpectation);
final FunctionValues result = new FunctionValues(loglikelihood, gradient);
return result;
}
示例6: getTrainers
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
private Collection<RemoteTrainer> getTrainers(final Map<FeatureKey, Integer> featureToIndex)
throws NotBoundException, IOException {
final File modelFolder = trainingParameters.getModelFolder();
modelFolder.mkdirs();
// Much quicker to transfer settings with files than over RMI
Util.serialize(trainingParameters, new File(modelFolder, "parameters"));
Util.serialize(cutoffsDictionary, new File(modelFolder, "cutoffs"));
Util.serialize(featureToIndex, trainingParameters.getFeatureToIndexFile());
final List<String> servers = new ArrayList<>();
for (final String line : Util.readFile(new File("servers.txt"))) {
servers.add(line);
}
return RemoteTrainer.getTrainers(servers);
}
示例7: train
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
private double[] train(final DifferentiableFunction lossFunction, final Map<FeatureKey, Integer> featureToIndex,
final Set<FeatureKey> boundedFeatures) throws IOException {
trainingParameters.getModelFolder().mkdirs();
final double[] weights = new double[featureToIndex.size()];
// Do training
train(lossFunction, Optimization.makeLBFGS(featureToIndex, boundedFeatures), weights);
// Save model
Util.serialize(weights, trainingParameters.getWeightsFile());
Util.serialize(trainingParameters.getFeatureSet(), trainingParameters.getFeaturesFile());
Util.serialize(featureToIndex, trainingParameters.getFeatureToIndexFile());
final File modelFolder = trainingParameters.getModelFolder();
modelFolder.mkdirs();
Files.copy(new File(dataParameters.getExistingModel(), "categories"), new File(modelFolder, "categories"));
Util.serialize(trainingParameters.getFeatureSet(), new File(modelFolder, "features"));
Util.serialize(cutoffsDictionary, new File(modelFolder, "cutoffs"));
Files.copy(new File(dataParameters.getExistingModel(), "unaryRules"), new File(modelFolder, "unaryRules"));
Files.copy(new File(dataParameters.getExistingModel(), "markedup"), new File(modelFolder, "markedup"));
Files.copy(new File(dataParameters.getExistingModel(), "seenRules"), new File(modelFolder, "seenRules"));
return weights;
}
示例8: evaluate
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
private void evaluate(final double testingSupertaggerBeam, final Optional<Double> supertaggerWeight)
throws IOException {
final int maxSentenceLength = 70;
final POSTagger posTagger = POSTagger
.getStanfordTagger(new File(dataParameters.getExistingModel(), "posTagger"));
final SRLParser parser = new JointSRLParser(EasySRL.makeParser(trainingParameters.getModelFolder()
.getAbsolutePath(), testingSupertaggerBeam, ParsingAlgorithm.ASTAR, 20000, true, supertaggerWeight, 1,
70), posTagger);
final SRLParser backoff = new BackoffSRLParser(parser, new PipelineSRLParser(EasySRL.makeParser(dataParameters
.getExistingModel().getAbsolutePath(), 0.0001, ParsingAlgorithm.ASTAR, 100000, false, Optional.empty(),
1, 70), Util.deserialize(new File(dataParameters.getExistingModel(), "labelClassifier")), posTagger));
final Results results = SRLEvaluation
.evaluate(backoff, ParallelCorpusReader.getPropBank00(), maxSentenceLength);
System.out.println("Final result: F1=" + results.getF1());
}
示例9: printParse
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
@Override
protected void printParse(final SyntaxTreeNode parse, final int sentenceNumber, final StringBuilder result) {
final List<List<ResolvedDependency>> labels = new ArrayList<>();
for (final SyntaxTreeNodeLeaf leaf : parse.getLeaves()) {
labels.add(new ArrayList<>(leaf.getCategory().getNumberOfArguments()));
for (int i = 0; i < leaf.getCategory().getNumberOfArguments(); i++) {
labels.get(labels.size() - 1).add(null); // TODO
}
}
for (final ResolvedDependency dep : parse.getAllLabelledDependencies()) {
final List<ResolvedDependency> labelsForWord = labels.get(dep.getHead());
if (dep.getArgumentIndex() > -1) {
labelsForWord.set(dep.getArgNumber() - 1, dep);
}
}
Preconditions.checkState(parse.getSemantics().isPresent());
result.append(parse.getSemantics().get());
Util.debugHook();
}
示例10: makeParser
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
@Deprecated
public static Parser makeParser(final CommandLineArguments commandLineOptions, final int maxChartSize,
final ModelFactory modelFactory) throws IOException {
final File modelFolder = Util.getFile(commandLineOptions.getModel());
Coindexation.parseMarkedUpFile(new File(modelFolder, "markedup"));
final ParsingAlgorithm algorithm = ParsingAlgorithm.valueOf(commandLineOptions.getParsingAlgorithm()
.toUpperCase());
final Parser parser;
final int nBest = commandLineOptions.getNbest();
if (algorithm == ParsingAlgorithm.CKY) {
parser = new ParserCKY(modelFactory, commandLineOptions.getMaxLength(), nBest,
commandLineOptions.getRootCategories(), modelFolder, maxChartSize);
} else if (algorithm == ParsingAlgorithm.BEAM) {
parser = new ParserBeamSearch(modelFactory, commandLineOptions.getMaxLength(), nBest,
commandLineOptions.getRootCategories(), modelFolder, maxChartSize);
} else {
parser = new ParserAStar(modelFactory, commandLineOptions.getMaxLength(), nBest,
commandLineOptions.getRootCategories(), modelFolder, maxChartSize);
}
return parser;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: getPropbankSection
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
private static Collection<SRLParse> getPropbankSection(final String section) throws IOException {
final Table<String, Integer, TreebankParse> PTB = new PennTreebank().readCorpus(WSJ);
final Table<String, Integer, SRLParse> srlParses = SRLParse.parseCorpus(PTB,
Util.readFileLineByLine(new File(PROPBANK, "prop.txt")),
USING_NOMBANK ? Util.readFileLineByLine(NOMBANK) : null);
final Table<String, Integer, SRLParse> goldParses = TreeBasedTable.create();
for (final Cell<String, Integer, TreebankParse> cell : PTB.cellSet()) {
// Propbank files skip sentences with no SRL deps. Add a default
// empty parse for all sentences.
goldParses.put(cell.getRowKey(), cell.getColumnKey(), new SRLParse(cell.getValue().getWords()));
}
goldParses.putAll(srlParses);
final Collection<SRLParse> result = new ArrayList<>();
for (final Cell<String, Integer, SRLParse> entry : goldParses.cellSet()) {
if (entry.getRowKey().startsWith("wsj_" + section)) {
result.add(entry.getValue());
}
}
return result;
}
示例15: fromString2
import edu.uw.easysrl.util.Util; //导入依赖的package包/类
@Override
Logic fromString2(final String input, final Map<String, Variable> nameToVar) {
final int i = input.indexOf("(");
final String predicateString = input.substring(0, i);
String argumentsString = input.substring(i + 1, input.length() - 1);
final List<Logic> arguments = new ArrayList<>();
int comma = Util.findNonNestedChar(argumentsString, ",");
while (comma != -1) {
final String argumentString = argumentsString.substring(0, comma);
parseArgument(predicateString, argumentString, arguments, nameToVar);
argumentsString = argumentsString.substring(comma + 1);
comma = Util.findNonNestedChar(argumentsString, ",");
}
parseArgument(predicateString, argumentsString, arguments, nameToVar);
if (VARIABLE_PARSER.canApply(predicateString, nameToVar)) {
return new AtomicSentence(VARIABLE_PARSER.fromString2(predicateString, nameToVar), arguments);
} else if (CONSTANT_PARSER.canApply(predicateString, nameToVar)) {
return new AtomicSentence(predicateString, arguments);
} else {
throw new IllegalArgumentException("Expected predicate: " + predicateString);
}
}