/** * 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, in -> {}); }
/** * Annotate a collection of input annotations IN PARALLEL, making use of * all available cores. * * @param annotations The input annotations to process */ public void annotate(Iterable<Annotation> annotations) { annotate(annotations, Runtime.getRuntime().availableProcessors()); }
/** * Annotate a collection of input annotations IN PARALLEL, making use of * all available cores. * * @param annotations The input annotations to process * @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, final Consumer<Annotation> callback) { annotate(annotations, Runtime.getRuntime().availableProcessors(), callback); }
/** {@inheritDoc} */ @Override public void annotate(Annotation annotation) { super.annotate(annotation); List<CoreLabel> words = annotation.get(CoreAnnotations.TokensAnnotation.class); if (words != null) { numWords += words.size(); } }
public static Annotation textToAnnotation(AnnotationPipeline pipeline, String text, String date) { Annotation annotation = new Annotation(text); annotation.set(CoreAnnotations.DocDateAnnotation.class, date); pipeline.annotate(annotation); return annotation; }
annotate(ann); callback.accept(ann);
pipeline.annotate(ann);
public static Temporal parseOrNull(String str) { Annotation doc = new Annotation(str); pipeline.annotate(doc); if (doc.get(CoreAnnotations.SentencesAnnotation.class) == null) { return null; } if (doc.get(CoreAnnotations.SentencesAnnotation.class).isEmpty()) { return null; } List<CoreMap> timexAnnotations = doc.get(TimeAnnotations.TimexAnnotations.class); if (timexAnnotations.size() > 1) { return null; } else if (timexAnnotations.isEmpty()) { return null; } CoreMap timex = timexAnnotations.get(0); if (timex.get(TimeExpression.Annotation.class) == null) { return null; } else { return timex.get(TimeExpression.Annotation.class).getTemporal(); } }
/** * TODO(gabor) JavaDoc * * @param sentence * @param pipeline */ public static void annotate(CoreMap sentence, AnnotationPipeline pipeline) { Annotation ann = new Annotation(StringUtils.join(sentence.get(CoreAnnotations.TokensAnnotation.class), " ")); ann.set(CoreAnnotations.TokensAnnotation.class, sentence.get(CoreAnnotations.TokensAnnotation.class)); ann.set(CoreAnnotations.SentencesAnnotation.class, Collections.singletonList(sentence)); pipeline.annotate(ann); }
/** * Parse a string with SUTime. * * @throws SUTimeParsingError if anything goes wrong */ public static Temporal parse(String str) throws SUTimeParsingError { try { Annotation doc = new Annotation(str); pipeline.annotate(doc); assert doc.get(CoreAnnotations.SentencesAnnotation.class) != null; assert ! doc.get(CoreAnnotations.SentencesAnnotation.class).isEmpty(); List<CoreMap> timexAnnotations = doc.get(TimeAnnotations.TimexAnnotations.class); if (timexAnnotations.size() > 1) { throw new RuntimeException("Too many timexes for '" + str + '\''); } CoreMap timex = timexAnnotations.get(0); return timex.get(TimeExpression.Annotation.class).getTemporal(); } catch (Exception e) { SUTimeSimpleParser.SUTimeParsingError parsingError = new SUTimeSimpleParser.SUTimeParsingError(str); parsingError.initCause(e); throw parsingError; } }
PrintWriter extPw, PrintWriter attrPw, PrintWriter debugPw, PrintWriter attrDebugPwGold, PrintWriter attrDebugPw) { pipeline.annotate(docAnnotation); String docId = docAnnotation.get(CoreAnnotations.DocIDAnnotation.class); String docDate = docAnnotation.get(CoreAnnotations.DocDateAnnotation.class);
pipeline.annotate(annotation);
public static void main(String[] args) { String text; if (args.length > 0) { text = IOUtils.slurpFileNoExceptions(args[0], "utf-8"); } else { text = "I can almost always tell when movies use fake dinosaurs."; } Annotation ann = new Annotation(text); Properties props = PropertiesUtils.asProperties( "annotators", "tokenize,ssplit,pos,depparse", "depparse.model", DependencyParser.DEFAULT_MODEL ); AnnotationPipeline pipeline = new StanfordCoreNLP(props); pipeline.annotate(ann); for (CoreMap sent : ann.get(CoreAnnotations.SentencesAnnotation.class)) { SemanticGraph sg = sent.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); log.info(IOUtils.eolChar + sg.toString(SemanticGraph.OutputFormat.LIST)); } }
ap.annotate(a); System.out.println(a.get(CoreAnnotations.TokensAnnotation.class)); for (CoreMap sentence : a.get(CoreAnnotations.SentencesAnnotation.class)) {
/** * 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, in -> {}); }
/** * Annotate a collection of input annotations IN PARALLEL, making use of * all available cores. * * @param annotations The input annotations to process * @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, final Consumer<Annotation> callback) { annotate(annotations, Runtime.getRuntime().availableProcessors(), callback); }
@Override public void annotate(Annotation annotation) { super.annotate(annotation); List<CoreLabel> words = annotation.get(CoreAnnotations.TokensAnnotation.class); if (words != null) { numWords += words.size(); } }
@Override public void annotate(Annotation annotation) { super.annotate(annotation); List<CoreLabel> words = annotation.get(CoreAnnotations.TokensAnnotation.class); if (words != null) { numWords += words.size(); } }
public static Annotation textToAnnotation(AnnotationPipeline pipeline, String text, String date) { Annotation annotation = new Annotation(text); annotation.set(CoreAnnotations.DocDateAnnotation.class, date); pipeline.annotate(annotation); return annotation; }
/** * TODO(gabor) JavaDoc * * @param sentence * @param pipeline */ public static void annotate(CoreMap sentence, AnnotationPipeline pipeline) { Annotation ann = new Annotation(StringUtils.join(sentence.get(CoreAnnotations.TokensAnnotation.class), " ")); ann.set(CoreAnnotations.TokensAnnotation.class, sentence.get(CoreAnnotations.TokensAnnotation.class)); ann.set(CoreAnnotations.SentencesAnnotation.class, Collections.singletonList(sentence)); pipeline.annotate(ann); }