(text: str, property: str)
| 69 | return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL) |
| 70 | |
| 71 | def extract_strict_value(text: str, property: str) -> str: |
| 72 | text_clean = re.sub(r"^```(?:json)?\s*|\s*```$", "", text.strip(), |
| 73 | flags=re.IGNORECASE | re.MULTILINE) |
| 74 | try: |
| 75 | data = json.loads(text_clean) |
| 76 | if property in data: |
| 77 | raw_value = data[property] |
| 78 | if isinstance(raw_value, (int, float)): |
| 79 | return float(raw_value) |
| 80 | if property in non_numeric_props_options: |
| 81 | options = non_numeric_props_options[property] |
| 82 | for opt in options: |
| 83 | if isinstance(opt, bool): |
| 84 | if str(raw_value).lower() == str(opt).lower(): |
| 85 | return str(opt) |
| 86 | elif str(raw_value).lower() == str(opt).lower(): |
| 87 | return opt |
| 88 | return "" |
| 89 | return str(raw_value) |
| 90 | except Exception: |
| 91 | pass |
| 92 | |
| 93 | pattern = rf'\{{[^{{}}]*"?{re.escape(property)}"?\s*:\s*(.*?)\s*\}}' |
| 94 | match = re.search(pattern, text_clean, flags=re.DOTALL | re.IGNORECASE) |
| 95 | if not match: |
| 96 | return "" |
| 97 | raw_value = match.group(1).strip().strip('"') |
| 98 | if property in non_numeric_props_options: |
| 99 | options = non_numeric_props_options[property] |
| 100 | for opt in options: |
| 101 | if isinstance(opt, bool): |
| 102 | if raw_value.lower() == str(opt).lower(): |
| 103 | return str(opt) |
| 104 | elif raw_value.lower() == opt.lower(): |
| 105 | return opt |
| 106 | return "" |
| 107 | try: |
| 108 | return float(raw_value) |
| 109 | except ValueError: |
| 110 | return "" |
| 111 | |
| 112 | |
| 113 | @TEXT_POSTPROCESSORS.register_module() |
no test coverage detected