gender identification in natural language processing

后端 未结 4 1618
暖寄归人
暖寄归人 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:19

    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
    

提交回复
热议问题