Load a problem from a str object.
(cls, data: str, translate: bool = True)
| 159 | |
| 160 | @classmethod |
| 161 | def from_txt(cls, data: str, translate: bool = True) -> Problem: |
| 162 | """Load a problem from a str object.""" |
| 163 | url = '' |
| 164 | if '\n' in data: |
| 165 | url, data = data.split('\n') |
| 166 | |
| 167 | if ' ? ' in data: |
| 168 | clauses, goal = data.split(' ? ') |
| 169 | goal = Construction.from_txt(goal) |
| 170 | else: |
| 171 | clauses, goal = data, None |
| 172 | |
| 173 | clauses = clauses.split('; ') |
| 174 | problem = Problem( |
| 175 | url=url, clauses=[Clause.from_txt(c) for c in clauses], goal=goal |
| 176 | ) |
| 177 | if translate: |
| 178 | return problem.translate() |
| 179 | return problem |
| 180 | |
| 181 | @classmethod |
| 182 | def to_dict(cls, data: list[Problem]) -> dict[str, Problem]: |