X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2FForest.java;h=4d8b34f28c63e23c6cd1a098d27737378003227c;hb=2cc11837a52505dd9863bcd366240a8f229af294;hp=1c8fbc5b6f8290bb0c6540a37fd2925900e7b89a;hpb=f1dba2b015c3da04fc2fab45604da2e6c9ae0a1d;p=sbp.git
diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java
index 1c8fbc5..4d8b34f 100644
--- a/src/edu/berkeley/sbp/Forest.java
+++ b/src/edu/berkeley/sbp/Forest.java
@@ -7,8 +7,10 @@ import java.util.*;
import java.lang.reflect.*;
/**
+ *
* An efficient representation of a collection of trees (Tomita's
* shared packed parse forest).
+ *
*/
public abstract class Forest implements GraphViz.ToGraphViz {
@@ -18,19 +20,21 @@ public abstract class Forest implements GraphViz.ToGraphViz {
/** expand this forest into a set of trees */
public void expand(HashSet> ht) { expand(ht, new HashSet>(), null); }
- /** create a new forest */
- public static Forest create(Input.Region loc, T head, Forest[] children, boolean unwrap) {
- return new One(loc, head, children, unwrap);
+ static Forest create(Input.Region loc, T head, Forest[] children, boolean lift) {
+ return new One(loc, head, children, lift);
}
+ /** create a new forest */
+ public static Forest create(Input.Region loc, T head, Forest[] children) {
+ return Forest.create(loc, head, children, false); }
+
// Package-Private //////////////////////////////////////////////////////////////////////////////
abstract void expand(HashSet> ht, HashSet> ignore, Tree bogus);
abstract void gather(HashSet> ignore);
+ abstract void edges(GraphViz.Node n);
boolean ambiguous() { return false; }
- public abstract void edges(GraphViz.Node n);
-
// One //////////////////////////////////////////////////////////////////////////////
@@ -42,21 +46,21 @@ public abstract class Forest implements GraphViz.ToGraphViz {
private final Forest[] children;
/** if true, the last child's children are considered children of this node */
- private final boolean unwrap;
+ private final boolean lift;
- private One(Input.Region loc, T head, Forest[] children, boolean unwrap) {
+ private One(Input.Region loc, T head, Forest[] children, boolean lift) {
this.location = loc;
this.head = head;
this.children = children==null ? emptyForestArray : new Forest[children.length];
if (children != null) System.arraycopy(children, 0, this.children, 0, children.length);
if (children != null) for(int i=0; i expand1() throws Ambiguous {
Tree[] ret = new Tree[children.length];
for(int i=0; i(location, head, ret, unwrap);
+ return new Tree(location, head, ret, lift);
}
void gather(HashSet> hf) {
@@ -69,7 +73,7 @@ public abstract class Forest implements GraphViz.ToGraphViz {
}
private void expand(final int i, Tree[] ta, HashSet> ht, HashSet> ignore, Tree bogus) {
if (i==children.length) {
- ht.add(new Tree(location, head, ta, unwrap));
+ ht.add(new Tree(location, head, ta, lift));
} else {
HashSet> ht2 = new HashSet>();
children[i].expand(ht2, ignore, bogus);
@@ -98,7 +102,7 @@ public abstract class Forest implements GraphViz.ToGraphViz {
if (edges) return;
edges = true;
for(int i=0; i