Writing a tree index and pattern matchers for Terms and Literals.