public void process ( CAS tcas ) { String text = tcas . getDocumentText ( ) ; Document document = new DocumentImpl ( text ) ; cogroo . analyze ( document ) ; for ( Sentence sentence : document . getSentences ( ) ) { // create sentence annotations AnnotationFS sentenceAnn = tcas . createAnnotation ( mSentenceType , sentence . getStart ( ) , sentence . getEnd ( ) ) ; tcas . getIndexRepository ( ) . addFS ( sentenceAnn ) ; int sentenceOffset = sentence . getStart ( ) ; AnnotationFS [ ] tokenAnnotationArr = new AnnotationFS [ sentence . getTokens ( ) . size ( ) ] ; int i = 0 ; for ( Token token : sentence . getTokens ( ) ) { // create token annotations tokenAnnotationArr [ i ] = tcas . createAnnotation ( mTokenType , sentenceOffset + token . getStart ( ) , sentenceOffset + token . getEnd ( ) ) ; // add POSTag annotations tokenAnnotationArr [ i ] . setStringValue ( this . mPosFeature , token . getPOSTag ( ) ) ; // add lexeme annotations tokenAnnotationArr [ i ] . setStringValue ( this . mLexemeFeature , token . getLexeme ( ) ) ; // add lemma annotations StringArrayFS lemmas = tcas . createStringArrayFS ( token . getLemmas ( ) . length ) ; lemmas . copyFromArray ( token . getLemmas ( ) , 0 , 0 , token . getLemmas ( ) . length ) ; tokenAnnotationArr [ i ] . setFeatureValue ( this . mLemmaFeature , lemmas ) ; tokenAnnotationArr [ i ] . setStringValue ( this . mFeaturesFeature , token . getFeatures ( ) ) ; tcas . getIndexRepository ( ) . addFS ( tokenAnnotationArr [ i ] ) ; i ++ ; } // chunks for ( Chunk chunk : sentence . getChunks ( ) ) { int start = sentence . getTokens ( ) . get ( chunk . getStart ( ) ) . getStart ( ) + sentenceOffset ; int end = sentence . getTokens ( ) . get ( chunk . getEnd ( ) - 1 ) . getEnd ( ) + sentenceOffset ; AnnotationFS chunkAnn = tcas . createAnnotation ( mChunkType , start , end ) ; chunkAnn . setStringValue ( mChunkFeature , chunk . getTag ( ) ) ; if ( chunk . getHeadIndex ( ) >= 0 ) { chunkAnn . setFeatureValue ( mChunkHead , tokenAnnotationArr [ chunk . getHeadIndex ( ) ] ) ; } tcas . getIndexRepository ( ) . addFS ( chunkAnn ) ; } // syntactic chunk for ( SyntacticChunk sc : sentence . getSyntacticChunks ( ) ) { int start = sentence . getTokens ( ) . get ( sc . getStart ( ) ) . getStart ( ) + sentenceOffset ; int end = sentence . getTokens ( ) . get ( sc . getEnd ( ) - 1 ) . getEnd ( ) + sentenceOffset ; AnnotationFS syntChunkAnn = tcas . createAnnotation ( mSyntacticChunkType , start , end ) ; syntChunkAnn . setStringValue ( mSyntacticChunkFeature , sc . getTag ( ) ) ; tcas . getIndexRepository ( ) . addFS ( syntChunkAnn ) ; } } }
Performs chunking on the given tcas object .