Class PhonexPattern

java.lang.Object
ca.phon.phonex.PhonexPattern
All Implemented Interfaces:
Comparable<PhonexPattern>

public class PhonexPattern extends Object implements Comparable<PhonexPattern>

A compiled representation of a phonex expression.

A phonex expression, specified as a string, must first be compiled into this class using the compile(String) method. The resulting PhonexPattern object can then be used to create a PhonexMatcher that can match arbitrary IPA sequences against the phonex expression. A single pattern can be used to create many matchers.

A typcial use case:

 // an expression to find geminates
 final String phonex = "(\c)\S?\1";
 final PhonexPattern pattern = PhonexPattern.compile(phonex);

 final IPATranscript ipa = IPATranscript.parseIPATranscript("ˈlæmp.poʊst");
 final PhonexMatcher matcher = pattern.matcher(ipa);
 boolean b = matcher.find();
 

For more information about phonex expressions, please refer to the phonex manual.

  • Field Details

    • USE_ANTLR4

      public static final String USE_ANTLR4
  • Method Details

    • compileSingleMatcher

      public static PhoneMatcher compileSingleMatcher(String phonex) throws PhonexPatternException
      Compile a phonex expression for a single matcher (including phone classes) and return the provided matcher.
      Parameters:
      phonex -
      Returns:
      Throws:
      PhonexPatternException
    • compile

      public static PhonexPattern compile(String phonex) throws PhonexPatternException
      Throws:
      PhonexPatternException
    • compile

      public static PhonexPattern compile(String phonex, int flags) throws PhonexPatternException
      Compile the given phonex into a pattern
      Parameters:
      phonex - the expression
      flags -
      Throws:
      PhonexPatternException - if the expression's syntax is invalid
    • matcher

      public PhonexMatcher matcher(Iterable<IPAElement> input)
      Create a new phonex matcher which will match the given input against this pattern.
      Parameters:
      input - The list of phones to be matched
    • pattern

      public String pattern()
      Return the phonex for this pattern.
      Returns:
      the phonex compiled into this pattern
    • getFsa

      public PhonexFSA getFsa()
      Access the internal fsa for package-level classes.
      Returns:
      the complied fsa
    • numberOfGroups

      public int numberOfGroups()
      Returns the number of groups in the compiled pattern.
      Returns:
      the number of groups in the pattern
    • groupName

      public String groupName(int gIdx)
      Get the group name for the specified group
      Returns:
      the group name for the specified group or null if the group is not named
      Throws:
      ArrayIndexOutOfBoundsException - if the given group index is out of bounds
    • groupIndex

      public int groupIndex(String groupName)
      Return the group index for the given group name.
      Returns:
      group index or invalid input: '<' 0 if not found
    • compareTo

      public int compareTo(PhonexPattern arg0)
      Compares phonex pattern strings.
      Specified by:
      compareTo in interface Comparable<PhonexPattern>