internal virtual GrammarArc optimizeArc(GrammarArc grammarArc) { GrammarNode grammarNode = grammarArc.getGrammarNode(); while (grammarNode.isEmpty() && grammarNode.arcList.size() == 1) { GrammarArc grammarArc2 = (GrammarArc)grammarNode.arcList.get(0); grammarArc = new GrammarArc(grammarArc2.getGrammarNode(), grammarArc.getProbability() + grammarArc2.getProbability()); grammarNode = grammarArc.getGrammarNode(); } return(grammarArc); }
private string traverse(int num, Set set, float num2) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { stringBuilder.append(" "); } stringBuilder.append("N(").append(this.getID()).append("):"); stringBuilder.append("p:").append(num2); if (this.isFinalNode()) { stringBuilder.append(" !"); } Word[][] array = this.getAlternatives(); for (int j = 0; j < array.Length; j++) { for (int k = 0; k < array[j].Length; k++) { stringBuilder.append(' ').append(array[j][k].getSpelling()); } if (j < array.Length - 1) { stringBuilder.append('|'); } } [email protected](stringBuilder); if (!this.isFinalNode() && !set.contains(this)) { set.add(this); GrammarArc[] successors = this.getSuccessors(); GrammarArc[] array2 = successors; int num3 = array2.Length; for (int l = 0; l < num3; l++) { GrammarArc grammarArc = array2[l]; GrammarNode grammarNode = grammarArc.getGrammarNode(); grammarNode.traverse(num + 1, set, grammarArc.getProbability()); } } else if (this.isFinalNode()) { set.add(this); } return(stringBuilder.toString()); }
private void traverseDot(PrintWriter printWriter, Set set) { if (!set.contains(this)) { set.add(this); printWriter.println(new StringBuilder().append("\tnode").append(this.getID()).append(" [ label=").append(this.getGDLLabel(this)).append(", color=").append(this.getGDLColor(this)).append(", shape=").append(this.getGDLShape(this)).append(" ]\n").toString()); GrammarArc[] successors = this.getSuccessors(); GrammarArc[] array = successors; int num = array.Length; for (int i = 0; i < num; i++) { GrammarArc grammarArc = array[i]; GrammarNode grammarNode = grammarArc.getGrammarNode(); float probability = grammarArc.getProbability(); printWriter.write(new StringBuilder().append("\tnode").append(this.getID()).append(" -> node").append(grammarNode.getID()).append(" [ label=").append(probability).append(" ]\n").toString()); grammarNode.traverseDot(printWriter, set); } } }
private void traverseGDL(PrintWriter printWriter, Set set) { if (!set.contains(this)) { set.add(this); printWriter.println(new StringBuilder().append(" node: { title: ").append(this.getGDLID(this)).append(" label: ").append(this.getGDLLabel(this)).append(" shape: ").append(this.getGDLShape(this)).append(" color: ").append(this.getGDLColor(this)).append('}').toString()); GrammarArc[] successors = this.getSuccessors(); GrammarArc[] array = successors; int num = array.Length; for (int i = 0; i < num; i++) { GrammarArc grammarArc = array[i]; GrammarNode grammarNode = grammarArc.getGrammarNode(); float probability = grammarArc.getProbability(); printWriter.println(new StringBuilder().append(" edge: { source: ").append(this.getGDLID(this)).append(" target: ").append(this.getGDLID(grammarNode)).append(" label: \"").append(probability).append("\"}").toString()); grammarNode.traverseGDL(printWriter, set); } } }
internal virtual void optimize() { for (int i = 0; i < this.arcList.size(); i++) { GrammarArc grammarArc = (GrammarArc)this.arcList.get(i); this.arcList.set(i, this.optimizeArc(grammarArc)); } if (this.isEmpty()) { ListIterator listIterator = this.arcList.listIterator(); while (listIterator.hasNext()) { GrammarArc grammarArc = (GrammarArc)listIterator.next(); if (this == grammarArc.getGrammarNode()) { listIterator.remove(); } } } }