Klasse NGramModel

java.lang.Object
opennlp.tools.ngram.NGramModel
Alle implementierten Schnittstellen:
Iterable<StringList>
Bekannte direkte Unterklassen:
NGramLanguageModel

public class NGramModel extends Object implements Iterable<StringList>
The NGramModel can be used to crate ngrams and character ngrams.
Siehe auch:
  • Konstruktordetails

  • Methodendetails

    • getCount

      public int getCount(StringList ngram)
      Retrieves the count of the given ngram.
      Parameter:
      ngram - an ngram
      Gibt zurück:
      count of the ngram or 0 if it is not contained
    • setCount

      public void setCount(StringList ngram, int count)
      Sets the count of an existing ngram.
      Parameter:
      ngram -
      count -
    • add

      public void add(StringList ngram)
      Adds one NGram, if it already exists the count increase by one.
      Parameter:
      ngram -
    • add

      public void add(StringList ngram, int minLength, int maxLength)
      Adds NGrams up to the specified length to the current instance.
      Parameter:
      ngram - the tokens to build the uni-grams, bi-grams, tri-grams, .. from.
      minLength - - minimal length
      maxLength - - maximal length
    • add

      public void add(CharSequence chars, int minLength, int maxLength)
      Adds character NGrams to the current instance.
      Parameter:
      chars -
      minLength -
      maxLength -
    • remove

      public void remove(StringList tokens)
      Removes the specified tokens form the NGram model, they are just dropped.
      Parameter:
      tokens -
    • contains

      public boolean contains(StringList tokens)
      Checks fit he given tokens are contained by the current instance.
      Parameter:
      tokens -
      Gibt zurück:
      true if the ngram is contained
    • size

      public int size()
      Retrieves the number of StringList entries in the current instance.
      Gibt zurück:
      number of different grams
    • iterator

      public Iterator<StringList> iterator()
      Retrieves an Iterator over all StringList entries.
      Angegeben von:
      iterator in Schnittstelle Iterable<StringList>
      Gibt zurück:
      iterator over all grams
    • numberOfGrams

      public int numberOfGrams()
      Retrieves the total count of all Ngrams.
      Gibt zurück:
      total count of all ngrams
    • cutoff

      public void cutoff(int cutoffUnder, int cutoffOver)
      Deletes all ngram which do appear less than the cutoffUnder value and more often than the cutoffOver value.
      Parameter:
      cutoffUnder -
      cutoffOver -
    • toDictionary

      public Dictionary toDictionary()
      Creates a dictionary which contain all StringList which are in the current NGramModel.

      Entries which are only different in the case are merged into one.

      Calling this method is the same as calling toDictionary(boolean) with true.

      Gibt zurück:
      a dictionary of the ngrams
    • toDictionary

      public Dictionary toDictionary(boolean caseSensitive)
      Creates a dictionary which contains all StringLists which are in the current NGramModel.
      Parameter:
      caseSensitive - Specifies whether case distinctions should be kept in the creation of the dictionary.
      Gibt zurück:
      a dictionary of the ngrams
    • serialize

      public void serialize(OutputStream out) throws IOException
      Writes the ngram instance to the given OutputStream.
      Parameter:
      out -
      Löst aus:
      IOException - if an I/O Error during writing occurs
    • equals

      public boolean equals(Object obj)
      Setzt außer Kraft:
      equals in Klasse Object
    • toString

      public String toString()
      Setzt außer Kraft:
      toString in Klasse Object
    • hashCode

      public int hashCode()
      Setzt außer Kraft:
      hashCode in Klasse Object