Skip to content

Commit

Permalink
Merge pull request nltk#664 from Liechti/develop
Browse files Browse the repository at this point in the history
Changes for Boolean Values nltk#621
  • Loading branch information
kmike committed May 1, 2014
2 parents 6f32e5a + efc009f commit 6f11c04
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions nltk/app/chartparser_app.py
Expand Up @@ -1091,16 +1091,16 @@ def update(self, chart=None):

def _edge_conflict(self, edge, lvl):
"""
Return 1 if the given edge overlaps with any edge on the given
Return True if the given edge overlaps with any edge on the given
level. This is used by _add_edge to figure out what level a
new edge should be added to.
"""
(s1, e1) = edge.span()
for otheredge in self._edgelevels[lvl]:
(s2, e2) = otheredge.span()
if (s1 <= s2 < e1) or (s2 <= s1 < e2) or (s1==s2==e1==e2):
return 1
return 0
return True
return False

def _analyze_edge(self, edge):
"""
Expand Down
12 changes: 6 additions & 6 deletions nltk/app/rdparser_app.py
Expand Up @@ -541,11 +541,11 @@ def _expand(self, *e):
index = self._productions.index(rv)
self._prodlist.selection_set(index)
self._animate_expand(old_frontier[0])
return 1
return True
else:
self._lastoper1['text'] = 'Expand:'
self._lastoper2['text'] = '(all expansions tried)'
return 0
return False

def _match(self, *e):
if self._animating_lock: return
Expand All @@ -555,11 +555,11 @@ def _match(self, *e):
self._lastoper1['text'] = 'Match:'
self._lastoper2['text'] = rv
self._animate_match(old_frontier[0])
return 1
return True
else:
self._lastoper1['text'] = 'Match:'
self._lastoper2['text'] = '(failed)'
return 0
return False

def _backtrack(self, *e):
if self._animating_lock: return
Expand All @@ -573,12 +573,12 @@ def _backtrack(self, *e):
self._animate_backtrack(self._parser.frontier()[0])
else:
self._animate_match_backtrack(self._parser.frontier()[0])
return 1
return True
else:
self._autostep = 0
self._lastoper1['text'] = 'Finished'
self._lastoper2['text'] = ''
return 0
return False

def about(self, *e):
ABOUT = ("NLTK Recursive Descent Parser Application\n"+
Expand Down
8 changes: 4 additions & 4 deletions nltk/app/srparser_app.py
Expand Up @@ -465,8 +465,8 @@ def reset(self, *e):
self._redraw()

def step(self, *e):
if self.reduce(): return 1
elif self.shift(): return 1
if self.reduce(): return True
elif self.shift(): return True
else:
if list(self._parser.parses()):
self._lastoper1['text'] = 'Finished:'
Expand All @@ -485,8 +485,8 @@ def shift(self, *e):
self._animate_shift()
else:
self._redraw()
return 1
return 0
return True
return False

def reduce(self, *e):
if self._animating_lock: return
Expand Down
16 changes: 8 additions & 8 deletions nltk/parse/recursivedescent.py
Expand Up @@ -426,12 +426,12 @@ def step(self):
possible, then perform the match, and return the matched
token. If an untried expansion is possible, then perform the
expansion, and return the production that it is based on. If
backtracking is possible, then backtrack, and return 1.
Otherwise, return 0.
backtracking is possible, then backtrack, and return True.
Otherwise, return None.
:return: 0 if no operation was performed; a token if a match
:return: None if no operation was performed; a token if a match
was performed; a production if an expansion was performed;
and 1 if a backtrack operation was performed.
and True if a backtrack operation was performed.
:rtype: Production or String or bool
"""
# Try matching (if we haven't already)
Expand All @@ -446,7 +446,7 @@ def step(self):
# Try backtracking
if self.backtrack():
self._trace_backtrack(self._tree, self._frontier)
return 1
return True

# Nothing left to do.
return None
Expand Down Expand Up @@ -527,9 +527,9 @@ def backtrack(self):
:return: true if an operation was successfully undone.
:rtype: bool
"""
if len(self._history) == 0: return 0
if len(self._history) == 0: return False
(self._rtext, self._tree, self._frontier) = self._history.pop()
return 1
return True

def expandable_productions(self):
"""
Expand Down Expand Up @@ -565,7 +565,7 @@ def untried_match(self):
:rtype: bool
"""

if len(self._rtext) == 0: return 0
if len(self._rtext) == 0: return False
tried_matches = self._tried_m.get(self._freeze(self._tree), [])
return (self._rtext[0] not in tried_matches)

Expand Down
26 changes: 13 additions & 13 deletions nltk/parse/shiftreduce.py
Expand Up @@ -137,15 +137,15 @@ def _match_rhs(self, rhs, rightmost_stack):
stack.
"""

if len(rightmost_stack) != len(rhs): return 0
if len(rightmost_stack) != len(rhs): return False
for i in range(len(rightmost_stack)):
if isinstance(rightmost_stack[i], Tree):
if not isinstance(rhs[i], Nonterminal): return 0
if rightmost_stack[i].label() != rhs[i].symbol(): return 0
if not isinstance(rhs[i], Nonterminal): return False
if rightmost_stack[i].label() != rhs[i].symbol(): return False
else:
if isinstance(rhs[i], Nonterminal): return 0
if rightmost_stack[i] != rhs[i]: return 0
return 1
if isinstance(rhs[i], Nonterminal): return False
if rightmost_stack[i] != rhs[i]: return False
return True

def _reduce(self, stack, remaining_text, production=None):
"""
Expand Down Expand Up @@ -332,10 +332,10 @@ def step(self):
Perform a single parsing operation. If a reduction is
possible, then perform that reduction, and return the
production that it is based on. Otherwise, if a shift is
possible, then perform it, and return 1. Otherwise,
return 0.
possible, then perform it, and return True. Otherwise,
return False.
:return: 0 if no operation was performed; 1 if a shift was
:return: False if no operation was performed; True if a shift was
performed; and the CFG production used to reduce if a
reduction was performed.
:rtype: Production or bool
Expand All @@ -351,10 +351,10 @@ def shift(self):
:return: True if the shift operation was successful.
:rtype: bool
"""
if len(self._remaining_text) == 0: return 0
if len(self._remaining_text) == 0: return False
self._history.append( (self._stack[:], self._remaining_text[:]) )
self._shift(self._stack, self._remaining_text)
return 1
return True

def reduce(self, production=None):
"""
Expand Down Expand Up @@ -386,9 +386,9 @@ def undo(self):
:return: true if an operation was successfully undone.
:rtype: bool
"""
if len(self._history) == 0: return 0
if len(self._history) == 0: return False
(self._stack, self._remaining_text) = self._history.pop()
return 1
return True

def reducible_productions(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions nltk/stem/porter.py
Expand Up @@ -240,15 +240,15 @@ def _cvc(self, word, i):
cav(e), lov(e), hop(e), crim(e), but
snow, box, tray.
"""
if i == 0: return 0 # i == 0 never happens perhaps
if i == 0: return False # i == 0 never happens perhaps
if i == 1: return (not self._cons(word, 0) and self._cons(word, 1))
if not self._cons(word, i) or self._cons(word, i-1) or not self._cons(word, i-2): return 0
if not self._cons(word, i) or self._cons(word, i-1) or not self._cons(word, i-2): return False

ch = word[i]
if ch == 'w' or ch == 'x' or ch == 'y':
return 0
return False

return 1
return True

def _step1ab(self, word):
"""step1ab() gets rid of plurals and -ed or -ing. e.g.
Expand Down

0 comments on commit 6f11c04

Please sign in to comment.