hu.birot.OTKit.grammarExamples
Class StringGrammar

java.lang.Object
  extended by hu.birot.OTKit.otBuildingBlocks.Grammar
      extended by hu.birot.OTKit.grammarExamples.StringGrammar

public class StringGrammar
extends Grammar

A subclass of Grammar playing with strings. Used in a number of articles of the author since 2007.

Forms in a String Grammar belong to type Form(o,"string"), where o is an array of integers of length StringGrammar.L. Each element of the array can have a value between 0 and StringGrammar.K.

Constraints are named as (where letter can be anything between 0 and StringGrammar.K):

"No"+letter assign 1 violation mark to each instance of letter.
"Ni"+letter assign 1 violation mark, if string begins with letter.
"Nf"+letter assign 1 violation mark, if string ends with letter.
"Assimilate" assign 1 violation mark to each adjacent character pair of different letters.
"Dissimilate" assign 1 violation mark to each adjacent character pair of the same letters.
"Faithfulness"pointwise faithfulness, see method Faithful().

See Also:
Grammar

Field Summary
 int K
          The size of the alphabet in this grammar.
 int L
          The length of strings in this grammar.
static IntegerViolation nulViol
          Violation(0).
static IntegerViolation oneViol
          Violation(1).
 
Fields inherited from class hu.birot.OTKit.otBuildingBlocks.Grammar
base, gen, hierarchy, topology, type, utter
 
Constructor Summary
StringGrammar(int alphabetsize, int length, java.lang.String h_type)
          To construct a string grammar, you must add the alphabet's size and the length of each string.
 
Method Summary
 Constraint Assimilate()
          This class creates constraint "Assimilate", which punishes each pair of different neighboring characters.
 Constraint Dissimilate()
          This class creates constraint "Dissimilate", which punishes each pair of similar neighboring characters.
 Constraint Faithful()
          This class creates constraint "Faithful", which punishes each locus such that the uf is different from the sf.
 Constraint No_i(int letter)
          This class creates a constraint assigning one violation mark to each occurrence of character letter in a string grammar.
 Constraint NoFinal_i(int letter)
          This class creates a constraint assigning one violation mark to the surface form if it ends with character letter.
 Constraint NoInitial_i(int letter)
          This class creates a constraint assigning one violation mark to the surface form if it begins with character letter.
 void setPragueHierarchy()
          This method sets the K-values to those used in my 2007 paper (ACL workshop in Prague).
 Form StrForm(int[] array)
          This method returns a Form based on the values in an array.
static int StrFormGet(Form f, int locus)
          This static method returns the value at position locus of the Form f.
 Form StrFormSet(Form f, int locus, int value)
          This method returns a Form that is similar to the Form, but the character in position locus is rewritten as value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

L

public final int L

The length of strings in this grammar.


K

public final int K

The size of the alphabet in this grammar. Each element of the array representing a form can have the integer values 0 ... K-1.


nulViol

public static final IntegerViolation nulViol
Violation(0). Predefined to speed up computations.


oneViol

public static final IntegerViolation oneViol
Violation(1). Predefined to speed up computations.

Constructor Detail

StringGrammar

public StringGrammar(int alphabetsize,
                     int length,
                     java.lang.String h_type)

To construct a string grammar, you must add the alphabet's size and the length of each string.

Parameters:
alphabetsize - The size of the alphabet (0 ... alphabetsize-1).
length - The length of the strings.
h_type - Type of the Hierarchy (for instance, "ot" or "hg").
Method Detail

StrForm

public Form StrForm(int[] array)
This method returns a Form based on the values in an array. (The array is cloned, so that a latter change in that array should not influence the immutable form.) The Form will be used in the StringGrammar ...


StrFormSet

public Form StrFormSet(Form f,
                       int locus,
                       int value)

This method returns a Form that is similar to the Form, but the character in position locus is rewritten as value. Obviously, 0 <= locus < StringGrammar.L and 0 <= value < StringGrammar.K must be satisfied. If f is not a Form of type "StringGrammar", the output is garbage.

Parameters:
f - The Form based on which a new Form is created.
locus - The position at which the character to be rewritten.
value - The new value of the character at position locus.
Returns:
A Form of type "StringGrammar" whose array is similar to f, but at position locus you find value.

StrFormGet

public static int StrFormGet(Form f,
                             int locus)

This static method returns the value at position locus of the Form f. If f is not of type "StringGrammar", then the output is garbage.

Parameters:
f - Form which is being read.
locus - Position within Form f.
Returns:
The character at position locus in Form f.

No_i

public Constraint No_i(int letter)
This class creates a constraint assigning one violation mark to each occurrence of character letter in a string grammar.

Parameters:
letter - The character being punished.
Returns:
A constraint, as described above.

NoInitial_i

public Constraint NoInitial_i(int letter)
This class creates a constraint assigning one violation mark to the surface form if it begins with character letter.

Parameters:
letter - The character being punished.
Returns:
A constraint, as described above.

NoFinal_i

public Constraint NoFinal_i(int letter)
This class creates a constraint assigning one violation mark to the surface form if it ends with character letter.

Parameters:
letter - The character being punished.
Returns:
A constraint, as described above.

Assimilate

public Constraint Assimilate()
This class creates constraint "Assimilate", which punishes each pair of different neighboring characters.

Returns:
Constraint "Assimilate".

Dissimilate

public Constraint Dissimilate()
This class creates constraint "Dissimilate", which punishes each pair of similar neighboring characters.

Returns:
Constraint "Dissimilate".

Faithful

public Constraint Faithful()

This class creates constraint "Faithful", which punishes each locus such that the uf is different from the sf. Each locus is assigned a violation mark that is the distance of the character in uf at that locus and of the character in sf at that locus. That is, the expression

d(uf[j],sf[j]) = Math.min( (uf[j] - sf[j] + K) % K, (uf[j] - sf[j] + K) % K )
is summed up for each locus j. Here, uf[j] and sf[j] denote the character at locus j in the underlying form string and in the surface form string respectively.

Returns:
Constraint "Faithful".

setPragueHierarchy

public void setPragueHierarchy()
This method sets the K-values to those used in my 2007 paper (ACL workshop in Prague).