Skip to content

Commit

Permalink
final changes to code
Browse files Browse the repository at this point in the history
  • Loading branch information
asaluja committed Jun 4, 2014
1 parent 03ad7aa commit 85a21b7
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 363 deletions.
173 changes: 0 additions & 173 deletions EMNLP2014/ioalgo.tex

This file was deleted.

2 changes: 1 addition & 1 deletion minrule-extraction/combine_minimal_grammars.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Arg2: directory where guaranteed binary minimal rules are
Arg3: directory where ZGC rules are
Arg4: output directory
Usage:
Usage: python combine_minimal_grammars.py invalid_rules guaranteed_binary_dir/ ZGC_rules_dir/ output_dir/
'''

import sys, commands, string, os, gzip, re
Expand Down
5 changes: 2 additions & 3 deletions minrule-extraction/featurize_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def decorateSentenceGrammar(minRule_file, hiero_file, out_file, lex_model, optDi
out_fh.write("%s\n"%ruleToPrint)
else:
seen_rules.extend(rules_output) #global write
#print "for grammar %s, out of %d rules, %d are also in hiero"%(minRule_file, numRulesTotal, numRulesInHiero)
print "Grammar %s featurization complete: %d rules"%(minRule_file, numRulesTotal)
if perSent and not marginal: #add the NT only rules, but only if we're not reading in marginals (since we already have the NT rules), then close
out_fh.write("[X] ||| [X,1] [X,2] ||| [1] [2] ||| Glue=1\n")
Expand Down Expand Up @@ -242,8 +241,8 @@ def main():
else:
pool = mp.Pool(numProcesses)
for minRule_file in minRule_grammars:
#decorateSentenceGrammar(minRule_grammars_loc + minRule_file, hiero_grammars_loc + minRule_file, outFile_loc + minRule_file, lex_model, optDict)
pool.apply_async(decorateSentenceGrammar, (minRule_grammars_loc + minRule_file, hiero_grammars_loc + minRule_file, outFile_loc + minRule_file, lex_model, optDict))
decorateSentenceGrammar(minRule_grammars_loc + minRule_file, hiero_grammars_loc + minRule_file, outFile_loc + minRule_file, lex_model, optDict)
#pool.apply_async(decorateSentenceGrammar, (minRule_grammars_loc + minRule_file, hiero_grammars_loc + minRule_file, outFile_loc + minRule_file, lex_model, optDict))
pool.close()
pool.join()

Expand Down
64 changes: 0 additions & 64 deletions minrule-extraction/temp.debug

This file was deleted.

8 changes: 0 additions & 8 deletions minrule-extraction/temp.in

This file was deleted.

1 change: 0 additions & 1 deletion minrule-extraction/temp.out

This file was deleted.

25 changes: 22 additions & 3 deletions parameter-estimation/count_estimation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/python -tt

'''
Description for file here.
28 May: Removed addone functionality, shifted it to featurize_rules.py
File: count_estimation.py
Date: May 25, 2014
Description: simple file that, given a 'full' directory (namely,
a derivation tree for every sentence pair with the rules for every
NT written out), estimates the counts for every rule. In this code,
we filter all rules with number of NTs > 2 on the RHS.
Update: 28 May: Removed addone functionality, shifted it to featurize_rules.py
'''

import sys, commands, string, cPickle, os, gzip, re, getopt
Expand Down Expand Up @@ -72,13 +76,28 @@ def IncrementCountsByLine(filehandle):

def WriteOutCounts(fileout):
reformatted = {}
binary = 0
unary = 0
preterm = 0
for rule in Counts:
arity = CheckArity(rule) #first, keep track of the counts of rules across pre-term, unary, and binary
if arity == 0:
preterm += 1
elif arity == 1:
unary += 1
elif arity == 2:
binary += 1
else:
sys.stderr.write("Error! Writing out rule with # of NTs on RHS > 2!\n")
srcKey = ' ||| '.join(rule.split(' ||| ')[:-1])
tgtKey = rule.split(' ||| ')[-1]
srcDict = reformatted[srcKey] if srcKey in reformatted else {}
srcDict[tgtKey] = Counts[rule]
reformatted[srcKey] = srcDict
cPickle.dump(reformatted, open(fileout, "wb"))
print "Number of pre-terminal rules (including singletons): %d"%preterm
print "Number of unary rules: %d"%unary
print "Number of binary rules: %d"%binary

def main():
(opts, args) = getopt.getopt(sys.argv[1:], 'n:')
Expand Down
Loading

0 comments on commit 85a21b7

Please sign in to comment.