I have written below code using stanford nlp packages.
GenderAnnotator myGenderAnnotation = new GenderAnnotator();
myGenderAnnotation.annotate(annotation);
Though the previous answer @Sebastian Schuster is some what close to the expected, it appears to be not working as for the current versions of Standford NLP
An updated and working example of that code segment is as below.
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(CoreAnnotations.GenderAnnotation.class));
}
}