java.lang.Object
com.github.szgabsz91.morpher.languagehandlers.hunmorph.impl.markov.FullMarkovModel
All Implemented Interfaces:
com.github.szgabsz91.morpher.core.io.IConvertable<MarkovModelMessage>, IMarkovModel

public class FullMarkovModel extends Object implements IMarkovModel
IMarkovModel implementation that stores every single transition route.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Node class for the FullMarkovModel.
  • Field Summary

    Fields inherited from interface com.github.szgabsz91.morpher.languagehandlers.hunmorph.impl.markov.IMarkovModel

    END, START
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
    Adds the given list of affix type to the Markov model.
    void
    add(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes, long relativeFrequency)
    Adds the given list of affix types to the Markov model, and sets the last relative frequency to the provided value.
    com.github.szgabsz91.morpher.languagehandlers.api.model.AffixTypeChain
    calculateProbabilities(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
    Creates a new AffixTypeChain containing the given affix types.
    double
    calculateProbability(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
    Calculates the probability of the affix type chain given with its list of AffixTypes.
    void
    Loads the state from the given MarkovModelMessage.
    void
    fromMessage(com.google.protobuf.Any message)
    Loads the state from the given message.
    List<com.github.szgabsz91.morpher.languagehandlers.api.model.ProbabilisticAffixType>
    getCandidates(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
    Returns the list of candidates that can come after the given list of affix types.
    com.github.szgabsz91.morpher.languagehandlers.api.model.ProbabilisticAffixType
    getProbabilityOfPOS(com.github.szgabsz91.morpher.core.model.AffixType pos)
    Returns the affix type with its probability for the given part of speech tag.
    Returns all the routes in this Markov model, with the relative frequency of the last node.
    boolean
    isAffixTypeChainValid(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypeChain)
    Returns if the affix type chain is valid or not.
    Reverses this FullMarkovModel.
    List<com.github.szgabsz91.morpher.languagehandlers.api.model.AffixTypeChain>
    sortAffixTypes(Set<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes, Predicate<com.github.szgabsz91.morpher.core.model.AffixType> posPredicate)
    Returns an ordered list of AffixTypeChain objects.
    Converts this Markov model to a MarkovModelMessage.
    Returns the hierarchical string representation of this Markov model.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FullMarkovModel

      public FullMarkovModel()
      Default constructor.
  • Method Details

    • add

      public void add(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
      Adds the given list of affix type to the Markov model.
      Specified by:
      add in interface IMarkovModel
      Parameters:
      affixTypes - the list of affix types
    • add

      public void add(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes, long relativeFrequency)
      Adds the given list of affix types to the Markov model, and sets the last relative frequency to the provided value.
      Parameters:
      affixTypes - the list of affix types
      relativeFrequency - the last relative frequency
    • isAffixTypeChainValid

      public boolean isAffixTypeChainValid(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypeChain)
      Returns if the affix type chain is valid or not. Returns if the given affix type chain is valid or not.
      Specified by:
      isAffixTypeChainValid in interface IMarkovModel
      Parameters:
      affixTypeChain - the affix type chain to check
      Returns:
      true if the affix type chain is valid, false otherwise
    • sortAffixTypes

      public List<com.github.szgabsz91.morpher.languagehandlers.api.model.AffixTypeChain> sortAffixTypes(Set<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes, Predicate<com.github.szgabsz91.morpher.core.model.AffixType> posPredicate)
      Returns an ordered list of AffixTypeChain objects. Tries to sort the given set of affix types, and returns a list of AffixTypeChain objects.
      Specified by:
      sortAffixTypes in interface IMarkovModel
      Parameters:
      affixTypes - the set of affix types
      posPredicate - predicate that returns if a given affix type is a part-of-speech tag or not
      Returns:
      the list of AffixTypeChain objects
    • calculateProbabilities

      public com.github.szgabsz91.morpher.languagehandlers.api.model.AffixTypeChain calculateProbabilities(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
      Creates a new AffixTypeChain containing the given affix types. Creates a new AffixTypeChain containing the appropriate part of speech tag and the given list of affix types, with the calculated local probabilities.
      Specified by:
      calculateProbabilities in interface IMarkovModel
      Parameters:
      affixTypes - the affix types on the chain
      Returns:
      the created AffixTypeChain
    • calculateProbability

      public double calculateProbability(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
      Calculates the probability of the affix type chain given with its list of AffixTypes. Calculates the probability of the affix type chain given with its list of AffixTypes.
      Specified by:
      calculateProbability in interface IMarkovModel
      Parameters:
      affixTypes - the list of AffixTypes on the affix type chain
      Returns:
      the probability of the affix type chain
    • getProbabilityOfPOS

      public com.github.szgabsz91.morpher.languagehandlers.api.model.ProbabilisticAffixType getProbabilityOfPOS(com.github.szgabsz91.morpher.core.model.AffixType pos)
      Returns the affix type with its probability for the given part of speech tag. Returns the affix type with its probability for the given part of speech tag.
      Specified by:
      getProbabilityOfPOS in interface IMarkovModel
      Parameters:
      pos - the part of speech tag
      Returns:
      the ProbabilisticAffixType instance
    • getCandidates

      public List<com.github.szgabsz91.morpher.languagehandlers.api.model.ProbabilisticAffixType> getCandidates(List<com.github.szgabsz91.morpher.core.model.AffixType> affixTypes)
      Returns the list of candidates that can come after the given list of affix types. Returns the candidates after the given list of affix types.
      Specified by:
      getCandidates in interface IMarkovModel
      Parameters:
      affixTypes - the already processed list of affix types
      Returns:
      the list of candidates, sorted by relative frequencies, in descending order
    • reverse

      public IMarkovModel reverse()
      Reverses this FullMarkovModel.
      Specified by:
      reverse in interface IMarkovModel
      Returns:
      the reversed FullMarkovModel
    • toMessage

      public MarkovModelMessage toMessage()
      Converts this Markov model to a MarkovModelMessage.
      Specified by:
      toMessage in interface com.github.szgabsz91.morpher.core.io.IConvertable<MarkovModelMessage>
      Returns:
      the MarkovModelMessage
    • fromMessage

      public void fromMessage(MarkovModelMessage message)
      Loads the state from the given MarkovModelMessage.
      Specified by:
      fromMessage in interface com.github.szgabsz91.morpher.core.io.IConvertable<MarkovModelMessage>
      Parameters:
      message - the MarkovModelMessage
    • fromMessage

      public void fromMessage(com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException
      Loads the state from the given message.
      Specified by:
      fromMessage in interface com.github.szgabsz91.morpher.core.io.IConvertable<MarkovModelMessage>
      Parameters:
      message - the message
      Throws:
      com.google.protobuf.InvalidProtocolBufferException - if the given message is not a MarkovModelMessage
    • getRoutes

      public Map<List<FullMarkovModel.Node>,Long> getRoutes()
      Returns all the routes in this Markov model, with the relative frequency of the last node.
      Returns:
      all the routes associated with the relative frequency of the last node
    • toString

      public String toString()
      Returns the hierarchical string representation of this Markov model.
      Overrides:
      toString in class Object