Package nzilbb.ag.util
Class LayerHierarchyTraversal<R>
- java.lang.Object
-
- nzilbb.ag.util.LayerHierarchyTraversal<R>
-
public class LayerHierarchyTraversal<R> extends Object
TraversesLayer
s aSchema
's Layer hierarchy.This base class handles the traversal. The pre-order and post-order operations (the actual work being done) can be implemented by subclassing to implement
pre(Layer)
andpost(Layer)
.For example, to print a list of layers in hierarchy order:
LayerHierarchyTraversal<StringBuffer> t = new LayerHierarchyTraversal<StringBuffer>(new StringBuffer(), schema) { protected void pre(Layer layer) { result.append(layer.getId() + "\n"); } }; System.out.println(t.getResult().toString());
- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<Layer>
defaultComparator
Default comparator for ordering peer layers.
-
Constructor Summary
Constructors Constructor Description LayerHierarchyTraversal()
Default constructor.LayerHierarchyTraversal(R result)
Constructor with starting result.LayerHierarchyTraversal(R result, Collection<Layer> layers)
Constructor with starting result and a collection of layers to immediately traverse.LayerHierarchyTraversal(R result, Comparator<Layer> comparator, Collection<Layer> layers)
Constructor with starting result and a collection of layers to immediately traverse.LayerHierarchyTraversal(R result, Comparator<Layer> comparator, Schema schema)
Constructor with starting result and schema to immediately traverse.LayerHierarchyTraversal(R result, Schema schema)
Constructor with starting result and schema to immediately traverse.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Comparator<Layer>
getPeerComparator()
Getter forpeerComparator
: Comparator for ordering peer layers.R
getResult()
Getter forresult
: The result of the traversal, if required.Schema
getSchema()
Getter forschema
: The schema to be traversed.LayerHierarchyTraversal<R>
setPeerComparator(Comparator<Layer> newPeerComparator)
Setter forpeerComparator
: Comparator for ordering peer layers.LayerHierarchyTraversal<R>
setResult(R newResult)
Setter forresult
: The result of the traversal, if required.LayerHierarchyTraversal<R>
setSchema(Schema newSchema)
Setter forschema
: The schema to be traversed.R
traverseLayers(Collection<Layer> layers)
Traverses the given collection of layers.R
traverseSchema(Schema schema)
Traverses the given schema.
-
-
-
Field Detail
-
defaultComparator
public static final Comparator<Layer> defaultComparator
Default comparator for ordering peer layers.The default ordering is
- non-included layers before included layers (dependency before pos)
- less alignment before more alignment (orthography before phone)
- fewer peers before more peers (orthography before pos)
- childless peers before childful peers (utterance before word)
- saturated before sparse (utterance before named entity)
- overlapping peers before sequential peers (parse tree before named entity)
- See Also:
peerComparator
-
-
Constructor Detail
-
LayerHierarchyTraversal
public LayerHierarchyTraversal()
Default constructor.
-
LayerHierarchyTraversal
public LayerHierarchyTraversal(R result)
Constructor with starting result.- Parameters:
result
- The result of the traversal.
-
LayerHierarchyTraversal
public LayerHierarchyTraversal(R result, Schema schema)
Constructor with starting result and schema to immediately traverse.- Parameters:
result
- The result of the traversal.schema
- The schema to be traversed.
-
LayerHierarchyTraversal
public LayerHierarchyTraversal(R result, Comparator<Layer> comparator, Schema schema)
Constructor with starting result and schema to immediately traverse. The comparator supplied determines the ordering among peer layers. e.g. to achieve the reverse of the default ordering (seedefaultComparator
), set comparator to:new Comparator<Layer>() { public int compare(Layer l1, Layer l2) { return -LayerHierarchyTraversal.defaultComparator.compare(l1,l2); } }
- Parameters:
result
- The result of the traversal.comparator
- Peer layer comparator.schema
- The schema to be traversed.
-
LayerHierarchyTraversal
public LayerHierarchyTraversal(R result, Collection<Layer> layers)
Constructor with starting result and a collection of layers to immediately traverse.- Parameters:
result
- The result of the traversal.layers
- A collection of layers to traverse.
-
LayerHierarchyTraversal
public LayerHierarchyTraversal(R result, Comparator<Layer> comparator, Collection<Layer> layers)
Constructor with starting result and a collection of layers to immediately traverse. The comparator supplied determines the ordering among peer layers. e.g. to achieve the reverse of the default ordering (seedefaultComparator
), set comparator to:new Comparator<Layer>() { public int compare(Layer l1, Layer l2) { return -LayerHierarchyTraversal.defaultComparator.compare(l1,l2); } }
- Parameters:
result
- The result of the traversal.comparator
- Peer layer comparator.layers
- A collection of layers to traverse.
-
-
Method Detail
-
getPeerComparator
public Comparator<Layer> getPeerComparator()
Getter forpeerComparator
: Comparator for ordering peer layers.- Returns:
- Comparator for ordering peer layers, or null for order the children are encountered in.
-
setPeerComparator
public LayerHierarchyTraversal<R> setPeerComparator(Comparator<Layer> newPeerComparator)
Setter forpeerComparator
: Comparator for ordering peer layers.- Parameters:
newPeerComparator
- Comparator for ordering peer layers, or null for order the children are encountered in.
-
getSchema
public Schema getSchema()
Getter forschema
: The schema to be traversed.- Returns:
- The schema to be traversed.
-
setSchema
public LayerHierarchyTraversal<R> setSchema(Schema newSchema)
Setter forschema
: The schema to be traversed.- Parameters:
newSchema
- The schema to be traversed.
-
getResult
public R getResult()
Getter forresult
: The result of the traversal, if required.- Returns:
- The result of the traversal, if required.
-
setResult
public LayerHierarchyTraversal<R> setResult(R newResult)
Setter forresult
: The result of the traversal, if required.- Parameters:
newResult
- The result of the traversal, if required.
-
traverseLayers
public R traverseLayers(Collection<Layer> layers)
Traverses the given collection of layers.- Parameters:
layers
- The layers to traverse.- Returns:
- Some result of the traversal, if required.
-
-