格式化用于显示的用量字符串 Args: amount: 用量 unit: 单位 Returns: 格式化后的字符串
(self, amount: str, unit: str = "")
| 179 | return estimated |
| 180 | |
| 181 | def format_for_display(self, amount: str, unit: str = "") -> str: |
| 182 | """ |
| 183 | 格式化用于显示的用量字符串 |
| 184 | |
| 185 | Args: |
| 186 | amount: 用量 |
| 187 | unit: 单位 |
| 188 | |
| 189 | Returns: |
| 190 | 格式化后的字符串 |
| 191 | """ |
| 192 | normalized, _ = self.normalize_amount(amount, unit) |
| 193 | |
| 194 | if unit and normalized: |
| 195 | # 如果有单位且不是特殊表达(如"适量"已经很完整) |
| 196 | if normalized not in ["适量", "少许", "中量", "大量"]: |
| 197 | return f"{normalized} {unit}" |
| 198 | else: |
| 199 | return normalized |
| 200 | else: |
| 201 | return normalized or amount |
| 202 | |
| 203 | # 使用示例 |
| 204 | def demo_normalization(): |
nothing calls this directly
no test coverage detected