public class MetricalLpcfg
extends java.lang.Object
implements java.io.Serializable
MetricalLpcfg keeps track of the lexicalized pcfg we've generated with
a MetricalLpcfgGenerator.| Modifier and Type | Field and Description |
|---|---|
private MetricalLpcfgProbabilityTracker |
probabilities
The probability tracker for this grammar.
|
private static long |
serialVersionUID
Version 1 Serializable
|
private java.util.List<MetricalLpcfgTree> |
trees
A List of the trees contained in this lpcfg.
|
| Modifier | Constructor and Description |
|---|---|
|
MetricalLpcfg()
Create a new empty grammar.
|
private |
MetricalLpcfg(MetricalLpcfg lpcfg)
Create a new grammar, used by the
deepCopy() method. |
| Modifier and Type | Method and Description |
|---|---|
void |
addTree(MetricalLpcfgTree tree)
Add a tree to our list of trees (
trees). |
MetricalLpcfg |
deepCopy()
Get a deep copy of this grammar.
|
static MetricalLpcfg |
deserialize(java.io.File serialized)
Load a grammar from a serialized file.
|
void |
extractTree(MetricalLpcfgTree toExtract)
Extract the given tree from our list of trees.
|
java.util.Set<Measure> |
getMeasures()
Get a Set of the Measures which are contained in any tree from within this lpcfg.
|
private double |
getNodeLogProbability(MetricalLpcfgNode node,
MetricalLpcfgHead parentHead,
Measure measure)
Get the log probability of the given Node.
|
MetricalLpcfgProbabilityTracker |
getProbabilityTracker()
Get the probability tracker of this grammar.
|
double |
getTreeLogProbability(MetricalLpcfgTree tree)
Get the log probability that the given tree would occur in this grammar.
|
java.util.List<MetricalLpcfgTree> |
getTrees()
Get the trees contained in this grammar.
|
static void |
serialize(MetricalLpcfg grammar,
java.io.File file)
Serialize the given grammar and write it out to the given file.
|
java.lang.String |
toString() |
java.lang.String |
toStringPretty()
Get the pretty, recursive version of this grammar with the default tab String (\t).
|
java.lang.String |
toStringPretty(java.lang.String tab)
Get the pretty, recursive version of this grammar with the given tab String.
|
private void |
updateCounts(MetricalLpcfgNode node,
MetricalLpcfgHead parentHead,
Measure measure,
boolean adding)
Update the counts maps recursively for each node under the given one.
|
private static final long serialVersionUID
private final java.util.List<MetricalLpcfgTree> trees
private final MetricalLpcfgProbabilityTracker probabilities
public MetricalLpcfg()
private MetricalLpcfg(MetricalLpcfg lpcfg)
deepCopy() method.lpcfg - The old grammar this one is to be a copy of.public double getTreeLogProbability(MetricalLpcfgTree tree)
tree - The tree whose log probability we want.private double getNodeLogProbability(MetricalLpcfgNode node, MetricalLpcfgHead parentHead, Measure measure)
node - The node whose log probability we want.parentHead - The head of the parent of this node.measure - The measure of the tree.public void extractTree(MetricalLpcfgTree toExtract) throws MetricalLpcfgElementNotFoundException
toExtract - The tree we want to remove from this grammar.MetricalLpcfgElementNotFoundException - If the given tree is not found
in the grammar.public void addTree(MetricalLpcfgTree tree)
trees).tree - A new tree we want to add to this grammar.private void updateCounts(MetricalLpcfgNode node, MetricalLpcfgHead parentHead, Measure measure, boolean adding) throws MetricalLpcfgElementNotFoundException
node - The node whose counts we want to update.parentHead - The head of the parent of this node.measure - The measure of the tree.adding - True if we are adding to the counts, false if we're removing.MetricalLpcfgElementNotFoundException - If somepublic java.util.Set<Measure> getMeasures()
public java.util.List<MetricalLpcfgTree> getTrees()
treespublic MetricalLpcfgProbabilityTracker getProbabilityTracker()
probabilitiespublic MetricalLpcfg deepCopy()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toStringPretty()
public java.lang.String toStringPretty(java.lang.String tab)
tab - The tab String to use for indenting tree levels.public static void serialize(MetricalLpcfg grammar, java.io.File file) throws java.io.FileNotFoundException, java.io.IOException
grammar - The grammar we want to serialize.file - The file to write out the grammar to.java.io.FileNotFoundException - The file could not be opened for writing.java.io.IOException - Some IO error occurred.deserialize(File)public static MetricalLpcfg deserialize(java.io.File serialized) throws java.lang.ClassNotFoundException, java.io.IOException
serialized - The file containing a serialized grammar.java.lang.ClassNotFoundException - The class could not be deserialized properly.java.io.IOException - Some IO error occurred.serialize(MetricalLpcfg, File)