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());
}
}
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("> ");
}
}
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));
}
}
}
Aggregations