edu.stanford.nlp.pipeline.Annotation.has()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中edu.stanford.nlp.pipeline.Annotation.has()方法的一些代码示例,展示了Annotation.has()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation.has()方法的具体详情如下:
包路径:edu.stanford.nlp.pipeline.Annotation
类名称:Annotation
方法名:has

Annotation.has介绍

暂无

代码示例

代码示例来源:origin: edu.stanford.nlp/corenlp

public void annotate(Annotation annotation) {
 // turn the annotation into a sentence
 if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
  for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
   List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
   ArrayList<TaggedWord> tagged = null;
   tagged = pos.apply(tokens);
   for (int i = 0; i < tokens.size(); ++i) {
    tokens.get(i).set(PartOfSpeechAnnotation.class, tagged.get(i).tag());
   }
  }
 } else {
  throw new RuntimeException("unable to find words/tokens in: " + annotation);
 }
}

代码示例来源:origin: edu.stanford.nlp/corenlp

public void annotate(Annotation annotation) {
 if (annotation.has(TokensAnnotation.class)) {
  List<CoreLabel> tokens = annotation.get(TokensAnnotation.class);
  List<CoreLabel> dateTokens = new ArrayList<CoreLabel>();
  List<CoreLabel> newTokens = process(tokens, dateTokens);
  // We assume that if someone is using this annotator, they don't
  // want the old tokens any more and get rid of them
  annotation.set(TokensAnnotation.class, newTokens);
  // if the doc date was found, save it. it is used by SUTime (inside the "ner" annotator)
  if(dateTokens.size() > 0){
   StringBuffer os = new StringBuffer();
   boolean first = true;
   for (CoreLabel t : dateTokens) {
    if (!first) os.append(" ");
    os.append(t.word());
    first = false;
   }
   //System.err.println("DOC DATE IS: " + os.toString());
   annotation.set(DocDateAnnotation.class, os.toString());
  }
 }
}

代码示例来源:origin: com.guokr/stan-cn-com

@Override
public void annotate(Annotation annotation) {
 if (annotation.has(CoreAnnotations.TokensAnnotation.class)) {
  List<CoreLabel> tokens = annotation.get(CoreAnnotations.TokensAnnotation.class);
  List<CoreLabel> newTokens = process(annotation, tokens);
  // We assume that if someone is using this annotator, they don't
  // want the old tokens any more and get rid of them
  annotation.set(CoreAnnotations.TokensAnnotation.class, newTokens);
 }
}

代码示例来源:origin: eu.fbk.dh/tint-geoloc-annotator

