fix(model): correctly parse tau flag from LCN sentence files - #9
Open
ThinkerDesigns wants to merge 1 commit into
Open
fix(model): correctly parse tau flag from LCN sentence files#9ThinkerDesigns wants to merge 1 commit into
ThinkerDesigns wants to merge 1 commit into
Conversation
The parser used bool() on the string after ";", but bool("False")
returns True since any non-empty string is truthy. This means writing
"; tau=False" in a sentence file silently set tau=True instead of False.
Fix: split on "=" to extract the actual boolean value string, then compare
with "true". Fixes IBM#5 which requested debugging this parsing issue.
There was a problem hiding this comment.
Pull request overview
This PR fixes boolean parsing of the tau flag when loading LCN sentence files via LCN.from_lcn() in lcn/model.py, ensuring that textual false values don’t incorrectly evaluate to True.
Changes:
- Replaces
bool(string)parsing of thetausuffix with explicit string parsing intended to recognizetau=true/tau=false. - Adds inline comments documenting why
bool("False")is incorrect for this use case.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+895
to
900
| tau_str = line[pos+1:].strip() | ||
| # Parse "tau=true" or "tau=false" correctly — bool() of any | ||
| # non-empty string (including "False") returns True, so we | ||
| # must split on "=" to get the actual boolean value. | ||
| tau = tau_str.split("=")[1].lower() == 'true' | ||
| line = line[:pos] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5
Bug: The
from_lcn()parser inlcn/model.pyusedbool(string)to parse thetauflag. In Python,bool("False")returnsTruebecause any non-empty string is truthy. This meant writing; tau=Falsein a sentence file silently settau = True.Fix: Split the value on
"="and compare with"true"instead of usingbool().Example — before:
After: