Automatic pattern recognition