public static void main(String[] args) { SemanticGraphFormatter fmt = new SemanticGraphFormatter(); System.out.println("0 1 2 3 4 5 6 7 8"); System.out.println("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); System.out.println(); fmt.test("[like subj>Bill obj>[muffins compound>blueberrry]]"); fmt.test("[eligible nsubj>Zambia cop>became xcomp>[receive mark>to obj>[assistance amod>UNCDF] nmod:in>1991]]"); fmt.test("[say advcl>[are mark>If nsubj>[polls det>the] xcomp>[believed aux>to auxpass>be]] nsubj>[voters amod>American] aux>will advmod>[much dep>[same det>the]] nmod:to>[Republicans nmod:poss>[Bush case>'s compound>George] case>to] dep>[vote advmod>when nsubj>they nmod:in>[elections amod>congressional det>the case>in] nmod:on>[[November num>7th case>on]]]]"); }
private void formatSGNodeOnelineHelper(SemanticGraph sg, IndexedWord node, StringBuilder sb, Set<IndexedWord> usedOneline) { usedOneline.add(node); boolean isntLeaf = (sg.outDegree(node) > 0); if (isntLeaf) { sb.append(LPAREN); } sb.append(formatLabel(node)); for (SemanticGraphEdge depcy : sg.getOutEdgesSorted(node)) { IndexedWord dep = depcy.getDependent(); sb.append(SPACE); if (showRelns) { sb.append(depcy.getRelation()); sb.append(COLON); } if (!usedOneline.contains(dep) && !used.contains(dep)) { // avoid infinite loop formatSGNodeOnelineHelper(sg, dep, sb, usedOneline); } else { sb.append(formatLabel(dep)); } } if (isntLeaf) { sb.append(RPAREN); } }
int spaces) { out.append(LPAREN); out.append(formatLabel(node)); if (smartIndent) { spaces += 1; formatSGNode(sg, dep, sp);
/** * Appends to this.out a one-line or multi-line string representation of the given * semantic graph, using the given number of spaces for indentation. */ private void formatSGNode(SemanticGraph sg, IndexedWord node, int spaces) { used.add(node); String oneline = formatSGNodeOneline(sg, node); boolean toolong = (spaces + oneline.length() > width); boolean breakable = sg.hasChildren(node); if (toolong && breakable) { formatSGNodeMultiline(sg, node, spaces); } else { out.append(oneline); } }
/** * Returns a {@code String} representation of this semantic graph, * formatted by the default semantic graph formatter. */ public String toFormattedString() { return formatter.formatSemanticGraph(this); }
private String formatSGNodeOneline(SemanticGraph sg, IndexedWord node) { StringBuilder sb = new StringBuilder(); Set<IndexedWord> usedOneline = Generics.newHashSet(); formatSGNodeOnelineHelper(sg, node, sb, usedOneline); return sb.toString(); }
/** * Returns a pretty-printed string representation of the given semantic graph, * on one or more lines. */ public String formatSemanticGraph(SemanticGraph sg) { if (sg.vertexSet().isEmpty()) { return "[]"; } out = new StringBuilder(); // not thread-safe!!! used = Generics.newHashSet(); if (sg.getRoots().size() == 1) { formatSGNode(sg, sg.getFirstRoot(), 1); } else { int index = 0; for (IndexedWord root: sg.getRoots()) { index+=1; out.append("root_").append(index).append("> "); formatSGNode(sg, root, 9); out.append("\n"); } } String result = out.toString(); if (!result.startsWith("[")) { result = "[" + result + "]"; } return result; }
/** * Returns a {@code String} representation of this semantic graph, * formatted by the supplied semantic graph formatter. */ public String toFormattedString(SemanticGraphFormatter formatter) { return formatter.formatSemanticGraph(this); }
/** * Appends to this.out a one-line or multi-line string representation of the given * semantic graph, using the given number of spaces for indentation. */ private void formatSGNode(SemanticGraph sg, IndexedWord node, int spaces) { used.add(node); String oneline = formatSGNodeOneline(sg, node); boolean toolong = (spaces + oneline.length() > width); boolean breakable = sg.hasChildren(node); if (toolong && breakable) { formatSGNodeMultiline(sg, node, spaces); } else { out.append(oneline); } }
private String formatSGNodeOneline(SemanticGraph sg, IndexedWord node) { StringBuilder sb = new StringBuilder(); Set<IndexedWord> usedOneline = Generics.newHashSet(); formatSGNodeOnelineHelper(sg, node, sb, usedOneline); return sb.toString(); }
/** * Returns a pretty-printed string representation of the given semantic graph, * on one or more lines. */ public String formatSemanticGraph(SemanticGraph sg) { if (sg.vertexSet().isEmpty()) { return "[]"; } out = new StringBuilder(); // not thread-safe!!! used = Generics.newHashSet(); if (sg.getRoots().size() == 1) { formatSGNode(sg, sg.getFirstRoot(), 1); } else { int index = 0; for (IndexedWord root: sg.getRoots()) { index+=1; out.append("root_").append(index).append(": "); formatSGNode(sg, root, 9); out.append("\n"); } } String result = out.toString(); if (!result.startsWith("[")) { result = "[" + result + "]"; } return result; }
/** * Pretty-prints this semantic graph to {@code System.out}, formatted by * the supplied semantic graph formatter. */ public void prettyPrint(SemanticGraphFormatter formatter) { System.out.println(formatter.formatSemanticGraph(this)); }
public static void main(String[] args) { SemanticGraphFormatter fmt = new SemanticGraphFormatter(); System.out.println("0 1 2 3 4 5 6 7 8"); System.out.println("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); System.out.println(); fmt.test("[like subj:Bill dobj:[muffins nn:blueberrry]]"); fmt.test("[eligible nsubj:Zambia cop:became xcomp:[receive aux:to dobj:[assistance amod:UNCDF] prep_in:1991]]"); fmt.test("[say advcl:[are mark:If nsubj:[polls det:the] xcomp:[believed aux:to auxpass:be]] nsubj:[voters amod:American] aux:will advmod:[much dep:[same det:the]] dep:[to pobj:[Republicans poss:[Bush possessive:'s nn:George]]] dep:[vote advmod:when nsubj:they prep:[in pobj:[elections amod:congressional det:the]] prep:[on pobj:[November num:7th]]]]"); }
/** * Appends to this.out a one-line or multi-line string representation of the given * semantic graph, using the given number of spaces for indentation. */ private void formatSGNode(SemanticGraph sg, IndexedWord node, int spaces) { used.add(node); String oneline = formatSGNodeOneline(sg, node); boolean toolong = (spaces + oneline.length() > width); boolean breakable = sg.hasChildren(node); if (toolong && breakable) { formatSGNodeMultiline(sg, node, spaces); } else { out.append(oneline); } }
private void formatSGNodeOnelineHelper(SemanticGraph sg, IndexedWord node, StringBuilder sb, Set<IndexedWord> usedOneline) { usedOneline.add(node); boolean isntLeaf = (sg.outDegree(node) > 0); if (isntLeaf) { sb.append(LPAREN); } sb.append(formatLabel(node)); for (SemanticGraphEdge depcy : sg.getOutEdgesSorted(node)) { IndexedWord dep = depcy.getDependent(); sb.append(SPACE); if (showRelns) { sb.append(depcy.getRelation()); sb.append(COLON); } if (!usedOneline.contains(dep) && !used.contains(dep)) { // avoid infinite loop formatSGNodeOnelineHelper(sg, dep, sb, usedOneline); } else { sb.append(formatLabel(dep)); } } if (isntLeaf) { sb.append(RPAREN); } }
int spaces) { out.append(LPAREN); out.append(formatLabel(node)); if (smartIndent) { spaces += 1; formatSGNode(sg, dep, sp);
private String formatSGNodeOneline(SemanticGraph sg, IndexedWord node) { StringBuilder sb = new StringBuilder(); Set<IndexedWord> usedOneline = Generics.newHashSet(); formatSGNodeOnelineHelper(sg, node, sb, usedOneline); return sb.toString(); }
/** * Returns a pretty-printed string representation of the given semantic graph, * on one or more lines. */ public String formatSemanticGraph(SemanticGraph sg) { if (sg.vertexSet().isEmpty()) { return "[]"; } out = new StringBuilder(); // not thread-safe!!! used = Generics.newHashSet(); if (sg.getRoots().size() == 1) { formatSGNode(sg, sg.getFirstRoot(), 1); } else { int index = 0; for (IndexedWord root: sg.getRoots()) { index+=1; out.append("root_").append(index).append("> "); formatSGNode(sg, root, 9); out.append("\n"); } } String result = out.toString(); if (!result.startsWith("[")) { result = "[" + result + "]"; } return result; }
/** * Pretty-prints this semantic graph to {@code System.out}, formatted by * the default semantic graph formatter. */ public void prettyPrint() { System.out.println(formatter.formatSemanticGraph(this)); }
public static void main(String[] args) { SemanticGraphFormatter fmt = new SemanticGraphFormatter(); System.out.println("0 1 2 3 4 5 6 7 8"); System.out.println("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); System.out.println(); fmt.test("[like subj>Bill dobj>[muffins compound>blueberrry]]"); fmt.test("[eligible nsubj>Zambia cop>became xcomp>[receive mark>to dobj>[assistance amod>UNCDF] nmod:in>1991]]"); fmt.test("[say advcl>[are mark>If nsubj>[polls det>the] xcomp>[believed aux>to auxpass>be]] nsubj>[voters amod>American] aux>will advmod>[much dep>[same det>the]] nmod:to>[Republicans nmod:poss>[Bush case>'s compound>George] case>to] dep>[vote advmod>when nsubj>they nmod:in>[elections amod>congressional det>the case>in] nmod:on>[[November num>7th case>on]]]]"); }