Skip to content

Instantly share code, notes, and snippets.

@shriphani
Created April 13, 2013 19:31
Show Gist options
  • Save shriphani/5379725 to your computer and use it in GitHub Desktop.
Save shriphani/5379725 to your computer and use it in GitHub Desktop.
import edu.stanford.nlp.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.time.TimeAnnotations;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.NormalizedNamedEntityTagAnnotation;
import edu.stanford.nlp.ling.tokensregex.types.Expressions.VarAssignmentExpression;
import java.util.*;
public class TestSUTime {
public static void main(String ... args) {
Properties p = new Properties();
p.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP s = new StanfordCoreNLP(p);
String text = "Apr 10 10:25pm";
Annotation document = new Annotation(text);
s.annotate(document);
List<CoreLabel> tokens = document.get(CoreAnnotations.TokensAnnotation.class);
for (CoreLabel token : tokens) {
String tag_type = token.get(NamedEntityTagAnnotation.class);
if (tag_type.equals("DATE") || tag_type.equals("TIME")) {
System.out.println(token.get(NormalizedNamedEntityTagAnnotation.class));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment