Skip to content

Commit

Permalink
Applied a few more automatic clean-ups in Eclipse.
Browse files Browse the repository at this point in the history
  • Loading branch information
slavstudent committed Oct 9, 2012
1 parent 3df728e commit 14db3ed
Show file tree
Hide file tree
Showing 155 changed files with 830 additions and 414 deletions.
2 changes: 1 addition & 1 deletion src/edu/berkeley/nlp/PCFGLA/ArrayParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.util.List;

import edu.berkeley.nlp.discPCFG.Linearizer;
import edu.berkeley.nlp.math.DoubleArrays;
import edu.berkeley.nlp.syntax.StateSet;
import edu.berkeley.nlp.syntax.Tree;
import edu.berkeley.nlp.math.DoubleArrays;
import edu.berkeley.nlp.util.ArrayUtil;
import edu.berkeley.nlp.util.Numberer;
import edu.berkeley.nlp.util.ScalingTools;
Expand Down
19 changes: 5 additions & 14 deletions src/edu/berkeley/nlp/PCFGLA/BerkeleyParser.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package edu.berkeley.nlp.PCFGLA;

import edu.berkeley.nlp.PCFGLA.GrammarTrainer.Options;
import edu.berkeley.nlp.PCFGLA.smoothing.SmoothAcrossParentBits;
import edu.berkeley.nlp.PCFGLA.smoothing.SmoothAcrossParentSubstate;
import edu.berkeley.nlp.PCFGLA.smoothing.Smoother;
import edu.berkeley.nlp.io.PTBLineLexer;
import edu.berkeley.nlp.io.PTBTokenizer;
import edu.berkeley.nlp.io.PTBLexer;
import edu.berkeley.nlp.syntax.StateSet;
import edu.berkeley.nlp.syntax.Tree;
import edu.berkeley.nlp.syntax.Trees;
import edu.berkeley.nlp.ui.TreeJPanel;
import edu.berkeley.nlp.util.CommandLineUtils;
import edu.berkeley.nlp.util.Numberer;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
Expand All @@ -33,6 +19,11 @@
import javax.imageio.ImageIO;
import javax.swing.JFrame;

import edu.berkeley.nlp.io.PTBLineLexer;
import edu.berkeley.nlp.syntax.Tree;
import edu.berkeley.nlp.ui.TreeJPanel;
import edu.berkeley.nlp.util.Numberer;

