Fix sparql generation for linked data.

Nested references no longer seem to work, either for referencing return
values or in filters.  So build predicate statements whenever there is
a relationship between types.

Change-Id: Id9015047764d36ed3854bf4a785fb6b5bcba639b
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>