Package ca.phon.ipa

Class IPATranscript

java.lang.Object
ca.phon.ipa.IPATranscript
All Implemented Interfaces:
IExtendable, Visitable<IPAElement>, Comparable<IPATranscript>, Iterable<IPAElement>

public final class IPATranscript extends Object implements Iterable<IPAElement>, Visitable<IPAElement>, IExtendable, Comparable<IPATranscript>

A (somewhat) immutable representation of an IPA transcription. While the number of elements in the transcription cannot be changed, runtime extensions provided by the IExtendable interface may be swapped.

Objects of this type should be created using either the parseIPATranscript(String) static method or IPATranscriptBuilder.

  • Field Details

    • USE_ANTLR4

      public static final String USE_ANTLR4
  • Constructor Details

    • IPATranscript

      public IPATranscript()
      Create an empty transcript
    • IPATranscript

      public IPATranscript(List<IPAElement> phones)
      Create a new transcript for a list of phones.
    • IPATranscript

      public IPATranscript(IPATranscript ipa)
      Createa new transcript with the phones from the given transcript.
      Parameters:
      ipa -
    • IPATranscript

      public IPATranscript(IPAElement... phones)
      Create a new transcript from an array of phones.
    • IPATranscript

      public IPATranscript(Object... elements)
  • Method Details

    • parseIPATranscript

      public static IPATranscript parseIPATranscript(String transcript) throws ParseException
      Convert a string into an IPATranscript
      Parameters:
      transcript - the text of the IPA transcription
      Throws:
      ParseException
    • length

      public int length()
      Length of transcription (in elements)
      Returns:
      length
    • matches

      public boolean matches(String phonex)
    • matches

      public boolean matches(String phonex, int flags)
      Returns true if this transcript matches the given phonex.
      Parameters:
      phonex -
      flags -
      Returns:
      true if the transcript matches the given phonex, false otherwise
      Throws:
      PhonexPatternException - if the given phonex is not valid
    • contains

      public boolean contains(String phonex)
    • contains

      public boolean contains(String phonex, int flags)
      Returns true if this transcript contains the given phonex pattern.
      Parameters:
      phonex -
      flags -
      Returns:
      true if the transcript contains the given phonex pattern, false otherwise
      Throws:
      PhonexPatternException - if the given phonex is not valid
    • elementAt

      public IPAElement elementAt(int index)
      Get the element at specified index
      Parameters:
      index -
      Returns:
      element
      Throws:
      ArrayIndexOutOfBoundsException
    • ipaIndexOf

      public int ipaIndexOf(int charIdx)
      Return the ipa element index of the given string index.
      Parameters:
      charIdx -
      Returns:
      ipaIndex
    • indexOf

      public int indexOf(IPAElement ele)
      Return the index of the given element
      Parameters:
      ele -
      Returns:
      index of element or invalid input: '<' 0 if not found
    • indexOf

      public int indexOf(String phonex)
      Returns the index of the first phone of the given phonex pattern in this transcript.
      Parameters:
      phonex -
      Returns:
      the index of the first phone in the given pattern or -1 if not found
      Throws:
      PhonexPatternException - if the given phonex is not valid
    • indexOf

      public int indexOf(String phonex, int index)
      Returns the index of the first phone of the given phonex pattern in this transcript starting at the given phone index.
      Parameters:
      phonex -
      index - of the phone to start searching from
      Returns:
      the index of the first phone in the given pattern or -1 if not found
      Throws:
      PhonexPatternException - if the given phonex is not valid
    • indexOf

      public int indexOf(IPATranscript transcript)
      Return the index of the first element in the given transcript.
      Parameters:
      transcript -
      Returns:
      the index or -1 if not found
    • split

      public IPATranscript[] split(String phonex)
    • split

      public IPATranscript[] split(String phonex, int flags)
      Split transcript using the given phonex pattern as a delimiter.
      Parameters:
      phonex -
      flags -
    • subsection

      public IPATranscript subsection(int start, int end)
      Return a subsection of this transcription.
      Parameters:
      start -
      end -
      Returns:
      a new IPATranscript which is a sub-section of this transcription
      Throws:
      ArrayIndexOutOfBoundsException - if either start or end are out of bounds
    • replaceFirst

      public IPATranscript replaceFirst(String pattern, String replacement) throws ParseException
      Replace the first occurrence of the a phonex expression with the given replacement.
      Parameters:
      pattern -
      replacement -
      Returns:
      a new IPA transcript
      Throws:
      ParseException
    • replaceFirst

      public IPATranscript replaceFirst(PhonexPattern pattern, IPATranscript replacement)
      Replace the first occurrence of the a phonex expression with the given replacement.
      Parameters:
      pattern -
      replacement -
      Returns:
      a new IPA transcript
    • replaceAll

      public IPATranscript replaceAll(String pattern, String replacement) throws ParseException
      Replace all occurrences of the a phonex expression with the given replacement.
      Parameters:
      pattern -
      replacement -
      Returns:
      a new IPA transcript
      Throws:
      ParseException
    • replaceAll

      public IPATranscript replaceAll(PhonexPattern pattern, IPATranscript replacement)
      Replace all occurrences of the a phonex expression with the given replacement.
      Parameters:
      pattern -
      replacement -
      Returns:
      a new IPA transcript
    • append

      public IPATranscript append(IPATranscript ipa)
      Return a new IPATranscript that include the contents of this transcript along with the contents of the given transcript appended at the end.
      Parameters:
      ipa -
    • removePunctuation

      public IPATranscript removePunctuation()
      Create a new transcript with all punctuation removed (except word boundaries). Same as removePunctuation(false)
      Returns:
      the filtered transcript
    • removePunctuation

      public IPATranscript removePunctuation(boolean ignoreWordBoundaries)
      Create a new transcript with all punctuation remove. Option to ignore word boundaries can be provided.
      Parameters:
      ignoreWordBoundaries -
      Returns:
      the filtered transcript
    • stripDiacritics

      public IPATranscript stripDiacritics()
      Remove all diacritics from phones and compound phones.
      Returns:
      transcript with filtered diacritics
    • stripDiacritics

      public IPATranscript stripDiacritics(Collection<Diacritic> selectedDiacritics)
      Strip only diacritics found in given diacritics
      Parameters:
      selectedDiacritics -
    • stripDiacriticsExcept

      public IPATranscript stripDiacriticsExcept(Collection<Diacritic> selectedDiacritics)
      Strip diacritics except those found in the given diacritics
      Parameters:
      selectedDiacritics -
    • stripDiacritics

      public IPATranscript stripDiacritics(Predicate<Diacritic> diacriticFilter)
      Strip diacritics from transcript using custom filter.
      Parameters:
      diacriticFilter -
      Returns:
    • stripDiacriticsFromText

      public static String stripDiacriticsFromText(String text, boolean onlyOrExcept, Collection<Diacritic> selectedDiacritics)
    • audiblePhones

      public IPATranscript audiblePhones()
      Create a list of IPAElements which produce a sound.
      Returns:
      audible phones
    • syllables

      public List<IPATranscript> syllables()
      Break the transcript into syllables.
      Returns:
      syllables
    • syllablesAndPauses

      public List<IPATranscript> syllablesAndPauses()
      Return syllables, including intra-word pauses.
      Returns:
      syllables and pauses
    • resetSyllabification

      public void resetSyllabification()
      Reset syllabification for the transcript.
    • words

      public List<IPATranscript> words()
      Break the transcript into words
      Returns:
      words
    • accept

      public void accept(Visitor<IPAElement> visitor)
      Description copied from interface: Visitable
      Accept the given visitor.
      Specified by:
      accept in interface Visitable<IPAElement>
    • stringIndexOfElement

      public int stringIndexOfElement(IPAElement ele)
      Finds the index of the given ipa element in the string representation of the transcript.
      Parameters:
      ele -
      Returns:
      the string index of the specified element or invalid input: '<' 0 if not found
    • stringIndexOf

      public int stringIndexOf(IPATranscript transcript)
      Find the index of the given ipa transcript in the string representation of this transcript.
      Parameters:
      transcript -
      Returns:
      the string index of the given transcript or invalid input: '<' 0 if not found
    • stringIndexOfElement

      public int stringIndexOfElement(int index)
      Finds the index of the specified ipa element in the string representation of the transcript.
      Parameters:
      index -
      Returns:
      the string index of the specified element or invalid input: '<' 0 if not found
    • getStressPattern

      public String getStressPattern()
    • matchesStressPattern

      public boolean matchesStressPattern(String pattern)
      Does this transcript's stress pattern match the given StressPattern
      Parameters:
      pattern -
      Returns:
      true if pattern matches, false otherwise
    • containsStressPattern

      public boolean containsStressPattern(String pattern)
      Does this transcript contain the given StressPattern
      Parameters:
      pattern -
      Returns:
      true if this transcript contains the stress pattern, false otherwise
    • findStressPattern

      public List<IPATranscript> findStressPattern(String pattern)
      Find all occurrences of the given StressPattern
      Parameters:
      pattern -
      Returns:
    • getCvPattern

      public String getCvPattern()
    • matchesCVPattern

      public boolean matchesCVPattern(String pattern)
    • containsCVPattern

      public boolean containsCVPattern(String pattern)
    • findCVPattern

      public List<IPATranscript> findCVPattern(String pattern)
    • cover

      public IPATranscript cover()
      Get default CGV pattern cover
      Returns:
      transcript covered using G=\g; C=\c; V=\v
    • cover

      public IPATranscript cover(String symbolMap)
      Cover using string encoding symbol map.
      Parameters:
      symbolMap -
    • cover

      public IPATranscript cover(List<PhoneMatcher> matchers, Map<PhoneMatcher,Character> symbolMap, boolean includeStress, boolean includeSyllableBoundaries, boolean includeDiacritics)
      Cover the image of IPAElements in the transcript using the given symbol map. The result will be a new IPATranscript whose elements have the same feature set and syllablifiation information as the original transcript. Elements which are not matched using the symbol table are copied as-is.
      Parameters:
      matchers -
      symbolMap -
      includeStress - include stress marker elements
      includeSyllableBoundaries - keep syllable boundaries (i.e., '.') elements
      includeDiacritics - keep diacritics on elements
    • cover

      public IPATranscript cover(Character consonantCover, Character vowelCover)
      Cover IPATranscript using provided cover characters.
      Parameters:
      consonantCover -
      vowelCover -
      Returns:
    • cover

      public IPATranscript cover(String consonantCover, String vowelCover)
    • getExtensions

      public Set<Class<?>> getExtensions()
      Description copied from interface: IExtendable
      Return all extension types supported
      Specified by:
      getExtensions in interface IExtendable
    • getExtension

      public <T> T getExtension(Class<T> cap)
      Description copied from interface: IExtendable
      Get the requested extension if available.
      Specified by:
      getExtension in interface IExtendable
      Returns:
      the capability object or null if the cability is not available
    • putExtension

      public <T> T putExtension(Class<T> cap, T impl)
      Description copied from interface: IExtendable
      Add a new extension.
      Specified by:
      putExtension in interface IExtendable
      Parameters:
      cap - the extension to add
      Returns:
      the added extension implementation
    • removeExtension

      public <T> T removeExtension(Class<T> cap)
      Description copied from interface: IExtendable
      Remove a capability.
      Specified by:
      removeExtension in interface IExtendable
      Parameters:
      cap - the capability to remove
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(boolean includeScType)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object ipa)
      Overrides:
      equals in class Object
    • toList

      public List<IPAElement> toList()
      Get an immutable list representation of this IPATranscript.
      Returns:
      list
    • iterator

      public Iterator<IPAElement> iterator()
      Specified by:
      iterator in interface Iterable<IPAElement>
    • compareTo

      public int compareTo(IPATranscript o)
      Specified by:
      compareTo in interface Comparable<IPATranscript>
    • compareTo

      public int compareTo(IPATranscript ipa, Comparator<IPAElement> comparator)