(sentence)
| 73 | |
| 74 | |
| 75 | def remove_formula(sentence): |
| 76 | # 首先尝试识别并移除完整的化学式 |
| 77 | # 匹配常见的化学式模式,包括括号、数字和多个元素的组合 |
| 78 | chemical_formula_pattern = r'\b[A-Z][a-z]?\d*(?:[A-Z][a-z]?\d*)*(?:\([A-Z][a-z]?\d*(?:[A-Z][a-z]?\d*)*\)\d*)*\b' |
| 79 | sentence = re.sub(chemical_formula_pattern, '', sentence) |
| 80 | |
| 81 | # 识别元素并过滤 |
| 82 | chem_elts = ['H', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts'] |
| 83 | contains_elements, matching_elements = contains_elements_and_matches(sentence, chem_elts) |
| 84 | |
| 85 | # 过滤掉答案中剩余的化学元素 |
| 86 | if contains_elements and matching_elements: |
| 87 | for element in matching_elements: |
| 88 | # 移除化学符号和可能的化合物 |
| 89 | pattern = re.compile(rf'\b\w*{element}\w*\b') |
| 90 | sentence = re.sub(pattern, '', sentence) |
| 91 | return sentence |
| 92 | |
| 93 | |
| 94 | def verify_float(number): |
no test coverage detected