I have written below code using stanford nlp packages.
GenderAnnotator myGenderAnnotation = new GenderAnnotator();
myGenderAnnotation.annotate(annotation);
The gender annotator doesn't add the information to the text output but you can still access it through code as shown in the following snippet:
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,parse,gender");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Annotation document = new Annotation("Annie goes to school");
pipeline.annotate(document);
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
System.out.print(token.value());
System.out.print(", Gender: ");
System.out.println(token.get(MachineReadingAnnotations.GenderAnnotation.class));
}
}
Output:
Annie, Gender: FEMALE
goes, Gender: null
to, Gender: null
school, Gender: null