/**
* Reads in the Penn Treebank and generates N_GRAMMARS different grammars.
*
Expand Down
1 change: 0 additions & 1 deletion src/edu/berkeley/nlp/PCFGLA/BinaryCounterTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import edu.berkeley.nlp.util.ArrayUtil;
import edu.berkeley.nlp.util.Counter;
import edu.berkeley.nlp.util.MapFactory;
import edu.berkeley.nlp.util.MapFactory.HashMapFactory;

public class BinaryCounterTable implements Serializable {
/**
Expand Down
12 changes: 9 additions & 3 deletions src/edu/berkeley/nlp/PCFGLA/BinaryRule.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package edu.berkeley.nlp.PCFGLA;

import edu.berkeley.nlp.util.*;
import java.io.Serializable;
import java.util.Random;

import edu.berkeley.nlp.util.ArrayUtil;
import edu.berkeley.nlp.util.Numberer;
import edu.berkeley.nlp.util.StringUtils;

/**
* Binary rules (ints for parent, left and right children)
*
Expand Down Expand Up @@ -68,11 +71,13 @@ public BinaryRule(BinaryRule b, double[][][] newScores) {
// this.scores = new double[lSubStates][rSubStates][pSubStates];
// }

@Override
public int hashCode() {
return ((int) parentState << 16) ^ ((int) leftChildState << 8)
^ ((int) rightChildState);
return (parentState << 16) ^ (leftChildState << 8)
^ (rightChildState);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
Expand All @@ -90,6 +95,7 @@ public boolean equals(Object o) {

private static final char[] charsToEscape = new char[] { '\"' };

@Override
public String toString() {
Numberer n = Numberer.getGlobalNumberer("tags");
String lState = (String) n.object(leftChildState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;

import edu.berkeley.nlp.syntax.Tree;
import edu.berkeley.nlp.util.ArrayUtil;
import edu.berkeley.nlp.util.ScalingTools;

/**
Expand Down Expand Up @@ -38,6 +37,7 @@ public CoarseToFineMaxRuleDerivationParser(Grammar gr, Lexicon lex,
variational, useGoldPOS, initializeCascade);
}

@Override
void doConstrainedMaxCScores(List<String> sentence, Grammar grammar,
Lexicon lexicon, final boolean scale) {
numSubStatesArray = grammar.numSubStates;
Expand Down Expand Up @@ -397,6 +397,7 @@ else if (scale)
}
}

@Override
public Tree<String> extractBestMaxRuleParse(int start, int end,
List<String> sentence) {
return extractBestMaxRuleParse1(start, end, 0, 0, sentence);
Expand Down
7 changes: 7 additions & 0 deletions src/edu/berkeley/nlp/PCFGLA/CoarseToFineMaxRuleParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ protected void createArrays(boolean firstTime, int numStates,

}

@Override
protected void clearArrays() {
iScore = oScore = null;
viScore = voScore = null;
Expand Down Expand Up @@ -1149,6 +1150,7 @@ public void updateFinalGrammarAndLexicon(Grammar grammar, Lexicon lexicon) {
lexiconCascade[endLevel - startLevel] = null;// tmpLexicon;
}

@Override
public Tree<String> getBestParse(List<String> sentence) {
return getBestConstrainedParse(sentence, null, false);
}
Expand All @@ -1157,6 +1159,7 @@ public double getLogInsideScore() {
return logLikelihood;
}

@Override
public Tree<String> getBestConstrainedParse(List<String> sentence,
List<String> posTags, boolean[][][][] allowedS) {// List<Integer>[][]
// pStates) {
Expand Down Expand Up @@ -1286,6 +1289,7 @@ public double getConfidence(Tree<String> tree) {

}

@Override
public double getLogLikelihood(Tree<String> tree) {
if (logLikelihood == Double.NEGATIVE_INFINITY)
return logLikelihood;
Expand Down Expand Up @@ -2398,6 +2402,7 @@ void doConstrainedViterbiOutsideScores(Grammar grammar,
// }
// }

@Override
public void printUnaryStats() {
System.out.println("Touched " + touchedRules + " rules.");
System.out.println("Used a total of " + totalUsedUnaries + " unaries.");
Expand Down Expand Up @@ -3365,6 +3370,7 @@ protected void setupScaling() {

}

@Override
public synchronized Object call() {
Tree<String> parse = getBestParse(nextSentence);
nextSentence = null;
Expand All @@ -3377,6 +3383,7 @@ public synchronized Object call() {
return null;
}

@Override
public CoarseToFineMaxRuleParser newInstance() {
CoarseToFineMaxRuleParser newParser = new CoarseToFineMaxRuleParser(
grammar, lexicon, unaryPenalty, endLevel, viterbiParse,
Expand Down
28 changes: 28 additions & 0 deletions src/edu/berkeley/nlp/PCFGLA/CoarseToFineMaxRuleProductParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public void initCascade(Grammar gr, Lexicon lex, int nGr) {
}
}

@Override
void doConstrainedInsideScores(Grammar grammar, boolean viterbi,
boolean logScores) {
if (!viterbi && logScores)
Expand Down Expand Up @@ -508,6 +509,7 @@ void doConstrainedInsideScores(Grammar grammar, boolean viterbi,
* outside scores.
*/

@Override
void doConstrainedOutsideScores(Grammar grammar, boolean viterbi,
boolean logScores) {
short[] numSubStatesArray = grammar.numSubStates;
Expand Down Expand Up @@ -730,6 +732,7 @@ void doConstrainedOutsideScores(Grammar grammar, boolean viterbi,
}
}

