A general framework for learning rules from data