Add fact parser validation, tests, and bulk fact loading with tests#100
Add fact parser validation, tests, and bulk fact loading with tests#100ColtonPayne merged 29 commits intomainfrom
Conversation
dyumanaditya
left a comment
There was a problem hiding this comment.
@ColtonPayne Everything looks good except for my one comment on explicit bound inverses.
| - `'pred@name(node)'` - invalid characters in predicate | ||
| - `'pred(node1,node2,node3)'` - more than 2 components | ||
| - `'pred(node):[1.5,2.0]'` - values out of range [0,1] | ||
| - `'~pred(node):[0.2,0.8]'` - negation with explicit bound |
There was a problem hiding this comment.
negation with explicit bound This should actually be allowed. The negation of an explicit bound is defined and has an explicit formula. Currently it is not supported but it needs to be.
The formula for the inverse of a bound [l, u] is: ~[l, u] = [1-u, 1-l]
kmukherji
left a comment
There was a problem hiding this comment.
Some more comments are inline.
Implements add_rule_from_csv() and add_rule_from_json() for bulk rule loading, following the same pattern as bulk fact loading from PR #100. Updates add_rules_from_file() with raise_errors parameter for backwards-compatible error handling. Adds comprehensive test coverage. Resolves #117 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kmukherji
left a comment
There was a problem hiding this comment.
Once these comments are addressed we can merge this branch.
| if raise_errors: | ||
| raise ValueError(f"{item_label} {idx}: Invalid end_time '{end_time_raw}'") | ||
| warnings.warn(f"{item_label} {idx}: Invalid end_time '{end_time_raw}', using default value") | ||
| end_time = 0 |
There was a problem hiding this comment.
I think we can resolve end_time errors by assigning end_time = start_time.
What do you think?
There was a problem hiding this comment.
We are currently handling invalid values for start_time and end_time by setting them to zero if the user passes a non-integer value. This is the default value provided by the Fact constructor.
# Parse start_time
try:
start_time = int(start_time_raw) if start_time_raw is not None and str(start_time_raw).strip() else 0
If raise_errors is false, we handle this gracefully. If raise_errors is true, we will not accept an invalid json/csv and force the user to correct the bad input.
There was a problem hiding this comment.
Yeah. I am talking about the specific case where start_time is a valid non-zero integer. But end_time has an error. Should we give a warning and set it to start_time?
Summary
This PR adds comprehensive input validation to the fact parser and implements bulk fact loading from CSV files with extensive test coverage.
Fact Parser Validation (
fact_parser.py) (Issue #91 )Bulk Fact Loading (
pyreason.py)add_fact_in_bulk()function to load facts from CSV filesTest Coverage
test_fact_parser.py:test_pyreason_file_loading.py:Test Data
example_facts.csvwith comprehensive test scenarios including both valid and invalid factsexample_facts_no_header.csvfor testing CSV without headersImplementation Notes
ValueErrorwith descriptive messages^[a-zA-Z_][a-zA-Z0-9_]*$(follows Python identifier rules)🤖 Generated with Claude Code