本文整理汇总了Java中edu.stanford.nlp.util.logging.Redwood.startTrack方法的典型用法代码示例。如果您正苦于以下问题:Java Redwood.startTrack方法的具体用法?Java Redwood.startTrack怎么用?Java Redwood.startTrack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.util.logging.Redwood
的用法示例。
在下文中一共展示了Redwood.startTrack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prettyLog
import edu.stanford.nlp.util.logging.Redwood; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public void prettyLog(RedwoodChannels channels, String description) {
Redwood.startTrack(description);
// sort keys by class name
List<Class> sortedKeys = new ArrayList<Class>(this.keySet());
Collections.sort(sortedKeys,
new Comparator<Class>(){
@Override
public int compare(Class a, Class b) {
return a.getCanonicalName().compareTo(b.getCanonicalName());
}
});
// log key/value pairs
for (Class key : sortedKeys) {
String keyName = key.getCanonicalName().replace("class ", "");
Object value = this.get(key);
if (PrettyLogger.dispatchable(value)) {
PrettyLogger.log(channels, keyName, value);
} else {
channels.logf("%s = %s", keyName, value);
}
}
Redwood.endTrack(description);
}
示例2: annotate
import edu.stanford.nlp.util.logging.Redwood; //导入方法依赖的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
* @param callback
* A function to be called when an annotation finishes. The return value of the callback is ignored.
*/
public void annotate(final Iterable<Annotation> annotations, int numThreads, final Function<Annotation, Object> callback) {
// case: single thread (no point in spawning threads)
if (numThreads == 1) {
for (Annotation ann : annotations) {
annotate(ann);
callback.apply(ann);
}
}
// Java's equivalent to ".map{ lambda(annotation) => annotate(annotation) }
Iterable<Runnable> threads = new Iterable<Runnable>() {
@Override
public Iterator<Runnable> iterator() {
final Iterator<Annotation> iter = annotations.iterator();
return new Iterator<Runnable>() {
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public Runnable next() {
if (!iter.hasNext()) {
throw new NoSuchElementException();
}
final Annotation input = iter.next();
return new Runnable() {
@Override
public void run() {
// (logging)
String beginningOfDocument = input.toString().substring(0, Math.min(50, input.toString().length()));
Redwood.startTrack("Annotating \"" + beginningOfDocument + "...\"");
// (annotate)
annotate(input);
// (callback)
callback.apply(input);
// (logging again)
Redwood.endTrack("Annotating \"" + beginningOfDocument + "...\"");
}
};
}
@Override
public void remove() {
iter.remove();
}
};
}
};
// Thread
Redwood.Util.threadAndRun(this.getClass().getSimpleName(), threads, numThreads);
}
示例3: annotate
import edu.stanford.nlp.util.logging.Redwood; //导入方法依赖的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
* @param callback A function to be called when an annotation finishes.
* The return value of the callback is ignored.
*/
public void annotate(final Iterable<Annotation> annotations, int numThreads, final Function<Annotation,Object> callback){
// case: single thread (no point in spawning threads)
if(numThreads == 1){
for(Annotation ann : annotations){
annotate(ann);
callback.apply(ann);
}
}
// Java's equivalent to ".map{ lambda(annotation) => annotate(annotation) }
Iterable<Runnable> threads = new Iterable<Runnable>(){
public Iterator<Runnable> iterator() {
final Iterator<Annotation> iter = annotations.iterator();
return new Iterator<Runnable>(){
public boolean hasNext() {
return iter.hasNext();
}
public Runnable next() {
final Annotation input = iter.next();
return new Runnable(){
public void run(){
//Jesus Christ, finally the body of the code
//(logging)
String beginningOfDocument = input.toString().substring(0,Math.min(50,input.toString().length()));
Redwood.startTrack("Annotating \"" + beginningOfDocument + "...\"");
//(annotate)
annotate(input);
//(callback)
callback.apply(input);
//(logging again)
Redwood.endTrack("Annotating \"" + beginningOfDocument + "...\"");
}
};
}
public void remove() {
iter.remove();
}
};
}
};
// Thread
Redwood.Util.threadAndRun(this.getClass().getSimpleName(), threads, numThreads );
}