Search in sources :

Example 6 with Annotator

use of edu.stanford.nlp.pipeline.Annotator in project CoreNLP by stanfordnlp.

the class Sentence method kbpTriples.

/**
   * Get the KBP triples associated with this sentence.
   * Note that this function may be slower than you would expect, as it has to
   * convert the underlying Protobuf representation back into {@link CoreLabel}s.
   *
   * @param props The properties to use for the KBP annotator.
   * @return A collection of {@link RelationTriple} objects representing the KBP triples in the sentence.
   */
public Collection<RelationTriple> kbpTriples(Properties props) {
    document.runKBP(props);
    synchronized (impl) {
        List<CoreLabel> tokens = asCoreLabels();
        Annotation doc = document.asAnnotation();
        return impl.getKbpTripleList().stream().map(x -> ProtobufAnnotationSerializer.fromProto(x, doc, this.sentenceIndex())).collect(Collectors.toList());
    }
}
Also used : java.util(java.util) CorefChain(edu.stanford.nlp.coref.data.CorefChain) ProtobufAnnotationSerializer(edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer) edu.stanford.nlp.util(edu.stanford.nlp.util) BiFunction(java.util.function.BiFunction) CoreNLPProtos(edu.stanford.nlp.pipeline.CoreNLPProtos) Tree(edu.stanford.nlp.trees.Tree) SemgrexMatcher(edu.stanford.nlp.semgraph.semgrex.SemgrexMatcher) Function(java.util.function.Function) SemanticGraphCoreAnnotations(edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations) RelationTriple(edu.stanford.nlp.ie.util.RelationTriple) SemanticGraph(edu.stanford.nlp.semgraph.SemanticGraph) SemgrexPattern(edu.stanford.nlp.semgraph.semgrex.SemgrexPattern) TokenSequencePattern(edu.stanford.nlp.ling.tokensregex.TokenSequencePattern) OutputStream(java.io.OutputStream) CoreLabel(edu.stanford.nlp.ling.CoreLabel) CoreAnnotations(edu.stanford.nlp.ling.CoreAnnotations) Polarity(edu.stanford.nlp.naturalli.Polarity) OperatorSpec(edu.stanford.nlp.naturalli.OperatorSpec) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Annotator(edu.stanford.nlp.pipeline.Annotator) SemanticGraphFactory(edu.stanford.nlp.semgraph.SemanticGraphFactory) Stream(java.util.stream.Stream) Annotation(edu.stanford.nlp.pipeline.Annotation) TokenSequenceMatcher(edu.stanford.nlp.ling.tokensregex.TokenSequenceMatcher) SentenceFragment(edu.stanford.nlp.naturalli.SentenceFragment) InputStream(java.io.InputStream) CoreLabel(edu.stanford.nlp.ling.CoreLabel) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 7 with Annotator

use of edu.stanford.nlp.pipeline.Annotator in project CoreNLP by stanfordnlp.

the class SUTimePipeline method main.

public static void main(String[] args) throws IOException {
    SUTimePipeline pipeline = new SUTimePipeline();
    Annotator timeAnnotator = pipeline.getTimeAnnotator("sutime", new Properties());
    BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("> ");
    for (String line; (line = is.readLine()) != null; ) {
        Annotation ann = pipeline.process(line, null, timeAnnotator);
        System.out.println(ann.get(TimeAnnotations.TimexAnnotations.class));
        System.out.print("> ");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) TimeAnnotator(edu.stanford.nlp.time.TimeAnnotator) Annotator(edu.stanford.nlp.pipeline.Annotator) GUTimeAnnotator(edu.stanford.nlp.time.GUTimeAnnotator) HeidelTimeAnnotator(edu.stanford.nlp.time.HeidelTimeAnnotator) BufferedReader(java.io.BufferedReader) Properties(java.util.Properties) Annotation(edu.stanford.nlp.pipeline.Annotation)

Example 8 with Annotator

use of edu.stanford.nlp.pipeline.Annotator in project CoreNLP by stanfordnlp.

the class SUTimeServlet method addResults.

private void addResults(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // if we can't handle UTF-8, need to do something like this...
    //String originalQuery = request.getParameter("q");
    //String query = WebappUtil.convertString(originalQuery);
    String query = request.getParameter("q");
    String dateString = request.getParameter("d");
    // TODO: this always returns true...
    boolean dateError = !pipeline.isDateOkay(dateString);
    boolean includeOffsets = parseBoolean(request.getParameter("includeOffsets"));
    PrintWriter out = response.getWriter();
    if (dateError) {
        out.println("<br><br>Warning: unparseable date " + StringEscapeUtils.escapeHtml4(dateString));
    }
    if (!StringUtils.isNullOrEmpty(query)) {
        Properties props = getTimeAnnotatorProperties(request);
        String annotatorType = request.getParameter("annotator");
        if (annotatorType == null) {
            annotatorType = "sutime";
        }
        Annotator timeAnnotator = pipeline.getTimeAnnotator(annotatorType, props);
        if (timeAnnotator != null) {
            Annotation anno = pipeline.process(query, dateString, timeAnnotator);
            out.println("<h3>Annotated Text</h3> <em>(tagged using " + annotatorType + "</em>)");
            displayAnnotation(out, query, anno, includeOffsets);
        } else {
            out.println("<br><br>Error creating annotator for " + StringEscapeUtils.escapeHtml4(annotatorType));
        }
    }
}
Also used : Annotator(edu.stanford.nlp.pipeline.Annotator) Properties(java.util.Properties) Annotation(edu.stanford.nlp.pipeline.Annotation) PrintWriter(java.io.PrintWriter)

Aggregations

Annotator (edu.stanford.nlp.pipeline.Annotator)8 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)5 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)4 Annotation (edu.stanford.nlp.pipeline.Annotation)4 CorefChain (edu.stanford.nlp.coref.data.CorefChain)3 Tree (edu.stanford.nlp.trees.Tree)3 RelationTriple (edu.stanford.nlp.ie.util.RelationTriple)2 CoreLabel (edu.stanford.nlp.ling.CoreLabel)2 TokenSequenceMatcher (edu.stanford.nlp.ling.tokensregex.TokenSequenceMatcher)2 TokenSequencePattern (edu.stanford.nlp.ling.tokensregex.TokenSequencePattern)2 OperatorSpec (edu.stanford.nlp.naturalli.OperatorSpec)2 Polarity (edu.stanford.nlp.naturalli.Polarity)2 SentenceFragment (edu.stanford.nlp.naturalli.SentenceFragment)2 CoreNLPProtos (edu.stanford.nlp.pipeline.CoreNLPProtos)2 ProtobufAnnotationSerializer (edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer)2 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)2 SemanticGraphFactory (edu.stanford.nlp.semgraph.SemanticGraphFactory)2 SemgrexMatcher (edu.stanford.nlp.semgraph.semgrex.SemgrexMatcher)2 SemgrexPattern (edu.stanford.nlp.semgraph.semgrex.SemgrexPattern)2 TreeCoreAnnotations (edu.stanford.nlp.trees.TreeCoreAnnotations)2