SentenceAnnotation::SentenceAnnotation(uima::CAS& aCas, size_t begin, size_t end, const TokenAnnotation& firstToken, const TokenAnnotation& lastToken, const ParagraphAnnotation& paragraph)
		{
			FSIndexRepository& indexRep = aCas.getIndexRepository();
			annotation = aCas.createAnnotation(tSentenceAnnotation, begin, end);
			setFirstToken(firstToken);
			setLastToken(lastToken);
			setParagraph(paragraph);
			indexRep.addFS(annotation);
		}
		SentenceAnnotation::SentenceAnnotation(CAS& aCas, size_t begin, size_t end, const TokenAnnotation& firstToken, const TokenAnnotation& lastToken) :
				ContextAreaAnnotation(aCas)
		{
			FSIndexRepository& indexRep = aCas.getIndexRepository();
			annotation = aCas.createAnnotation(tSentenceAnnotation, begin, end);
			setFirstToken(firstToken);
			setLastToken(lastToken);
			indexRep.addFS(annotation);
		}
Пример #3
0
    bool parseForNextToken()
    {
        size_t pos      = getCurrentPosition();
        assert( pos < codestr.size() );

        //
        // Consume whitespace
        //
        for ( ; 
              pos < codestr.size() && isWhitespace(codestr[pos]);
            ++pos )
        {
            // do nothing, just consume space. 
        }

        //
        // End of the line?
        //
        if ( pos == codestr.size() )
        {
            setLastToken( "", TOK_EOF );
            return false;
        }

        size_t startPos = pos;

        //
        // Search for the next token
        //
        TokenType type  = TOK_UNKNOWN;
        bool      done  = false;
        bool      error = false;

        for ( ;
            (!done) && pos < codestr.size() && (!isWhitespace(codestr[pos]))
                    && ((pos == startPos) || !isEndOfToken(codestr[pos]) );
            ++pos )
        {
            char c = codestr[pos];

            switch ( type )
            {
                case TOK_UNKNOWN:
                    if ( c == '(' )
                    {
                        type = TOK_OPEN;
                        done = true;
                    }
                    else if ( c == ')' )
                    {
                        type = TOK_CLOSE;
                        done = true;
                    }
                    else if ( c == ',' )
                    {
                        type = TOK_SEP;
                        done = true;
                    }
                    else if ( isNumeric( c ) )
                    {
                        type = TOK_NUMERIC;
                    }
                    else if ( isIdent( c ) )
                    {
                        type = TOK_IDENT;
                    }
                    else
                    {
                        error = true;
                    }
                    break;
                
                case TOK_NUMERIC:
                    if ( isNumeric( c ) == false )
                    {
                        error = true;
                    }
                    break;

                case TOK_IDENT:
                    if ( isIdent( c ) == false )
                    {
                        error = true;
                    }
                    break;

                default:
                    error = true;
            }

            //
            // Was there an error while parsing the token?
            //
            if ( error )
            {
                    std::cerr << "Error while parsing token. "
                            << "start=" << startPos << ", "
                            << "pos="   << pos      << ", "
                            << "type="  << toString(type) << ", "
                            << "value: "
                            << codestr.substr( startPos, pos - startPos+1 )
                            << std::endl;

                    return false;
            }
        }

        setLastToken( codestr.substr(startPos, pos - startPos), type );
        setCurrentPosition( pos );

        return !isEOF();
    }