Pigs are extremely intelligent, on par with dogs at least, and I've seen rankings that place them as high as 4th, behind only apes, dolphins, and elephants.
This doesn't mean that any pig could articulate "I'm going to die". That isn't necessary. Nearly every ungulate (maybe not moose?) has a built-in mortal fear ready to surface at any time. New events, or repeated events with bad associations, bring out that fear. It takes a great deal of training to relax that.