Prolog engine for tree parsing