According to this definition, we can recognize sarcasm by evaluating the polarity of the sentences.
a sarcastic sentence contains two or more words, which may cause conflict in sentiment polarities (both positive and negative) in a sentence, whereas a normal sentence should contain at most one polarity.