Learning definable hypotheses on trees