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


Java Trees类代码示例

本文整理汇总了Java中edu.berkeley.nlp.syntax.Trees的典型用法代码示例。如果您正苦于以下问题:Java Trees类的具体用法?Java Trees怎么用?Java Trees使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Trees类属于edu.berkeley.nlp.syntax包,在下文中一共展示了Trees类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
	Tree<String> goldTree = (new Trees.PennTreeReader(new StringReader(
			"(ROOT (S (NP (DT the) (NN can)) (VP (VBD fell))))"))).next();
	Tree<String> guessedTree = (new Trees.PennTreeReader(new StringReader(
			"(ROOT (S (NP (DT the)) (VP (MB can) (VP (VBD fell)))))")))
			.next();
	LabeledConstituentEval<String> eval = new LabeledConstituentEval<String>(
			Collections.singleton("ROOT"), new HashSet<String>());
	RuleEval<String> rule_eval = new RuleEval<String>(
			Collections.singleton("ROOT"), new HashSet<String>());
	System.out.println("Gold tree:\n"
			+ Trees.PennTreeRenderer.render(goldTree));
	System.out.println("Guessed tree:\n"
			+ Trees.PennTreeRenderer.render(guessedTree));
	eval.evaluate(guessedTree, goldTree);
	eval.display(true);
	rule_eval.evaluate(guessedTree, goldTree);
	rule_eval.display(true);
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:20,代码来源:EnglishPennTreebankParseEvaluator.java

