Spaces:
Sleeping
Sleeping
| """ | |
| grader.py (Task 2 β Property Discovery) | |
| ----------------------------------------- | |
| Deterministic scorer for natural-language property submissions. | |
| One submission attempt per episode. | |
| """ | |
| from __future__ import annotations | |
| from typing import Tuple | |
| from utils import SemanticMatcher | |
| # ββ Grader ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| class Task2Grader: | |
| """ | |
| Grades a Task 2 property submission. | |
| Parameters | |
| ---------- | |
| function_name : name of the target function | |
| property : the 'property' field from the target function's data | |
| """ | |
| def __init__(self, function_name: str, property: str) -> None: | |
| self.function_name = function_name | |
| self.property = property | |
| # ββ Public API ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def grade(self, submitted: str) -> Tuple[float, str]: | |
| """Deterministic score in [0.0, 1.0].""" | |
| if not submitted or not submitted.strip(): | |
| return 0.0, "no_match" | |
| SemanticMatcherInstance = SemanticMatcher() | |
| return ( | |
| SemanticMatcherInstance.matchscore(self.property, submitted), | |
| SemanticMatcherInstance.confidence() | |
| ) |