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


Java Redwood类代码示例

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


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

示例1: trainModel

import edu.stanford.nlp.util.logging.Redwood; //导入依赖的package包/类
public static void trainModel() throws IOException {
    forceTrack("Training data");
    List<Pair<KBPInput, String>> trainExamples = DatasetUtils.readDataset(TRAIN_FILE);
    log.info("Read " + trainExamples.size() + " examples");
    log.info("" + trainExamples.stream().map(Pair::second).filter(NO_RELATION::equals).count() + " are " + NO_RELATION);
    endTrack("Training data");

    // Featurize + create the dataset
    forceTrack("Creating dataset");
    RVFDataset<String, String> dataset = new RVFDataset<>();
    final AtomicInteger i = new AtomicInteger(0);
    long beginTime = System.currentTimeMillis();
    trainExamples.stream().parallel().forEach(example -> {
        if (i.incrementAndGet() % 1000 == 0) {
            log.info("[" + Redwood.formatTimeDifference(System.currentTimeMillis() - beginTime) +
                    "] Featurized " + i.get() + " / " + trainExamples.size() + " examples");
        }
        Counter<String> features = features(example.first);  // This takes a while per example
        synchronized (dataset) {
            dataset.add(new RVFDatum<>(features, example.second));
        }
    });
    trainExamples.clear();  // Free up some memory
    endTrack("Creating dataset");

    // Train the classifier
    log.info("Training classifier:");
    Classifier<String, String> classifier = trainMultinomialClassifier(dataset, FEATURE_THRESHOLD, SIGMA);
    dataset.clear();  // Free up some memory

    // Save the classifier
    IOUtils.writeObjectToFile(new IntelKBPStatisticalExtractor(classifier), MODEL_FILE);
}
 
开发者ID:intel-analytics,项目名称:InformationExtraction,代码行数:34,代码来源:IntelKBPStatisticalExtractor.java

示例2: 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);
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:31,代码来源:ArrayCoreMap.java

示例3: annotate

import edu.stanford.nlp.util.logging.Redwood; //导入依赖的package包/类
public void annotate(Annotation annotation) {
  if (verbose) {
    timer.start();
    Redwood.log(Redwood.DBG, "Adding TokensRegexAnnotator annotation...");
  }

  if (options.setTokenOffsets) {
    addTokenOffsets(annotation);
  }
  List<CoreMap> allMatched;
  if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
    allMatched = new ArrayList<CoreMap>();
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
      List<CoreMap> matched = extract(sentence);
      if (matched != null && options.matchedExpressionsAnnotationKey != null) {
        allMatched.addAll(matched);
        sentence.set(options.matchedExpressionsAnnotationKey, matched);
        for (CoreMap cm:matched) {
          cm.set(CoreAnnotations.SentenceIndexAnnotation.class, sentence.get(CoreAnnotations.SentenceIndexAnnotation.class));
        }
      }
    }
  } else {
    allMatched = extract(annotation);
  }
  if (options.matchedExpressionsAnnotationKey != null) {
    annotation.set(options.matchedExpressionsAnnotationKey, allMatched);
  }

  if (verbose)
    timer.stop("done.");
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:34,代码来源:TokensRegexAnnotator.java

示例4: 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);
}
 
开发者ID:begab,项目名称:kpe,代码行数:62,代码来源:SzTEAnnotationPipeline.java

示例5: 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 );
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:51,代码来源:AnnotationPipeline.java

示例6: annotate

import edu.stanford.nlp.util.logging.Redwood; //导入依赖的package包/类
public void annotate(Annotation annotation) {
      TimeIndex timeIndex = new TimeIndex();
  String docDate = annotation.get(CoreAnnotations.DocDateAnnotation.class);
  if(docDate == null){
    Calendar cal = annotation.get(CoreAnnotations.CalendarAnnotation.class);
    if(cal == null){
      Redwood.log(Redwood.WARN, "No document date specified");
    } else {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss");
      docDate = dateFormat.format(cal.getTime());
    }
  }
  List<CoreMap> allTimeExpressions; // initialized below = null;
  List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
  if (sentences != null) {
    allTimeExpressions = new ArrayList<CoreMap>();
    List<CoreMap> allNumerics = new ArrayList<CoreMap>();
    for (CoreMap sentence: sentences) {
      // make sure that token character offsets align with the actual sentence text
      // They may not align due to token normalizations, such as "(" to "-LRB-".
      CoreMap alignedSentence =  NumberSequenceClassifier.alignSentence(sentence); 
      // uncomment the next line for verbose dumping of tokens....
      // System.err.println("SENTENCE: " + ((ArrayCoreMap) sentence).toShorterString());
      List<CoreMap> timeExpressionsForSentence = 
        timexExtractor.extractTimeExpressionCoreMaps(alignedSentence, docDate, timeIndex);
      if (timeExpressionsForSentence != null) {
        allTimeExpressions.addAll(timeExpressionsForSentence);
        sentence.set(TimeAnnotations.TimexAnnotations.class, timeExpressionsForSentence);
        for (CoreMap timeExpression:timeExpressionsForSentence) {
          timeExpression.set(CoreAnnotations.SentenceIndexAnnotation.class, sentence.get(CoreAnnotations.SentenceIndexAnnotation.class));
        }
      }
      List<CoreMap> numbers = alignedSentence.get(CoreAnnotations.NumerizedTokensAnnotation.class);
      if(numbers != null){
        sentence.set(CoreAnnotations.NumerizedTokensAnnotation.class, numbers);
        allNumerics.addAll(numbers);
      }
    }
    annotation.set(CoreAnnotations.NumerizedTokensAnnotation.class, allNumerics);
  } else {
    allTimeExpressions = annotateSingleSentence(annotation, docDate, timeIndex);
  }
  annotation.set(TimeAnnotations.TimexAnnotations.class, allTimeExpressions);
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:45,代码来源:TimeAnnotator.java


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