Skip to content

Commit

Permalink
Fix bug in entry point method
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlls committed Dec 18, 2022
1 parent cd6241b commit bca3955
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions negate/negate.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,15 @@ def _get_entry_point(self, doc: SpacyDoc) -> Optional[SpacyToken]:
# If the root token is not an AUX or a VERB, look for an AUX or VERB in
# its children.
if not (self._is_aux(root) or self._is_verb(root)):
entry_point = [tk for tk in doc if self._is_aux(tk)
or self._is_verb(tk)]
entry_point = None
if root.children:
entry_point = [tk for tk in root.children
if self._is_aux(tk) or self._is_verb(tk)]
# No AUX or VERB found in the root children -> Take the first AUX
# or VERB in the sentence, if any.
if not entry_point:
entry_point = [tk for tk in doc
if self._is_aux(tk) or self._is_verb(tk)]
return entry_point[0] if entry_point else None
return root

Expand Down
2 changes: 1 addition & 1 deletion tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@

# Miscellaneous
misc = [
# ("A small Python module that doesn't negate sentences.", "A small Python module that negates sentences.", True),
("A small Python module that doesn't negate sentences.", "A small Python module that negates sentences.", True),
("You should always be careful.", "You shouldn't always be careful.", True),
("You must be careful.", "You must not be careful.", False),
("I would have done it differently.", "I wouldn't have done it differently.", True),
Expand Down

0 comments on commit bca3955

Please sign in to comment.