public int [ ] sentPosDetect ( String s ) { double sentProb = 1 ; sentProbs . clear ( ) ; StringBuffer sb = new StringBuffer ( s ) ; List enders = scanner . getPositions ( s ) ; List positions = new ArrayList ( enders . size ( ) ) ; for ( int i = 0 , end = enders . size ( ) , index = 0 ; i < end ; i ++ ) { Integer candidate = ( Integer ) enders . get ( i ) ; int cint = candidate . intValue ( ) ; // skip over the leading parts of non-token final delimiters int fws = getFirstWS ( s , cint + 1 ) ; if ( ( ( i + 1 ) < end ) && ( ( ( Integer ) enders . get ( i + 1 ) ) . intValue ( ) < fws ) ) { continue ; } Pair pair = new Pair ( sb , candidate ) ; double [ ] probs = model . eval ( cgen . getContext ( pair ) ) ; String bestOutcome = model . getBestOutcome ( probs ) ; sentProb *= probs [ model . getIndex ( bestOutcome ) ] ; if ( bestOutcome . equals ( "T" ) && isAcceptableBreak ( s , index , cint ) ) { if ( index != cint ) { positions . add ( INT_POOL . get ( getFirstNonWS ( s , getFirstWS ( s , cint + 1 ) ) ) ) ; sentProbs . add ( new Double ( probs [ model . getIndex ( bestOutcome ) ] ) ) ; } index = cint + 1 ; } } int [ ] sentPositions = new int [ positions . size ( ) ] ; for ( int i = 0 ; i < sentPositions . length ; i ++ ) { sentPositions [ i ] = ( ( Integer ) positions . get ( i ) ) . intValue ( ) ; } return sentPositions ; }
Detect the position of the first words of sentences in a String .