Skip to content

Conversation

@ColtonPayne
Copy link
Collaborator

@ColtonPayne ColtonPayne commented Jan 21, 2026

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)

  • Added validation for empty/whitespace-only input
  • Validates parentheses structure and placement
  • Enforces valid predicate naming (must start with letter or underscore, alphanumeric + underscore allowed)
  • Validates component structure (no nested parentheses, colons, etc.)
  • Validates interval bounds are within [0, 1] range
  • Validates interval lower <= upper bound
  • Prevents double negation and negation with explicit bounds
  • Provides clear, specific error messages for each validation failure

Bulk Fact Loading (pyreason.py)

  • Implemented add_fact_in_bulk() function to load facts from CSV files
  • Supports optional header row detection
  • Handles optional columns: name, start_time, end_time, static
  • Provides warnings for invalid data (malformed facts, invalid times, etc.) without crashing
  • Supports multiple boolean formats for static field (True/true/1/yes, False/false/0/no)

Test Coverage

  • 333 new lines in test_fact_parser.py:
    • Tests for valid fact parsing (node/edge facts, intervals, negation, etc.)
    • Tests for invalid inputs (missing parentheses, empty fields, invalid characters, etc.)
    • Edge cases and boundary conditions
  • 204 new lines in test_pyreason_file_loading.py:
    • Tests for bulk fact loading from CSV
    • Warning validation for invalid facts
    • Tests with/without headers, various static value formats
    • Error handling tests

Test Data

  • Created example_facts.csv with comprehensive test scenarios including both valid and invalid facts
  • Created example_facts_no_header.csv for testing CSV without headers

Implementation Notes

  • All validation errors raise ValueError with descriptive messages
  • Bulk loading continues processing even when individual rows fail (with warnings)
  • Predicate validation regex: ^[a-zA-Z_][a-zA-Z0-9_]*$ (follows Python identifier rules)

🤖 Generated with Claude Code

@ColtonPayne ColtonPayne added the AI PR contains AI Generated Code label Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI PR contains AI Generated Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants