Class PatternBuilder

java.lang.Object
nzilbb.labbcat.PatternBuilder

public class PatternBuilder extends Object
Helper class for building layered search patterns for LabbcatView.search(JsonObject,String[],String[],boolean,Integer,Integer,Integer).

e.g.

// words starting with 'ps...'
  JSONObject pattern = new PatternBuilder().addMatchLayer("orthography", "ps.*").build();
 
 // the word 'the' followed immediately or with one intervening word by
 // a hapax legomenon (word with a frequency of 1) that doesn't start with a vowel
 JSONObject pattern2 = new PatternBuilder()
    .addColumn()
    .addMatchLayer("orthography", "the")
    .addColumn()
    .addNotMatchLayer("phonemes", "[cCEFHiIPqQuUV0123456789~#\\$@].*")
    .addMaxLayer("frequency", 2)
    .build();
 
Author:
Robert Fromont robert@fromont.net.nz
  • Constructor Details

    • PatternBuilder

      public PatternBuilder()
      Default constructor.
  • Method Details

    • addColumn

      public PatternBuilder addColumn()
      Adds a column to the search matrix.
      Returns:
      A reference to this builder.
    • addColumn

      public PatternBuilder addColumn(int adj)
      Adds a column to the search matrix.
      Parameters:
      adj - Maximum distance, in tokens, from previous column.
      Returns:
      A reference to this builder.
    • addMatchLayer

      public PatternBuilder addMatchLayer(String layerId, String regularExpression)
      Adds a layer for matching a regular expression.
      Parameters:
      layerId - The ID of the layer.
      regularExpression - The regular expression to match.
      Returns:
      A reference to this object.
    • addNotMatchLayer

      public PatternBuilder addNotMatchLayer(String layerId, String regularExpression)
      Adds a layer for not matching a regular expression.
      Parameters:
      layerId - The ID of the layer.
      regularExpression - The regular expression to match.
      Returns:
      A reference to this object.
    • addMinLayer

      public PatternBuilder addMinLayer(String layerId, double min)
      Adds a layer for matching a minimum value.
      Parameters:
      layerId - The ID of the layer.
      min - The minimum value.
      Returns:
      A reference to this object.
    • addMinLayer

      public PatternBuilder addMinLayer(String layerId, int min)
      Adds a layer for matching a minimum value.
      Parameters:
      layerId - The ID of the layer.
      min - The minimum value.
      Returns:
      A reference to this object.
    • addMaxLayer

      public PatternBuilder addMaxLayer(String layerId, double max)
      Adds a layer for matching a maximum value.
      Parameters:
      layerId - The ID of the layer.
      max - The maximum value.
      Returns:
      A reference to this object.
    • addMaxLayer

      public PatternBuilder addMaxLayer(String layerId, int max)
      Adds a layer for matching a maximum value.
      Parameters:
      layerId - The ID of the layer.
      max - The maximum value.
      Returns:
      A reference to this object.
    • addRangeLayer

      public PatternBuilder addRangeLayer(String layerId, double min, double max)
      Adds a layer for matching a minimum to maximum range.
      Parameters:
      layerId - The ID of the layer.
      min - The minimum value.
      max - The maximum value.
      Returns:
      A reference to this object.
    • addRangeLayer

      public PatternBuilder addRangeLayer(String layerId, int min, int max)
      Adds a layer for matching a minimum to maximum range.
      Parameters:
      layerId - The ID of the layer.
      min - The minimum value.
      max - The maximum value.
      Returns:
      A reference to this object.
    • build

      public javax.json.JsonObject build()
      Returns:
      A valid pattern object.
    • toString

      public String toString()
      A String representation of the JSON pattern object.
      Overrides:
      toString in class Object
      Returns:
      A String representation of the JSON pattern object.