@Override
void initializeChart(List<String> sentence, Lexicon lexicon,
boolean noSubstates, boolean noSmoothing, List<String> posTags,
boolean scale) {
Expand Down Expand Up @@ -919,6 +922,7 @@ protected void createArrays(boolean firstTime, int numStates,
}
}

@Override
protected void clearArrays() {
iScore = oScore = null;
viScore = voScore = null;
Expand All @@ -929,6 +933,7 @@ protected void clearArrays() {
narrowRExtent = wideRExtent = narrowLExtent = wideLExtent = null;
}

@Override
protected void pruneChart(double threshold, short[] numSubStatesArray,
int level) {
int totalStates = 0, previouslyPossible = 0, nowPossible = 0;
Expand Down Expand Up @@ -1064,6 +1069,7 @@ protected void pruneChart(double threshold, short[] numSubStatesArray,

int level;

@Override
public void doPreParses(List<String> sentence, Tree<StateSet> tree,
boolean noSmoothing, List<String> posTags) {
boolean keepGoldAlive = (tree != null); // we are given the gold tree ->
Expand Down Expand Up @@ -1194,6 +1200,7 @@ public void doPreParses(List<String> sentence, Tree<StateSet> tree,
}
}

@Override
protected void ensureGoldTreeSurvives(Tree<StateSet> tree, int level) {
List<Tree<StateSet>> children = tree.getChildren();
for (Tree<StateSet> child : children) {
Expand Down Expand Up @@ -1250,10 +1257,12 @@ private void setGoldTreeCountsToOne(Tree<StateSet> tree) {
// lexiconCascade[endLevel-startLevel] = null;//tmpLexicon;
// }

@Override
public Tree<String> getBestParse(List<String> sentence) {
return getBestConstrainedParse(sentence, null, false);
}

@Override
public double getLogInsideScore() {
return logLikelihood;
}
Expand Down Expand Up @@ -1297,6 +1306,7 @@ public double getLogInsideScore() {
// }
// }

@Override
public Tree<String> getBestConstrainedParse(List<String> sentence,
List<String> posTags, boolean noPreparse) {
if (sentence.size() == 0)
Expand Down Expand Up @@ -1325,12 +1335,14 @@ public Tree<String> getBestConstrainedParse(List<String> sentence,
return bestTree;
}

@Override
public double getModelScore(Tree<String> parsedTree) {
if (viterbiParse)
return logLikelihood;
return savedScore;
}

@Override
public double getConfidence(Tree<String> tree) {
if (logLikelihood == Double.NEGATIVE_INFINITY)
return logLikelihood;
Expand All @@ -1345,6 +1357,7 @@ public double getConfidence(Tree<String> tree) {

}

@Override
public double getLogLikelihood(Tree<String> tree) {
// if (logLikelihood == Double.NEGATIVE_INFINITY) return logLikelihood;
//
Expand All @@ -1371,6 +1384,7 @@ public double getLogLikelihood(Tree<String> tree) {
return Double.NEGATIVE_INFINITY;
}

@Override
public double getLogLikelihood() {
if (logLikelihood == Double.NEGATIVE_INFINITY)
return logLikelihood;
Expand All @@ -1391,6 +1405,7 @@ public double getLogLikelihood() {
* been computed. In particular, the narrowRExtent and other arrays need not
* be updated.
*/
@Override
void doConstrainedMaxCScores(List<String> sentence, Grammar grammar,
Lexicon lexicon, final boolean scale) {
short[] numSubStatesArray = grammar.numSubStates;
Expand Down Expand Up @@ -1742,6 +1757,7 @@ else if (scale)
* Returns the best parse, the one with maximum expected labelled recall.
* Assumes that the maxc* arrays have been filled.
*/
@Override
public Tree<String> extractBestMaxRuleParse(int start, int end,
List<String> sentence) {
return extractBestMaxRuleParse1(start, end, 0, sentence);
Expand All @@ -1751,6 +1767,7 @@ public Tree<String> extractBestMaxRuleParse(int start, int end,
* Returns the best parse for state "state", potentially starting with a
* unary rule
*/
@Override
public Tree<String> extractBestMaxRuleParse1(int start, int end, int state,
List<String> sentence) {
// System.out.println(start+", "+end+";");
Expand Down Expand Up @@ -1789,6 +1806,7 @@ public Tree<String> extractBestMaxRuleParse1(int start, int end, int state,
/**
* Returns the best parse for state "state", but cannot start with a unary
*/
@Override
public Tree<String> extractBestMaxRuleParse2(int start, int end, int state,
List<String> sentence) {
List<Tree<String>> children = new ArrayList<Tree<String>>();
Expand Down Expand Up @@ -1841,6 +1859,7 @@ public Tree<String> extractBestMaxRuleParse2(int start, int end, int state,
* more.
*/

@Override
void doConstrainedViterbiInsideScores(Grammar grammar, boolean level0grammar) {
short[] numSubStatesArray = grammar.numSubStates;
// double[] oldIScores = new double[maxNSubStates];
Expand Down Expand Up @@ -2203,6 +2222,7 @@ void doConstrainedViterbiInsideScores(Grammar grammar, boolean level0grammar) {
// }
// }

@Override
void doConstrainedViterbiOutsideScores(Grammar grammar,
boolean level0grammar) {
for (int diff = length; diff >= 1; diff--) {
Expand Down Expand Up @@ -2458,6 +2478,7 @@ void doConstrainedViterbiOutsideScores(Grammar grammar,
// }
// }

@Override
public void printUnaryStats() {
System.out.println("Touched " + touchedRules + " rules.");
System.out.println("Used a total of " + totalUsedUnaries + " unaries.");
Expand All @@ -2470,6 +2491,7 @@ public void printUnaryStats() {
* intermediate nodes in a unary chain because it parses with a unary-closed
* grammar.
*/
@Override
public Tree<String> extractBestViterbiParse(int gState, int gp, int start,
int end, List<String> sentence) {
// find sources of inside score
Expand Down Expand Up @@ -2821,6 +2843,7 @@ private double[] closeVariationalRules(double[][] ruleScores, int start,
return closedScores;
}

@Override
void doScaledConstrainedInsideScores(Grammar grammar) {
double initVal = 0;
short[] numSubStatesArray = grammar.numSubStates;
Expand Down Expand Up @@ -3109,6 +3132,7 @@ void doScaledConstrainedInsideScores(Grammar grammar) {
}
}

@Override
void doScaledConstrainedOutsideScores(Grammar grammar) {
double initVal = 0;
short[] numSubStatesArray = grammar.numSubStates;
Expand Down Expand Up @@ -3386,6 +3410,7 @@ void doScaledConstrainedOutsideScores(Grammar grammar) {
}
}

@Override
protected void setupScaling() {
// create arrays for scaling coefficients
iScale = new int[length][length + 1][];
Expand All @@ -3412,6 +3437,7 @@ protected void setupScaling() {

}

@Override
public synchronized Object call() {
Tree<String> parse = getBestParse(nextSentence);
nextSentence = null;
Expand All @@ -3433,6 +3459,7 @@ public synchronized Object call() {
// return newParser;
// }

@Override
public double getSentenceProbability(int start, int end, boolean sumScores) {
// System.out.println((allowedStates[start][end][0]));
// System.out.println((allowedSubStates[start][end][0][0]));
Expand All @@ -3453,6 +3480,7 @@ public double getSentenceProbability(int start, int end, boolean sumScores) {
return Math.log(score);
}

@Override
public boolean[][][] getAllowedStates() {
return allowedStates;
}
Expand Down
Loading

0 comments on commit 14db3ed

Please sign in to comment.