edu.stanford.nlp.parser.lexparser
Class AbstractDependencyGrammar

java.lang.Object
  extended by edu.stanford.nlp.parser.lexparser.AbstractDependencyGrammar
All Implemented Interfaces:
DependencyGrammar, Serializable
Direct Known Subclasses:
MLEDependencyGrammar

public abstract class AbstractDependencyGrammar
extends Object
implements DependencyGrammar

An abstract base class for dependency grammars. The only thing you have to implement in a subclass is scoreTB. A subclass also has to either call super() in its constructor, or otherwise initialize the tagBin array. The call to initTagBins() (in the constructor) must be made after all keys have been entered into Numberer.getGlobalNumberer("tags").

Author:
Galen Andrew
See Also:
Serialized Form

Field Summary
protected  boolean directional
           
protected  Map expandDependencyMap
           
protected  int numTagBins
           
protected static IntTaggedWord stopTW
           
protected  int[] tagBin
           
protected  edu.stanford.nlp.parser.lexparser.TagProjection tagProjection
           
protected  TreebankLanguagePack tlp
           
protected  boolean useCoarseDistance
           
protected  boolean useDistance
           
protected static IntTaggedWord wildTW
           
 
Constructor Summary
AbstractDependencyGrammar(TreebankLanguagePack tlp, edu.stanford.nlp.parser.lexparser.TagProjection tagProjection, boolean directional, boolean useDistance, boolean useCoarseDistance)
           
 
Method Summary
static short courseDistanceBin(int distance)
           
 short distanceBin(int distance)
           
protected  edu.stanford.nlp.parser.lexparser.Dependency intern(IntTaggedWord headTW, IntTaggedWord argTW, boolean leftHeaded, int dist)
           
 int numDistBins()
           
 int numTagBins()
           
 void readData(BufferedReader in)
          Default is to throw exception.
static short regDistanceBin(int distance)
           
static boolean rootTW(IntTaggedWord rTW)
           
 double score(edu.stanford.nlp.parser.lexparser.Dependency dependency)
          Score a Dependency according to the grammar.
 double score(int headWord, int headTag, int argWord, int argTag, boolean leftHeaded, int dist)
          cdm: this seems to fail to do the tagbin'ing you'd expect ...
 double scoreTB(int headWord, int headTag, int argWord, int argTag, boolean leftHeaded, int dist)
          Score a dependency according to the grammar, where the elements of the dependency are represented in separate paramters.
 int tagBin(int tag)
          Converts a tag (coded as an integer via a Numberer) from its representation in the full tag space to the reduced (projected) tag space used in the DependencyGrammar.
protected static Numberer tagNumberer()
           
 void tune(Collection<Tree> trees)
          Default is no-op.
protected  short valenceBin(int distance)
           
protected static Numberer wordNumberer()
           
 void writeData(PrintWriter out)
          Default is to throw exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.stanford.nlp.parser.lexparser.DependencyGrammar
scoreTB
 

Field Detail

tagProjection

protected edu.stanford.nlp.parser.lexparser.TagProjection tagProjection

numTagBins

protected int numTagBins

tagBin

protected int[] tagBin

tlp

protected TreebankLanguagePack tlp

directional

protected boolean directional

useDistance

protected boolean useDistance

useCoarseDistance

protected boolean useCoarseDistance

stopTW

protected static final IntTaggedWord stopTW

wildTW

protected static final IntTaggedWord wildTW

expandDependencyMap

protected transient Map expandDependencyMap
Constructor Detail

AbstractDependencyGrammar

public AbstractDependencyGrammar(TreebankLanguagePack tlp,
                                 edu.stanford.nlp.parser.lexparser.TagProjection tagProjection,
                                 boolean directional,
                                 boolean useDistance,
                                 boolean useCoarseDistance)
Method Detail

tagNumberer

protected static Numberer tagNumberer()

wordNumberer

protected static Numberer wordNumberer()

tune

public void tune(Collection<Tree> trees)
Default is no-op.

Specified by:
tune in interface DependencyGrammar
Parameters:
trees -

numTagBins

public int numTagBins()
Specified by:
numTagBins in interface DependencyGrammar
Returns:
The number of tags recognized in the reduced (projected) tag space used in the DependencyGrammar.

tagBin

public int tagBin(int tag)
Description copied from interface: DependencyGrammar
Converts a tag (coded as an integer via a Numberer) from its representation in the full tag space to the reduced (projected) tag space used in the DependencyGrammar.

Specified by:
tagBin in interface DependencyGrammar
Parameters:
tag - An int encoding a tag (in the "tags" Numberer)
Returns:
An int representing the tag in the reduced binTag space

rootTW

public static boolean rootTW(IntTaggedWord rTW)

valenceBin

protected short valenceBin(int distance)

numDistBins

public int numDistBins()
Specified by:
numDistBins in interface DependencyGrammar
Returns:
The number of distance buckets (measured between the head and the nearest corner of the argument) used in calculating attachment probabilities by the DependencyGrammar

distanceBin

public short distanceBin(int distance)
Specified by:
distanceBin in interface DependencyGrammar
Returns:
The distance bucket corresponding the the original distance (measured between the head and the nearest corner of the argument) used in calculating attachment probabilities by the DependencyGrammar. Bucket numbers are small integers [0, ..., numDistBins - 1].

regDistanceBin

public static short regDistanceBin(int distance)

courseDistanceBin

public static short courseDistanceBin(int distance)

score

public double score(edu.stanford.nlp.parser.lexparser.Dependency dependency)
Description copied from interface: DependencyGrammar
Score a Dependency according to the grammar.

Specified by:
score in interface DependencyGrammar
Parameters:
dependency - The dependency object to be scored, in normal form.
Returns:
The negative log probability given to the dependency by the grammar. This may be Double.NEGATIVE_INFINITY for "impossible".

score

public double score(int headWord,
                    int headTag,
                    int argWord,
                    int argTag,
                    boolean leftHeaded,
                    int dist)
cdm: this seems to fail to do the tagbin'ing you'd expect ...

Specified by:
score in interface DependencyGrammar
Returns:
The negative log probability given to the dependency by the grammar. This may be Double.NEGATIVE_INFINITY for "impossible".

scoreTB

public double scoreTB(int headWord,
                      int headTag,
                      int argWord,
                      int argTag,
                      boolean leftHeaded,
                      int dist)
Description copied from interface: DependencyGrammar
Score a dependency according to the grammar, where the elements of the dependency are represented in separate paramters. The tags in the dependency have already been mapped to a reduced space by a tagProjection function.

Specified by:
scoreTB in interface DependencyGrammar
Returns:
The negative log probability given to the dependency by the grammar. This may be Double.NEGATIVE_INFINITY for "impossible".

readData

public void readData(BufferedReader in)
              throws IOException
Default is to throw exception.

Specified by:
readData in interface DependencyGrammar
Parameters:
in -
Throws:
IOException

writeData

public void writeData(PrintWriter out)
               throws IOException
Default is to throw exception.

Specified by:
writeData in interface DependencyGrammar
Parameters:
out -
Throws:
IOException

intern

protected edu.stanford.nlp.parser.lexparser.Dependency intern(IntTaggedWord headTW,
                                                              IntTaggedWord argTW,
                                                              boolean leftHeaded,
                                                              int dist)


Stanford NLP Group