Anfonwch hwn fel neges destun: Query Rewriting and Optimization for Ontological Databases