/* Stelle einen Term als Baum dar, mit dem Programm /bin/dot. Siehe das Handbuch dazu unter Unix: man dot ... Man bekommt dot von AT&T als Teil des Graphikpakets graphviz unter http://www.research.att.com/sw/tools/graphviz/download.html */ /* Schreibe den Prolog-Term als Baum auf die Datei .tmp.dot : */ dot(Term,Datei) :- ground(Term), !, concat(Datei,'.tmp.dot',File), tell(File), write('digraph syntaxbaum {'), write('\n center=true;\n size=\"7.5,14\";\n ratio=compress;\n'), drawTree(Term,0,_), write('}'), told. dot(Term,File) :- write(user,'Your term contains free variables! Error'), nl. /* -------- Loesung von Aufgabe 12 einfuegen (ggf. mit consult) ! ------- drawTree(+Term,+Wurzelnummer,-naechste nicht verbrauchte Knotennummer) */ /* Anzeigen: */ displayTree(Term) :- (ground(Term) -> showTree(Term,testbaum) ; write(user,'Your term contains free variables! Error\n') ). showTree(Term,Datei) :- dot(Term,Datei), viewgraph(Datei). viewgraph(Datei) :- concatAtoms(['dot -Tps ',Datei,'.tmp.dot ',' -o',Datei,'.tmp.ps '],Command1), concatAtoms(['ghostview -magstep -2 ',Datei,'.tmp.ps &\n'],Command2), shell(Command1), shell(Command2). concatAtoms([At],At) :- !, atom(At). concatAtoms([A1,A2],Atom) :- !, concat(A1,A2,Atom). concatAtoms([At1,At2|Ats],Atom) :- concatAtoms([At2|Ats],Atom2), concat(At1,Atom2,Atom). /* Beispiel: displayTree(s(np(det('Der'),a(junge),n('Hund')), vp(v(jagt), adv(manchmal), np(np(det(die),a(schnelle),n('Katze')), conj(und), np(det(den),a(flinken),n('Hasen')))))). */