Añotador
Temporal Tagger
testAid.java
Go to the documentation of this file.
1 package oeg.tagger.core.time.aidCoreNLP;
2 
3 import edu.stanford.nlp.ling.CoreAnnotations;
4 import edu.stanford.nlp.ling.CoreLabel;
5 import edu.stanford.nlp.pipeline.Annotation;
6 import edu.stanford.nlp.pipeline.StanfordCoreNLP;
7 import edu.stanford.nlp.util.CoreMap;
8 import java.io.PrintWriter;
9 import java.util.List;
10 import java.util.Properties;
13 
20 public class testAid {
21 
22  public static void main(String[] args) {
23 
24  String text = "La sonda Juno de la NASA, la nave impulsada por energía solar que ha viajado más lejos en el espacio, ha llegado este martes tras cinco años de viaje a la órbita de Júpiter, el planeta más grande del Sistema Solar, a la que dará 37 vueltas antes de estrellarse contra su superficie. El expresidente del Gobierno asegura que el secretario general del PSOE debería dimitir si recibe un revés del comité federal.";
25  text = "El 50,2% decidió votar en contra del acuerdo de paz entre el Gobierno y las FARC, por el 49.7% que se decantó por el ‘sí’. La abstención, de más del 60%, y la pésima imagen de la guerrilla han sido determinantes en el resultado de la votación, que ninguna encuesta supo predecir. Evitar que continúe el conflicto armado, que ha atravesado el país durante más de 50 años y ha dejado ocho millones de víctimas, es el primer desafío. El presidente, Juan Manuel Santos, ha asegurado que el cese bilateral del fuego seguirá vigente. Colombia se adentra, no obstante, en un limbo plagado de incertidumbre. Nadie sabe con exactitud qué va a ocurrir a partir de ahora.";
26  String posModel = "../annotador-core/src/main/resources/ixa-pipes/morph-models-1.5.0/es/es-pos-perceptron-autodict01-ancora-2.0.bin";
27  String lemmaModel = "../annotador-core/src/main/resources/ixa-pipes/morph-models-1.5.0/es/es-lemma-perceptron-ancora-2.0.bin";
28  String parseModel = "../annotador-core/src/main/resources/ixa-pipes/morph-models-1.5.0/es/es-parser-chunking.bin";
29 
30  Properties properties = new Properties();
31  properties.setProperty("annotators", "spanish, readability");
32 
33  properties.setProperty("spanish.posModel", posModel);
34  properties.setProperty("spanish.lemmaModel", lemmaModel);
35 // properties.setProperty("spanish.parserModel", parseModel);
36  properties.setProperty("readability.language", "es");
37 
38  properties.setProperty("customAnnotatorClass.spanish", "oeg.tagger.core.time.aidCoreNLP.BasicAnnotator");
39  properties.setProperty("customAnnotatorClass.readability", "eu.fbk.dh.tint.readability.ReadabilityAnnotator");
40 
41  StanfordCoreNLP corenlp = new StanfordCoreNLP(properties);
42  Annotation annotation = new Annotation(text);
43  corenlp.annotate(annotation);
44 
45 // try {
46 // String json = JSONOutputter.jsonPrint(annotation);
47 // System.out.println(json);
48 // } catch (IOException e) {
49 // e.printStackTrace();
50 // }
51  PrintWriter out = new PrintWriter(System.out);
52  List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
53 
54 // Tree tree = annotation.get(CoreAnnotations.SentencesAnnotation.class).get(0).get(TreeCoreAnnotations.TreeAnnotation.class);
55 // System.out.println("--------\n" + tree + "\n--------\n");
56  for (CoreMap sentence : sentences) {
57  // NOTE: Depending on what tokensregex rules are specified, there are other annotations
58  // that are of interest other than just the tokens and what we print out here
59  for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
60  // Print out words, lemma, ne, and normalized ne
61  String word = token.get(CoreAnnotations.TextAnnotation.class);
62  String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);
63  String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
64  String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
65  String myNe = token.get(myNER.MyNamedEntityTagAnnotation.class);
66  String normalized = token.get(CoreAnnotations.NormalizedNamedEntityTagAnnotation.class);
67  String myNeNormalized = token.get(myNER.MyNormalizedNamedEntityTagAnnotation.class);
68 
69 // String tnormalized = token.get(temporal.MyNormalizedTemporalAnnotation.class);
70 // String myTeNormalized = token.get(temporal.MyTemporalAnnotation.class);
71 // Double myTeValue = token.get(temporal.MyValueAnnotation.class);
72 // String myTeType = token.get(temporal.MyTypeTemporalAnnotation.class);
73  String value = token.get(timex.Value.class);
74  String type = token.get(timex.Type.class);
75 // out.println("token: " + "word="+word + ", myNe=" + myNe + ", myNenormalized=" + myNeNormalized + "\t\t" + token.value());
76 // out.println("token: " + "TIMEX=(" + type + ", " + value + ") \t word=" + word + ", ne=" + ne + ", normalized=" + normalized + ", myNe=" + myNe + ", myNenormalized=" + myNeNormalized + "\t myT=" + tnormalized + "\t myTnormalized=" + myTeNormalized + "\t myTValue=" + myTeValue + "\t myTType=" + myTeType);
77  out.println("token: " + "word=" + word + ", lemma=" + lemma + ", pos=" + pos + ", ne=" + ne + ", normalized=" + normalized + ", myNe=" + myNe + ", myNenormalized=" + myNeNormalized);
78  }
79  }
80  out.flush();
81  }
82 
83 }
oeg.tagger.core.time
oeg.tagger.core.time.annotation.timex.Type
Definition: timex.java:35
oeg.tagger.core.time.aidCoreNLP.testAid
Definition: testAid.java:20
oeg.tagger.core
oeg
oeg.tagger.core.time.annotation
Definition: date.java:1
oeg.tagger.core.time.annotation.timex.Value
Definition: timex.java:27
oeg.tagger.core.time.annotation.myNER.MyNormalizedNamedEntityTagAnnotation
Definition: myNER.java:24
oeg.tagger
oeg.tagger.core.time.annotation.myNER.MyNamedEntityTagAnnotation
Definition: myNER.java:16
oeg.tagger.core.time.annotation.timex
Definition: timex.java:14
oeg.tagger.core.time.annotation.myNER
Definition: myNER.java:11
oeg.tagger.core.time.aidCoreNLP.testAid.main
static void main(String[] args)
Definition: testAid.java:22