Restructuring the query construction

- Don't generate/use ontological term queries if the relevant fragments
  are going to be unused.
Ensure input graph iris are escaped.
Match output to the current format

- It's very raw looking but will do for now.