本文整理汇总了Java中edu.stanford.nlp.util.Function类的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于edu.stanford.nlp.util包,在下文中一共展示了Function类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: transformTree
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
@Override
public Tree transformTree(Tree t, Tree root) {
StringBuilder newCategory = new StringBuilder(t.label().value());
for (Map.Entry<TregexPattern,Function<TregexMatcher,String>> e : activeAnnotations.entrySet()) {
TregexMatcher m = e.getKey().matcher(root);
if (m.matchesAt(t)) {
newCategory.append(e.getValue().apply(m));
// System.out.println("node match " + e.getValue()); //testing
// t.pennPrint(); //testing
}
}
String newCat = newCategory.toString();
t.label().setValue(newCat);
// cdm Mar 2005: the equivalent of the below wasn't being done in the old
// code, but it really needs to be!
if (t.isPreTerminal()) {
HasTag lab = (HasTag) t.label();
lab.setTag(newCat);
}
// t.pennPrint(); //testing
return t;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:25,代码来源:ArabicTreebankParserParams.java
示例2: main
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* This method just tests the functionality of the included transformers.
*/
public static void main(String[] args) {
//TreeFactory tf = new LabeledScoredTreeFactory();
Tree stringyTree = null;
try {
stringyTree = (new PennTreeReader(new StringReader("(S (VP (VBZ Try) (NP (DT this))) (. .))"), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree();
} catch (IOException e) {
}
System.out.println(stringyTree);
Function<Tree, Tree> a = getLabeledTreeToCategoryWordTagTreeFunction();
Tree adaptyTree = a.apply(stringyTree);
System.out.println(adaptyTree);
adaptyTree.percolateHeads(new CollinsHeadFinder());
System.out.println(adaptyTree);
Function<Tree, Tree> b = getLabeledTreeToStringLabeledTreeFunction();
Tree stringLabelTree = b.apply(adaptyTree);
System.out.println(stringLabelTree);
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:23,代码来源:TreeFunctions.java
示例3: UnbrokenCategoryDominates
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
*
* @param arg This may have a ! and then maybe a @ and then either an
* identifier or regex
*/
UnbrokenCategoryDominates(String arg,
Function<String, String> basicCatFunction) {
super("<+(" + arg + ')');
if (arg.startsWith("!")) {
negatedPattern = true;
arg = arg.substring(1);
} else {
negatedPattern = false;
}
if (arg.startsWith("@")) {
basicCat = true;
this.basicCatFunction = basicCatFunction;
arg = arg.substring(1);
} else {
basicCat = false;
}
if (arg.matches("/.*/")) {
pattern = Pattern.compile(arg.substring(1, arg.length() - 1));
} else if (arg.matches("__")) {
pattern = Pattern.compile("^.*$");
} else {
pattern = Pattern.compile("^(?:" + arg + ")$");
}
}
开发者ID:jaimeguzman,项目名称:data_mining,代码行数:30,代码来源:Relation.java
示例4: main
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* This method just tests the functionality of the included transformers.
*/
public static void main(String[] args) {
//TreeFactory tf = new LabeledScoredTreeFactory();
Tree stringyTree = null;
try {
stringyTree = (new PennTreeReader(new StringReader("(S (VP (VBZ Try) (NP (DT this))) (. .))"), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree();
} catch (IOException e) {
// do nothing
}
System.out.println(stringyTree);
Function<Tree, Tree> a = getLabeledTreeToCategoryWordTagTreeFunction();
Tree adaptyTree = a.apply(stringyTree);
System.out.println(adaptyTree);
adaptyTree.percolateHeads(new CollinsHeadFinder());
System.out.println(adaptyTree);
Function<Tree, Tree> b = getLabeledTreeToStringLabeledTreeFunction();
Tree stringLabelTree = b.apply(adaptyTree);
System.out.println(stringLabelTree);
}
开发者ID:amark-india,项目名称:eventspotter,代码行数:24,代码来源:TreeFunctions.java
示例5: UnbrokenCategoryFollows
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* @param arg The pattern to match, perhaps preceded by ! and/or @
*/
UnbrokenCategoryFollows(String arg,
Function<String, String> basicCatFunction) {
super(",+(" + arg + ')');
if (arg.startsWith("!")) {
negatedPattern = true;
arg = arg.substring(1);
} else {
negatedPattern = false;
}
if (arg.startsWith("@")) {
basicCat = true;
this.basicCatFunction = basicCatFunction;
arg = arg.substring(1);
} else {
basicCat = false;
}
if (arg.matches("/.*/")) {
pattern = Pattern.compile(arg.substring(1, arg.length() - 1));
} else if (arg.matches("__")) {
pattern = Pattern.compile("^.*$");
} else {
pattern = Pattern.compile("^(?:" + arg + ")$");
}
}
开发者ID:amark-india,项目名称:eventspotter,代码行数:28,代码来源:Relation.java
示例6: DelimitRegExIterator
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
public DelimitRegExIterator(Reader r, String delimiter, Function<String,T> op) {
this.op = op;
BufferedReader in = new BufferedReader(r);
try {
String line;
StringBuilder input = new StringBuilder();
while ((line = in.readLine()) != null) {
input.append(line).append("\n");
}
line = input.toString();
Pattern p = Pattern.compile("^"+delimiter);
Matcher m = p.matcher(line);
line = m.replaceAll("");
p = Pattern.compile(delimiter+"$");
m = p.matcher(line);
line = m.replaceAll("");
line = line.trim();
tokens = Arrays.asList(line.split(delimiter)).iterator();
} catch (Exception e) {
}
setNext();
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:24,代码来源:DelimitRegExIterator.java
示例7: UnbrokenCategoryPrecedes
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* @param arg The pattern to match, perhaps preceded by ! and/or @
*/
UnbrokenCategoryPrecedes(String arg,
Function<String, String> basicCatFunction) {
super(".+(" + arg + ')');
if (arg.startsWith("!")) {
negatedPattern = true;
arg = arg.substring(1);
} else {
negatedPattern = false;
}
if (arg.startsWith("@")) {
basicCat = true;
this.basicCatFunction = basicCatFunction; // todo -- this was missing a this. which must be testable in a unit test!!! Make one
arg = arg.substring(1);
} else {
basicCat = false;
}
if (arg.matches("/.*/")) {
pattern = Pattern.compile(arg.substring(1, arg.length() - 1));
} else if (arg.matches("__")) {
pattern = Pattern.compile("^.*$");
} else {
pattern = Pattern.compile("^(?:" + arg + ")$");
}
}
开发者ID:jaimeguzman,项目名称:data_mining,代码行数:28,代码来源:Relation.java
示例8: annotate
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* Annotate a collection of input annotations IN PARALLEL, making use of threads given in numThreads.
*
* @param annotations
* The input annotations to process
* @param numThreads
* The number of threads to run on
*/
public void annotate(final Iterable<Annotation> annotations, int numThreads) {
annotate(annotations, numThreads, new Function<Annotation, Object>() {
@Override
public Object apply(Annotation in) {
return null;
}
});
}
开发者ID:begab,项目名称:kpe,代码行数:17,代码来源:SzTEAnnotationPipeline.java
示例9: tallyTreeIterator
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
protected void tallyTreeIterator(Iterator<Tree> treeIterator, Function<Tree, Tree> f) {
while (treeIterator.hasNext()) {
Tree tree = treeIterator.next();
try {
tree = f.apply(tree);
} catch (Exception e) {
if (Test.verbose) {
e.printStackTrace();
}
}
tallyTree(tree);
}
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:14,代码来源:AbstractTreeExtractor.java
示例10: getSentencesFromXML
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* Returns a list of sentences contained in an XML file, occuring between the begin and end of a selected tag.
*
* @param splitOnTag the tag which denotes text boundaries
* @param sentenceDelimiter The text that separates sentences
* @param doPTBEscaping whether to escape PTB tokens using a {@link PTBEscapingProcessor}
* @return A list of sentences contained in an XML file
*/
public List<List<? extends HasWord>> getSentencesFromXML(Reader input, String splitOnTag, String sentenceDelimiter, boolean doPTBEscaping) {
Function<List<HasWord>, List<HasWord>> escaper;
if (doPTBEscaping) {
escaper = new PTBEscapingProcessor();
} else {
escaper = new NullEscaper();
}
return getSentencesFromXML(input, escaper, splitOnTag, sentenceDelimiter);
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:18,代码来源:DocumentPreprocessor.java
示例11: getSentencesFromText
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
private List<List<? extends HasWord>> getSentencesFromText(Reader fileOrURL, boolean doPTBEscaping, String sentenceDelimiter, int tagDelimiter) {
Function<List<HasWord>, List<HasWord>> escaper;
if (doPTBEscaping) {
escaper = new PTBEscapingProcessor();
} else {
escaper = new NullEscaper();
}
return getSentencesFromText(fileOrURL, escaper, sentenceDelimiter, tagDelimiter);
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:10,代码来源:DocumentPreprocessor.java
示例12: transform
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* Returns the counter with keys modified according to function F. Eager evaluation.
*/
public static <T1,T2> Counter<T2> transform(Counter<T1> c, Function<T1,T2> f) {
Counter<T2> c2 = new ClassicCounter<T2>();
for(T1 key : c.keySet()) {
c2.setCount(f.apply(key),c.getCount(key));
}
return c2;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:11,代码来源:Counters.java
示例13: XMLBeginEndIterator
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
public XMLBeginEndIterator(Reader in, String tagNameRegexp, Function<String,E> op, boolean keepInternalTags, boolean keepDelimitingTags) {
this.tagNamePattern = Pattern.compile(tagNameRegexp);
this.op = op;
this.keepInternalTags = keepInternalTags;
this.keepDelimitingTags = keepDelimitingTags;
this.in = new BufferedReader(in);
setNext();
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:9,代码来源:XMLBeginEndIterator.java
示例14: lexicalize
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* Returns a lexicalized Tree whose Labels are CategoryWordTag
* instances, all corresponds to the input tree.
*/
public static Tree lexicalize(Tree t, HeadFinder hf) {
Function<Tree,Tree> a = TreeFunctions.getLabeledTreeToCategoryWordTagTreeFunction();
Tree t1 = a.apply(t);
t1.percolateHeads(hf);
return t1;
}
开发者ID:FabianFriedrich,项目名称:Text2Process,代码行数:11,代码来源:Trees.java
示例15: tallyTreeIterator
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
protected void tallyTreeIterator(Iterator<Tree> treeIterator,
Function<Tree, Tree> f, double weight) {
while (treeIterator.hasNext()) {
Tree tree = treeIterator.next();
try {
tree = f.apply(tree);
} catch (Exception e) {
if (op.testOptions.verbose) {
e.printStackTrace();
}
}
tallyTree(tree, weight);
}
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:15,代码来源:AbstractTreeExtractor.java
示例16: LazyLoadTreesByParsing
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
public LazyLoadTreesByParsing(String filename, String encoding, boolean tokenized, Function<Object, Tree> lp) {
this.filename = filename;
this.encoding = encoding;
this.reader = null;
this.tokenized = tokenized;
this.lp = lp;
}
开发者ID:amark-india,项目名称:eventspotter,代码行数:8,代码来源:GrammaticalStructure.java
示例17: lexicalize
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
/**
* Returns a lexicalized Tree whose Labels are CategoryWordTag
* instances, all corresponds to the input tree.
*/
public static Tree lexicalize(Tree t, HeadFinder hf) {
Function<Tree,Tree> a =
TreeFunctions.getLabeledTreeToCategoryWordTagTreeFunction();
Tree t1 = a.apply(t);
t1.percolateHeads(hf);
return t1;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:12,代码来源:Trees.java
示例18: removeBaselineFeature
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
private void removeBaselineFeature(String featName) {
if(baselineFeatures.contains(featName)) {
baselineFeatures.remove(featName);
Pair<TregexPattern,Function<TregexMatcher,String>> p = annotationPatterns.get(featName);
activeAnnotations.remove(p);
}
}
开发者ID:amark-india,项目名称:eventspotter,代码行数:8,代码来源:ArabicTreebankParserParams.java
示例19: loadParser
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
private static Function<List<? extends HasWord>, Tree> loadParser(String parserFile, String parserOptions, boolean makeCopulaHead) {
if (parserFile == null || "".equals(parserFile)) {
parserFile = DEFAULT_PARSER_FILE;
if (parserOptions == null) {
parserOptions = "-retainTmpSubcategories";
}
}
if (parserOptions == null) {
parserOptions = "";
}
if (makeCopulaHead) {
parserOptions = "-makeCopulaHead " + parserOptions;
}
parserOptions = parserOptions.trim();
// Load parser by reflection, so that this class doesn't require parser
// for runtime use
// LexicalizedParser lp = LexicalizedParser.loadModel(parserFile);
// For example, the tregex package uses TreePrint, which uses
// GrammaticalStructure, which would then import the
// LexicalizedParser. The tagger can read trees, which means it
// would depend on tregex and therefore depend on the parser.
Function<List<? extends HasWord>, Tree> lp;
try {
Class<?>[] classes = new Class<?>[] { String.class, String[].class };
Method method = Class.forName("edu.stanford.nlp.parser.lexparser.LexicalizedParser").getMethod("loadModel", classes);
String[] opts = {};
if (parserOptions.length() > 0) {
opts = parserOptions.split(" +");
}
lp = (Function<List<? extends HasWord>,Tree>) method.invoke(null, parserFile, opts);
} catch (Exception cnfe) {
throw new RuntimeException(cnfe);
}
return lp;
}
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:36,代码来源:GrammaticalStructure.java
示例20: XMLBeginEndIterator
import edu.stanford.nlp.util.Function; //导入依赖的package包/类
public XMLBeginEndIterator(Reader in, String tagNameRegexp, Function<String,E> op,
boolean keepInternalTags, boolean keepDelimitingTags, boolean countDepth) {
this.tagNamePattern = Pattern.compile(tagNameRegexp);
this.op = op;
this.keepInternalTags = keepInternalTags;
this.keepDelimitingTags = keepDelimitingTags;
this.countDepth = countDepth;
this.inputReader = new BufferedReader(in);
setNext();
}
开发者ID:chbrown,项目名称:stanford-parser,代码行数:11,代码来源:XMLBeginEndIterator.java
注:本文中的edu.stanford.nlp.util.Function类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论