gender identification in natural language processing

后端 未结 4 1619
暖寄归人
暖寄归人 2021-02-11 03:04

I have written below code using stanford nlp packages.

GenderAnnotator myGenderAnnotation = new GenderAnnotator();
myGenderAnnotation.annotate(annotation);
         


        
4条回答
  •  感动是毒
    2021-02-11 03:14

    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));
      }
    }
    

提交回复
热议问题