Map<String, GeocodResult> cache = new HashMap<>();
if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
  for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {

代码示例来源:origin: eu.fbk.dh/tint-tense

@Override public void annotate(Annotation annotation) {
  if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
    for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {

代码示例来源:origin: eu.fbk.pikes/pikes-depparse-annotation

@Override
public void annotate(Annotation annotation) {
  if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
    int sentOffset = 0;
    for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
      SemanticGraph dependencies = sentence.get(
          SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
      DepParseInfo info = new DepParseInfo(dependencies);
      List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
      if (dependencies != null) {
        for (int i = 0; i < tokens.size(); i++) {
          CoreLabel token = tokens.get(i);
          int j = i + sentOffset;
          String label = info.getDepLabels().get(j + 1);
          int head = info.getDepParents().get(j + 1) - 1 - sentOffset;
          if (head < -1) {
            head = -1;
          }
          token.set(CoreAnnotations.CoNLLDepTypeAnnotation.class, label);
          token.set(CoreAnnotations.CoNLLDepParentIndexAnnotation.class, head);
        }
      }
      sentOffset += tokens.size();
    }
  } else {
    throw new RuntimeException("unable to find words/tokens in: " + annotation);
  }
}

代码示例来源:origin: edu.stanford.nlp/corenlp

if (annotation.has(CoreAnnotations.TextAnnotation.class)) {
 String text = annotation.get(CoreAnnotations.TextAnnotation.class);
 Reader r = new StringReader(text);  // don't wrap in BufferedReader.  It gives you nothing for in memory String unless you need the readLine() method!

代码示例来源:origin: com.guokr/stan-cn-com

/**
 * Does the actual work of splitting TextAnnotation into CoreLabels,
 * which are then attached to the TokensAnnotation.
 */
@Override
public void annotate(Annotation annotation) {
 Timing timer = null;
 if (VERBOSE) {
  timer = new Timing();
  timer.start();
  System.err.print("Tokenizing ... ");
 }
 if (annotation.has(CoreAnnotations.TextAnnotation.class)) {
  String text = annotation.get(CoreAnnotations.TextAnnotation.class);
  Reader r = new StringReader(text);  // don't wrap in BufferedReader.  It gives you nothing for in memory String unless you need the readLine() method!
  List<CoreLabel> tokens = getTokenizer(r).tokenize();
  // cdm 2010-05-15: This is now unnecessary, as it is done in CoreLabelTokenFactory
  // for (CoreLabel token: tokens) {
  //   token.set(CoreAnnotations.TextAnnotation.class, token.get(CoreAnnotations.TextAnnotation.class));
  // }
  annotation.set(CoreAnnotations.TokensAnnotation.class, tokens);
  if (VERBOSE) {
   timer.stop("done.");
   System.err.println("output: " + annotation.get(CoreAnnotations.TokensAnnotation.class));
   System.err.println();
  }
 } else {
  throw new RuntimeException("unable to find text in annotation: " + annotation);
 }
}

代码示例来源:origin: com.guokr/stan-cn-com

public void annotate(Annotation annotation) {
 if (VERBOSE) {
  System.err.print("Finding lemmas ...");
 }
 Morphology morphology = new Morphology();
 if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
  for (CoreMap sentence :
     annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
   List<CoreLabel> tokens =
    sentence.get(CoreAnnotations.TokensAnnotation.class);
   //System.err.println("Lemmatizing sentence: " + tokens);
   for (CoreLabel token : tokens) {
    String text = token.get(CoreAnnotations.TextAnnotation.class);
    String posTag = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
    addLemma(morphology, CoreAnnotations.LemmaAnnotation.class, token, text, posTag);
   }
  }
 } else {
  throw new RuntimeException("Unable to find words/tokens in: " +
                annotation);
 }
}

代码示例来源:origin: edu.stanford.nlp/corenlp

public void annotate(Annotation annotation) {
 if (VERBOSE) {
  System.err.print("Finding lemmas ...");
 }
 Morphology morphology = new Morphology();
 if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
  for (CoreMap sentence :
     annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
   List<CoreLabel> tokens =
    sentence.get(CoreAnnotations.TokensAnnotation.class);
   //System.err.println("Lemmatizing sentence: " + tokens);
   for (CoreLabel token : tokens) {
    String text = token.get(CoreAnnotations.TextAnnotation.class);
    String posTag = token.get(PartOfSpeechAnnotation.class);
    this.addLemma(morphology, LemmaAnnotation.class, token, text, posTag);
   }
  }
 } else {
  throw new RuntimeException("Unable to find words/tokens in: " +
                annotation);
 }
}

代码示例来源:origin: edu.stanford.nlp/corenlp

System.err.print("PTB tokenizing...");
if (annotation.has(CoreAnnotations.TokensAnnotation.class)) {

代码示例来源:origin: eu.fbk.dh/tint-textpro

@Override
public void annotate(Annotation annotation) {
  if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {

代码示例来源:origin: com.guokr/stan-cn-com

System.err.print("Sentence splitting ...");
if ( ! annotation.has(CoreAnnotations.TokensAnnotation.class)) {
 throw new IllegalArgumentException("WordsToSentencesAnnotator: unable to find words/tokens in: " + annotation);

代码示例来源:origin: com.guokr/stan-cn-com

@Override
public void annotate(Annotation annotation) {
 // turn the annotation into a sentence
 if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
  if (nThreads == 1) {
   for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
    doOneSentence(sentence);
   }
  } else {
   MulticoreWrapper<CoreMap, CoreMap> wrapper = new MulticoreWrapper<CoreMap, CoreMap>(nThreads, new POSTaggerProcessor());
   for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
    wrapper.put(sentence);
    while (wrapper.peek()) {
     wrapper.poll();
    }
   }
   wrapper.join();
   while (wrapper.peek()) {
    wrapper.poll();
   }
  }
 } else {
  throw new RuntimeException("unable to find words/tokens in: " + annotation);
 }
}

相关文章