Load deduction rule from a str object.
(cls, string: str, to_dict: bool = False)
| 382 | |
| 383 | @classmethod |
| 384 | def from_string(cls, string: str, to_dict: bool = False) -> Theorem: |
| 385 | """Load deduction rule from a str object.""" |
| 386 | theorems = string.split('\n') |
| 387 | theorems = [l for l in theorems if l and not l.startswith('#')] |
| 388 | theorems = [cls.from_txt(l) for l in theorems] |
| 389 | |
| 390 | for i, th in enumerate(theorems): |
| 391 | th.rule_name = 'r{:02}'.format(i) |
| 392 | |
| 393 | if to_dict: |
| 394 | result = {} |
| 395 | for t in theorems: |
| 396 | if t.name in result: |
| 397 | t.name += '_' |
| 398 | result[t.rule_name] = t |
| 399 | |
| 400 | return result |
| 401 | |
| 402 | return theorems |
| 403 | |
| 404 | @classmethod |
| 405 | def from_txt(cls, data: str) -> Theorem: |
no test coverage detected