2017-04-12 5 views
0

this tutorialを使用してStanfordNLPを使用して名前付きエンティティの認識を試みています。私はエラーが発生していますStanfordNLP:互換性のないタイプ:オブジェクトをCoreMapに変換できません

incompatible types: Object cannot be converted to CoreMap 私はタイプキャストObjectにしようとしましたが、それを働かせることができませんでした。

部分コード投げ誤り

// these are all the sentences in this document 
    // a CoreMap is essentially a Map that uses class objects as keys and has values with 
    // custom types 
    List sentences = document.get(SentencesAnnotation.class); 
    StringBuilder sb = new StringBuilder(); 
for (CoreMap sentence : sentences) { 
    // traversing the words in the current sentence, "O" is a sensible default to initialise 
    // tokens to since we're not interested in unclassified/unknown things.. 
    String prevNeToken = "O"; 
    String currNeToken = "O"; 
    boolean newToken = true; 
    for (CoreLabel token : sentence.get(TokensAnnotation.class)) { 
     currNeToken = token.get(NamedEntityTagAnnotation.class); 
     String word = token.get(TextAnnotation.class); 
     // Strip out "O"s completely, makes code below easier to understand 
     if (currNeToken.equals("O")) { 
     // LOG.debug("Skipping '{}' classified as {}", word, currNeToken); 
     if (!prevNeToken.equals("O") && (sb.length() > 0)) { 
      handleEntity(prevNeToken, sb, tokens); 
      newToken = true; 
     } 
     continue; 
     } 

     if (newToken) { 
     prevNeToken = currNeToken; 
     newToken = false; 
     sb.append(word); 
     continue; 
     } 

     if (currNeToken.equals(prevNeToken)) { 
     sb.append(" " + word); 
     } else { 
     // We're done with the current entity - print it out and reset 
     // TODO save this token into an appropriate ADT to return for useful processing.. 
     handleEntity(prevNeToken, sb, tokens); 
     newToken = true; 
     } 
     prevNeToken = currNeToken; 
    } 
    } 

私はNLPとのnoobです。 ありがとうございます。

+0

に三行を変更 あなたはFYI例外 – Ironluca

+0

を投げているコードセグメントを投稿することができ、完全なコードのためのリンクは質問に記載されています。 –

答えて

0

私はこの問題を解決することができました。この

List<CoreMap> sentences = document.get(SentencesAnnotation.class); 
関連する問題