2017-05-02 1 views
1

는 나는 그런스탠포드 NLP : 구두점 토큰을 보관 하시겠습니까?

같은 문장 유아 교육에

대학교, 심리학

  • 내가 스탠포드 파서를 사용하여 텍스트에 주석을 찾고 있어요.
  • 그런 다음 각 문장을 반복하고 NER (명명 된 엔티티 인식)를 사용하여 "학사 학위"를 식별합니다.
  • 트리플을 처리함으로써 개체가 "BE IN"을 따르고 대학 전공이 될 가능성이 있음을 알 수 있습니다.
  • 그래서 추가 분석을 위해 객체 문구를 보냅니다. 내 문제는

    이 절차에 대한 나의 코드를 통해 루프

유아 교육

심리학

에서 내가 분리하는 방법을 모르는 것입니다 어떤 POS 요구 사항이 충족되면 오브젝트가 3 중으로 유지됩니다.

private void processTripleObject(List<CoreLabel> objectPhrase) 
{ 
    try 
    { 
     StringBuilder sb = new StringBuilder(); 
     for(CoreLabel token: objectPhrase) 
     { 
      String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); 

      TALog.getLogger().debug("pos: "+pos+" word "+token.word()); 
      if(!matchDegreeNameByPos(pos)) 
      { 
       return; 
      } 

      sb.append(token.word()); 
      sb.append(SPACE); 
     } 

     IdentifiedToken itoken = new IdentifiedToken(IdentifiedToken.SKILL, sb.toString()); 

    } 
    catch(Exception e) 
    { 
     TALog.getLogger().error(e.getMessage(),e); 
    } 

가르침과 심리학 사이의 쉼표가 토큰에 없기 때문에 나는 구분을 인식하는 방법을 모른다.

누구든지 조언 할 수 있습니까?

답변

2

token.get(CoreAnnotations.PartOfSpeechAnnotation.class)은 POS 태그가없는 경우 토큰을 반환합니다. CoreNLP 3.7.0 및 "tokenize ssplit pos" 주석 자로 테스트되었습니다. 그런 다음 관심있는 구두점이있는 문자열에 pos이 있는지 확인할 수 있습니다. 예 : 방금 테스트 한 일부 코드 :

String punctuations = ".,;!?"; 
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) { 
    for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) { 
     // pos could be "NN" but could also be "," 
     String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); 
     if (punctuations.contains(pos)) { 
      // do something with it 
     } 
    } 
} 
관련 문제