Multi-term named entities in Stanford Named Entity Recognizer

前端 未结 8 1462
春和景丽
春和景丽 2021-01-31 19:33

I\'m using the Stanford Named Entity Recognizer http://nlp.stanford.edu/software/CRF-NER.shtml and it\'s working fine. This is

    List&         


        
8条回答
  •  耶瑟儿~
    2021-01-31 20:21

    List> out = classifier.classify(text);
    for (List sentence : out) {
        String s = "";
        String prevLabel = null;
        for (CoreLabel word : sentence) {
          if(prevLabel == null  || prevLabel.equals(word.get(CoreAnnotations.AnswerAnnotation.class)) ) {
             s = s + " " + word;
             prevLabel = word.get(CoreAnnotations.AnswerAnnotation.class);
          }
          else {
            if(!prevLabel.equals("O"))
               System.out.println(s.trim() + '/' + prevLabel + ' ');
            s = " " + word;
            prevLabel = word.get(CoreAnnotations.AnswerAnnotation.class);
          }
        }
        if(!prevLabel.equals("O"))
            System.out.println(s + '/' + prevLabel + ' ');
    }
    

    I just wrote a small logic and it's working fine. what I did is group words with same label if they are adjacent.

提交回复
热议问题