示例2: unAnnotateTreeSpecial

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static Tree<String> unAnnotateTreeSpecial(Tree<String> annotatedTree) {
	// Remove intermediate nodes (labels beginning with "Y"
	// Remove all material on node labels which follow their base symbol
	// (cuts at the leftmost -, ^, or : character)
	// Examples: a node with label @NP->DT_JJ will be spliced out, and a
	// node with label NP^S will be reduced to NP
	Tree<String> debinarizedTree = Trees.spliceNodes(annotatedTree,
			new Filter<String>() {
				public boolean accept(String s) {
					return s.startsWith("Y");
				}
			});
	Tree<String> unAnnotatedTree = (new Trees.FunctionNodeStripper())
			.transformTree(debinarizedTree);
	return unAnnotatedTree;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:17,代码来源:TreeAnnotations.java

示例3: unAnnotateTree

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static Tree<String> unAnnotateTree(Tree<String> annotatedTree,
		boolean keepFunctionLabel) {
	// Remove intermediate nodes (labels beginning with "@"
	// Remove all material on node labels which follow their base symbol
	// (cuts at the leftmost -, ^, or : character)
	// Examples: a node with label @NP->DT_JJ will be spliced out, and a
	// node with label NP^S will be reduced to NP
	Tree<String> debinarizedTree = Trees.spliceNodes(annotatedTree,
			new Filter<String>() {
				public boolean accept(String s) {
					return s.startsWith("@") && !s.equals("@");
				}
			});
	if (keepFunctionLabel)
		return debinarizedTree;
	Tree<String> unAnnotatedTree = (new Trees.FunctionNodeStripper())
			.transformTree(debinarizedTree);
	return unAnnotatedTree;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:20,代码来源:TreeAnnotations.java

示例4: main

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static void main(String args[]) {
	// test the binarization
	Trees.PennTreeReader reader = new Trees.PennTreeReader(
			new StringReader(
					"((S (NP (DT the) (JJ quick) (JJ (AA (BB (CC brown)))) (NN fox)) (VP (VBD jumped) (PP (IN over) (NP (DT the) (JJ lazy) (NN dog)))) (. .)))"));
	Tree<String> tree = reader.next();
	System.out.println("tree");
	System.out.println(Trees.PennTreeRenderer.render(tree));
	for (Binarization binarization : Binarization.values()) {
		System.out.println("binarization type " + binarization.name());
		// print the binarization
		try {
			Tree<String> binarizedTree = binarizeTree(tree, binarization);
			System.out
					.println(Trees.PennTreeRenderer.render(binarizedTree));
			System.out.println("unbinarized");
			Tree<String> unBinarizedTree = unAnnotateTree(binarizedTree,
					false);
			System.out.println(Trees.PennTreeRenderer
					.render(unBinarizedTree));
			System.out.println("------------");
		} catch (Error e) {
			System.out.println("binarization not implemented");
		}
	}
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:27,代码来源:TreeAnnotations.java

示例5: readTrees

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static List<Tree<String>> readTrees(String basePath, int low,
		int high, Charset charset) throws Exception {
	Collection<Tree<String>> trees = PennTreebankReader.readTrees(basePath,
			low, high, charset);
	// System.out.println("in readTrees");
	// normalize trees
	Trees.TreeTransformer<String> treeTransformer = (keepFunctionLabels) ? new Trees.FunctionLabelRetainingTreeNormalizer()
			: new Trees.StandardTreeNormalizer();
	List<Tree<String>> normalizedTreeList = new ArrayList<Tree<String>>();
	for (Tree<String> tree : trees) {
		Tree<String> normalizedTree = treeTransformer.transformTree(tree);
		normalizedTreeList.add(normalizedTree);
	}
	if (normalizedTreeList.size() == 0) {
		throw new Exception("failed to load any trees at " + basePath
				+ " from " + low + " to " + high);
	}
	return normalizedTreeList;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:20,代码来源:Corpus.java

示例6: main

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
/**
 * Go through trees and determine their heads and print them. Just for
 * debuggin'. <br>
 * Usage: <code>
 * java edu.stanford.nlp.trees.CollinsHeadFinder treebankFilePath
 * </code>
 * 
 * @param args
 *            The treebankFilePath
 */

public static void main(String[] args) {
	Trees.PennTreeReader reader = new Trees.PennTreeReader(
			new StringReader(
					"((S (NP (DT the) (JJ quick) (JJ (AA (BB (CC brown)))) (NN fox)) (VP (VBD jumped) (PP (IN over) (NP (DT the) (JJ lazy) (NN dog)))) (. .)))"));
	Tree<String> tree = reader.next();
	System.out.println("tree " + tree);

	CollinsHeadFinder headFinder = new CollinsHeadFinder();
	while (!tree.isLeaf()) {
		Tree<String> head = headFinder.determineHead(tree);
		System.out.println("head " + head);
		tree = head;
	}
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:26,代码来源:CollinsHeadFinder.java

示例7: labelTrees

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
private void labelTrees(Grammar grammar, List<Tree<String>> trainTrees,
		List<List<String>> goldPOStags) {
	List<Tree<String>> trainTreesNoGF = stripOffGF(trainTrees);
	StateSetTreeList stateSetTrees = new StateSetTreeList(trainTreesNoGF,
			grammar.numSubStates, false, tagNumberer);

	int index = 0;
	for (Tree<StateSet> stateSetTree : stateSetTrees) {
		List<String> goldPOS = goldPOStags.get(index++);

		Tree<String> labeledTree = guessGF(stateSetTree, grammar, goldPOS);

		Tree<String> debinarizedTree = Trees.spliceNodes(labeledTree,
				new Filter<String>() {
					public boolean accept(String s) {
						return s.startsWith("@");
					}
				});

		System.out.println(debinarizedTree + "\n");
	}

}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:24,代码来源:GermanSharedTask.java

示例8: advance

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
private void advance() {
	nextTreeIterator = null;
	while (nextTreeIterator == null && fileIterator.hasNext()) {
		try {
			File file = fileIterator.next();
			nextTreeIterator = new Trees.PennTreeReader(
					new BufferedReader(new FileReader(file)));
		} catch (FileNotFoundException e) {
		}
	}
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:12,代码来源:PennTreebankReader.java

示例9: main

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static void main(String[] args) {
	Collection<Tree<String>> trees = readTrees(args[0]);
	for (Tree<String> tree : trees) {
		tree = (new Trees.StandardTreeNormalizer()).transformTree(tree);
		System.out.println(Trees.PennTreeRenderer.render(tree));
	}
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:8,代码来源:PennTreebankReader.java

示例10: debinarizeTree

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static Tree<String> debinarizeTree(Tree<String> annotatedTree) {
	// Remove intermediate nodes (labels beginning with "@"
	// Remove all material on node labels which follow their base symbol
	// (cuts at the leftmost -, ^, or : character)
	// Examples: a node with label @NP->DT_JJ will be spliced out, and a
	// node with label NP^S will be reduced to NP
	Tree<String> debinarizedTree = Trees.spliceNodes(annotatedTree,
			new Filter<String>() {
				public boolean accept(String s) {
					return s.startsWith("@") && !s.equals("@");
				}
			});
	return debinarizedTree;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:15,代码来源:TreeAnnotations.java

示例11: main

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	if (args.length < 3) {
		System.out
				.println("usage: java TreeGenerator <input file for grammar> <maxLength> <nTrees>\n");
		System.exit(2);
	}
	String inFileName = args[0];
	int maxLength = Integer.parseInt(args[1]);
	int nTrees = Integer.parseInt(args[2]);

	System.out.println("Loading grammar from " + inFileName + ".");
	ParserData pData = ParserData.Load(inFileName);
	if (pData == null) {
		System.out.println("Failed to load grammar from file" + inFileName
				+ ".");
		System.exit(1);
	}

	grammar = pData.getGrammar();
	lexicon = (SophisticatedLexicon) pData.getLexicon();
	Numberer.setNumberers(pData.getNumbs());
	tagNumberer = Numberer.getGlobalNumberer("tags");
	grammar.splitRules();

	int nGen = 0;
	while (nGen < nTrees) {
		Tree<String> artTree = generateTree(0, 0);
		System.out.println(artTree.getYield().toString());
		Tree<String> tree = TreeAnnotations.unAnnotateTree(artTree, false);
		if (tree.getYield().size() > maxLength)
			continue;
		System.out.println("Generated tree of length "
				+ tree.getYield().size() + ".\n"
				+ Trees.PennTreeRenderer.render(tree) + "\n");
		nGen++;
	}

}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:42,代码来源:TreeGenerator.java

示例12: loadSingleFile

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
private void loadSingleFile(String path) throws Exception {
	System.out.print("Loading trees from single file...");
	InputStreamReader inputData = new InputStreamReader(
			new FileInputStream(path), "UTF-8");
	PennTreeReader treeReader = new PennTreeReader(inputData);

	while (treeReader.hasNext()) {
		trainTrees.add(treeReader.next());
	}

	Trees.TreeTransformer<String> treeTransformer = (keepFunctionLabels) ? new Trees.FunctionLabelRetainingTreeNormalizer()
			: new Trees.StandardTreeNormalizer();
	ArrayList<Tree<String>> normalizedTreeList = new ArrayList<Tree<String>>();
	for (Tree<String> tree : trainTrees) {
		Tree<String> normalizedTree = treeTransformer.transformTree(tree);
		normalizedTreeList.add(normalizedTree);
	}
	if (normalizedTreeList.size() == 0) {
		throw new Exception("failed to load any trees at " + path);
	}
	trainTrees = normalizedTreeList;

	devTestTrees = trainTrees;
	System.out.println("done");

	// trainTrees.addAll(readTrees(path,-1,
	// Integer.MAX_VALUE,Charset.defaultCharset()));
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:29,代码来源:Corpus.java

示例13: determineNonTrivialHead

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
protected Tree<String> determineNonTrivialHead(Tree<String> t) {
	Tree<String> theHead = null;
	String motherCat = Trees.FunctionNodeStripper.transformLabel(t);
	if (DEBUG) {
		System.err.println("Looking for head of " + t.getLabel());
	}
	// We know we have nonterminals underneath
	// (a bit of a Penn Treebank assumption, but).

	// Look at label.
	// a total special case....
	// first look for POS tag at end
	// this appears to be redundant in the Collins case since the rule
	// already would do that
	// Tree lastDtr = t.lastChild();
	// if (tlp.basicCategory(lastDtr.label().value()).equals("POS")) {
	// theHead = lastDtr;
	// } else {
	String[][] how = (String[][]) nonTerminalInfo.get(motherCat);
	if (how == null) {
		if (DEBUG) {
			System.err.println("Warning: No rule found for " + motherCat);
		}
		if (defaultRule != null) {
			return traverseLocate(t.getChildren(), defaultRule, true);
		} else {
			return null;
		}
	}
	for (int i = 0; i < how.length; i++) {
		boolean deflt = (i == how.length - 1);
		theHead = traverseLocate(t.getChildren(), how[i], deflt);
		if (theHead != null) {
			break;
		}
	}
	return theHead;
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:39,代码来源:AbstractCollinsHeadFinder.java

示例14: main

import edu.berkeley.nlp.syntax.Trees; //导入依赖的package包/类
public static void main(String[] args) {
	Collection<Tree<String>> trees = readTrees(args[0],
			Charset.defaultCharset());
	for (Tree<String> tree : trees) {
		tree = (new Trees.StandardTreeNormalizer()).transformTree(tree);
		System.out.println(Trees.PennTreeRenderer.render(tree));
	}
}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:9,代码来源:PennTreebankReader.java


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