[marf-cvs] marf/src/marf/nlp/Parsing ProbabilisticParser.java,1.29,1.30
Brought to you by:
mokhov
From: Serguei A. M. <mo...@us...> - 2006-01-30 03:43:30
|
Update of /cvsroot/marf/marf/src/marf/nlp/Parsing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30462/marf/nlp/Parsing Modified Files: ProbabilisticParser.java Log Message: Avoid a dump() call in compileGrammar() for now as it was dumping a useless contents under ProbabilisticGrammarCompiler file name. Make sure the binary dump filename is properly set to Grammar in ProbabilisticParser. Adjust some formatting and naming along the way. Index: ProbabilisticParser.java =================================================================== RCS file: /cvsroot/marf/marf/src/marf/nlp/Parsing/ProbabilisticParser.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** ProbabilisticParser.java 3 Jan 2006 04:59:02 -0000 1.29 --- ProbabilisticParser.java 30 Jan 2006 03:43:17 -0000 1.30 *************** *** 30,58 **** * and its probability * ! * Create and clear pi[num_words, num_words, num_nonterminals] * ! * # base case ! * for i <-- 1 to num_words ! * for A <-- 1 to num_nonterminals ! * if (A --> wi) is in grammar then ! * pi [i, i, A] = P(A --> wi) * ! * # recursive case ! * for span <-- 2 to num_words ! * for begin <-- 1 to num_words - span + 1 ! * end <-- begin + span - 1 ! * for m = begin to end - 1 * ! * for A = 1 to num nonterminals ! * for B = 1 to num nonterminals ! * for C = 1 to num nonterminals * ! * prob = pi [begin, m, B] * pi [m + 1, end, C] * P(A --> BC) * ! * if (prob > pi[begin, end, A]) then ! * pi [begin, end, A] = prob ! * back[begin, end, A] = {m, B, C} * ! * return build_tree(back[1, num_words, 1]), [1, num_words, 1]) * </pre> * --- 30,58 ---- * and its probability * ! * create and clear pi[num_words, num_words, num_nonterminals] * ! * # base case ! * for i <-- 1 to num_words ! * for A <-- 1 to num_nonterminals ! * if (A --> wi) is in grammar then ! * pi [i, i, A] = P(A --> wi) * ! * # recursive case ! * for span <-- 2 to num_words ! * for begin <-- 1 to num_words - span + 1 ! * end <-- begin + span - 1 ! * for m = begin to end - 1 * ! * for A = 1 to num nonterminals ! * for B = 1 to num nonterminals ! * for C = 1 to num nonterminals * ! * prob = pi [begin, m, B] * pi [m + 1, end, C] * P(A --> BC) * ! * if (prob > pi[begin, end, A]) then ! * pi [begin, end, A] = prob ! * back[begin, end, A] = {m, B, C} * ! * return build_tree(back[1, num_words, 1]), [1, num_words, 1]) * </pre> * *************** *** 79,83 **** * 3-dimensional parse matrix for CYK. */ ! private double[][][] aoParseMatrix = null; /** --- 79,83 ---- * 3-dimensional parse matrix for CYK. */ ! private double[][][] adParseMatrix = null; /** *************** *** 134,137 **** --- 134,138 ---- this.oGrammar = new Grammar(); this.oObjectToSerialize = this.oGrammar; + setFilename(this.oGrammar.getClass().getName() + "." + getDefaultExtension()); } *************** *** 194,198 **** Vector oNonTerminals = this.oGrammar.getNonTerminalList(); ! this.aoParseMatrix = new double[this.oWords.size()][this.oWords.size()][oNonTerminals.size()]; this.aoBack = new Vector[this.oWords.size()][this.oWords.size()][oNonTerminals.size()]; --- 195,199 ---- Vector oNonTerminals = this.oGrammar.getNonTerminalList(); ! this.adParseMatrix = new double[this.oWords.size()][this.oWords.size()][oNonTerminals.size()]; this.aoBack = new Vector[this.oWords.size()][this.oWords.size()][oNonTerminals.size()]; *************** *** 227,231 **** } ! this.aoParseMatrix[i][i][A] = oRule.getProbability(); if(Debug.isDebugOn()) --- 228,232 ---- } ! this.adParseMatrix[i][i][A] = oRule.getProbability(); if(Debug.isDebugOn()) *************** *** 276,286 **** */ double dProb = ! this.aoParseMatrix[iBegin][m][iB] * ! this.aoParseMatrix[m + 1][iEnd][iC] * oRule.getProbability(); ! if(dProb > this.aoParseMatrix[iBegin][iEnd][iA]) { ! this.aoParseMatrix[iBegin][iEnd][iA] = dProb; Vector oBackIndices = new Vector(); --- 277,287 ---- */ double dProb = ! this.adParseMatrix[iBegin][m][iB] * ! this.adParseMatrix[m + 1][iEnd][iC] * oRule.getProbability(); ! if(dProb > this.adParseMatrix[iBegin][iEnd][iA]) { ! this.adParseMatrix[iBegin][iEnd][iA] = dProb; Vector oBackIndices = new Vector(); *************** *** 297,301 **** ( "[" + iBegin + "][" + iEnd + "][" + iA + "] = " + ! this.aoParseMatrix[iBegin][iEnd][iA] + ", [" + m + "][" + iB + "][" + iC + "] = " + "prob: " + dProb --- 298,302 ---- ( "[" + iBegin + "][" + iEnd + "][" + iA + "] = " + ! this.adParseMatrix[iBegin][iEnd][iA] + ", [" + m + "][" + iB + "][" + iC + "] = " + "prob: " + dProb *************** *** 317,321 **** // No parse ! if(this.aoParseMatrix[0][this.oWords.size() - 1][0] == 0) { return false; --- 318,322 ---- // No parse ! if(this.adParseMatrix[0][this.oWords.size() - 1][0] == 0) { return false; *************** *** 370,374 **** for(int k = 0; k < this.oGrammar.getNonTerminalList().size(); k++) { ! System.out.print("\t" + this.aoParseMatrix[i][j][k]); } } --- 371,375 ---- for(int k = 0; k < this.oGrammar.getNonTerminalList().size(); k++) { ! System.out.print("\t" + this.adParseMatrix[i][j][k]); } } *************** *** 390,394 **** try { ! ProbabilisticGrammarCompiler oGrammarCompiler = new ProbabilisticGrammarCompiler(this.strGrammarFilename); oGrammarCompiler.compileGrammar(); --- 391,396 ---- try { ! ProbabilisticGrammarCompiler oGrammarCompiler ! = new ProbabilisticGrammarCompiler(this.strGrammarFilename); oGrammarCompiler.compileGrammar(); *************** *** 441,445 **** ( oLHS + ! " (" + this.aoParseMatrix[i][j][piA] + ")" + " [" + getSentencePart(i, j) + " ]" ); --- 443,447 ---- ( oLHS + ! " (" + this.adParseMatrix[i][j][piA] + ")" + " [" + getSentencePart(i, j) + " ]" ); |