Java源码示例:edu.stanford.nlp.trees.TreeCoreAnnotations

示例1
@Override public void process(JCas jCas) throws AnalysisEngineProcessException {
  DKPro2CoreNlp converter = new DKPro2CoreNlp();
  Annotation annotatios = converter.convert(jCas, new Annotation());
  List<CoreMap> sentences = annotatios.get(CoreAnnotations.SentencesAnnotation.class);

  long startTime = System.currentTimeMillis();
  int factCount = 0;
  int exception = 0;
  for (CoreMap sentence : sentences) {
    try {
      SemanticGraph semanticGraph = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
      Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
      ClausIE clausIE = new ClausIE(semanticGraph, tree, clausieOptions);
      clausIE.detectClauses();
      clausIE.generatePropositions();
      List<Proposition> propositions = new ArrayList<>(clausIE.getPropositions());

      if(removeRedundant) {
        removeRedundant(propositions);
      }

      for (Proposition p : propositions) {
//        System.out.println(p);
//        System.out.println(p.getDictRelation());

          OpenFact of = new OpenFact(jCas);
          Subject subject = addConstituentToJCas(jCas, Subject.class, p, 0);
          of.setBegin(subject.getBegin());
          of.setSubject(subject);
          Relation relation = addConstituentToJCas(jCas, Relation.class, p, 1);
          relation.setNormalizedForm(p.getDictRelation());
          of.setRelation(relation);
          ObjectF object = addConstituentToJCas(jCas, ObjectF.class, p, 2);
          of.setEnd(object.getEnd());
          of.setObject(object);
          of.setText(p.toString());
          of.addToIndexes();
          factCount++;
      }
    } catch (Exception e) {
      exception++;
      logger_.info("Exception at ClausIEAnalysisEngine: "+e.getMessage() + "\n" + e.getStackTrace().toString());
      if(exception > 15) {
        throw new AnalysisEngineProcessException(e);
      }
    }
  }
  double runTime = System.currentTimeMillis() - startTime;
  String docId = JCasUtil.selectSingle(jCas, DocumentMetaData.class).getDocumentId();
  logger_.info( "Document '" + docId + "' done in " + runTime + "ms (" + factCount + " facts).");
}
 
示例2
public static Tree getTree(String sentence) {
    return getOneSentence(sentence).get(TreeCoreAnnotations.TreeAnnotation.class);
}
 
示例3
static void addParseTree(Map<String,Object> sent_info, CoreMap sentence) {
	sent_info.put("parse", sentence.get(TreeCoreAnnotations.TreeAnnotation.class).toString());
}