private ParseTree[] parseTreesFromLastCalculation;
@Override
public GraphViz generatePDFcode(String pdfPath) {
GraphViz gv = new GraphViz(pdfPath);
this.numOfParseTrees = -1;
GlobalVariables.getPrematureParameters().logDebug("I'm starting with the grammar tree creation.");
if (this.wordToParse == null) {
try {
GrammTree tree = this.generateWords(this.cutNonTerminalBranches, this.cutTerminalDoubleBranches, false);
GlobalVariables.getPrematureParameters().logDebug("Nodes in tree: " + tree.getSize());
GlobalVariables.getPrematureParameters().logDebug("Terminal nodes in tree: " + tree.getTermNum());
nodeNum = 0;
gv.addln("digraph G {");
traverseTree(gv, tree);
gv.addln("};");
} catch (Exception e) {}
} else { // Parser type 2.
gv.addln("digraph G {");
if (this.getRules().stream().allMatch(r -> r.getRightSide().getWordLength() > 0)) {
CtxtFreeGrammar gramm = new CtxtFreeGrammar(this);
try {
if (this.parseTreesFromLastCalculation == null || this.dontRecalculateParseTrees == null) {
this.parseTreesFromLastCalculation = ChartParser.parse(gramm, this.wordToParse, null);
}
gv.addln(parseTreesFromLastCalculation[this.displayParseTreeNum % parseTreesFromLastCalculation.length].toString());
this.numOfParseTrees = parseTreesFromLastCalculation.length;
} catch (Exception e) {
if (e.getMessage().toLowerCase().contains("user")) {
gv.addln("b [label=\"User aborted\"];");
gv.addln("b -> a;");
}
gv.addln("a [label=\"CANNOT PARSE\"];\n c [label=\""
+ Arrays.toString(this.wordToParse)
.replace("[", "").replace("]", "")
.replace(", ", "")
+ "\"];");
gv.addln("a -> c;");
}
} else {
gv.addln("SORRY EPSILON NOT ALLOWED \"USE <>\";");
}
gv.addln("};");
}
return gv;
}