some query refactoring for SMW sparql endpoint