Class LayerHierarchyTraversal<R>


  • public class LayerHierarchyTraversal<R>
    extends Object
    Traverses Layers a Schema'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) and post(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 Detail

      • defaultComparator

        public static final Comparator<Layer> defaultComparator
        Default comparator for ordering peer layers.

        The default ordering is

        1. non-included layers before included layers (dependency before pos)
        2. less alignment before more alignment (orthography before phone)
        3. fewer peers before more peers (orthography before pos)
        4. childless peers before childful peers (utterance before word)
        5. saturated before sparse (utterance before named entity)
        6. 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 (see defaultComparator), 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 (see defaultComparator), 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 for peerComparator: 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 for peerComparator: 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 for schema: The schema to be traversed.
        Returns:
        The schema to be traversed.
      • setSchema

        public LayerHierarchyTraversal<R> setSchema​(Schema newSchema)
        Setter for schema: The schema to be traversed.
        Parameters:
        newSchema - The schema to be traversed.
      • getResult

        public R getResult()
        Getter for result: The result of the traversal, if required.
        Returns:
        The result of the traversal, if required.
      • setResult

        public LayerHierarchyTraversal<R> setResult​(R newResult)
        Setter for result: 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.
      • traverseSchema

        public R traverseSchema​(Schema schema)
        Traverses the given schema.
        Parameters:
        schema - The schema to traverse.
        Returns:
        Some result of the traversal, if required.