edu.stanford.nlp.parser.lexparser
Class BinaryGrammar

java.lang.Object
  extended by edu.stanford.nlp.parser.lexparser.BinaryGrammar
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<BinaryRule>

public class BinaryGrammar
extends java.lang.Object
implements java.io.Serializable, java.lang.Iterable<BinaryRule>

Maintains efficient indexing of binary grammar rules.

Author:
Dan Klein, Christopher Manning (generified and optimized storage)
See Also:
Serialized Form

Constructor Summary
BinaryGrammar(int numStates)
           
BinaryGrammar(int numStates, java.lang.String stateSpace)
           
 
Method Summary
 void addRule(BinaryRule br)
           
 boolean isSynthetic(int state)
           
 java.util.Iterator<BinaryRule> iterator()
           
 int numRules()
           
 void readData(java.io.BufferedReader in)
          Populates data in this BinaryGrammar from the character stream given by the Reader r.
 java.util.Iterator<BinaryRule> ruleIteratorByLeftChild(int state)
           
 java.util.Iterator<BinaryRule> ruleIteratorByParent(int state)
           
 java.util.Iterator<BinaryRule> ruleIteratorByRightChild(int state)
           
 java.util.List<BinaryRule> ruleListByLeftChild(int state)
           
 java.util.List<BinaryRule> ruleListByParent(int state)
           
 java.util.List<BinaryRule> ruleListByRightChild(int state)
           
 java.util.List<BinaryRule> rules()
           
 java.util.Set<BinaryRule> ruleSetByLeftChild(int state)
           
 java.util.Set<BinaryRule> ruleSetByRightChild(int state)
           
 double scoreRule(BinaryRule br)
           
 void splitRules()
          Populates the "splitRules" accessor lists using the existing rule lists.
 BinaryRule[] splitRulesWithLC(int state)
           
 BinaryRule[] splitRulesWithRC(int state)
           
 java.lang.String stateSpace()
           
 void writeData(java.io.Writer w)
          Writes out data from this Object to the Writer w.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryGrammar

public BinaryGrammar(int numStates)

BinaryGrammar

public BinaryGrammar(int numStates,
                     java.lang.String stateSpace)
Method Detail

numRules

public int numRules()

rules

public java.util.List<BinaryRule> rules()

stateSpace

public java.lang.String stateSpace()

isSynthetic

public boolean isSynthetic(int state)

splitRules

public void splitRules()
Populates the "splitRules" accessor lists using the existing rule lists. If the state is synthetic, these lists contain all rules for the state. If the state is NOT synthetic, these lists contain only the rules in which both children are not synthetic.

This method must be called before the grammar is used, either after training or deserializing grammar.


splitRulesWithLC

public BinaryRule[] splitRulesWithLC(int state)

splitRulesWithRC

public BinaryRule[] splitRulesWithRC(int state)

scoreRule

public double scoreRule(BinaryRule br)

addRule

public void addRule(BinaryRule br)

iterator

public java.util.Iterator<BinaryRule> iterator()
Specified by:
iterator in interface java.lang.Iterable<BinaryRule>

ruleIteratorByParent

public java.util.Iterator<BinaryRule> ruleIteratorByParent(int state)

ruleIteratorByRightChild

public java.util.Iterator<BinaryRule> ruleIteratorByRightChild(int state)

ruleIteratorByLeftChild

public java.util.Iterator<BinaryRule> ruleIteratorByLeftChild(int state)

ruleListByParent

public java.util.List<BinaryRule> ruleListByParent(int state)

ruleListByRightChild

public java.util.List<BinaryRule> ruleListByRightChild(int state)

ruleListByLeftChild

public java.util.List<BinaryRule> ruleListByLeftChild(int state)

ruleSetByRightChild

public java.util.Set<BinaryRule> ruleSetByRightChild(int state)

ruleSetByLeftChild

public java.util.Set<BinaryRule> ruleSetByLeftChild(int state)

readData

public void readData(java.io.BufferedReader in)
              throws java.io.IOException
Populates data in this BinaryGrammar from the character stream given by the Reader r.

Parameters:
in - Where input is read from
Throws:
java.io.IOException - If format is bung

writeData

public void writeData(java.io.Writer w)
               throws java.io.IOException
Writes out data from this Object to the Writer w.

Parameters:
w - Where output is written
Throws:
java.io.IOException - If data can't be written


Stanford NLP Group