The standard machine learning approach for doing exactly what you describe is to use a conditional random field. I don't think wikipedia has a great page on it , but check out
http://en.wikipedia.org/wiki/Conditional_random_field for a jumping place.
CRFs are used in places like voice and images where recognition or decoding of a segment logically depends on the pieces near it.