Class PhoneticEngine


  • public class PhoneticEngine
    extends java.lang.Object
    Converts words into potential phonetic representations.

    This is a two-stage process. Firstly, the word is converted into a phonetic representation that takes into account the likely source language. Next, this phonetic representation is converted into a pan-European 'average' representation, allowing comparison between different versions of essentially the same word from different languages.

    This class is intentionally immutable and thread-safe. If you wish to alter the settings for a PhoneticEngine, you must make a new one with the updated settings.

    Ported from phoneticengine.php

    Since:
    1.6
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  PhoneticEngine.Builder
      Builder for a PhoneticEngine.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PhoneticEngine.Builder builder()
      Creates a new builder for a PhoneticEngine.
      java.lang.String encode​(java.lang.String input)
      Encodes a string to its phonetic representation.
      java.lang.String encode​(java.lang.String input, Languages.LanguageSet languageSet)
      Encodes an input string into an output phonetic representation, given a set of possible origin languages.
      Lang getLang()
      Gets the Lang language guessing rules being used.
      int getMaxPhonemes()
      Gets the maximum number of phonemes the engine will calculate for a given input.
      NameType getNameType()
      Gets the NameType being used.
      RuleType getRuleType()
      Gets the RuleType being used.
      boolean isConcat()
      Tests whether multiple phonetic encodings are concatenated or just the first one is kept.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PhoneticEngine

        @Deprecated
        public PhoneticEngine​(NameType nameType,
                              RuleType ruleType,
                              boolean concatenate)
        Deprecated.
        Use builder() instead.
        Generates a new, fully-configured phonetic engine.
        Parameters:
        nameType - the type of names it will use, null is treated as NameType.GENERIC.
        ruleType - the type of rules it will apply, null is treated as RuleType.APPROX.
        concatenate - if it will concatenate multiple encodings.
      • PhoneticEngine

        @Deprecated
        public PhoneticEngine​(NameType nameType,
                              RuleType ruleType,
                              boolean concatenate,
                              int maxPhonemes)
        Deprecated.
        Use builder() instead.
        Generates a new, fully-configured phonetic engine.
        Parameters:
        nameType - the type of names it will use, null is treated as NameType.GENERIC.
        ruleType - the type of rules it will apply, null is treated as RuleType.APPROX.
        concatenate - if it will concatenate multiple encodings.
        maxPhonemes - the maximum number of phonemes that will be handled, less than 0 will reset to the default of 20.
        Throws:
        java.lang.IllegalArgumentException - Thrown if ruleType is RULES.
        Since:
        1.7
    • Method Detail

      • builder

        public static PhoneticEngine.Builder builder()
        Creates a new builder for a PhoneticEngine.
        Returns:
        a new builder for a PhoneticEngine.
        Since:
        1.23.0
      • encode

        public java.lang.String encode​(java.lang.String input)
        Encodes a string to its phonetic representation.
        Parameters:
        input - the String to encode, not null.
        Returns:
        The encoding of the input.
        Throws:
        java.lang.IllegalArgumentException - Thrown if the input is longer than the maximum allowed length.
      • encode

        public java.lang.String encode​(java.lang.String input,
                                       Languages.LanguageSet languageSet)
        Encodes an input string into an output phonetic representation, given a set of possible origin languages.
        Parameters:
        input - String to phoneticise; a String with dashes or spaces separating each word, not null.
        languageSet - set of possible origin languages.
        Returns:
        A phonetic representation of the input; a String containing '-'-separated phonetic representations of the input.
        Throws:
        java.lang.IllegalArgumentException - Thrown if the input is longer than the maximum allowed length.
      • getLang

        public Lang getLang()
        Gets the Lang language guessing rules being used.
        Returns:
        The Lang in use.
      • getMaxPhonemes

        public int getMaxPhonemes()
        Gets the maximum number of phonemes the engine will calculate for a given input.
        Returns:
        The maximum number of phonemes.
        Since:
        1.7
      • getNameType

        public NameType getNameType()
        Gets the NameType being used.
        Returns:
        The NameType in use.
      • getRuleType

        public RuleType getRuleType()
        Gets the RuleType being used.
        Returns:
        The RuleType in use.
      • isConcat

        public boolean isConcat()
        Tests whether multiple phonetic encodings are concatenated or just the first one is kept.
        Returns:
        true if multiple phonetic encodings are returned, false if just the first is.