Commit 7df1fb14 by Steven Bird

code cleanups -- replaced 'has_key' with 'in'

parent a39be2c0
......@@ -211,7 +211,7 @@ class ChartMatrixView(object):
except: pass
def _fire_callbacks(self, event, *args):
if not self._callbacks.has_key(event): return
if event not in self._callbacks: return
for cb_func in self._callbacks[event].keys(): cb_func(*args)
def select_cell(self, i, j):
......@@ -1076,7 +1076,7 @@ class ChartView(object):
self._resize()
else:
for edge in self._chart:
if not self._edgetags.has_key(edge):
if edge not in self._edgetags:
self._add_edge(edge)
self._resize()
......@@ -1139,7 +1139,7 @@ class ChartView(object):
# Do NOT show leaf edges in the chart.
if isinstance(edge, LeafEdge): return
if self._edgetags.has_key(edge): return
if edge in self._edgetags: return
self._analyze_edge(edge)
self._grow()
......@@ -1246,11 +1246,11 @@ class ChartView(object):
If no colors are specified, use intelligent defaults
(dependant on selection, etc.)
"""
if not self._edgetags.has_key(edge): return
if edge not in self._edgetags: return
c = self._chart_canvas
if linecolor is not None and textcolor is not None:
if self._marks.has_key(edge):
if edge in self._marks:
linecolor = self._marks[edge]
tags = self._edgetags[edge]
c.itemconfig(tags[0], fill=linecolor)
......@@ -1262,7 +1262,7 @@ class ChartView(object):
return
else:
N = self._chart.num_leaves()
if self._marks.has_key(edge):
if edge in self._marks:
self._color_edge(self._marks[edge])
if (edge.is_complete() and edge.span() == (0, N)):
self._color_edge(edge, '#084', '#042')
......@@ -1574,7 +1574,7 @@ class ChartView(object):
except: pass
def _fire_callbacks(self, event, *args):
if not self._callbacks.has_key(event): return
if event not in self._callbacks: return
for cb_func in self._callbacks[event].keys(): cb_func(*args)
#######################################################################
......
......@@ -62,7 +62,7 @@ class Chat(object):
words = ""
for word in string.split(string.lower(str)):
if self._reflections.has_key(word):
if word in self._reflections:
word = self._reflections[word]
words += ' ' + word
return words
......
......@@ -600,7 +600,7 @@ class CanvasWidget(object):
call it. If no ancestors have a drag callback, do nothing.
"""
if self.__draggable:
if self.__callbacks.has_key('drag'):
if 'drag' in self.__callbacks:
cb = self.__callbacks['drag']
try:
cb(self)
......@@ -615,7 +615,7 @@ class CanvasWidget(object):
otherwise, find the closest ancestor with a click callback, and
call it. If no ancestors have a click callback, do nothing.
"""
if self.__callbacks.has_key(button):
if button in self.__callbacks:
cb = self.__callbacks[button]
#try:
cb(self)
......@@ -826,7 +826,7 @@ class SymbolWidget(TextWidget):
:type symbol: str
:param symbol: The name of the symbol to display.
"""
if not SymbolWidget.SYMBOLS.has_key(symbol):
if symbol not in SymbolWidget.SYMBOLS:
raise ValueError('Unknown symbol: %s' % symbol)
self._symbol = symbol
self.set_text(SymbolWidget.SYMBOLS[symbol])
......@@ -2218,7 +2218,7 @@ class ColorizedList(object):
self._textwidget.tag_lower('highlight', 'sel')
def _fire_callback(self, event, itemnum):
if not self._callbacks.has_key(event): return
if event not in self._callbacks: return
if 0 <= itemnum < len(self._items):
item = self._items[itemnum]
else:
......
......@@ -1660,7 +1660,7 @@ def demo(choice=None,
'3': ('Bottom-up left-corner', BU_LC_STRATEGY),
'4': ('Filtered left-corner', LC_STRATEGY)}
choices = []
if strategies.has_key(choice): choices = [choice]
if choice in strategies: choices = [choice]
if choice=='6': choices = "1234"
# Run the requested chart parser(s), except the stepping parser.
......
......@@ -288,7 +288,7 @@ class ProbabilisticNonprojectiveParser(object):
originals = []
swapped = False
for new_index in new_indexes:
if self.inner_nodes.has_key(new_index):
if new_index in self.inner_nodes:
for old_val in self.inner_nodes[new_index]:
if not old_val in originals:
originals.append(old_val)
......
......@@ -281,7 +281,7 @@ class ProbabilisticProjectiveDependencyParser(object):
for j in range(0, len(self._tokens) + 1):
chart[i].append(ChartCell(i,j))
if i==j+1:
if self._grammar._tags.has_key(tokens[i-1]):
if tokens[i-1] in self._grammar._tags:
for tag in self._grammar._tags[tokens[i-1]]:
chart[i][j].add(DependencySpan(i-1,i,i-1,[-1], [tag]))
else:
......@@ -367,7 +367,7 @@ class ProbabilisticProjectiveDependencyParser(object):
for child_index in range(0 - (nr_left_children + 1), nr_right_children + 2):
head_word = dg.nodelist[node_index]['word']
head_tag = dg.nodelist[node_index]['tag']
if tags.has_key(head_word):
if head_word in tags:
tags[head_word].add(head_tag)
else:
tags[head_word] = set([head_tag])
......@@ -387,11 +387,11 @@ class ProbabilisticProjectiveDependencyParser(object):
productions.append(DependencyProduction(head_word, [child]))
head_event = '(head (%s %s) (mods (%s, %s, %s) left))' % (child, child_tag, prev_tag, head_word, head_tag)
mod_event = '(mods (%s, %s, %s) left))' % (prev_tag, head_word, head_tag)
if events.has_key(head_event):
if head_event in events:
events[head_event] += 1
else:
events[head_event] = 1
if events.has_key(mod_event):
if mod_event in events:
events[mod_event] += 1
else:
events[mod_event] = 1
......@@ -407,11 +407,11 @@ class ProbabilisticProjectiveDependencyParser(object):
productions.append(DependencyProduction(head_word, [child]))
head_event = '(head (%s %s) (mods (%s, %s, %s) right))' % (child, child_tag, prev_tag, head_word, head_tag)
mod_event = '(mods (%s, %s, %s) right))' % (prev_tag, head_word, head_tag)
if events.has_key(head_event):
if head_event in events:
events[head_event] += 1
else:
events[head_event] = 1
if events.has_key(mod_event):
if mod_event in events:
events[mod_event] += 1
else:
events[mod_event] = 1
......
......@@ -114,7 +114,7 @@ class HoleSemantics(object):
self.labels.add(args[0])
else:
label = args[0]
assert not self.fragments.has_key(label)
assert label not in self.fragments
self.fragments[label] = (func, args[1:])
else:
raise ValueError(usr.node)
......@@ -269,7 +269,7 @@ class HoleSemantics(object):
def _formula_tree(self, plugging, node):
if node in plugging:
return self._formula_tree(plugging, plugging[node])
elif self.fragments.has_key(node):
elif node in self.fragments:
pred,args = self.fragments[node]
children = [self._formula_tree(plugging, arg) for arg in args]
return reduce(Constants.MAP[pred.variable.name], children)
......
......@@ -500,7 +500,7 @@ class PorterStemmer(StemmerI):
self.k = j
self.k0 = i
if self.pool.has_key(self.b[self.k0:self.k+1]):
if self.b[self.k0:self.k+1] in self.pool:
return self.pool[self.b[self.k0:self.k+1]]
if self.k <= self.k0 + 1:
......
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/ccg.doctest", line 69, in ccg.doctest
Failed example:
for parse in parser.nbest_parse("you prefer that cake".split(),1):
chart.printCCGDerivation(parse)
for parse in parser.nbest_parse("that is the cake which you prefer".split(), 1):
chart.printCCGDerivation(parse) # doctest: +NORMALIZE_WHITESPACE
Expected:
you prefer that cake
NP ((S\NP)/NP) (NP/N) N
--------------------->B
((S\NP)/N)
--------------------------->
(S\NP)
--------------------------------<
S
that is the cake which you prefer
NP ((S\NP)/NP) (NP/N) N ((N\N)/(S/NP)) NP ((S\NP)/NP)
--------------------->B
((S\NP)/N)
------>T
(N/(N\N))
--------------------------->B
((S\NP)/(N\N))
------------------------------------------->B
((S\NP)/(S/NP))
----->T
(S/(S\NP))
------------------>B
(S/NP)
------------------------------------------------------------->
(S\NP)
-------------------------------------------------------------------<
S
Got:
you prefer that cake
NP ((S\NP)/NP) (NP/N) N
--------------------->B
((S\NP)/N)
--------------------------->
(S\NP)
--------------------------------<
S
that is the cake which you prefer
NP ((S\NP)/NP) (NP/N) N ((N\N)/(S/NP)) NP ((S\NP)/NP)
--------------------->B
((S\NP)/N)
------>T
(N/(N\N))
--------------------------->B
((S\NP)/(N\N))
----->T
(S/(S\NP))
------------------>B
(S/NP)
---------------------------------->
(N\N)
------------------------------------------------------------->
(S\NP)
-------------------------------------------------------------------<
S
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/ccg.doctest", line 118, in ccg.doctest
Failed example:
for parse in parser.nbest_parse(sent,1):
chart.printCCGDerivation(parse) # doctest: +NORMALIZE_WHITESPACE
Expected:
that is the dough which you will eat without cooking
NP ((S\NP)/NP) (NP/N) N ((N\N)/(S/NP)) NP ((S\NP)/VP) (VP/NP) ((VP\VP)/VP['ing']) (VP['ing']/NP)
--------------------->B
((S\NP)/N)
------->T
(N/(N\N))
----->T
(S/(S\NP))
------------------>B
(S/VP)
------------------------------------->B
((VP\VP)/NP)
----------------------------------------------<Sx
(VP/NP)
---------------------------------------------------------------->B
(S/NP)
-------------------------------------------------------------------------------->
(N\N)
--------------------------------------------------------------------------------------->
N
------------------------------------------------------------------------------------------------------------>
(S\NP)
------------------------------------------------------------------------------------------------------------------<
S
Got:
that is the dough which you will eat without cooking
NP ((S\NP)/NP) (NP/N) N ((N\N)/(S/NP)) NP ((S\NP)/VP) (VP/NP) ((VP\VP)/VP['ing']) (VP['ing']/NP)
--------------------->B
((S\NP)/N)
------->T
(N/(N\N))
---------------------------->B
((S\NP)/(N\N))
-------------------------------------------->B
((S\NP)/(S/NP))
----->T
(S/(S\NP))
------------------>B
(S/VP)
------------------------------------->B
((VP\VP)/NP)
----------------------------------------------<Sx
(VP/NP)
---------------------------------------------------------------->B
(S/NP)
------------------------------------------------------------------------------------------------------------>
(S\NP)
------------------------------------------------------------------------------------------------------------------<
S
.
\ No newline at end of file
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 172, in chat80.doctest
Failed example:
for answer in chat80.sql_query('corpora/city_database/city.db', q):
print "%-10s %4s" % answer
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest chat80.doctest[16]>", line 1, in <module>
for answer in chat80.sql_query('corpora/city_database/city.db', q):
File "/Users/sb/git/nltk/nltk/sem/chat80.py", line 420, in sql_query
connection = sqlite3.connect(path)
ValueError: database parameter must be string or APSW Connection object
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 205, in chat80.doctest
Failed example:
trees = cp.nbest_parse(query.split())
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest chat80.doctest[21]>", line 1, in <module>
trees = cp.nbest_parse(query.split())
AttributeError: 'FeatureGrammar' object has no attribute 'nbest_parse'
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 206, in chat80.doctest
Failed example:
answer = trees[0].node['SEM']
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest chat80.doctest[22]>", line 1, in <module>
answer = trees[0].node['SEM']
NameError: name 'trees' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 207, in chat80.doctest
Failed example:
q = join(answer)
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest chat80.doctest[23]>", line 1, in <module>
q = join(answer)
NameError: name 'answer' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 208, in chat80.doctest
Failed example:
print q
Expected:
SELECT City FROM city_table WHERE Country="china"
Got:
SELECT City, Population FROM city_table WHERE Country = 'china' and Population > 1000
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 210, in chat80.doctest
Failed example:
rows = chat80.sql_query('corpora/city_database/city.db', q)
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest chat80.doctest[25]>", line 1, in <module>
rows = chat80.sql_query('corpora/city_database/city.db', q)
File "/Users/sb/git/nltk/nltk/sem/chat80.py", line 420, in sql_query
connection = sqlite3.connect(path)
ValueError: database parameter must be string or APSW Connection object
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/chat80.doctest", line 211, in chat80.doctest
Failed example:
for r in rows: print "%s" % r,
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest chat80.doctest[26]>", line 1, in <module>
for r in rows: print "%s" % r,
NameError: name 'rows' is not defined
.
\ No newline at end of file
.
\ No newline at end of file
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/classify.doctest", line 106, in classify.doctest
Failed example:
nltk.classify.svm.demo()
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest classify.doctest[14]>", line 1, in <module>
nltk.classify.svm.demo()
AttributeError: 'module' object has no attribute 'svm'
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/classify.doctest", line 148, in classify.doctest
Failed example:
test_maxent(nltk.classify.MaxentClassifier.ALGORITHMS)
# doctest: +ELLIPSIS
Expected:
[Found megam: ...]
test[0] test[1] test[2] test[3]
p(x) p(y) p(x) p(y) p(x) p(y) p(x) p(y)
-----------------------------------------------------------------------
LBFGSB 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
GIS 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
IIS 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
Nelder-Mead 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
CG 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
BFGS 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
MEGAM 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
Powell 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
Got:
[Found megam: /usr/local/bin/megam.opt]
test[0] test[1] test[2] test[3]
p(x) p(y) p(x) p(y) p(x) p(y) p(x) p(y)
-----------------------------------------------------------------------
LBFGSB Error: ValueError('operands could not be broadcast together with shapes (18) (12) ',)
GIS 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
IIS 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
Nelder-Mead 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
CG Error: ValueError('operands could not be broadcast together with shapes (18) (12) ',)
BFGS Error: ValueError('operands could not be broadcast together with shapes (18) (12) ',)
MEGAM 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
TADM Error: LookupError("\n\n===========================================================================\n NLTK was unable to find the tadm executable! Use config_tadm() or\n set the TADM_DIR environment variable.\n\n >>> config_tadm('/path/to/tadm')\n\n For more information, on tadm, see:\n <http://tadm.sf.net>\n===========================================================================",)
Powell 0.16 0.84 0.46 0.54 0.41 0.59 0.76 0.24
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/classify.doctest", line 185, in classify.doctest
Failed example:
classifier = maxent.MaxentClassifier.train(
train, bernoulli=False, encoding=encoding, trace=0)
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest classify.doctest[21]>", line 2, in <module>
train, bernoulli=False, encoding=encoding, trace=0)
File "/Users/sb/git/nltk/nltk/classify/maxent.py", line 323, in train
gaussian_prior_sigma, **cutoffs)
File "/Users/sb/git/nltk/nltk/classify/maxent.py", line 1453, in train_maxent_classifier_with_scipy
model.fit(algorithm=algorithm)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/maxentropy/maxentropy.py", line 1026, in fit
return model.fit(self, self.K, algorithm)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/maxentropy/maxentropy.py", line 226, in fit
callback=callback)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/optimize/optimize.py", line 636, in fmin_cg
gfk = myfprime(x0)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/optimize/optimize.py", line 176, in function_wrapper
return function(x, *args)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/maxentropy/maxentropy.py", line 420, in grad
G = self.expectations() - self.K
ValueError: operands could not be broadcast together with shapes (12) (8)
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/classify.doctest", line 188, in classify.doctest
Failed example:
classifier.batch_classify(test)
Expected:
['y', 'x']
Got:
['y', 'y']
.
\ No newline at end of file
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 21, in collocations.doctest
Failed example:
finder.nbest(bigram_measures.pmi, 10) # doctest: +NORMALIZE_WHITESPACE
Expected:
[('cutting', 'instrument'), ('sewed', 'fig'), ('sweet', 'savor'),
('Ben', 'Ammi'), ('appoint', 'overseers'), ('olive', 'leaf'),
('months', 'later'), ('remaining', 'silent'), ('seek', 'occasion'),
('leaf', 'plucked')]
Got:
[(u'Allon', u'Bacuth'), (u'Ashteroth', u'Karnaim'), (u'Ben', u'Ammi'), (u'En', u'Mishpat'), (u'Jegar', u'Sahadutha'), (u'Salt', u'Sea'), (u'Whoever', u'sheds'), (u'appoint', u'overseers'), (u'aromatic', u'resin'), (u'cutting', u'instrument')]
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 32, in collocations.doctest
Failed example:
finder.nbest(bigram_measures.pmi, 10) # doctest: +NORMALIZE_WHITESPACE
Expected:
[('Lahai', 'Roi'), ('gray', 'hairs'), ('Beer', 'Lahai'), ('Most', 'High'),
('ewe', 'lambs'), ('many', 'colors'), ('burnt', 'offering'),
('Paddan', 'Aram'), ('east', 'wind'), ('living', 'creature')]
Got:
[(u'Beer', u'Lahai'), (u'Lahai', u'Roi'), (u'gray', u'hairs'), (u'Most', u'High'), (u'ewe', u'lambs'), (u'many', u'colors'), (u'burnt', u'offering'), (u'Paddan', u'Aram'), (u'east', u'wind'), (u'living', u'creature')]
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 41, in collocations.doctest
Failed example:
finder.nbest(bigram_measures.pmi, 5) # doctest: +NORMALIZE_WHITESPACE
Expected:
[(('weekend', 'N'), ('duty', 'N')),
(('top', 'ADJ'), ('official', 'N')),
(('George', 'NP'), ('P.', 'NP')),
(('medical', 'ADJ'), ('intern', 'N')),
(('1962', 'NUM'), ("governor's", 'N'))]
Got:
[(('1,119', 'NUM'), ('votes', 'N')), (('1962', 'NUM'), ("governor's", 'N')), (('637', 'NUM'), ('E.', 'NP')), (('Alpharetta', 'NP'), ('prison', 'N')), (('Bar', 'N'), ('Association', 'N'))]
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 52, in collocations.doctest
Failed example:
finder.nbest(bigram_measures.pmi, 10) # doctest: +NORMALIZE_WHITESPACE
Expected:
[(':', '('), ('(', 'NUM'), ('NUM', ')'), (':', 'NUM'), (')', 'NUM'),
('-', 'WH'), ('VN', ':'), ('``', 'EX'), ('EX', 'MOD'), ('WH', 'VBZ')]
Got:
[(':', '('), ('(', 'NUM'), ('NUM', ')'), (':', 'NUM'), ('', 'WH'), (')', 'NUM'), ('VN', ':'), ('``', 'EX'), ('EX', 'MOD'), ('WH', 'VBZ')]
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 64, in collocations.doctest
Failed example:
finder.nbest(bigram_measures.likelihood_ratio, 10) # doctest: +NORMALIZE_WHITESPACE
Expected:
[('chief', 'chief'), ('hundred', 'years'), ('father', 'father'), ('lived', 'years'),
('years', 'father'), ('lived', 'father'), ('land', 'Egypt'), ('land', 'Canaan'),
('lived', 'hundred'), ('land', 'land')]
Got:
[(u'became', u'father'), (u'hundred', u'years'), (u'lived', u'years'), (u'father', u'became'), (u'years', u'became'), (u'land', u'Egypt'), (u'land', u'Canaan'), (u'lived', u'became'), (u'became', u'years'), (u'years', u'lived')]
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 181, in collocations.doctest
Failed example:
print '%0.2f' % bigram_measures.likelihood_ratio(110, (2552, 221), 31777)
Expected:
270.72
Got:
541.44
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 183, in collocations.doctest
Failed example:
print '%0.2f' % bigram_measures.likelihood_ratio(8, (13, 32), 31777)
Expected:
95.29
Got:
190.57
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/collocations.doctest", line 207, in collocations.doctest
Failed example:
print '%0.2f' % cont_bigram_measures.likelihood_ratio(8, 5, 24, 31740)
Expected:
95.29
Got:
190.57
.
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -223,9 +223,9 @@ class StatementFindingAstVisitor(compiler.visitor.ASTVisitor):
return 0
# If this line is excluded, or suite_spots maps this line to
# another line that is exlcuded, then we're excluded.
elif self.excluded.has_key(lineno) or \
self.suite_spots.has_key(lineno) and \
self.excluded.has_key(self.suite_spots[lineno][1]):
elif lineno in self.excluded or \
lineno in self.suite_spots and \
self.suite_spots[lineno][1] in self.excluded:
return 0
# Otherwise, this is an executable line.
else:
......@@ -254,8 +254,8 @@ class StatementFindingAstVisitor(compiler.visitor.ASTVisitor):
lastprev = self.getLastLine(prevsuite)
firstelse = self.getFirstLine(suite)
for l in range(lastprev+1, firstelse):
if self.suite_spots.has_key(l):
self.doSuite(None, suite, exclude=self.excluded.has_key(l))
if l in self.suite_spots:
self.doSuite(None, suite, exclude=(l in self.excluded))
break
else:
self.doSuite(None, suite)
......@@ -390,9 +390,9 @@ class coverage:
long_opts = optmap.values()
options, args = getopt.getopt(argv, short_opts, long_opts)
for o, a in options:
if optmap.has_key(o):
if o in optmap:
settings[optmap[o]] = 1
elif optmap.has_key(o + ':'):
elif o + ':' in optmap:
settings[optmap[o + ':']] = a
elif o[2:] in long_opts:
settings[o[2:]] = 1
......@@ -549,14 +549,14 @@ class coverage:
def merge_data(self, new_data):
for file_name, file_data in new_data.items():
if self.cexecuted.has_key(file_name):
if file_name in self.cexecuted:
self.merge_file_data(self.cexecuted[file_name], file_data)
else:
self.cexecuted[file_name] = file_data
def merge_file_data(self, cache_data, new_data):
for line_number in new_data.keys():
if not cache_data.has_key(line_number):
if line_number not in cache_data:
cache_data[line_number] = new_data[line_number]
# canonical_filename(filename). Return a canonical filename for the
......@@ -564,7 +564,7 @@ class coverage:
# normalized case). See [GDR 2001-12-04b, 3.3].
def canonical_filename(self, filename):
if not self.canonical_filename_cache.has_key(filename):
if filename not in self.canonical_filename_cache:
f = filename
if os.path.isabs(f) and not os.path.exists(f):
f = os.path.basename(f)
......@@ -587,7 +587,7 @@ class coverage:
# Can't do anything useful with exec'd strings, so skip them.
continue
f = self.canonical_filename(filename)
if not self.cexecuted.has_key(f):
if f not in self.cexecuted:
self.cexecuted[f] = {}
self.cexecuted[f][lineno] = 1
self.c = {}
......@@ -615,7 +615,7 @@ class coverage:
return self.analyze_morf(morf)[:-1]
def analyze_morf2(self, morf):
if self.analysis_cache.has_key(morf):
if morf in self.analysis_cache:
return self.analysis_cache[morf]
filename = self.morf_filename(morf)
ext = os.path.splitext(filename)[1]
......@@ -804,13 +804,13 @@ class coverage:
filename, statements, excluded, line_map, definfo = \
self.analyze_morf2(morf)
self.canonicalize_filenames()
if not self.cexecuted.has_key(filename):
if filename not in self.cexecuted:
self.cexecuted[filename] = {}
missing = []
for line in statements:
lines = line_map.get(line, [line, line])
for l in range(lines[0], lines[1]+1):
if self.cexecuted[filename].has_key(l):
if l in self.cexecuted[filename]:
break
else:
missing.append(line)
......
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/data.doctest", line 41, in data.doctest
Failed example:
url.replace('\\', '/') # doctest: +ELLIPSIS
Expected:
'file:...toy.cfg'
Got:
"file:ZipFilePathPointer('/usr/share/nltk_data/grammars/sample_grammars.zip', 'sample_grammars/toy.cfg')"
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/data.doctest", line 43, in data.doctest
Failed example:
print nltk.data.load(url) # doctest: +ELLIPSIS
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest data.doctest[6]>", line 1, in <module>
print nltk.data.load(url) # doctest: +ELLIPSIS
File "/Users/sb/git/nltk/nltk/data.py", line 589, in load
% resource_url)
ValueError: Could not determine format for file:ZipFilePathPointer('/usr/share/nltk_data/grammars/sample_grammars.zip', 'sample_grammars/toy.cfg') based on its file
extension; use the "format" argument to specify the format explicitly.
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/data.doctest", line 179, in data.doctest
Failed example:
str(path) # doctest: +ELLIPSIS
Expected:
'...rural.txt'
Got:
"ZipFilePathPointer('/usr/share/nltk_data/corpora/abc.zip', 'abc/rural.txt')"
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/data.doctest", line 256, in data.doctest
Failed example:
for i, url in enumerate(urls):
nltk.data.retrieve(url, 'toy-%d.cfg' % i) # doctest: +ELLIPSIS
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest data.doctest[47]>", line 2, in <module>
nltk.data.retrieve(url, 'toy-%d.cfg' % i) # doctest: +ELLIPSIS
File "/Users/sb/git/nltk/nltk/data.py", line 480, in retrieve
infile = _open(resource_url)
File "/Users/sb/git/nltk/nltk/data.py", line 676, in _open
return open(path, 'rb')
IOError: [Errno 2] No such file or directory: "ZipFilePathPointer('/usr/share/nltk_data/grammars/sample_grammars.zip', 'sample_grammars/toy.cfg')"
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 348, in gluesemantics.doctest
Failed example:
for r in glue.get_readings(glue.gfl_to_compiled(gfl)):
print r.simplify().normalize()
Expected:
exists x.(dog(x) & exists z1.(John(z1) & sees(z1,x)))
exists x.(John(x) & exists z1.(dog(z1) & sees(x,z1)))
Got:
exists z1.(dog(z1) & exists z2.(John(z2) & sees(z2,z1)))
exists z1.(John(z1) & exists z2.(dog(z2) & sees(z1,z2)))
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 385, in gluesemantics.doctest
Failed example:
depparser = MaltParser(tagger=tagger)
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[149]>", line 1, in <module>
depparser = MaltParser(tagger=tagger)
File "/Users/sb/git/nltk/nltk/parse/malt.py", line 24, in __init__
self.config_malt()
File "/Users/sb/git/nltk/nltk/parse/malt.py", line 73, in config_malt
verbose=verbose)
File "/Users/sb/git/nltk/nltk/internals.py", line 510, in find_binary
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find the malt.jar executable! Use
config_malt.jar() or set the MALTPARSERHOME environment variable.
>>> config_malt.jar('/path/to/malt.jar')
Searched in:
- .
- /usr/local/bin
For more information, on malt.jar, see:
<http://w3.msi.vxu.se/~jha/maltparser/index.html>
===========================================================================
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 390, in gluesemantics.doctest
Failed example:
glue = Glue(depparser=depparser)
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[150]>", line 1, in <module>
glue = Glue(depparser=depparser)
NameError: name 'depparser' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 391, in gluesemantics.doctest
Failed example:
for reading in glue.parse_to_meaning('every girl chases a dog'):
print reading.simplify().normalize()
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[151]>", line 1, in <module>
for reading in glue.parse_to_meaning('every girl chases a dog'):
File "/Users/sb/git/nltk/nltk/sem/glue.py", line 433, in parse_to_meaning
for agenda in self.parse_to_compiled(sentence):
File "/Users/sb/git/nltk/nltk/sem/glue.py", line 515, in parse_to_compiled
gfls = [self.depgraph_to_glue(dg) for dg in self.dep_parse(sentence)]
File "/Users/sb/git/nltk/nltk/sem/glue.py", line 522, in dep_parse
self.depparser = MaltParser(tagger=self.get_pos_tagger())
File "/Users/sb/git/nltk/nltk/parse/malt.py", line 24, in __init__
self.config_malt()
File "/Users/sb/git/nltk/nltk/parse/malt.py", line 73, in config_malt
verbose=verbose)
File "/Users/sb/git/nltk/nltk/internals.py", line 510, in find_binary
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find the malt.jar executable! Use
config_malt.jar() or set the MALTPARSERHOME environment variable.
>>> config_malt.jar('/path/to/malt.jar')
Searched in:
- .
- /usr/local/bin
For more information, on malt.jar, see:
<http://w3.msi.vxu.se/~jha/maltparser/index.html>
===========================================================================
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 396, in gluesemantics.doctest
Failed example:
drtglue = DrtGlue(depparser=depparser)
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[152]>", line 1, in <module>
drtglue = DrtGlue(depparser=depparser)
NameError: name 'depparser' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 397, in gluesemantics.doctest
Failed example:
for reading in drtglue.parse_to_meaning('every girl chases a dog'):
print reading.simplify().normalize()
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[153]>", line 1, in <module>
for reading in drtglue.parse_to_meaning('every girl chases a dog'):
NameError: name 'drtglue' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 411, in gluesemantics.doctest
Failed example:
readings = drtglue.parse_to_meaning('John sees Mary')
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[155]>", line 1, in <module>
readings = drtglue.parse_to_meaning('John sees Mary')
NameError: name 'drtglue' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 412, in gluesemantics.doctest
Failed example:
for drs in readings:
print drs.simplify().normalize()
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[156]>", line 1, in <module>
for drs in readings:
NameError: name 'readings' is not defined
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/gluesemantics.doctest", line 423, in gluesemantics.doctest
Failed example:
readings[0].equiv(readings[1])
Exception raised:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest gluesemantics.doctest[157]>", line 1, in <module>
readings[0].equiv(readings[1])
NameError: name 'readings' is not defined
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/probability.doctest", line 133, in probability.doctest
Failed example:
train_and_test(gt)
Expected:
14.43%
Got:
0.17%
.
\ No newline at end of file
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/relextract.doctest", line 66, in relextract.doctest
Failed example:
for doc in conll2002.chunked_sents('ned.train')[27]:
print doc
Expected:
('Het', 'Art')
(ORG Hof/N van/Prep Cassatie/N)
('verbrak', 'V')
('het', 'Art')
('arrest', 'N')
('zodat', 'Conj')
('het', 'Pron')
('moest', 'V')
('worden', 'V')
('overgedaan', 'V')
('door', 'Prep')
('het', 'Art')
('hof', 'N')
('van', 'Prep')
('beroep', 'N')
('van', 'Prep')
(LOC Antwerpen/N)
('.', 'Punc')
Got:
(u'Het', u'Art')
(ORG Hof/N van/Prep Cassatie/N)
(u'verbrak', u'V')
(u'het', u'Art')
(u'arrest', u'N')
(u'zodat', u'Conj')
(u'het', u'Pron')
(u'moest', u'V')
(u'worden', u'V')
(u'overgedaan', u'V')
(u'door', u'Prep')
(u'het', u'Art')
(u'hof', u'N')
(u'van', u'Prep')
(u'beroep', u'N')
(u'van', u'Prep')
(LOC Antwerpen/N)
(u'.', u'Punc')
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/relextract.doctest", line 235, in relextract.doctest
Failed example:
for r in rels[:10]:
print relextract.show_clause(r, relsym='DE') # doctest: +NORMALIZE_WHITESPACE
Expected:
DE('tribunal_supremo', 'victoria')
DE('museo_de_arte', 'alcorc\xe3\xb3n')
DE('museo_de_bellas_artes', 'a_coru\xe3\xb1a')
DE('siria', 'l\xe3\xadbano')
DE('uni\xe3\xb3n_europea', 'pek\xe3\xadn')
DE('ej\xe3\xa9rcito', 'rogberi')
DE('juzgado_de_instrucci\xe3\xb3n_n\xe3\xbamero_1', 'san_sebasti\xe3\xa1n')
DE('psoe', 'villanueva_de_la_serena')
DE('ej\xe3\xa9rcito', 'l\xe3\xadbano')
DE('juzgado_de_lo_penal_n\xe3\xbamero_2', 'ceuta')
Got:
DE(u'tribunal_supremo', u'victoria')
DE(u'museo_de_arte', u'alcorc\xf3n')
DE(u'museo_de_bellas_artes', u'a_coru\xf1a')
DE(u'siria', u'l\xedbano')
DE(u'uni\xf3n_europea', u'pek\xedn')
DE(u'ej\xe9rcito', u'rogberi')
DE(u'juzgado_de_instrucci\xf3n_n\xfamero_1', u'san_sebasti\xe1n')
DE(u'psoe', u'villanueva_de_la_serena')
DE(u'ej\xe9rcito', u'l\xedbano')
DE(u'juzgado_de_lo_penal_n\xfamero_2', u'ceuta')
***************************************************************************
File "/Users/sb/git/nltk/nltk/test/relextract.doctest", line 258, in relextract.doctest
Failed example:
for doc in conll2002.chunked_sents('ned.train'):
for r in relextract.extract_rels('PER', 'ORG', doc, corpus='conll2002', pattern=VAN):
print relextract.show_clause(r, relsym="VAN")
Expected:
VAN("cornet_d'elzius", 'buitenlandse_handel')
VAN('johan_rottiers', 'kardinaal_van_roey_instituut')
VAN('annie_lennox', 'eurythmics')
Got:
VAN(u"cornet_d'elzius", u'buitenlandse_handel')
VAN(u'johan_rottiers', u'kardinaal_van_roey_instituut')
VAN(u'annie_lennox', u'eurythmics')
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment