My first thought is that it might be possible, and if it were my problem I would take the time to try to develop it into working code. However the only thing this reminds me of is how parsers have changed over the years from being a batch process and parsing an entire file to real time parsing of lines within an IDE to give back more specific errors.
This also reminds me of BDD (Binary decision diagram), I am thinking that the Reduced Ordered Binary Decision Diagram could be used to short cut the process, but don’t ask me how, it is just a WAG.
On a side note. I am actually working through the entire creation of the image based on your question and realized that gvterm wants to use xdot. I am guessing that you installed GraphViz, set up the path to xdot and then the process worked to display the graph? If so, then you should note that in your response.
Since your question is of value to others learning Prolog at a beginner or intermediate level I am creating a Nice to Know topic to give an example of this based on your question.