Text this: Semantic optimisation in datalog programs