MCPcopy Create free account
hub / github.com/Enfoirer/Text2GraphRAG / normalize_amount

Method normalize_amount

agent/amount_normalizer.py:90–121  ·  view source on GitHub ↗

标准化用量表达 Args: amount: 原始用量 unit: 单位 Returns: Tuple[标准化后的用量, 估算数值]

(self, amount: str, unit: str = "")

Source from the content-addressed store, hash-verified

88 }
89
90 def normalize_amount(self, amount: str, unit: str = "") -> Tuple[str, Optional[float]]:
91 """
92 标准化用量表达
93
94 Args:
95 amount: 原始用量
96 unit: 单位
97
98 Returns:
99 Tuple[标准化后的用量, 估算数值]
100 """
101 if not amount:
102 return "", None
103
104 # 清理输入
105 amount = amount.strip()
106
107 # 尝试提取数字
108 number_match = re.match(r'^(\d+(?:\.\d+)?)', amount)
109 if number_match:
110 # 如果是纯数字,直接返回
111 try:
112 numeric_value = float(number_match.group(1))
113 return amount, numeric_value
114 except ValueError:
115 pass
116
117 # 标准化非数值表达
118 normalized = self.amount_mappings.get(amount, amount)
119 estimated = self.estimated_values.get(normalized, None)
120
121 return normalized, estimated
122
123 def parse_amount_with_unit(self, amount_str: str) -> Tuple[str, str, Optional[float]]:
124 """

Callers 3

get_comparable_valueMethod · 0.95
format_for_displayMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected