That's a nontrivial problem to solve. Consider "I avoided becoming hungover again!". In other words, you'd have to do a full semantic analysis and get the scope of negations right. I hear that current sentiment analysis techniques use a heuristic by looking for a nearby negation.